X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FDisk%2FUdfDxe%2FFileSystemOperations.c;h=5df267761ff6e2c0c115a17342136b38f4834b60;hp=904262a2ba5cec52d2c840779e986fe228686de1;hb=880ec68338541b63672ea521c0dffee181df8ede;hpb=b434f7532770714b1683b73cd54b8a38d5674251 diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c index 904262a2ba..5df267761f 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c @@ -14,6 +14,23 @@ #include "Udf.h" +// +// Vendor-Defined Device Path GUID for UDF file system +// +EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID; + +/** + Find the anchor volume descriptor pointer. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[out] AnchorPoint Anchor volume descriptor pointer. + + @retval EFI_SUCCESS Anchor volume descriptor pointer found. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval other Anchor volume descriptor pointer not found. + +**/ EFI_STATUS FindAnchorVolumeDescriptorPointer ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -58,6 +75,22 @@ FindAnchorVolumeDescriptorPointer ( return EFI_VOLUME_CORRUPTED; } +/** + Save the content of Logical Volume Descriptors and Partitions Descriptors in + memory. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] AnchorPoint Anchor volume descriptor pointer. + @param[out] Volume UDF volume information structure. + + @retval EFI_SUCCESS The descriptors were saved. + @retval EFI_OUT_OF_RESOURCES The descriptors were not saved due to lack of + resources. + @retval other The descriptors were not saved due to + ReadDisk error. + +**/ EFI_STATUS StartMainVolumeDescriptorSequence ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -211,11 +244,17 @@ Error_Alloc_Pds: return Status; } -// -// Return a Partition Descriptor given a Long Allocation Descriptor. This is -// necessary to calculate the right extent (LongAd) offset which is added up -// with partition's starting location. -// +/** + Return a Partition Descriptor given a Long Allocation Descriptor. This is + necessary to calculate the right extent (LongAd) offset which is added up + with partition's starting location. + + @param[in] Volume Volume information pointer. + @param[in] LongAd Long Allocation Descriptor pointer. + + @return A pointer to a Partition Descriptor. + +**/ UDF_PARTITION_DESCRIPTOR * GetPdFromLongAd ( IN UDF_VOLUME_INFO *Volume, @@ -270,9 +309,15 @@ GetPdFromLongAd ( return NULL; } -// -// Return logical sector number of a given Long Allocation Descriptor. -// +/** + Return logical sector number of a given Long Allocation Descriptor. + + @param[in] Volume Volume information pointer. + @param[in] LongAd Long Allocation Descriptor pointer. + + @return The logical sector number of a given Long Allocation Descriptor. + +**/ UINT64 GetLongAdLsn ( IN UDF_VOLUME_INFO *Volume, @@ -288,25 +333,44 @@ GetLongAdLsn ( LongAd->ExtentLocation.LogicalBlockNumber; } -// -// Return logical sector number of a given Short Allocation Descriptor. -// +/** + Return logical sector number of a given Short Allocation Descriptor. + + @param[in] PartitionDesc Partition Descriptor pointer. + @param[in] ShortAd Short Allocation Descriptor pointer. + + @return The logical sector number of a given Short Allocation Descriptor. + +**/ UINT64 GetShortAdLsn ( IN UDF_PARTITION_DESCRIPTOR *PartitionDesc, IN UDF_SHORT_ALLOCATION_DESCRIPTOR *ShortAd ) { + ASSERT (PartitionDesc != NULL); + return (UINT64)PartitionDesc->PartitionStartingLocation + ShortAd->ExtentPosition; } -// -// Find File Set Descriptor of a given Logical Volume Descriptor. -// -// The found FSD will contain the extent (LogicalVolumeContentsUse) where our -// root directory is. -// +/** + Find File Set Descriptor of a given Logical Volume Descriptor. + + The found FSD will contain the extent (LogicalVolumeContentsUse) where our + root directory is. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] Volume Volume information pointer. + @param[in] LogicalVolDescNum Index of Logical Volume Descriptor + @param[out] FileSetDesc File Set Descriptor pointer. + + @retval EFI_SUCCESS File Set Descriptor pointer found. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval other File Set Descriptor pointer not found. + +**/ EFI_STATUS FindFileSetDescriptor ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -347,9 +411,20 @@ FindFileSetDescriptor ( return EFI_SUCCESS; } -// -// Get all File Set Descriptors for each Logical Volume Descriptor. -// +/** + Get all File Set Descriptors for each Logical Volume Descriptor. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in, out] Volume Volume information pointer. + + @retval EFI_SUCCESS File Set Descriptors were got. + @retval EFI_OUT_OF_RESOURCES File Set Descriptors were not got due to lack + of resources. + @retval other Error occured when finding File Set + Descriptor in Logical Volume Descriptor. + +**/ EFI_STATUS GetFileSetDescriptors ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -412,9 +487,17 @@ Error_Alloc_Fsd: return Status; } -// -// Read Volume and File Structure on an UDF file system. -// +/** + Read Volume and File Structure on an UDF file system. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[out] Volume Volume information pointer. + + @retval EFI_SUCCESS Volume and File Structure were read. + @retval other Volume and File Structure were not read. + +**/ EFI_STATUS ReadVolumeFileStructure ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -453,9 +536,14 @@ ReadVolumeFileStructure ( return Status; } -// -// Calculate length of a given File Identifier Descriptor. -// +/** + Calculate length of a given File Identifier Descriptor. + + @param[in] FileIdentifierDesc File Identifier Descriptor pointer. + + @return The length of a given File Identifier Descriptor. + +**/ UINT64 GetFidDescriptorLength ( IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc @@ -468,9 +556,13 @@ GetFidDescriptorLength ( ); } -// -// Duplicate a given File Identifier Descriptor. -// +/** + Duplicate a given File Identifier Descriptor. + + @param[in] FileIdentifierDesc File Identifier Descriptor pointer. + @param[out] NewFileIdentifierDesc The duplicated File Identifier Descriptor. + +**/ VOID DuplicateFid ( IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc, @@ -480,11 +572,19 @@ DuplicateFid ( *NewFileIdentifierDesc = (UDF_FILE_IDENTIFIER_DESCRIPTOR *)AllocateCopyPool ( (UINTN) GetFidDescriptorLength (FileIdentifierDesc), FileIdentifierDesc); + + ASSERT (*NewFileIdentifierDesc != NULL); } -// -// Duplicate either a given File Entry or a given Extended File Entry. -// +/** + Duplicate either a given File Entry or a given Extended File Entry. + + @param[in] BlockIo BlockIo interface. + @param[in] Volume Volume information pointer. + @param[in] FileEntry (Extended) File Entry pointer. + @param[out] NewFileEntry The duplicated (Extended) File Entry. + +**/ VOID DuplicateFe ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -494,17 +594,25 @@ DuplicateFe ( ) { *NewFileEntry = AllocateCopyPool (Volume->FileEntrySize, FileEntry); + + ASSERT (*NewFileEntry != NULL); } -// -// Get raw data + length of a given File Entry or Extended File Entry. -// -// The file's recorded data can contain either real file content (inline) or -// a sequence of extents (or Allocation Descriptors) which tells where file's -// content is stored in. -// -// NOTE: The FE/EFE can be thought it was an inode. -// +/** + Get raw data + length of a given File Entry or Extended File Entry. + + The file's recorded data can contain either real file content (inline) or + a sequence of extents (or Allocation Descriptors) which tells where file's + content is stored in. + + NOTE: The FE/EFE can be thought it was an inode. + + @param[in] FileEntryData (Extended) File Entry pointer. + @param[out] Data Buffer contains the raw data of a given + (Extended) File Entry. + @param[out] Length Length of the data in Buffer. + +**/ VOID GetFileEntryData ( IN VOID *FileEntryData, @@ -530,9 +638,15 @@ GetFileEntryData ( } } -// -// Get Allocation Descriptors' data information from a given FE/EFE. -// +/** + Get Allocation Descriptors' data information from a given FE/EFE. + + @param[in] FileEntryData (Extended) File Entry pointer. + @param[out] AdsData Buffer contains the Allocation Descriptors' + data from a given FE/EFE. + @param[out] Length Length of the data in AdsData. + +**/ VOID GetAdsInformation ( IN VOID *FileEntryData, @@ -558,9 +672,18 @@ GetAdsInformation ( } } -// -// Read next Long Allocation Descriptor from a given file's data. -// +/** + Read next Long Allocation Descriptor from a given file's data. + + @param[in] Data File's data pointer. + @param[in,out] Offset Starting offset of the File's data to read. + @param[in] Length Length of the data to read. + @param[out] FoundLongAd Long Allocation Descriptor pointer. + + @retval EFI_SUCCESS A Long Allocation Descriptor was found. + @retval EFI_DEVICE_ERROR No more Long Allocation Descriptors. + +**/ EFI_STATUS GetLongAdFromAds ( IN VOID *Data, @@ -587,9 +710,9 @@ GetLongAdFromAds ( // If it's either an indirect AD (Extended Alllocation Descriptor) or an // allocated AD, then return it. // - ExtentFlags = GET_EXTENT_FLAGS (LONG_ADS_SEQUENCE, LongAd); - if (ExtentFlags == EXTENT_IS_NEXT_EXTENT || - ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) { + ExtentFlags = GET_EXTENT_FLAGS (LongAdsSequence, LongAd); + if (ExtentFlags == ExtentIsNextExtent || + ExtentFlags == ExtentRecordedAndAllocated) { break; } @@ -597,7 +720,7 @@ GetLongAdFromAds ( // This AD is either not recorded but allocated, or not recorded and not // allocated. Skip it. // - *Offset += AD_LENGTH (LONG_ADS_SEQUENCE); + *Offset += AD_LENGTH (LongAdsSequence); } *FoundLongAd = LongAd; @@ -605,9 +728,18 @@ GetLongAdFromAds ( return EFI_SUCCESS; } -// -// Read next Short Allocation Descriptor from a given file's data. -// +/** + Read next Short Allocation Descriptor from a given file's data. + + @param[in] Data File's data pointer. + @param[in,out] Offset Starting offset of the File's data to read. + @param[in] Length Length of the data to read. + @param[out] FoundShortAd Short Allocation Descriptor pointer. + + @retval EFI_SUCCESS A Short Allocation Descriptor was found. + @retval EFI_DEVICE_ERROR No more Short Allocation Descriptors. + +**/ EFI_STATUS GetShortAdFromAds ( IN VOID *Data, @@ -634,9 +766,9 @@ GetShortAdFromAds ( // If it's either an indirect AD (Extended Alllocation Descriptor) or an // allocated AD, then return it. // - ExtentFlags = GET_EXTENT_FLAGS (SHORT_ADS_SEQUENCE, ShortAd); - if (ExtentFlags == EXTENT_IS_NEXT_EXTENT || - ExtentFlags == EXTENT_RECORDED_AND_ALLOCATED) { + ExtentFlags = GET_EXTENT_FLAGS (ShortAdsSequence, ShortAd); + if (ExtentFlags == ExtentIsNextExtent || + ExtentFlags == ExtentRecordedAndAllocated) { break; } @@ -644,7 +776,7 @@ GetShortAdFromAds ( // This AD is either not recorded but allocated, or not recorded and not // allocated. Skip it. // - *Offset += AD_LENGTH (SHORT_ADS_SEQUENCE); + *Offset += AD_LENGTH (ShortAdsSequence); } *FoundShortAd = ShortAd; @@ -652,10 +784,21 @@ GetShortAdFromAds ( return EFI_SUCCESS; } -// -// Get either a Short Allocation Descriptor or a Long Allocation Descriptor from -// file's data. -// +/** + Get either a Short Allocation Descriptor or a Long Allocation Descriptor from + file's data. + + @param[in] RecordingFlags Flag to indicate the type of descriptor. + @param[in] Data File's data pointer. + @param[in,out] Offset Starting offset of the File's data to read. + @param[in] Length Length of the data to read. + @param[out] FoundAd Allocation Descriptor pointer. + + @retval EFI_SUCCESS A Short Allocation Descriptor was found. + @retval EFI_DEVICE_ERROR No more Allocation Descriptors. + Invalid type of descriptor was given. + +**/ EFI_STATUS GetAllocationDescriptor ( IN UDF_FE_RECORDING_FLAGS RecordingFlags, @@ -665,14 +808,14 @@ GetAllocationDescriptor ( OUT VOID **FoundAd ) { - if (RecordingFlags == LONG_ADS_SEQUENCE) { + if (RecordingFlags == LongAdsSequence) { return GetLongAdFromAds ( Data, Offset, Length, (UDF_LONG_ALLOCATION_DESCRIPTOR **)FoundAd ); - } else if (RecordingFlags == SHORT_ADS_SEQUENCE) { + } else if (RecordingFlags == ShortAdsSequence) { return GetShortAdFromAds ( Data, Offset, @@ -684,9 +827,17 @@ GetAllocationDescriptor ( return EFI_DEVICE_ERROR; } -// -// Return logical sector number of either Short or Long Allocation Descriptor. -// +/** + Return logical sector number of either Short or Long Allocation Descriptor. + + @param[in] RecordingFlags Flag to indicate the type of descriptor. + @param[in] Volume Volume information pointer. + @param[in] ParentIcb Long Allocation Descriptor pointer. + @param[in] Ad Allocation Descriptor pointer. + + @return The logical sector number of the given Allocation Descriptor. + +**/ UINT64 GetAllocationDescriptorLsn ( IN UDF_FE_RECORDING_FLAGS RecordingFlags, @@ -695,9 +846,9 @@ GetAllocationDescriptorLsn ( IN VOID *Ad ) { - if (RecordingFlags == LONG_ADS_SEQUENCE) { + if (RecordingFlags == LongAdsSequence) { return GetLongAdLsn (Volume, (UDF_LONG_ALLOCATION_DESCRIPTOR *)Ad); - } else if (RecordingFlags == SHORT_ADS_SEQUENCE) { + } else if (RecordingFlags == ShortAdsSequence) { return GetShortAdLsn ( GetPdFromLongAd (Volume, ParentIcb), (UDF_SHORT_ALLOCATION_DESCRIPTOR *)Ad @@ -707,9 +858,27 @@ GetAllocationDescriptorLsn ( return 0; } -// -// Return offset + length of a given indirect Allocation Descriptor (AED). -// +/** + Return offset + length of a given indirect Allocation Descriptor (AED). + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] Volume Volume information pointer. + @param[in] ParentIcb Long Allocation Descriptor pointer. + @param[in] RecordingFlags Flag to indicate the type of descriptor. + @param[in] Ad Allocation Descriptor pointer. + @param[out] Offset Offset of a given indirect Allocation + Descriptor. + @param[out] Length Length of a given indirect Allocation + Descriptor. + + @retval EFI_SUCCESS The offset and length were returned. + @retval EFI_OUT_OF_RESOURCES The offset and length were not returned due + to lack of resources. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval other The offset and length were not returned. + +**/ EFI_STATUS GetAedAdsOffset ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -778,9 +947,25 @@ Exit: return Status; } -// -// Read Allocation Extent Descriptor into memory. -// +/** + Read Allocation Extent Descriptor into memory. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] Volume Volume information pointer. + @param[in] ParentIcb Long Allocation Descriptor pointer. + @param[in] RecordingFlags Flag to indicate the type of descriptor. + @param[in] Ad Allocation Descriptor pointer. + @param[out] Data Buffer that contains the Allocation Extent + Descriptor. + @param[out] Length Length of Data. + + @retval EFI_SUCCESS The Allocation Extent Descriptor was read. + @retval EFI_OUT_OF_RESOURCES The Allocation Extent Descriptor was not read + due to lack of resources. + @retval other Fail to read the disk. + +**/ EFI_STATUS GetAedAdsData ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -830,9 +1015,19 @@ GetAedAdsData ( ); } -// -// Function used to serialise reads of Allocation Descriptors. -// +/** + Function used to serialise reads of Allocation Descriptors. + + @param[in] RecordingFlags Flag to indicate the type of descriptor. + @param[in] Ad Allocation Descriptor pointer. + @param[in, out] Buffer Buffer to hold the next Allocation Descriptor. + @param[in] Length Length of Buffer. + + @retval EFI_SUCCESS Buffer was grown to hold the next Allocation + Descriptor. + @retval EFI_OUT_OF_RESOURCES Buffer was not grown due to lack of resources. + +**/ EFI_STATUS GrowUpBufferToNextAd ( IN UDF_FE_RECORDING_FLAGS RecordingFlags, @@ -860,9 +1055,26 @@ GrowUpBufferToNextAd ( return EFI_SUCCESS; } -// -// Read data or size of either a File Entry or an Extended File Entry. -// +/** + Read data or size of either a File Entry or an Extended File Entry. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] Volume Volume information pointer. + @param[in] ParentIcb Long Allocation Descriptor pointer. + @param[in] FileEntryData FE/EFE structure pointer. + @param[in, out] ReadFileInfo Read file information pointer. + + @retval EFI_SUCCESS Data or size of a FE/EFE was read. + @retval EFI_OUT_OF_RESOURCES Data or size of a FE/EFE was not read due to + lack of resources. + @retval EFI_INVALID_PARAMETER The read file flag given in ReadFileInfo is + invalid. + @retval EFI_UNSUPPORTED The FE recording flag given in FileEntryData + is not supported. + @retval other Data or size of a FE/EFE was not read. + +**/ EFI_STATUS ReadFile ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -893,9 +1105,18 @@ ReadFile ( LogicalBlockSize = LV_BLOCK_SIZE (Volume, UDF_DEFAULT_LV_NUM); DoFreeAed = FALSE; + // + // set BytesLeft to suppress incorrect compiler/analyzer warnings + // + BytesLeft = 0; + DataOffset = 0; + FilePosition = 0; + FinishedSeeking = FALSE; + Data = NULL; + switch (ReadFileInfo->Flags) { - case READ_FILE_GET_FILESIZE: - case READ_FILE_ALLOCATE_AND_READ: + case ReadFileGetFileSize: + case ReadFileAllocateAndRead: // // Initialise ReadFileInfo structure for either getting file size, or // reading file's recorded data. @@ -903,7 +1124,7 @@ ReadFile ( ReadFileInfo->ReadLength = 0; ReadFileInfo->FileData = NULL; break; - case READ_FILE_SEEK_AND_READ: + case ReadFileSeekAndRead: // // About to seek a file and/or read its data. // @@ -928,15 +1149,15 @@ ReadFile ( RecordingFlags = GET_FE_RECORDING_FLAGS (FileEntryData); switch (RecordingFlags) { - case INLINE_DATA: + case InlineData: // // There are no extents for this FE/EFE. All data is inline. // GetFileEntryData (FileEntryData, &Data, &Length); - if (ReadFileInfo->Flags == READ_FILE_GET_FILESIZE) { + if (ReadFileInfo->Flags == ReadFileGetFileSize) { ReadFileInfo->ReadLength = Length; - } else if (ReadFileInfo->Flags == READ_FILE_ALLOCATE_AND_READ) { + } else if (ReadFileInfo->Flags == ReadFileAllocateAndRead) { // // Allocate buffer for starting read data. // @@ -950,7 +1171,7 @@ ReadFile ( // CopyMem (ReadFileInfo->FileData, Data, (UINTN) Length); ReadFileInfo->ReadLength = Length; - } else if (ReadFileInfo->Flags == READ_FILE_SEEK_AND_READ) { + } else if (ReadFileInfo->Flags == ReadFileSeekAndRead) { // // If FilePosition is non-zero, seek file to FilePosition, read // FileDataSize bytes and then updates FilePosition. @@ -962,11 +1183,16 @@ ReadFile ( ); ReadFileInfo->FilePosition += ReadFileInfo->FileDataSize; + } else { + ASSERT (FALSE); + return EFI_INVALID_PARAMETER; } + Status = EFI_SUCCESS; break; - case LONG_ADS_SEQUENCE: - case SHORT_ADS_SEQUENCE: + + case LongAdsSequence: + case ShortAdsSequence: // // This FE/EFE contains a run of Allocation Descriptors. Get data + size // for start reading them out. @@ -994,7 +1220,7 @@ ReadFile ( // Check if AD is an indirect AD. If so, read Allocation Extent // Descriptor and its extents (ADs). // - if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == EXTENT_IS_NEXT_EXTENT) { + if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == ExtentIsNextExtent) { if (!DoFreeAed) { DoFreeAed = TRUE; } else { @@ -1014,6 +1240,7 @@ ReadFile ( if (EFI_ERROR (Status)) { goto Error_Get_Aed; } + ASSERT (Data != NULL); AdOffset = 0; continue; @@ -1027,10 +1254,10 @@ ReadFile ( Ad); switch (ReadFileInfo->Flags) { - case READ_FILE_GET_FILESIZE: + case ReadFileGetFileSize: ReadFileInfo->ReadLength += ExtentLength; break; - case READ_FILE_ALLOCATE_AND_READ: + case ReadFileAllocateAndRead: // // Increase FileData (if necessary) to read next extent. // @@ -1061,7 +1288,7 @@ ReadFile ( ReadFileInfo->ReadLength += ExtentLength; break; - case READ_FILE_SEEK_AND_READ: + case ReadFileSeekAndRead: // // Seek file first before reading in its data. // @@ -1077,9 +1304,6 @@ ReadFile ( if (FilePosition + ExtentLength > ReadFileInfo->FilePosition) { Offset = ReadFileInfo->FilePosition - FilePosition; - if (Offset < 0) { - Offset = -(Offset); - } } else { Offset = 0; } @@ -1140,11 +1364,19 @@ ReadFile ( } break; - case EXTENDED_ADS_SEQUENCE: + case ExtendedAdsSequence: // FIXME: Not supported. Got no volume with it, yet. ASSERT (FALSE); Status = EFI_UNSUPPORTED; break; + + default: + // + // A flag value reserved by the ECMA-167 standard (3rd Edition - June + // 1997); 14.6 ICB Tag; 14.6.8 Flags (RBP 18); was found. + // + Status = EFI_UNSUPPORTED; + break; } Done: @@ -1156,7 +1388,7 @@ Done: Error_Read_Disk_Blk: Error_Alloc_Buffer_To_Next_Ad: - if (ReadFileInfo->Flags != READ_FILE_SEEK_AND_READ) { + if (ReadFileInfo->Flags != ReadFileSeekAndRead) { FreePool (ReadFileInfo->FileData); } @@ -1168,9 +1400,22 @@ Error_Get_Aed: return Status; } -// -// Find a file by its filename from a given Parent file. -// +/** + Find a file by its filename from a given Parent file. + + @param[in] BlockIo BlockIo interface. + @param[in] DiskIo DiskIo interface. + @param[in] Volume Volume information pointer. + @param[in] FileName File name string. + @param[in] Parent Parent directory file. + @param[in] Icb Long Allocation Descriptor pointer. + @param[out] File Found file. + + @retval EFI_SUCCESS The file was found. + @retval EFI_INVALID_PARAMETER One or more input parameters are invalid. + @retval EFI_NOT_FOUND The file was not found. + +**/ EFI_STATUS InternalFindFile ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo, @@ -1189,6 +1434,13 @@ InternalFindFile ( CHAR16 FoundFileName[UDF_FILENAME_LENGTH]; VOID *CompareFileEntry; + // + // Check if both Parent->FileIdentifierDesc and Icb are NULL. + // + if ((Parent->FileIdentifierDesc == NULL) && (Icb == NULL)) { + return EFI_INVALID_PARAMETER; + } + // // Check if parent file is really directory. // @@ -1201,6 +1453,10 @@ InternalFindFile ( // FE/EFE and FID descriptors. // if (StrCmp (FileName, L".") == 0) { + if (Parent->FileIdentifierDesc == NULL) { + return EFI_INVALID_PARAMETER; + } + DuplicateFe (BlockIo, Volume, Parent->FileEntry, &File->FileEntry); DuplicateFid (Parent->FileIdentifierDesc, &File->FileIdentifierDesc); @@ -1218,7 +1474,7 @@ InternalFindFile ( BlockIo, DiskIo, Volume, - Parent->FileIdentifierDesc ? + (Parent->FileIdentifierDesc != NULL) ? &Parent->FileIdentifierDesc->Icb : Icb, Parent->FileEntry, @@ -1494,13 +1750,14 @@ Error_Read_Disk_Blk: @param[in] FilePath File's absolute path. @param[in] Root Root directory file. @param[in] Parent Parent directory file. + @param[in] Icb ICB of Parent. @param[out] File Found file. - @retval EFI_SUCCESS @p FilePath was found. + @retval EFI_SUCCESS FilePath was 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 @p FilePath file was not found due to lack of + @retval EFI_OUT_OF_RESOURCES The FilePath file was not found due to lack of resources. **/ @@ -1621,7 +1878,7 @@ FindFile ( @param[in] Volume UDF volume information structure. @param[in] ParentIcb ICB of the parent file. @param[in] FileEntryData FE/EFE of the parent file. - @param[in out] ReadDirInfo Next read directory listing structure + @param[in, out] ReadDirInfo Next read directory listing structure information. @param[out] FoundFid File Identifier Descriptor pointer. @@ -1654,7 +1911,7 @@ ReadDirectoryEntry ( // The directory's recorded data has not been read yet. So let's cache it // into memory and the next calls won't need to read it again. // - ReadFileInfo.Flags = READ_FILE_ALLOCATE_AND_READ; + ReadFileInfo.Flags = ReadFileAllocateAndRead; Status = ReadFile ( BlockIo, @@ -1745,7 +2002,7 @@ GetFileNameFromFid ( } if (Index < Length) { - *FileName |= OstaCompressed[Index]; + *FileName |= (CHAR16)(OstaCompressed[Index]); } FileName++; @@ -1793,7 +2050,7 @@ ResolveSymlink ( UDF_PATH_COMPONENT *PathComp; UINT8 PathCompLength; CHAR16 FileName[UDF_FILENAME_LENGTH]; - CHAR16 *C; + CHAR16 *Char; UINTN Index; UINT8 CompressionId; UDF_FILE_INFO PreviousFile; @@ -1804,7 +2061,7 @@ ResolveSymlink ( // all its data here -- usually the data will be inline with the FE/EFE for // lower filenames. // - ReadFileInfo.Flags = READ_FILE_ALLOCATE_AND_READ; + ReadFileInfo.Flags = ReadFileAllocateAndRead; Status = ReadFile ( BlockIo, @@ -1870,24 +2127,24 @@ ResolveSymlink ( return EFI_VOLUME_CORRUPTED; } - C = FileName; + Char = FileName; for (Index = 1; Index < PathCompLength; Index++) { if (CompressionId == 16) { - *C = *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + + *Char = *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index) << 8; Index++; } else { - *C = 0; + *Char = 0; } if (Index < Length) { - *C |= *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index); + *Char |= (CHAR16)(*(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index)); } - C++; + Char++; } - *C = L'\0'; + *Char = L'\0'; break; } @@ -2006,7 +2263,7 @@ CleanupFileInformation ( @param[in] File File information structure. @param[out] Size Size of the file. - @retval EFI_SUCCESS File size calculated and set in @p Size. + @retval EFI_SUCCESS File size calculated and set in Size. @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported. @retval EFI_NO_MEDIA The device has no media. @retval EFI_DEVICE_ERROR The device reported an error. @@ -2027,7 +2284,7 @@ GetFileSize ( EFI_STATUS Status; UDF_READ_FILE_INFO ReadFileInfo; - ReadFileInfo.Flags = READ_FILE_GET_FILESIZE; + ReadFileInfo.Flags = ReadFileGetFileSize; Status = ReadFile ( BlockIo, @@ -2052,7 +2309,7 @@ GetFileSize ( @param[in] File File pointer. @param[in] FileSize Size of the file. @param[in] FileName Filename of the file. - @param[in out] BufferSize Size of the returned file infomation. + @param[in, out] BufferSize Size of the returned file infomation. @param[out] Buffer Data of the returned file information. @retval EFI_SUCCESS File information set. @@ -2080,7 +2337,7 @@ SetFileInfo ( // // Calculate the needed size for the EFI_FILE_INFO structure. // - FileInfoLength = sizeof (EFI_FILE_INFO) + (FileName ? + FileInfoLength = sizeof (EFI_FILE_INFO) + ((FileName != NULL) ? StrSize (FileName) : sizeof (CHAR16)); if (*BufferSize < FileInfoLength) { @@ -2325,9 +2582,9 @@ GetVolumeSize ( @param[in] Volume UDF volume information structure. @param[in] File File information structure. @param[in] FileSize Size of the file. - @param[in out] FilePosition File position. - @param[in out] Buffer File data. - @param[in out] BufferSize Read size. + @param[in, out] FilePosition File position. + @param[in, out] Buffer File data. + @param[in, out] BufferSize Read size. @retval EFI_SUCCESS File seeked and read. @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported. @@ -2353,7 +2610,7 @@ ReadFileData ( EFI_STATUS Status; UDF_READ_FILE_INFO ReadFileInfo; - ReadFileInfo.Flags = READ_FILE_SEEK_AND_READ; + ReadFileInfo.Flags = ReadFileSeekAndRead; ReadFileInfo.FilePosition = *FilePosition; ReadFileInfo.FileData = Buffer; ReadFileInfo.FileDataSize = *BufferSize; @@ -2398,7 +2655,6 @@ SupportUdfFileSystem ( EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode; EFI_GUID *VendorDefinedGuid; - EFI_GUID UdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID; // // Open Device Path protocol on ControllerHandle @@ -2435,7 +2691,7 @@ SupportUdfFileSystem ( DevicePathSubType (LastDevicePathNode) == MEDIA_VENDOR_DP) { VendorDefinedGuid = (EFI_GUID *)((UINTN)LastDevicePathNode + OFFSET_OF (VENDOR_DEVICE_PATH, Guid)); - if (CompareGuid (VendorDefinedGuid, &UdfDevPathGuid)) { + if (CompareGuid (VendorDefinedGuid, &gUdfDevPathGuid)) { Status = EFI_SUCCESS; } }