X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDisk%2FPartitionDxe%2FMbr.c;h=a35b4f2d0de86a8ab43971dac032943121704ebf;hp=f89f3e190e68a39d0ea969fb031884db65cd2097;hb=493d8e3a5e86f78ef975e18dfa5754adce9e82de;hpb=c63cd426a8ed53070d32260a94d5d99bf0ec2c83 diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c index f89f3e190e..a35b4f2d0d 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c @@ -1,20 +1,4 @@ -/*++ - -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -Module Name: - - Mbr.c - -Abstract: - +/** @file Decode a hard disk partitioned with the legacy MBR found on most PC's MBR - Master Boot Record is in the first sector of a partitioned hard disk. @@ -22,35 +6,39 @@ Abstract: code that is not run on an EFI system. The legacy code reads the first sector of the active partition into memory and - BPB - Boot(?) Parameter Block is in the first sector of a FAT file system. + BPB - BIOS Parameter Block is in the first sector of a FAT file system. The BPB contains information about the FAT file system. The BPB is always on the first sector of a media. The first sector also contains the legacy boot strap code. ---*/ +Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ #include "Partition.h" -STATIC +/** + Test to see if the Mbr buffer is a valid MBR. + + @param Mbr Parent Handle. + @param LastLba Last Lba address on the device. + + @retval TRUE Mbr is a Valid MBR. + @retval FALSE Mbr is not a Valid MBR. + +**/ BOOLEAN PartitionValidMbr ( IN MASTER_BOOT_RECORD *Mbr, IN EFI_LBA LastLba ) -/*++ - -Routine Description: - Test to see if the Mbr buffer is a valid MBR - -Arguments: - Mbr - Parent Handle - LastLba - Last Lba address on the device. - -Returns: - TRUE - Mbr is a Valid MBR - FALSE - Mbr is not a Valid MBR - ---*/ { UINT32 StartingLBA; UINT32 EndingLBA; @@ -104,37 +92,38 @@ Returns: } } // - // Non of the regions overlapped so MBR is O.K. + // None of the regions overlapped so MBR is O.K. // return MbrValid; } + +/** + Install child handles if the Handle supports MBR format. + + @param[in] This Calling context. + @param[in] Handle Parent Handle. + @param[in] DiskIo Parent DiskIo interface. + @param[in] DiskIo2 Parent DiskIo2 interface. + @param[in] BlockIo Parent BlockIo interface. + @param[in] BlockIo2 Parent BlockIo2 interface. + @param[in] DevicePath Parent Device Path. + + @retval EFI_SUCCESS A child handle was added. + @retval EFI_MEDIA_CHANGED Media change was detected. + @retval Others MBR partition was not found. + +**/ EFI_STATUS PartitionInstallMbrChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN EFI_DISK_IO2_PROTOCOL *DiskIo2, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) -/*++ - -Routine Description: - Install child handles if the Handle supports MBR format. - -Arguments: - This - Calling context. - Handle - Parent Handle - DiskIo - Parent DiskIo interface - BlockIo - Parent BlockIo interface - DevicePath - Parent Device Path - -Returns: - EFI_SUCCESS - If a child handle was added - EFI_MEDIA_CHANGED - Media changed Detected - !EFI_SUCCESS - Not found MBR partition. - ---*/ { EFI_STATUS Status; MASTER_BOOT_RECORD *Mbr; @@ -146,27 +135,33 @@ Returns: UINT32 PartitionNumber; EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; + UINT32 BlockSize; + UINT32 MediaId; + EFI_LBA LastBlock; - Mbr = NULL; Found = EFI_NOT_FOUND; - Mbr = AllocatePool (BlockIo->Media->BlockSize); + BlockSize = BlockIo->Media->BlockSize; + MediaId = BlockIo->Media->MediaId; + LastBlock = BlockIo->Media->LastBlock; + + Mbr = AllocatePool (BlockSize); if (Mbr == NULL) { - goto Done; + return Found; } - Status = BlockIo->ReadBlocks ( - BlockIo, - BlockIo->Media->MediaId, - 0, - BlockIo->Media->BlockSize, - Mbr - ); + Status = DiskIo->ReadDisk ( + DiskIo, + MediaId, + 0, + BlockSize, + Mbr + ); if (EFI_ERROR (Status)) { Found = Status; goto Done; } - if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) { + if (!PartitionValidMbr (Mbr, LastBlock)) { goto Done; } // @@ -178,9 +173,9 @@ Returns: LastDevicePathNode = NULL; ZeroMem (&ParentHdDev, sizeof (ParentHdDev)); DevicePathNode = DevicePath; - while (!EfiIsDevicePathEnd (DevicePathNode)) { + while (!IsDevicePathEnd (DevicePathNode)) { LastDevicePathNode = DevicePathNode; - DevicePathNode = EfiNextDevicePathNode (DevicePathNode); + DevicePathNode = NextDevicePathNode (DevicePathNode); } if (LastDevicePathNode != NULL) { @@ -227,13 +222,15 @@ Returns: HdDev.PartitionNumber = PartitionNumber ++; HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[Index].StartingLBA); HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA); - CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (UINT32)); + CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (Mbr->UniqueMbrSignature)); Status = PartitionInstallChildHandle ( This, Handle, DiskIo, + DiskIo2, BlockIo, + BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, HdDev.PartitionStart, @@ -255,13 +252,13 @@ Returns: do { - Status = BlockIo->ReadBlocks ( - BlockIo, - BlockIo->Media->MediaId, - ExtMbrStartingLba, - BlockIo->Media->BlockSize, - Mbr - ); + Status = DiskIo->ReadDisk ( + DiskIo, + MediaId, + MultU64x32 (ExtMbrStartingLba, BlockSize), + BlockSize, + Mbr + ); if (EFI_ERROR (Status)) { Found = Status; goto Done; @@ -290,17 +287,19 @@ Returns: *((UINT32 *) &HdDev.Signature[0]) = 0; Status = PartitionInstallChildHandle ( - This, - Handle, - DiskIo, - BlockIo, - DevicePath, - (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, - HdDev.PartitionStart - ParentHdDev.PartitionStart, - HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1, - MBR_SIZE, - (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION) - ); + This, + Handle, + DiskIo, + DiskIo2, + BlockIo, + BlockIo2, + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, + HdDev.PartitionStart - ParentHdDev.PartitionStart, + HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1, + MBR_SIZE, + (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION) + ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; }