13 EFI_FILE_PROTOCOL_REVISION,
30#define _ROOT_FILE(_PrivData) (_PrivData)->Root
31#define _PARENT_FILE(_PrivData) \
32 ((_PrivData)->IsRootDirectory ? (_PrivData)->Root : &(_PrivData)->File)
33#define _FILE(_PrivData) _PARENT_FILE(_PrivData)
63 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
65 if ((This ==
NULL) || (Root ==
NULL)) {
66 Status = EFI_INVALID_PARAMETER;
67 goto Error_Invalid_Params;
70 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (This);
72 if (PrivFsData->OpenFiles == 0) {
82 if (EFI_ERROR (Status)) {
83 goto Error_Read_Udf_Volume;
98 if (EFI_ERROR (Status)) {
99 goto Error_Find_Root_Dir;
104 if (PrivFileData ==
NULL) {
105 Status = EFI_OUT_OF_RESOURCES;
106 goto Error_Alloc_Priv_File_Data;
109 PrivFileData->Signature = PRIVATE_UDF_FILE_DATA_SIGNATURE;
110 PrivFileData->SimpleFs = This;
111 PrivFileData->Root = &PrivFsData->Root;
112 PrivFileData->IsRootDirectory =
TRUE;
115 (VOID *)&PrivFileData->FileIo,
116 (VOID *)&gUdfFileIoOps,
120 *Root = &PrivFileData->FileIo;
122 PrivFsData->OpenFiles++;
124 gBS->RestoreTPL (OldTpl);
128Error_Alloc_Priv_File_Data:
133Error_Read_Udf_Volume:
135 gBS->RestoreTPL (OldTpl);
176 CHAR16 FilePath[UDF_PATH_LENGTH];
179 CHAR16 *TempFileName;
181 ZeroMem (FilePath,
sizeof FilePath);
182 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
184 if ((This ==
NULL) || (NewHandle ==
NULL) || (FileName ==
NULL)) {
185 Status = EFI_INVALID_PARAMETER;
186 goto Error_Invalid_Params;
189 if (OpenMode != EFI_FILE_MODE_READ) {
190 Status = EFI_WRITE_PROTECTED;
191 goto Error_Invalid_Params;
194 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
196 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (PrivFileData->SimpleFs);
201 if (*FileName == L
'\\') {
202 StrCpyS (FilePath, UDF_PATH_LENGTH, FileName);
204 StrCpyS (FilePath, UDF_PATH_LENGTH, PrivFileData->AbsoluteFileName);
205 StrCatS (FilePath, UDF_PATH_LENGTH, L
"\\");
206 StrCatS (FilePath, UDF_PATH_LENGTH, FileName);
210 if (FilePath[0] == L
'\0') {
211 Status = EFI_NOT_FOUND;
212 goto Error_Bad_FileName;
220 _ROOT_FILE (PrivFileData),
221 _PARENT_FILE (PrivFileData),
222 &_PARENT_FILE (PrivFileData)->FileIdentifierDesc->Icb,
225 if (EFI_ERROR (Status)) {
226 goto Error_Find_File;
231 if (NewPrivFileData ==
NULL) {
232 Status = EFI_OUT_OF_RESOURCES;
233 goto Error_Alloc_New_Priv_File_Data;
237 (VOID *)NewPrivFileData,
238 (VOID *)PrivFileData,
243 NewPrivFileData->IsRootDirectory =
FALSE;
245 StrCpyS (NewPrivFileData->AbsoluteFileName, UDF_PATH_LENGTH, FilePath);
246 FileName = NewPrivFileData->AbsoluteFileName;
248 while ((TempFileName =
StrStr (FileName, L
"\\")) !=
NULL) {
249 FileName = TempFileName + 1;
252 StrCpyS (NewPrivFileData->FileName, UDF_FILENAME_LENGTH, FileName);
258 &NewPrivFileData->File,
259 &NewPrivFileData->FileSize
261 if (EFI_ERROR (Status)) {
264 "%a: GetFileSize() fails with status - %r.\n",
268 goto Error_Get_File_Size;
271 NewPrivFileData->FilePosition = 0;
273 (VOID *)&NewPrivFileData->ReadDirInfo,
277 *NewHandle = &NewPrivFileData->FileIo;
279 PrivFsData->OpenFiles++;
281 gBS->RestoreTPL (OldTpl);
288Error_Alloc_New_Priv_File_Data:
294 gBS->RestoreTPL (OldTpl);
334 VOID *NewFileEntryData;
335 CHAR16 FileName[UDF_FILENAME_LENGTH];
337 UINT64 BufferSizeUint64;
339 ZeroMem (FileName,
sizeof FileName);
340 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
342 if ((This ==
NULL) || (BufferSize ==
NULL) || ((*BufferSize != 0) &&
345 Status = EFI_INVALID_PARAMETER;
346 goto Error_Invalid_Params;
349 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
350 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (PrivFileData->SimpleFs);
352 BlockIo = PrivFsData->BlockIo;
353 DiskIo = PrivFsData->DiskIo;
354 Volume = &PrivFsData->Volume;
355 ReadDirInfo = &PrivFileData->ReadDirInfo;
356 NewFileIdentifierDesc =
NULL;
357 NewFileEntryData =
NULL;
359 Parent = _PARENT_FILE (PrivFileData);
361 Status = EFI_VOLUME_CORRUPTED;
363 if (IS_FID_NORMAL_FILE (Parent->FileIdentifierDesc)) {
364 if (PrivFileData->FilePosition > PrivFileData->FileSize) {
368 Status = EFI_DEVICE_ERROR;
369 goto Error_File_Beyond_The_Eof;
372 if (PrivFileData->FilePosition == PrivFileData->FileSize) {
378 BufferSizeUint64 = *BufferSize;
385 PrivFileData->FileSize,
386 &PrivFileData->FilePosition,
390 ASSERT (BufferSizeUint64 <= MAX_UINTN);
391 *BufferSize = (
UINTN)BufferSizeUint64;
392 }
else if (IS_FID_DIRECTORY_FILE (Parent->FileIdentifierDesc)) {
393 if ((ReadDirInfo->FidOffset == 0) && (PrivFileData->FilePosition > 0)) {
394 Status = EFI_DEVICE_ERROR;
404 &Parent->FileIdentifierDesc->Icb,
407 &NewFileIdentifierDesc
409 if (EFI_ERROR (Status)) {
410 if (Status == EFI_DEVICE_ERROR) {
411 FreePool (ReadDirInfo->DirectoryData);
429 ASSERT (NewFileIdentifierDesc !=
NULL);
431 if (!IS_FID_PARENT_FILE (NewFileIdentifierDesc)) {
435 FreePool ((VOID *)NewFileIdentifierDesc);
442 &NewFileIdentifierDesc->Icb,
445 if (EFI_ERROR (Status)) {
449 ASSERT (NewFileEntryData !=
NULL);
451 if (FE_ICB_FILE_TYPE (NewFileEntryData) == UdfFileEntrySymlink) {
460 if (EFI_ERROR (Status)) {
461 goto Error_Resolve_Symlink;
464 FreePool ((VOID *)NewFileEntryData);
465 NewFileEntryData = FoundFile.FileEntry;
468 if (EFI_ERROR (Status)) {
469 FreePool ((VOID *)FoundFile.FileIdentifierDesc);
470 goto Error_Get_FileName;
473 FreePool ((VOID *)NewFileIdentifierDesc);
474 NewFileIdentifierDesc = FoundFile.FileIdentifierDesc;
476 FoundFile.FileIdentifierDesc = NewFileIdentifierDesc;
477 FoundFile.FileEntry = NewFileEntryData;
480 if (EFI_ERROR (Status)) {
481 goto Error_Get_FileName;
492 if (EFI_ERROR (Status)) {
493 goto Error_Get_File_Size;
503 if (EFI_ERROR (Status)) {
504 goto Error_Set_File_Info;
507 PrivFileData->FilePosition++;
509 }
else if (IS_FID_DELETED_FILE (Parent->FileIdentifierDesc)) {
514 Status = EFI_DEVICE_ERROR;
520Error_Resolve_Symlink:
521 if (NewFileEntryData !=
NULL) {
526 if (NewFileIdentifierDesc !=
NULL) {
527 FreePool ((VOID *)NewFileIdentifierDesc);
531Error_File_Beyond_The_Eof:
533 gBS->RestoreTPL (OldTpl);
556 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
561 Status = EFI_INVALID_PARAMETER;
565 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
567 if (!PrivFileData->IsRootDirectory) {
570 if (PrivFileData->ReadDirInfo.DirectoryData !=
NULL) {
571 FreePool (PrivFileData->ReadDirInfo.DirectoryData);
578 gBS->RestoreTPL (OldTpl);
602 return EFI_INVALID_PARAMETER;
605 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
607 (VOID)PrivFileData->FileIo.Close (This);
609 return EFI_WARN_DELETE_FAILURE;
639 return EFI_UNSUPPORTED;
661 if ((This ==
NULL) || (Position ==
NULL)) {
662 return EFI_INVALID_PARAMETER;
665 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
671 if (IS_FID_DIRECTORY_FILE (PrivFileData->File.FileIdentifierDesc)) {
672 return EFI_UNSUPPORTED;
678 *Position = PrivFileData->FilePosition;
705 return EFI_INVALID_PARAMETER;
708 Status = EFI_UNSUPPORTED;
710 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
712 FileIdentifierDesc = _FILE (PrivFileData)->FileIdentifierDesc;
713 ASSERT (FileIdentifierDesc !=
NULL);
714 if (IS_FID_DIRECTORY_FILE (FileIdentifierDesc)) {
721 PrivFileData->FilePosition = Position;
722 PrivFileData->ReadDirInfo.FidOffset = 0;
725 }
else if (IS_FID_NORMAL_FILE (FileIdentifierDesc)) {
730 if (Position == 0xFFFFFFFFFFFFFFFF) {
731 PrivFileData->FilePosition = PrivFileData->FileSize;
733 PrivFileData->FilePosition = Position;
775 UINTN FileSystemInfoLength;
777 UINT64 FreeSpaceSize;
779 UINTN FileSystemVolumeLabelLength;
780 CHAR16 VolumeLabel[64];
782 if ((This ==
NULL) || (InformationType ==
NULL) || (BufferSize ==
NULL) ||
783 ((*BufferSize != 0) && (Buffer ==
NULL)))
785 return EFI_INVALID_PARAMETER;
788 PrivFileData = PRIVATE_UDF_FILE_DATA_FROM_THIS (This);
790 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (PrivFileData->SimpleFs);
792 Status = EFI_UNSUPPORTED;
794 if (
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
796 _FILE (PrivFileData),
797 PrivFileData->FileSize,
798 PrivFileData->FileName,
802 }
else if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
804 if (EFI_ERROR (Status)) {
808 FileSystemInfoLength =
StrSize (VolumeLabel) +
810 if (*BufferSize < FileSystemInfoLength) {
811 *BufferSize = FileSystemInfoLength;
812 return EFI_BUFFER_TOO_SMALL;
828 if (EFI_ERROR (Status)) {
832 FileSystemInfo->
Size = FileSystemInfoLength;
835 PrivFsData->Volume.LogicalVolDesc.LogicalBlockSize;
837 FileSystemInfo->
FreeSpace = FreeSpaceSize;
839 *BufferSize = FileSystemInfoLength;
841 }
else if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
843 if (EFI_ERROR (Status)) {
847 FileSystemVolumeLabelLength =
StrSize (VolumeLabel) +
849 if (*BufferSize < FileSystemVolumeLabelLength) {
850 *BufferSize = FileSystemVolumeLabelLength;
851 return EFI_BUFFER_TOO_SMALL;
857 (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL) / sizeof (CHAR16),
892 return EFI_WRITE_PROTECTED;
916 return EFI_WRITE_PROTECTED;
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
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)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI UdfFlush(IN EFI_FILE_PROTOCOL *This)
EFI_STATUS EFIAPI UdfRead(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI UdfSetInfo(IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI UdfOpenVolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root)
EFI_STATUS EFIAPI UdfGetPosition(IN EFI_FILE_PROTOCOL *This, OUT UINT64 *Position)
EFI_STATUS EFIAPI UdfGetInfo(IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI UdfClose(IN EFI_FILE_PROTOCOL *This)
EFI_STATUS EFIAPI UdfDelete(IN EFI_FILE_PROTOCOL *This)
EFI_STATUS EFIAPI UdfSetPosition(IN EFI_FILE_PROTOCOL *This, IN UINT64 Position)
EFI_STATUS EFIAPI UdfWrite(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI UdfOpen(IN EFI_FILE_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes)
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
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 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 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 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)
EFI_STATUS GetVolumeLabel(IN UDF_VOLUME_INFO *Volume, IN UINTN CharMax, OUT CHAR16 *String)
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)
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)
CHAR16 * MangleFileName(IN CHAR16 *FileName)
#define ARRAY_SIZE(Array)
#define DEBUG(Expression)
STATIC EFI_STATUS SetFileInfo(IN SEMIHOST_FCB *Fcb, IN EFI_FILE_INFO *Info)
VOID EFIAPI Exit(IN EFI_STATUS Status)