Skip to content

Commit 07bc92f

Browse files
Extravert-irHeisSpiter
authored andcommitted
[USETUP][SETUPLIB] Added support for formatting partition in BTRFS and installing ReactOS on it.
Removed code related to EXT2 boot sector for now. CORE-13769
1 parent 934104d commit 07bc92f

File tree

5 files changed

+63
-29
lines changed

5 files changed

+63
-29
lines changed

base/setup/lib/fsutil.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "partlist.h"
2525

2626
#include <fslib/vfatlib.h>
27+
#include <fslib/btrfslib.h>
2728
// #include <fslib/ext2lib.h>
2829
// #include <fslib/ntfslib.h>
2930

@@ -42,7 +43,9 @@ FILE_SYSTEM RegisteredFileSystems[] =
4243
{ L"EXT2" , Ext2Format, Ext2Chkdsk },
4344
{ L"EXT3" , Ext2Format, Ext2Chkdsk },
4445
{ L"EXT4" , Ext2Format, Ext2Chkdsk },
46+
#endif
4547
{ L"BTRFS", BtrfsFormatEx, BtrfsChkdskEx },
48+
#if 0
4649
{ L"FFS" , FfsFormat , FfsChkdsk },
4750
{ L"REISERFS", ReiserfsFormat, ReiserfsChkdsk },
4851
#endif
@@ -283,11 +286,10 @@ GetFileSystem(
283286
{
284287
FileSystemName = L"FAT";
285288
}
286-
else if (PartEntry->PartitionType == PARTITION_EXT2)
289+
else if (PartEntry->PartitionType == PARTITION_LINUX)
287290
{
288291
// WARNING: See the warning above.
289-
FileSystemName = L"EXT2";
290-
// FIXME: We may have EXT3, 4 too...
292+
FileSystemName = L"BTRFS";
291293
}
292294
else if (PartEntry->PartitionType == PARTITION_IFS)
293295
{
@@ -303,7 +305,7 @@ GetFileSystem(
303305
// HACK: WARNING: We cannot write on this FS yet!
304306
if (FileSystemName)
305307
{
306-
if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS)
308+
if (PartEntry->PartitionType == PARTITION_IFS)
307309
DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName);
308310
}
309311

@@ -375,6 +377,10 @@ PreparePartitionForFormatting(
375377
}
376378
}
377379
}
380+
else if (wcscmp(FileSystem->FileSystemName, L"BTRFS") == 0)
381+
{
382+
SetPartitionType(PartEntry, PARTITION_LINUX);
383+
}
378384
#if 0
379385
else if (wcscmp(FileSystem->FileSystemName, L"EXT2") == 0)
380386
{

base/setup/usetup/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ endif()
4141

4242
add_pch(usetup usetup.h SOURCE)
4343
set_module_type(usetup nativecui)
44-
target_link_libraries(usetup inflib setuplib zlib_solo ext2lib vfatlib)
44+
target_link_libraries(usetup inflib setuplib zlib_solo ext2lib vfatlib btrfslib)
4545
add_importlibs(usetup ntdll)
4646
add_cd_file(TARGET usetup DESTINATION reactos/system32 NO_CAB NAME_ON_CD smss.exe FOR bootcd regtest)

base/setup/usetup/bootsup.c

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ typedef struct _FAT32_BOOTSECTOR
7979

8080
} FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
8181

82-
typedef struct _EXT2_BOOTSECTOR
82+
typedef struct _BTRFS_BOOTSECTOR
8383
{
84-
// The EXT2 bootsector is completely user-specific.
85-
// No FS data is stored there.
86-
UCHAR Fill[1024];
87-
} EXT2_BOOTSECTOR, *PEXT2_BOOTSECTOR;
84+
UCHAR JumpBoot[3];
85+
UCHAR ChunkMapSize;
86+
UCHAR BootDrive;
87+
ULONGLONG PartitionStartLBA;
88+
UCHAR Fill[1521]; // 1536 - 15
89+
USHORT BootSectorMagic;
90+
} BTRFS_BOOTSECTOR, *PBTRFS_BOOTSECTOR;
91+
C_ASSERT(sizeof(BTRFS_BOOTSECTOR) == 3 * 512);
8892

8993
// TODO: Add more bootsector structures!
9094

