2 The internal header file of FvSimpleFileSystem driver.
4 Copyright (c) 2014, ARM Limited. All rights reserved.
5 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef __FVFS_INTERNAL_H__
12 #define __FVFS_INTERNAL_H__
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/DevicePathLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiLib.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/FirmwareVolume2.h>
28 #include <Protocol/SimpleFileSystem.h>
29 #include <Protocol/UnicodeCollation.h>
31 #include <Guid/FileSystemInfo.h>
32 #include <Guid/FileInfo.h>
33 #include <Guid/FileSystemVolumeLabelInfo.h>
35 typedef struct _FV_FILESYSTEM_FILE FV_FILESYSTEM_FILE
;
36 typedef struct _FV_FILESYSTEM_FILE_INFO FV_FILESYSTEM_FILE_INFO
;
37 typedef struct _FV_FILESYSTEM_INSTANCE FV_FILESYSTEM_INSTANCE
;
40 // Struct representing an instance of the "filesystem". There will be one of
41 // these structs per FV.
43 struct _FV_FILESYSTEM_INSTANCE
{
45 LIST_ENTRY FileInfoHead
;
47 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
48 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
;
49 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs
;
50 FV_FILESYSTEM_FILE
*Root
;
55 // Struct representing a opening file. Each opening operation on file will
56 // create such an instance except for the "root directory", which will only
57 // be created once for each FV.
59 struct _FV_FILESYSTEM_FILE
{
62 FV_FILESYSTEM_FILE_INFO
*DirReadNext
;
63 FV_FILESYSTEM_INSTANCE
*Instance
;
64 EFI_FILE_PROTOCOL FileProtocol
;
65 FV_FILESYSTEM_FILE_INFO
*FvFileInfo
;
70 // Struct representing the info of a file.
72 struct _FV_FILESYSTEM_FILE_INFO
{
77 EFI_FILE_INFO FileInfo
;
80 #define FVFS_FILE_SIGNATURE SIGNATURE_32 ('f', 'v', 'f', 'i')
81 #define FVFS_FILE_INFO_SIGNATURE SIGNATURE_32 ('f', 'v', 'i', 'n')
82 #define FVFS_INSTANCE_SIGNATURE SIGNATURE_32 ('f', 'v', 'f', 's')
84 #define FVFS_INSTANCE_FROM_SIMPLE_FS_THIS(This) CR ( \
86 FV_FILESYSTEM_INSTANCE, \
88 FVFS_INSTANCE_SIGNATURE \
91 #define FVFS_FILE_FROM_FILE_THIS(This) CR ( \
98 #define FVFS_FILE_INFO_FROM_LINK(This) CR ( \
100 FV_FILESYSTEM_FILE_INFO, \
102 FVFS_FILE_INFO_SIGNATURE \
105 #define FVFS_FILE_FROM_LINK(FileLink) CR (FileLink, FV_FILESYSTEM_FILE, Link, FVFS_FILE_SIGNATURE)
107 #define FVFS_GET_FIRST_FILE(Instance) FVFS_FILE_FROM_LINK (GetFirstNode (&Instance->FileHead))
109 #define FVFS_GET_FIRST_FILE_INFO(Instance) FVFS_FILE_INFO_FROM_LINK (GetFirstNode (&Instance->FileInfoHead))
111 #define FV_FILETYPE_IS_EXECUTABLE(Type) ((Type) == EFI_FV_FILETYPE_PEIM ||\
112 (Type) == EFI_FV_FILETYPE_DRIVER || \
113 (Type) == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER || \
114 (Type) == EFI_FV_FILETYPE_APPLICATION)
117 Open the root directory on a volume.
119 @param This A pointer to the volume to open the root directory.
120 @param RootFile A pointer to the location to return the opened file handle for the
123 @retval EFI_SUCCESS The device was opened.
124 @retval EFI_UNSUPPORTED This volume does not support the requested file system type.
125 @retval EFI_NO_MEDIA The device has no medium.
126 @retval EFI_DEVICE_ERROR The device reported an error.
127 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
128 @retval EFI_ACCESS_DENIED The service denied access to the file.
129 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
130 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
131 longer supported. Any existing file handles for this volume are
132 no longer valid. To access the files on the new medium, the
133 volume must be reopened with OpenVolume().
138 FvSimpleFileSystemOpenVolume (
139 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
140 OUT EFI_FILE_PROTOCOL
**RootFile
144 Test to see if this driver supports ControllerHandle.
146 @param DriverBinding Protocol instance pointer.
147 @param ControllerHandle Handle of device to test
148 @param RemainingDevicePath Optional parameter use to pick a specific child
151 @retval EFI_SUCCESS This driver supports this device
152 @retval EFI_ALREADY_STARTED This driver is already running on this device
153 @retval other This driver does not support this device
158 FvSimpleFileSystemDriverSupported (
159 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
160 IN EFI_HANDLE ControllerHandle
,
161 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
165 Start this driver on ControllerHandle by opening a FV protocol and
166 installing a SimpleFileSystem protocol on ControllerHandle.
168 @param DriverBinding Protocol instance pointer.
169 @param ControllerHandle Handle of device to bind driver to
170 @param RemainingDevicePath Optional parameter use to pick a specific child
173 @retval EFI_SUCCESS This driver is added to ControllerHandle
174 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
175 @retval other This driver does not support this device
180 FvSimpleFileSystemDriverStart (
181 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
182 IN EFI_HANDLE ControllerHandle
,
183 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
187 Stop this driver on ControllerHandle by removing SimpleFileSystem protocol and closing
188 the FV protocol on ControllerHandle.
190 @param DriverBinding Protocol instance pointer.
191 @param ControllerHandle Handle of device to stop driver on
192 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
193 children is zero stop the entire bus driver.
194 @param ChildHandleBuffer List of Child Handles to Stop.
196 @retval EFI_SUCCESS This driver is removed ControllerHandle
197 @retval other This driver was not removed from this device
202 FvSimpleFileSystemDriverStop (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
,
204 IN EFI_HANDLE ControllerHandle
,
205 IN UINTN NumberOfChildren
,
206 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
210 Opens a new file relative to the source file's location.
212 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
213 handle to the source location. This would typically be an open
214 handle to a directory.
215 @param NewHandle A pointer to the location to return the opened handle for the new
217 @param FileName The Null-terminated string of the name of the file to be opened.
218 The file name may contain the following path modifiers: "\", ".",
220 @param OpenMode The mode to open the file. The only valid combinations that the
221 file may be opened with are: Read, Read/Write, or Create/Read/Write.
222 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
223 attribute bits for the newly created file.
225 @retval EFI_SUCCESS The file was opened.
226 @retval EFI_NOT_FOUND The specified file could not be found on the device.
227 @retval EFI_NO_MEDIA The device has no medium.
228 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
230 @retval EFI_DEVICE_ERROR The device reported an error.
231 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
232 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
233 when the media is write-protected.
234 @retval EFI_ACCESS_DENIED The service denied access to the file.
235 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
236 @retval EFI_VOLUME_FULL The volume is full.
241 FvSimpleFileSystemOpen (
242 IN EFI_FILE_PROTOCOL
*This
,
243 OUT EFI_FILE_PROTOCOL
**NewHandle
,
250 Closes a specified file handle.
252 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
255 @retval EFI_SUCCESS The file was closed.
260 FvSimpleFileSystemClose (
261 IN EFI_FILE_PROTOCOL
*This
265 Reads data from a file.
267 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
268 handle to read data from.
269 @param BufferSize On input, the size of the Buffer. On output, the amount of data
270 returned in Buffer. In both cases, the size is measured in bytes.
271 @param Buffer The buffer into which the data is read.
273 @retval EFI_SUCCESS Data was read.
274 @retval EFI_NO_MEDIA The device has no medium.
275 @retval EFI_DEVICE_ERROR The device reported an error.
276 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
277 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
278 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
279 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory
280 entry. BufferSize has been updated with the size
281 needed to complete the request.
286 FvSimpleFileSystemRead (
287 IN EFI_FILE_PROTOCOL
*This
,
288 IN OUT UINTN
*BufferSize
,
293 Writes data to a file.
295 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
296 handle to write data to.
297 @param BufferSize On input, the size of the Buffer. On output, the amount of data
298 actually written. In both cases, the size is measured in bytes.
299 @param Buffer The buffer of data to write.
301 @retval EFI_SUCCESS Data was written.
302 @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
303 @retval EFI_NO_MEDIA The device has no medium.
304 @retval EFI_DEVICE_ERROR The device reported an error.
305 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
306 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
307 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
308 @retval EFI_ACCESS_DENIED The file was opened read only.
309 @retval EFI_VOLUME_FULL The volume is full.
314 FvSimpleFileSystemWrite (
315 IN EFI_FILE_PROTOCOL
*This
,
316 IN OUT UINTN
*BufferSize
,
321 Returns a file's current position.
323 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
324 handle to get the current position on.
325 @param Position The address to return the file's current position value.
327 @retval EFI_SUCCESS The position was returned.
328 @retval EFI_UNSUPPORTED The request is not valid on open directories.
329 @retval EFI_DEVICE_ERROR An attempt was made to get the position from a deleted file.
334 FvSimpleFileSystemGetPosition (
335 IN EFI_FILE_PROTOCOL
*This
,
340 Sets a file's current position.
342 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
343 file handle to set the requested position on.
344 @param Position The byte position from the start of the file to set.
346 @retval EFI_SUCCESS The position was set.
347 @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open
349 @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted file.
354 FvSimpleFileSystemSetPosition (
355 IN EFI_FILE_PROTOCOL
*This
,
360 Flushes all modified data associated with a file to a device.
362 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
365 @retval EFI_SUCCESS The data was flushed.
366 @retval EFI_NO_MEDIA The device has no medium.
367 @retval EFI_DEVICE_ERROR The device reported an error.
368 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
369 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
370 @retval EFI_ACCESS_DENIED The file was opened read-only.
371 @retval EFI_VOLUME_FULL The volume is full.
376 FvSimpleFileSystemFlush (
377 IN EFI_FILE_PROTOCOL
*This
381 Close and delete the file handle.
383 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
384 handle to the file to delete.
386 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
387 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted.
392 FvSimpleFileSystemDelete (
393 IN EFI_FILE_PROTOCOL
*This
397 Returns information about a file.
399 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
400 handle the requested information is for.
401 @param InformationType The type identifier for the information being requested.
402 @param BufferSize On input, the size of Buffer. On output, the amount of data
403 returned in Buffer. In both cases, the size is measured in bytes.
404 @param Buffer A pointer to the data buffer to return. The buffer's type is
405 indicated by InformationType.
407 @retval EFI_SUCCESS The information was returned.
408 @retval EFI_UNSUPPORTED The InformationType is not known.
409 @retval EFI_NO_MEDIA The device has no medium.
410 @retval EFI_DEVICE_ERROR The device reported an error.
411 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
412 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
413 BufferSize has been updated with the size needed to complete
418 FvSimpleFileSystemGetInfo (
419 IN EFI_FILE_PROTOCOL
*This
,
420 IN EFI_GUID
*InformationType
,
421 IN OUT UINTN
*BufferSize
,
426 Sets information about a file.
428 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
429 handle the information is for.
430 @param InformationType The type identifier for the information being set.
431 @param BufferSize The size, in bytes, of Buffer.
432 @param Buffer A pointer to the data buffer to write. The buffer's type is
433 indicated by InformationType.
435 @retval EFI_SUCCESS The information was set.
436 @retval EFI_UNSUPPORTED The InformationType is not known.
437 @retval EFI_NO_MEDIA The device has no medium.
438 @retval EFI_DEVICE_ERROR The device reported an error.
439 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
440 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media is
442 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID
443 and the media is read only.
444 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID
445 and the media is read-only.
446 @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file to a
447 file that is already present.
448 @retval EFI_ACCESS_DENIED An attempt is being made to change the EFI_FILE_DIRECTORY
450 @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a directory.
451 @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file was opened
452 read-only and an attempt is being made to modify a field
453 other than Attribute.
454 @retval EFI_VOLUME_FULL The volume is full.
455 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type indicated
461 FvSimpleFileSystemSetInfo (
462 IN EFI_FILE_PROTOCOL
*This
,
463 IN EFI_GUID
*InformationType
,
469 Get the size of the buffer that will be returned by FvFsReadFile.
471 @param FvProtocol A pointer to the EFI_FIRMWARE_VOLUME2_PROTOCOL instance.
472 @param FvFileInfo A pointer to the FV_FILESYSTEM_FILE_INFO instance that is a struct
473 representing a file's info.
475 @retval EFI_SUCCESS The file size was gotten correctly.
476 @retval Others The file size wasn't gotten correctly.
481 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
,
482 IN OUT FV_FILESYSTEM_FILE_INFO
*FvFileInfo
486 Retrieves a Unicode string that is the user readable name of the driver.
488 This function retrieves the user readable name of a driver in the form of a
489 Unicode string. If the driver specified by This has a user readable name in
490 the language specified by Language, then a pointer to the driver name is
491 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
492 by This does not support the language specified by Language,
493 then EFI_UNSUPPORTED is returned.
495 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
496 EFI_COMPONENT_NAME_PROTOCOL instance.
498 @param Language[in] A pointer to a Null-terminated ASCII string
499 array indicating the language. This is the
500 language of the driver name that the caller is
501 requesting, and it must match one of the
502 languages specified in SupportedLanguages. The
503 number of languages supported by a driver is up
504 to the driver writer. Language is specified
505 in RFC 4646 or ISO 639-2 language code format.
507 @param DriverName[out] A pointer to the Unicode string to return.
508 This Unicode string is the name of the
509 driver specified by This in the language
510 specified by Language.
512 @retval EFI_SUCCESS The Unicode string for the Driver specified by
513 This and the language specified by Language was
514 returned in DriverName.
516 @retval EFI_INVALID_PARAMETER Language is NULL.
518 @retval EFI_INVALID_PARAMETER DriverName is NULL.
520 @retval EFI_UNSUPPORTED The driver specified by This does not support
521 the language specified by Language.
526 FvSimpleFileSystemComponentNameGetDriverName (
527 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
529 OUT CHAR16
**DriverName
533 Retrieves a Unicode string that is the user readable name of the controller
534 that is being managed by a driver.
536 This function retrieves the user readable name of the controller specified by
537 ControllerHandle and ChildHandle in the form of a Unicode string. If the
538 driver specified by This has a user readable name in the language specified by
539 Language, then a pointer to the controller name is returned in ControllerName,
540 and EFI_SUCCESS is returned. If the driver specified by This is not currently
541 managing the controller specified by ControllerHandle and ChildHandle,
542 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
543 support the language specified by Language, then EFI_UNSUPPORTED is returned.
545 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
546 EFI_COMPONENT_NAME_PROTOCOL instance.
548 @param ControllerHandle[in] The handle of a controller that the driver
549 specified by This is managing. This handle
550 specifies the controller whose name is to be
553 @param ChildHandle[in] The handle of the child controller to retrieve
554 the name of. This is an optional parameter that
555 may be NULL. It will be NULL for device
556 drivers. It will also be NULL for a bus drivers
557 that wish to retrieve the name of the bus
558 controller. It will not be NULL for a bus
559 driver that wishes to retrieve the name of a
562 @param Language[in] A pointer to a Null-terminated ASCII string
563 array indicating the language. This is the
564 language of the driver name that the caller is
565 requesting, and it must match one of the
566 languages specified in SupportedLanguages. The
567 number of languages supported by a driver is up
568 to the driver writer. Language is specified in
569 RFC 4646 or ISO 639-2 language code format.
571 @param ControllerName[out] A pointer to the Unicode string to return.
572 This Unicode string is the name of the
573 controller specified by ControllerHandle and
574 ChildHandle in the language specified by
575 Language from the point of view of the driver
578 @retval EFI_SUCCESS The Unicode string for the user readable name in
579 the language specified by Language for the
580 driver specified by This was returned in
583 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
585 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
588 @retval EFI_INVALID_PARAMETER Language is NULL.
590 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
592 @retval EFI_UNSUPPORTED The driver specified by This is not currently
593 managing the controller specified by
594 ControllerHandle and ChildHandle.
596 @retval EFI_UNSUPPORTED The driver specified by This does not support
597 the language specified by Language.
602 FvSimpleFileSystemComponentNameGetControllerName (
603 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
604 IN EFI_HANDLE ControllerHandle
,
605 IN EFI_HANDLE ChildHandle OPTIONAL
,
607 OUT CHAR16
**ControllerName
610 extern EFI_UNICODE_COLLATION_PROTOCOL
*mUnicodeCollation
;
611 extern EFI_FILE_PROTOCOL mFileSystemTemplate
;
612 extern EFI_COMPONENT_NAME_PROTOCOL gFvSimpleFileSystemComponentName
;
613 extern EFI_COMPONENT_NAME2_PROTOCOL gFvSimpleFileSystemComponentName2
;