- Add a new property to the disk entry: NoMbr flag. It's set, if MBR's first two...
authorAleksey Bragin <aleksey@reactos.org>
Fri, 10 Apr 2009 10:37:08 +0000 (10:37 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Fri, 10 Apr 2009 10:37:08 +0000 (10:37 +0000)
- If this flag is set for a boot disk, ReactOS MBR code will be installed on it.
See issue #4355 for more details.

svn path=/trunk/; revision=40437

reactos/base/setup/usetup/interface/usetup.c
reactos/base/setup/usetup/partlist.c
reactos/base/setup/usetup/partlist.h

index 87c0bc5..5574cee 100644 (file)
@@ -2380,6 +2380,28 @@ FormatPartitionPage (PINPUT_RECORD Ir)
                 CheckActiveBootPartition(PartitionList);
             }
 
+            /* Install MBR if necessary */
+            if (DiskEntry->NoMbr &&
+                DiskEntry->BiosDiskNumber == 0)
+            {
+                wcscpy(PathBuffer, SourceRootPath.Buffer);
+                wcscat(PathBuffer, L"\\loader\\dosmbr.bin");
+
+                DPRINT("Install MBR bootcode: %S ==> %S\n",
+                    PathBuffer, DestinationRootPath.Buffer);
+
+                /* Install MBR bootcode */
+                Status = InstallMbrBootCodeToDisk(PathBuffer, DestinationRootPath.Buffer);
+                if (!NT_SUCCESS (Status))
+                {
+                    DPRINT1("InstallMbrBootCodeToDisk() failed (Status %lx)\n",
+                        Status);
+                    return FALSE;
+                }
+
+                DiskEntry->NoMbr = FALSE;
+            }
+
             if (wcscmp(FileSystemList->Selected->FileSystem, L"FAT") == 0)
             {
                 /* FIXME: Install boot code. This is a hack! */
index f4b2c31..3528862 100644 (file)
@@ -775,10 +775,6 @@ AddDiskToList (HANDLE FileHandle,
   }
   Checksum = ~Checksum + 1;
 
-  RtlFreeHeap (ProcessHeap,
-               0,
-               Mbr);
-
   swprintf(Identifier, L"%08x-%08x-A", Checksum, Signature);
   DPRINT("Identifier: %S\n", Identifier);
 
@@ -799,6 +795,17 @@ AddDiskToList (HANDLE FileHandle,
   }
   DiskEntry->BiosFound = FALSE;
 
+  /* Check if this disk has a valid MBR */
+  if (Mbr->BootCode[0] == 0 && Mbr->BootCode[1] == 0)
+    DiskEntry->NoMbr = TRUE;
+  else
+    DiskEntry->NoMbr = FALSE;
+
+  /* Free Mbr sector buffer */
+  RtlFreeHeap (ProcessHeap,
+               0,
+               Mbr);
+
   ListEntry = List->BiosDiskListHead.Flink;
   while(ListEntry != &List->BiosDiskListHead)
   {
@@ -2672,6 +2679,7 @@ WritePartitionsToDisk (PPARTLIST List)
         }
 
         DiskEntry1->NewDisk = FALSE;
+        DiskEntry1->NoMbr = FALSE;
       }
     }
 
index 13b1458..a1a4826 100644 (file)
@@ -109,6 +109,7 @@ typedef struct _DISKENTRY
   BOOLEAN Modified;
 
   BOOLEAN NewDisk;
+  BOOLEAN NoMbr; /* MBR is absent */
 
   UNICODE_STRING DriverName;