]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
Add DiskIo2 protocol definition to MdePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Mbr.c
index 68b389ae91cb2d1c8e63bafd9141ea944c5cbfd9..a35b4f2d0de86a8ab43971dac032943121704ebf 100644 (file)
@@ -6,13 +6,13 @@
         code that is not run on an EFI system. The legacy code reads the \r
         first sector of the active partition into memory and \r
 \r
-  BPB - Boot(?) Parameter Block is in the first sector of a FAT file system. \r
+  BPB - BIOS Parameter Block is in the first sector of a FAT file system. \r
         The BPB contains information about the FAT file system. The BPB is \r
         always on the first sector of a media. The first sector also contains\r
         the legacy boot strap code.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+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
 http://opensource.org/licenses/bsd-license.php\r
@@ -34,7 +34,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @retval FALSE       Mbr is not a Valid MBR.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 PartitionValidMbr (\r
   IN  MASTER_BOOT_RECORD      *Mbr,\r
@@ -102,11 +101,13 @@ PartitionValidMbr (
 /**\r
   Install child handles if the Handle supports MBR format.\r
 \r
-  @param  This              Calling context.\r
-  @param  Handle            Parent Handle.\r
-  @param  DiskIo            Parent DiskIo interface.\r
-  @param  BlockIo           Parent BlockIo interface.\r
-  @param  DevicePath        Parent Device Path.\r
+  @param[in]  This              Calling context.\r
+  @param[in]  Handle            Parent Handle.\r
+  @param[in]  DiskIo            Parent DiskIo interface.\r
+  @param[in]  DiskIo2           Parent DiskIo2 interface.\r
+  @param[in]  BlockIo           Parent BlockIo interface.\r
+  @param[in]  BlockIo2          Parent BlockIo2 interface.\r
+  @param[in]  DevicePath        Parent Device Path.\r
    \r
   @retval EFI_SUCCESS       A child handle was added.\r
   @retval EFI_MEDIA_CHANGED Media change was detected.\r
@@ -118,7 +119,9 @@ PartitionInstallMbrChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
   )\r
 {\r
@@ -132,27 +135,33 @@ PartitionInstallMbrChildHandles (
   UINT32                    PartitionNumber;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode;\r
   EFI_DEVICE_PATH_PROTOCOL  *LastDevicePathNode;\r
+  UINT32                    BlockSize;\r
+  UINT32                    MediaId;\r
+  EFI_LBA                   LastBlock;\r
 \r
-  Mbr             = NULL;\r
   Found           = EFI_NOT_FOUND;\r
 \r
-  Mbr             = AllocatePool (BlockIo->Media->BlockSize);\r
+  BlockSize = BlockIo->Media->BlockSize;\r
+  MediaId   = BlockIo->Media->MediaId;\r
+  LastBlock = BlockIo->Media->LastBlock;\r
+\r
+  Mbr = AllocatePool (BlockSize);\r
   if (Mbr == NULL) {\r
-    goto Done;\r
+    return Found;\r
   }\r
 \r
-  Status = BlockIo->ReadBlocks (\r
-                      BlockIo,\r
-                      BlockIo->Media->MediaId,\r
-                      0,\r
-                      BlockIo->Media->BlockSize,\r
-                      Mbr\r
-                      );\r
+  Status = DiskIo->ReadDisk (\r
+                     DiskIo,\r
+                     MediaId,\r
+                     0,\r
+                     BlockSize,\r
+                     Mbr\r
+                     );\r
   if (EFI_ERROR (Status)) {\r
     Found = Status;\r
     goto Done;\r
   }\r
-  if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
+  if (!PartitionValidMbr (Mbr, LastBlock)) {\r
     goto Done;\r
   }\r
   //\r
@@ -164,9 +173,9 @@ PartitionInstallMbrChildHandles (
   LastDevicePathNode = NULL;\r
   ZeroMem (&ParentHdDev, sizeof (ParentHdDev));\r
   DevicePathNode = DevicePath;\r
-  while (!EfiIsDevicePathEnd (DevicePathNode)) {\r
+  while (!IsDevicePathEnd (DevicePathNode)) {\r
     LastDevicePathNode  = DevicePathNode;\r
-    DevicePathNode      = EfiNextDevicePathNode (DevicePathNode);\r
+    DevicePathNode      = NextDevicePathNode (DevicePathNode);\r
   }\r
 \r
   if (LastDevicePathNode != NULL) {\r
@@ -213,13 +222,15 @@ PartitionInstallMbrChildHandles (
       HdDev.PartitionNumber = PartitionNumber ++;\r
       HdDev.PartitionStart  = UNPACK_UINT32 (Mbr->Partition[Index].StartingLBA);\r
       HdDev.PartitionSize   = UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA);\r
-      CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (UINT32));\r
+      CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (Mbr->UniqueMbrSignature));\r
 \r
       Status = PartitionInstallChildHandle (\r
                 This,\r
                 Handle,\r
                 DiskIo,\r
+                DiskIo2,\r
                 BlockIo,\r
+                BlockIo2,\r
                 DevicePath,\r
                 (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
                 HdDev.PartitionStart,\r
@@ -241,13 +252,13 @@ PartitionInstallMbrChildHandles (
 \r
     do {\r
 \r
-      Status = BlockIo->ReadBlocks (\r
-                          BlockIo,\r
-                          BlockIo->Media->MediaId,\r
-                          ExtMbrStartingLba,\r
-                          BlockIo->Media->BlockSize,\r
-                          Mbr\r
-                          );\r
+      Status = DiskIo->ReadDisk (\r
+                         DiskIo,\r
+                         MediaId,\r
+                         MultU64x32 (ExtMbrStartingLba, BlockSize),\r
+                         BlockSize,\r
+                         Mbr\r
+                         );\r
       if (EFI_ERROR (Status)) {\r
         Found = Status;\r
         goto Done;\r
@@ -276,17 +287,19 @@ PartitionInstallMbrChildHandles (
       *((UINT32 *) &HdDev.Signature[0]) = 0;\r
 \r
       Status = PartitionInstallChildHandle (\r
-                This,\r
-                Handle,\r
-                DiskIo,\r
-                BlockIo,\r
-                DevicePath,\r
-                (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
-                HdDev.PartitionStart - ParentHdDev.PartitionStart,\r
-                HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,\r
-                MBR_SIZE,\r
-                (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION)\r
-                );\r
+                 This,\r
+                 Handle,\r
+                 DiskIo,\r
+                 DiskIo2,\r
+                 BlockIo,\r
+                 BlockIo2,\r
+                 DevicePath,\r
+                 (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
+                 HdDev.PartitionStart - ParentHdDev.PartitionStart,\r
+                 HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,\r
+                 MBR_SIZE,\r
+                 (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION)\r
+                 );\r
       if (!EFI_ERROR (Status)) {\r
         Found = EFI_SUCCESS;\r
       }\r