@@ -1837,7 +1841,7 @@ InstallFat32BootCodeToDisk(
18371841

18381842
static
18391843
NTSTATUS
1840-
InstallExt2BootCodeToDisk(
1844+
InstallBtrfsBootCodeToDisk(
18411845
PWSTR SrcPath,
18421846
PWSTR RootPath)
18431847
{
@@ -1848,8 +1852,9 @@ InstallExt2BootCodeToDisk(
18481852
HANDLE FileHandle;
18491853
LARGE_INTEGER FileOffset;
18501854
// PEXT2_BOOTSECTOR OrigBootSector;
1851-
PEXT2_BOOTSECTOR NewBootSector;
1855+
PBTRFS_BOOTSECTOR NewBootSector;
18521856
// USHORT BackupBootSector;
1857+
PARTITION_INFORMATION_EX PartInfo;
18531858

18541859
#if 0
18551860
/* Allocate buffer for original bootsector */
@@ -1897,7 +1902,7 @@ InstallExt2BootCodeToDisk(
18971902
#endif
18981903

18991904
/* Allocate buffer for new bootsector */
1900-
NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(EXT2_BOOTSECTOR));
1905+
NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(BTRFS_BOOTSECTOR));
19011906
if (NewBootSector == NULL)
19021907
{
19031908
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@@ -1932,7 +1937,7 @@ InstallExt2BootCodeToDisk(
19321937
NULL,
19331938
&IoStatusBlock,
19341939
NewBootSector,
1935-
sizeof(EXT2_BOOTSECTOR),
1940+
sizeof(BTRFS_BOOTSECTOR),
19361941
NULL,
19371942
NULL);
19381943
NtClose(FileHandle);
@@ -1981,6 +1986,28 @@ InstallExt2BootCodeToDisk(
19811986
return Status;
19821987
}
19831988

1989+
/* Obtaining partition info and writing it to bootsector */
1990+
Status = NtDeviceIoControlFile(FileHandle,
1991+
NULL,
1992+
NULL,
1993+
NULL,
1994+
&IoStatusBlock,
1995+
IOCTL_DISK_GET_PARTITION_INFO_EX,
1996+
NULL,
1997+
0,
1998+
&PartInfo,
1999+
sizeof(PartInfo));
2000+
2001+
if (!NT_SUCCESS(Status))
2002+
{
2003+
DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status);
2004+
NtClose(FileHandle);
2005+
RtlFreeHeap(ProcessHeap, 0, NewBootSector);
2006+
return Status;
2007+
}
2008+
2009+
NewBootSector->PartitionStartLBA = PartInfo.StartingOffset.QuadPart / SECTORSIZE;
2010+
19842011
/* Write sector 0 */
19852012
FileOffset.QuadPart = 0ULL;
19862013
Status = NtWriteFile(FileHandle,
@@ -1989,7 +2016,7 @@ InstallExt2BootCodeToDisk(
19892016
NULL,
19902017
&IoStatusBlock,
19912018
NewBootSector,
1992-
sizeof(EXT2_BOOTSECTOR),
2019+
sizeof(BTRFS_BOOTSECTOR),
19932020
&FileOffset,
19942021
NULL);
19952022
#if 0
@@ -2552,7 +2579,7 @@ InstallFatBootcodeToPartition(
25522579

25532580
static
25542581
NTSTATUS
2555-
InstallExt2BootcodeToPartition(
2582+
InstallBtrfsBootcodeToPartition(
25562583
PUNICODE_STRING SystemRootPath,
25572584
PUNICODE_STRING SourceRootPath,
25582585
PUNICODE_STRING DestinationArcPath,
@@ -2563,7 +2590,7 @@ InstallExt2BootcodeToPartition(
25632590
WCHAR SrcPath[MAX_PATH];
25642591
WCHAR DstPath[MAX_PATH];
25652592

2566-
/* EXT2 partition */
2593+
/* BTRFS partition */
25672594
DPRINT("System path: '%wZ'\n", SystemRootPath);
25682595

25692596
/* Copy FreeLoader to the system partition, always overwriting the older version */
@@ -2625,7 +2652,7 @@ InstallExt2BootcodeToPartition(
26252652
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, BootSector);
26262653

26272654
DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath);
2628-
Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(EXT2_BOOTSECTOR));
2655+
Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(BTRFS_BOOTSECTOR));
26292656
if (!NT_SUCCESS(Status))
26302657
{
26312658
DPRINT1("SaveBootSector() failed (Status %lx)\n", Status);
@@ -2645,14 +2672,14 @@ InstallExt2BootcodeToPartition(
26452672
/* Install new bootsector on the disk */
26462673
// if (PartitionType == PARTITION_EXT2)
26472674
{
2648-
/* Install EXT2 bootcode */
2649-
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\ext2.bin");
2675+
/* Install BTRFS bootcode */
2676+
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\btrfs.bin");
26502677

2651-
DPRINT1("Install EXT2 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
2652-
Status = InstallExt2BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
2678+
DPRINT1("Install BTRFS bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
2679+
Status = InstallBtrfsBootCodeToDisk(SrcPath, SystemRootPath->Buffer);
26532680
if (!NT_SUCCESS(Status))
26542681
{
2655-
DPRINT1("InstallExt2BootCodeToDisk() failed (Status %lx)\n", Status);
2682+
DPRINT1("InstallBtrfsBootCodeToDisk() failed (Status %lx)\n", Status);
26562683
return Status;
26572684
}
26582685
}
@@ -2684,12 +2711,12 @@ InstallVBRToPartition(
26842711
PartitionType);
26852712
}
26862713

2687-
case PARTITION_EXT2:
2714+
case PARTITION_LINUX:
26882715
{
2689-
return InstallExt2BootcodeToPartition(SystemRootPath,
2690-
SourceRootPath,
2691-
DestinationArcPath,
2692-
PartitionType);
2716+
return InstallBtrfsBootcodeToPartition(SystemRootPath,
2717+
SourceRootPath,
2718+
DestinationArcPath,
2719+
PartitionType);
26932720
}
26942721

26952722
case PARTITION_IFS:

boot/bootdata/txtsetup.sif

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pci.sys=,,,,,,,,,,,,4
5656
scsiport.sys=,,,,,,x,,,,,,4
5757
storport.sys=,,,,,,x,,,,,,4
5858
fastfat.sys=,,,,,,x,,,,,,4
59+
btrfs.sys=,,,,,,x,,,,,,4
5960
ramdisk.sys=,,,,,,x,,,,,,4
6061
classpnp.sys=,,,,,,,,,,,,4
6162
pciide.sys=,,,,,,,,,,,,4

drivers/filesystems/btrfs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ add_definitions(-D__KERNEL__)
4141
set_module_type(btrfs kernelmodedriver)
4242
target_link_libraries(btrfs rtlver ntoskrnl_vista zlib_solo wdmguid ${PSEH_LIB})
4343
add_importlibs(btrfs ntoskrnl hal)
44-
add_cd_file(TARGET btrfs DESTINATION reactos/system32/drivers FOR all)
44+
add_cd_file(TARGET btrfs DESTINATION reactos/system32/drivers NO_CAB FOR all)

0 commit comments

Comments
 (0)