From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.zytor.com (terminus.zytor.com [65.50.211.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2BE0D21E1B748 for ; Thu, 21 Sep 2017 06:52:03 -0700 (PDT) Received: from [IPv6:2804:18:83c:db95:d693:b6a1:a6f8:8b0d] ([IPv6:2804:18:83c:db95:d693:b6a1:a6f8:8b0d]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id v8LDqnG1028129 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 21 Sep 2017 06:52:52 -0700 Date: Thu, 21 Sep 2017 10:52:46 -0300 User-Agent: K-9 Mail for Android In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103B97756A@shsmsx102.ccr.corp.intel.com> References: <33171F84-A619-43B3-B9A8-0EC2CA8BA110@zytor.com> <0C09AFA07DD0434D9E2A0C6AEB0483103B97756A@shsmsx102.ccr.corp.intel.com> MIME-Version: 1.0 To: "Zeng, Star" , "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" , Laszlo Ersek , "Dong, Eric" From: Paulo Alcantara Message-ID: <7CD2E165-74AE-4E76-A686-BA8CE17720DE@zytor.com> Subject: Re: [PATCH v3 2/2] MdeModulePkg/PartitionDxe: Fix creation of UDF logical partition X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Sep 2017 13:52:03 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On September 21, 2017 10:47:07 AM GMT-03:00, "Zeng, Star" wrote: >Does it have functional impact? Nope=2E When Partition driver walks the partition detect routine table, it= executes each routine and then checks for EFI_NO_MEDIA and EFI_MEDIA_CHANG= ED only=2E So, the child handle is installed and the EFI_NOT_FOUND is a no-= op in that case=2E Thanks! Paulo > >Thanks, >Star >-----Original Message----- >From: Paulo Alcantara [mailto:pcacjr@zytor=2Ecom]=20 >Sent: Thursday, September 21, 2017 9:29 PM >To: Wu, Hao A ; edk2-devel@lists=2E01=2Eorg >Cc: Ni, Ruiyu ; Laszlo Ersek ; >Dong, Eric ; Zeng, Star >Subject: RE: [edk2] [PATCH v3 2/2] MdeModulePkg/PartitionDxe: Fix >creation of UDF logical partition > > > >On September 21, 2017 9:44:10 AM GMT-03:00, "Wu, Hao A" > wrote: >>One small comment, within function PartitionInstallUdfChildHandles(): >> >> =2E=2E=2E >> // >> // Install partition child handle for UDF file system >> // >> Status =3D PartitionInstallChildHandle ( >> =2E=2E=2E >> ); >>if (!EFI_ERROR (Status)) { <----- Is this a typo? "if (EFI_ERROR >>(Status)) {" =20 >> Status =3D EFI_NOT_FOUND; >> } > >Yes, it is=2E Good catch! Could you please fix that for me by removing >the if condition? Otherwise I can send a v4 later with that=2E > >Thanks! >Paulo > >> =20 >> >>Best Regards, >>Hao Wu >> >> >>> -----Original Message----- >>> From: edk2-devel [mailto:edk2-devel-bounces@lists=2E01=2Eorg] On Behal= f >>Of Paulo >>> Alcantara >>> Sent: Thursday, September 21, 2017 2:16 AM >>> To: edk2-devel@lists=2E01=2Eorg >>> Cc: Ni, Ruiyu; Laszlo Ersek; Dong, Eric; Zeng, Star >>> Subject: [edk2] [PATCH v3 2/2] MdeModulePkg/PartitionDxe: Fix >>creation of >>> UDF logical partition >>>=20 >>> Do not reserve entire block device size for an UDF file system -=20 >>> instead, reserve the appropriate space (UDF logical volume space) >for=20 >>> it=2E >>>=20 >>> Additionally, only create a logical partition for UDF logical >volumes=20 >>> that are currently supported by EDK2 UDF file system implementation=2E >>For >>> instance, an UDF volume with a single LVD and a single Physical >(Type >>1) >>> Partition will be supported=2E >>>=20 >>> Cc: Eric Dong >>> Cc: Ruiyu Ni >>> Cc: Star Zeng >>> Cc: Laszlo Ersek >>> Reported-by: Ruiyu Ni >>> Contributed-under: TianoCore Contribution Agreement 1=2E1 >>> Signed-off-by: Paulo Alcantara >>> --- >>> MdeModulePkg/Universal/Disk/PartitionDxe/Udf=2Ec | 363 >>++++++++++-- >>> MdeModulePkg/Universal/Disk/UdfDxe/File=2Ec | 16 +- >>> MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations=2Ec | 627 >>> ++++++++------------ >>> MdeModulePkg/Universal/Disk/UdfDxe/Udf=2Ec | 7 - >>> MdeModulePkg/Universal/Disk/UdfDxe/Udf=2Eh | 158 >>++--- >>> 5 files changed, 606 insertions(+), 565 deletions(-) >>>=20 >>> diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf=2Ec >>> b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf=2Ec >>> index 609f56cef6=2E=2E572ba7a81a 100644 >>> --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf=2Ec >>> +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf=2Ec >>> @@ -64,11 +64,12 @@ FindAnchorVolumeDescriptorPointer ( >>> OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint >>> ) >>> { >>> - EFI_STATUS Status; >>> - UINT32 BlockSize; >>> - EFI_LBA EndLBA; >>> - EFI_LBA DescriptorLBAs[4]; >>> - UINTN Index; >>> + EFI_STATUS Status; >>> + UINT32 BlockSize; >>> + EFI_LBA EndLBA; >>> + EFI_LBA DescriptorLBAs[4]; >>> + UINTN Index; >>> + UDF_DESCRIPTOR_TAG *DescriptorTag; >>>=20 >>> BlockSize =3D BlockIo->Media->BlockSize; >>> EndLBA =3D BlockIo->Media->LastBlock; @@ -88,10 +89,13 @@=20 >>> FindAnchorVolumeDescriptorPointer ( >>> if (EFI_ERROR (Status)) { >>> return Status; >>> } >>> + >>> + DescriptorTag =3D &AnchorPoint->DescriptorTag; >>> + >>> // >>> // Check if read LBA has a valid AVDP descriptor=2E >>> // >>> - if (IS_AVDP (AnchorPoint)) { >>> + if (DescriptorTag->TagIdentifier =3D=3D >>UdfAnchorVolumeDescriptorPointer) { >>> return EFI_SUCCESS; >>> } >>> } >>> @@ -102,23 +106,18 @@ FindAnchorVolumeDescriptorPointer ( } >>>=20 >>> /** >>> - Check if block device supports a valid UDF file system as >>specified by OSTA >>> - Universal Disk Format Specification 2=2E60=2E >>> + Find UDF volume identifiers in a Volume Recognition Sequence=2E >>>=20 >>> - @param[in] BlockIo BlockIo interface=2E >>> - @param[in] DiskIo DiskIo interface=2E >>> + @param[in] BlockIo BlockIo interface=2E >>> + @param[in] DiskIo DiskIo interface=2E >>>=20 >>> - @retval EFI_SUCCESS UDF file system found=2E >>> - @retval EFI_UNSUPPORTED UDF file system not found=2E >>> - @retval EFI_NO_MEDIA The device has no media=2E >>> - @retval EFI_DEVICE_ERROR The device reported an error=2E >>> - @retval EFI_VOLUME_CORRUPTED The file system structures are >>corrupted=2E >>> - @retval EFI_OUT_OF_RESOURCES The scan was not successful due to >>lack of >>> - resources=2E >>> + @retval EFI_SUCCESS UDF volume identifiers were >found=2E >>> + @retval EFI_NOT_FOUND UDF volume identifiers were not >>found=2E >>> + @retval other Failed to perform disk I/O=2E >>>=20 >>> **/ >>> EFI_STATUS >>> -SupportUdfFileSystem ( >>> +FindUdfVolumeIdentifiers ( >>> IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >>> IN EFI_DISK_IO_PROTOCOL *DiskIo >>> ) >>> @@ -128,7 +127,6 @@ SupportUdfFileSystem ( >>> UINT64 EndDiskOffset; >>> CDROM_VOLUME_DESCRIPTOR VolDescriptor; >>> CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor; >>> - UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; >>>=20 >>> ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof=20 >>> (CDROM_VOLUME_DESCRIPTOR)); >>>=20 >>> @@ -167,7 +165,7 @@ SupportUdfFileSystem ( >>> (CompareMem ((VOID *)&VolDescriptor, >>> (VOID *)&TerminatingVolDescriptor, >>> sizeof (CDROM_VOLUME_DESCRIPTOR)) =3D=3D 0)) { >>> - return EFI_UNSUPPORTED; >>> + return EFI_NOT_FOUND; >>> } >>> } >>>=20 >>> @@ -176,7 +174,7 @@ SupportUdfFileSystem ( >>> // >>> Offset +=3D UDF_LOGICAL_SECTOR_SIZE; >>> if (Offset >=3D EndDiskOffset) { >>> - return EFI_UNSUPPORTED; >>> + return EFI_NOT_FOUND; >>> } >>>=20 >>> Status =3D DiskIo->ReadDisk ( >>> @@ -196,7 +194,7 @@ SupportUdfFileSystem ( >>> (CompareMem ((VOID *)VolDescriptor=2EUnknown=2EId, >>> (VOID *)UDF_NSR3_IDENTIFIER, >>> sizeof (VolDescriptor=2EUnknown=2EId)) !=3D 0)) { >>> - return EFI_UNSUPPORTED; >>> + return EFI_NOT_FOUND; >>> } >>>=20 >>> // >>> @@ -204,7 +202,7 @@ SupportUdfFileSystem ( >>> // >>> Offset +=3D UDF_LOGICAL_SECTOR_SIZE; >>> if (Offset >=3D EndDiskOffset) { >>> - return EFI_UNSUPPORTED; >>> + return EFI_NOT_FOUND; >>> } >>>=20 >>> Status =3D DiskIo->ReadDisk ( >>> @@ -221,15 +219,291 @@ SupportUdfFileSystem ( >>> if (CompareMem ((VOID *)VolDescriptor=2EUnknown=2EId, >>> (VOID *)UDF_TEA_IDENTIFIER, >>> sizeof (VolDescriptor=2EUnknown=2EId)) !=3D 0) { >>> - return EFI_UNSUPPORTED; >>> + return EFI_NOT_FOUND; >>> + } >>> + >>> + return EFI_SUCCESS; >>> +} >>> + >>> +/** >>> + Check if Logical Volume Descriptor is supported by current EDK2 >>UDF file >>> + system implementation=2E >>> + >>> + @param[in] LogicalVolDesc Logical Volume Descriptor pointer=2E >>> + >>> + @retval TRUE Logical Volume Descriptor is >>supported=2E >>> + @retval FALSE Logical Volume Descriptor is not >>supported=2E >>> + >>> +**/ >>> +BOOLEAN >>> +IsLogicalVolumeDescriptorSupported ( >>> + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc >>> + ) >>> +{ >>> + // >>> + // Check for a valid UDF revision range >>> + // >>> + switch (UDF_LVD_REVISION (LogicalVolDesc)) { >>> + case 0x0102: >>> + case 0x0150: >>> + case 0x0200: >>> + case 0x0201: >>> + case 0x0250: >>> + case 0x0260: >>> + break; >>> + default: >>> + return FALSE; >>> + } >>> + >>> + // >>> + // Check for a single Partition Map // if=20 >>> + (LogicalVolDesc->NumberOfPartitionMaps > 1) { >>> + return FALSE; >>> + } >>> + // >>> + // UDF 1=2E02 revision supports only Type 1 (Physical) partitions, >>but >>> + // let's check it any way=2E >>> + // >>> + // PartitionMap[0] -> type >>> + // PartitionMap[1] -> length (in bytes) // if=20 >>> + (LogicalVolDesc->PartitionMaps[0] !=3D 1 || >>> + LogicalVolDesc->PartitionMaps[1] !=3D 6) { >>> + return FALSE; >>> + } >>> + >>> + return TRUE; >>> +} >>> + >>> +/** >>> + Find UDF logical volume location and whether it is supported by >>current EDK2 >>> + UDF file system implementation=2E >>> + >>> + @param[in] BlockIo BlockIo interface=2E >>> + @param[in] DiskIo DiskIo interface=2E >>> + @param[in] AnchorPoint Anchor volume descriptor pointer=2E >>> + @param[out] MainVdsStartBlock Main VDS starting block number=2E >>> + @param[out] MainVdsEndBlock Main VDS ending block number=2E >>> + >>> + @retval EFI_SUCCESS UDF logical volume was found=2E >>> + @retval EFI_VOLUME_CORRUPTED UDF file system structures are >>> corrupted=2E >>> + @retval EFI_UNSUPPORTED UDF logical volume is not >>supported=2E >>> + @retval other Failed to perform disk I/O=2E >>> + >>> +**/ >>> +EFI_STATUS >>> +FindLogicalVolumeLocation ( >>> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >>> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >>> + IN UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint, >>> + OUT UINT64 *MainVdsStartBlock, >>> + OUT UINT64 *MainVdsEndBlock >>> + ) >>> +{ >>> + EFI_STATUS Status; >>> + UINT32 BlockSize; >>> + EFI_LBA LastBlock; >>> + UDF_EXTENT_AD *ExtentAd; >>> + UINT64 SeqBlocksNum; >>> + UINT64 SeqStartBlock; >>> + UINT64 GuardMainVdsStartBlock; >>> + VOID *Buffer; >>> + UINT64 SeqEndBlock; >>> + BOOLEAN StopSequence; >>> + UINTN LvdsCount; >>> + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; >>> + UDF_DESCRIPTOR_TAG *DescriptorTag; >>> + >>> + BlockSize =3D BlockIo->Media->BlockSize; LastBlock =3D=20 >>> + BlockIo->Media->LastBlock; ExtentAd =3D=20 >>> + &AnchorPoint->MainVolumeDescriptorSequenceExtent; >>> + >>> + // >>> + // UDF 2=2E60, 2=2E2=2E3=2E1 struct MainVolumeDescriptorSequenceExt= ent >>> + // >>> + // The Main Volume Descriptor Sequence Extent shall have a >minimum >>length >>> of >>> + // 16 logical sectors=2E >>> + // >>> + // Also make sure it does not exceed maximum number of blocks in >>the disk=2E >>> + // >>> + SeqBlocksNum =3D DivU64x32 ((UINT64)ExtentAd->ExtentLength, >>BlockSize); >>> + if (SeqBlocksNum < 16 || (EFI_LBA)SeqBlocksNum > LastBlock + 1) { >>> + return EFI_VOLUME_CORRUPTED; >>> + } >>> + >>> + // >>> + // Check for valid Volume Descriptor Sequence starting block >>number >>> + // >>> + SeqStartBlock =3D (UINT64)ExtentAd->ExtentLocation; if=20 >>> + (SeqStartBlock > LastBlock || >>> + SeqStartBlock + SeqBlocksNum - 1 > LastBlock) { >>> + return EFI_VOLUME_CORRUPTED; >>> } >>>=20 >>> + GuardMainVdsStartBlock =3D SeqStartBlock; >>> + >>> + // >>> + // Allocate buffer for reading disk blocks // Buffer =3D=20 >>> + AllocateZeroPool ((UINTN)BlockSize); if (Buffer =3D=3D NULL) { >>> + return EFI_OUT_OF_RESOURCES; >>> + } >>> + >>> + SeqEndBlock =3D SeqStartBlock + SeqBlocksNum; StopSequence =3D >FALSE; =20 >>> + LvdsCount =3D 0; Status =3D EFI_VOLUME_CORRUPTED; // // Start Mai= n=20 >>> + Volume Descriptor Sequence // for (; SeqStartBlock < SeqEndBlock > >>> + && !StopSequence; >>SeqStartBlock++) { >>> + // >>> + // Read disk block >>> + // >>> + Status =3D BlockIo->ReadBlocks ( >>> + BlockIo, >>> + BlockIo->Media->MediaId, >>> + SeqStartBlock, >>> + BlockSize, >>> + Buffer >>> + ); >>> + if (EFI_ERROR (Status)) { >>> + goto Out_Free; >>> + } >>> + >>> + DescriptorTag =3D Buffer; >>> + >>> + // >>> + // ECMA 167, 8=2E4=2E1 Contents of a Volume Descriptor Sequence >>> + // >>> + // - A Volume Descriptor Sequence shall contain one or more >>Primary >>> Volume >>> + // Descriptors=2E >>> + // - A Volume Descriptor Sequence shall contain zero or more >>> Implementation >>> + // Use Volume Descriptors=2E >>> + // - A Volume Descriptor Sequence shall contain zero or more >>Partition >>> + // Descriptors=2E >>> + // - A Volume Descriptor Sequence shall contain zero or more >>Logical >>> Volume >>> + // Descriptors=2E >>> + // - A Volume Descriptor Sequence shall contain zero or more >>Unallocated >>> + // Space Descriptors=2E >>> + // >>> + switch (UDF_TAG_ID (DescriptorTag)) { >>> + case UdfPrimaryVolumeDescriptor: >>> + case UdfImplemenationUseVolumeDescriptor: >>> + case UdfPartitionDescriptor: >>> + case UdfUnallocatedSpaceDescriptor: >>> + break; >>> + >>> + case UdfLogicalVolumeDescriptor: >>> + LogicalVolDesc =3D Buffer; >>> + >>> + // >>> + // Check for existence of a single LVD and whether it is >>supported by >>> + // current EDK2 UDF file system implementation=2E >>> + // >>> + if (++LvdsCount > 1 || >>> + !IsLogicalVolumeDescriptorSupported (LogicalVolDesc)) { >>> + Status =3D EFI_UNSUPPORTED; >>> + StopSequence =3D TRUE; >>> + } >>> + >>> + break; >>> + >>> + case UdfTerminatingDescriptor: >>> + // >>> + // Stop the sequence when we find a Terminating Descriptor >>> + // (aka Unallocated Sector), se we don't have to walk all the >>unallocated >>> + // area unnecessarily=2E >>> + // >>> + StopSequence =3D TRUE; >>> + break; >>> + >>> + default: >>> + // >>> + // An invalid Volume Descriptor has been found in the >sequece=2E >>Volume is >>> + // corrupted=2E >>> + // >>> + Status =3D EFI_VOLUME_CORRUPTED; >>> + goto Out_Free; >>> + } >>> + } >>> + >>> + // >>> + // Check if LVD was found >>> + // >>> + if (!EFI_ERROR (Status) && LvdsCount =3D=3D 1) { >>> + *MainVdsStartBlock =3D GuardMainVdsStartBlock; >>> + // >>> + // We do not need to read either LVD or PD descriptors to know >>the last >>> + // valid block in the found UDF file system=2E It's already >>LastBlock=2E >>> + // >>> + *MainVdsEndBlock =3D LastBlock; >>> + >>> + Status =3D EFI_SUCCESS; >>> + } >>> + >>> +Out_Free: >>> + // >>> + // Free block read buffer >>> + // >>> + FreePool (Buffer); >>> + >>> + return Status; >>> +} >>> + >>> +/** >>> + Find a supported UDF file system in block device=2E >>> + >>> + @param[in] BlockIo BlockIo interface=2E >>> + @param[in] DiskIo DiskIo interface=2E >>> + @param[out] StartingLBA UDF file system starting LBA=2E >>> + @param[out] EndingLBA UDF file system starting LBA=2E >>> + >>> + @retval EFI_SUCCESS UDF file system was found=2E >>> + @retval other UDF file system was not found=2E >>> + >>> +**/ >>> +EFI_STATUS >>> +FindUdfFileSystem ( >>> + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, >>> + IN EFI_DISK_IO_PROTOCOL *DiskIo, >>> + OUT EFI_LBA *StartingLBA, >>> + OUT EFI_LBA *EndingLBA >>> + ) >>> +{ >>> + EFI_STATUS Status; >>> + UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; >>> + >>> + // >>> + // Find UDF volume identifiers >>> + // >>> + Status =3D FindUdfVolumeIdentifiers (BlockIo, DiskIo); if=20 >>> + (EFI_ERROR (Status)) { >>> + return Status; >>> + } >>> + >>> + // >>> + // Find Anchor Volume Descriptor Pointer // >>> Status =3D FindAnchorVolumeDescriptorPointer (BlockIo, DiskIo, >>&AnchorPoint); >>> if (EFI_ERROR (Status)) { >>> - return EFI_UNSUPPORTED; >>> + return Status; >>> } >>>=20 >>> - return EFI_SUCCESS; >>> + // >>> + // Find Logical Volume location >>> + // >>> + Status =3D FindLogicalVolumeLocation ( >>> + BlockIo, >>> + DiskIo, >>> + &AnchorPoint, >>> + (UINT64 *)StartingLBA, >>> + (UINT64 *)EndingLBA >>> + ); >>> + >>> + return Status; >>> } >>>=20 >>> /** >>> @@ -263,9 +537,9 @@ PartitionInstallUdfChildHandles ( >>> UINT32 RemainderByMediaBlockSize; >>> EFI_STATUS Status; >>> EFI_BLOCK_IO_MEDIA *Media; >>> - EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; >>> - EFI_GUID *VendorDefinedGuid; >>> EFI_PARTITION_INFO_PROTOCOL PartitionInfo; >>> + EFI_LBA StartingLBA; >>> + EFI_LBA EndingLBA; >>>=20 >>> Media =3D BlockIo->Media; >>>=20 >>> @@ -281,35 +555,10 @@ PartitionInstallUdfChildHandles ( >>> return EFI_NOT_FOUND; >>> } >>>=20 >>> - DevicePathNode =3D DevicePath; >>> - while (!IsDevicePathEnd (DevicePathNode)) { >>> - // >>> - // Do not allow checking for UDF file systems in CDROM "El >>Torito" >>> - // partitions, and skip duplicate installation of UDF file >>system child >>> - // nodes=2E >>> - // >>> - if (DevicePathType (DevicePathNode) =3D=3D MEDIA_DEVICE_PATH) { >>> - if (DevicePathSubType (DevicePathNode) =3D=3D MEDIA_CDROM_DP) { >>> - return EFI_NOT_FOUND; >>> - } >>> - if (DevicePathSubType (DevicePathNode) =3D=3D MEDIA_VENDOR_DP) = { >>> - VendorDefinedGuid =3D (EFI_GUID *)((UINTN)DevicePathNode + >>> - OFFSET_OF >>(VENDOR_DEVICE_PATH, Guid)); >>> - if (CompareGuid (VendorDefinedGuid, &gUdfDevPathGuid)) { >>> - return EFI_NOT_FOUND; >>> - } >>> - } >>> - } >>> - // >>> - // Try next device path node >>> - // >>> - DevicePathNode =3D NextDevicePathNode (DevicePathNode); >>> - } >>> - >>> // >>> - // Check if block device supports an UDF file system >>> + // Search for an UDF file system on block device >>> // >>> - Status =3D SupportUdfFileSystem (BlockIo, DiskIo); >>> + Status =3D FindUdfFileSystem (BlockIo, DiskIo, &StartingLBA, >>&EndingLBA); >>> if (EFI_ERROR (Status)) { >>> return EFI_NOT_FOUND; >>> } >>> @@ -334,8 +583,8 @@ PartitionInstallUdfChildHandles ( >>> DevicePath, >>> (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath, >>> &PartitionInfo, >>> - 0, >>> - Media->LastBlock, >>> + StartingLBA, >>> + EndingLBA, >>> Media->BlockSize >>> ); >>> if (!EFI_ERROR (Status)) { >>> diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File=2Ec >>> b/MdeModulePkg/Universal/Disk/UdfDxe/File=2Ec >>> index 625f2c5637=2E=2E6f07bf2066 100644 >>> --- a/MdeModulePkg/Universal/Disk/UdfDxe/File=2Ec >>> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/File=2Ec >>> @@ -131,7 +131,6 @@ Error_Alloc_Priv_File_Data: >>> CleanupFileInformation (&PrivFsData->Root); >>>=20 >>> Error_Find_Root_Dir: >>> - CleanupVolumeInformation (&PrivFsData->Volume); >>>=20 >>> Error_Read_Udf_Volume: >>> Error_Invalid_Params: >>> @@ -429,7 +428,7 @@ UdfRead ( >>> } >>> ASSERT (NewFileEntryData !=3D NULL); >>>=20 >>> - if (IS_FE_SYMLINK (NewFileEntryData)) { >>> + if (FE_ICB_FILE_TYPE (NewFileEntryData) =3D=3D UdfFileEntrySymlin= k) >>{ >>> Status =3D ResolveSymlink ( >>> BlockIo, >>> DiskIo, >>> @@ -529,7 +528,6 @@ UdfClose ( >>> EFI_TPL OldTpl; >>> EFI_STATUS Status; >>> PRIVATE_UDF_FILE_DATA *PrivFileData; >>> - PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData; >>>=20 >>> OldTpl =3D gBS->RaiseTPL (TPL_CALLBACK); >>>=20 >>> @@ -542,8 +540,6 @@ UdfClose ( >>>=20 >>> PrivFileData =3D PRIVATE_UDF_FILE_DATA_FROM_THIS (This); >>>=20 >>> - PrivFsData =3D PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (PrivFileData- >>> >SimpleFs); >>> - >>> if (!PrivFileData->IsRootDirectory) { >>> CleanupFileInformation (&PrivFileData->File); >>>=20 >>> @@ -552,10 +548,6 @@ UdfClose ( >>> } >>> } >>>=20 >>> - if (--PrivFsData->OpenFiles =3D=3D 0) { >>> - CleanupVolumeInformation (&PrivFsData->Volume); >>> - } >>> - >>> FreePool ((VOID *)PrivFileData); >>>=20 >>> Exit: >>> @@ -652,7 +644,7 @@ UdfGetPosition ( >>> // As per UEFI spec, if the file handle is a directory, then the >>current file >>> // position has no meaning and the operation is not supported=2E >>> // >>> - if (IS_FID_DIRECTORY_FILE >>(&PrivFileData->File=2EFileIdentifierDesc)) { >>> + if (IS_FID_DIRECTORY_FILE >(PrivFileData->File=2EFileIdentifierDesc)) >>{ >>> return EFI_UNSUPPORTED; >>> } >>>=20 >>> @@ -788,7 +780,7 @@ UdfGetInfo ( >>> } else if (CompareGuid (InformationType, >&gEfiFileSystemInfoGuid)) >>{ >>> String =3D VolumeLabel; >>>=20 >>> - FileSetDesc =3D PrivFsData->Volume=2EFileSetDescs[0]; >>> + FileSetDesc =3D &PrivFsData->Volume=2EFileSetDesc; >>>=20 >>> OstaCompressed =3D &FileSetDesc->LogicalVolumeIdentifier[0]; >>>=20 >>> @@ -847,7 +839,7 @@ UdfGetInfo ( >>> FileSystemInfo->Size =3D FileSystemInfoLength; >>> FileSystemInfo->ReadOnly =3D TRUE; >>> FileSystemInfo->BlockSize =3D >>> - LV_BLOCK_SIZE (&PrivFsData->Volume, UDF_DEFAULT_LV_NUM); >>> + PrivFsData->Volume=2ELogicalVolDesc=2ELogicalBlockSize; >>> FileSystemInfo->VolumeSize =3D VolumeSize; >>> FileSystemInfo->FreeSpace =3D FreeSpaceSize; >>>=20 >>> diff --git >>a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations=2Ec >>> b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations=2Ec >>> index 5df267761f=2E=2E62d817989f 100644 >>> --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations=2Ec >>> +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations=2Ec >>> @@ -38,11 +38,12 @@ FindAnchorVolumeDescriptorPointer ( >>> OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint >>> ) >>> { >>> - EFI_STATUS Status; >>> - UINT32 BlockSize; >>> - EFI_LBA EndLBA; >>> - EFI_LBA DescriptorLBAs[4]; >>> - UINTN Index; >>> + EFI_STATUS Status; >>> + UINT32 BlockSize; >>> + EFI_LBA EndLBA; >>> + EFI_LBA DescriptorLBAs[4]; >>> + UINTN Index; >>> + UDF_DESCRIPTOR_TAG *DescriptorTag; >>>=20 >>> BlockSize =3D BlockIo->Media->BlockSize; >>> EndLBA =3D BlockIo->Media->LastBlock; @@ -62,10 +63,13 @@=20 >>> FindAnchorVolumeDescriptorPointer ( >>> if (EFI_ERROR (Status)) { >>> return Status; >>> } >>> + >>> + DescriptorTag =3D &AnchorPoint->DescriptorTag; >>> + >>> // >>> // Check if read LBA has a valid AVDP descriptor=2E >>> // >>> - if (IS_AVDP (AnchorPoint)) { >>> + if (DescriptorTag->TagIdentifier =3D=3D >>UdfAnchorVolumeDescriptorPointer) { >>> return EFI_SUCCESS; >>> } >>> } >>> @@ -99,148 +103,98 @@ StartMainVolumeDescriptorSequence ( >>> OUT UDF_VOLUME_INFO *Volume >>> ) >>> { >>> - EFI_STATUS Status; >>> - UINT32 BlockSize; >>> - UDF_EXTENT_AD *ExtentAd; >>> - UINT64 StartingLsn; >>> - UINT64 EndingLsn; >>> - VOID *Buffer; >>> - UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; >>> - UDF_PARTITION_DESCRIPTOR *PartitionDesc; >>> - UINTN Index; >>> - UINT32 LogicalBlockSize; >>> + EFI_STATUS Status; >>> + UINT32 BlockSize; >>> + UDF_EXTENT_AD *ExtentAd; >>> + EFI_LBA SeqStartBlock; >>> + EFI_LBA SeqEndBlock; >>> + BOOLEAN StopSequence; >>> + VOID *Buffer; >>> + UDF_DESCRIPTOR_TAG *DescriptorTag; >>> + UINT32 LogicalBlockSize; >>> + >>> + BlockSize =3D BlockIo->Media->BlockSize; ExtentAd =3D=20 >>> + &AnchorPoint->MainVolumeDescriptorSequenceExtent; >>>=20 >>> // >>> - // We've already found an ADVP on the volume=2E It contains the >>extent >>> - // (MainVolumeDescriptorSequenceExtent) where the Main Volume=20 >>> Descriptor >>> - // Sequence starts=2E Therefore, we'll look for Logical Volume >>Descriptors and >>> - // Partitions Descriptors and save them in memory, accordingly=2E >>> - // >>> - // Note also that each descriptor will be aligned on a block size >>(BlockSize) >>> - // boundary, so we need to read one block at a time=2E >>> + // Allocate buffer for reading disk blocks >>> // >>> - BlockSize =3D BlockIo->Media->BlockSize; >>> - ExtentAd =3D &AnchorPoint->MainVolumeDescriptorSequenceExtent; >>> - StartingLsn =3D (UINT64)ExtentAd->ExtentLocation; >>> - EndingLsn =3D StartingLsn + DivU64x32 ( >>> - =20 >(UINT64)ExtentAd->ExtentLength, >>> - BlockSize >>> - ); >>> - >>> - Volume->LogicalVolDescs =3D >>> - (UDF_LOGICAL_VOLUME_DESCRIPTOR **)AllocateZeroPool (ExtentAd- >>> >ExtentLength); >>> - if (Volume->LogicalVolDescs =3D=3D NULL) { >>> - return EFI_OUT_OF_RESOURCES; >>> - } >>> - >>> - Volume->PartitionDescs =3D >>> - (UDF_PARTITION_DESCRIPTOR **)AllocateZeroPool (ExtentAd- >>> >ExtentLength); >>> - if (Volume->PartitionDescs =3D=3D NULL) { >>> - Status =3D EFI_OUT_OF_RESOURCES; >>> - goto Error_Alloc_Pds; >>> - } >>> - >>> - Buffer =3D AllocateZeroPool (BlockSize); >>> + Buffer =3D AllocateZeroPool ((UINTN)BlockSize); >>> if (Buffer =3D=3D NULL) { >>> - Status =3D EFI_OUT_OF_RESOURCES; >>> - goto Error_Alloc_Buf; >>> + return EFI_OUT_OF_RESOURCES; >>> } >>>=20 >>> - Volume->LogicalVolDescsNo =3D 0; >>> - Volume->PartitionDescsNo =3D 0; >>> - >>> - while (StartingLsn <=3D EndingLsn) { >>> - Status =3D DiskIo->ReadDisk ( >>> - DiskIo, >>> + // >>> + // The logical partition created by Partition driver is relative >>to the main >>> + // VDS extent location, so we start the Main Volume Descriptor >>Sequence at >>> + // LBA 0=2E >>> + // >>> + // We don't need to check again if we have valid Volume >>Descriptors here >>> since >>> + // Partition driver already did=2E >>> + // >>> + SeqStartBlock =3D 0; >>> + SeqEndBlock =3D SeqStartBlock + DivU64x32 >>((UINT64)ExtentAd->ExtentLength, >>> + BlockSize);=20 >StopSequence=20 >>> + =3D FALSE; for (; SeqStartBlock < SeqEndBlock && !StopSequence; >>SeqStartBlock++) { >>> + // >>> + // Read disk block >>> + // >>> + Status =3D BlockIo->ReadBlocks ( >>> + BlockIo, >>> BlockIo->Media->MediaId, >>> - MultU64x32 (StartingLsn, BlockSize), >>> + SeqStartBlock, >>> BlockSize, >>> Buffer >>> ); >>> if (EFI_ERROR (Status)) { >>> - goto Error_Read_Disk_Blk; >>> + goto Out_Free; >>> } >>>=20 >>> - if (IS_TD (Buffer)) { >>> + DescriptorTag =3D Buffer; >>> + >>> + switch (UDF_TAG_ID (DescriptorTag)) { >>> + case UdfPartitionDescriptor: >>> // >>> - // Found a Terminating Descriptor=2E Stop the sequence then=2E >>> + // Save Partition Descriptor >>> // >>> + CopyMem (&Volume->PartitionDesc, Buffer, sizeof (Volume- >>> >PartitionDesc)); >>> break; >>> - } >>>=20 >>> - if (IS_LVD (Buffer)) { >>> + case UdfLogicalVolumeDescriptor: >>> // >>> - // Found a Logical Volume Descriptor=2E >>> + // Save Logical Volume Descriptor >>> // >>> - LogicalVolDesc =3D >>> - (UDF_LOGICAL_VOLUME_DESCRIPTOR *) >>> - AllocateZeroPool (sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR)); >>> - if (LogicalVolDesc =3D=3D NULL) { >>> - Status =3D EFI_OUT_OF_RESOURCES; >>> - goto Error_Alloc_Lvd; >>> - } >>> + CopyMem (&Volume->LogicalVolDesc, Buffer, sizeof (Volume- >>> >LogicalVolDesc)); >>> + break; >>>=20 >>> - CopyMem ((VOID *)LogicalVolDesc, Buffer, >>> - sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR)); >>> - Volume->LogicalVolDescs[Volume->LogicalVolDescsNo++] =3D >>> LogicalVolDesc; >>> - } else if (IS_PD (Buffer)) { >>> - // >>> - // Found a Partition Descriptor=2E >>> - // >>> - PartitionDesc =3D >>> - (UDF_PARTITION_DESCRIPTOR *) >>> - AllocateZeroPool (sizeof (UDF_PARTITION_DESCRIPTOR)); >>> - if (PartitionDesc =3D=3D NULL) { >>> - Status =3D EFI_OUT_OF_RESOURCES; >>> - goto Error_Alloc_Pd; >>> - } >>> + case UdfTerminatingDescriptor: >>> + StopSequence =3D TRUE; >>> + break; >>>=20 >>> - CopyMem ((VOID *)PartitionDesc, Buffer, >>> - sizeof (UDF_PARTITION_DESCRIPTOR)); >>> - Volume->PartitionDescs[Volume->PartitionDescsNo++] =3D >>PartitionDesc; >>> + default: >>> + ; >>> } >>> - >>> - StartingLsn++; >>> } >>>=20 >>> // >>> - // When an UDF volume (revision 2=2E00 or higher) contains a File >>Entry rather >>> - // than an Extended File Entry (which is not recommended as per >>spec), we >>> need >>> - // to make sure the size of a FE will be _at least_ 2048 >>> - // (UDF_LOGICAL_SECTOR_SIZE) bytes long to keep backward >>compatibility=2E >>> + // Determine FE (File Entry) size >>> // >>> - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); >>> + LogicalBlockSize =3D Volume->LogicalVolDesc=2ELogicalBlockSize; >>> if (LogicalBlockSize >=3D UDF_LOGICAL_SECTOR_SIZE) { >>> - Volume->FileEntrySize =3D LogicalBlockSize; >>> + Volume->FileEntrySize =3D (UINTN)LogicalBlockSize; >>> } else { >>> Volume->FileEntrySize =3D UDF_LOGICAL_SECTOR_SIZE; >>> } >>>=20 >>> - FreePool (Buffer); >>> + Status =3D EFI_SUCCESS; >>>=20 >>> - return EFI_SUCCESS; >>> - >>> -Error_Alloc_Pd: >>> -Error_Alloc_Lvd: >>> - for (Index =3D 0; Index < Volume->PartitionDescsNo; Index++) { >>> - FreePool ((VOID *)Volume->PartitionDescs[Index]); >>> - } >>> - >>> - for (Index =3D 0; Index < Volume->LogicalVolDescsNo; Index++) { >>> - FreePool ((VOID *)Volume->LogicalVolDescs[Index]); >>> - } >>> - >>> -Error_Read_Disk_Blk: >>> +Out_Free: >>> + // >>> + // Free block read buffer >>> + // >>> FreePool (Buffer); >>>=20 >>> -Error_Alloc_Buf: >>> - FreePool ((VOID *)Volume->PartitionDescs); >>> - Volume->PartitionDescs =3D NULL; >>> - >>> -Error_Alloc_Pds: >>> - FreePool ((VOID *)Volume->LogicalVolDescs); >>> - Volume->LogicalVolDescs =3D NULL; >>> - >>> return Status; >>> } >>>=20 >>> @@ -262,48 +216,53 @@ GetPdFromLongAd ( >>> ) >>> { >>> UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; >>> - UINTN Index; >>> - UDF_PARTITION_DESCRIPTOR *PartitionDesc; >>> UINT16 PartitionNum; >>>=20 >>> - LogicalVolDesc =3D Volume->LogicalVolDescs[UDF_DEFAULT_LV_NUM]; >>> + LogicalVolDesc =3D &Volume->LogicalVolDesc; >>>=20 >>> - switch (LV_UDF_REVISION (LogicalVolDesc)) { >>> + switch (UDF_LVD_REVISION (LogicalVolDesc)) { >>> case 0x0102: >>> + case 0x0150: >>> + case 0x0200: >>> + case 0x0201: >>> + case 0x0250: >>> + case 0x0260: >>> // >>> - // As per UDF 1=2E02 specification: >>> + // UDF 1=2E02 specification: >>> // >>> // There shall be exactly one prevailing Logical Volume >>Descriptor recorded >>> // per Volume Set=2E The Partition Maps field shall contain only >>Type 1 >>> // Partition Maps=2E >>> // >>> - PartitionNum =3D *(UINT16 >>*)((UINTN)&LogicalVolDesc->PartitionMaps[4]); >>> - break; >>> - case 0x0150: >>> + // UDF 1=2E50 through 2=2E60 specs say: >>> // >>> - // Ensure Type 1 Partition map=2E Other types aren't supported in >>this >>> - // implementation=2E >>> + // For the purpose of interchange partition maps shall be >>limited to >>> + // Partition Map type 1, except type 2 maps as described in the >>document=2E >>> + // >>> + // NOTE: Only one Type 1 (Physical) Partition is supported=2E It >>has been >>> + // checked already in Partition driver for existence of a >single >>Type 1 >>> + // Partition map, so we don't have to double check here=2E >>> + // >>> + // Partition reference number can also be retrieved from >>> + // LongAd->ExtentLocation=2EPartitionReferenceNumber, however the >>spec >>> says >>> + // it may be 0, so let's not rely on it=2E >>> // >>> - if (LogicalVolDesc->PartitionMaps[0] !=3D 1 || >>> - LogicalVolDesc->PartitionMaps[1] !=3D 6) { >>> - return NULL; >>> - } >>> PartitionNum =3D *(UINT16 >>*)((UINTN)&LogicalVolDesc->PartitionMaps[4]); >>> break; >>> - case 0x0260: >>> + >>> + default: >>> // >>> - // Fall through=2E >>> + // Unsupported UDF revision >>> // >>> - default: >>> - PartitionNum =3D LongAd->ExtentLocation=2EPartitionReferenceNumbe= r; >>> - break; >>> + return NULL; >>> } >>>=20 >>> - =20 --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E