[TCPSVCS] Remove hardcoded C drive letter (#800)
[reactos.git] / base / setup / usetup / bootsup.c
index 75319fb..37cd680 100644 (file)
@@ -3,7 +3,7 @@
  * PROJECT:         ReactOS text-mode setup
  * FILE:            base/setup/usetup/bootsup.c
  * PURPOSE:         Bootloader support functions
- * PROGRAMMER:      Eric Kohl
+ * PROGRAMMER:
  */
 
 #include "usetup.h"
@@ -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!
 
@@ -435,13 +439,13 @@ CreateFreeLoaderIniForReactOS(
 static
 NTSTATUS
 CreateFreeLoaderIniForReactOSAndBootSector(
-    PWCHAR IniPath,
-    PWCHAR ArcPath,
-    PWCHAR Section,
-    PWCHAR Description,
-    PWCHAR BootDrive,
-    PWCHAR BootPartition,
-    PWCHAR BootSector)
+    IN PCWSTR IniPath,
+    IN PCWSTR ArcPath,
+    IN PCWSTR Section,
+    IN PCWSTR Description,
+    IN PCWSTR BootDrive,
+    IN PCWSTR BootPartition,
+    IN PCWSTR BootSector)
 {
     PINICACHE IniCache;
     PINICACHESECTION IniSection;
@@ -453,7 +457,7 @@ CreateFreeLoaderIniForReactOSAndBootSector(
     CreateCommonFreeLoaderSections(IniCache);
 
     /* Add the ReactOS entries */
-    CreateFreeLoaderReactOSEntries(IniCache, ArcPath);
+    CreateFreeLoaderReactOSEntries(IniCache, (PWCHAR)ArcPath);
 
     /* Get "Operating Systems" section */
     IniSection = IniCacheGetSection(IniCache, L"Operating Systems");
@@ -462,11 +466,11 @@ CreateFreeLoaderIniForReactOSAndBootSector(
     IniCacheInsertKey(IniSection,
                       NULL,
                       INSERT_LAST,
-                      Section,
-                      Description);
+                      (PWCHAR)Section,
+                      (PWCHAR)Description);
 
     /* Create new section */
-    IniSection = IniCacheAppendSection(IniCache, Section);
+    IniSection = IniCacheAppendSection(IniCache, (PWCHAR)Section);
 
     /* BootType=BootSector */
     IniCacheInsertKey(IniSection,
@@ -480,24 +484,24 @@ CreateFreeLoaderIniForReactOSAndBootSector(
                       NULL,
                       INSERT_LAST,
                       L"BootDrive",
-                      BootDrive);
+                      (PWCHAR)BootDrive);
 
     /* BootPartition= */
     IniCacheInsertKey(IniSection,
                       NULL,
                       INSERT_LAST,
                       L"BootPartition",
-                      BootPartition);
+                      (PWCHAR)BootPartition);
 
     /* BootSector= */
     IniCacheInsertKey(IniSection,
                       NULL,
                       INSERT_LAST,
                       L"BootSectorFile",
-                      BootSector);
+                      (PWCHAR)BootSector);
 
     /* Save the INI file */
-    IniCacheSave(IniCache, IniPath);
+    IniCacheSave(IniCache, (PWCHAR)IniPath);
     IniCacheDestroy(IniCache);
 
     return STATUS_SUCCESS;
@@ -1269,7 +1273,10 @@ InstallMbrBootCodeToDisk(
         return Status;
     }
 
-    /* Copy partition table from old MBR to new */
+    /*
+     * Copy the disk signature, the reserved fields and
+     * the partition table from the old MBR to the new one.
+     */
     RtlCopyMemory(&NewBootSector->Signature,
                   &OrigBootSector->Signature,
                   sizeof(PARTITION_SECTOR) - offsetof(PARTITION_SECTOR, Signature) /* Length of partition table */);
@@ -1834,7 +1841,7 @@ InstallFat32BootCodeToDisk(
 
 static
 NTSTATUS
-InstallExt2BootCodeToDisk(
+InstallBtrfsBootCodeToDisk(
     PWSTR SrcPath,
     PWSTR RootPath)
 {
@@ -1845,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 */
@@ -1894,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);
@@ -1929,7 +1937,7 @@ InstallExt2BootCodeToDisk(
                         NULL,
                         &IoStatusBlock,
                         NewBootSector,
-                        sizeof(EXT2_BOOTSECTOR),
+                        sizeof(BTRFS_BOOTSECTOR),
                         NULL,
                         NULL);
     NtClose(FileHandle);
@@ -1978,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,
@@ -1986,7 +2016,7 @@ InstallExt2BootCodeToDisk(
                          NULL,
                          &IoStatusBlock,
                          NewBootSector,
-                         sizeof(EXT2_BOOTSECTOR),
+                         sizeof(BTRFS_BOOTSECTOR),
                          &FileOffset,
                          NULL);
 #if 0
@@ -2257,11 +2287,9 @@ InstallFatBootcodeToPartition(
     /* FAT or FAT32 partition */
     DPRINT("System path: '%wZ'\n", SystemRootPath);
 
-    /* Copy FreeLoader to the system partition */
-    wcscpy(SrcPath, SourceRootPath->Buffer);
-    wcscat(SrcPath, L"\\loader\\freeldr.sys");
-    wcscpy(DstPath, SystemRootPath->Buffer);
-    wcscat(DstPath, L"\\freeldr.sys");
+    /* Copy FreeLoader to the system partition, always overwriting the older version */
+    CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
 
     DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
     Status = SetupCopyFile(SrcPath, DstPath);
@@ -2271,11 +2299,10 @@ InstallFatBootcodeToPartition(
         return Status;
     }
 
-    /* Prepare for possibly copying 'freeldr.ini' */
-    wcscpy(DstPath, SystemRootPath->Buffer);
-    wcscat(DstPath, L"\\freeldr.ini");
+    /* Prepare for possibly updating 'freeldr.ini' */
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.ini");
 
-    DoesFreeLdrExist = DoesFileExist(SystemRootPath->Buffer, L"freeldr.ini");
+    DoesFreeLdrExist = DoesFileExist(NULL, DstPath);
     if (DoesFreeLdrExist)
     {
         /* Update existing 'freeldr.ini' */
@@ -2292,10 +2319,12 @@ InstallFatBootcodeToPartition(
     /* Check for NT and other bootloaders */
 
     // FIXME: Check for Vista+ bootloader!
-    if (DoesFileExist(SystemRootPath->Buffer, L"ntldr") == TRUE ||
-        DoesFileExist(SystemRootPath->Buffer, L"boot.ini") == TRUE)
+    /*** Status = FindNTOSBootLoader(PartitionHandle, NtLdr, &Version); ***/
+    /*** Status = FindNTOSBootLoader(PartitionHandle, BootMgr, &Version); ***/
+    if (DoesFileExist_2(SystemRootPath->Buffer, L"NTLDR") == TRUE ||
+        DoesFileExist_2(SystemRootPath->Buffer, L"BOOT.INI") == TRUE)
     {
-        /* Search root directory for 'ntldr' and 'boot.ini' */
+        /* Search root directory for 'NTLDR' and 'BOOT.INI' */
         DPRINT1("Found Microsoft Windows NT/2000/XP boot loader\n");
 
         /* Create or update 'freeldr.ini' */
@@ -2303,8 +2332,7 @@ InstallFatBootcodeToPartition(
         {
             /* Create new 'freeldr.ini' */
             DPRINT1("Create new 'freeldr.ini'\n");
-            // wcscpy(DstPath, SystemRootPath->Buffer);
-            // wcscat(DstPath, L"\\freeldr.ini");
+            // CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.ini");
 
             Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer);
             if (!NT_SUCCESS(Status))
@@ -2314,15 +2342,13 @@ InstallFatBootcodeToPartition(
             }
 
             /* Install new bootcode into a file */
-            wcscpy(DstPath, SystemRootPath->Buffer);
-            wcscat(DstPath, L"\\bootsect.ros");
+            CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"bootsect.ros");
 
             if (PartitionType == PARTITION_FAT32 ||
                 PartitionType == PARTITION_FAT32_XINT13)
             {
                 /* Install FAT32 bootcode */
-                wcscpy(SrcPath, SourceRootPath->Buffer);
-                wcscat(SrcPath, L"\\loader\\fat32.bin");
+                CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat32.bin");
 
                 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, DstPath);
                 Status = InstallFat32BootCodeToFile(SrcPath, DstPath,
@@ -2336,8 +2362,7 @@ InstallFatBootcodeToPartition(
             else
             {
                 /* Install FAT16 bootcode */
-                wcscpy(SrcPath, SourceRootPath->Buffer);
-                wcscat(SrcPath, L"\\loader\\fat.bin");
+                CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
 
                 DPRINT1("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath);
                 Status = InstallFat16BootCodeToFile(SrcPath, DstPath,
@@ -2351,9 +2376,10 @@ InstallFatBootcodeToPartition(
         }
 
         /* Update 'boot.ini' */
-        wcscpy(DstPath, SystemRootPath->Buffer);
-        wcscat(DstPath, L"\\boot.ini");
+        CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"boot.ini");
 
+        /* Windows' NTLDR loads an external bootsector file when the specified drive
+           letter is C:, otherwise it will interpret it as a boot DOS path specifier. */
         DPRINT1("Update 'boot.ini': %S\n", DstPath);
         Status = UpdateBootIni(DstPath,
                                L"C:\\bootsect.ros",
@@ -2368,31 +2394,97 @@ InstallFatBootcodeToPartition(
     {
         /* Non-NT bootloaders: install our own bootloader */
 
-        PWCHAR Section;
-        PWCHAR Description;
-        PWCHAR BootDrive;
-        PWCHAR BootPartition;
-        PWCHAR BootSector;
-        PWCHAR BootSectorFileName;
+        PCWSTR Section;
+        PCWSTR Description;
+        PCWSTR BootDrive;
+        PCWSTR BootPartition;
+        PCWSTR BootSector;
+
+        /* Search for COMPAQ MS-DOS 1.x (1.11, 1.12, based on MS-DOS 1.25) boot loader */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"IOSYS.COM") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"MSDOS.COM") == TRUE)
+        {
+            DPRINT1("Found COMPAQ MS-DOS 1.x (1.11, 1.12) / MS-DOS 1.25 boot loader\n");
 
-        if (DoesFileExist(SystemRootPath->Buffer, L"io.sys") == TRUE ||
-            DoesFileExist(SystemRootPath->Buffer, L"msdos.sys") == TRUE)
+            Section       = L"DOS";
+            Description   = L"\"COMPAQ MS-DOS 1.x / MS-DOS 1.25\"";
+            BootDrive     = L"hd0";
+            BootPartition = L"1";
+            BootSector    = L"BOOTSECT.DOS";
+        }
+        else
+        /* Search for Microsoft DOS or Windows 9x boot loader */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"IO.SYS") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"MSDOS.SYS") == TRUE)
+            // WINBOOT.SYS
         {
-            /* Search for root directory for 'io.sys' and 'msdos.sys' */
             DPRINT1("Found Microsoft DOS or Windows 9x boot loader\n");
 
             Section       = L"DOS";
-            Description   = L"\"DOS/Windows\"";
+            Description   = L"\"MS-DOS/Windows\"";
             BootDrive     = L"hd0";
             BootPartition = L"1";
             BootSector    = L"BOOTSECT.DOS";
+        }
+        else
+        /* Search for IBM PC-DOS or DR-DOS 5.x boot loader */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"IBMIO.COM" ) == TRUE || // Some people refer to this file instead of IBMBIO.COM...
+            DoesFileExist_2(SystemRootPath->Buffer, L"IBMBIO.COM") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"IBMDOS.COM") == TRUE)
+        {
+            DPRINT1("Found IBM PC-DOS or DR-DOS 5.x or IBM OS/2 1.0\n");
 
-            BootSectorFileName = L"\\bootsect.dos";
+            Section       = L"DOS";
+            Description   = L"\"IBM PC-DOS or DR-DOS 5.x or IBM OS/2 1.0\"";
+            BootDrive     = L"hd0";
+            BootPartition = L"1";
+            BootSector    = L"BOOTSECT.DOS";
         }
         else
-        if (DoesFileExist(SystemRootPath->Buffer, L"kernel.sys") == TRUE)
+        /* Search for DR-DOS 3.x boot loader */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"DRBIOS.SYS") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"DRBDOS.SYS") == TRUE)
+        {
+            DPRINT1("Found DR-DOS 3.x\n");
+
+            Section       = L"DOS";
+            Description   = L"\"DR-DOS 3.x\"";
+            BootDrive     = L"hd0";
+            BootPartition = L"1";
+            BootSector    = L"BOOTSECT.DOS";
+        }
+        else
+        /* Search for MS OS/2 1.x */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"OS2BOOT.COM") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"OS2BIO.COM" ) == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"OS2DOS.COM" ) == TRUE)
+        {
+            DPRINT1("Found MS OS/2 1.x\n");
+
+            Section       = L"DOS";
+            Description   = L"\"MS OS/2 1.x\"";
+            BootDrive     = L"hd0";
+            BootPartition = L"1";
+            BootSector    = L"BOOTSECT.OS2";
+        }
+        else
+        /* Search for MS or IBM OS/2 */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"OS2BOOT") == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"OS2LDR" ) == TRUE ||
+            DoesFileExist_2(SystemRootPath->Buffer, L"OS2KRNL") == TRUE)
+        {
+            DPRINT1("Found MS/IBM OS/2\n");
+
+            Section       = L"DOS";
+            Description   = L"\"MS/IBM OS/2\"";
+            BootDrive     = L"hd0";
+            BootPartition = L"1";
+            BootSector    = L"BOOTSECT.OS2";
+        }
+        else
+        /* Search for FreeDOS boot loader */
+        if (DoesFileExist_2(SystemRootPath->Buffer, L"kernel.sys") == TRUE)
         {
-            /* Search for root directory for 'kernel.sys' */
             DPRINT1("Found FreeDOS boot loader\n");
 
             Section       = L"DOS";
@@ -2400,8 +2492,6 @@ InstallFatBootcodeToPartition(
             BootDrive     = L"hd0";
             BootPartition = L"1";
             BootSector    = L"BOOTSECT.DOS";
-
-            BootSectorFileName = L"\\bootsect.dos";
         }
         else
         {
@@ -2413,8 +2503,6 @@ InstallFatBootcodeToPartition(
             BootDrive     = L"hd0";
             BootPartition = L"1";
             BootSector    = L"BOOTSECT.OLD";
-
-            BootSectorFileName = L"\\bootsect.old";
         }
 
         /* Create or update 'freeldr.ini' */
@@ -2422,8 +2510,7 @@ InstallFatBootcodeToPartition(
         {
             /* Create new 'freeldr.ini' */
             DPRINT1("Create new 'freeldr.ini'\n");
-            // wcscpy(DstPath, SystemRootPath->Buffer);
-            // wcscat(DstPath, L"\\freeldr.ini");
+            // CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.ini");
 
             if (IsThereAValidBootSector(SystemRootPath->Buffer))
             {
@@ -2438,8 +2525,7 @@ InstallFatBootcodeToPartition(
                 }
 
                 /* Save current bootsector */
-                wcscpy(DstPath, SystemRootPath->Buffer);
-                wcscat(DstPath, BootSectorFileName);
+                CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, BootSector);
 
                 DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath);
                 Status = SaveBootSector(SystemRootPath->Buffer, DstPath, SECTORSIZE);
@@ -2464,8 +2550,7 @@ InstallFatBootcodeToPartition(
                 PartitionType == PARTITION_FAT32_XINT13)
             {
                 /* Install FAT32 bootcode */
-                wcscpy(SrcPath, SourceRootPath->Buffer);
-                wcscat(SrcPath, L"\\loader\\fat32.bin");
+                CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat32.bin");
 
                 DPRINT1("Install FAT32 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
                 Status = InstallFat32BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
@@ -2478,8 +2563,7 @@ InstallFatBootcodeToPartition(
             else
             {
                 /* Install FAT16 bootcode */
-                wcscpy(SrcPath, SourceRootPath->Buffer);
-                wcscat(SrcPath, L"\\loader\\fat.bin");
+                CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
 
                 DPRINT1("Install FAT16 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
                 Status = InstallFat16BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
@@ -2497,7 +2581,7 @@ InstallFatBootcodeToPartition(
 
 static
 NTSTATUS
-InstallExt2BootcodeToPartition(
+InstallBtrfsBootcodeToPartition(
     PUNICODE_STRING SystemRootPath,
     PUNICODE_STRING SourceRootPath,
     PUNICODE_STRING DestinationArcPath,
@@ -2508,14 +2592,12 @@ 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 */
-    wcscpy(SrcPath, SourceRootPath->Buffer);
-    wcscat(SrcPath, L"\\loader\\freeldr.sys");
-    wcscpy(DstPath, SystemRootPath->Buffer);
-    wcscat(DstPath, L"\\freeldr.sys");
+    /* Copy FreeLoader to the system partition, always overwriting the older version */
+    CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");
 
     DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
     Status = SetupCopyFile(SrcPath, DstPath);
@@ -2526,10 +2608,9 @@ InstallExt2BootcodeToPartition(
     }
 
     /* Prepare for possibly copying 'freeldr.ini' */
-    wcscpy(DstPath, SystemRootPath->Buffer);
-    wcscat(DstPath, L"\\freeldr.ini");
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.ini");
 
-    DoesFreeLdrExist = DoesFileExist(SystemRootPath->Buffer, L"freeldr.ini");
+    DoesFreeLdrExist = DoesFileExist(NULL, DstPath);
     if (DoesFreeLdrExist)
     {
         /* Update existing 'freeldr.ini' */
@@ -2550,18 +2631,19 @@ InstallExt2BootcodeToPartition(
     {
         /* Create new 'freeldr.ini' */
         DPRINT1("Create new 'freeldr.ini'\n");
-        wcscpy(DstPath, SystemRootPath->Buffer);
-        wcscat(DstPath, L"\\freeldr.ini");
+        CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"\\freeldr.ini");
 
         /* Certainly SysLinux, GRUB, LILO... or an unknown boot loader */
         DPRINT1("*nix or unknown boot loader found\n");
 
         if (IsThereAValidBootSector(SystemRootPath->Buffer))
         {
+            PCWSTR BootSector = L"BOOTSECT.OLD";
+
             Status = CreateFreeLoaderIniForReactOSAndBootSector(
                          DstPath, DestinationArcPath->Buffer,
                          L"Linux", L"\"Linux\"",
-                         L"hd0", L"1", L"BOOTSECT.OLD");
+                         L"hd0", L"1", BootSector);
             if (!NT_SUCCESS(Status))
             {
                 DPRINT1("CreateFreeLoaderIniForReactOSAndBootSector() failed (Status %lx)\n", Status);
@@ -2569,11 +2651,10 @@ InstallExt2BootcodeToPartition(
             }
 
             /* Save current bootsector */
-            wcscpy(DstPath, SystemRootPath->Buffer);
-            wcscat(DstPath, L"\\bootsect.old");
+            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);
@@ -2593,15 +2674,14 @@ InstallExt2BootcodeToPartition(
         /* Install new bootsector on the disk */
         // if (PartitionType == PARTITION_EXT2)
         {
-            /* Install EXT2 bootcode */
-            wcscpy(SrcPath, SourceRootPath->Buffer);
-            wcscat(SrcPath, 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;
             }
         }
@@ -2633,15 +2713,16 @@ InstallVBRToPartition(
                                                  PartitionType);
         }
 
-        case PARTITION_EXT2:
+        case PARTITION_LINUX:
         {
-            return InstallExt2BootcodeToPartition(SystemRootPath,
-                                                  SourceRootPath,
-                                                  DestinationArcPath,
-                                                  PartitionType);
+            return InstallBtrfsBootcodeToPartition(SystemRootPath,
+                                                   SourceRootPath,
+                                                   DestinationArcPath,
+                                                   PartitionType);
         }
 
         case PARTITION_IFS:
+            DPRINT1("Partitions of type NTFS or HPFS are not supported yet!\n");
             break;
 
         default:
@@ -2659,17 +2740,24 @@ InstallFatBootcodeToFloppy(
     PUNICODE_STRING DestinationArcPath)
 {
     NTSTATUS Status;
-    UNICODE_STRING FloppyDevice = RTL_CONSTANT_STRING(L"\\Device\\Floppy0");
+    PFILE_SYSTEM FatFS;
+    UNICODE_STRING FloppyDevice = RTL_CONSTANT_STRING(L"\\Device\\Floppy0\\");
     WCHAR SrcPath[MAX_PATH];
     WCHAR DstPath[MAX_PATH];
 
     /* Format the floppy first */
-    Status = VfatFormat(&FloppyDevice,
-                        FMIFS_FLOPPY,
-                        NULL,
-                        TRUE,
-                        0,
-                        NULL);
+    FatFS = GetFileSystemByName(L"FAT");
+    if (!FatFS)
+    {
+        DPRINT1("FAT FS non existent on this system?!\n");
+        return STATUS_NOT_SUPPORTED;
+    }
+    Status = FatFS->FormatFunc(&FloppyDevice,
+                               FMIFS_FLOPPY,
+                               NULL,
+                               TRUE,
+                               0,
+                               NULL);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("VfatFormat() failed (Status %lx)\n", Status);
@@ -2677,10 +2765,8 @@ InstallFatBootcodeToFloppy(
     }
 
     /* Copy FreeLoader to the boot partition */
-    wcscpy(SrcPath, SourceRootPath->Buffer);
-    wcscat(SrcPath, L"\\loader\\freeldr.sys");
-
-    wcscpy(DstPath, L"\\Device\\Floppy0\\freeldr.sys");
+    CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, FloppyDevice.Buffer, L"freeldr.sys");
 
     DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
     Status = SetupCopyFile(SrcPath, DstPath);
@@ -2691,7 +2777,7 @@ InstallFatBootcodeToFloppy(
     }
 
     /* Create new 'freeldr.ini' */
-    wcscpy(DstPath, L"\\Device\\Floppy0\\freeldr.ini");
+    CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, FloppyDevice.Buffer, L"freeldr.ini");
 
     DPRINT("Create new 'freeldr.ini'\n");
     Status = CreateFreeLoaderIniForReactOS(DstPath, DestinationArcPath->Buffer);
@@ -2701,17 +2787,15 @@ InstallFatBootcodeToFloppy(
         return Status;
     }
 
-    /* Install FAT12/16 boosector */
-    wcscpy(SrcPath, SourceRootPath->Buffer);
-    wcscat(SrcPath, L"\\loader\\fat.bin");
-
-    wcscpy(DstPath, L"\\Device\\Floppy0");
+    /* Install FAT12 boosector */
+    CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\fat.bin");
+    RtlStringCchCopyW(DstPath, ARRAYSIZE(DstPath), FloppyDevice.Buffer);
 
     DPRINT("Install FAT bootcode: %S ==> %S\n", SrcPath, DstPath);
     Status = InstallFat12BootCodeToFloppy(SrcPath, DstPath);
     if (!NT_SUCCESS(Status))
     {
-        DPRINT1("InstallFat16BootCodeToDisk() failed (Status %lx)\n", Status);
+        DPRINT1("InstallFat12BootCodeToFloppy() failed (Status %lx)\n", Status);
         return Status;
     }