From nobody Sat Apr 27 21:01:20 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1505654167972814.8170174125931; Sun, 17 Sep 2017 06:16:07 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9674B21E9781D; Sun, 17 Sep 2017 06:13:02 -0700 (PDT) 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 B530B21E8799F for ; Sun, 17 Sep 2017 06:13:00 -0700 (PDT) Received: from localhost.localdomain ([IPv6:2804:7f4:c480:8f0c:0:0:0:2]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id v8HDDhe6002117 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 17 Sep 2017 06:13:50 -0700 X-Original-To: edk2-devel@lists.01.org From: Paulo Alcantara To: edk2-devel@lists.01.org Date: Sun, 17 Sep 2017 10:13:26 -0300 Message-Id: <37b896c68ff32f81de986b0997f309325bd6ca67.1505653040.git.pcacjr@zytor.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v2 1/3] MdePkg: Add UDF volume structure definitions 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: , Cc: Michael D Kinney , Laszlo Ersek , Ruiyu Ni , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch adds a fewe more UDF structures in order to detect Logical Volume and Partition descriptors during Main Volume Descriptor Sequence in Partition driver. Cc: Michael D Kinney Cc: Liming Gao Cc: Laszlo Ersek Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Paulo Alcantara Reported-by: Ruiyu Ni --- MdePkg/Include/IndustryStandard/Udf.h | 63 ++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/MdePkg/Include/IndustryStandard/Udf.h b/MdePkg/Include/Industr= yStandard/Udf.h index 0febb4bcda..6cc42f8543 100644 --- a/MdePkg/Include/IndustryStandard/Udf.h +++ b/MdePkg/Include/IndustryStandard/Udf.h @@ -27,9 +27,19 @@ #define _GET_TAG_ID(_Pointer) \ (((UDF_DESCRIPTOR_TAG *)(_Pointer))->TagIdentifier) =20 +#define IS_PD(_Pointer) \ + ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 5)) +#define IS_LVD(_Pointer) \ + ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 6)) +#define IS_TD(_Pointer) \ + ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 8)) + #define IS_AVDP(_Pointer) \ ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 2)) =20 +#define LV_UDF_REVISION(_Lv) \ + *(UINT16 *)(UINTN)(_Lv)->DomainIdentifier.IdentifierSuffix + #pragma pack(1) =20 typedef struct { @@ -55,6 +65,59 @@ typedef struct { UINT8 Reserved[480]; } UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER; =20 +typedef struct { + UINT8 CharacterSetType; + UINT8 CharacterSetInfo[63]; +} UDF_CHAR_SPEC; + +typedef struct { + UINT8 Flags; + UINT8 Identifier[23]; + UINT8 IdentifierSuffix[8]; +} UDF_ENTITY_ID; + +typedef struct { + UINT32 LogicalBlockNumber; + UINT16 PartitionReferenceNumber; +} UDF_LB_ADDR; + +typedef struct { + UINT32 ExtentLength; + UDF_LB_ADDR ExtentLocation; + UINT8 ImplementationUse[6]; +} UDF_LONG_ALLOCATION_DESCRIPTOR; + +typedef struct { + UDF_DESCRIPTOR_TAG DescriptorTag; + UINT32 VolumeDescriptorSequenceNumber; + UDF_CHAR_SPEC DescriptorCharacterSet; + UINT8 LogicalVolumeIdentifier[128]; + UINT32 LogicalBlockSize; + UDF_ENTITY_ID DomainIdentifier; + UDF_LONG_ALLOCATION_DESCRIPTOR LogicalVolumeContentsUse; + UINT32 MapTableLength; + UINT32 NumberOfPartitionMaps; + UDF_ENTITY_ID ImplementationIdentifier; + UINT8 ImplementationUse[128]; + UDF_EXTENT_AD IntegritySequenceExtent; + UINT8 PartitionMaps[6]; +} UDF_LOGICAL_VOLUME_DESCRIPTOR; + +typedef struct { + UDF_DESCRIPTOR_TAG DescriptorTag; + UINT32 VolumeDescriptorSequenceNumber; + UINT16 PartitionFlags; + UINT16 PartitionNumber; + UDF_ENTITY_ID PartitionContents; + UINT8 PartitionContentsUse[128]; + UINT32 AccessType; + UINT32 PartitionStartingLocation; + UINT32 PartitionLength; + UDF_ENTITY_ID ImplementationIdentifier; + UINT8 ImplementationUse[128]; + UINT8 Reserved[156]; +} UDF_PARTITION_DESCRIPTOR; + #pragma pack() =20 #endif --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Apr 27 21:01:20 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1505654170914975.1117967097464; Sun, 17 Sep 2017 06:16:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D3AC621E97813; Sun, 17 Sep 2017 06:13:05 -0700 (PDT) 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 BF37821E977FF for ; Sun, 17 Sep 2017 06:13:04 -0700 (PDT) Received: from localhost.localdomain ([IPv6:2804:7f4:c480:8f0c:0:0:0:2]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id v8HDDhe7002117 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 17 Sep 2017 06:13:53 -0700 X-Original-To: edk2-devel@lists.01.org From: Paulo Alcantara To: edk2-devel@lists.01.org Date: Sun, 17 Sep 2017 10:13:27 -0300 Message-Id: <1321928015f9ed919425051e0d75c132de77348c.1505653040.git.pcacjr@zytor.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v2 2/3] 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: , Cc: Ruiyu Ni , Laszlo Ersek , Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Do not use entire block device size for the UDF logical partition, instead reserve the appropriate space (LVD space) for it. Cc: Eric Dong Cc: Ruiyu Ni Cc: Star Zeng Cc: Laszlo Ersek Reported-by: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Paulo Alcantara --- MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 323 ++++++++++++++++++-- 1 file changed, 299 insertions(+), 24 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/= Universal/Disk/PartitionDxe/Udf.c index 7856b5dfc1..3e84882922 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c @@ -84,24 +84,8 @@ FindAnchorVolumeDescriptorPointer ( return EFI_VOLUME_CORRUPTED; } =20 -/** - Check if block device supports a valid UDF file system as specified by O= STA - Universal Disk Format Specification 2.60. - - @param[in] BlockIo BlockIo interface. - @param[in] DiskIo DiskIo interface. - - @retval EFI_SUCCESS UDF file system found. - @retval EFI_UNSUPPORTED UDF file system not found. - @retval EFI_NO_MEDIA The device has no media. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_OUT_OF_RESOURCES The scan was not successful due to lack of - resources. - -**/ EFI_STATUS -SupportUdfFileSystem ( +FindUdfVolumeIdentifiers ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo ) @@ -111,7 +95,6 @@ SupportUdfFileSystem ( UINT64 EndDiskOffset; CDROM_VOLUME_DESCRIPTOR VolDescriptor; CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor; - UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; =20 ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof (CDROM_VOLUME_DESCRIP= TOR)); =20 @@ -207,12 +190,302 @@ SupportUdfFileSystem ( return EFI_UNSUPPORTED; } =20 + return EFI_SUCCESS; +} + +EFI_STATUS +GetPartitionNumber ( + IN UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc, + OUT UINT16 *PartitionNum + ) +{ + EFI_STATUS Status; + UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd; + + Status =3D EFI_SUCCESS; + + switch (LV_UDF_REVISION (LogicalVolDesc)) { + case 0x0102: + // + // UDF 1.20 only supports Type 1 Partition + // + *PartitionNum =3D *(UINT16 *)((UINTN)&LogicalVolDesc->PartitionMaps[4]= ); + break; + case 0x0150: + // + // Ensure Type 1 Partition map + // + ASSERT (LogicalVolDesc->PartitionMaps[0] =3D=3D 1 && + LogicalVolDesc->PartitionMaps[1] =3D=3D 6); + *PartitionNum =3D *(UINT16 *)((UINTN)&LogicalVolDesc->PartitionMaps[4]= ); + break; + case 0x0260: + LongAd =3D &LogicalVolDesc->LogicalVolumeContentsUse; + *PartitionNum =3D LongAd->ExtentLocation.PartitionReferenceNumber; + break; + default: + // + // Unhandled UDF revision + // + Status =3D EFI_VOLUME_CORRUPTED; + break; + } + + return Status; +} + +EFI_STATUS +FindLogicalVolumeLocation ( + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + IN UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint, + OUT UINT64 *MainVdsStartLsn, + OUT UINT64 *LogicalVolEndLsn + ) +{ + EFI_STATUS Status; + UINT32 BlockSize; + EFI_LBA LastBlock; + UDF_EXTENT_AD *ExtentAd; + UINT64 StartingLsn; + UINT64 EndingLsn; + VOID *Buffer; + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; + UDF_PARTITION_DESCRIPTOR *PartitionDesc; + UINT64 GuardMainVdsStartLsn; + UINT16 PartitionNum; + + BlockSize =3D BlockIo->Media->BlockSize; + LastBlock =3D BlockIo->Media->LastBlock; + ExtentAd =3D &AnchorPoint->MainVolumeDescriptorSequenceExte= nt; + StartingLsn =3D (UINT64)ExtentAd->ExtentLocation; + EndingLsn =3D + StartingLsn + DivU64x32 ((UINT64)ExtentAd->ExtentLength, BlockSize); + + LogicalVolDesc =3D NULL; + PartitionDesc =3D NULL; + GuardMainVdsStartLsn =3D StartingLsn; + + // + // Allocate buffer for reading disk blocks + // + Buffer =3D AllocateZeroPool (BlockSize); + if (Buffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status =3D EFI_VOLUME_CORRUPTED; + + // + // As per UDF 2.60 specification: + // + // There shall be exactly one prevailing Logical Volume Descriptor + // recorded per Volume Set. + // + // Start Main Volume Descriptor Sequence and find Logical Volume Descrip= tor + // + while (StartingLsn <=3D EndingLsn) { + // + // Read disk block + // + Status =3D DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (StartingLsn, BlockSize), + BlockSize, + Buffer + ); + if (EFI_ERROR (Status)) { + goto Out_Free; + } + + // + // Check if read block is a Terminating Descriptor + // + if (IS_TD (Buffer)) { + // + // Stop Main Volume Descriptor Sequence + // + break; + } + + // + // Check if read block is a Logical Volume Descriptor + // + if (IS_LVD (Buffer)) { + // + // Ensure only one LVD (Logical Volume Descriptor) is handled + // + if (LogicalVolDesc !=3D NULL) { + Status =3D EFI_UNSUPPORTED; + goto Out_Free; + } + + // + // As per UDF 2.60 specification: + // + // For the purpose of interchange, Partition Maps shall be limited to + // Partition Map type 1, except type 2 maps. + // + // NOTE: Type 1 Partitions are the only supported in this implementa= tion. + // + LogicalVolDesc =3D AllocateZeroPool (sizeof (*LogicalVolDesc)); + if (LogicalVolDesc =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Out_Free; + } + + // + // Save Logical Volume Descriptor + // + CopyMem (LogicalVolDesc, Buffer, sizeof (*LogicalVolDesc)); + } else if (IS_PD (Buffer)) { + // + // Ensure only one PD (Partition Descriptor) is handled + // + if (PartitionDesc !=3D NULL) { + Status =3D EFI_UNSUPPORTED; + goto Out_Free; + } + + // + // Found a Partition Descriptor. + // + // As per UDF 2.60 specification: + // + // A Partition Descriptor Access Type of read-only, rewritable, + // overwritable, write-once and pseudo-overwritable shall be + // supported. There shall be exactly one prevailing Partition + // Descriptor recorded per volume, with one exception. For Volume + // Sets that consist of single volume, the volume may contain 2 non- + // overlapping Partitions with 2 prevailing Partition Descriptors on= ly + // if one has an Access Type of read-only and the other has an + // Access Type of rewritable, overwritable, or write-once. The + // Logical Volume for this volume would consist of the contents of + // both partitions. + // + PartitionDesc =3D AllocateZeroPool (sizeof (*PartitionDesc)); + if (PartitionDesc =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Out_Free; + } + + // + // Save Partition Descriptor + // + CopyMem (PartitionDesc, Buffer, sizeof (*PartitionDesc)); + } + // + // Go to next disk block + // + StartingLsn++; + } + + Status =3D EFI_VOLUME_CORRUPTED; + + // + // Check if LVD and PD were found + // + if (LogicalVolDesc !=3D NULL && PartitionDesc !=3D NULL) { + // + // Get partition number from Partition map in LVD descriptor + // + Status =3D GetPartitionNumber (LogicalVolDesc, &PartitionNum); + if (EFI_ERROR (Status)) { + goto Out_Free; + } + + // + // Make sure we're handling expected Partition Descriptor + // + if (PartitionDesc->PartitionNumber !=3D PartitionNum) { + Status =3D EFI_VOLUME_CORRUPTED; + goto Out_Free; + } + + // + // Cover the main VDS area so UdfDxe driver will also be able to get L= VD and + // PD descriptors out from the file system. + // + *MainVdsStartLsn =3D GuardMainVdsStartLsn; + *LogicalVolEndLsn =3D *MainVdsStartLsn + (UINT64)ExtentAd->ExtentLengt= h; + + // + // Cover UDF partition area + // + *LogicalVolEndLsn +=3D + ((UINT64)PartitionDesc->PartitionStartingLocation - + *LogicalVolEndLsn) + PartitionDesc->PartitionLength - 1; + // + // Ensure to not attempt reading past end of device + // + if (*LogicalVolEndLsn > LastBlock) { + Status =3D EFI_VOLUME_CORRUPTED; + } else { + Status =3D EFI_SUCCESS; + } + } + +Out_Free: + // + // Free block read buffer + // + FreePool (Buffer); + // + // Free Logical Volume Descriptor + // + if (LogicalVolDesc !=3D NULL) { + FreePool (LogicalVolDesc); + } + // + // Free Partition Descriptor + // + if (PartitionDesc !=3D NULL) { + FreePool (PartitionDesc); + } + + return Status; +} + +EFI_STATUS +FindUdfLogicalVolume ( + 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 (EFI_ERROR (Status)) { + return Status; + } + + // + // Find Anchor Volume Descriptor Pointer + // Status =3D FindAnchorVolumeDescriptorPointer (BlockIo, DiskIo, &AnchorPo= int); 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 /** @@ -250,6 +523,8 @@ PartitionInstallUdfChildHandles ( EFI_GUID *VendorDefinedGuid; EFI_GUID UdfDevPathGuid =3D EFI_UDF_DEVICE_PATH_GUID; EFI_PARTITION_INFO_PROTOCOL PartitionInfo; + EFI_LBA StartingLBA; + EFI_LBA EndingLBA; =20 Media =3D BlockIo->Media; =20 @@ -291,9 +566,9 @@ PartitionInstallUdfChildHandles ( } =20 // - // Check if block device supports an UDF file system + // Find UDF logical volume on block device // - Status =3D SupportUdfFileSystem (BlockIo, DiskIo); + Status =3D FindUdfLogicalVolume (BlockIo, DiskIo, &StartingLBA, &EndingL= BA); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } @@ -318,8 +593,8 @@ PartitionInstallUdfChildHandles ( DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath, &PartitionInfo, - 0, - Media->LastBlock, + StartingLBA, + EndingLBA, Media->BlockSize ); if (!EFI_ERROR (Status)) { --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Apr 27 21:01:20 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1505654173912426.10317386302586; Sun, 17 Sep 2017 06:16:13 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1AE2021E945E2; Sun, 17 Sep 2017 06:13:10 -0700 (PDT) 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 DA53F21E8799F for ; Sun, 17 Sep 2017 06:13:08 -0700 (PDT) Received: from localhost.localdomain ([IPv6:2804:7f4:c480:8f0c:0:0:0:2]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id v8HDDhe8002117 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 17 Sep 2017 06:13:56 -0700 X-Original-To: edk2-devel@lists.01.org From: Paulo Alcantara To: edk2-devel@lists.01.org Date: Sun, 17 Sep 2017 10:13:28 -0300 Message-Id: <600e6e752b285bbe960ad22d8ae969cbbd84b85b.1505653040.git.pcacjr@zytor.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v2 3/3] MdeModulePkg/UdfDxe: Rework driver to support PartitionDxe changes 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: , Cc: Ruiyu Ni , Laszlo Ersek , Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch reworks the driver to support Partition driver changes. Cc: Eric Dong Cc: Paulo Alcantara Cc: Ruiyu Ni Cc: Star Zeng Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Paulo Alcantara Reported-by: Ruiyu Ni --- MdeModulePkg/Universal/Disk/UdfDxe/File.c | 13 +- MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 515 ++++++++--= ---------- MdeModulePkg/Universal/Disk/UdfDxe/Udf.c | 7 - MdeModulePkg/Universal/Disk/UdfDxe/Udf.h | 88 +--- 4 files changed, 204 insertions(+), 419 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c b/MdeModulePkg/Unive= rsal/Disk/UdfDxe/File.c index 01361141bb..f2c62967e8 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/File.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c @@ -100,6 +100,7 @@ UdfOpenVolume ( &PrivFsData->Volume, &PrivFsData->Root ); + ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { goto Error_Find_Root_Dir; } @@ -131,7 +132,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: @@ -528,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 @@ -541,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->Simpl= eFs); - if (!PrivFileData->IsRootDirectory) { CleanupFileInformation (&PrivFileData->File); =20 @@ -551,10 +548,6 @@ UdfClose ( } } =20 - if (--PrivFsData->OpenFiles =3D=3D 0) { - CleanupVolumeInformation (&PrivFsData->Volume); - } - FreePool ((VOID *)PrivFileData); =20 Exit: @@ -787,7 +780,7 @@ UdfGetInfo ( } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { String =3D VolumeLabel; =20 - FileSetDesc =3D PrivFsData->Volume.FileSetDescs[0]; + FileSetDesc =3D &PrivFsData->Volume.FileSetDesc; =20 OstaCompressed =3D &FileSetDesc->LogicalVolumeIdentifier[0]; =20 @@ -846,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.LogicalVolDesc.LogicalBlockSize; FileSystemInfo->VolumeSize =3D VolumeSize; FileSystemInfo->FreeSpace =3D FreeSpaceSize; =20 diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/Md= eModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c index 4609580b30..63b643e60a 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c @@ -60,154 +60,111 @@ FindAnchorVolumeDescriptorPointer ( =20 EFI_STATUS StartMainVolumeDescriptorSequence ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint, - OUT UDF_VOLUME_INFO *Volume + IN EFI_BLOCK_IO_PROTOCOL *BlockIo, + IN EFI_DISK_IO_PROTOCOL *DiskIo, + 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; + UINT64 BlockOffset; + VOID *Buffer; + UINT32 LogicalBlockSize; + + BlockSize =3D BlockIo->Media->BlockSize; =20 // - // We've already found an ADVP on the volume. It contains the extent - // (MainVolumeDescriptorSequenceExtent) where the Main Volume Descriptor - // Sequence starts. Therefore, we'll look for Logical Volume Descriptors= and - // Partitions Descriptors and save them in memory, accordingly. - // - // Note also that each descriptor will be aligned on a block size (Block= Size) - // boundary, so we need to read one block at a time. + // Allocate buffer for reading disk blocks // - BlockSize =3D BlockIo->Media->BlockSize; - ExtentAd =3D &AnchorPoint->MainVolumeDescriptorSequenceExtent; - StartingLsn =3D (UINT64)ExtentAd->ExtentLocation; - EndingLsn =3D StartingLsn + DivU64x32 ( - (UINT64)ExtentAd->ExtentLength, - BlockSize - ); - - Volume->LogicalVolDescs =3D - (UDF_LOGICAL_VOLUME_DESCRIPTOR **)AllocateZeroPool (ExtentAd->ExtentLe= ngth); - 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) { + // + // As per UDF 2.60 specification: + // + // --- + // For the purpose of interchange, Partition Maps shall be limited to + // Partition Map type 1, except type 2 maps. + // --- + // A Partition Descriptor Access Type of read-only, rewritable, + // overwritable, write-once and pseudo-overwritable shall be + // supported. There shall be exactly one prevailing Partition + // Descriptor recorded per volume, with one exception. For Volume + // Sets that consist of single volume, the volume may contain 2 non- + // overlapping Partitions with 2 prevailing Partition Descriptors only + // if one has an Access Type of read-only and the other has an + // Access Type of rewritable, overwritable, or write-once. The + // Logical Volume for this volume would consist of the contents of + // both partitions. + // --- + // + // 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. + // + // We don't need to make sure we got both LVD and PD -- that is, if we a= re + // here, that means Partition driver was able to find them both previous= ly. + // + for (BlockOffset =3D 0; + BlockOffset < MultU64x32 (BlockIo->Media->LastBlock, + BlockIo->Media->BlockSize); + BlockOffset +=3D BlockSize) { + // Read disk block + // Status =3D DiskIo->ReadDisk ( DiskIo, BlockIo->Media->MediaId, - MultU64x32 (StartingLsn, BlockSize), + BlockOffset, BlockSize, Buffer ); if (EFI_ERROR (Status)) { - goto Error_Read_Disk_Blk; + goto Out_Free; } =20 + // + // Check if read block is a Terminating Descriptor + // if (IS_TD (Buffer)) { // - // Found a Terminating Descriptor. Stop the sequence then. + // Terminate Main Volume Descriptor Sequence // break; } =20 if (IS_LVD (Buffer)) { // - // Found a Logical Volume Descriptor. + // 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 ((VOID *)LogicalVolDesc, Buffer, - sizeof (UDF_LOGICAL_VOLUME_DESCRIPTOR)); - Volume->LogicalVolDescs[Volume->LogicalVolDescsNo++] =3D LogicalVolD= esc; + CopyMem (&Volume->LogicalVolDesc, Buffer, sizeof (Volume->LogicalVol= Desc)); } else if (IS_PD (Buffer)) { // - // Found a Partition Descriptor. + // Save Partition Descriptor // - 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; - } - - CopyMem ((VOID *)PartitionDesc, Buffer, - sizeof (UDF_PARTITION_DESCRIPTOR)); - Volume->PartitionDescs[Volume->PartitionDescsNo++] =3D PartitionDesc; + CopyMem (&Volume->PartitionDesc, Buffer, sizeof (Volume->PartitionDe= sc)); } - - StartingLsn++; } =20 // - // When an UDF volume (revision 2.00 or higher) contains a File Entry ra= ther - // than an Extended File Entry (which is not recommended as per spec), w= e need - // to make sure the size of a FE will be _at least_ 2048 - // (UDF_LOGICAL_SECTOR_SIZE) bytes long to keep backward compatibility. + // Determine FE (File Entry) size // - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); + LogicalBlockSize =3D Volume->LogicalVolDesc.LogicalBlockSize; 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); - - 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]); - } + Status =3D EFI_SUCCESS; =20 -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 @@ -223,11 +180,9 @@ 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)) { case 0x0102: @@ -252,19 +207,21 @@ GetPdFromLongAd ( PartitionNum =3D *(UINT16 *)((UINTN)&LogicalVolDesc->PartitionMaps[4]); break; case 0x0260: - // - // Fall through. - // - default: PartitionNum =3D LongAd->ExtentLocation.PartitionReferenceNumber; break; + default: + // + // Unhandled UDF revision + // + return NULL; } =20 - for (Index =3D 0; Index < Volume->PartitionDescsNo; Index++) { - PartitionDesc =3D Volume->PartitionDescs[Index]; - if (PartitionDesc->PartitionNumber =3D=3D PartitionNum) { - return PartitionDesc; - } + // + // Check if partition number matches Partition Descriptor found in Main = Volume + // Descriptor Sequence. + // + if (Volume->PartitionDesc.PartitionNumber =3D=3D PartitionNum) { + return &Volume->PartitionDesc; } =20 return NULL; @@ -284,8 +241,9 @@ GetLongAdLsn ( PartitionDesc =3D GetPdFromLongAd (Volume, LongAd); ASSERT (PartitionDesc !=3D NULL); =20 - return (UINT64)PartitionDesc->PartitionStartingLocation + - LongAd->ExtentLocation.LogicalBlockNumber; + return (UINT64)PartitionDesc->PartitionStartingLocation - + Volume->MainVdsStartLocation + + LongAd->ExtentLocation.LogicalBlockNumber; } =20 // @@ -293,12 +251,13 @@ GetLongAdLsn ( // UINT64 GetShortAdLsn ( + IN UDF_VOLUME_INFO *Volume, IN UDF_PARTITION_DESCRIPTOR *PartitionDesc, IN UDF_SHORT_ALLOCATION_DESCRIPTOR *ShortAd ) { - return (UINT64)PartitionDesc->PartitionStartingLocation + - ShortAd->ExtentPosition; + return (UINT64)PartitionDesc->PartitionStartingLocation - + Volume->MainVdsStartLocation + ShortAd->ExtentPosition; } =20 // @@ -311,36 +270,39 @@ EFI_STATUS FindFileSetDescriptor ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN UDF_VOLUME_INFO *Volume, - IN UINTN LogicalVolDescNum, - OUT UDF_FILE_SET_DESCRIPTOR *FileSetDesc + IN UDF_VOLUME_INFO *Volume ) { EFI_STATUS Status; UINT64 Lsn; UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; =20 - LogicalVolDesc =3D Volume->LogicalVolDescs[LogicalVolDescNum]; + LogicalVolDesc =3D &Volume->LogicalVolDesc; Lsn =3D GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse); =20 // - // Read extent (Long Ad). + // As per UDF 2.60 specification: + // + // There shall be exactly one File Set Descriptor recorded per Logical + // Volume. + // + // Read disk block // Status =3D DiskIo->ReadDisk ( DiskIo, BlockIo->Media->MediaId, MultU64x32 (Lsn, LogicalVolDesc->LogicalBlockSize), - sizeof (UDF_FILE_SET_DESCRIPTOR), - (VOID *)FileSetDesc + sizeof (Volume->FileSetDesc), + &Volume->FileSetDesc ); if (EFI_ERROR (Status)) { return Status; } =20 // - // Check if the read extent contains a valid FSD's tag identifier. + // Check if read block is a File Set Descriptor // - if (!IS_FSD (FileSetDesc)) { + if (!IS_FSD (&Volume->FileSetDesc)) { return EFI_VOLUME_CORRUPTED; } =20 @@ -348,71 +310,6 @@ FindFileSetDescriptor ( } =20 // -// Get all File Set Descriptors for each Logical Volume Descriptor. -// -EFI_STATUS -GetFileSetDescriptors ( - IN EFI_BLOCK_IO_PROTOCOL *BlockIo, - IN EFI_DISK_IO_PROTOCOL *DiskIo, - IN OUT UDF_VOLUME_INFO *Volume - ) -{ - EFI_STATUS Status; - UINTN Index; - UDF_FILE_SET_DESCRIPTOR *FileSetDesc; - UINTN Count; - - Volume->FileSetDescs =3D - (UDF_FILE_SET_DESCRIPTOR **)AllocateZeroPool ( - Volume->LogicalVolDescsNo * sizeof (UDF_FILE_SET_DESCRIPTOR)); - if (Volume->FileSetDescs =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - for (Index =3D 0; Index < Volume->LogicalVolDescsNo; Index++) { - FileSetDesc =3D AllocateZeroPool (sizeof (UDF_FILE_SET_DESCRIPTOR)); - if (FileSetDesc =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto Error_Alloc_Fsd; - } - - // - // Find a FSD for this LVD. - // - Status =3D FindFileSetDescriptor ( - BlockIo, - DiskIo, - Volume, - Index, - FileSetDesc - ); - if (EFI_ERROR (Status)) { - goto Error_Find_Fsd; - } - - // - // Got one. Save it. - // - Volume->FileSetDescs[Index] =3D FileSetDesc; - } - - Volume->FileSetDescsNo =3D Volume->LogicalVolDescsNo; - return EFI_SUCCESS; - -Error_Find_Fsd: - Count =3D Index + 1; - for (Index =3D 0; Index < Count; Index++) { - FreePool ((VOID *)Volume->FileSetDescs[Index]); - } - - FreePool ((VOID *)Volume->FileSetDescs); - Volume->FileSetDescs =3D NULL; - -Error_Alloc_Fsd: - return Status; -} - -// // Read Volume and File Structure on an UDF file system. // EFI_STATUS @@ -424,9 +321,10 @@ ReadVolumeFileStructure ( { EFI_STATUS Status; UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint; + UDF_EXTENT_AD *ExtentAd; =20 // - // Find an AVDP. + // Find Anchor Volume Descriptor Pointer // Status =3D FindAnchorVolumeDescriptorPointer ( BlockIo, @@ -438,12 +336,18 @@ ReadVolumeFileStructure ( } =20 // - // AVDP has been found. Start MVDS. + // Save Main VDS start block number + // + ExtentAd =3D &AnchorPoint.MainVolumeDescriptorSequenceExtent; + + Volume->MainVdsStartLocation =3D (UINT64)ExtentAd->ExtentLocation; + + // + // Start Main Volume Descriptor Sequence. // Status =3D StartMainVolumeDescriptorSequence ( BlockIo, DiskIo, - &AnchorPoint, Volume ); if (EFI_ERROR (Status)) { @@ -699,6 +603,7 @@ GetAllocationDescriptorLsn ( return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad); } else if (RecordingFlags =3D=3D SHORT_ADS_SEQUENCE) { return GetShortAdLsn ( + Volume, GetPdFromLongAd (Volume, ParentIcb), (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad ); @@ -740,7 +645,7 @@ GetAedAdsOffset ( return EFI_OUT_OF_RESOURCES; } =20 - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); + LogicalBlockSize =3D Volume->LogicalVolDesc.LogicalBlockSize; =20 // // Read extent. @@ -890,7 +795,7 @@ ReadFile ( UINT32 ExtentLength; UDF_FE_RECORDING_FLAGS RecordingFlags; =20 - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); + LogicalBlockSize =3D Volume->LogicalVolDesc.LogicalBlockSize; DoFreeAed =3D FALSE; =20 // @@ -1355,6 +1260,9 @@ ReadUdfVolumeInformation ( { EFI_STATUS Status; =20 + // + // Read all necessary UDF volume information and keep it private to the = driver + // Status =3D ReadVolumeFileStructure ( BlockIo, DiskIo, @@ -1364,13 +1272,12 @@ ReadUdfVolumeInformation ( return Status; } =20 - Status =3D GetFileSetDescriptors ( - BlockIo, - DiskIo, - Volume - ); + // + // Find File Set Descriptor + // + Status =3D FindFileSetDescriptor (BlockIo, DiskIo, Volume); if (EFI_ERROR (Status)) { - CleanupVolumeInformation (Volume); + return Status; } =20 return Status; @@ -1407,7 +1314,7 @@ FindRootDirectory ( BlockIo, DiskIo, Volume, - &Volume->FileSetDescs[0]->RootDirectoryIcb, + &Volume->FileSetDesc.RootDirectoryIcb, &File->FileEntry ); if (EFI_ERROR (Status)) { @@ -1424,7 +1331,7 @@ FindRootDirectory ( L"\\", NULL, &Parent, - &Volume->FileSetDescs[0]->RootDirectoryIcb, + &Volume->FileSetDesc.RootDirectoryIcb, File ); if (EFI_ERROR (Status)) { @@ -1465,7 +1372,7 @@ FindFileEntry ( UINT32 LogicalBlockSize; =20 Lsn =3D GetLongAdLsn (Volume, Icb); - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); + LogicalBlockSize =3D Volume->LogicalVolDesc.LogicalBlockSize; =20 *FileEntry =3D AllocateZeroPool (Volume->FileEntrySize); if (*FileEntry =3D=3D NULL) { @@ -1959,43 +1866,6 @@ Error_Find_File: } =20 /** - Clean up in-memory UDF volume information. - - @param[in] Volume Volume information pointer. - -**/ -VOID -CleanupVolumeInformation ( - IN UDF_VOLUME_INFO *Volume - ) -{ - UINTN Index; - - if (Volume->LogicalVolDescs !=3D NULL) { - for (Index =3D 0; Index < Volume->LogicalVolDescsNo; Index++) { - FreePool ((VOID *)Volume->LogicalVolDescs[Index]); - } - FreePool ((VOID *)Volume->LogicalVolDescs); - } - - if (Volume->PartitionDescs !=3D NULL) { - for (Index =3D 0; Index < Volume->PartitionDescsNo; Index++) { - FreePool ((VOID *)Volume->PartitionDescs[Index]); - } - FreePool ((VOID *)Volume->PartitionDescs); - } - - if (Volume->FileSetDescs !=3D NULL) { - for (Index =3D 0; Index < Volume->FileSetDescsNo; Index++) { - FreePool ((VOID *)Volume->FileSetDescs[Index]); - } - FreePool ((VOID *)Volume->FileSetDescs); - } - - ZeroMem ((VOID *)Volume, sizeof (UDF_VOLUME_INFO)); -} - -/** Clean up in-memory UDF file information. =20 @param[in] File File information pointer. @@ -2249,91 +2119,100 @@ GetVolumeSize ( OUT UINT64 *FreeSpaceSize ) { - UDF_EXTENT_AD ExtentAd; - UINT32 LogicalBlockSize; - UINT64 Lsn; - EFI_STATUS Status; - UDF_LOGICAL_VOLUME_INTEGRITY *LogicalVolInt; - UINTN Index; - UINTN Length; - UINT32 LsnsNo; - - *VolumeSize =3D 0; - *FreeSpaceSize =3D 0; - - for (Index =3D 0; Index < Volume->LogicalVolDescsNo; Index++) { - CopyMem ((VOID *)&ExtentAd, - (VOID *)&Volume->LogicalVolDescs[Index]->IntegritySequenceExt= ent, - sizeof (UDF_EXTENT_AD)); - if (ExtentAd.ExtentLength =3D=3D 0) { - continue; - } + EFI_STATUS Status; + UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc; + UDF_EXTENT_AD *ExtentAd; + UINT64 Lsn; + UINT32 LogicalBlockSize; + UDF_LOGICAL_VOLUME_INTEGRITY *LogicalVolInt; + UINTN Index; + UINTN Length; + UINT32 LsnsNo; =20 - LogicalBlockSize =3D LV_BLOCK_SIZE (Volume, Index); + LogicalVolDesc =3D &Volume->LogicalVolDesc; =20 - Read_Next_Sequence: - LogicalVolInt =3D (UDF_LOGICAL_VOLUME_INTEGRITY *) - AllocatePool (ExtentAd.ExtentLength); - if (LogicalVolInt =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } + ExtentAd =3D &LogicalVolDesc->IntegritySequenceExtent; =20 - Lsn =3D (UINT64)ExtentAd.ExtentLocation; + if (ExtentAd->ExtentLength =3D=3D 0) { + return EFI_VOLUME_CORRUPTED; + } =20 - Status =3D DiskIo->ReadDisk ( - DiskIo, - BlockIo->Media->MediaId, - MultU64x32 (Lsn, LogicalBlockSize), - ExtentAd.ExtentLength, - (VOID *)LogicalVolInt - ); - if (EFI_ERROR (Status)) { - FreePool ((VOID *)LogicalVolInt); - return Status; - } + LogicalVolInt =3D AllocatePool (ExtentAd->ExtentLength); + if (LogicalVolInt =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } =20 - if (!IS_LVID (LogicalVolInt)) { - FreePool ((VOID *)LogicalVolInt); - return EFI_VOLUME_CORRUPTED; - } + // + // Get location of Logical Volume Integrity Descriptor + // + Lsn =3D (UINT64)ExtentAd->ExtentLocation - Volume->MainVdsStartLocation; =20 - Length =3D LogicalVolInt->NumberOfPartitions; - for (Index =3D 0; Index < Length; Index +=3D sizeof (UINT32)) { - LsnsNo =3D *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index); - if (LsnsNo =3D=3D 0xFFFFFFFFUL) { - // - // Size not specified. - // - continue; - } + LogicalBlockSize =3D LogicalVolDesc->LogicalBlockSize; =20 - *FreeSpaceSize +=3D MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize); - } + // + // Read disk block + // + Status =3D DiskIo->ReadDisk ( + DiskIo, + BlockIo->Media->MediaId, + MultU64x32 (Lsn, LogicalBlockSize), + ExtentAd->ExtentLength, + LogicalVolInt + ); + if (EFI_ERROR (Status)) { + goto Out_Free; + } =20 - Length =3D (LogicalVolInt->NumberOfPartitions * sizeof (UINT32)) << 1; - for (; Index < Length; Index +=3D sizeof (UINT32)) { - LsnsNo =3D *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index); - if (LsnsNo =3D=3D 0xFFFFFFFFUL) { - // - // Size not specified. - // - continue; - } + // + // Check if read block is a Logical Volume Integrity Descriptor + // + if (!IS_LVID (LogicalVolInt)) { + Status =3D EFI_VOLUME_CORRUPTED; + goto Out_Free; + } =20 - *VolumeSize +=3D MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize); - } + *VolumeSize =3D 0; + *FreeSpaceSize =3D 0; =20 - CopyMem ((VOID *)&ExtentAd,(VOID *)&LogicalVolInt->NextIntegrityExtent, - sizeof (UDF_EXTENT_AD)); - if (ExtentAd.ExtentLength > 0) { - FreePool ((VOID *)LogicalVolInt); - goto Read_Next_Sequence; + Length =3D LogicalVolInt->NumberOfPartitions; + for (Index =3D 0; Index < Length; Index +=3D sizeof (UINT32)) { + LsnsNo =3D *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index); + // + // Check if size is not specified + // + if (LsnsNo =3D=3D 0xFFFFFFFFUL) { + continue; } + // + // Accumulate free space size + // + *FreeSpaceSize +=3D MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize); + } =20 - FreePool ((VOID *)LogicalVolInt); + Length =3D LogicalVolInt->NumberOfPartitions * sizeof (UINT32) * 2; + for (; Index < Length; Index +=3D sizeof (UINT32)) { + LsnsNo =3D *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index); + // + // Check if size is not specified + // + if (LsnsNo =3D=3D 0xFFFFFFFFUL) { + continue; + } + // + // Accumulate used volume space + // + *VolumeSize +=3D MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize); } =20 - return EFI_SUCCESS; + Status =3D EFI_SUCCESS; + +Out_Free: + // + // Free Logical Volume Integrity Descriptor + // + FreePool (LogicalVolInt); + + return Status; } =20 /** diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c b/MdeModulePkg/Univer= sal/Disk/UdfDxe/Udf.c index 49dc7077b7..d4163b89ca 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c @@ -276,13 +276,6 @@ UdfDriverBindingStop ( NULL ); =20 - // - // Check if there's any open file. If so, clean them up. - // - if (PrivFsData->OpenFiles > 0) { - CleanupVolumeInformation (&PrivFsData->Volume); - } - FreePool ((VOID *)PrivFsData); } =20 diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h b/MdeModulePkg/Univer= sal/Disk/UdfDxe/Udf.h index 240d420ff5..c5f83914d8 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h +++ b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h @@ -49,16 +49,8 @@ { 0x89, 0x56, 0x73, 0xCD, 0xA3, 0x26, 0xCD, 0x0A } \ } =20 -#define UDF_DEFAULT_LV_NUM 0 - #define IS_PVD(_Pointer) \ ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 1)) -#define IS_PD(_Pointer) \ - ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 5)) -#define IS_LVD(_Pointer) \ - ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 6)) -#define IS_TD(_Pointer) \ - ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 8)) #define IS_FSD(_Pointer) \ ((BOOLEAN)(_GET_TAG_ID (_Pointer) =3D=3D 256)) #define IS_FE(_Pointer) \ @@ -152,14 +144,8 @@ typedef enum { #define IS_VALID_COMPRESSION_ID(_CompId) \ ((BOOLEAN)((_CompId) =3D=3D 8 || (_CompId) =3D=3D 16)) =20 -#define LV_BLOCK_SIZE(_Vol, _LvNum) \ - (_Vol)->LogicalVolDescs[(_LvNum)]->LogicalBlockSize - #define UDF_STANDARD_IDENTIFIER_LENGTH 5 =20 -#define LV_UDF_REVISION(_Lv) \ - *(UINT16 *)(UINTN)(_Lv)->DomainIdentifier.IdentifierSuffix - #pragma pack(1) =20 typedef struct { @@ -186,17 +172,6 @@ typedef struct { #pragma pack(1) =20 typedef struct { - UINT8 CharacterSetType; - UINT8 CharacterSetInfo[63]; -} UDF_CHAR_SPEC; - -typedef struct { - UINT8 Flags; - UINT8 Identifier[23]; - UINT8 IdentifierSuffix[8]; -} UDF_ENTITY_ID; - -typedef struct { UINT16 TypeAndTimezone; INT16 Year; UINT8 Month; @@ -210,17 +185,6 @@ typedef struct { } UDF_TIMESTAMP; =20 typedef struct { - UINT32 LogicalBlockNumber; - UINT16 PartitionReferenceNumber; -} UDF_LB_ADDR; - -typedef struct { - UINT32 ExtentLength; - UDF_LB_ADDR ExtentLocation; - UINT8 ImplementationUse[6]; -} UDF_LONG_ALLOCATION_DESCRIPTOR; - -typedef struct { UDF_DESCRIPTOR_TAG DescriptorTag; UINT32 PrevAllocationExtentDescriptor; UINT32 LengthOfAllocationDescriptors; @@ -235,37 +199,6 @@ typedef struct { } UDF_VOLUME_DESCRIPTOR; =20 typedef struct { - UDF_DESCRIPTOR_TAG DescriptorTag; - UINT32 VolumeDescriptorSequenceNumber; - UINT16 PartitionFlags; - UINT16 PartitionNumber; - UDF_ENTITY_ID PartitionContents; - UINT8 PartitionContentsUse[128]; - UINT32 AccessType; - UINT32 PartitionStartingLocation; - UINT32 PartitionLength; - UDF_ENTITY_ID ImplementationIdentifier; - UINT8 ImplementationUse[128]; - UINT8 Reserved[156]; -} UDF_PARTITION_DESCRIPTOR; - -typedef struct { - UDF_DESCRIPTOR_TAG DescriptorTag; - UINT32 VolumeDescriptorSequenceNumber; - UDF_CHAR_SPEC DescriptorCharacterSet; - UINT8 LogicalVolumeIdentifier[128]; - UINT32 LogicalBlockSize; - UDF_ENTITY_ID DomainIdentifier; - UDF_LONG_ALLOCATION_DESCRIPTOR LogicalVolumeContentsUse; - UINT32 MapTableLength; - UINT32 NumberOfPartitionMaps; - UDF_ENTITY_ID ImplementationIdentifier; - UINT8 ImplementationUse[128]; - UDF_EXTENT_AD IntegritySequenceExtent; - UINT8 PartitionMaps[6]; -} UDF_LOGICAL_VOLUME_DESCRIPTOR; - -typedef struct { UDF_DESCRIPTOR_TAG DescriptorTag; UDF_TIMESTAMP RecordingDateTime; UINT32 IntegrityType; @@ -389,12 +322,10 @@ typedef struct { // UDF filesystem driver's private data // typedef struct { - UDF_LOGICAL_VOLUME_DESCRIPTOR **LogicalVolDescs; - UINTN LogicalVolDescsNo; - UDF_PARTITION_DESCRIPTOR **PartitionDescs; - UINTN PartitionDescsNo; - UDF_FILE_SET_DESCRIPTOR **FileSetDescs; - UINTN FileSetDescsNo; + UINT64 MainVdsStartLocation; + UDF_LOGICAL_VOLUME_DESCRIPTOR LogicalVolDesc; + UDF_PARTITION_DESCRIPTOR PartitionDesc; + UDF_FILE_SET_DESCRIPTOR FileSetDesc; UINTN FileEntrySize; } UDF_VOLUME_INFO; =20 @@ -883,17 +814,6 @@ ResolveSymlink ( ); =20 /** - Clean up in-memory UDF volume information. - - @param[in] Volume Volume information pointer. - -**/ -VOID -CleanupVolumeInformation ( - IN UDF_VOLUME_INFO *Volume - ); - -/** Clean up in-memory UDF file information. =20 @param[in] File File information pointer. --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel