\r
#include "Partition.h"\r
\r
-#define MAX_CORRECTION_BLOCKS_NUM 512u\r
+#define MAX_CORRECTION_BLOCKS_NUM 512u\r
\r
//\r
// C5BD4D42-1A76-4996-8956-73CDA326CD0A\r
}\r
\r
typedef struct {\r
- VENDOR_DEVICE_PATH DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL End;\r
+ VENDOR_DEVICE_PATH DevicePath;\r
+ EFI_DEVICE_PATH_PROTOCOL End;\r
} UDF_DEVICE_PATH;\r
\r
//\r
// Vendor-Defined Device Path GUID for UDF file system\r
//\r
-EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;\r
+EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;\r
\r
//\r
// Vendor-Defined Media Device Path for UDF file system\r
//\r
-UDF_DEVICE_PATH gUdfDevicePath = {\r
- { { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,\r
- { sizeof (VENDOR_DEVICE_PATH), 0 } },\r
+UDF_DEVICE_PATH gUdfDevicePath = {\r
+ {\r
+ { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,\r
+ { sizeof (VENDOR_DEVICE_PATH), 0 }\r
+ },\r
EFI_UDF_DEVICE_PATH_GUID\r
},\r
- { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
- { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
+ { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+ { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }\r
}\r
};\r
\r
// That said, we define a magic number of 512 blocks to be used as correction\r
// when attempting to find AVDP and define last block number.\r
//\r
- BlockSize = BlockIo->Media->BlockSize;\r
- EndLBA = BlockIo->Media->LastBlock;\r
+ BlockSize = BlockIo->Media->BlockSize;\r
+ EndLBA = BlockIo->Media->LastBlock;\r
*LastRecordedBlock = EndLBA;\r
- AvdpsCount = 0;\r
+ AvdpsCount = 0;\r
\r
//\r
// Check if the block size of the underlying media can hold the data of an\r
// Find AVDP at block 256\r
//\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- MultU64x32 (256, BlockSize),\r
- sizeof (*AnchorPoint),\r
- AnchorPoint\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ MultU64x32 (256, BlockSize),\r
+ sizeof (*AnchorPoint),\r
+ AnchorPoint\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
// Find AVDP at block N - 256\r
//\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- MultU64x32 ((UINT64)EndLBA - 256, BlockSize),\r
- sizeof (*AnchorPoint),\r
- AnchorPoint\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ MultU64x32 ((UINT64)EndLBA - 256, BlockSize),\r
+ sizeof (*AnchorPoint),\r
+ AnchorPoint\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
//\r
// Check if read block is a valid AVDP descriptor\r
//\r
- if (DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer &&\r
- ++AvdpsCount == 2) {\r
- DEBUG ((DEBUG_INFO, "%a: found AVDP at block %Ld\n", __FUNCTION__,\r
- EndLBA - 256));\r
+ if ((DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer) &&\r
+ (++AvdpsCount == 2))\r
+ {\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a: found AVDP at block %Ld\n",\r
+ __FUNCTION__,\r
+ EndLBA - 256\r
+ ));\r
return EFI_SUCCESS;\r
}\r
\r
// Find AVDP at block N\r
//\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- MultU64x32 ((UINT64)EndLBA, BlockSize),\r
- sizeof (*AnchorPoint),\r
- AnchorPoint\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ MultU64x32 ((UINT64)EndLBA, BlockSize),\r
+ sizeof (*AnchorPoint),\r
+ AnchorPoint\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
// Read consecutive MAX_CORRECTION_BLOCKS_NUM disk blocks\r
//\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- MultU64x32 ((UINT64)EndLBA - MAX_CORRECTION_BLOCKS_NUM, BlockSize),\r
- Size,\r
- AnchorPoints\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ MultU64x32 ((UINT64)EndLBA - MAX_CORRECTION_BLOCKS_NUM, BlockSize),\r
+ Size,\r
+ AnchorPoints\r
+ );\r
if (EFI_ERROR (Status)) {\r
goto Out_Free;\r
}\r
// Calculate last recorded block number\r
//\r
LastAvdpBlockNum = EndLBA - (MAX_CORRECTION_BLOCKS_NUM - Index);\r
- DEBUG ((DEBUG_WARN, "%a: found AVDP at block %Ld\n", __FUNCTION__,\r
- LastAvdpBlockNum));\r
- DEBUG ((DEBUG_WARN, "%a: correcting last block from %Ld to %Ld\n",\r
- __FUNCTION__, EndLBA, LastAvdpBlockNum));\r
+ DEBUG ((\r
+ DEBUG_WARN,\r
+ "%a: found AVDP at block %Ld\n",\r
+ __FUNCTION__,\r
+ LastAvdpBlockNum\r
+ ));\r
+ DEBUG ((\r
+ DEBUG_WARN,\r
+ "%a: correcting last block from %Ld to %Ld\n",\r
+ __FUNCTION__,\r
+ EndLBA,\r
+ LastAvdpBlockNum\r
+ ));\r
//\r
// Save read AVDP from last block\r
//\r
// Set last recorded block number\r
//\r
*LastRecordedBlock = LastAvdpBlockNum;\r
- Status = EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
break;\r
}\r
}\r
IN EFI_DISK_IO_PROTOCOL *DiskIo\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT64 Offset;\r
- UINT64 EndDiskOffset;\r
- CDROM_VOLUME_DESCRIPTOR VolDescriptor;\r
- CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor;\r
+ EFI_STATUS Status;\r
+ UINT64 Offset;\r
+ UINT64 EndDiskOffset;\r
+ CDROM_VOLUME_DESCRIPTOR VolDescriptor;\r
+ CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor;\r
\r
ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof (CDROM_VOLUME_DESCRIPTOR));\r
\r
//\r
// Start Volume Recognition Sequence\r
//\r
- EndDiskOffset = MultU64x32 (BlockIo->Media->LastBlock,\r
- BlockIo->Media->BlockSize);\r
+ EndDiskOffset = MultU64x32 (\r
+ BlockIo->Media->LastBlock,\r
+ BlockIo->Media->BlockSize\r
+ );\r
\r
for (Offset = UDF_VRS_START_OFFSET; Offset < EndDiskOffset;\r
- Offset += UDF_LOGICAL_SECTOR_SIZE) {\r
+ Offset += UDF_LOGICAL_SECTOR_SIZE)\r
+ {\r
//\r
// Check if block device has a Volume Structure Descriptor and an Extended\r
// Area.\r
//\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- Offset,\r
- sizeof (CDROM_VOLUME_DESCRIPTOR),\r
- (VOID *)&VolDescriptor\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ Offset,\r
+ sizeof (CDROM_VOLUME_DESCRIPTOR),\r
+ (VOID *)&VolDescriptor\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
- if (CompareMem ((VOID *)VolDescriptor.Unknown.Id,\r
- (VOID *)UDF_BEA_IDENTIFIER,\r
- sizeof (VolDescriptor.Unknown.Id)) == 0) {\r
+ if (CompareMem (\r
+ (VOID *)VolDescriptor.Unknown.Id,\r
+ (VOID *)UDF_BEA_IDENTIFIER,\r
+ sizeof (VolDescriptor.Unknown.Id)\r
+ ) == 0)\r
+ {\r
break;\r
}\r
\r
- if ((CompareMem ((VOID *)VolDescriptor.Unknown.Id,\r
- (VOID *)CDVOL_ID,\r
- sizeof (VolDescriptor.Unknown.Id)) != 0) ||\r
- (CompareMem ((VOID *)&VolDescriptor,\r
- (VOID *)&TerminatingVolDescriptor,\r
- sizeof (CDROM_VOLUME_DESCRIPTOR)) == 0)) {\r
+ if ((CompareMem (\r
+ (VOID *)VolDescriptor.Unknown.Id,\r
+ (VOID *)CDVOL_ID,\r
+ sizeof (VolDescriptor.Unknown.Id)\r
+ ) != 0) ||\r
+ (CompareMem (\r
+ (VOID *)&VolDescriptor,\r
+ (VOID *)&TerminatingVolDescriptor,\r
+ sizeof (CDROM_VOLUME_DESCRIPTOR)\r
+ ) == 0))\r
+ {\r
return EFI_NOT_FOUND;\r
}\r
}\r
}\r
\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- Offset,\r
- sizeof (CDROM_VOLUME_DESCRIPTOR),\r
- (VOID *)&VolDescriptor\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ Offset,\r
+ sizeof (CDROM_VOLUME_DESCRIPTOR),\r
+ (VOID *)&VolDescriptor\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
- if ((CompareMem ((VOID *)VolDescriptor.Unknown.Id,\r
- (VOID *)UDF_NSR2_IDENTIFIER,\r
- sizeof (VolDescriptor.Unknown.Id)) != 0) &&\r
- (CompareMem ((VOID *)VolDescriptor.Unknown.Id,\r
- (VOID *)UDF_NSR3_IDENTIFIER,\r
- sizeof (VolDescriptor.Unknown.Id)) != 0)) {\r
+ if ((CompareMem (\r
+ (VOID *)VolDescriptor.Unknown.Id,\r
+ (VOID *)UDF_NSR2_IDENTIFIER,\r
+ sizeof (VolDescriptor.Unknown.Id)\r
+ ) != 0) &&\r
+ (CompareMem (\r
+ (VOID *)VolDescriptor.Unknown.Id,\r
+ (VOID *)UDF_NSR3_IDENTIFIER,\r
+ sizeof (VolDescriptor.Unknown.Id)\r
+ ) != 0))\r
+ {\r
return EFI_NOT_FOUND;\r
}\r
\r
}\r
\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- Offset,\r
- sizeof (CDROM_VOLUME_DESCRIPTOR),\r
- (VOID *)&VolDescriptor\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ Offset,\r
+ sizeof (CDROM_VOLUME_DESCRIPTOR),\r
+ (VOID *)&VolDescriptor\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
- if (CompareMem ((VOID *)VolDescriptor.Unknown.Id,\r
- (VOID *)UDF_TEA_IDENTIFIER,\r
- sizeof (VolDescriptor.Unknown.Id)) != 0) {\r
+ if (CompareMem (\r
+ (VOID *)VolDescriptor.Unknown.Id,\r
+ (VOID *)UDF_TEA_IDENTIFIER,\r
+ sizeof (VolDescriptor.Unknown.Id)\r
+ ) != 0)\r
+ {\r
return EFI_NOT_FOUND;\r
}\r
\r
**/\r
BOOLEAN\r
IsLogicalVolumeDescriptorSupported (\r
- UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc\r
+ UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc\r
)\r
{\r
//\r
// Check for a valid UDF revision range\r
//\r
switch (LogicalVolDesc->DomainIdentifier.Suffix.Domain.UdfRevision) {\r
- case 0x0102:\r
- case 0x0150:\r
- case 0x0200:\r
- case 0x0201:\r
- case 0x0250:\r
- case 0x0260:\r
- break;\r
- default:\r
- return FALSE;\r
+ case 0x0102:\r
+ case 0x0150:\r
+ case 0x0200:\r
+ case 0x0201:\r
+ case 0x0250:\r
+ case 0x0260:\r
+ break;\r
+ default:\r
+ return FALSE;\r
}\r
\r
//\r
if (LogicalVolDesc->NumberOfPartitionMaps > 1) {\r
return FALSE;\r
}\r
+\r
//\r
// UDF 1.02 revision supports only Type 1 (Physical) partitions, but\r
// let's check it any way.\r
// PartitionMap[0] -> type\r
// PartitionMap[1] -> length (in bytes)\r
//\r
- if (LogicalVolDesc->PartitionMaps[0] != 1 ||\r
- LogicalVolDesc->PartitionMaps[1] != 6) {\r
+ if ((LogicalVolDesc->PartitionMaps[0] != 1) ||\r
+ (LogicalVolDesc->PartitionMaps[1] != 6))\r
+ {\r
return FALSE;\r
}\r
\r
UDF_DESCRIPTOR_TAG *DescriptorTag;\r
\r
BlockSize = BlockIo->Media->BlockSize;\r
- ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;\r
+ ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;\r
\r
//\r
// UDF 2.60, 2.2.3.1 struct MainVolumeDescriptorSequenceExtent\r
// Also make sure it does not exceed maximum number of blocks in the disk.\r
//\r
SeqBlocksNum = DivU64x32 ((UINT64)ExtentAd->ExtentLength, BlockSize);\r
- if (SeqBlocksNum < 16 || (EFI_LBA)SeqBlocksNum > LastRecordedBlock + 1) {\r
+ if ((SeqBlocksNum < 16) || ((EFI_LBA)SeqBlocksNum > LastRecordedBlock + 1)) {\r
return EFI_VOLUME_CORRUPTED;\r
}\r
\r
// Check for valid Volume Descriptor Sequence starting block number\r
//\r
SeqStartBlock = (UINT64)ExtentAd->ExtentLocation;\r
- if (SeqStartBlock > LastRecordedBlock ||\r
- SeqStartBlock + SeqBlocksNum - 1 > LastRecordedBlock) {\r
+ if ((SeqStartBlock > LastRecordedBlock) ||\r
+ (SeqStartBlock + SeqBlocksNum - 1 > LastRecordedBlock))\r
+ {\r
return EFI_VOLUME_CORRUPTED;\r
}\r
\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- SeqEndBlock = SeqStartBlock + SeqBlocksNum;\r
+ SeqEndBlock = SeqStartBlock + SeqBlocksNum;\r
StopSequence = FALSE;\r
- LvdsCount = 0;\r
- Status = EFI_VOLUME_CORRUPTED;\r
+ LvdsCount = 0;\r
+ Status = EFI_VOLUME_CORRUPTED;\r
//\r
// Start Main Volume Descriptor Sequence\r
//\r
- for (; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {\r
+ for ( ; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {\r
//\r
// Read disk block\r
//\r
Status = BlockIo->ReadBlocks (\r
- BlockIo,\r
- BlockIo->Media->MediaId,\r
- SeqStartBlock,\r
- BlockSize,\r
- Buffer\r
- );\r
+ BlockIo,\r
+ BlockIo->Media->MediaId,\r
+ SeqStartBlock,\r
+ BlockSize,\r
+ Buffer\r
+ );\r
if (EFI_ERROR (Status)) {\r
goto Out_Free;\r
}\r
// Space Descriptors.\r
//\r
switch (DescriptorTag->TagIdentifier) {\r
- case UdfPrimaryVolumeDescriptor:\r
- case UdfImplemenationUseVolumeDescriptor:\r
- case UdfPartitionDescriptor:\r
- case UdfUnallocatedSpaceDescriptor:\r
- break;\r
-\r
- case UdfLogicalVolumeDescriptor:\r
- LogicalVolDesc = Buffer;\r
-\r
- //\r
- // Check for existence of a single LVD and whether it is supported by\r
- // current EDK2 UDF file system implementation.\r
- //\r
- if (++LvdsCount > 1 ||\r
- !IsLogicalVolumeDescriptorSupported (LogicalVolDesc)) {\r
- Status = EFI_UNSUPPORTED;\r
+ case UdfPrimaryVolumeDescriptor:\r
+ case UdfImplemenationUseVolumeDescriptor:\r
+ case UdfPartitionDescriptor:\r
+ case UdfUnallocatedSpaceDescriptor:\r
+ break;\r
+\r
+ case UdfLogicalVolumeDescriptor:\r
+ LogicalVolDesc = Buffer;\r
+\r
+ //\r
+ // Check for existence of a single LVD and whether it is supported by\r
+ // current EDK2 UDF file system implementation.\r
+ //\r
+ if ((++LvdsCount > 1) ||\r
+ !IsLogicalVolumeDescriptorSupported (LogicalVolDesc))\r
+ {\r
+ Status = EFI_UNSUPPORTED;\r
+ StopSequence = TRUE;\r
+ }\r
+\r
+ break;\r
+\r
+ case UdfTerminatingDescriptor:\r
+ //\r
+ // Stop the sequence when we find a Terminating Descriptor\r
+ // (aka Unallocated Sector), se we don't have to walk all the unallocated\r
+ // area unnecessarily.\r
+ //\r
StopSequence = TRUE;\r
- }\r
-\r
- break;\r
-\r
- case UdfTerminatingDescriptor:\r
- //\r
- // Stop the sequence when we find a Terminating Descriptor\r
- // (aka Unallocated Sector), se we don't have to walk all the unallocated\r
- // area unnecessarily.\r
- //\r
- StopSequence = TRUE;\r
- break;\r
-\r
- default:\r
- //\r
- // An invalid Volume Descriptor has been found in the sequece. Volume is\r
- // corrupted.\r
- //\r
- Status = EFI_VOLUME_CORRUPTED;\r
- goto Out_Free;\r
+ break;\r
+\r
+ default:\r
+ //\r
+ // An invalid Volume Descriptor has been found in the sequece. Volume is\r
+ // corrupted.\r
+ //\r
+ Status = EFI_VOLUME_CORRUPTED;\r
+ goto Out_Free;\r
}\r
}\r
\r
//\r
// Check if LVD was found\r
//\r
- if (!EFI_ERROR (Status) && LvdsCount == 1) {\r
+ if (!EFI_ERROR (Status) && (LvdsCount == 1)) {\r
*MainVdsStartBlock = GuardMainVdsStartBlock;\r
//\r
// We do not need to read either LVD or PD descriptors to know the last\r
// Find Anchor Volume Descriptor Pointer\r
//\r
Status = FindAnchorVolumeDescriptorPointer (\r
- BlockIo,\r
- DiskIo,\r
- &AnchorPoint,\r
- &LastRecordedBlock\r
- );\r
+ BlockIo,\r
+ DiskIo,\r
+ &AnchorPoint,\r
+ &LastRecordedBlock\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
// Find Logical Volume location\r
//\r
Status = FindLogicalVolumeLocation (\r
- BlockIo,\r
- DiskIo,\r
- &AnchorPoint,\r
- LastRecordedBlock,\r
- (UINT64 *)StartingLBA,\r
- (UINT64 *)EndingLBA\r
- );\r
+ BlockIo,\r
+ DiskIo,\r
+ &AnchorPoint,\r
+ LastRecordedBlock,\r
+ (UINT64 *)StartingLBA,\r
+ (UINT64 *)EndingLBA\r
+ );\r
\r
return Status;\r
}\r
EFI_LBA EndingLBA;\r
BOOLEAN ChildCreated;\r
\r
- Media = BlockIo->Media;\r
+ Media = BlockIo->Media;\r
ChildCreated = FALSE;\r
\r
//\r
//\r
ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));\r
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;\r
- PartitionInfo.Type = PARTITION_TYPE_OTHER;\r
+ PartitionInfo.Type = PARTITION_TYPE_OTHER;\r
\r
//\r
// Install partition child handle for UDF file system\r
//\r
Status = PartitionInstallChildHandle (\r
- This,\r
- Handle,\r
- DiskIo,\r
- DiskIo2,\r
- BlockIo,\r
- BlockIo2,\r
- DevicePath,\r
- (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath,\r
- &PartitionInfo,\r
- StartingLBA,\r
- EndingLBA,\r
- Media->BlockSize,\r
- NULL\r
- );\r
+ This,\r
+ Handle,\r
+ DiskIo,\r
+ DiskIo2,\r
+ BlockIo,\r
+ BlockIo2,\r
+ DevicePath,\r
+ (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath,\r
+ &PartitionInfo,\r
+ StartingLBA,\r
+ EndingLBA,\r
+ Media->BlockSize,\r
+ NULL\r
+ );\r
if (EFI_ERROR (Status)) {\r
return (ChildCreated ? EFI_SUCCESS : Status);\r
}\r