2 This driver uses the EFI_FIRMWARE_VOLUME2_PROTOCOL to expose files in firmware
3 volumes via the the EFI_SIMPLE_FILESYSTEM_PROTOCOL and EFI_FILE_PROTOCOL.
5 It will expose a single directory, containing one file for each file in the firmware
6 volume. If a file has a UI section, its contents will be used as a filename.
7 Otherwise, a string representation of the GUID will be used.
8 Files of an executable type (That is PEIM, DRIVER, COMBINED_PEIM_DRIVER and APPLICATION)
9 will have ".efi" added to their filename.
11 Its primary intended use is to be able to start EFI applications embedded in FVs
12 from the UEFI shell. It is entirely read-only.
14 Copyright (c) 2014, ARM Limited. All rights reserved.
15 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
17 SPDX-License-Identifier: BSD-2-Clause-Patent
21 #include "FvSimpleFileSystemInternal.h"
24 // Template for EFI_FILE_SYSTEM_INFO data structure.
26 EFI_FILE_SYSTEM_INFO mFsInfoTemplate
= {
27 0, // Populate at runtime
29 0, // Don't know volume size
31 0, // Don't know block size
32 L
"" // Populate at runtime
36 // Template for EFI_FILE_PROTOCOL data structure.
38 EFI_FILE_PROTOCOL mFileSystemTemplate
= {
39 EFI_FILE_PROTOCOL_REVISION
,
40 FvSimpleFileSystemOpen
,
41 FvSimpleFileSystemClose
,
42 FvSimpleFileSystemDelete
,
43 FvSimpleFileSystemRead
,
44 FvSimpleFileSystemWrite
,
45 FvSimpleFileSystemGetPosition
,
46 FvSimpleFileSystemSetPosition
,
47 FvSimpleFileSystemGetInfo
,
48 FvSimpleFileSystemSetInfo
,
49 FvSimpleFileSystemFlush
53 Find and call ReadSection on the first section found of an executable type.
55 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
56 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
57 representing a file's info.
58 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
59 the memory represented by *Buffer.
60 @param Buffer Pointer to a pointer to a data buffer to contain file content.
62 @retval EFI_SUCCESS The call completed successfully.
63 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
64 @retval EFI_ACCESS_DENIED The firmware volume is configured to disallow reads.
65 @retval EFI_NOT_FOUND The requested file was not found in the firmware volume.
66 @retval EFI_DEVICE_ERROR A hardware error occurred when attempting toaccess the firmware volume.
70 FvFsFindExecutableSection (
71 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
72 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
73 IN OUT UINTN
*BufferSize
,
77 EFI_SECTION_TYPE SectionType
;
78 UINT32 AuthenticationStatus
;
81 for (SectionType
= EFI_SECTION_PE32
; SectionType
<= EFI_SECTION_TE
; SectionType
++) {
82 Status
= FvProtocol
->ReadSection (
84 &FvFileInfo
->NameGuid
,
91 if (Status
!= EFI_NOT_FOUND
) {
100 Get the size of the buffer that will be returned by FvFsReadFile.
102 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
103 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
104 representing a file's info.
106 @retval EFI_SUCCESS The file size was gotten correctly.
107 @retval Others The file size wasn't gotten correctly.
112 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
113 IN OUT FV_FILESYSTEM_FILE_INFO
*FvFileInfo
116 UINT32 AuthenticationStatus
;
117 EFI_FV_FILETYPE FoundType
;
118 EFI_FV_FILE_ATTRIBUTES Attributes
;
124 // To get the size of a section, we pass 0 for BufferSize. But we can't pass
125 // NULL for Buffer, as that will cause a return of INVALID_PARAMETER, and we
126 // can't pass NULL for *Buffer, as that will cause the callee to allocate
127 // a buffer of the sections size.
129 IgnoredPtr
= &IgnoredByte
;
130 FvFileInfo
->FileInfo
.FileSize
= 0;
132 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo
->Type
)) {
134 // Get the size of the first executable section out of the file.
136 Status
= FvFsFindExecutableSection (FvProtocol
, FvFileInfo
, (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
, &IgnoredPtr
);
137 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) {
140 } else if (FvFileInfo
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
142 // Try to get the size of a raw section out of the file
144 Status
= FvProtocol
->ReadSection (
146 &FvFileInfo
->NameGuid
,
150 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
151 &AuthenticationStatus
153 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) {
157 if (EFI_ERROR (Status
)) {
159 // Didn't find a raw section, just return the whole file's size.
161 return FvProtocol
->ReadFile (
163 &FvFileInfo
->NameGuid
,
165 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
168 &AuthenticationStatus
173 // Get the size of the entire file
175 return FvProtocol
->ReadFile (
177 &FvFileInfo
->NameGuid
,
179 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
182 &AuthenticationStatus
190 Helper function to read a file.
192 The data returned depends on the type of the underlying FV file:
193 - For executable types, the first section found that contains executable code is returned.
194 - For files of type FREEFORM, the driver attempts to return the first section of type RAW.
195 If none is found, the entire contents of the FV file are returned.
196 - On all other files the entire contents of the FV file is returned, as by
197 EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadFile.
199 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
200 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
201 representing a file's info.
202 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
203 the memory represented by *Buffer.
204 @param Buffer Pointer to a pointer to a data buffer to contain file content.
206 @retval EFI_SUCCESS The call completed successfully.
207 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
208 @retval EFI_ACCESS_DENIED The firmware volume is configured to disallow reads.
209 @retval EFI_NOT_FOUND The requested file was not found in the firmware volume.
210 @retval EFI_DEVICE_ERROR A hardware error occurred when attempting toaccess the firmware volume.
215 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
216 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
217 IN OUT UINTN
*BufferSize
,
221 UINT32 AuthenticationStatus
;
222 EFI_FV_FILETYPE FoundType
;
223 EFI_FV_FILE_ATTRIBUTES Attributes
;
226 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo
->Type
)) {
228 // Read the first executable section out of the file.
230 Status
= FvFsFindExecutableSection (FvProtocol
, FvFileInfo
, BufferSize
, Buffer
);
231 } else if (FvFileInfo
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
233 // Try to read a raw section out of the file
235 Status
= FvProtocol
->ReadSection (
237 &FvFileInfo
->NameGuid
,
242 &AuthenticationStatus
244 if (EFI_ERROR (Status
)) {
246 // Didn't find a raw section, just return the whole file.
248 Status
= FvProtocol
->ReadFile (
250 &FvFileInfo
->NameGuid
,
255 &AuthenticationStatus
260 // Read the entire file
262 Status
= FvProtocol
->ReadFile (
264 &FvFileInfo
->NameGuid
,
269 &AuthenticationStatus
277 Helper function for populating an EFI_FILE_INFO for a file.
279 Note the CreateTime, LastAccessTime and ModificationTime fields in EFI_FILE_INFO
280 are full zero as FV2 protocol has no corresponding info to fill.
282 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
283 representing a file's info.
284 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
285 the memory represented by FileInfo.
286 @param FileInfo A pointer to EFI_FILE_INFO to contain the returned file info.
288 @retval EFI_SUCCESS The call completed successfully.
289 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
294 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
295 IN OUT UINTN
*BufferSize
,
296 OUT EFI_FILE_INFO
*FileInfo
301 InfoSize
= (UINTN
)FvFileInfo
->FileInfo
.Size
;
302 if (*BufferSize
< InfoSize
) {
303 *BufferSize
= InfoSize
;
304 return EFI_BUFFER_TOO_SMALL
;
308 // Initialize FileInfo
310 CopyMem (FileInfo
, &FvFileInfo
->FileInfo
, InfoSize
);
312 *BufferSize
= InfoSize
;
317 Removes the last directory or file entry in a path by changing the last
320 @param Path The pointer to the path to modify.
322 @retval FALSE Nothing was found to remove.
323 @retval TRUE A directory or file was removed.
328 RemoveLastItemFromPath (
336 // get directory name from path... ('chop' off extra)
338 for ( Walker
= Path
, LastSlash
= NULL
339 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
343 if ((*Walker
== L
'\\') && (*(Walker
+ 1) != CHAR_NULL
)) {
344 LastSlash
= Walker
+ 1;
348 if (LastSlash
!= NULL
) {
349 *LastSlash
= CHAR_NULL
;
357 Function to clean up paths.
359 - Single periods in the path are removed.
360 - Double periods in the path are removed along with a single parent directory.
361 - Forward slashes L'/' are converted to backward slashes L'\'.
363 This will be done inline and the existing buffer may be larger than required
366 @param Path The pointer to the string containing the path.
368 @retval NULL An error occurred.
369 @return Path in all other instances.
374 TrimFilePathToAbsolutePath (
386 // Fix up the '/' vs '\'
388 for (TempString
= Path
; (TempString
!= NULL
) && (*TempString
!= CHAR_NULL
); TempString
++) {
389 if (*TempString
== L
'/') {
397 while ((TempString
= StrStr (Path
, L
"\\..\\")) != NULL
) {
398 *TempString
= CHAR_NULL
;
400 RemoveLastItemFromPath (Path
);
401 TempSize
= StrSize (TempString
);
402 CopyMem (Path
+ StrLen (Path
), TempString
, TempSize
);
405 if (((TempString
= StrStr (Path
, L
"\\..")) != NULL
) && (*(TempString
+ 3) == CHAR_NULL
)) {
406 *TempString
= CHAR_NULL
;
407 RemoveLastItemFromPath (Path
);
413 while ((TempString
= StrStr (Path
, L
"\\.\\")) != NULL
) {
414 *TempString
= CHAR_NULL
;
416 TempSize
= StrSize (TempString
);
417 CopyMem (Path
+ StrLen (Path
), TempString
, TempSize
);
420 if (((TempString
= StrStr (Path
, L
"\\.")) != NULL
) && (*(TempString
+ 2) == CHAR_NULL
)) {
421 *(TempString
+ 1) = CHAR_NULL
;
424 while ((TempString
= StrStr (Path
, L
"\\\\")) != NULL
) {
425 *TempString
= CHAR_NULL
;
427 TempSize
= StrSize (TempString
);
428 CopyMem (Path
+ StrLen (Path
), TempString
, TempSize
);
431 if (((TempString
= StrStr (Path
, L
"\\\\")) != NULL
) && (*(TempString
+ 1) == CHAR_NULL
)) {
432 *(TempString
) = CHAR_NULL
;
439 Opens a new file relative to the source file's location.
441 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
442 handle to the source location. This would typically be an open
443 handle to a directory.
444 @param NewHandle A pointer to the location to return the opened handle for the new
446 @param FileName The Null-terminated string of the name of the file to be opened.
447 The file name may contain the following path modifiers: "\", ".",
449 @param OpenMode The mode to open the file. The only valid combinations that the
450 file may be opened with are: Read, Read/Write, or Create/Read/Write.
451 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
452 attribute bits for the newly created file.
454 @retval EFI_SUCCESS The file was opened.
455 @retval EFI_NOT_FOUND The specified file could not be found on the device.
456 @retval EFI_NO_MEDIA The device has no medium.
457 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
459 @retval EFI_DEVICE_ERROR The device reported an error.
460 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
461 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
462 when the media is write-protected.
463 @retval EFI_ACCESS_DENIED The service denied access to the file.
464 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
465 @retval EFI_VOLUME_FULL The volume is full.
470 FvSimpleFileSystemOpen (
471 IN EFI_FILE_PROTOCOL
*This
,
472 OUT EFI_FILE_PROTOCOL
**NewHandle
,
478 FV_FILESYSTEM_INSTANCE
*Instance
;
479 FV_FILESYSTEM_FILE
*File
;
480 FV_FILESYSTEM_FILE
*NewFile
;
481 FV_FILESYSTEM_FILE_INFO
*FvFileInfo
;
482 LIST_ENTRY
*FvFileInfoLink
;
484 UINTN FileNameLength
;
485 UINTN NewFileNameLength
;
486 CHAR16
*FileNameWithExtension
;
489 // Check for a valid mode
492 case EFI_FILE_MODE_READ
:
496 return EFI_WRITE_PROTECTED
;
499 File
= FVFS_FILE_FROM_FILE_THIS (This
);
500 Instance
= File
->Instance
;
502 FileName
= TrimFilePathToAbsolutePath (FileName
);
503 if (FileName
== NULL
) {
504 return EFI_INVALID_PARAMETER
;
507 if (FileName
[0] == L
'\\') {
512 // Check for opening root
514 if ((StrCmp (FileName
, L
".") == 0) || (StrCmp (FileName
, L
"") == 0)) {
515 NewFile
= AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE
));
516 if (NewFile
== NULL
) {
517 return EFI_OUT_OF_RESOURCES
;
520 NewFile
->Signature
= FVFS_FILE_SIGNATURE
;
521 NewFile
->Instance
= Instance
;
522 NewFile
->FvFileInfo
= File
->FvFileInfo
;
523 CopyMem (&NewFile
->FileProtocol
, &mFileSystemTemplate
, sizeof (mFileSystemTemplate
));
524 InitializeListHead (&NewFile
->Link
);
525 InsertHeadList (&Instance
->FileHead
, &NewFile
->Link
);
527 NewFile
->DirReadNext
= NULL
;
528 if (!IsListEmpty (&Instance
->FileInfoHead
)) {
529 NewFile
->DirReadNext
= FVFS_GET_FIRST_FILE_INFO (Instance
);
532 *NewHandle
= &NewFile
->FileProtocol
;
537 // Do a linear search for a file in the FV with a matching filename
539 Status
= EFI_NOT_FOUND
;
541 for (FvFileInfoLink
= GetFirstNode (&Instance
->FileInfoHead
);
542 !IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
);
543 FvFileInfoLink
= GetNextNode (&Instance
->FileInfoHead
, FvFileInfoLink
))
545 FvFileInfo
= FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink
);
546 if (mUnicodeCollation
->StriColl (mUnicodeCollation
, &FvFileInfo
->FileInfo
.FileName
[0], FileName
) == 0) {
547 Status
= EFI_SUCCESS
;
552 // If the file has not been found check if the filename exists with an extension
553 // in case there was no extension present.
554 // FvFileSystem adds a 'virtual' extension '.EFI' to EFI applications and drivers
555 // present in the Firmware Volume
556 if (Status
== EFI_NOT_FOUND
) {
557 FileNameLength
= StrLen (FileName
);
559 // Does the filename already contain the '.EFI' extension?
560 if (mUnicodeCollation
->StriColl (mUnicodeCollation
, FileName
+ FileNameLength
- 4, L
".efi") != 0) {
561 // No, there was no extension. So add one and search again for the file
562 // NewFileNameLength = FileNameLength + 1 + 4 = (Number of non-null character) + (file extension) + (a null character)
563 NewFileNameLength
= FileNameLength
+ 1 + 4;
564 FileNameWithExtension
= AllocatePool (NewFileNameLength
* 2);
565 StrCpyS (FileNameWithExtension
, NewFileNameLength
, FileName
);
566 StrCatS (FileNameWithExtension
, NewFileNameLength
, L
".EFI");
568 for (FvFileInfoLink
= GetFirstNode (&Instance
->FileInfoHead
);
569 !IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
);
570 FvFileInfoLink
= GetNextNode (&Instance
->FileInfoHead
, FvFileInfoLink
))
572 FvFileInfo
= FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink
);
573 if (mUnicodeCollation
->StriColl (mUnicodeCollation
, &FvFileInfo
->FileInfo
.FileName
[0], FileNameWithExtension
) == 0) {
574 Status
= EFI_SUCCESS
;
581 if (!EFI_ERROR (Status
)) {
582 NewFile
= AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE
));
583 if (NewFile
== NULL
) {
584 return EFI_OUT_OF_RESOURCES
;
587 NewFile
->Signature
= FVFS_FILE_SIGNATURE
;
588 NewFile
->Instance
= Instance
;
589 NewFile
->FvFileInfo
= FvFileInfo
;
590 CopyMem (&NewFile
->FileProtocol
, &mFileSystemTemplate
, sizeof (mFileSystemTemplate
));
591 InitializeListHead (&NewFile
->Link
);
592 InsertHeadList (&Instance
->FileHead
, &NewFile
->Link
);
594 *NewHandle
= &NewFile
->FileProtocol
;
598 return EFI_NOT_FOUND
;
602 Closes a specified file handle.
604 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
607 @retval EFI_SUCCESS The file was closed.
612 FvSimpleFileSystemClose (
613 IN EFI_FILE_PROTOCOL
*This
616 FV_FILESYSTEM_INSTANCE
*Instance
;
617 FV_FILESYSTEM_FILE
*File
;
619 File
= FVFS_FILE_FROM_FILE_THIS (This
);
620 Instance
= File
->Instance
;
622 if (File
!= Instance
->Root
) {
623 RemoveEntryList (&File
->Link
);
631 Reads data from a file.
633 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
634 handle to read data from.
635 @param BufferSize On input, the size of the Buffer. On output, the amount of data
636 returned in Buffer. In both cases, the size is measured in bytes.
637 @param Buffer The buffer into which the data is read.
639 @retval EFI_SUCCESS Data was read.
640 @retval EFI_NO_MEDIA The device has no medium.
641 @retval EFI_DEVICE_ERROR The device reported an error.
642 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
643 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
644 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
645 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory
646 entry. BufferSize has been updated with the size
647 needed to complete the request.
652 FvSimpleFileSystemRead (
653 IN EFI_FILE_PROTOCOL
*This
,
654 IN OUT UINTN
*BufferSize
,
658 FV_FILESYSTEM_INSTANCE
*Instance
;
659 FV_FILESYSTEM_FILE
*File
;
661 LIST_ENTRY
*FvFileInfoLink
;
665 File
= FVFS_FILE_FROM_FILE_THIS (This
);
666 Instance
= File
->Instance
;
668 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
669 if (File
->DirReadNext
) {
671 // Directory read: populate Buffer with an EFI_FILE_INFO
673 Status
= FvFsGetFileInfo (File
->DirReadNext
, BufferSize
, Buffer
);
674 if (!EFI_ERROR (Status
)) {
676 // Successfully read a directory entry, now update the pointer to the
677 // next file, which will be read on the next call to this function
679 FvFileInfoLink
= GetNextNode (&Instance
->FileInfoHead
, &File
->DirReadNext
->Link
);
680 if (IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
)) {
682 // No more files left
684 File
->DirReadNext
= NULL
;
686 File
->DirReadNext
= FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink
);
693 // Directory read. All entries have been read, so return a zero-size
700 FileSize
= (UINTN
)File
->FvFileInfo
->FileInfo
.FileSize
;
702 FileBuffer
= AllocateZeroPool (FileSize
);
703 if (FileBuffer
== NULL
) {
704 return EFI_DEVICE_ERROR
;
707 Status
= FvFsReadFile (File
->Instance
->FvProtocol
, File
->FvFileInfo
, &FileSize
, &FileBuffer
);
708 if (EFI_ERROR (Status
)) {
709 FreePool (FileBuffer
);
710 return EFI_DEVICE_ERROR
;
713 if (*BufferSize
+ File
->Position
> FileSize
) {
714 *BufferSize
= (UINTN
)(FileSize
- File
->Position
);
717 CopyMem (Buffer
, (UINT8
*)FileBuffer
+ File
->Position
, *BufferSize
);
718 File
->Position
+= *BufferSize
;
720 FreePool (FileBuffer
);
727 Writes data to a file.
729 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
730 handle to write data to.
731 @param BufferSize On input, the size of the Buffer. On output, the amount of data
732 actually written. In both cases, the size is measured in bytes.
733 @param Buffer The buffer of data to write.
735 @retval EFI_SUCCESS Data was written.
736 @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
737 @retval EFI_NO_MEDIA The device has no medium.
738 @retval EFI_DEVICE_ERROR The device reported an error.
739 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
740 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
741 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
742 @retval EFI_ACCESS_DENIED The file was opened read only.
743 @retval EFI_VOLUME_FULL The volume is full.
748 FvSimpleFileSystemWrite (
749 IN EFI_FILE_PROTOCOL
*This
,
750 IN OUT UINTN
*BufferSize
,
754 FV_FILESYSTEM_INSTANCE
*Instance
;
755 FV_FILESYSTEM_FILE
*File
;
757 File
= FVFS_FILE_FROM_FILE_THIS (This
);
758 Instance
= File
->Instance
;
760 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
761 return EFI_UNSUPPORTED
;
763 return EFI_WRITE_PROTECTED
;
768 Returns a file's current position.
770 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
771 handle to get the current position on.
772 @param Position The address to return the file's current position value.
774 @retval EFI_SUCCESS The position was returned.
775 @retval EFI_UNSUPPORTED The request is not valid on open directories.
776 @retval EFI_DEVICE_ERROR An attempt was made to get the position from a deleted file.
781 FvSimpleFileSystemGetPosition (
782 IN EFI_FILE_PROTOCOL
*This
,
786 FV_FILESYSTEM_INSTANCE
*Instance
;
787 FV_FILESYSTEM_FILE
*File
;
789 File
= FVFS_FILE_FROM_FILE_THIS (This
);
790 Instance
= File
->Instance
;
792 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
793 return EFI_UNSUPPORTED
;
795 *Position
= File
->Position
;
801 Sets a file's current position.
803 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
804 file handle to set the requested position on.
805 @param Position The byte position from the start of the file to set.
807 @retval EFI_SUCCESS The position was set.
808 @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open
810 @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted file.
815 FvSimpleFileSystemSetPosition (
816 IN EFI_FILE_PROTOCOL
*This
,
820 FV_FILESYSTEM_INSTANCE
*Instance
;
821 FV_FILESYSTEM_FILE
*File
;
823 File
= FVFS_FILE_FROM_FILE_THIS (This
);
824 Instance
= File
->Instance
;
826 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
828 return EFI_UNSUPPORTED
;
832 // Reset directory position to first entry
834 if (File
->DirReadNext
) {
835 File
->DirReadNext
= FVFS_GET_FIRST_FILE_INFO (Instance
);
837 } else if (Position
== 0xFFFFFFFFFFFFFFFFull
) {
838 File
->Position
= File
->FvFileInfo
->FileInfo
.FileSize
;
840 File
->Position
= Position
;
847 Flushes all modified data associated with a file to a device.
849 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
852 @retval EFI_SUCCESS The data was flushed.
853 @retval EFI_NO_MEDIA The device has no medium.
854 @retval EFI_DEVICE_ERROR The device reported an error.
855 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
856 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
857 @retval EFI_ACCESS_DENIED The file was opened read-only.
858 @retval EFI_VOLUME_FULL The volume is full.
863 FvSimpleFileSystemFlush (
864 IN EFI_FILE_PROTOCOL
*This
867 return EFI_WRITE_PROTECTED
;
871 Close and delete the file handle.
873 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
874 handle to the file to delete.
876 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
877 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted.
882 FvSimpleFileSystemDelete (
883 IN EFI_FILE_PROTOCOL
*This
888 Status
= FvSimpleFileSystemClose (This
);
889 ASSERT_EFI_ERROR (Status
);
891 return EFI_WARN_DELETE_FAILURE
;
895 Returns information about a file.
897 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
898 handle the requested information is for.
899 @param InformationType The type identifier for the information being requested.
900 @param BufferSize On input, the size of Buffer. On output, the amount of data
901 returned in Buffer. In both cases, the size is measured in bytes.
902 @param Buffer A pointer to the data buffer to return. The buffer's type is
903 indicated by InformationType.
905 @retval EFI_SUCCESS The information was returned.
906 @retval EFI_UNSUPPORTED The InformationType is not known.
907 @retval EFI_NO_MEDIA The device has no medium.
908 @retval EFI_DEVICE_ERROR The device reported an error.
909 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
910 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
911 BufferSize has been updated with the size needed to complete
916 FvSimpleFileSystemGetInfo (
917 IN EFI_FILE_PROTOCOL
*This
,
918 IN EFI_GUID
*InformationType
,
919 IN OUT UINTN
*BufferSize
,
923 FV_FILESYSTEM_FILE
*File
;
924 EFI_FILE_SYSTEM_INFO
*FsInfoOut
;
925 EFI_FILE_SYSTEM_VOLUME_LABEL
*FsVolumeLabel
;
926 FV_FILESYSTEM_INSTANCE
*Instance
;
930 File
= FVFS_FILE_FROM_FILE_THIS (This
);
932 if (CompareGuid (InformationType
, &gEfiFileSystemInfoGuid
)) {
934 // Return filesystem info
936 Instance
= File
->Instance
;
938 Size
= sizeof (EFI_FILE_SYSTEM_INFO
) + StrSize (Instance
->VolumeLabel
) - sizeof (CHAR16
);
940 if (*BufferSize
< Size
) {
942 return EFI_BUFFER_TOO_SMALL
;
946 // Cast output buffer for convenience
948 FsInfoOut
= (EFI_FILE_SYSTEM_INFO
*)Buffer
;
950 CopyMem (FsInfoOut
, &mFsInfoTemplate
, sizeof (EFI_FILE_SYSTEM_INFO
));
952 FsInfoOut
->VolumeLabel
,
953 (*BufferSize
- OFFSET_OF (EFI_FILE_SYSTEM_INFO
, VolumeLabel
)) / sizeof (CHAR16
),
954 Instance
->VolumeLabel
,
955 StrLen (Instance
->VolumeLabel
)
957 ASSERT_EFI_ERROR (Status
);
958 FsInfoOut
->Size
= Size
;
960 } else if (CompareGuid (InformationType
, &gEfiFileInfoGuid
)) {
964 return FvFsGetFileInfo (File
->FvFileInfo
, BufferSize
, (EFI_FILE_INFO
*)Buffer
);
965 } else if (CompareGuid (InformationType
, &gEfiFileSystemVolumeLabelInfoIdGuid
)) {
967 // Return Volume Label
969 Instance
= File
->Instance
;
970 Size
= sizeof (EFI_FILE_SYSTEM_VOLUME_LABEL
) + StrSize (Instance
->VolumeLabel
) - sizeof (CHAR16
);
971 if (*BufferSize
< Size
) {
973 return EFI_BUFFER_TOO_SMALL
;
976 FsVolumeLabel
= (EFI_FILE_SYSTEM_VOLUME_LABEL
*)Buffer
;
978 FsVolumeLabel
->VolumeLabel
,
979 (*BufferSize
- OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL
, VolumeLabel
)) / sizeof (CHAR16
),
980 Instance
->VolumeLabel
,
981 StrLen (Instance
->VolumeLabel
)
983 ASSERT_EFI_ERROR (Status
);
986 return EFI_UNSUPPORTED
;
991 Sets information about a file.
993 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
994 handle the information is for.
995 @param InformationType The type identifier for the information being set.
996 @param BufferSize The size, in bytes, of Buffer.
997 @param Buffer A pointer to the data buffer to write. The buffer's type is
998 indicated by InformationType.
1000 @retval EFI_SUCCESS The information was set.
1001 @retval EFI_UNSUPPORTED The InformationType is not known.
1002 @retval EFI_NO_MEDIA The device has no medium.
1003 @retval EFI_DEVICE_ERROR The device reported an error.
1004 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1005 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media is
1007 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID
1008 and the media is read only.
1009 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID
1010 and the media is read-only.
1011 @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file to a
1012 file that is already present.
1013 @retval EFI_ACCESS_DENIED An attempt is being made to change the EFI_FILE_DIRECTORY
1015 @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a directory.
1016 @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file was opened
1017 read-only and an attempt is being made to modify a field
1018 other than Attribute.
1019 @retval EFI_VOLUME_FULL The volume is full.
1020 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type indicated
1026 FvSimpleFileSystemSetInfo (
1027 IN EFI_FILE_PROTOCOL
*This
,
1028 IN EFI_GUID
*InformationType
,
1029 IN UINTN BufferSize
,
1033 if (CompareGuid (InformationType
, &gEfiFileSystemInfoGuid
) ||
1034 CompareGuid (InformationType
, &gEfiFileInfoGuid
) ||
1035 CompareGuid (InformationType
, &gEfiFileSystemVolumeLabelInfoIdGuid
))
1037 return EFI_WRITE_PROTECTED
;
1040 return EFI_UNSUPPORTED
;