UDF revision 2.00 or higher is the only supported. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Paulo Alcantara <pca...@zytor.com> --- MdeModulePkg/MdeModulePkg.dec | 6 + .../Universal/Disk/PartitionDxe/Partition.c | 3 +- .../Universal/Disk/PartitionDxe/Partition.h | 41 ++- .../Universal/Disk/PartitionDxe/PartitionDxe.inf | 10 +- .../Universal/Disk/PartitionDxe/PartitionDxe.uni | Bin 3206 -> 3290 bytes MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 330 +++++++++++++++++++++ MdePkg/Include/IndustryStandard/Udf.h | 79 +++++ 7 files changed, 461 insertions(+), 8 deletions(-) create mode 100644 MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c create mode 100644 MdePkg/Include/IndustryStandard/Udf.h
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index c58f424..4d8b346 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -600,6 +600,12 @@ # @Prompt Enable S3 performance data support. gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwarePerformanceDataTableS3Support|TRUE|BOOLEAN|0x00010064 + ## Indicates if UDF/ECMA-167 filesystem will be supported.<BR><BR> + # TRUE - UDF/ECMA-167 filesystem will be supported.<BR> + # FALSE - UDF/ECMA-167 filesystem will not be supported.<BR> + # @Prompt Enable UDF/ECMA-167 filesystem support. + gEfiMdeModulePkgTokenSpaceGuid.PcdUdfFileSystemSupport|FALSE|BOOLEAN|0x00010069 + [PcdsFeatureFlag.IA32, PcdsFeatureFlag.X64] ## Indicates if DxeIpl should switch to long mode to enter DXE phase. # It is assumed that 64-bit DxeCore is built in firmware if it is true; otherwise 32-bit DxeCore diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c index 28639b0..fc7f253 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c @@ -2,7 +2,7 @@ Partition driver that produces logical BlockIo devices from a physical BlockIo device. The logical BlockIo devices are based on the format of the raw block devices media. Currently "El Torito CD-ROM", Legacy - MBR, and GPT partition schemes are supported. + MBR, GPT partition and UDF/ECMA-167 volume schemes are supported. Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials @@ -45,6 +45,7 @@ PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = { PartitionInstallGptChildHandles, PartitionInstallElToritoChildHandles, PartitionInstallMbrChildHandles, + PartitionInstallUdfChildHandles, NULL }; diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h index 06470f6..aa132ea 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h @@ -1,8 +1,8 @@ /** @file - Partition driver that produces logical BlockIo devices from a physical + Partition driver that produces logical BlockIo devices from a physical BlockIo device. The logical BlockIo devices are based on the format - of the raw block devices media. Currently "El Torito CD-ROM", Legacy - MBR, and GPT partition schemes are supported. + of the raw block devices media. Currently "El Torito CD-ROM", Legacy + MBR, GPT partition and UDF/ECMA-167 volume schemes are supported. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> This program and the accompanying materials @@ -15,8 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#ifndef _PARTITION_H_ -#define _PARTITION_H_ +#ifndef _PARTITION_H_ +#define _PARTITION_H_ #include <Uefi.h> #include <Protocol/BlockIo.h> @@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <IndustryStandard/Mbr.h> #include <IndustryStandard/ElTorito.h> +#include <IndustryStandard/Udf.h> // @@ -411,7 +412,7 @@ PartitionInstallElToritoChildHandles ( @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. @@ -428,6 +429,34 @@ PartitionInstallMbrChildHandles ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ); +/** + Install child handles if the Handle supports UDF/ECMA-167 volume 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 Child handle(s) was added. + @retval EFI_MEDIA_CHANGED Media changed Detected. + @retval other no child handle was added. + +**/ +EFI_STATUS +PartitionInstallUdfChildHandles ( + 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 + ); + typedef EFI_STATUS (*PARTITION_DETECT_ROUTINE) ( diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf index 6806263..c4ad28d 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf @@ -4,7 +4,7 @@ # This module produces the logical Block I/O device that represents # the bytes from Start to End of the Parent Block I/O device. # The partition of physical BlockIo device supported is one of legacy MBR, GPT, -# and "El Torito" partitions. +# "El Torito" partitions and UDF/ECMA-167 volumes. # # Caution: This module requires additional review when modified. # This driver will have external input - disk partition. @@ -46,12 +46,14 @@ Mbr.c Gpt.c ElTorito.c + Udf.c Partition.c Partition.h [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec [LibraryClasses] @@ -63,6 +65,7 @@ BaseLib UefiDriverEntryPoint DebugLib + PcdLib [Guids] @@ -85,5 +88,10 @@ gEfiDiskIoProtocolGuid ## TO_START gEfiDiskIo2ProtocolGuid ## TO_START + +[FeaturePcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdUdfFileSystemSupport ## CONSUMES + + [UserExtensions.TianoCore."ExtraFiles"] PartitionDxeExtra.uni diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.uni b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.uni index 53e439843dc55857c3b041e09b55289d502364e0..462ba5b5195a6138895b818086048931435a42ce 100644 GIT binary patch delta 126 zcmZpZyd}9|71QKROgj1s42cYR3@Ho>4517z3~mhi46Y2$489DG47v=43}y`GK$$Xz je1;r`QifcH)Xle<!Z{gZCU0aCogBa;MXL76={)iPj35}w delta 36 mcmca5*(SMR6%%VBLmorQ<mF8In>m<6IHBA~9^=XTcw_+2cnXOC diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c new file mode 100644 index 0000000..9f803bd --- /dev/null +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c @@ -0,0 +1,330 @@ +/** @file + Decode an UDF/ECMA-167 formatted medium + +Copyright (c) 2014 Paulo Alcantara <pca...@zytor.com><BR> +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" + + +EFI_GUID gUdfVolumeSignatureGuid = { + 0xC5BD4D42, 0x1A76, 0x4996, + { 0x89, 0x56, 0x73, 0xCD, 0xA3, 0x26, 0xCD, 0x0A } +}; + +// +// The UDF/ECMA-167 file system driver only supports UDF revision 2.00 or +// higher. +// +// Note the "NSR03" identifier. +// +UDF_STANDARD_IDENTIFIER gUdfStandardIdentifiers[NR_STANDARD_IDENTIFIERS] = { + { { 'B', 'E', 'A', '0', '1' } }, + { { 'N', 'S', 'R', '0', '3' } }, + { { 'T', 'E', 'A', '0', '1' } }, +}; + +typedef struct { + VENDOR_DEVICE_PATH DevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} UDF_DEVICE_PATH; + +// +// C5BD4D42-1A76-4996-8956-73CDA326CD0A +// +#define EFI_UDF_DEVICE_PATH_GUID \ + { 0xC5BD4D42, 0x1A76, 0x4996, \ + { 0x89, 0x56, 0x73, 0xCD, 0xA3, 0x26, 0xCD, 0x0A } \ + } + +UDF_DEVICE_PATH gUdfDevicePath = { + { { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, + { sizeof (VENDOR_DEVICE_PATH), 0 } }, + EFI_UDF_DEVICE_PATH_GUID + }, + { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } + } +}; + +EFI_STATUS +FindAnchorVolumeDescriptorPointer ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint + ) +{ + EFI_STATUS Status; + UINT32 BlockSize; + EFI_LBA EndLBA; + + BlockSize = BlockIo->Media->BlockSize; + EndLBA = BlockIo->Media->LastBlock; + + // + // Look for an AVDP at LBA 256. + // + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (0x100ULL, BlockSize), + sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), + (VOID *)AnchorPoint + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (IS_AVDP (AnchorPoint)) { + return EFI_SUCCESS; + } + + // + // Look for an AVDP at last LBA - 256. + // + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (EndLBA - 0x100ULL, BlockSize), + sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), + (VOID *)AnchorPoint + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (IS_AVDP (AnchorPoint)) { + return EFI_SUCCESS; + } + + // + // Look for an AVDP at last LBA. + // + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (EndLBA, BlockSize), + sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER), + (VOID *)AnchorPoint + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (IS_AVDP (AnchorPoint)) { + return EFI_SUCCESS; + } + + // + // There is no AVDP on this medium. + // + return EFI_VOLUME_CORRUPTED; +} + +EFI_STATUS +SupportUdfFileSystem ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo + ) +{ + EFI_STATUS Status; + UINT64 Offset; + UINT64 EndDiskOffset; + UDF_VOLUME_DESCRIPTOR VolDescriptor; + UDF_VOLUME_DESCRIPTOR TerminatingVolDescriptor; + UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; + + ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof (UDF_VOLUME_DESCRIPTOR)); + + // + // Start Volume Recognition Sequence. + // + EndDiskOffset = (UINT64)BlockIo->Media->LastBlock * BlockIo->Media->BlockSize; + + for (Offset = UDF_VRS_START_OFFSET; Offset < EndDiskOffset; + Offset += UDF_LOGICAL_SECTOR_SIZE) { + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + Offset, + sizeof (UDF_VOLUME_DESCRIPTOR), + (VOID *)&VolDescriptor + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (!CompareMem ( + (VOID *)&VolDescriptor.StandardIdentifier, + (VOID *)&gUdfStandardIdentifiers[BEA_IDENTIFIER], + UDF_STANDARD_IDENTIFIER_LENGTH + ) + ) { + break; + } + + if (CompareMem ( + (VOID *)&VolDescriptor.StandardIdentifier, + (VOID *)UDF_CDROM_VOLUME_IDENTIFIER, + UDF_STANDARD_IDENTIFIER_LENGTH + ) || + !CompareMem ( + (VOID *)&VolDescriptor, + (VOID *)&TerminatingVolDescriptor, + sizeof (UDF_VOLUME_DESCRIPTOR) + ) + ) { + return EFI_UNSUPPORTED; + } + } + + // + // Look for "NSR03" identifier in the Extended Area + // + Offset += UDF_LOGICAL_SECTOR_SIZE; + if (Offset >= EndDiskOffset) { + return EFI_UNSUPPORTED; + } + + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + Offset, + sizeof (UDF_VOLUME_DESCRIPTOR), + (VOID *)&VolDescriptor + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (CompareMem ( + (VOID *)&VolDescriptor.StandardIdentifier, + (VOID *)&gUdfStandardIdentifiers[VSD_IDENTIFIER], + UDF_STANDARD_IDENTIFIER_LENGTH + ) + ) { + return EFI_UNSUPPORTED; + } + + // + // Look for "TEA01" identifier in the Extended Area + // + Offset += UDF_LOGICAL_SECTOR_SIZE; + if (Offset >= EndDiskOffset) { + return EFI_UNSUPPORTED; + } + + Status = DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + Offset, + sizeof (UDF_VOLUME_DESCRIPTOR), + (VOID *)&VolDescriptor + ); + if (EFI_ERROR (Status)) { + return Status; + } + + if (CompareMem ( + (VOID *)&VolDescriptor.StandardIdentifier, + (VOID *)&gUdfStandardIdentifiers[TEA_IDENTIFIER], + UDF_STANDARD_IDENTIFIER_LENGTH + ) + ) { + return EFI_UNSUPPORTED; + } + + Status = FindAnchorVolumeDescriptorPointer (BlockIo, DiskIo, &AnchorPoint); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + +/** + Install child handles if the Handle supports UDF/ECMA-167 volume 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 Child handle(s) was added. + @retval EFI_MEDIA_CHANGED Media changed Detected. + @retval other no child handle was added. + +**/ +EFI_STATUS +PartitionInstallUdfChildHandles ( + 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 + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; + EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; + EFI_GUID *VendorDevGuid; + EFI_GUID UdfDevGuid = EFI_UDF_DEVICE_PATH_GUID; + + if (!FeaturePcdGet (PcdUdfFileSystemSupport)) { + return EFI_NOT_FOUND; + } + + Status = SupportUdfFileSystem (BlockIo, DiskIo); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + LastDevicePathNode = NULL; + DevicePathNode = DevicePath; + while (!IsDevicePathEnd (DevicePathNode)) { + LastDevicePathNode = DevicePathNode; + DevicePathNode = NextDevicePathNode (DevicePathNode); + } + if (LastDevicePathNode) { + VendorDevGuid = (EFI_GUID *)((UINT8 *)LastDevicePathNode + OFFSET_OF (VENDOR_DEVICE_PATH, Guid)); + if (DevicePathSubType (LastDevicePathNode) == MEDIA_VENDOR_DP && + CompareGuid (VendorDevGuid, &UdfDevGuid)) { + return EFI_NOT_FOUND; + } + } + + Status = PartitionInstallChildHandle ( + This, + Handle, + DiskIo, + DiskIo2, + BlockIo, + BlockIo2, + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath, + 0, + BlockIo->Media->LastBlock, + BlockIo->Media->BlockSize, + FALSE + ); + if (!EFI_ERROR (Status)) { + Status = EFI_NOT_FOUND; + } + + return Status; +} diff --git a/MdePkg/Include/IndustryStandard/Udf.h b/MdePkg/Include/IndustryStandard/Udf.h new file mode 100644 index 0000000..4fdf199 --- /dev/null +++ b/MdePkg/Include/IndustryStandard/Udf.h @@ -0,0 +1,79 @@ +/** @file + UDF/ECMA-167 Volume and File Structure Format Definition. + +Copyright (c) 2014 Paulo Alcantara <pca...@zytor.com><BR> +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. + +**/ + +#ifndef _UDF_H_ +#define _UDF_H_ + + +#define UDF_LOGICAL_SECTOR_SHIFT 11 +#define UDF_LOGICAL_SECTOR_SIZE ((UINT64)(1 << UDF_LOGICAL_SECTOR_SHIFT)) +#define UDF_VRS_START_OFFSET ((UINT64)(16 << UDF_LOGICAL_SECTOR_SHIFT)) +#define UDF_STANDARD_IDENTIFIER_LENGTH 5 +#define UDF_CDROM_VOLUME_IDENTIFIER "CD001" + +#define _GET_TAG_ID(_Pointer) \ + (((UDF_DESCRIPTOR_TAG *) (_Pointer))->TagIdentifier) + +#define IS_PVD(_Pointer) \ + ((BOOLEAN)(_GET_TAG_ID (_Pointer) == 1)) +#define IS_AVDP(_Pointer) \ + ((BOOLEAN)(_GET_TAG_ID (_Pointer) == 2)) + +typedef struct { + UINT8 StandardIdentifier[UDF_STANDARD_IDENTIFIER_LENGTH]; +} UDF_STANDARD_IDENTIFIER; + +enum { + BEA_IDENTIFIER, + VSD_IDENTIFIER, + TEA_IDENTIFIER, + NR_STANDARD_IDENTIFIERS, +}; + +#pragma pack(1) + +typedef struct { + UINT16 TagIdentifier; + UINT16 DescriptorVersion; + UINT8 TagChecksum; + UINT8 Reserved; + UINT16 TagSerialNumber; + UINT16 DescriptorCRC; + UINT16 DescriptorCRCLength; + UINT32 TagLocation; +} UDF_DESCRIPTOR_TAG; + +typedef struct { + UINT32 ExtentLength; + UINT32 ExtentLocation; +} UDF_EXTENT_AD; + +typedef struct { + UINT8 StructureType; + UINT8 StandardIdentifier[UDF_STANDARD_IDENTIFIER_LENGTH]; + UINT8 StructureVersion; + UINT8 Reserved; + UINT8 StructureData[2040]; +} UDF_VOLUME_DESCRIPTOR; + +typedef struct { + UDF_DESCRIPTOR_TAG DescriptorTag; + UDF_EXTENT_AD MainVolumeDescriptorSequenceExtent; + UDF_EXTENT_AD ReserveVolumeDescriptorSequenceExtent; + UINT8 Reserved[480]; +} UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER; + +#pragma pack() + +#endif // _UDF_H_ -- 1.9.3 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel