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 This program and the accompanying materials
18 are licensed and made available under the terms and conditions of the BSD License
19 which accompanies this distribution. The full text of the license may be found at
20 http://opensource.org/licenses/bsd-license.php
22 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
23 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 #include "FvSimpleFileSystemInternal.h"
30 // Template for EFI_FILE_SYSTEM_INFO data structure.
32 EFI_FILE_SYSTEM_INFO mFsInfoTemplate
= {
33 0, // Populate at runtime
35 0, // Don't know volume size
37 0, // Don't know block size
38 L
"" // Populate at runtime
42 // Template for EFI_FILE_PROTOCOL data structure.
44 EFI_FILE_PROTOCOL mFileSystemTemplate
= {
45 EFI_FILE_PROTOCOL_REVISION
,
46 FvSimpleFileSystemOpen
,
47 FvSimpleFileSystemClose
,
48 FvSimpleFileSystemDelete
,
49 FvSimpleFileSystemRead
,
50 FvSimpleFileSystemWrite
,
51 FvSimpleFileSystemGetPosition
,
52 FvSimpleFileSystemSetPosition
,
53 FvSimpleFileSystemGetInfo
,
54 FvSimpleFileSystemSetInfo
,
55 FvSimpleFileSystemFlush
59 Find and call ReadSection on the first section found of an executable type.
61 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
62 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
63 representing a file's info.
64 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
65 the memory represented by *Buffer.
66 @param Buffer Pointer to a pointer to a data buffer to contain file content.
68 @retval EFI_SUCCESS The call completed successfully.
69 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
70 @retval EFI_ACCESS_DENIED The firmware volume is configured to disallow reads.
71 @retval EFI_NOT_FOUND The requested file was not found in the firmware volume.
72 @retval EFI_DEVICE_ERROR A hardware error occurred when attempting toaccess the firmware volume.
76 FvFsFindExecutableSection (
77 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
78 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
79 IN OUT UINTN
*BufferSize
,
83 EFI_SECTION_TYPE SectionType
;
84 UINT32 AuthenticationStatus
;
87 for (SectionType
= EFI_SECTION_PE32
; SectionType
<= EFI_SECTION_TE
; SectionType
++) {
88 Status
= FvProtocol
->ReadSection (
90 &FvFileInfo
->NameGuid
,
97 if (Status
!= EFI_NOT_FOUND
) {
102 return EFI_NOT_FOUND
;
106 Get the size of the buffer that will be returned by FvFsReadFile.
108 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
109 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
110 representing a file's info.
112 @retval EFI_SUCCESS The file size was gotten correctly.
113 @retval Others The file size wasn't gotten correctly.
118 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
119 IN OUT FV_FILESYSTEM_FILE_INFO
*FvFileInfo
122 UINT32 AuthenticationStatus
;
123 EFI_FV_FILETYPE FoundType
;
124 EFI_FV_FILE_ATTRIBUTES Attributes
;
130 // To get the size of a section, we pass 0 for BufferSize. But we can't pass
131 // NULL for Buffer, as that will cause a return of INVALID_PARAMETER, and we
132 // can't pass NULL for *Buffer, as that will cause the callee to allocate
133 // a buffer of the sections size.
135 IgnoredPtr
= &IgnoredByte
;
136 FvFileInfo
->FileInfo
.FileSize
= 0;
138 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo
->Type
)) {
140 // Get the size of the first executable section out of the file.
142 Status
= FvFsFindExecutableSection (FvProtocol
, FvFileInfo
, (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
, &IgnoredPtr
);
143 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) {
146 } else if (FvFileInfo
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
148 // Try to get the size of a raw section out of the file
150 Status
= FvProtocol
->ReadSection (
152 &FvFileInfo
->NameGuid
,
156 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
157 &AuthenticationStatus
159 if (Status
== EFI_WARN_BUFFER_TOO_SMALL
) {
162 if (EFI_ERROR (Status
)) {
164 // Didn't find a raw section, just return the whole file's size.
166 return FvProtocol
->ReadFile (
168 &FvFileInfo
->NameGuid
,
170 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
173 &AuthenticationStatus
178 // Get the size of the entire file
180 return FvProtocol
->ReadFile (
182 &FvFileInfo
->NameGuid
,
184 (UINTN
*)&FvFileInfo
->FileInfo
.FileSize
,
187 &AuthenticationStatus
195 Helper function to read a file.
197 The data returned depends on the type of the underlying FV file:
198 - For executable types, the first section found that contains executable code is returned.
199 - For files of type FREEFORM, the driver attempts to return the first section of type RAW.
200 If none is found, the entire contents of the FV file are returned.
201 - On all other files the entire contents of the FV file is returned, as by
202 EFI_FIRMWARE_VOLUME2_PROTOCOL.ReadFile.
204 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
205 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
206 representing a file's info.
207 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
208 the memory represented by *Buffer.
209 @param Buffer Pointer to a pointer to a data buffer to contain file content.
211 @retval EFI_SUCCESS The call completed successfully.
212 @retval EFI_WARN_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
213 @retval EFI_ACCESS_DENIED The firmware volume is configured to disallow reads.
214 @retval EFI_NOT_FOUND The requested file was not found in the firmware volume.
215 @retval EFI_DEVICE_ERROR A hardware error occurred when attempting toaccess the firmware volume.
220 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
221 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
222 IN OUT UINTN
*BufferSize
,
226 UINT32 AuthenticationStatus
;
227 EFI_FV_FILETYPE FoundType
;
228 EFI_FV_FILE_ATTRIBUTES Attributes
;
231 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo
->Type
)) {
233 // Read the first executable section out of the file.
235 Status
= FvFsFindExecutableSection (FvProtocol
, FvFileInfo
, BufferSize
, Buffer
);
236 } else if (FvFileInfo
->Type
== EFI_FV_FILETYPE_FREEFORM
) {
238 // Try to read a raw section out of the file
240 Status
= FvProtocol
->ReadSection (
242 &FvFileInfo
->NameGuid
,
247 &AuthenticationStatus
249 if (EFI_ERROR (Status
)) {
251 // Didn't find a raw section, just return the whole file.
253 Status
= FvProtocol
->ReadFile (
255 &FvFileInfo
->NameGuid
,
260 &AuthenticationStatus
265 // Read the entire file
267 Status
= FvProtocol
->ReadFile (
269 &FvFileInfo
->NameGuid
,
274 &AuthenticationStatus
282 Helper function for populating an EFI_FILE_INFO for a file.
284 Note the CreateTime, LastAccessTime and ModificationTime fields in EFI_FILE_INFO
285 are full zero as FV2 protocol has no corresponding info to fill.
287 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
288 representing a file's info.
289 @param BufferSize Pointer to a caller-allocated UINTN. It indicates the size of
290 the memory represented by FileInfo.
291 @param FileInfo A pointer to EFI_FILE_INFO to contain the returned file info.
293 @retval EFI_SUCCESS The call completed successfully.
294 @retval EFI_BUFFER_TOO_SMALL The buffer is too small to contain the requested output.
299 IN FV_FILESYSTEM_FILE_INFO
*FvFileInfo
,
300 IN OUT UINTN
*BufferSize
,
301 OUT EFI_FILE_INFO
*FileInfo
306 InfoSize
= (UINTN
)FvFileInfo
->FileInfo
.Size
;
307 if (*BufferSize
< InfoSize
) {
308 *BufferSize
= InfoSize
;
309 return EFI_BUFFER_TOO_SMALL
;
313 // Initialize FileInfo
315 CopyMem (FileInfo
, &FvFileInfo
->FileInfo
, InfoSize
);
317 *BufferSize
= InfoSize
;
322 Removes the last directory or file entry in a path by changing the last
325 @param Path The pointer to the path to modify.
327 @retval FALSE Nothing was found to remove.
328 @retval TRUE A directory or file was removed.
333 RemoveLastItemFromPath (
340 // get directory name from path... ('chop' off extra)
342 for ( Walker
= Path
, LastSlash
= NULL
343 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
346 if (*Walker
== L
'\\' && *(Walker
+ 1) != CHAR_NULL
) {
347 LastSlash
= Walker
+ 1;
351 if (LastSlash
!= NULL
) {
352 *LastSlash
= CHAR_NULL
;
360 Function to clean up paths.
362 - Single periods in the path are removed.
363 - Double periods in the path are removed along with a single parent directory.
364 - Forward slashes L'/' are converted to backward slashes L'\'.
366 This will be done inline and the existing buffer may be larger than required
369 @param Path The pointer to the string containing the path.
371 @retval NULL An error occured.
372 @return Path in all other instances.
377 TrimFilePathToAbsolutePath (
389 // Fix up the '/' vs '\'
391 for (TempString
= Path
; (TempString
!= NULL
) && (*TempString
!= CHAR_NULL
); TempString
++) {
392 if (*TempString
== L
'/') {
400 while ((TempString
= StrStr (Path
, L
"\\..\\")) != NULL
) {
401 *TempString
= CHAR_NULL
;
403 RemoveLastItemFromPath (Path
);
404 TempSize
= StrSize (TempString
);
405 CopyMem (Path
+ StrLen (Path
), TempString
, TempSize
);
408 if (((TempString
= StrStr (Path
, L
"\\..")) != NULL
) && (*(TempString
+ 3) == CHAR_NULL
)) {
409 *TempString
= CHAR_NULL
;
410 RemoveLastItemFromPath (Path
);
416 while ((TempString
= StrStr (Path
, L
"\\.\\")) != NULL
) {
417 *TempString
= CHAR_NULL
;
419 TempSize
= StrSize (TempString
);
420 CopyMem(Path
+ StrLen (Path
), TempString
, TempSize
);
423 if (((TempString
= StrStr (Path
, L
"\\.")) != NULL
) && (*(TempString
+ 2) == CHAR_NULL
)) {
424 *(TempString
+ 1) = CHAR_NULL
;
427 while ((TempString
= StrStr (Path
, L
"\\\\")) != NULL
) {
428 *TempString
= CHAR_NULL
;
430 TempSize
= StrSize(TempString
);
431 CopyMem(Path
+ StrLen(Path
), TempString
, TempSize
);
434 if (((TempString
= StrStr(Path
, L
"\\\\")) != NULL
) && (*(TempString
+ 1) == CHAR_NULL
)) {
435 *(TempString
) = CHAR_NULL
;
442 Opens a new file relative to the source file's location.
444 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
445 handle to the source location. This would typically be an open
446 handle to a directory.
447 @param NewHandle A pointer to the location to return the opened handle for the new
449 @param FileName The Null-terminated string of the name of the file to be opened.
450 The file name may contain the following path modifiers: "\", ".",
452 @param OpenMode The mode to open the file. The only valid combinations that the
453 file may be opened with are: Read, Read/Write, or Create/Read/Write.
454 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
455 attribute bits for the newly created file.
457 @retval EFI_SUCCESS The file was opened.
458 @retval EFI_NOT_FOUND The specified file could not be found on the device.
459 @retval EFI_NO_MEDIA The device has no medium.
460 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
462 @retval EFI_DEVICE_ERROR The device reported an error.
463 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
464 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
465 when the media is write-protected.
466 @retval EFI_ACCESS_DENIED The service denied access to the file.
467 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
468 @retval EFI_VOLUME_FULL The volume is full.
473 FvSimpleFileSystemOpen (
474 IN EFI_FILE_PROTOCOL
*This
,
475 OUT EFI_FILE_PROTOCOL
**NewHandle
,
481 FV_FILESYSTEM_INSTANCE
*Instance
;
482 FV_FILESYSTEM_FILE
*File
;
483 FV_FILESYSTEM_FILE
*NewFile
;
484 FV_FILESYSTEM_FILE_INFO
*FvFileInfo
;
485 LIST_ENTRY
*FvFileInfoLink
;
487 UINTN FileNameLength
;
488 UINTN NewFileNameLength
;
489 CHAR16
*FileNameWithExtension
;
492 // Check for a valid mode
495 case EFI_FILE_MODE_READ
:
499 return EFI_WRITE_PROTECTED
;
502 File
= FVFS_FILE_FROM_FILE_THIS (This
);
503 Instance
= File
->Instance
;
505 FileName
= TrimFilePathToAbsolutePath (FileName
);
506 if (FileName
== NULL
) {
507 return EFI_INVALID_PARAMETER
;
510 if (FileName
[0] == L
'\\') {
515 // Check for opening root
517 if (StrCmp (FileName
, L
".") == 0 || StrCmp (FileName
, L
"") == 0) {
518 NewFile
= AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE
));
519 if (NewFile
== NULL
) {
520 return EFI_OUT_OF_RESOURCES
;
522 NewFile
->Signature
= FVFS_FILE_SIGNATURE
;
523 NewFile
->Instance
= Instance
;
524 NewFile
->FvFileInfo
= File
->FvFileInfo
;
525 CopyMem (&NewFile
->FileProtocol
, &mFileSystemTemplate
, sizeof (mFileSystemTemplate
));
526 InitializeListHead (&NewFile
->Link
);
527 InsertHeadList (&Instance
->FileHead
, &NewFile
->Link
);
529 NewFile
->DirReadNext
= NULL
;
530 if (!IsListEmpty (&Instance
->FileInfoHead
)) {
531 NewFile
->DirReadNext
= FVFS_GET_FIRST_FILE_INFO (Instance
);
534 *NewHandle
= &NewFile
->FileProtocol
;
539 // Do a linear search for a file in the FV with a matching filename
541 Status
= EFI_NOT_FOUND
;
543 for (FvFileInfoLink
= GetFirstNode (&Instance
->FileInfoHead
);
544 !IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
);
545 FvFileInfoLink
= GetNextNode (&Instance
->FileInfoHead
, FvFileInfoLink
)) {
546 FvFileInfo
= FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink
);
547 if (mUnicodeCollation
->StriColl (mUnicodeCollation
, &FvFileInfo
->FileInfo
.FileName
[0], FileName
) == 0) {
548 Status
= EFI_SUCCESS
;
553 // If the file has not been found check if the filename exists with an extension
554 // in case there was no extension present.
555 // FvFileSystem adds a 'virtual' extension '.EFI' to EFI applications and drivers
556 // present in the Firmware Volume
557 if (Status
== EFI_NOT_FOUND
) {
558 FileNameLength
= StrLen (FileName
);
560 // Does the filename already contain the '.EFI' extension?
561 if (mUnicodeCollation
->StriColl (mUnicodeCollation
, FileName
+ FileNameLength
- 4, L
".efi") != 0) {
562 // No, there was no extension. So add one and search again for the file
563 // NewFileNameLength = FileNameLength + 1 + 4 = (Number of non-null character) + (file extension) + (a null character)
564 NewFileNameLength
= FileNameLength
+ 1 + 4;
565 FileNameWithExtension
= AllocatePool (NewFileNameLength
* 2);
566 StrCpyS (FileNameWithExtension
, NewFileNameLength
, FileName
);
567 StrCatS (FileNameWithExtension
, NewFileNameLength
, L
".EFI");
569 for (FvFileInfoLink
= GetFirstNode (&Instance
->FileInfoHead
);
570 !IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
);
571 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
);
630 Reads data from a file.
632 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
633 handle to read data from.
634 @param BufferSize On input, the size of the Buffer. On output, the amount of data
635 returned in Buffer. In both cases, the size is measured in bytes.
636 @param Buffer The buffer into which the data is read.
638 @retval EFI_SUCCESS Data was read.
639 @retval EFI_NO_MEDIA The device has no medium.
640 @retval EFI_DEVICE_ERROR The device reported an error.
641 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
642 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
643 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
644 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory
645 entry. BufferSize has been updated with the size
646 needed to complete the request.
651 FvSimpleFileSystemRead (
652 IN EFI_FILE_PROTOCOL
*This
,
653 IN OUT UINTN
*BufferSize
,
657 FV_FILESYSTEM_INSTANCE
*Instance
;
658 FV_FILESYSTEM_FILE
*File
;
660 LIST_ENTRY
*FvFileInfoLink
;
664 File
= FVFS_FILE_FROM_FILE_THIS (This
);
665 Instance
= File
->Instance
;
667 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
668 if (File
->DirReadNext
) {
670 // Directory read: populate Buffer with an EFI_FILE_INFO
672 Status
= FvFsGetFileInfo (File
->DirReadNext
, BufferSize
, Buffer
);
673 if (!EFI_ERROR (Status
)) {
675 // Successfully read a directory entry, now update the pointer to the
676 // next file, which will be read on the next call to this function
678 FvFileInfoLink
= GetNextNode (&Instance
->FileInfoHead
, &File
->DirReadNext
->Link
);
679 if (IsNull (&Instance
->FileInfoHead
, FvFileInfoLink
)) {
681 // No more files left
683 File
->DirReadNext
= NULL
;
685 File
->DirReadNext
= FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink
);
691 // Directory read. All entries have been read, so return a zero-size
698 FileSize
= (UINTN
)File
->FvFileInfo
->FileInfo
.FileSize
;
700 FileBuffer
= AllocateZeroPool (FileSize
);
701 if (FileBuffer
== NULL
) {
702 return EFI_DEVICE_ERROR
;
705 Status
= FvFsReadFile (File
->Instance
->FvProtocol
, File
->FvFileInfo
, &FileSize
, &FileBuffer
);
706 if (EFI_ERROR (Status
)) {
707 FreePool (FileBuffer
);
708 return EFI_DEVICE_ERROR
;
711 if (*BufferSize
+ File
->Position
> FileSize
) {
712 *BufferSize
= (UINTN
)(FileSize
- File
->Position
);
715 CopyMem (Buffer
, (UINT8
*)FileBuffer
+ File
->Position
, *BufferSize
);
716 File
->Position
+= *BufferSize
;
718 FreePool (FileBuffer
);
725 Writes data to a file.
727 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
728 handle to write data to.
729 @param BufferSize On input, the size of the Buffer. On output, the amount of data
730 actually written. In both cases, the size is measured in bytes.
731 @param Buffer The buffer of data to write.
733 @retval EFI_SUCCESS Data was written.
734 @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
735 @retval EFI_NO_MEDIA The device has no medium.
736 @retval EFI_DEVICE_ERROR The device reported an error.
737 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
738 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
739 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
740 @retval EFI_ACCESS_DENIED The file was opened read only.
741 @retval EFI_VOLUME_FULL The volume is full.
746 FvSimpleFileSystemWrite (
747 IN EFI_FILE_PROTOCOL
*This
,
748 IN OUT UINTN
*BufferSize
,
752 FV_FILESYSTEM_INSTANCE
*Instance
;
753 FV_FILESYSTEM_FILE
*File
;
755 File
= FVFS_FILE_FROM_FILE_THIS (This
);
756 Instance
= File
->Instance
;
758 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
759 return EFI_UNSUPPORTED
;
761 return EFI_WRITE_PROTECTED
;
766 Returns a file's current position.
768 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
769 handle to get the current position on.
770 @param Position The address to return the file's current position value.
772 @retval EFI_SUCCESS The position was returned.
773 @retval EFI_UNSUPPORTED The request is not valid on open directories.
774 @retval EFI_DEVICE_ERROR An attempt was made to get the position from a deleted file.
779 FvSimpleFileSystemGetPosition (
780 IN EFI_FILE_PROTOCOL
*This
,
784 FV_FILESYSTEM_INSTANCE
*Instance
;
785 FV_FILESYSTEM_FILE
*File
;
787 File
= FVFS_FILE_FROM_FILE_THIS (This
);
788 Instance
= File
->Instance
;
790 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
791 return EFI_UNSUPPORTED
;
793 *Position
= File
->Position
;
799 Sets a file's current position.
801 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
802 file handle to set the requested position on.
803 @param Position The byte position from the start of the file to set.
805 @retval EFI_SUCCESS The position was set.
806 @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open
808 @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted file.
813 FvSimpleFileSystemSetPosition (
814 IN EFI_FILE_PROTOCOL
*This
,
818 FV_FILESYSTEM_INSTANCE
*Instance
;
819 FV_FILESYSTEM_FILE
*File
;
821 File
= FVFS_FILE_FROM_FILE_THIS (This
);
822 Instance
= File
->Instance
;
824 if (File
->FvFileInfo
== Instance
->Root
->FvFileInfo
) {
826 return EFI_UNSUPPORTED
;
829 // Reset directory position to first entry
831 if (File
->DirReadNext
) {
832 File
->DirReadNext
= FVFS_GET_FIRST_FILE_INFO (Instance
);
834 } else if (Position
== 0xFFFFFFFFFFFFFFFFull
) {
835 File
->Position
= File
->FvFileInfo
->FileInfo
.FileSize
;
837 File
->Position
= Position
;
844 Flushes all modified data associated with a file to a device.
846 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
849 @retval EFI_SUCCESS The data was flushed.
850 @retval EFI_NO_MEDIA The device has no medium.
851 @retval EFI_DEVICE_ERROR The device reported an error.
852 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
853 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
854 @retval EFI_ACCESS_DENIED The file was opened read-only.
855 @retval EFI_VOLUME_FULL The volume is full.
860 FvSimpleFileSystemFlush (
861 IN EFI_FILE_PROTOCOL
*This
864 return EFI_WRITE_PROTECTED
;
868 Close and delete the file handle.
870 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
871 handle to the file to delete.
873 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
874 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted.
879 FvSimpleFileSystemDelete (
880 IN EFI_FILE_PROTOCOL
*This
885 Status
= FvSimpleFileSystemClose (This
);
886 ASSERT_EFI_ERROR (Status
);
888 return EFI_WARN_DELETE_FAILURE
;
892 Returns information about a file.
894 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
895 handle the requested information is for.
896 @param InformationType The type identifier for the information being requested.
897 @param BufferSize On input, the size of Buffer. On output, the amount of data
898 returned in Buffer. In both cases, the size is measured in bytes.
899 @param Buffer A pointer to the data buffer to return. The buffer's type is
900 indicated by InformationType.
902 @retval EFI_SUCCESS The information was returned.
903 @retval EFI_UNSUPPORTED The InformationType is not known.
904 @retval EFI_NO_MEDIA The device has no medium.
905 @retval EFI_DEVICE_ERROR The device reported an error.
906 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
907 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
908 BufferSize has been updated with the size needed to complete
913 FvSimpleFileSystemGetInfo (
914 IN EFI_FILE_PROTOCOL
*This
,
915 IN EFI_GUID
*InformationType
,
916 IN OUT UINTN
*BufferSize
,
920 FV_FILESYSTEM_FILE
*File
;
921 EFI_FILE_SYSTEM_INFO
*FsInfoOut
;
922 EFI_FILE_SYSTEM_VOLUME_LABEL
*FsVolumeLabel
;
923 FV_FILESYSTEM_INSTANCE
*Instance
;
927 File
= FVFS_FILE_FROM_FILE_THIS (This
);
929 if (CompareGuid (InformationType
, &gEfiFileSystemInfoGuid
)) {
931 // Return filesystem info
933 Instance
= File
->Instance
;
935 Size
= sizeof (EFI_FILE_SYSTEM_INFO
) + StrSize (Instance
->VolumeLabel
) - sizeof (CHAR16
);
937 if (*BufferSize
< Size
) {
939 return EFI_BUFFER_TOO_SMALL
;
943 // Cast output buffer for convenience
945 FsInfoOut
= (EFI_FILE_SYSTEM_INFO
*) Buffer
;
947 CopyMem (FsInfoOut
, &mFsInfoTemplate
, sizeof (EFI_FILE_SYSTEM_INFO
));
948 Status
= StrnCpyS ( FsInfoOut
->VolumeLabel
,
949 (*BufferSize
- OFFSET_OF (EFI_FILE_SYSTEM_INFO
, VolumeLabel
)) / sizeof (CHAR16
),
950 Instance
->VolumeLabel
,
951 StrLen (Instance
->VolumeLabel
)
953 ASSERT_EFI_ERROR (Status
);
954 FsInfoOut
->Size
= Size
;
956 } else if (CompareGuid (InformationType
, &gEfiFileInfoGuid
)) {
960 return FvFsGetFileInfo (File
->FvFileInfo
, BufferSize
, (EFI_FILE_INFO
*) Buffer
);
961 } else if (CompareGuid (InformationType
, &gEfiFileSystemVolumeLabelInfoIdGuid
)) {
963 // Return Volume Label
965 Instance
= File
->Instance
;
966 Size
= sizeof (EFI_FILE_SYSTEM_VOLUME_LABEL
) + StrSize (Instance
->VolumeLabel
) - sizeof (CHAR16
);;
967 if (*BufferSize
< Size
) {
969 return EFI_BUFFER_TOO_SMALL
;
972 FsVolumeLabel
= (EFI_FILE_SYSTEM_VOLUME_LABEL
*) Buffer
;
973 Status
= StrnCpyS (FsVolumeLabel
->VolumeLabel
,
974 (*BufferSize
- OFFSET_OF (EFI_FILE_SYSTEM_VOLUME_LABEL
, VolumeLabel
)) / sizeof (CHAR16
),
975 Instance
->VolumeLabel
,
976 StrLen (Instance
->VolumeLabel
)
978 ASSERT_EFI_ERROR (Status
);
981 return EFI_UNSUPPORTED
;
986 Sets information about a file.
988 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
989 handle the information is for.
990 @param InformationType The type identifier for the information being set.
991 @param BufferSize The size, in bytes, of Buffer.
992 @param Buffer A pointer to the data buffer to write. The buffer's type is
993 indicated by InformationType.
995 @retval EFI_SUCCESS The information was set.
996 @retval EFI_UNSUPPORTED The InformationType is not known.
997 @retval EFI_NO_MEDIA The device has no medium.
998 @retval EFI_DEVICE_ERROR The device reported an error.
999 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1000 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media is
1002 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID
1003 and the media is read only.
1004 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID
1005 and the media is read-only.
1006 @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file to a
1007 file that is already present.
1008 @retval EFI_ACCESS_DENIED An attempt is being made to change the EFI_FILE_DIRECTORY
1010 @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a directory.
1011 @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file was opened
1012 read-only and an attempt is being made to modify a field
1013 other than Attribute.
1014 @retval EFI_VOLUME_FULL The volume is full.
1015 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type indicated
1021 FvSimpleFileSystemSetInfo (
1022 IN EFI_FILE_PROTOCOL
*This
,
1023 IN EFI_GUID
*InformationType
,
1024 IN UINTN BufferSize
,
1028 if (CompareGuid (InformationType
, &gEfiFileSystemInfoGuid
) ||
1029 CompareGuid (InformationType
, &gEfiFileInfoGuid
) ||
1030 CompareGuid (InformationType
, &gEfiFileSystemVolumeLabelInfoIdGuid
)) {
1031 return EFI_WRITE_PROTECTED
;
1034 return EFI_UNSUPPORTED
;