From 07bc92f740a5e4f70a82c5835a5e9266c9967462 Mon Sep 17 00:00:00 2001 From: Victor Perevertkin Date: Thu, 14 Jun 2018 02:30:06 +0300 Subject: [PATCH] [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 --- base/setup/lib/fsutil.c | 14 +++-- base/setup/usetup/CMakeLists.txt | 2 +- base/setup/usetup/bootsup.c | 73 ++++++++++++++++-------- boot/bootdata/txtsetup.sif | 1 + drivers/filesystems/btrfs/CMakeLists.txt | 2 +- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/base/setup/lib/fsutil.c b/base/setup/lib/fsutil.c index bec91c49880..db1f3073bed 100644 --- a/base/setup/lib/fsutil.c +++ b/base/setup/lib/fsutil.c @@ -24,6 +24,7 @@ #include "partlist.h" #include +#include // #include // #include @@ -42,7 +43,9 @@ FILE_SYSTEM RegisteredFileSystems[] = { L"EXT2" , Ext2Format, Ext2Chkdsk }, { L"EXT3" , Ext2Format, Ext2Chkdsk }, { L"EXT4" , Ext2Format, Ext2Chkdsk }, +#endif { L"BTRFS", BtrfsFormatEx, BtrfsChkdskEx }, +#if 0 { L"FFS" , FfsFormat , FfsChkdsk }, { L"REISERFS", ReiserfsFormat, ReiserfsChkdsk }, #endif @@ -283,11 +286,10 @@ GetFileSystem( { FileSystemName = L"FAT"; } - else if (PartEntry->PartitionType == PARTITION_EXT2) + else if (PartEntry->PartitionType == PARTITION_LINUX) { // WARNING: See the warning above. - FileSystemName = L"EXT2"; - // FIXME: We may have EXT3, 4 too... + FileSystemName = L"BTRFS"; } else if (PartEntry->PartitionType == PARTITION_IFS) { @@ -303,7 +305,7 @@ Quit: // For code temporarily disabled above // HACK: WARNING: We cannot write on this FS yet! if (FileSystemName) { - if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS) + if (PartEntry->PartitionType == PARTITION_IFS) DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName); } @@ -375,6 +377,10 @@ PreparePartitionForFormatting( } } } + else if (wcscmp(FileSystem->FileSystemName, L"BTRFS") == 0) + { + SetPartitionType(PartEntry, PARTITION_LINUX); + } #if 0 else if (wcscmp(FileSystem->FileSystemName, L"EXT2") == 0) { diff --git a/base/setup/usetup/CMakeLists.txt b/base/setup/usetup/CMakeLists.txt index 13aea12e163..db5b7d713b3 100644 --- a/base/setup/usetup/CMakeLists.txt +++ b/base/setup/usetup/CMakeLists.txt @@ -41,6 +41,6 @@ endif() add_pch(usetup usetup.h SOURCE) set_module_type(usetup nativecui) -target_link_libraries(usetup inflib setuplib zlib_solo ext2lib vfatlib) +target_link_libraries(usetup inflib setuplib zlib_solo ext2lib vfatlib btrfslib) add_importlibs(usetup ntdll) add_cd_file(TARGET usetup DESTINATION reactos/system32 NO_CAB NAME_ON_CD smss.exe FOR bootcd regtest) diff --git a/base/setup/usetup/bootsup.c b/base/setup/usetup/bootsup.c index b59767131b7..309e096d39e 100644 --- a/base/setup/usetup/bootsup.c +++ b/base/setup/usetup/bootsup.c @@ -79,12 +79,16 @@ typedef struct _FAT32_BOOTSECTOR } FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR; -typedef struct _EXT2_BOOTSECTOR +typedef struct _BTRFS_BOOTSECTOR { - // The EXT2 bootsector is completely user-specific. - // No FS data is stored there. - UCHAR Fill[1024]; -} EXT2_BOOTSECTOR, *PEXT2_BOOTSECTOR; + UCHAR JumpBoot[3]; + UCHAR ChunkMapSize; + UCHAR BootDrive; + ULONGLONG PartitionStartLBA; + UCHAR Fill[1521]; // 1536 - 15 + USHORT BootSectorMagic; +} BTRFS_BOOTSECTOR, *PBTRFS_BOOTSECTOR; +C_ASSERT(sizeof(BTRFS_BOOTSECTOR) == 3 * 512); // TODO: Add more bootsector structures! @@ -1837,7 +1841,7 @@ InstallFat32BootCodeToDisk( static NTSTATUS -InstallExt2BootCodeToDisk( +InstallBtrfsBootCodeToDisk( PWSTR SrcPath, PWSTR RootPath) { @@ -1848,8 +1852,9 @@ InstallExt2BootCodeToDisk( HANDLE FileHandle; LARGE_INTEGER FileOffset; // PEXT2_BOOTSECTOR OrigBootSector; - PEXT2_BOOTSECTOR NewBootSector; + PBTRFS_BOOTSECTOR NewBootSector; // USHORT BackupBootSector; + PARTITION_INFORMATION_EX PartInfo; #if 0 /* Allocate buffer for original bootsector */ @@ -1897,7 +1902,7 @@ InstallExt2BootCodeToDisk( #endif /* Allocate buffer for new bootsector */ - NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(EXT2_BOOTSECTOR)); + NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(BTRFS_BOOTSECTOR)); if (NewBootSector == NULL) { // RtlFreeHeap(ProcessHeap, 0, OrigBootSector); @@ -1932,7 +1937,7 @@ InstallExt2BootCodeToDisk( NULL, &IoStatusBlock, NewBootSector, - sizeof(EXT2_BOOTSECTOR), + sizeof(BTRFS_BOOTSECTOR), NULL, NULL); NtClose(FileHandle); @@ -1981,6 +1986,28 @@ InstallExt2BootCodeToDisk( return Status; } + /* Obtaining partition info and writing it to bootsector */ + Status = NtDeviceIoControlFile(FileHandle, + NULL, + NULL, + NULL, + &IoStatusBlock, + IOCTL_DISK_GET_PARTITION_INFO_EX, + NULL, + 0, + &PartInfo, + sizeof(PartInfo)); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status); + NtClose(FileHandle); + RtlFreeHeap(ProcessHeap, 0, NewBootSector); + return Status; + } + + NewBootSector->PartitionStartLBA = PartInfo.StartingOffset.QuadPart / SECTORSIZE; + /* Write sector 0 */ FileOffset.QuadPart = 0ULL; Status = NtWriteFile(FileHandle, @@ -1989,7 +2016,7 @@ InstallExt2BootCodeToDisk( NULL, &IoStatusBlock, NewBootSector, - sizeof(EXT2_BOOTSECTOR), + sizeof(BTRFS_BOOTSECTOR), &FileOffset, NULL); #if 0 @@ -2552,7 +2579,7 @@ InstallFatBootcodeToPartition( static NTSTATUS -InstallExt2BootcodeToPartition( +InstallBtrfsBootcodeToPartition( PUNICODE_STRING SystemRootPath, PUNICODE_STRING SourceRootPath, PUNICODE_STRING DestinationArcPath, @@ -2563,7 +2590,7 @@ InstallExt2BootcodeToPartition( WCHAR SrcPath[MAX_PATH]; WCHAR DstPath[MAX_PATH]; - /* EXT2 partition */ + /* BTRFS partition */ DPRINT("System path: '%wZ'\n", SystemRootPath); /* Copy FreeLoader to the system partition, always overwriting the older version */ @@ -2625,7 +2652,7 @@ InstallExt2BootcodeToPartition( CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, BootSector); DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath); - Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(EXT2_BOOTSECTOR)); + Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(BTRFS_BOOTSECTOR)); if (!NT_SUCCESS(Status)) { DPRINT1("SaveBootSector() failed (Status %lx)\n", Status); @@ -2645,14 +2672,14 @@ InstallExt2BootcodeToPartition( /* Install new bootsector on the disk */ // if (PartitionType == PARTITION_EXT2) { - /* Install EXT2 bootcode */ - CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\ext2.bin"); + /* Install BTRFS bootcode */ + CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\btrfs.bin"); - DPRINT1("Install EXT2 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); - Status = InstallExt2BootCodeToDisk(SrcPath, SystemRootPath->Buffer); + DPRINT1("Install BTRFS bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer); + Status = InstallBtrfsBootCodeToDisk(SrcPath, SystemRootPath->Buffer); if (!NT_SUCCESS(Status)) { - DPRINT1("InstallExt2BootCodeToDisk() failed (Status %lx)\n", Status); + DPRINT1("InstallBtrfsBootCodeToDisk() failed (Status %lx)\n", Status); return Status; } } @@ -2684,12 +2711,12 @@ InstallVBRToPartition( PartitionType); } - case PARTITION_EXT2: + case PARTITION_LINUX: { - return InstallExt2BootcodeToPartition(SystemRootPath, - SourceRootPath, - DestinationArcPath, - PartitionType); + return InstallBtrfsBootcodeToPartition(SystemRootPath, + SourceRootPath, + DestinationArcPath, + PartitionType); } case PARTITION_IFS: diff --git a/boot/bootdata/txtsetup.sif b/boot/bootdata/txtsetup.sif index fc2aa632847..73eda6f7fa5 100644 --- a/boot/bootdata/txtsetup.sif +++ b/boot/bootdata/txtsetup.sif @@ -56,6 +56,7 @@ pci.sys=,,,,,,,,,,,,4 scsiport.sys=,,,,,,x,,,,,,4 storport.sys=,,,,,,x,,,,,,4 fastfat.sys=,,,,,,x,,,,,,4 +btrfs.sys=,,,,,,x,,,,,,4 ramdisk.sys=,,,,,,x,,,,,,4 classpnp.sys=,,,,,,,,,,,,4 pciide.sys=,,,,,,,,,,,,4 diff --git a/drivers/filesystems/btrfs/CMakeLists.txt b/drivers/filesystems/btrfs/CMakeLists.txt index 123c9f0522d..65e61d255a4 100644 --- a/drivers/filesystems/btrfs/CMakeLists.txt +++ b/drivers/filesystems/btrfs/CMakeLists.txt @@ -41,4 +41,4 @@ add_definitions(-D__KERNEL__) set_module_type(btrfs kernelmodedriver) target_link_libraries(btrfs rtlver ntoskrnl_vista zlib_solo wdmguid ${PSEH_LIB}) add_importlibs(btrfs ntoskrnl hal) -add_cd_file(TARGET btrfs DESTINATION reactos/system32/drivers FOR all) +add_cd_file(TARGET btrfs DESTINATION reactos/system32/drivers NO_CAB FOR all)