15EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;
43 BlockSize = BlockIo->Media->BlockSize;
44 EndLBA = BlockIo->Media->LastBlock;
45 DescriptorLBAs[0] = 256;
46 DescriptorLBAs[1] = EndLBA - 256;
47 DescriptorLBAs[2] = EndLBA;
48 DescriptorLBAs[3] = 512;
50 for (Index = 0; Index <
ARRAY_SIZE (DescriptorLBAs); Index++) {
51 Status = DiskIo->ReadDisk (
53 BlockIo->Media->MediaId,
58 if (EFI_ERROR (Status)) {
62 DescriptorTag = &AnchorPoint->DescriptorTag;
67 if (DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer) {
75 return EFI_VOLUME_CORRUPTED;
107 BOOLEAN StopSequence;
110 UINT32 LogicalBlockSize;
112 BlockSize = BlockIo->Media->BlockSize;
113 ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;
119 if (Buffer ==
NULL) {
120 return EFI_OUT_OF_RESOURCES;
132 SeqEndBlock = SeqStartBlock +
DivU64x32 (
133 (UINT64)ExtentAd->ExtentLength,
136 StopSequence =
FALSE;
137 for ( ; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {
141 Status = BlockIo->ReadBlocks (
143 BlockIo->Media->MediaId,
148 if (EFI_ERROR (Status)) {
152 DescriptorTag = Buffer;
154 switch (DescriptorTag->TagIdentifier) {
155 case UdfPartitionDescriptor:
159 CopyMem (&Volume->PartitionDesc, Buffer, sizeof (Volume->PartitionDesc));
162 case UdfLogicalVolumeDescriptor:
166 CopyMem (&Volume->LogicalVolDesc, Buffer, sizeof (Volume->LogicalVolDesc));
169 case UdfTerminatingDescriptor:
181 LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;
182 if (LogicalBlockSize >= UDF_LOGICAL_SECTOR_SIZE) {
183 Volume->FileEntrySize = (
UINTN)LogicalBlockSize;
185 Volume->FileEntrySize = UDF_LOGICAL_SECTOR_SIZE;
219 LogicalVolDesc = &Volume->LogicalVolDesc;
221 switch (LogicalVolDesc->DomainIdentifier.Suffix.Domain.UdfRevision) {
247 if (LongAd->ExtentLocation.PartitionReferenceNumber != 0) {
254 PartitionNum = *(UINT16 *)((
UINTN)&LogicalVolDesc->PartitionMaps[4]);
268 if (Volume->PartitionDesc.PartitionNumber == PartitionNum) {
269 return &Volume->PartitionDesc;
297 if (PartitionDesc ==
NULL) {
300 "%a: Fail to get the Partition Descriptor from the given Long Allocation Descriptor.\n",
303 return EFI_UNSUPPORTED;
306 *Lsn = (UINT64)PartitionDesc->PartitionStartingLocation -
307 Volume->MainVdsStartLocation +
308 LongAd->ExtentLocation.LogicalBlockNumber;
330 return (UINT64)PartitionDesc->PartitionStartingLocation -
331 Volume->MainVdsStartLocation + ShortAd->ExtentPosition;
361 LogicalVolDesc = &Volume->LogicalVolDesc;
362 Status =
GetLongAdLsn (Volume, &LogicalVolDesc->LogicalVolumeContentsUse, &Lsn);
363 if (EFI_ERROR (Status)) {
375 Status = DiskIo->ReadDisk (
377 BlockIo->Media->MediaId,
378 MultU64x32 (Lsn, LogicalVolDesc->LogicalBlockSize),
379 sizeof (Volume->FileSetDesc),
382 if (EFI_ERROR (Status)) {
386 DescriptorTag = &Volume->FileSetDesc.DescriptorTag;
391 if (DescriptorTag->TagIdentifier != UdfFileSetDescriptor) {
392 return EFI_VOLUME_CORRUPTED;
428 if (EFI_ERROR (Status)) {
435 ExtentAd = &AnchorPoint.MainVolumeDescriptorSequenceExtent;
437 Volume->MainVdsStartLocation = (UINT64)ExtentAd->ExtentLocation;
448 if (EFI_ERROR (Status)) {
470 FileIdentifierDesc->LengthOfFileIdentifier +
471 FileIdentifierDesc->LengthOfImplementationUse) >> 2) << 2
488 *NewFileIdentifierDesc =
509 OUT VOID **NewFileEntry
543 IN VOID *FileEntryData,
553 DescriptorTag = FileEntryData;
555 if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {
558 *Length = ExtendedFileEntry->InformationLength;
559 *Data = (VOID *)((UINT8 *)ExtendedFileEntry->Data +
560 ExtendedFileEntry->LengthOfExtendedAttributes);
561 }
else if (DescriptorTag->TagIdentifier == UdfFileEntry) {
564 *Length = FileEntry->InformationLength;
565 *Data = (VOID *)((UINT8 *)FileEntry->Data +
566 FileEntry->LengthOfExtendedAttributes);
569 if ((*Length > FileEntrySize) ||
571 ((
UINTN)(*Data) - (
UINTN)FileEntryData > FileEntrySize - *Length))
573 return EFI_VOLUME_CORRUPTED;
602 IN VOID *FileEntryData,
612 DescriptorTag = FileEntryData;
614 if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {
617 *Length = ExtendedFileEntry->LengthOfAllocationDescriptors;
618 *AdsData = (VOID *)((UINT8 *)ExtendedFileEntry->Data +
619 ExtendedFileEntry->LengthOfExtendedAttributes);
620 }
else if (DescriptorTag->TagIdentifier == UdfFileEntry) {
623 *Length = FileEntry->LengthOfAllocationDescriptors;
624 *AdsData = (VOID *)((UINT8 *)FileEntry->Data +
625 FileEntry->LengthOfExtendedAttributes);
628 if ((*Length > FileEntrySize) ||
630 ((
UINTN)(*AdsData) - (
UINTN)FileEntryData > FileEntrySize - *Length))
632 return EFI_VOLUME_CORRUPTED;
653 IN OUT UINT64 *Offset,
659 UDF_EXTENT_FLAGS ExtentFlags;
662 if (*Offset >= Length) {
666 return EFI_DEVICE_ERROR;
676 ExtentFlags = GET_EXTENT_FLAGS (LongAdsSequence, LongAd);
677 if ((ExtentFlags == ExtentIsNextExtent) ||
678 (ExtentFlags == ExtentRecordedAndAllocated))
687 *Offset += AD_LENGTH (LongAdsSequence);
690 *FoundLongAd = LongAd;
710 IN OUT UINT64 *Offset,
716 UDF_EXTENT_FLAGS ExtentFlags;
719 if (*Offset >= Length) {
723 return EFI_DEVICE_ERROR;
733 ExtentFlags = GET_EXTENT_FLAGS (ShortAdsSequence, ShortAd);
734 if ((ExtentFlags == ExtentIsNextExtent) ||
735 (ExtentFlags == ExtentRecordedAndAllocated))
744 *Offset += AD_LENGTH (ShortAdsSequence);
747 *FoundShortAd = ShortAd;
769 IN UDF_FE_RECORDING_FLAGS RecordingFlags,
771 IN OUT UINT64 *Offset,
776 if (RecordingFlags == LongAdsSequence) {
783 }
else if (RecordingFlags == ShortAdsSequence) {
796 return EFI_DEVICE_ERROR;
817 IN UDF_FE_RECORDING_FLAGS RecordingFlags,
826 if (RecordingFlags == LongAdsSequence) {
828 }
else if (RecordingFlags == ShortAdsSequence) {
830 if (PartitionDesc ==
NULL) {
831 return EFI_UNSUPPORTED;
846 return EFI_UNSUPPORTED;
876 IN UDF_FE_RECORDING_FLAGS RecordingFlags,
886 UINT32 LogicalBlockSize;
890 ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad);
898 if (EFI_ERROR (Status)) {
904 return EFI_OUT_OF_RESOURCES;
907 LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;
912 Status = DiskIo->ReadDisk (
914 BlockIo->Media->MediaId,
919 if (EFI_ERROR (Status)) {
925 DescriptorTag = &AllocExtDesc->DescriptorTag;
930 if (DescriptorTag->TagIdentifier != UdfAllocationExtentDescriptor) {
931 Status = EFI_VOLUME_CORRUPTED;
938 *Offset =
MultU64x32 (Lsn, LogicalBlockSize) +
940 *Length = AllocExtDesc->LengthOfAllocationDescriptors;
973 IN UDF_FE_RECORDING_FLAGS RecordingFlags,
995 if (EFI_ERROR (Status)) {
1003 if (*Data ==
NULL) {
1004 return EFI_OUT_OF_RESOURCES;
1007 return DiskIo->ReadDisk (
1009 BlockIo->Media->MediaId,
1031 IN UDF_FE_RECORDING_FLAGS RecordingFlags,
1033 IN OUT VOID **Buffer,
1037 UINT32 ExtentLength;
1039 ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad);
1041 if (*Buffer ==
NULL) {
1043 if (*Buffer ==
NULL) {
1044 return EFI_OUT_OF_RESOURCES;
1048 if (*Buffer ==
NULL) {
1049 return EFI_OUT_OF_RESOURCES;
1082 IN VOID *FileEntryData,
1087 UINT32 LogicalBlockSize;
1095 UINT64 FilePosition;
1100 BOOLEAN FinishedSeeking;
1101 UINT32 ExtentLength;
1102 UDF_FE_RECORDING_FLAGS RecordingFlags;
1104 LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;
1113 FinishedSeeking =
FALSE;
1116 switch (ReadFileInfo->Flags) {
1117 case ReadFileGetFileSize:
1118 case ReadFileAllocateAndRead:
1123 ReadFileInfo->ReadLength = 0;
1124 ReadFileInfo->FileData =
NULL;
1126 case ReadFileSeekAndRead:
1130 Length = ReadFileInfo->FileSize - ReadFileInfo->FilePosition;
1131 if (ReadFileInfo->FileDataSize > Length) {
1135 ReadFileInfo->FileDataSize = Length;
1141 BytesLeft = ReadFileInfo->FileDataSize;
1144 FinishedSeeking =
FALSE;
1149 RecordingFlags = GET_FE_RECORDING_FLAGS (FileEntryData);
1150 switch (RecordingFlags) {
1155 Status =
GetFileEntryData (FileEntryData, Volume->FileEntrySize, &Data, &Length);
1156 if (EFI_ERROR (Status)) {
1160 if (ReadFileInfo->Flags == ReadFileGetFileSize) {
1161 ReadFileInfo->ReadLength = Length;
1162 }
else if (ReadFileInfo->Flags == ReadFileAllocateAndRead) {
1167 if (ReadFileInfo->FileData ==
NULL) {
1168 return EFI_OUT_OF_RESOURCES;
1175 ReadFileInfo->ReadLength = Length;
1176 }
else if (ReadFileInfo->Flags == ReadFileSeekAndRead) {
1182 ReadFileInfo->FileData,
1183 (VOID *)((UINT8 *)Data + ReadFileInfo->FilePosition),
1184 (
UINTN)ReadFileInfo->FileDataSize
1187 ReadFileInfo->FilePosition += ReadFileInfo->FileDataSize;
1190 return EFI_INVALID_PARAMETER;
1196 case LongAdsSequence:
1197 case ShortAdsSequence:
1202 Status =
GetAdsInformation (FileEntryData, Volume->FileEntrySize, &Data, &Length);
1203 if (EFI_ERROR (Status)) {
1220 if (Status == EFI_DEVICE_ERROR) {
1229 if (GET_EXTENT_FLAGS (RecordingFlags, Ad) == ExtentIsNextExtent) {
1248 if (EFI_ERROR (Status)) {
1252 ASSERT (Data !=
NULL);
1258 ExtentLength = GET_EXTENT_LENGTH (RecordingFlags, Ad);
1267 if (EFI_ERROR (Status)) {
1271 switch (ReadFileInfo->Flags) {
1272 case ReadFileGetFileSize:
1273 ReadFileInfo->ReadLength += ExtentLength;
1275 case ReadFileAllocateAndRead:
1282 &ReadFileInfo->FileData,
1283 ReadFileInfo->ReadLength
1285 if (EFI_ERROR (Status)) {
1286 goto Error_Alloc_Buffer_To_Next_Ad;
1292 Status = DiskIo->ReadDisk (
1294 BlockIo->Media->MediaId,
1297 (VOID *)((UINT8 *)ReadFileInfo->FileData +
1298 ReadFileInfo->ReadLength)
1300 if (EFI_ERROR (Status)) {
1301 goto Error_Read_Disk_Blk;
1304 ReadFileInfo->ReadLength += ExtentLength;
1306 case ReadFileSeekAndRead:
1310 if (FinishedSeeking) {
1312 goto Skip_File_Seek;
1315 if (FilePosition + ExtentLength < ReadFileInfo->FilePosition) {
1316 FilePosition += ExtentLength;
1320 if (FilePosition + ExtentLength > ReadFileInfo->FilePosition) {
1321 Offset = ReadFileInfo->FilePosition - FilePosition;
1329 FinishedSeeking =
TRUE;
1335 if (ExtentLength - Offset > BytesLeft) {
1336 DataLength = BytesLeft;
1338 DataLength = ExtentLength - Offset;
1344 Status = DiskIo->ReadDisk (
1346 BlockIo->Media->MediaId,
1349 (VOID *)((UINT8 *)ReadFileInfo->FileData +
1352 if (EFI_ERROR (Status)) {
1353 goto Error_Read_Disk_Blk;
1359 DataOffset += DataLength;
1360 ReadFileInfo->FilePosition += DataLength;
1362 BytesLeft -= DataLength;
1363 if (BytesLeft == 0) {
1378 AdOffset += AD_LENGTH (RecordingFlags);
1382 case ExtendedAdsSequence:
1385 Status = EFI_UNSUPPORTED;
1393 Status = EFI_UNSUPPORTED;
1405Error_Alloc_Buffer_To_Next_Ad:
1406 if (ReadFileInfo->Flags != ReadFileSeekAndRead) {
1439 IN CHAR16 *FileName,
1449 CHAR16 FoundFileName[UDF_FILENAME_LENGTH];
1450 VOID *CompareFileEntry;
1455 if ((Parent->FileIdentifierDesc ==
NULL) && (Icb ==
NULL)) {
1456 return EFI_INVALID_PARAMETER;
1462 if (FE_ICB_FILE_TYPE (Parent->FileEntry) != UdfFileEntryDirectory) {
1463 return EFI_NOT_FOUND;
1470 if (
StrCmp (FileName, L
".") == 0) {
1471 if (Parent->FileIdentifierDesc ==
NULL) {
1472 return EFI_INVALID_PARAMETER;
1475 DuplicateFe (BlockIo, Volume, Parent->FileEntry, &File->FileEntry);
1476 if (File->FileEntry ==
NULL) {
1477 return EFI_OUT_OF_RESOURCES;
1480 DuplicateFid (Parent->FileIdentifierDesc, &File->FileIdentifierDesc);
1481 if (File->FileIdentifierDesc ==
NULL) {
1483 return EFI_OUT_OF_RESOURCES;
1500 (Parent->FileIdentifierDesc !=
NULL) ?
1501 &Parent->FileIdentifierDesc->Icb :
1507 if (EFI_ERROR (Status)) {
1508 if (Status == EFI_DEVICE_ERROR) {
1509 Status = EFI_NOT_FOUND;
1523 ASSERT (FileIdentifierDesc !=
NULL);
1525 if (FileIdentifierDesc->FileCharacteristics & PARENT_FILE) {
1531 if ((
StrCmp (FileName, L
"..") == 0) || (
StrCmp (FileName, L
"\\") == 0)) {
1537 if (EFI_ERROR (Status)) {
1541 if (
StrCmp (FileName, FoundFileName) == 0) {
1550 FreePool ((VOID *)FileIdentifierDesc);
1553 if (ReadDirInfo.DirectoryData !=
NULL) {
1557 FreePool (ReadDirInfo.DirectoryData);
1563 File->FileIdentifierDesc = FileIdentifierDesc;
1571 if (
StrCmp (FileName, L
"\\") != 0) {
1576 &FileIdentifierDesc->Icb,
1579 if (EFI_ERROR (Status)) {
1587 (VOID *)Parent->FileEntry,
1588 (VOID *)CompareFileEntry,
1589 Volume->FileEntrySize
1592 File->FileEntry = CompareFileEntry;
1594 FreePool ((VOID *)FileIdentifierDesc);
1595 FreePool ((VOID *)CompareFileEntry);
1596 Status = EFI_NOT_FOUND;
1604 FreePool ((VOID *)FileIdentifierDesc);
1640 if (EFI_ERROR (Status)) {
1648 if (EFI_ERROR (Status)) {
1686 &Volume->FileSetDesc.RootDirectoryIcb,
1689 if (EFI_ERROR (Status)) {
1693 Parent.FileEntry = File->FileEntry;
1694 Parent.FileIdentifierDesc =
NULL;
1703 &Volume->FileSetDesc.RootDirectoryIcb,
1706 if (EFI_ERROR (Status)) {
1736 OUT VOID **FileEntry
1741 UINT32 LogicalBlockSize;
1746 if (EFI_ERROR (Status)) {
1750 LogicalBlockSize = Volume->LogicalVolDesc.LogicalBlockSize;
1753 if (ReadBuffer ==
NULL) {
1754 return EFI_OUT_OF_RESOURCES;
1760 Status = DiskIo->ReadDisk (
1762 BlockIo->Media->MediaId,
1764 Volume->FileEntrySize,
1767 if (EFI_ERROR (Status)) {
1768 goto Error_Read_Disk_Blk;
1771 DescriptorTag = ReadBuffer;
1777 if ((DescriptorTag->TagIdentifier != UdfFileEntry) &&
1778 (DescriptorTag->TagIdentifier != UdfExtendedFileEntry))
1780 Status = EFI_VOLUME_CORRUPTED;
1781 goto Error_Invalid_Fe;
1784 *FileEntry = ReadBuffer;
1819 IN CHAR16 *FilePath,
1827 CHAR16 FileName[UDF_FILENAME_LENGTH];
1828 CHAR16 *FileNamePointer;
1832 Status = EFI_NOT_FOUND;
1835 while (*FilePath != L
'\0') {
1836 FileNamePointer = FileName;
1837 while (*FilePath != L
'\0' && *FilePath != L
'\\') {
1838 if ((((
UINTN)FileNamePointer - (
UINTN)FileName) /
sizeof (CHAR16)) >=
1841 return EFI_NOT_FOUND;
1844 *FileNamePointer++ = *FilePath++;
1847 *FileNamePointer = L
'\0';
1848 if (FileName[0] == L
'\0') {
1874 DuplicateFe (BlockIo, Volume, Root->FileEntry, &File->FileEntry);
1875 if (File->FileEntry ==
NULL) {
1876 Status = EFI_OUT_OF_RESOURCES;
1881 DuplicateFid (Root->FileIdentifierDesc, &File->FileIdentifierDesc);
1882 if (File->FileIdentifierDesc ==
NULL) {
1884 Status = EFI_OUT_OF_RESOURCES;
1903 if (EFI_ERROR (Status)) {
1911 if (FE_ICB_FILE_TYPE (File->FileEntry) == UdfFileEntrySymlink) {
1912 FreePool ((VOID *)File->FileIdentifierDesc);
1914 FileEntry = File->FileEntry;
1927 if (EFI_ERROR (Status)) {
1933 (VOID *)&PreviousFile,
1942 if ((*FilePath != L
'\0') && (*FilePath == L
'\\')) {
1977 IN VOID *FileEntryData,
1986 if (ReadDirInfo->DirectoryData ==
NULL) {
1991 ReadFileInfo.Flags = ReadFileAllocateAndRead;
2001 if (EFI_ERROR (Status)) {
2008 ReadDirInfo->DirectoryData = ReadFileInfo.FileData;
2009 ReadDirInfo->DirectoryLength = ReadFileInfo.ReadLength;
2013 if (ReadDirInfo->FidOffset >= ReadDirInfo->DirectoryLength) {
2019 return EFI_DEVICE_ERROR;
2025 FileIdentifierDesc = GET_FID_FROM_ADS (
2026 ReadDirInfo->DirectoryData,
2027 ReadDirInfo->FidOffset
2033 }
while (FileIdentifierDesc->FileCharacteristics & DELETED_FILE);
2036 if (*FoundFid ==
NULL) {
2037 return EFI_OUT_OF_RESOURCES;
2067 OUT CHAR16 *FileName
2070 UINT8 *OstaCompressed;
2071 UINT8 CompressionId;
2074 CHAR16 *FileNameBak;
2077 return EFI_BUFFER_TOO_SMALL;
2082 (UINT8 *)FileIdentifierDesc->Data +
2083 FileIdentifierDesc->LengthOfImplementationUse
2086 CompressionId = OstaCompressed[0];
2087 if (!IS_VALID_COMPRESSION_ID (CompressionId)) {
2088 return EFI_VOLUME_CORRUPTED;
2091 FileNameBak = FileName;
2096 Length = FileIdentifierDesc->LengthOfFileIdentifier;
2097 if (CompressionId == 16) {
2098 if (((
UINTN)Length >> 1) > CharMax) {
2099 return EFI_BUFFER_TOO_SMALL;
2102 if ((Length != 0) && ((
UINTN)Length - 1 > CharMax)) {
2103 return EFI_BUFFER_TOO_SMALL;
2107 for (Index = 1; Index < Length; Index++) {
2108 if (CompressionId == 16) {
2109 *FileName = OstaCompressed[Index++] << 8;
2114 if (Index < Length) {
2115 *FileName |= (CHAR16)(OstaCompressed[Index]);
2121 Index = ((
UINTN)FileName - (
UINTN)FileNameBak) /
sizeof (CHAR16);
2122 if (Index > CharMax - 1) {
2123 Index = CharMax - 1;
2126 FileNameBak[Index] = L
'\0';
2162 IN VOID *FileEntryData,
2172 UINT8 PathCompLength;
2173 CHAR16 FileName[UDF_FILENAME_LENGTH];
2176 UINT8 CompressionId;
2189 ReadFileInfo.Flags = ReadFileAllocateAndRead;
2195 &Parent->FileIdentifierDesc->Icb,
2199 if (EFI_ERROR (Status)) {
2203 Length = ReadFileInfo.ReadLength;
2205 Data = (UINT8 *)ReadFileInfo.FileData;
2206 EndData = Data + Length;
2213 PathCompLength = PathComp->LengthOfComponentIdentifier;
2215 switch (PathComp->ComponentType) {
2227 goto Next_Path_Component;
2232 CopyMem ((VOID *)FileName, L
"..", 6);
2238 DuplicateFe (BlockIo, Volume, PreviousFile.FileEntry, &File->FileEntry);
2239 if (File->FileEntry ==
NULL) {
2240 Status = EFI_OUT_OF_RESOURCES;
2241 goto Error_Find_File;
2245 PreviousFile.FileIdentifierDesc,
2246 &File->FileIdentifierDesc
2248 if (File->FileIdentifierDesc ==
NULL) {
2250 Status = EFI_OUT_OF_RESOURCES;
2251 goto Error_Find_File;
2254 goto Next_Path_Component;
2263 CompressionId = PathComp->ComponentIdentifier[0];
2264 if (!IS_VALID_COMPRESSION_ID (CompressionId)) {
2265 return EFI_VOLUME_CORRUPTED;
2268 if ((
UINTN)PathComp->ComponentIdentifier + PathCompLength > (
UINTN)EndData) {
2269 return EFI_VOLUME_CORRUPTED;
2273 for (Index = 1; Index < PathCompLength; Index++) {
2274 if (CompressionId == 16) {
2275 *Char = *(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier +
2280 return EFI_UNSUPPORTED;
2286 if (Index < Length) {
2287 *Char |= (CHAR16)(*(UINT8 *)((UINT8 *)PathComp->ComponentIdentifier + Index));
2293 Index = ((
UINTN)Char - (
UINTN)FileName) /
sizeof (CHAR16);
2298 FileName[Index] = L
'\0';
2305 Status = EFI_VOLUME_CORRUPTED;
2306 goto Error_Find_File;
2321 if (EFI_ERROR (Status)) {
2322 goto Error_Find_File;
2327 if (Data >= EndData) {
2334 if ((File->FileEntry ==
NULL) || (File->FileIdentifierDesc ==
NULL)) {
2335 Status = EFI_VOLUME_CORRUPTED;
2336 goto Error_Find_File;
2340 (VOID *)&PreviousFile,
2345 (VOID *)&PreviousFile,
2350 if (NotParent && NotFile) {
2367 if ((File->FileEntry ==
NULL) || (File->FileIdentifierDesc ==
NULL)) {
2368 return EFI_VOLUME_CORRUPTED;
2375 (VOID *)&PreviousFile,
2399 if (File->FileEntry !=
NULL) {
2403 if (File->FileIdentifierDesc !=
NULL) {
2404 FreePool ((VOID *)File->FileIdentifierDesc);
2440 ReadFileInfo.Flags = ReadFileGetFileSize;
2446 &File->FileIdentifierDesc->Icb,
2450 if (EFI_ERROR (Status)) {
2454 *Size = ReadFileInfo.ReadLength;
2480 IN CHAR16 *FileName,
2485 UINTN FileInfoLength;
2497 if (*BufferSize < FileInfoLength) {
2501 *BufferSize = FileInfoLength;
2502 return EFI_BUFFER_TOO_SMALL;
2514 if (IS_FID_DIRECTORY_FILE (File->FileIdentifierDesc)) {
2516 }
else if (IS_FID_NORMAL_FILE (File->FileIdentifierDesc)) {
2520 if (IS_FID_HIDDEN_FILE (File->FileIdentifierDesc)) {
2524 DescriptorTag = File->FileEntry;
2526 if (DescriptorTag->TagIdentifier == UdfFileEntry) {
2532 if (FileEntry->IcbTag.Flags & (1 << 10)) {
2546 FileEntry->AccessTime.HundredsOfMicroseconds;
2549 FileEntry->AccessTime.Year;
2551 FileEntry->AccessTime.Month;
2553 FileEntry->AccessTime.Day;
2555 FileEntry->AccessTime.Hour;
2557 FileEntry->AccessTime.Minute;
2559 FileEntry->AccessTime.Second;
2561 FileEntry->AccessTime.HundredsOfMicroseconds;
2562 }
else if (DescriptorTag->TagIdentifier == UdfExtendedFileEntry) {
2568 if (ExtendedFileEntry->IcbTag.Flags & (1 << 10)) {
2582 ExtendedFileEntry->AccessTime.HundredsOfMicroseconds;
2585 ExtendedFileEntry->AccessTime.Year;
2587 ExtendedFileEntry->AccessTime.Month;
2589 ExtendedFileEntry->AccessTime.Day;
2591 ExtendedFileEntry->AccessTime.Hour;
2593 ExtendedFileEntry->AccessTime.Minute;
2595 ExtendedFileEntry->AccessTime.Second;
2597 ExtendedFileEntry->AccessTime.HundredsOfMicroseconds;
2611 if (FileName !=
NULL) {
2617 *BufferSize = FileInfoLength;
2651 UINT8 *OstaCompressed;
2652 UINT8 CompressionId;
2655 FileSetDesc = &Volume->FileSetDesc;
2657 OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];
2659 CompressionId = OstaCompressed[0];
2660 if (!IS_VALID_COMPRESSION_ID (CompressionId)) {
2661 return EFI_VOLUME_CORRUPTED;
2665 for (Index = 1; Index < 128; Index++) {
2666 if (CompressionId == 16) {
2667 if ((Index >> 1) > CharMax) {
2668 return EFI_BUFFER_TOO_SMALL;
2671 *String = *(UINT8 *)(OstaCompressed + Index) << 8;
2674 if (Index > CharMax) {
2675 return EFI_BUFFER_TOO_SMALL;
2682 *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));
2690 if (*String == L
'\0') {
2697 Index = ((
UINTN)String - (
UINTN)StringBak) /
sizeof (CHAR16);
2698 if (Index > CharMax - 1) {
2699 Index = CharMax - 1;
2702 StringBak[Index] = L
'\0';
2736 OUT UINT64 *VolumeSize,
2737 OUT UINT64 *FreeSpaceSize
2744 UINT32 LogicalBlockSize;
2751 LogicalVolDesc = &Volume->LogicalVolDesc;
2753 ExtentAd = &LogicalVolDesc->IntegritySequenceExtent;
2755 if ((ExtentAd->ExtentLength == 0) ||
2758 return EFI_VOLUME_CORRUPTED;
2762 if (LogicalVolInt ==
NULL) {
2763 return EFI_OUT_OF_RESOURCES;
2769 Lsn = (UINT64)ExtentAd->ExtentLocation - Volume->MainVdsStartLocation;
2771 LogicalBlockSize = LogicalVolDesc->LogicalBlockSize;
2776 Status = DiskIo->ReadDisk (
2778 BlockIo->Media->MediaId,
2780 ExtentAd->ExtentLength,
2783 if (EFI_ERROR (Status)) {
2787 DescriptorTag = &LogicalVolInt->DescriptorTag;
2792 if (DescriptorTag->TagIdentifier != UdfLogicalVolumeIntegrityDescriptor) {
2793 Status = EFI_VOLUME_CORRUPTED;
2797 if ((LogicalVolInt->NumberOfPartitions > MAX_UINT32 / sizeof (UINT32) / 2) ||
2798 (LogicalVolInt->NumberOfPartitions *
sizeof (UINT32) * 2 >
2801 Status = EFI_VOLUME_CORRUPTED;
2808 Length = LogicalVolInt->NumberOfPartitions;
2809 for (Index = 0; Index < Length; Index +=
sizeof (UINT32)) {
2810 LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);
2814 if (LsnsNo == 0xFFFFFFFFUL) {
2821 *FreeSpaceSize +=
MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);
2824 Length = LogicalVolInt->NumberOfPartitions *
sizeof (UINT32) * 2;
2825 for ( ; Index < Length; Index +=
sizeof (UINT32)) {
2826 LsnsNo = *(UINT32 *)((UINT8 *)LogicalVolInt->Data + Index);
2830 if (LsnsNo == 0xFFFFFFFFUL) {
2837 *VolumeSize +=
MultU64x32 ((UINT64)LsnsNo, LogicalBlockSize);
2879 IN OUT UINT64 *FilePosition,
2880 IN OUT VOID *Buffer,
2881 IN OUT UINT64 *BufferSize
2887 ReadFileInfo.Flags = ReadFileSeekAndRead;
2888 ReadFileInfo.FilePosition = *FilePosition;
2889 ReadFileInfo.FileData = Buffer;
2890 ReadFileInfo.FileDataSize = *BufferSize;
2891 ReadFileInfo.FileSize = FileSize;
2897 &File->FileIdentifierDesc->Icb,
2901 if (EFI_ERROR (Status)) {
2905 *BufferSize = ReadFileInfo.FileDataSize;
2906 *FilePosition = ReadFileInfo.FilePosition;
2936 Status =
gBS->OpenProtocol (
2938 &gEfiDevicePathProtocolGuid,
2939 (VOID **)&DevicePath,
2940 This->DriverBindingHandle,
2942 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2944 if (EFI_ERROR (Status)) {
2945 return EFI_UNSUPPORTED;
2948 Status = EFI_UNSUPPORTED;
2953 LastDevicePathNode =
NULL;
2954 DevicePathNode = DevicePath;
2956 LastDevicePathNode = DevicePathNode;
2964 if ((LastDevicePathNode !=
NULL) &&
2968 VendorDefinedGuid = (
EFI_GUID *)((
UINTN)LastDevicePathNode +
2970 if (
CompareGuid (VendorDefinedGuid, &gUdfDevPathGuid)) {
2978 gBS->CloseProtocol (
2980 &gEfiDevicePathProtocolGuid,
2981 This->DriverBindingHandle,
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS GetFileNameFromFid(IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc, IN UINTN CharMax, OUT CHAR16 *FileName)
EFI_STATUS ReadUdfVolumeInformation(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, OUT UDF_VOLUME_INFO *Volume)
EFI_STATUS GetFileEntryData(IN VOID *FileEntryData, IN UINTN FileEntrySize, OUT VOID **Data, OUT UINT64 *Length)
UDF_PARTITION_DESCRIPTOR * GetPdFromLongAd(IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd)
EFI_STATUS GetAllocationDescriptorLsn(IN UDF_FE_RECORDING_FLAGS RecordingFlags, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN VOID *Ad, OUT UINT64 *Lsn)
EFI_STATUS GetLongAdLsn(IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *LongAd, OUT UINT64 *Lsn)
EFI_STATUS GetFileSize(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_FILE_INFO *File, OUT UINT64 *Size)
EFI_STATUS GetVolumeSize(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, OUT UINT64 *VolumeSize, OUT UINT64 *FreeSpaceSize)
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)
EFI_STATUS GetAedAdsOffset(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN UDF_FE_RECORDING_FLAGS RecordingFlags, IN VOID *Ad, OUT UINT64 *Offset, OUT UINT64 *Length)
EFI_STATUS GetAdsInformation(IN VOID *FileEntryData, IN UINTN FileEntrySize, OUT VOID **AdsData, OUT UINT64 *Length)
EFI_STATUS GetAllocationDescriptor(IN UDF_FE_RECORDING_FLAGS RecordingFlags, IN VOID *Data, IN OUT UINT64 *Offset, IN UINT64 Length, OUT VOID **FoundAd)
EFI_STATUS GetAedAdsData(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN UDF_FE_RECORDING_FLAGS RecordingFlags, IN VOID *Ad, OUT VOID **Data, OUT UINT64 *Length)
EFI_STATUS SetFileInfo(IN UDF_FILE_INFO *File, IN UINT64 FileSize, IN CHAR16 *FileName, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS ReadDirectoryEntry(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN VOID *FileEntryData, IN OUT UDF_READ_DIRECTORY_INFO *ReadDirInfo, OUT UDF_FILE_IDENTIFIER_DESCRIPTOR **FoundFid)
EFI_STATUS ReadFile(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN VOID *FileEntryData, IN OUT UDF_READ_FILE_INFO *ReadFileInfo)
EFI_STATUS GetShortAdFromAds(IN VOID *Data, IN OUT UINT64 *Offset, IN UINT64 Length, OUT UDF_SHORT_ALLOCATION_DESCRIPTOR **FoundShortAd)
EFI_STATUS SupportUdfFileSystem(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle)
EFI_STATUS GrowUpBufferToNextAd(IN UDF_FE_RECORDING_FLAGS RecordingFlags, IN VOID *Ad, IN OUT VOID **Buffer, IN UINT64 Length)
EFI_STATUS FindFileSetDescriptor(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume)
EFI_STATUS ReadFileData(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_FILE_INFO *File, IN UINT64 FileSize, IN OUT UINT64 *FilePosition, IN OUT VOID *Buffer, IN OUT UINT64 *BufferSize)
EFI_STATUS FindFile(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN CHAR16 *FilePath, IN UDF_FILE_INFO *Root, IN UDF_FILE_INFO *Parent, IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb, OUT UDF_FILE_INFO *File)
VOID DuplicateFid(IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc, OUT UDF_FILE_IDENTIFIER_DESCRIPTOR **NewFileIdentifierDesc)
EFI_STATUS GetVolumeLabel(IN UDF_VOLUME_INFO *Volume, IN UINTN CharMax, OUT CHAR16 *String)
UINT64 GetFidDescriptorLength(IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc)
VOID CleanupFileInformation(IN UDF_FILE_INFO *File)
EFI_STATUS ResolveSymlink(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_FILE_INFO *Parent, IN VOID *FileEntryData, OUT UDF_FILE_INFO *File)
EFI_STATUS FindFileEntry(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb, OUT VOID **FileEntry)
VOID DuplicateFe(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN UDF_VOLUME_INFO *Volume, IN VOID *FileEntry, OUT VOID **NewFileEntry)
UINT64 GetShortAdLsn(IN UDF_VOLUME_INFO *Volume, IN UDF_PARTITION_DESCRIPTOR *PartitionDesc, IN UDF_SHORT_ALLOCATION_DESCRIPTOR *ShortAd)
EFI_STATUS FindAnchorVolumeDescriptorPointer(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, OUT UDF_ANCHOR_VOLUME_DESCRIPTOR_POINTER *AnchorPoint)
EFI_STATUS FindRootDirectory(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, OUT UDF_FILE_INFO *File)
EFI_STATUS ReadVolumeFileStructure(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, OUT UDF_VOLUME_INFO *Volume)
EFI_STATUS GetLongAdFromAds(IN VOID *Data, IN OUT UINT64 *Offset, IN UINT64 Length, OUT UDF_LONG_ALLOCATION_DESCRIPTOR **FoundLongAd)
EFI_STATUS InternalFindFile(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN CHAR16 *FileName, IN UDF_FILE_INFO *Parent, IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb, OUT UDF_FILE_INFO *File)
#define ARRAY_SIZE(Array)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
VOID EFIAPI Exit(IN EFI_STATUS Status)
#define EFI_UNSPECIFIED_TIMEZONE
EFI_TIME ModificationTime