/*++\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
--*/\r
\r
#include "Partition.h"\r
-#include "Mbr.h"\r
\r
+STATIC\r
BOOLEAN\r
PartitionValidMbr (\r
IN MASTER_BOOT_RECORD *Mbr,\r
return MbrValid;\r
}\r
\r
-BOOLEAN\r
+EFI_STATUS\r
PartitionInstallMbrChildHandles (\r
IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
IN EFI_HANDLE Handle,\r
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
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
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
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
continue;\r
}\r
\r
- if (Mbr->Partition[Index].OSIndicator == 0xEE) {\r
+ if (Mbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION) {\r
//\r
// This is the guard MBR for the GPT. If you ever see a GPT disk with zero partitions you can get here.\r
// We can not produce an MBR BlockIo for this device as the MBR spans the GPT headers. So formating \r
);\r
\r
if (!EFI_ERROR (Status)) {\r
- Found = TRUE;\r
+ Found = EFI_SUCCESS;\r
}\r
}\r
} else {\r
Mbr\r
);\r
if (EFI_ERROR (Status)) {\r
+ Found = Status;\r
goto Done;\r
}\r
\r
break;\r
}\r
\r
+ if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) ||\r
+ (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) {\r
+ ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA);\r
+ continue;\r
+ }\r
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
(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
- Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION\r
+ if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) &&\r
+ (Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION)\r
) {\r
break;\r
}\r
}\r
\r
Done:\r
- gBS->FreePool (Mbr);\r
+ FreePool (Mbr);\r
\r
return Found;\r
}\r