2 SimpleFileSystem protocol as defined in the UEFI 2.0 specification.
4 The SimpleFileSystem protocol is the programmatic access to the FAT (12,16,32)
5 file system specified in UEFI 2.0. It can also be used to abstract a file
8 UEFI 2.0 can boot from any valid EFI image contained in a SimpleFileSystem.
10 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #ifndef __SIMPLE_FILE_SYSTEM_H__
16 #define __SIMPLE_FILE_SYSTEM_H__
18 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
20 0x964e5b22, 0x6459, 0x11d2, {0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
23 typedef struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
;
25 typedef struct _EFI_FILE_PROTOCOL EFI_FILE_PROTOCOL
;
26 typedef struct _EFI_FILE_PROTOCOL
*EFI_FILE_HANDLE
;
29 /// Protocol GUID name defined in EFI1.1.
31 #define SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
34 /// Protocol name defined in EFI1.1.
36 typedef EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_FILE_IO_INTERFACE
;
37 typedef EFI_FILE_PROTOCOL EFI_FILE
;
40 Open the root directory on a volume.
42 @param This A pointer to the volume to open the root directory.
43 @param Root A pointer to the location to return the opened file handle for the
46 @retval EFI_SUCCESS The device was opened.
47 @retval EFI_UNSUPPORTED This volume does not support the requested file system type.
48 @retval EFI_NO_MEDIA The device has no medium.
49 @retval EFI_DEVICE_ERROR The device reported an error.
50 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
51 @retval EFI_ACCESS_DENIED The service denied access to the file.
52 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
53 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
54 longer supported. Any existing file handles for this volume are
55 no longer valid. To access the files on the new medium, the
56 volume must be reopened with OpenVolume().
61 (EFIAPI
*EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME
)(
62 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
63 OUT EFI_FILE_PROTOCOL
**Root
66 #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
69 /// Revision defined in EFI1.1
71 #define EFI_FILE_IO_INTERFACE_REVISION EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
73 struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
{
75 /// The version of the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. The version
76 /// specified by this specification is 0x00010000. All future revisions
77 /// must be backwards compatible.
80 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume
;
84 Opens a new file relative to the source file's location.
86 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
87 handle to the source location. This would typically be an open
88 handle to a directory.
89 @param NewHandle A pointer to the location to return the opened handle for the new
91 @param FileName The Null-terminated string of the name of the file to be opened.
92 The file name may contain the following path modifiers: "\", ".",
94 @param OpenMode The mode to open the file. The only valid combinations that the
95 file may be opened with are: Read, Read/Write, or Create/Read/Write.
96 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
97 attribute bits for the newly created file.
99 @retval EFI_SUCCESS The file was opened.
100 @retval EFI_NOT_FOUND The specified file could not be found on the device.
101 @retval EFI_NO_MEDIA The device has no medium.
102 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
104 @retval EFI_DEVICE_ERROR The device reported an error.
105 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
106 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
107 when the media is write-protected.
108 @retval EFI_ACCESS_DENIED The service denied access to the file.
109 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
110 @retval EFI_VOLUME_FULL The volume is full.
115 (EFIAPI
*EFI_FILE_OPEN
)(
116 IN EFI_FILE_PROTOCOL
*This
,
117 OUT EFI_FILE_PROTOCOL
**NewHandle
,
126 #define EFI_FILE_MODE_READ 0x0000000000000001ULL
127 #define EFI_FILE_MODE_WRITE 0x0000000000000002ULL
128 #define EFI_FILE_MODE_CREATE 0x8000000000000000ULL
133 #define EFI_FILE_READ_ONLY 0x0000000000000001ULL
134 #define EFI_FILE_HIDDEN 0x0000000000000002ULL
135 #define EFI_FILE_SYSTEM 0x0000000000000004ULL
136 #define EFI_FILE_RESERVED 0x0000000000000008ULL
137 #define EFI_FILE_DIRECTORY 0x0000000000000010ULL
138 #define EFI_FILE_ARCHIVE 0x0000000000000020ULL
139 #define EFI_FILE_VALID_ATTR 0x0000000000000037ULL
142 Closes a specified file handle.
144 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
147 @retval EFI_SUCCESS The file was closed.
152 (EFIAPI
*EFI_FILE_CLOSE
)(
153 IN EFI_FILE_PROTOCOL
*This
157 Close and delete the file handle.
159 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
160 handle to the file to delete.
162 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
163 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted.
168 (EFIAPI
*EFI_FILE_DELETE
)(
169 IN EFI_FILE_PROTOCOL
*This
173 Reads data from a file.
175 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
176 handle to read data from.
177 @param BufferSize On input, the size of the Buffer. On output, the amount of data
178 returned in Buffer. In both cases, the size is measured in bytes.
179 @param Buffer The buffer into which the data is read.
181 @retval EFI_SUCCESS Data was read.
182 @retval EFI_NO_MEDIA The device has no medium.
183 @retval EFI_DEVICE_ERROR The device reported an error.
184 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
185 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
186 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
187 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory
188 entry. BufferSize has been updated with the size
189 needed to complete the request.
194 (EFIAPI
*EFI_FILE_READ
)(
195 IN EFI_FILE_PROTOCOL
*This
,
196 IN OUT UINTN
*BufferSize
,
201 Writes data to a file.
203 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
204 handle to write data to.
205 @param BufferSize On input, the size of the Buffer. On output, the amount of data
206 actually written. In both cases, the size is measured in bytes.
207 @param Buffer The buffer of data to write.
209 @retval EFI_SUCCESS Data was written.
210 @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
211 @retval EFI_NO_MEDIA The device has no medium.
212 @retval EFI_DEVICE_ERROR The device reported an error.
213 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
214 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
215 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
216 @retval EFI_ACCESS_DENIED The file was opened read only.
217 @retval EFI_VOLUME_FULL The volume is full.
222 (EFIAPI
*EFI_FILE_WRITE
)(
223 IN EFI_FILE_PROTOCOL
*This
,
224 IN OUT UINTN
*BufferSize
,
229 Sets a file's current position.
231 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
232 file handle to set the requested position on.
233 @param Position The byte position from the start of the file to set.
235 @retval EFI_SUCCESS The position was set.
236 @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open
238 @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted file.
243 (EFIAPI
*EFI_FILE_SET_POSITION
)(
244 IN EFI_FILE_PROTOCOL
*This
,
249 Returns a file's current position.
251 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
252 handle to get the current position on.
253 @param Position The address to return the file's current position value.
255 @retval EFI_SUCCESS The position was returned.
256 @retval EFI_UNSUPPORTED The request is not valid on open directories.
257 @retval EFI_DEVICE_ERROR An attempt was made to get the position from a deleted file.
262 (EFIAPI
*EFI_FILE_GET_POSITION
)(
263 IN EFI_FILE_PROTOCOL
*This
,
268 Returns information about a file.
270 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
271 handle the requested information is for.
272 @param InformationType The type identifier for the information being requested.
273 @param BufferSize On input, the size of Buffer. On output, the amount of data
274 returned in Buffer. In both cases, the size is measured in bytes.
275 @param Buffer A pointer to the data buffer to return. The buffer's type is
276 indicated by InformationType.
278 @retval EFI_SUCCESS The information was returned.
279 @retval EFI_UNSUPPORTED The InformationType is not known.
280 @retval EFI_NO_MEDIA The device has no medium.
281 @retval EFI_DEVICE_ERROR The device reported an error.
282 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
283 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry.
284 BufferSize has been updated with the size needed to complete
289 (EFIAPI
*EFI_FILE_GET_INFO
)(
290 IN EFI_FILE_PROTOCOL
*This
,
291 IN EFI_GUID
*InformationType
,
292 IN OUT UINTN
*BufferSize
,
297 Sets information about a file.
299 @param File A pointer to the EFI_FILE_PROTOCOL instance that is the file
300 handle the information is for.
301 @param InformationType The type identifier for the information being set.
302 @param BufferSize The size, in bytes, of Buffer.
303 @param Buffer A pointer to the data buffer to write. The buffer's type is
304 indicated by InformationType.
306 @retval EFI_SUCCESS The information was set.
307 @retval EFI_UNSUPPORTED The InformationType is not known.
308 @retval EFI_NO_MEDIA The device has no medium.
309 @retval EFI_DEVICE_ERROR The device reported an error.
310 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
311 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media is
313 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID
314 and the media is read only.
315 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID
316 and the media is read-only.
317 @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file to a
318 file that is already present.
319 @retval EFI_ACCESS_DENIED An attempt is being made to change the EFI_FILE_DIRECTORY
321 @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a directory.
322 @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file was opened
323 read-only and an attempt is being made to modify a field
324 other than Attribute.
325 @retval EFI_VOLUME_FULL The volume is full.
326 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type indicated
332 (EFIAPI
*EFI_FILE_SET_INFO
)(
333 IN EFI_FILE_PROTOCOL
*This
,
334 IN EFI_GUID
*InformationType
,
340 Flushes all modified data associated with a file to a device.
342 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
345 @retval EFI_SUCCESS The data was flushed.
346 @retval EFI_NO_MEDIA The device has no medium.
347 @retval EFI_DEVICE_ERROR The device reported an error.
348 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
349 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
350 @retval EFI_ACCESS_DENIED The file was opened read-only.
351 @retval EFI_VOLUME_FULL The volume is full.
356 (EFIAPI
*EFI_FILE_FLUSH
)(
357 IN EFI_FILE_PROTOCOL
*This
362 // If Event is NULL, then blocking I/O is performed.
363 // If Event is not NULL and non-blocking I/O is supported, then non-blocking I/O is performed,
364 // and Event will be signaled when the read request is completed.
365 // The caller must be prepared to handle the case where the callback associated with Event
366 // occurs before the original asynchronous I/O request call returns.
371 // Defines whether or not the signaled event encountered an error.
376 // For OpenEx(): Not Used, ignored.
377 // For ReadEx(): On input, the size of the Buffer. On output, the amount of data returned in Buffer.
378 // In both cases, the size is measured in bytes.
379 // For WriteEx(): On input, the size of the Buffer. On output, the amount of data actually written.
380 // In both cases, the size is measured in bytes.
381 // For FlushEx(): Not used, ignored.
386 // For OpenEx(): Not Used, ignored.
387 // For ReadEx(): The buffer into which the data is read.
388 // For WriteEx(): The buffer of data to write.
389 // For FlushEx(): Not Used, ignored.
395 Opens a new file relative to the source directory's location.
397 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
398 handle to the source location.
399 @param NewHandle A pointer to the location to return the opened handle for the new
401 @param FileName The Null-terminated string of the name of the file to be opened.
402 The file name may contain the following path modifiers: "\", ".",
404 @param OpenMode The mode to open the file. The only valid combinations that the
405 file may be opened with are: Read, Read/Write, or Create/Read/Write.
406 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
407 attribute bits for the newly created file.
408 @param Token A pointer to the token associated with the transaction.
410 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully.
411 If Event is not NULL (asynchronous I/O): The request was successfully
412 queued for processing.
413 @retval EFI_NOT_FOUND The specified file could not be found on the device.
414 @retval EFI_NO_MEDIA The device has no medium.
415 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
417 @retval EFI_DEVICE_ERROR The device reported an error.
418 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
419 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
420 when the media is write-protected.
421 @retval EFI_ACCESS_DENIED The service denied access to the file.
422 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
423 @retval EFI_VOLUME_FULL The volume is full.
428 (EFIAPI
*EFI_FILE_OPEN_EX
)(
429 IN EFI_FILE_PROTOCOL
*This
,
430 OUT EFI_FILE_PROTOCOL
**NewHandle
,
433 IN UINT64 Attributes
,
434 IN OUT EFI_FILE_IO_TOKEN
*Token
438 Reads data from a file.
440 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to read data from.
441 @param Token A pointer to the token associated with the transaction.
443 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully.
444 If Event is not NULL (asynchronous I/O): The request was successfully
445 queued for processing.
446 @retval EFI_NO_MEDIA The device has no medium.
447 @retval EFI_DEVICE_ERROR The device reported an error.
448 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
449 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
450 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
451 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources.
455 (EFIAPI
*EFI_FILE_READ_EX
)(
456 IN EFI_FILE_PROTOCOL
*This
,
457 IN OUT EFI_FILE_IO_TOKEN
*Token
461 Writes data to a file.
463 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to write data to.
464 @param Token A pointer to the token associated with the transaction.
466 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully.
467 If Event is not NULL (asynchronous I/O): The request was successfully
468 queued for processing.
469 @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
470 @retval EFI_NO_MEDIA The device has no medium.
471 @retval EFI_DEVICE_ERROR The device reported an error.
472 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
473 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
474 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
475 @retval EFI_ACCESS_DENIED The file was opened read only.
476 @retval EFI_VOLUME_FULL The volume is full.
477 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources.
481 (EFIAPI
*EFI_FILE_WRITE_EX
)(
482 IN EFI_FILE_PROTOCOL
*This
,
483 IN OUT EFI_FILE_IO_TOKEN
*Token
487 Flushes all modified data associated with a file to a device.
489 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file
491 @param Token A pointer to the token associated with the transaction.
493 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully.
494 If Event is not NULL (asynchronous I/O): The request was successfully
495 queued for processing.
496 @retval EFI_NO_MEDIA The device has no medium.
497 @retval EFI_DEVICE_ERROR The device reported an error.
498 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
499 @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
500 @retval EFI_ACCESS_DENIED The file was opened read-only.
501 @retval EFI_VOLUME_FULL The volume is full.
502 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources.
507 (EFIAPI
*EFI_FILE_FLUSH_EX
)(
508 IN EFI_FILE_PROTOCOL
*This
,
509 IN OUT EFI_FILE_IO_TOKEN
*Token
512 #define EFI_FILE_PROTOCOL_REVISION 0x00010000
513 #define EFI_FILE_PROTOCOL_REVISION2 0x00020000
514 #define EFI_FILE_PROTOCOL_LATEST_REVISION EFI_FILE_PROTOCOL_REVISION2
517 // Revision defined in EFI1.1.
519 #define EFI_FILE_REVISION EFI_FILE_PROTOCOL_REVISION
522 /// The EFI_FILE_PROTOCOL provides file IO access to supported file systems.
523 /// An EFI_FILE_PROTOCOL provides access to a file's or directory's contents,
524 /// and is also a reference to a location in the directory tree of the file system
525 /// in which the file resides. With any given file handle, other files may be opened
526 /// relative to this file's location, yielding new file handles.
528 struct _EFI_FILE_PROTOCOL
{
530 /// The version of the EFI_FILE_PROTOCOL interface. The version specified
531 /// by this specification is EFI_FILE_PROTOCOL_LATEST_REVISION.
532 /// Future versions are required to be backward compatible to version 1.0.
536 EFI_FILE_CLOSE Close
;
537 EFI_FILE_DELETE Delete
;
539 EFI_FILE_WRITE Write
;
540 EFI_FILE_GET_POSITION GetPosition
;
541 EFI_FILE_SET_POSITION SetPosition
;
542 EFI_FILE_GET_INFO GetInfo
;
543 EFI_FILE_SET_INFO SetInfo
;
544 EFI_FILE_FLUSH Flush
;
545 EFI_FILE_OPEN_EX OpenEx
;
546 EFI_FILE_READ_EX ReadEx
;
547 EFI_FILE_WRITE_EX WriteEx
;
548 EFI_FILE_FLUSH_EX FlushEx
;
551 extern EFI_GUID gEfiSimpleFileSystemProtocolGuid
;