]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/Disk/Partition/Dxe/Mbr.c
Fix a critical bug: When reading block succeeds but detecting MBR fails, it should...
[mirror_edk2.git] / EdkModulePkg / Universal / Disk / Partition / Dxe / Mbr.c
index 0930292a9c840714d457913cf5a9ab06e83d92da..d71698c82673dcb08641b05b5482c4c4eca4f755 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -30,8 +30,8 @@ Abstract:
 --*/\r
 \r
 #include "Partition.h"\r
-#include "Mbr.h"\r
 \r
+STATIC\r
 BOOLEAN\r
 PartitionValidMbr (\r
   IN  MASTER_BOOT_RECORD      *Mbr,\r
@@ -109,7 +109,7 @@ Returns:
   return MbrValid;\r
 }\r
 \r
-BOOLEAN\r
+EFI_STATUS\r
 PartitionInstallMbrChildHandles (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
@@ -130,8 +130,9 @@ Arguments:
   DevicePath - Parent Device Path\r
 \r
 Returns:\r
-  EFI_SUCCESS - If a child handle was added\r
-  other       - A child handle was not added\r
+  EFI_SUCCESS       - If a child handle was added\r
+  EFI_MEDIA_CHANGED - Media changed Detected\r
+       !EFI_SUCCESS      - Not found MBR partition.\r
 \r
 --*/\r
 {\r
@@ -141,13 +142,13 @@ Returns:
   UINTN                     Index;\r
   HARDDRIVE_DEVICE_PATH     HdDev;\r
   HARDDRIVE_DEVICE_PATH     ParentHdDev;\r
-  BOOLEAN                   Found;\r
+  EFI_STATUS                Found;\r
   UINT32                    PartitionNumber;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode;\r
   EFI_DEVICE_PATH_PROTOCOL  *LastDevicePathNode;\r
 \r
   Mbr             = NULL;\r
-  Found           = FALSE;\r
+  Found           = EFI_NOT_FOUND;\r
 \r
   Mbr             = AllocatePool (BlockIo->Media->BlockSize);\r
   if (Mbr == NULL) {\r
@@ -161,7 +162,11 @@ Returns:
                       BlockIo->Media->BlockSize,\r
                       Mbr\r
                       );\r
-  if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
+  if (EFI_ERROR (Status)) {\r
+    Found = Status;\r
+    goto Done;\r
+  }\r
+  if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
     goto Done;\r
   }\r
   //\r
@@ -182,7 +187,7 @@ Returns:
     if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH &&\r
         DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP\r
         ) {\r
-      gBS->CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));\r
+      CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));\r
     } else {\r
       LastDevicePathNode = NULL;\r
     }\r
@@ -238,7 +243,7 @@ Returns:
                 );\r
 \r
       if (!EFI_ERROR (Status)) {\r
-        Found = TRUE;\r
+        Found = EFI_SUCCESS;\r
       }\r
     }\r
   } else {\r
@@ -258,6 +263,7 @@ Returns:
                           Mbr\r
                           );\r
       if (EFI_ERROR (Status)) {\r
+        Found = Status;\r
         goto Done;\r
       }\r
 \r
@@ -273,8 +279,8 @@ Returns:
       HdDev.PartitionNumber = PartitionNumber ++;\r
       HdDev.PartitionStart  = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart;\r
       HdDev.PartitionSize   = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA);\r
-      if (HdDev.PartitionStart + HdDev.PartitionSize - 1 >=\r
-            ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) {\r
+      if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) ||\r
+          (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) {\r
         break;\r
       }\r
 \r
@@ -296,7 +302,7 @@ Returns:
                 (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION)\r
                 );\r
       if (!EFI_ERROR (Status)) {\r
-        Found = TRUE;\r
+        Found = EFI_SUCCESS;\r
       }\r
 \r
       if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) &&\r
@@ -316,7 +322,7 @@ Returns:
   }\r
 \r
 Done:\r
-  gBS->FreePool (Mbr);\r
+  FreePool (Mbr);\r
 \r
   return Found;\r
 }\r