@@ -79,12 +79,16 @@ typedef struct _FAT32_BOOTSECTOR
79
79
80
80
} FAT32_BOOTSECTOR , * PFAT32_BOOTSECTOR ;
81
81
82
- typedef struct _EXT2_BOOTSECTOR
82
+ typedef struct _BTRFS_BOOTSECTOR
83
83
{
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 );
88
92
89
93
// TODO: Add more bootsector structures!
90
94
@@ -1837,7 +1841,7 @@ InstallFat32BootCodeToDisk(
1837
1841
1838
1842
static
1839
1843
NTSTATUS
1840
- InstallExt2BootCodeToDisk (
1844
+ InstallBtrfsBootCodeToDisk (
1841
1845
PWSTR SrcPath ,
1842
1846
PWSTR RootPath )
1843
1847
{
@@ -1848,8 +1852,9 @@ InstallExt2BootCodeToDisk(
1848
1852
HANDLE FileHandle ;
1849
1853
LARGE_INTEGER FileOffset ;
1850
1854
// PEXT2_BOOTSECTOR OrigBootSector;
1851
- PEXT2_BOOTSECTOR NewBootSector ;
1855
+ PBTRFS_BOOTSECTOR NewBootSector ;
1852
1856
// USHORT BackupBootSector;
1857
+ PARTITION_INFORMATION_EX PartInfo ;
1853
1858
1854
1859
#if 0
1855
1860
/* Allocate buffer for original bootsector */
@@ -1897,7 +1902,7 @@ InstallExt2BootCodeToDisk(
1897
1902
#endif
1898
1903
1899
1904
/* Allocate buffer for new bootsector */
1900
- NewBootSector = RtlAllocateHeap (ProcessHeap , 0 , sizeof (EXT2_BOOTSECTOR ));
1905
+ NewBootSector = RtlAllocateHeap (ProcessHeap , 0 , sizeof (BTRFS_BOOTSECTOR ));
1901
1906
if (NewBootSector == NULL )
1902
1907
{
1903
1908
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@@ -1932,7 +1937,7 @@ InstallExt2BootCodeToDisk(
1932
1937
NULL ,
1933
1938
& IoStatusBlock ,
1934
1939
NewBootSector ,
1935
- sizeof (EXT2_BOOTSECTOR ),
1940
+ sizeof (BTRFS_BOOTSECTOR ),
1936
1941
NULL ,
1937
1942
NULL );
1938
1943
NtClose (FileHandle );
@@ -1981,6 +1986,28 @@ InstallExt2BootCodeToDisk(
1981
1986
return Status ;
1982
1987
}
1983
1988
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
+
1984
2011
/* Write sector 0 */
1985
2012
FileOffset .QuadPart = 0ULL ;
1986
2013
Status = NtWriteFile (FileHandle ,
@@ -1989,7 +2016,7 @@ InstallExt2BootCodeToDisk(
1989
2016
NULL ,
1990
2017
& IoStatusBlock ,
1991
2018
NewBootSector ,
1992
- sizeof (EXT2_BOOTSECTOR ),
2019
+ sizeof (BTRFS_BOOTSECTOR ),
1993
2020
& FileOffset ,
1994
2021
NULL );
1995
2022
#if 0
@@ -2552,7 +2579,7 @@ InstallFatBootcodeToPartition(
2552
2579
2553
2580
static
2554
2581
NTSTATUS
2555
- InstallExt2BootcodeToPartition (
2582
+ InstallBtrfsBootcodeToPartition (
2556
2583
PUNICODE_STRING SystemRootPath ,
2557
2584
PUNICODE_STRING SourceRootPath ,
2558
2585
PUNICODE_STRING DestinationArcPath ,
@@ -2563,7 +2590,7 @@ InstallExt2BootcodeToPartition(
2563
2590
WCHAR SrcPath [MAX_PATH ];
2564
2591
WCHAR DstPath [MAX_PATH ];
2565
2592
2566
- /* EXT2 partition */
2593
+ /* BTRFS partition */
2567
2594
DPRINT ("System path: '%wZ'\n" , SystemRootPath );
2568
2595
2569
2596
/* Copy FreeLoader to the system partition, always overwriting the older version */
@@ -2625,7 +2652,7 @@ InstallExt2BootcodeToPartition(
2625
2652
CombinePaths (DstPath , ARRAYSIZE (DstPath ), 2 , SystemRootPath -> Buffer , BootSector );
2626
2653
2627
2654
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 ));
2629
2656
if (!NT_SUCCESS (Status ))
2630
2657
{
2631
2658
DPRINT1 ("SaveBootSector() failed (Status %lx)\n" , Status );
@@ -2645,14 +2672,14 @@ InstallExt2BootcodeToPartition(
2645
2672
/* Install new bootsector on the disk */
2646
2673
// if (PartitionType == PARTITION_EXT2)
2647
2674
{
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" );
2650
2677
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 );
2653
2680
if (!NT_SUCCESS (Status ))
2654
2681
{
2655
- DPRINT1 ("InstallExt2BootCodeToDisk () failed (Status %lx)\n" , Status );
2682
+ DPRINT1 ("InstallBtrfsBootCodeToDisk () failed (Status %lx)\n" , Status );
2656
2683
return Status ;
2657
2684
}
2658
2685
}
@@ -2684,12 +2711,12 @@ InstallVBRToPartition(
2684
2711
PartitionType );
2685
2712
}
2686
2713
2687
- case PARTITION_EXT2 :
2714
+ case PARTITION_LINUX :
2688
2715
{
2689
- return InstallExt2BootcodeToPartition (SystemRootPath ,
2690
- SourceRootPath ,
2691
- DestinationArcPath ,
2692
- PartitionType );
2716
+ return InstallBtrfsBootcodeToPartition (SystemRootPath ,
2717
+ SourceRootPath ,
2718
+ DestinationArcPath ,
2719
+ PartitionType );
2693
2720
}
2694
2721
2695
2722
case PARTITION_IFS :
0 commit comments