2 Handle on-disk format and volume structures in UDF/ECMA-167 file systems.
4 Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
12 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 // Vendor-Defined Device Path GUID for UDF file system
20 EFI_GUID gUdfDevPathGuid
= EFI_UDF_DEVICE_PATH_GUID
;
23 Find the anchor volume descriptor pointer.
25 @param[in] BlockIo BlockIo interface.
26 @param[in] DiskIo DiskIo interface.
27 @param[out] AnchorPoint Anchor volume descriptor pointer.
29 @retval EFI_SUCCESS Anchor volume descriptor pointer found.
30 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
31 @retval other Anchor volume descriptor pointer not found.
35 FindAnchorVolumeDescriptorPointer (
36 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
37 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
38 OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER
*AnchorPoint
44 EFI_LBA DescriptorLBAs
[4];
46 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
48 BlockSize
= BlockIo
->Media
->BlockSize
;
49 EndLBA
= BlockIo
->Media
->LastBlock
;
50 DescriptorLBAs
[0] = 256;
51 DescriptorLBAs
[1] = EndLBA
- 256;
52 DescriptorLBAs
[2] = EndLBA
;
53 DescriptorLBAs
[3] = 512;
55 for (Index
= 0; Index
< ARRAY_SIZE (DescriptorLBAs
); Index
++) {
56 Status
= DiskIo
->ReadDisk (
58 BlockIo
->Media
->MediaId
,
59 MultU64x32 (DescriptorLBAs
[Index
], BlockSize
),
60 sizeof (UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER
),
63 if (EFI_ERROR (Status
)) {
67 DescriptorTag
= &AnchorPoint
->DescriptorTag
;
70 // Check if read LBA has a valid AVDP descriptor.
72 if (DescriptorTag
->TagIdentifier
== UdfAnchorVolumeDescriptorPointer
) {
79 return EFI_VOLUME_CORRUPTED
;
83 Save the content of Logical Volume Descriptors and Partitions Descriptors in
86 @param[in] BlockIo BlockIo interface.
87 @param[in] DiskIo DiskIo interface.
88 @param[in] AnchorPoint Anchor volume descriptor pointer.
89 @param[out] Volume UDF volume information structure.
91 @retval EFI_SUCCESS The descriptors were saved.
92 @retval EFI_OUT_OF_RESOURCES The descriptors were not saved due to lack of
94 @retval other The descriptors were not saved due to
99 StartMainVolumeDescriptorSequence (
100 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
101 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
102 IN UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER
*AnchorPoint
,
103 OUT UDF_VOLUME_INFO
*Volume
108 UDF_EXTENT_AD
*ExtentAd
;
109 EFI_LBA SeqStartBlock
;
111 BOOLEAN StopSequence
;
113 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
114 UINT32 LogicalBlockSize
;
116 BlockSize
= BlockIo
->Media
->BlockSize
;
117 ExtentAd
= &AnchorPoint
->MainVolumeDescriptorSequenceExtent
;
120 // Allocate buffer for reading disk blocks
122 Buffer
= AllocateZeroPool ((UINTN
)BlockSize
);
123 if (Buffer
== NULL
) {
124 return EFI_OUT_OF_RESOURCES
;
128 // The logical partition created by Partition driver is relative to the main
129 // VDS extent location, so we start the Main Volume Descriptor Sequence at
132 // We don't need to check again if we have valid Volume Descriptors here since
133 // Partition driver already did.
136 SeqEndBlock
= SeqStartBlock
+ DivU64x32 ((UINT64
)ExtentAd
->ExtentLength
,
138 StopSequence
= FALSE
;
139 for (; SeqStartBlock
< SeqEndBlock
&& !StopSequence
; SeqStartBlock
++) {
143 Status
= BlockIo
->ReadBlocks (
145 BlockIo
->Media
->MediaId
,
150 if (EFI_ERROR (Status
)) {
154 DescriptorTag
= Buffer
;
156 switch (DescriptorTag
->TagIdentifier
) {
157 case UdfPartitionDescriptor
:
159 // Save Partition Descriptor
161 CopyMem (&Volume
->PartitionDesc
, Buffer
, sizeof (Volume
->PartitionDesc
));
164 case UdfLogicalVolumeDescriptor
:
166 // Save Logical Volume Descriptor
168 CopyMem (&Volume
->LogicalVolDesc
, Buffer
, sizeof (Volume
->LogicalVolDesc
));
171 case UdfTerminatingDescriptor
:
181 // Determine FE (File Entry) size
183 LogicalBlockSize
= Volume
->LogicalVolDesc
.LogicalBlockSize
;
184 if (LogicalBlockSize
>= UDF_LOGICAL_SECTOR_SIZE
) {
185 Volume
->FileEntrySize
= (UINTN
)LogicalBlockSize
;
187 Volume
->FileEntrySize
= UDF_LOGICAL_SECTOR_SIZE
;
190 Status
= EFI_SUCCESS
;
194 // Free block read buffer
202 Return a Partition Descriptor given a Long Allocation Descriptor. This is
203 necessary to calculate the right extent (LongAd) offset which is added up
204 with partition's starting location.
206 @param[in] Volume Volume information pointer.
207 @param[in] LongAd Long Allocation Descriptor pointer.
209 @return A pointer to a Partition Descriptor.
212 UDF_PARTITION_DESCRIPTOR
*
214 IN UDF_VOLUME_INFO
*Volume
,
215 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*LongAd
218 UDF_LOGICAL_VOLUME_DESCRIPTOR
*LogicalVolDesc
;
221 LogicalVolDesc
= &Volume
->LogicalVolDesc
;
223 switch (LogicalVolDesc
->DomainIdentifier
.Suffix
.Domain
.UdfRevision
) {
231 // UDF 1.02 specification:
233 // There shall be exactly one prevailing Logical Volume Descriptor recorded
234 // per Volume Set. The Partition Maps field shall contain only Type 1
237 // UDF 1.50 through 2.60 specs say:
239 // For the purpose of interchange partition maps shall be limited to
240 // Partition Map type 1, except type 2 maps as described in the document.
242 // NOTE: Only one Type 1 (Physical) Partition is supported. It has been
243 // checked already in Partition driver for existence of a single Type 1
244 // Partition map, so we don't have to double check here.
246 // Partition reference number can also be retrieved from
247 // LongAd->ExtentLocation.PartitionReferenceNumber, however the spec says
248 // it may be 0, so let's not rely on it.
250 PartitionNum
= *(UINT16
*)((UINTN
)&LogicalVolDesc
->PartitionMaps
[4]);
255 // Unsupported UDF revision
261 // Check if partition number matches Partition Descriptor found in Main Volume
262 // Descriptor Sequence.
264 if (Volume
->PartitionDesc
.PartitionNumber
== PartitionNum
) {
265 return &Volume
->PartitionDesc
;
272 Return logical sector number of a given Long Allocation Descriptor.
274 @param[in] Volume Volume information pointer.
275 @param[in] LongAd Long Allocation Descriptor pointer.
277 @return The logical sector number of a given Long Allocation Descriptor.
282 IN UDF_VOLUME_INFO
*Volume
,
283 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*LongAd
286 UDF_PARTITION_DESCRIPTOR
*PartitionDesc
;
288 PartitionDesc
= GetPdFromLongAd (Volume
, LongAd
);
289 ASSERT (PartitionDesc
!= NULL
);
291 return (UINT64
)PartitionDesc
->PartitionStartingLocation
-
292 Volume
->MainVdsStartLocation
+
293 LongAd
->ExtentLocation
.LogicalBlockNumber
;
297 Return logical sector number of a given Short Allocation Descriptor.
299 @param[in] Volume Volume pointer.
300 @param[in] PartitionDesc Partition Descriptor pointer.
301 @param[in] ShortAd Short Allocation Descriptor pointer.
303 @return The logical sector number of a given Short Allocation Descriptor.
308 IN UDF_VOLUME_INFO
*Volume
,
309 IN UDF_PARTITION_DESCRIPTOR
*PartitionDesc
,
310 IN UDF_SHORT_ALLOCATION_DESCRIPTOR
*ShortAd
313 return (UINT64
)PartitionDesc
->PartitionStartingLocation
-
314 Volume
->MainVdsStartLocation
+ ShortAd
->ExtentPosition
;
318 Find File Set Descriptor of a given Logical Volume Descriptor.
320 The found FSD will contain the extent (LogicalVolumeContentsUse) where our
323 @param[in] BlockIo BlockIo interface.
324 @param[in] DiskIo DiskIo interface.
325 @param[in] Volume Volume information pointer.
327 @retval EFI_SUCCESS File Set Descriptor pointer found.
328 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
329 @retval other File Set Descriptor pointer not found.
333 FindFileSetDescriptor (
334 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
335 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
336 IN UDF_VOLUME_INFO
*Volume
341 UDF_LOGICAL_VOLUME_DESCRIPTOR
*LogicalVolDesc
;
342 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
344 LogicalVolDesc
= &Volume
->LogicalVolDesc
;
345 Lsn
= GetLongAdLsn (Volume
, &LogicalVolDesc
->LogicalVolumeContentsUse
);
348 // As per UDF 2.60 specification:
350 // There shall be exactly one File Set Descriptor recorded per Logical
355 Status
= DiskIo
->ReadDisk (
357 BlockIo
->Media
->MediaId
,
358 MultU64x32 (Lsn
, LogicalVolDesc
->LogicalBlockSize
),
359 sizeof (Volume
->FileSetDesc
),
362 if (EFI_ERROR (Status
)) {
366 DescriptorTag
= &Volume
->FileSetDesc
.DescriptorTag
;
369 // Check if read block is a File Set Descriptor
371 if (DescriptorTag
->TagIdentifier
!= UdfFileSetDescriptor
) {
372 return EFI_VOLUME_CORRUPTED
;
379 Read Volume and File Structure on an UDF file system.
381 @param[in] BlockIo BlockIo interface.
382 @param[in] DiskIo DiskIo interface.
383 @param[out] Volume Volume information pointer.
385 @retval EFI_SUCCESS Volume and File Structure were read.
386 @retval other Volume and File Structure were not read.
390 ReadVolumeFileStructure (
391 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
392 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
393 OUT UDF_VOLUME_INFO
*Volume
397 UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER AnchorPoint
;
398 UDF_EXTENT_AD
*ExtentAd
;
401 // Find Anchor Volume Descriptor Pointer
403 Status
= FindAnchorVolumeDescriptorPointer (
408 if (EFI_ERROR (Status
)) {
413 // Save Main VDS start block number
415 ExtentAd
= &AnchorPoint
.MainVolumeDescriptorSequenceExtent
;
417 Volume
->MainVdsStartLocation
= (UINT64
)ExtentAd
->ExtentLocation
;
420 // Start Main Volume Descriptor Sequence.
422 Status
= StartMainVolumeDescriptorSequence (
428 if (EFI_ERROR (Status
)) {
436 Calculate length of a given File Identifier Descriptor.
438 @param[in] FileIdentifierDesc File Identifier Descriptor pointer.
440 @return The length of a given File Identifier Descriptor.
444 GetFidDescriptorLength (
445 IN UDF_FILE_IDENTIFIER_DESCRIPTOR
*FileIdentifierDesc
449 (INTN
)((OFFSET_OF (UDF_FILE_IDENTIFIER_DESCRIPTOR
, Data
[0]) + 3 +
450 FileIdentifierDesc
->LengthOfFileIdentifier
+
451 FileIdentifierDesc
->LengthOfImplementationUse
) >> 2) << 2
456 Duplicate a given File Identifier Descriptor.
458 @param[in] FileIdentifierDesc File Identifier Descriptor pointer.
459 @param[out] NewFileIdentifierDesc The duplicated File Identifier Descriptor.
464 IN UDF_FILE_IDENTIFIER_DESCRIPTOR
*FileIdentifierDesc
,
465 OUT UDF_FILE_IDENTIFIER_DESCRIPTOR
**NewFileIdentifierDesc
468 *NewFileIdentifierDesc
=
469 (UDF_FILE_IDENTIFIER_DESCRIPTOR
*)AllocateCopyPool (
470 (UINTN
) GetFidDescriptorLength (FileIdentifierDesc
), FileIdentifierDesc
);
472 ASSERT (*NewFileIdentifierDesc
!= NULL
);
476 Duplicate either a given File Entry or a given Extended File Entry.
478 @param[in] BlockIo BlockIo interface.
479 @param[in] Volume Volume information pointer.
480 @param[in] FileEntry (Extended) File Entry pointer.
481 @param[out] NewFileEntry The duplicated (Extended) File Entry.
486 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
487 IN UDF_VOLUME_INFO
*Volume
,
489 OUT VOID
**NewFileEntry
492 *NewFileEntry
= AllocateCopyPool (Volume
->FileEntrySize
, FileEntry
);
494 ASSERT (*NewFileEntry
!= NULL
);
498 Get raw data + length of a given File Entry or Extended File Entry.
500 The file's recorded data can contain either real file content (inline) or
501 a sequence of extents (or Allocation Descriptors) which tells where file's
502 content is stored in.
504 NOTE: The FE/EFE can be thought it was an inode.
506 @param[in] FileEntryData (Extended) File Entry pointer.
507 @param[out] Data Buffer contains the raw data of a given
508 (Extended) File Entry.
509 @param[out] Length Length of the data in Buffer.
514 IN VOID
*FileEntryData
,
519 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
520 UDF_EXTENDED_FILE_ENTRY
*ExtendedFileEntry
;
521 UDF_FILE_ENTRY
*FileEntry
;
523 DescriptorTag
= FileEntryData
;
525 if (DescriptorTag
->TagIdentifier
== UdfExtendedFileEntry
) {
526 ExtendedFileEntry
= (UDF_EXTENDED_FILE_ENTRY
*)FileEntryData
;
528 *Length
= ExtendedFileEntry
->InformationLength
;
529 *Data
= (VOID
*)((UINT8
*)ExtendedFileEntry
->Data
+
530 ExtendedFileEntry
->LengthOfExtendedAttributes
);
531 } else if (DescriptorTag
->TagIdentifier
== UdfFileEntry
) {
532 FileEntry
= (UDF_FILE_ENTRY
*)FileEntryData
;
534 *Length
= FileEntry
->InformationLength
;
535 *Data
= (VOID
*)((UINT8
*)FileEntry
->Data
+
536 FileEntry
->LengthOfExtendedAttributes
);
541 Get Allocation Descriptors' data information from a given FE/EFE.
543 @param[in] FileEntryData (Extended) File Entry pointer.
544 @param[out] AdsData Buffer contains the Allocation Descriptors'
545 data from a given FE/EFE.
546 @param[out] Length Length of the data in AdsData.
551 IN VOID
*FileEntryData
,
556 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
557 UDF_EXTENDED_FILE_ENTRY
*ExtendedFileEntry
;
558 UDF_FILE_ENTRY
*FileEntry
;
560 DescriptorTag
= FileEntryData
;
562 if (DescriptorTag
->TagIdentifier
== UdfExtendedFileEntry
) {
563 ExtendedFileEntry
= (UDF_EXTENDED_FILE_ENTRY
*)FileEntryData
;
565 *Length
= ExtendedFileEntry
->LengthOfAllocationDescriptors
;
566 *AdsData
= (VOID
*)((UINT8
*)ExtendedFileEntry
->Data
+
567 ExtendedFileEntry
->LengthOfExtendedAttributes
);
568 } else if (DescriptorTag
->TagIdentifier
== UdfFileEntry
) {
569 FileEntry
= (UDF_FILE_ENTRY
*)FileEntryData
;
571 *Length
= FileEntry
->LengthOfAllocationDescriptors
;
572 *AdsData
= (VOID
*)((UINT8
*)FileEntry
->Data
+
573 FileEntry
->LengthOfExtendedAttributes
);
578 Read next Long Allocation Descriptor from a given file's data.
580 @param[in] Data File's data pointer.
581 @param[in,out] Offset Starting offset of the File's data to read.
582 @param[in] Length Length of the data to read.
583 @param[out] FoundLongAd Long Allocation Descriptor pointer.
585 @retval EFI_SUCCESS A Long Allocation Descriptor was found.
586 @retval EFI_DEVICE_ERROR No more Long Allocation Descriptors.
592 IN OUT UINT64
*Offset
,
594 OUT UDF_LONG_ALLOCATION_DESCRIPTOR
**FoundLongAd
597 UDF_LONG_ALLOCATION_DESCRIPTOR
*LongAd
;
598 UDF_EXTENT_FLAGS ExtentFlags
;
601 if (*Offset
>= Length
) {
603 // No more Long Allocation Descriptors.
605 return EFI_DEVICE_ERROR
;
609 (UDF_LONG_ALLOCATION_DESCRIPTOR
*)((UINT8
*)Data
+ *Offset
);
612 // If it's either an indirect AD (Extended Alllocation Descriptor) or an
613 // allocated AD, then return it.
615 ExtentFlags
= GET_EXTENT_FLAGS (LongAdsSequence
, LongAd
);
616 if (ExtentFlags
== ExtentIsNextExtent
||
617 ExtentFlags
== ExtentRecordedAndAllocated
) {
622 // This AD is either not recorded but allocated, or not recorded and not
623 // allocated. Skip it.
625 *Offset
+= AD_LENGTH (LongAdsSequence
);
628 *FoundLongAd
= LongAd
;
634 Read next Short Allocation Descriptor from a given file's data.
636 @param[in] Data File's data pointer.
637 @param[in,out] Offset Starting offset of the File's data to read.
638 @param[in] Length Length of the data to read.
639 @param[out] FoundShortAd Short Allocation Descriptor pointer.
641 @retval EFI_SUCCESS A Short Allocation Descriptor was found.
642 @retval EFI_DEVICE_ERROR No more Short Allocation Descriptors.
648 IN OUT UINT64
*Offset
,
650 OUT UDF_SHORT_ALLOCATION_DESCRIPTOR
**FoundShortAd
653 UDF_SHORT_ALLOCATION_DESCRIPTOR
*ShortAd
;
654 UDF_EXTENT_FLAGS ExtentFlags
;
657 if (*Offset
>= Length
) {
659 // No more Short Allocation Descriptors.
661 return EFI_DEVICE_ERROR
;
665 (UDF_SHORT_ALLOCATION_DESCRIPTOR
*)((UINT8
*)Data
+ *Offset
);
668 // If it's either an indirect AD (Extended Alllocation Descriptor) or an
669 // allocated AD, then return it.
671 ExtentFlags
= GET_EXTENT_FLAGS (ShortAdsSequence
, ShortAd
);
672 if (ExtentFlags
== ExtentIsNextExtent
||
673 ExtentFlags
== ExtentRecordedAndAllocated
) {
678 // This AD is either not recorded but allocated, or not recorded and not
679 // allocated. Skip it.
681 *Offset
+= AD_LENGTH (ShortAdsSequence
);
684 *FoundShortAd
= ShortAd
;
690 Get either a Short Allocation Descriptor or a Long Allocation Descriptor from
693 @param[in] RecordingFlags Flag to indicate the type of descriptor.
694 @param[in] Data File's data pointer.
695 @param[in,out] Offset Starting offset of the File's data to read.
696 @param[in] Length Length of the data to read.
697 @param[out] FoundAd Allocation Descriptor pointer.
699 @retval EFI_SUCCESS A Short Allocation Descriptor was found.
700 @retval EFI_DEVICE_ERROR No more Allocation Descriptors.
701 Invalid type of descriptor was given.
705 GetAllocationDescriptor (
706 IN UDF_FE_RECORDING_FLAGS RecordingFlags
,
708 IN OUT UINT64
*Offset
,
713 if (RecordingFlags
== LongAdsSequence
) {
714 return GetLongAdFromAds (
718 (UDF_LONG_ALLOCATION_DESCRIPTOR
**)FoundAd
720 } else if (RecordingFlags
== ShortAdsSequence
) {
721 return GetShortAdFromAds (
725 (UDF_SHORT_ALLOCATION_DESCRIPTOR
**)FoundAd
729 return EFI_DEVICE_ERROR
;
733 Return logical sector number of either Short or Long Allocation Descriptor.
735 @param[in] RecordingFlags Flag to indicate the type of descriptor.
736 @param[in] Volume Volume information pointer.
737 @param[in] ParentIcb Long Allocation Descriptor pointer.
738 @param[in] Ad Allocation Descriptor pointer.
740 @return The logical sector number of the given Allocation Descriptor.
744 GetAllocationDescriptorLsn (
745 IN UDF_FE_RECORDING_FLAGS RecordingFlags
,
746 IN UDF_VOLUME_INFO
*Volume
,
747 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*ParentIcb
,
751 if (RecordingFlags
== LongAdsSequence
) {
752 return GetLongAdLsn (Volume
, (UDF_LONG_ALLOCATION_DESCRIPTOR
*)Ad
);
753 } else if (RecordingFlags
== ShortAdsSequence
) {
754 return GetShortAdLsn (
756 GetPdFromLongAd (Volume
, ParentIcb
),
757 (UDF_SHORT_ALLOCATION_DESCRIPTOR
*)Ad
765 Return offset + length of a given indirect Allocation Descriptor (AED).
767 @param[in] BlockIo BlockIo interface.
768 @param[in] DiskIo DiskIo interface.
769 @param[in] Volume Volume information pointer.
770 @param[in] ParentIcb Long Allocation Descriptor pointer.
771 @param[in] RecordingFlags Flag to indicate the type of descriptor.
772 @param[in] Ad Allocation Descriptor pointer.
773 @param[out] Offset Offset of a given indirect Allocation
775 @param[out] Length Length of a given indirect Allocation
778 @retval EFI_SUCCESS The offset and length were returned.
779 @retval EFI_OUT_OF_RESOURCES The offset and length were not returned due
780 to lack of resources.
781 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
782 @retval other The offset and length were not returned.
787 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
788 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
789 IN UDF_VOLUME_INFO
*Volume
,
790 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*ParentIcb
,
791 IN UDF_FE_RECORDING_FLAGS RecordingFlags
,
801 UINT32 LogicalBlockSize
;
802 UDF_ALLOCATION_EXTENT_DESCRIPTOR
*AllocExtDesc
;
803 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
805 ExtentLength
= GET_EXTENT_LENGTH (RecordingFlags
, Ad
);
806 Lsn
= GetAllocationDescriptorLsn (RecordingFlags
,
811 Data
= AllocatePool (ExtentLength
);
813 return EFI_OUT_OF_RESOURCES
;
816 LogicalBlockSize
= Volume
->LogicalVolDesc
.LogicalBlockSize
;
821 Status
= DiskIo
->ReadDisk (
823 BlockIo
->Media
->MediaId
,
824 MultU64x32 (Lsn
, LogicalBlockSize
),
828 if (EFI_ERROR (Status
)) {
832 AllocExtDesc
= (UDF_ALLOCATION_EXTENT_DESCRIPTOR
*)Data
;
834 DescriptorTag
= &AllocExtDesc
->DescriptorTag
;
837 // Check if read extent contains a valid tag identifier for AED.
839 if (DescriptorTag
->TagIdentifier
!= UdfAllocationExtentDescriptor
) {
840 Status
= EFI_VOLUME_CORRUPTED
;
845 // Get AED's block offset and its length.
847 *Offset
= MultU64x32 (Lsn
, LogicalBlockSize
) +
848 sizeof (UDF_ALLOCATION_EXTENT_DESCRIPTOR
);
849 *Length
= AllocExtDesc
->LengthOfAllocationDescriptors
;
858 Read Allocation Extent Descriptor into memory.
860 @param[in] BlockIo BlockIo interface.
861 @param[in] DiskIo DiskIo interface.
862 @param[in] Volume Volume information pointer.
863 @param[in] ParentIcb Long Allocation Descriptor pointer.
864 @param[in] RecordingFlags Flag to indicate the type of descriptor.
865 @param[in] Ad Allocation Descriptor pointer.
866 @param[out] Data Buffer that contains the Allocation Extent
868 @param[out] Length Length of Data.
870 @retval EFI_SUCCESS The Allocation Extent Descriptor was read.
871 @retval EFI_OUT_OF_RESOURCES The Allocation Extent Descriptor was not read
872 due to lack of resources.
873 @retval other Fail to read the disk.
878 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
879 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
880 IN UDF_VOLUME_INFO
*Volume
,
881 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*ParentIcb
,
882 IN UDF_FE_RECORDING_FLAGS RecordingFlags
,
892 // Get AED's offset + length.
894 Status
= GetAedAdsOffset (
904 if (EFI_ERROR (Status
)) {
909 // Allocate buffer to read in AED's data.
911 *Data
= AllocatePool ((UINTN
) (*Length
));
913 return EFI_OUT_OF_RESOURCES
;
916 return DiskIo
->ReadDisk (
918 BlockIo
->Media
->MediaId
,
926 Function used to serialise reads of Allocation Descriptors.
928 @param[in] RecordingFlags Flag to indicate the type of descriptor.
929 @param[in] Ad Allocation Descriptor pointer.
930 @param[in, out] Buffer Buffer to hold the next Allocation Descriptor.
931 @param[in] Length Length of Buffer.
933 @retval EFI_SUCCESS Buffer was grown to hold the next Allocation
935 @retval EFI_OUT_OF_RESOURCES Buffer was not grown due to lack of resources.
939 GrowUpBufferToNextAd (
940 IN UDF_FE_RECORDING_FLAGS RecordingFlags
,
942 IN OUT VOID
**Buffer
,
948 ExtentLength
= GET_EXTENT_LENGTH (RecordingFlags
, Ad
);
950 if (*Buffer
== NULL
) {
951 *Buffer
= AllocatePool (ExtentLength
);
952 if (*Buffer
== NULL
) {
953 return EFI_OUT_OF_RESOURCES
;
956 *Buffer
= ReallocatePool ((UINTN
) Length
, (UINTN
) (Length
+ ExtentLength
), *Buffer
);
957 if (*Buffer
== NULL
) {
958 return EFI_OUT_OF_RESOURCES
;
966 Read data or size of either a File Entry or an Extended File Entry.
968 @param[in] BlockIo BlockIo interface.
969 @param[in] DiskIo DiskIo interface.
970 @param[in] Volume Volume information pointer.
971 @param[in] ParentIcb Long Allocation Descriptor pointer.
972 @param[in] FileEntryData FE/EFE structure pointer.
973 @param[in, out] ReadFileInfo Read file information pointer.
975 @retval EFI_SUCCESS Data or size of a FE/EFE was read.
976 @retval EFI_OUT_OF_RESOURCES Data or size of a FE/EFE was not read due to
978 @retval EFI_INVALID_PARAMETER The read file flag given in ReadFileInfo is
980 @retval EFI_UNSUPPORTED The FE recording flag given in FileEntryData
982 @retval other Data or size of a FE/EFE was not read.
987 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
988 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
989 IN UDF_VOLUME_INFO
*Volume
,
990 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*ParentIcb
,
991 IN VOID
*FileEntryData
,
992 IN OUT UDF_READ_FILE_INFO
*ReadFileInfo
996 UINT32 LogicalBlockSize
;
1003 UINT64 FilePosition
;
1008 BOOLEAN FinishedSeeking
;
1009 UINT32 ExtentLength
;
1010 UDF_FE_RECORDING_FLAGS RecordingFlags
;
1012 LogicalBlockSize
= Volume
->LogicalVolDesc
.LogicalBlockSize
;
1016 // set BytesLeft to suppress incorrect compiler/analyzer warnings
1021 FinishedSeeking
= FALSE
;
1024 switch (ReadFileInfo
->Flags
) {
1025 case ReadFileGetFileSize
:
1026 case ReadFileAllocateAndRead
:
1028 // Initialise ReadFileInfo structure for either getting file size, or
1029 // reading file's recorded data.
1031 ReadFileInfo
->ReadLength
= 0;
1032 ReadFileInfo
->FileData
= NULL
;
1034 case ReadFileSeekAndRead
:
1036 // About to seek a file and/or read its data.
1038 Length
= ReadFileInfo
->FileSize
- ReadFileInfo
->FilePosition
;
1039 if (ReadFileInfo
->FileDataSize
> Length
) {
1041 // About to read beyond the EOF -- truncate it.
1043 ReadFileInfo
->FileDataSize
= Length
;
1047 // Initialise data to start seeking and/or reading a file.
1049 BytesLeft
= ReadFileInfo
->FileDataSize
;
1052 FinishedSeeking
= FALSE
;
1057 RecordingFlags
= GET_FE_RECORDING_FLAGS (FileEntryData
);
1058 switch (RecordingFlags
) {
1061 // There are no extents for this FE/EFE. All data is inline.
1063 GetFileEntryData (FileEntryData
, &Data
, &Length
);
1065 if (ReadFileInfo
->Flags
== ReadFileGetFileSize
) {
1066 ReadFileInfo
->ReadLength
= Length
;
1067 } else if (ReadFileInfo
->Flags
== ReadFileAllocateAndRead
) {
1069 // Allocate buffer for starting read data.
1071 ReadFileInfo
->FileData
= AllocatePool ((UINTN
) Length
);
1072 if (ReadFileInfo
->FileData
== NULL
) {
1073 return EFI_OUT_OF_RESOURCES
;
1077 // Read all inline data into ReadFileInfo->FileData
1079 CopyMem (ReadFileInfo
->FileData
, Data
, (UINTN
) Length
);
1080 ReadFileInfo
->ReadLength
= Length
;
1081 } else if (ReadFileInfo
->Flags
== ReadFileSeekAndRead
) {
1083 // If FilePosition is non-zero, seek file to FilePosition, read
1084 // FileDataSize bytes and then updates FilePosition.
1087 ReadFileInfo
->FileData
,
1088 (VOID
*)((UINT8
*)Data
+ ReadFileInfo
->FilePosition
),
1089 (UINTN
) ReadFileInfo
->FileDataSize
1092 ReadFileInfo
->FilePosition
+= ReadFileInfo
->FileDataSize
;
1095 return EFI_INVALID_PARAMETER
;
1098 Status
= EFI_SUCCESS
;
1101 case LongAdsSequence
:
1102 case ShortAdsSequence
:
1104 // This FE/EFE contains a run of Allocation Descriptors. Get data + size
1105 // for start reading them out.
1107 GetAdsInformation (FileEntryData
, &Data
, &Length
);
1114 Status
= GetAllocationDescriptor (
1121 if (Status
== EFI_DEVICE_ERROR
) {
1122 Status
= EFI_SUCCESS
;
1127 // Check if AD is an indirect AD. If so, read Allocation Extent
1128 // Descriptor and its extents (ADs).
1130 if (GET_EXTENT_FLAGS (RecordingFlags
, Ad
) == ExtentIsNextExtent
) {
1137 Status
= GetAedAdsData (
1147 if (EFI_ERROR (Status
)) {
1150 ASSERT (Data
!= NULL
);
1156 ExtentLength
= GET_EXTENT_LENGTH (RecordingFlags
, Ad
);
1158 Lsn
= GetAllocationDescriptorLsn (RecordingFlags
,
1163 switch (ReadFileInfo
->Flags
) {
1164 case ReadFileGetFileSize
:
1165 ReadFileInfo
->ReadLength
+= ExtentLength
;
1167 case ReadFileAllocateAndRead
:
1169 // Increase FileData (if necessary) to read next extent.
1171 Status
= GrowUpBufferToNextAd (
1174 &ReadFileInfo
->FileData
,
1175 ReadFileInfo
->ReadLength
1177 if (EFI_ERROR (Status
)) {
1178 goto Error_Alloc_Buffer_To_Next_Ad
;
1182 // Read extent's data into FileData.
1184 Status
= DiskIo
->ReadDisk (
1186 BlockIo
->Media
->MediaId
,
1187 MultU64x32 (Lsn
, LogicalBlockSize
),
1189 (VOID
*)((UINT8
*)ReadFileInfo
->FileData
+
1190 ReadFileInfo
->ReadLength
)
1192 if (EFI_ERROR (Status
)) {
1193 goto Error_Read_Disk_Blk
;
1196 ReadFileInfo
->ReadLength
+= ExtentLength
;
1198 case ReadFileSeekAndRead
:
1200 // Seek file first before reading in its data.
1202 if (FinishedSeeking
) {
1204 goto Skip_File_Seek
;
1207 if (FilePosition
+ ExtentLength
< ReadFileInfo
->FilePosition
) {
1208 FilePosition
+= ExtentLength
;
1212 if (FilePosition
+ ExtentLength
> ReadFileInfo
->FilePosition
) {
1213 Offset
= ReadFileInfo
->FilePosition
- FilePosition
;
1219 // Done with seeking file. Start reading its data.
1221 FinishedSeeking
= TRUE
;
1225 // Make sure we don't read more data than really wanted.
1227 if (ExtentLength
- Offset
> BytesLeft
) {
1228 DataLength
= BytesLeft
;
1230 DataLength
= ExtentLength
- Offset
;
1234 // Read extent's data into FileData.
1236 Status
= DiskIo
->ReadDisk (
1238 BlockIo
->Media
->MediaId
,
1239 Offset
+ MultU64x32 (Lsn
, LogicalBlockSize
),
1241 (VOID
*)((UINT8
*)ReadFileInfo
->FileData
+
1244 if (EFI_ERROR (Status
)) {
1245 goto Error_Read_Disk_Blk
;
1249 // Update current file's position.
1251 DataOffset
+= DataLength
;
1252 ReadFileInfo
->FilePosition
+= DataLength
;
1254 BytesLeft
-= DataLength
;
1255 if (BytesLeft
== 0) {
1257 // There is no more file data to read.
1259 Status
= EFI_SUCCESS
;
1268 // Point to the next AD (extent).
1270 AdOffset
+= AD_LENGTH (RecordingFlags
);
1274 case ExtendedAdsSequence
:
1275 // FIXME: Not supported. Got no volume with it, yet.
1277 Status
= EFI_UNSUPPORTED
;
1282 // A flag value reserved by the ECMA-167 standard (3rd Edition - June
1283 // 1997); 14.6 ICB Tag; 14.6.8 Flags (RBP 18); was found.
1285 Status
= EFI_UNSUPPORTED
;
1296 Error_Read_Disk_Blk
:
1297 Error_Alloc_Buffer_To_Next_Ad
:
1298 if (ReadFileInfo
->Flags
!= ReadFileSeekAndRead
) {
1299 FreePool (ReadFileInfo
->FileData
);
1311 Find a file by its filename from a given Parent file.
1313 @param[in] BlockIo BlockIo interface.
1314 @param[in] DiskIo DiskIo interface.
1315 @param[in] Volume Volume information pointer.
1316 @param[in] FileName File name string.
1317 @param[in] Parent Parent directory file.
1318 @param[in] Icb Long Allocation Descriptor pointer.
1319 @param[out] File Found file.
1321 @retval EFI_SUCCESS The file was found.
1322 @retval EFI_INVALID_PARAMETER One or more input parameters are invalid.
1323 @retval EFI_NOT_FOUND The file was not found.
1328 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1329 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1330 IN UDF_VOLUME_INFO
*Volume
,
1331 IN CHAR16
*FileName
,
1332 IN UDF_FILE_INFO
*Parent
,
1333 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*Icb
,
1334 OUT UDF_FILE_INFO
*File
1338 UDF_FILE_IDENTIFIER_DESCRIPTOR
*FileIdentifierDesc
;
1339 UDF_READ_DIRECTORY_INFO ReadDirInfo
;
1341 CHAR16 FoundFileName
[UDF_FILENAME_LENGTH
];
1342 VOID
*CompareFileEntry
;
1345 // Check if both Parent->FileIdentifierDesc and Icb are NULL.
1347 if ((Parent
->FileIdentifierDesc
== NULL
) && (Icb
== NULL
)) {
1348 return EFI_INVALID_PARAMETER
;
1352 // Check if parent file is really directory.
1354 if (FE_ICB_FILE_TYPE (Parent
->FileEntry
) != UdfFileEntryDirectory
) {
1355 return EFI_NOT_FOUND
;
1359 // If FileName is current file or working directory, just duplicate Parent's
1360 // FE/EFE and FID descriptors.
1362 if (StrCmp (FileName
, L
".") == 0) {
1363 if (Parent
->FileIdentifierDesc
== NULL
) {
1364 return EFI_INVALID_PARAMETER
;
1367 DuplicateFe (BlockIo
, Volume
, Parent
->FileEntry
, &File
->FileEntry
);
1368 DuplicateFid (Parent
->FileIdentifierDesc
, &File
->FileIdentifierDesc
);
1374 // Start directory listing.
1376 ZeroMem ((VOID
*)&ReadDirInfo
, sizeof (UDF_READ_DIRECTORY_INFO
));
1380 Status
= ReadDirectoryEntry (
1384 (Parent
->FileIdentifierDesc
!= NULL
) ?
1385 &Parent
->FileIdentifierDesc
->Icb
:
1391 if (EFI_ERROR (Status
)) {
1392 if (Status
== EFI_DEVICE_ERROR
) {
1393 Status
= EFI_NOT_FOUND
;
1399 if (FileIdentifierDesc
->FileCharacteristics
& PARENT_FILE
) {
1401 // This FID contains the location (FE/EFE) of the parent directory of this
1402 // directory (Parent), and if FileName is either ".." or "\\", then it's
1403 // the expected FID.
1405 if (StrCmp (FileName
, L
"..") == 0 || StrCmp (FileName
, L
"\\") == 0) {
1410 Status
= GetFileNameFromFid (FileIdentifierDesc
, FoundFileName
);
1411 if (EFI_ERROR (Status
)) {
1415 if (StrCmp (FileName
, FoundFileName
) == 0) {
1417 // FID has been found. Prepare to find its respective FE/EFE.
1424 FreePool ((VOID
*)FileIdentifierDesc
);
1427 if (ReadDirInfo
.DirectoryData
!= NULL
) {
1429 // Free all allocated resources for the directory listing.
1431 FreePool (ReadDirInfo
.DirectoryData
);
1435 Status
= EFI_SUCCESS
;
1437 File
->FileIdentifierDesc
= FileIdentifierDesc
;
1440 // If the requested file is root directory, then the FE/EFE was already
1441 // retrieved in UdfOpenVolume() function, thus no need to find it again.
1443 // Otherwise, find FE/EFE from the respective FID.
1445 if (StrCmp (FileName
, L
"\\") != 0) {
1446 Status
= FindFileEntry (
1450 &FileIdentifierDesc
->Icb
,
1453 if (EFI_ERROR (Status
)) {
1458 // Make sure that both Parent's FE/EFE and found FE/EFE are not equal.
1460 if (CompareMem ((VOID
*)Parent
->FileEntry
, (VOID
*)CompareFileEntry
,
1461 Volume
->FileEntrySize
) != 0) {
1462 File
->FileEntry
= CompareFileEntry
;
1464 FreePool ((VOID
*)FileIdentifierDesc
);
1465 FreePool ((VOID
*)CompareFileEntry
);
1466 Status
= EFI_NOT_FOUND
;
1474 FreePool ((VOID
*)FileIdentifierDesc
);
1480 Read volume information on a medium which contains a valid UDF file system.
1482 @param[in] BlockIo BlockIo interface.
1483 @param[in] DiskIo DiskIo interface.
1484 @param[out] Volume UDF volume information structure.
1486 @retval EFI_SUCCESS Volume information read.
1487 @retval EFI_NO_MEDIA The device has no media.
1488 @retval EFI_DEVICE_ERROR The device reported an error.
1489 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1490 @retval EFI_OUT_OF_RESOURCES The volume was not read due to lack of resources.
1494 ReadUdfVolumeInformation (
1495 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1496 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1497 OUT UDF_VOLUME_INFO
*Volume
1503 // Read all necessary UDF volume information and keep it private to the driver
1505 Status
= ReadVolumeFileStructure (
1510 if (EFI_ERROR (Status
)) {
1515 // Find File Set Descriptor
1517 Status
= FindFileSetDescriptor (BlockIo
, DiskIo
, Volume
);
1518 if (EFI_ERROR (Status
)) {
1526 Find the root directory on an UDF volume.
1528 @param[in] BlockIo BlockIo interface.
1529 @param[in] DiskIo DiskIo interface.
1530 @param[in] Volume UDF volume information structure.
1531 @param[out] File Root directory file.
1533 @retval EFI_SUCCESS Root directory found.
1534 @retval EFI_NO_MEDIA The device has no media.
1535 @retval EFI_DEVICE_ERROR The device reported an error.
1536 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1537 @retval EFI_OUT_OF_RESOURCES The root directory was not found due to lack of
1543 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1544 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1545 IN UDF_VOLUME_INFO
*Volume
,
1546 OUT UDF_FILE_INFO
*File
1550 UDF_FILE_INFO Parent
;
1552 Status
= FindFileEntry (
1556 &Volume
->FileSetDesc
.RootDirectoryIcb
,
1559 if (EFI_ERROR (Status
)) {
1563 Parent
.FileEntry
= File
->FileEntry
;
1564 Parent
.FileIdentifierDesc
= NULL
;
1573 &Volume
->FileSetDesc
.RootDirectoryIcb
,
1576 if (EFI_ERROR (Status
)) {
1577 FreePool (File
->FileEntry
);
1584 Find either a File Entry or a Extended File Entry from a given ICB.
1586 @param[in] BlockIo BlockIo interface.
1587 @param[in] DiskIo DiskIo interface.
1588 @param[in] Volume UDF volume information structure.
1589 @param[in] Icb ICB of the FID.
1590 @param[out] FileEntry File Entry or Extended File Entry.
1592 @retval EFI_SUCCESS File Entry or Extended File Entry found.
1593 @retval EFI_NO_MEDIA The device has no media.
1594 @retval EFI_DEVICE_ERROR The device reported an error.
1595 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1596 @retval EFI_OUT_OF_RESOURCES The FE/EFE entry was not found due to lack of
1602 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1603 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1604 IN UDF_VOLUME_INFO
*Volume
,
1605 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*Icb
,
1606 OUT VOID
**FileEntry
1611 UINT32 LogicalBlockSize
;
1612 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
1614 Lsn
= GetLongAdLsn (Volume
, Icb
);
1615 LogicalBlockSize
= Volume
->LogicalVolDesc
.LogicalBlockSize
;
1617 *FileEntry
= AllocateZeroPool (Volume
->FileEntrySize
);
1618 if (*FileEntry
== NULL
) {
1619 return EFI_OUT_OF_RESOURCES
;
1625 Status
= DiskIo
->ReadDisk (
1627 BlockIo
->Media
->MediaId
,
1628 MultU64x32 (Lsn
, LogicalBlockSize
),
1629 Volume
->FileEntrySize
,
1632 if (EFI_ERROR (Status
)) {
1633 goto Error_Read_Disk_Blk
;
1636 DescriptorTag
= *FileEntry
;
1639 // Check if the read extent contains a valid Tag Identifier for the expected
1642 if (DescriptorTag
->TagIdentifier
!= UdfFileEntry
&&
1643 DescriptorTag
->TagIdentifier
!= UdfExtendedFileEntry
) {
1644 Status
= EFI_VOLUME_CORRUPTED
;
1645 goto Error_Invalid_Fe
;
1651 Error_Read_Disk_Blk
:
1652 FreePool (*FileEntry
);
1658 Find a file given its absolute path on an UDF volume.
1660 @param[in] BlockIo BlockIo interface.
1661 @param[in] DiskIo DiskIo interface.
1662 @param[in] Volume UDF volume information structure.
1663 @param[in] FilePath File's absolute path.
1664 @param[in] Root Root directory file.
1665 @param[in] Parent Parent directory file.
1666 @param[in] Icb ICB of Parent.
1667 @param[out] File Found file.
1669 @retval EFI_SUCCESS FilePath was found.
1670 @retval EFI_NO_MEDIA The device has no media.
1671 @retval EFI_DEVICE_ERROR The device reported an error.
1672 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1673 @retval EFI_OUT_OF_RESOURCES The FilePath file was not found due to lack of
1679 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1680 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1681 IN UDF_VOLUME_INFO
*Volume
,
1682 IN CHAR16
*FilePath
,
1683 IN UDF_FILE_INFO
*Root
,
1684 IN UDF_FILE_INFO
*Parent
,
1685 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*Icb
,
1686 OUT UDF_FILE_INFO
*File
1690 CHAR16 FileName
[UDF_FILENAME_LENGTH
];
1691 CHAR16
*FileNamePointer
;
1692 UDF_FILE_INFO PreviousFile
;
1695 Status
= EFI_NOT_FOUND
;
1697 CopyMem ((VOID
*)&PreviousFile
, (VOID
*)Parent
, sizeof (UDF_FILE_INFO
));
1698 while (*FilePath
!= L
'\0') {
1699 FileNamePointer
= FileName
;
1700 while (*FilePath
!= L
'\0' && *FilePath
!= L
'\\') {
1701 *FileNamePointer
++ = *FilePath
++;
1704 *FileNamePointer
= L
'\0';
1705 if (FileName
[0] == L
'\0') {
1707 // Open root directory.
1711 // There is no file found for the root directory yet. So, find only its
1714 // See UdfOpenVolume() function.
1716 Status
= InternalFindFile (BlockIo
,
1725 // We've already a file pointer (Root) for the root directory. Duplicate
1726 // its FE/EFE and FID descriptors.
1728 DuplicateFe (BlockIo
, Volume
, Root
->FileEntry
, &File
->FileEntry
);
1729 DuplicateFid (Root
->FileIdentifierDesc
, &File
->FileIdentifierDesc
);
1730 Status
= EFI_SUCCESS
;
1734 // No root directory. Find filename from the current directory.
1736 Status
= InternalFindFile (BlockIo
,
1745 if (EFI_ERROR (Status
)) {
1750 // If the found file is a symlink, then find its respective FE/EFE and
1753 if (FE_ICB_FILE_TYPE (File
->FileEntry
) == UdfFileEntrySymlink
) {
1754 FreePool ((VOID
*)File
->FileIdentifierDesc
);
1756 FileEntry
= File
->FileEntry
;
1758 Status
= ResolveSymlink (BlockIo
,
1765 FreePool (FileEntry
);
1767 if (EFI_ERROR (Status
)) {
1772 if (CompareMem ((VOID
*)&PreviousFile
, (VOID
*)Parent
,
1773 sizeof (UDF_FILE_INFO
)) != 0) {
1774 CleanupFileInformation (&PreviousFile
);
1777 CopyMem ((VOID
*)&PreviousFile
, (VOID
*)File
, sizeof (UDF_FILE_INFO
));
1778 if (*FilePath
!= L
'\0' && *FilePath
== L
'\\') {
1787 Read a directory entry at a time on an UDF volume.
1789 @param[in] BlockIo BlockIo interface.
1790 @param[in] DiskIo DiskIo interface.
1791 @param[in] Volume UDF volume information structure.
1792 @param[in] ParentIcb ICB of the parent file.
1793 @param[in] FileEntryData FE/EFE of the parent file.
1794 @param[in, out] ReadDirInfo Next read directory listing structure
1796 @param[out] FoundFid File Identifier Descriptor pointer.
1798 @retval EFI_SUCCESS Directory entry read.
1799 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
1800 @retval EFI_NO_MEDIA The device has no media.
1801 @retval EFI_DEVICE_ERROR The device reported an error.
1802 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1803 @retval EFI_OUT_OF_RESOURCES The directory entry was not read due to lack of
1808 ReadDirectoryEntry (
1809 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1810 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1811 IN UDF_VOLUME_INFO
*Volume
,
1812 IN UDF_LONG_ALLOCATION_DESCRIPTOR
*ParentIcb
,
1813 IN VOID
*FileEntryData
,
1814 IN OUT UDF_READ_DIRECTORY_INFO
*ReadDirInfo
,
1815 OUT UDF_FILE_IDENTIFIER_DESCRIPTOR
**FoundFid
1819 UDF_READ_FILE_INFO ReadFileInfo
;
1820 UDF_FILE_IDENTIFIER_DESCRIPTOR
*FileIdentifierDesc
;
1822 if (ReadDirInfo
->DirectoryData
== NULL
) {
1824 // The directory's recorded data has not been read yet. So let's cache it
1825 // into memory and the next calls won't need to read it again.
1827 ReadFileInfo
.Flags
= ReadFileAllocateAndRead
;
1837 if (EFI_ERROR (Status
)) {
1842 // Fill in ReadDirInfo structure with the read directory's data information.
1844 ReadDirInfo
->DirectoryData
= ReadFileInfo
.FileData
;
1845 ReadDirInfo
->DirectoryLength
= ReadFileInfo
.ReadLength
;
1849 if (ReadDirInfo
->FidOffset
>= ReadDirInfo
->DirectoryLength
) {
1851 // There are no longer FIDs for this directory. By returning
1852 // EFI_DEVICE_ERROR to the callee will indicate end of directory
1855 return EFI_DEVICE_ERROR
;
1859 // Get FID for this entry.
1861 FileIdentifierDesc
= GET_FID_FROM_ADS (ReadDirInfo
->DirectoryData
,
1862 ReadDirInfo
->FidOffset
);
1864 // Update FidOffset to point to next FID.
1866 ReadDirInfo
->FidOffset
+= GetFidDescriptorLength (FileIdentifierDesc
);
1867 } while (FileIdentifierDesc
->FileCharacteristics
& DELETED_FILE
);
1869 DuplicateFid (FileIdentifierDesc
, FoundFid
);
1875 Get a filename (encoded in OSTA-compressed format) from a File Identifier
1876 Descriptor on an UDF volume.
1878 @param[in] FileIdentifierDesc File Identifier Descriptor pointer.
1879 @param[out] FileName Decoded filename.
1881 @retval EFI_SUCCESS Filename decoded and read.
1882 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1885 GetFileNameFromFid (
1886 IN UDF_FILE_IDENTIFIER_DESCRIPTOR
*FileIdentifierDesc
,
1887 OUT CHAR16
*FileName
1890 UINT8
*OstaCompressed
;
1891 UINT8 CompressionId
;
1897 (UINT8
*)FileIdentifierDesc
->Data
+
1898 FileIdentifierDesc
->LengthOfImplementationUse
1901 CompressionId
= OstaCompressed
[0];
1902 if (!IS_VALID_COMPRESSION_ID (CompressionId
)) {
1903 return EFI_VOLUME_CORRUPTED
;
1909 Length
= FileIdentifierDesc
->LengthOfFileIdentifier
;
1910 for (Index
= 1; Index
< Length
; Index
++) {
1911 if (CompressionId
== 16) {
1912 *FileName
= OstaCompressed
[Index
++] << 8;
1917 if (Index
< Length
) {
1918 *FileName
|= (CHAR16
)(OstaCompressed
[Index
]);
1930 Resolve a symlink file on an UDF volume.
1932 @param[in] BlockIo BlockIo interface.
1933 @param[in] DiskIo DiskIo interface.
1934 @param[in] Volume UDF volume information structure.
1935 @param[in] Parent Parent file.
1936 @param[in] FileEntryData FE/EFE structure pointer.
1937 @param[out] File Resolved file.
1939 @retval EFI_SUCCESS Symlink file resolved.
1940 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
1941 @retval EFI_NO_MEDIA The device has no media.
1942 @retval EFI_DEVICE_ERROR The device reported an error.
1943 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1944 @retval EFI_OUT_OF_RESOURCES The symlink file was not resolved due to lack of
1950 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
1951 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
1952 IN UDF_VOLUME_INFO
*Volume
,
1953 IN UDF_FILE_INFO
*Parent
,
1954 IN VOID
*FileEntryData
,
1955 OUT UDF_FILE_INFO
*File
1959 UDF_READ_FILE_INFO ReadFileInfo
;
1963 UDF_PATH_COMPONENT
*PathComp
;
1964 UINT8 PathCompLength
;
1965 CHAR16 FileName
[UDF_FILENAME_LENGTH
];
1968 UINT8 CompressionId
;
1969 UDF_FILE_INFO PreviousFile
;
1972 // Symlink files on UDF volumes do not contain so much data other than
1973 // Path Components which resolves to real filenames, so it's OK to read in
1974 // all its data here -- usually the data will be inline with the FE/EFE for
1977 ReadFileInfo
.Flags
= ReadFileAllocateAndRead
;
1983 &Parent
->FileIdentifierDesc
->Icb
,
1987 if (EFI_ERROR (Status
)) {
1991 Length
= ReadFileInfo
.ReadLength
;
1993 Data
= (UINT8
*)ReadFileInfo
.FileData
;
1994 EndData
= Data
+ Length
;
1996 CopyMem ((VOID
*)&PreviousFile
, (VOID
*)Parent
, sizeof (UDF_FILE_INFO
));
1999 PathComp
= (UDF_PATH_COMPONENT
*)Data
;
2001 PathCompLength
= PathComp
->LengthOfComponentIdentifier
;
2003 switch (PathComp
->ComponentType
) {
2006 // This Path Component specifies the root directory hierarchy subject to
2007 // agreement between the originator and recipient of the medium. Skip it.
2013 // "\\." of the current directory. Read next Path Component.
2015 goto Next_Path_Component
;
2018 // ".." (parent directory). Go to it.
2020 CopyMem ((VOID
*)FileName
, L
"..", 6);
2024 // "." (current file). Duplicate both FE/EFE and FID of this file.
2026 DuplicateFe (BlockIo
, Volume
, PreviousFile
.FileEntry
, &File
->FileEntry
);
2027 DuplicateFid (PreviousFile
.FileIdentifierDesc
,
2028 &File
->FileIdentifierDesc
);
2029 goto Next_Path_Component
;
2032 // This Path Component identifies an object, either a file or a
2033 // directory or an alias.
2035 // Decode it from the compressed data in ComponentIdentifier and find
2038 CompressionId
= PathComp
->ComponentIdentifier
[0];
2039 if (!IS_VALID_COMPRESSION_ID (CompressionId
)) {
2040 return EFI_VOLUME_CORRUPTED
;
2044 for (Index
= 1; Index
< PathCompLength
; Index
++) {
2045 if (CompressionId
== 16) {
2046 *Char
= *(UINT8
*)((UINT8
*)PathComp
->ComponentIdentifier
+
2053 if (Index
< Length
) {
2054 *Char
|= (CHAR16
)(*(UINT8
*)((UINT8
*)PathComp
->ComponentIdentifier
+ Index
));
2065 // Find file from the read filename in symlink's file data.
2067 Status
= InternalFindFile (
2076 if (EFI_ERROR (Status
)) {
2077 goto Error_Find_File
;
2080 Next_Path_Component
:
2081 Data
+= sizeof (UDF_PATH_COMPONENT
) + PathCompLength
;
2082 if (Data
>= EndData
) {
2086 if (CompareMem ((VOID
*)&PreviousFile
, (VOID
*)Parent
,
2087 sizeof (UDF_FILE_INFO
)) != 0) {
2088 CleanupFileInformation (&PreviousFile
);
2091 CopyMem ((VOID
*)&PreviousFile
, (VOID
*)File
, sizeof (UDF_FILE_INFO
));
2095 // Unmap the symlink file.
2097 FreePool (ReadFileInfo
.FileData
);
2102 if (CompareMem ((VOID
*)&PreviousFile
, (VOID
*)Parent
,
2103 sizeof (UDF_FILE_INFO
)) != 0) {
2104 CleanupFileInformation (&PreviousFile
);
2107 FreePool (ReadFileInfo
.FileData
);
2113 Clean up in-memory UDF file information.
2115 @param[in] File File information pointer.
2119 CleanupFileInformation (
2120 IN UDF_FILE_INFO
*File
2123 if (File
->FileEntry
!= NULL
) {
2124 FreePool (File
->FileEntry
);
2126 if (File
->FileIdentifierDesc
!= NULL
) {
2127 FreePool ((VOID
*)File
->FileIdentifierDesc
);
2130 ZeroMem ((VOID
*)File
, sizeof (UDF_FILE_INFO
));
2134 Find a file from its absolute path on an UDF volume.
2136 @param[in] BlockIo BlockIo interface.
2137 @param[in] DiskIo DiskIo interface.
2138 @param[in] Volume UDF volume information structure.
2139 @param[in] File File information structure.
2140 @param[out] Size Size of the file.
2142 @retval EFI_SUCCESS File size calculated and set in Size.
2143 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
2144 @retval EFI_NO_MEDIA The device has no media.
2145 @retval EFI_DEVICE_ERROR The device reported an error.
2146 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
2147 @retval EFI_OUT_OF_RESOURCES The file size was not calculated due to lack of
2153 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
2154 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
2155 IN UDF_VOLUME_INFO
*Volume
,
2156 IN UDF_FILE_INFO
*File
,
2161 UDF_READ_FILE_INFO ReadFileInfo
;
2163 ReadFileInfo
.Flags
= ReadFileGetFileSize
;
2169 &File
->FileIdentifierDesc
->Icb
,
2173 if (EFI_ERROR (Status
)) {
2177 *Size
= ReadFileInfo
.ReadLength
;
2183 Set information about a file on an UDF volume.
2185 @param[in] File File pointer.
2186 @param[in] FileSize Size of the file.
2187 @param[in] FileName Filename of the file.
2188 @param[in, out] BufferSize Size of the returned file infomation.
2189 @param[out] Buffer Data of the returned file information.
2191 @retval EFI_SUCCESS File information set.
2192 @retval EFI_NO_MEDIA The device has no media.
2193 @retval EFI_DEVICE_ERROR The device reported an error.
2194 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
2195 @retval EFI_OUT_OF_RESOURCES The file information was not set due to lack of
2201 IN UDF_FILE_INFO
*File
,
2203 IN CHAR16
*FileName
,
2204 IN OUT UINTN
*BufferSize
,
2208 UINTN FileInfoLength
;
2209 EFI_FILE_INFO
*FileInfo
;
2210 UDF_FILE_ENTRY
*FileEntry
;
2211 UDF_EXTENDED_FILE_ENTRY
*ExtendedFileEntry
;
2212 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
2215 // Calculate the needed size for the EFI_FILE_INFO structure.
2217 FileInfoLength
= sizeof (EFI_FILE_INFO
) + ((FileName
!= NULL
) ?
2218 StrSize (FileName
) :
2220 if (*BufferSize
< FileInfoLength
) {
2222 // The given Buffer has no size enough for EFI_FILE_INFO structure.
2224 *BufferSize
= FileInfoLength
;
2225 return EFI_BUFFER_TOO_SMALL
;
2229 // Buffer now contains room enough to store EFI_FILE_INFO structure.
2230 // Now, fill it in with all necessary information about the file.
2232 FileInfo
= (EFI_FILE_INFO
*)Buffer
;
2233 FileInfo
->Size
= FileInfoLength
;
2234 FileInfo
->Attribute
&= ~EFI_FILE_VALID_ATTR
;
2235 FileInfo
->Attribute
|= EFI_FILE_READ_ONLY
;
2237 if (IS_FID_DIRECTORY_FILE (File
->FileIdentifierDesc
)) {
2238 FileInfo
->Attribute
|= EFI_FILE_DIRECTORY
;
2239 } else if (IS_FID_NORMAL_FILE (File
->FileIdentifierDesc
)) {
2240 FileInfo
->Attribute
|= EFI_FILE_ARCHIVE
;
2243 if (IS_FID_HIDDEN_FILE (File
->FileIdentifierDesc
)) {
2244 FileInfo
->Attribute
|= EFI_FILE_HIDDEN
;
2247 DescriptorTag
= File
->FileEntry
;
2249 if (DescriptorTag
->TagIdentifier
== UdfFileEntry
) {
2250 FileEntry
= (UDF_FILE_ENTRY
*)File
->FileEntry
;
2253 // Check if FE has the system attribute set.
2255 if (FileEntry
->IcbTag
.Flags
& (1 << 10)) {
2256 FileInfo
->Attribute
|= EFI_FILE_SYSTEM
;
2259 FileInfo
->FileSize
= FileSize
;
2260 FileInfo
->PhysicalSize
= FileSize
;
2262 FileInfo
->CreateTime
.Year
= FileEntry
->AccessTime
.Year
;
2263 FileInfo
->CreateTime
.Month
= FileEntry
->AccessTime
.Month
;
2264 FileInfo
->CreateTime
.Day
= FileEntry
->AccessTime
.Day
;
2265 FileInfo
->CreateTime
.Hour
= FileEntry
->AccessTime
.Hour
;
2266 FileInfo
->CreateTime
.Minute
= FileEntry
->AccessTime
.Second
;
2267 FileInfo
->CreateTime
.Second
= FileEntry
->AccessTime
.Second
;
2268 FileInfo
->CreateTime
.Nanosecond
=
2269 FileEntry
->AccessTime
.HundredsOfMicroseconds
;
2271 FileInfo
->LastAccessTime
.Year
=
2272 FileEntry
->AccessTime
.Year
;
2273 FileInfo
->LastAccessTime
.Month
=
2274 FileEntry
->AccessTime
.Month
;
2275 FileInfo
->LastAccessTime
.Day
=
2276 FileEntry
->AccessTime
.Day
;
2277 FileInfo
->LastAccessTime
.Hour
=
2278 FileEntry
->AccessTime
.Hour
;
2279 FileInfo
->LastAccessTime
.Minute
=
2280 FileEntry
->AccessTime
.Minute
;
2281 FileInfo
->LastAccessTime
.Second
=
2282 FileEntry
->AccessTime
.Second
;
2283 FileInfo
->LastAccessTime
.Nanosecond
=
2284 FileEntry
->AccessTime
.HundredsOfMicroseconds
;
2285 } else if (DescriptorTag
->TagIdentifier
== UdfExtendedFileEntry
) {
2286 ExtendedFileEntry
= (UDF_EXTENDED_FILE_ENTRY
*)File
->FileEntry
;
2289 // Check if EFE has the system attribute set.
2291 if (ExtendedFileEntry
->IcbTag
.Flags
& (1 << 10)) {
2292 FileInfo
->Attribute
|= EFI_FILE_SYSTEM
;
2295 FileInfo
->FileSize
= FileSize
;
2296 FileInfo
->PhysicalSize
= FileSize
;
2298 FileInfo
->CreateTime
.Year
= ExtendedFileEntry
->CreationTime
.Year
;
2299 FileInfo
->CreateTime
.Month
= ExtendedFileEntry
->CreationTime
.Month
;
2300 FileInfo
->CreateTime
.Day
= ExtendedFileEntry
->CreationTime
.Day
;
2301 FileInfo
->CreateTime
.Hour
= ExtendedFileEntry
->CreationTime
.Hour
;
2302 FileInfo
->CreateTime
.Minute
= ExtendedFileEntry
->CreationTime
.Second
;
2303 FileInfo
->CreateTime
.Second
= ExtendedFileEntry
->CreationTime
.Second
;
2304 FileInfo
->CreateTime
.Nanosecond
=
2305 ExtendedFileEntry
->AccessTime
.HundredsOfMicroseconds
;
2307 FileInfo
->LastAccessTime
.Year
=
2308 ExtendedFileEntry
->AccessTime
.Year
;
2309 FileInfo
->LastAccessTime
.Month
=
2310 ExtendedFileEntry
->AccessTime
.Month
;
2311 FileInfo
->LastAccessTime
.Day
=
2312 ExtendedFileEntry
->AccessTime
.Day
;
2313 FileInfo
->LastAccessTime
.Hour
=
2314 ExtendedFileEntry
->AccessTime
.Hour
;
2315 FileInfo
->LastAccessTime
.Minute
=
2316 ExtendedFileEntry
->AccessTime
.Minute
;
2317 FileInfo
->LastAccessTime
.Second
=
2318 ExtendedFileEntry
->AccessTime
.Second
;
2319 FileInfo
->LastAccessTime
.Nanosecond
=
2320 ExtendedFileEntry
->AccessTime
.HundredsOfMicroseconds
;
2323 FileInfo
->CreateTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
2324 FileInfo
->CreateTime
.Daylight
= EFI_TIME_ADJUST_DAYLIGHT
;
2325 FileInfo
->LastAccessTime
.TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
2326 FileInfo
->LastAccessTime
.Daylight
= EFI_TIME_ADJUST_DAYLIGHT
;
2328 CopyMem ((VOID
*)&FileInfo
->ModificationTime
,
2329 (VOID
*)&FileInfo
->LastAccessTime
,
2332 if (FileName
!= NULL
) {
2333 StrCpyS (FileInfo
->FileName
, StrLen (FileName
) + 1, FileName
);
2335 FileInfo
->FileName
[0] = '\0';
2338 *BufferSize
= FileInfoLength
;
2344 Get volume and free space size information of an UDF volume.
2346 @param[in] BlockIo BlockIo interface.
2347 @param[in] DiskIo DiskIo interface.
2348 @param[in] Volume UDF volume information structure.
2349 @param[out] VolumeSize Volume size.
2350 @param[out] FreeSpaceSize Free space size.
2352 @retval EFI_SUCCESS Volume and free space size calculated.
2353 @retval EFI_NO_MEDIA The device has no media.
2354 @retval EFI_DEVICE_ERROR The device reported an error.
2355 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
2356 @retval EFI_OUT_OF_RESOURCES The volume and free space size were not
2357 calculated due to lack of resources.
2362 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
2363 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
2364 IN UDF_VOLUME_INFO
*Volume
,
2365 OUT UINT64
*VolumeSize
,
2366 OUT UINT64
*FreeSpaceSize
2370 UDF_LOGICAL_VOLUME_DESCRIPTOR
*LogicalVolDesc
;
2371 UDF_EXTENT_AD
*ExtentAd
;
2373 UINT32 LogicalBlockSize
;
2374 UDF_LOGICAL_VOLUME_INTEGRITY
*LogicalVolInt
;
2375 UDF_DESCRIPTOR_TAG
*DescriptorTag
;
2380 LogicalVolDesc
= &Volume
->LogicalVolDesc
;
2382 ExtentAd
= &LogicalVolDesc
->IntegritySequenceExtent
;
2384 if (ExtentAd
->ExtentLength
== 0) {
2385 return EFI_VOLUME_CORRUPTED
;
2388 LogicalVolInt
= AllocatePool (ExtentAd
->ExtentLength
);
2389 if (LogicalVolInt
== NULL
) {
2390 return EFI_OUT_OF_RESOURCES
;
2394 // Get location of Logical Volume Integrity Descriptor
2396 Lsn
= (UINT64
)ExtentAd
->ExtentLocation
- Volume
->MainVdsStartLocation
;
2398 LogicalBlockSize
= LogicalVolDesc
->LogicalBlockSize
;
2403 Status
= DiskIo
->ReadDisk (
2405 BlockIo
->Media
->MediaId
,
2406 MultU64x32 (Lsn
, LogicalBlockSize
),
2407 ExtentAd
->ExtentLength
,
2410 if (EFI_ERROR (Status
)) {
2414 DescriptorTag
= &LogicalVolInt
->DescriptorTag
;
2417 // Check if read block is a Logical Volume Integrity Descriptor
2419 if (DescriptorTag
->TagIdentifier
!= UdfLogicalVolumeIntegrityDescriptor
) {
2420 Status
= EFI_VOLUME_CORRUPTED
;
2427 Length
= LogicalVolInt
->NumberOfPartitions
;
2428 for (Index
= 0; Index
< Length
; Index
+= sizeof (UINT32
)) {
2429 LsnsNo
= *(UINT32
*)((UINT8
*)LogicalVolInt
->Data
+ Index
);
2431 // Check if size is not specified
2433 if (LsnsNo
== 0xFFFFFFFFUL
) {
2437 // Accumulate free space size
2439 *FreeSpaceSize
+= MultU64x32 ((UINT64
)LsnsNo
, LogicalBlockSize
);
2442 Length
= LogicalVolInt
->NumberOfPartitions
* sizeof (UINT32
) * 2;
2443 for (; Index
< Length
; Index
+= sizeof (UINT32
)) {
2444 LsnsNo
= *(UINT32
*)((UINT8
*)LogicalVolInt
->Data
+ Index
);
2446 // Check if size is not specified
2448 if (LsnsNo
== 0xFFFFFFFFUL
) {
2452 // Accumulate used volume space
2454 *VolumeSize
+= MultU64x32 ((UINT64
)LsnsNo
, LogicalBlockSize
);
2457 Status
= EFI_SUCCESS
;
2461 // Free Logical Volume Integrity Descriptor
2463 FreePool (LogicalVolInt
);
2469 Seek a file and read its data into memory on an UDF volume.
2471 @param[in] BlockIo BlockIo interface.
2472 @param[in] DiskIo DiskIo interface.
2473 @param[in] Volume UDF volume information structure.
2474 @param[in] File File information structure.
2475 @param[in] FileSize Size of the file.
2476 @param[in, out] FilePosition File position.
2477 @param[in, out] Buffer File data.
2478 @param[in, out] BufferSize Read size.
2480 @retval EFI_SUCCESS File seeked and read.
2481 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
2482 @retval EFI_NO_MEDIA The device has no media.
2483 @retval EFI_DEVICE_ERROR The device reported an error.
2484 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
2485 @retval EFI_OUT_OF_RESOURCES The file's recorded data was not read due to lack
2491 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
2492 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
2493 IN UDF_VOLUME_INFO
*Volume
,
2494 IN UDF_FILE_INFO
*File
,
2496 IN OUT UINT64
*FilePosition
,
2497 IN OUT VOID
*Buffer
,
2498 IN OUT UINT64
*BufferSize
2502 UDF_READ_FILE_INFO ReadFileInfo
;
2504 ReadFileInfo
.Flags
= ReadFileSeekAndRead
;
2505 ReadFileInfo
.FilePosition
= *FilePosition
;
2506 ReadFileInfo
.FileData
= Buffer
;
2507 ReadFileInfo
.FileDataSize
= *BufferSize
;
2508 ReadFileInfo
.FileSize
= FileSize
;
2514 &File
->FileIdentifierDesc
->Icb
,
2518 if (EFI_ERROR (Status
)) {
2522 *BufferSize
= ReadFileInfo
.FileDataSize
;
2523 *FilePosition
= ReadFileInfo
.FilePosition
;
2529 Check if ControllerHandle supports an UDF file system.
2531 @param[in] This Protocol instance pointer.
2532 @param[in] ControllerHandle Handle of device to test.
2534 @retval EFI_SUCCESS UDF file system found.
2535 @retval EFI_UNSUPPORTED UDF file system not found.
2539 SupportUdfFileSystem (
2540 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2541 IN EFI_HANDLE ControllerHandle
2545 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
2546 EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
;
2547 EFI_DEVICE_PATH_PROTOCOL
*LastDevicePathNode
;
2548 EFI_GUID
*VendorDefinedGuid
;
2551 // Open Device Path protocol on ControllerHandle
2553 Status
= gBS
->OpenProtocol (
2555 &gEfiDevicePathProtocolGuid
,
2556 (VOID
**)&DevicePath
,
2557 This
->DriverBindingHandle
,
2559 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2561 if (EFI_ERROR (Status
)) {
2562 return EFI_UNSUPPORTED
;
2565 Status
= EFI_UNSUPPORTED
;
2568 // Get last Device Path node
2570 LastDevicePathNode
= NULL
;
2571 DevicePathNode
= DevicePath
;
2572 while (!IsDevicePathEnd (DevicePathNode
)) {
2573 LastDevicePathNode
= DevicePathNode
;
2574 DevicePathNode
= NextDevicePathNode (DevicePathNode
);
2577 // Check if last Device Path node contains a Vendor-Defined Media Device Path
2578 // of an UDF file system.
2580 if (LastDevicePathNode
!= NULL
&&
2581 DevicePathType (LastDevicePathNode
) == MEDIA_DEVICE_PATH
&&
2582 DevicePathSubType (LastDevicePathNode
) == MEDIA_VENDOR_DP
) {
2583 VendorDefinedGuid
= (EFI_GUID
*)((UINTN
)LastDevicePathNode
+
2584 OFFSET_OF (VENDOR_DEVICE_PATH
, Guid
));
2585 if (CompareGuid (VendorDefinedGuid
, &gUdfDevPathGuid
)) {
2586 Status
= EFI_SUCCESS
;
2591 // Close Device Path protocol on ControllerHandle
2593 gBS
->CloseProtocol (
2595 &gEfiDevicePathProtocolGuid
,
2596 This
->DriverBindingHandle
,