1 /** 2 Based on Protocol/SimpleFileSystem.h, original notice: 3 4 SimpleFileSystem protocol as defined in the UEFI 2.0 specification. 5 6 The SimpleFileSystem protocol is the programmatic access to the FAT (12,16,32) 7 file system specified in UEFI 2.0. It can also be used to abstract a file 8 system other than FAT. 9 10 UEFI 2.0 can boot from any valid EFI image contained in a SimpleFileSystem. 11 12 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. 13 This program and the accompanying materials are licensed and made available under 14 the terms and conditions of the BSD License that accompanies this distribution. 15 The full text of the license may be found at 16 http://opensource.org/licenses/bsd-license.php. 17 18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 20 21 **/ 22 module uefi.protocols.simplefilesystem; 23 import uefi.base; 24 import uefi.base_type; 25 26 public: 27 extern (C): 28 enum EFI_GUID EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID = EFI_GUID(0x964e5b22, 29 0x6459, 0x11d2, [0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b]); 30 alias EFI_SIMPLE_FILE_SYSTEM_PROTOCOL = _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; 31 alias EFI_FILE_PROTOCOL = _EFI_FILE_PROTOCOL; 32 alias EFI_FILE_HANDLE = _EFI_FILE_PROTOCOL*; 33 /// Protocol GUID name defined in EFI1.1. 34 enum SIMPLE_FILE_SYSTEM_PROTOCOL = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; 35 /// Protocol name defined in EFI1.1. 36 alias EFI_FILE_IO_INTERFACE = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; 37 alias EFI_FILE = EFI_FILE_PROTOCOL; 38 /** 39 Open the root directory on a volume. 40 41 @param This A pointer to the volume to open the root directory. 42 @param Root A pointer to the location to return the opened file handle for the 43 root directory. 44 45 @retval EFI_SUCCESS The device was opened. 46 @retval EFI_UNSUPPORTED This volume does not support the requested file system type. 47 @retval EFI_NO_MEDIA The device has no medium. 48 @retval EFI_DEVICE_ERROR The device reported an error. 49 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 50 @retval EFI_ACCESS_DENIED The service denied access to the file. 51 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources. 52 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no 53 longer supported. Any existing file handles for this volume are 54 no longer valid. To access the files on the new medium, the 55 volume must be reopened with OpenVolume(). 56 57 **/ 58 alias EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME = EFI_STATUS function( 59 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* This, EFI_FILE_PROTOCOL** Root) @nogc nothrow; 60 enum EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION = 0x00010000; 61 /// Revision defined in EFI1.1 62 enum EFI_FILE_IO_INTERFACE_REVISION = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION; 63 struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL 64 { 65 /// 66 /// The version of the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. The version 67 /// specified by this specification is 0x00010000. All future revisions 68 /// must be backwards compatible. 69 /// 70 UINT64 Revision; 71 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME OpenVolume; 72 73 } 74 /** 75 Opens a new file relative to the source file's location. 76 77 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 78 handle to the source location. This would typically be an open 79 handle to a directory. 80 @param NewHandle A pointer to the location to return the opened handle for the new 81 file. 82 @param FileName The Null-terminated string of the name of the file to be opened. 83 The file name may contain the following path modifiers: "\", ".", 84 and "..". 85 @param OpenMode The mode to open the file. The only valid combinations that the 86 file may be opened with are: Read, Read/Write, or Create/Read/Write. 87 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the 88 attribute bits for the newly created file. 89 90 @retval EFI_SUCCESS The file was opened. 91 @retval EFI_NOT_FOUND The specified file could not be found on the device. 92 @retval EFI_NO_MEDIA The device has no medium. 93 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no 94 longer supported. 95 @retval EFI_DEVICE_ERROR The device reported an error. 96 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 97 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write 98 when the media is write-protected. 99 @retval EFI_ACCESS_DENIED The service denied access to the file. 100 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. 101 @retval EFI_VOLUME_FULL The volume is full. 102 103 **/ 104 alias EFI_FILE_OPEN = EFI_STATUS function(EFI_FILE_PROTOCOL* This, 105 EFI_FILE_PROTOCOL** NewHandle, CHAR16* FileName, UINT64 OpenMode, UINT64 Attributes) @nogc nothrow; 106 enum EFI_FILE_MODE_READ = 0x0000000000000001UL; 107 enum EFI_FILE_MODE_WRITE = 0x0000000000000002UL; 108 enum EFI_FILE_MODE_CREATE = 0x8000000000000000UL; 109 enum EFI_FILE_READ_ONLY = 0x0000000000000001UL; 110 enum EFI_FILE_HIDDEN = 0x0000000000000002UL; 111 enum EFI_FILE_SYSTEM = 0x0000000000000004UL; 112 enum EFI_FILE_RESERVED = 0x0000000000000008UL; 113 enum EFI_FILE_DIRECTORY = 0x0000000000000010UL; 114 enum EFI_FILE_ARCHIVE = 0x0000000000000020UL; 115 enum EFI_FILE_VALID_ATTR = 0x0000000000000037UL; 116 /** 117 Closes a specified file handle. 118 119 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 120 handle to close. 121 122 @retval EFI_SUCCESS The file was closed. 123 124 **/ 125 alias EFI_FILE_CLOSE = EFI_STATUS function(EFI_FILE_PROTOCOL* This) @nogc nothrow; 126 /** 127 Close and delete the file handle. 128 129 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the 130 handle to the file to delete. 131 132 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed. 133 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted. 134 135 **/ 136 alias EFI_FILE_DELETE = EFI_STATUS function(EFI_FILE_PROTOCOL* This) @nogc nothrow; 137 /** 138 Reads data from a file. 139 140 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 141 handle to read data from. 142 @param BufferSize On input, the size of the Buffer. On output, the amount of data 143 returned in Buffer. In both cases, the size is measured in bytes. 144 @param Buffer The buffer into which the data is read. 145 146 @retval EFI_SUCCESS Data was read. 147 @retval EFI_NO_MEDIA The device has no medium. 148 @retval EFI_DEVICE_ERROR The device reported an error. 149 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file. 150 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file. 151 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 152 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory 153 entry. BufferSize has been updated with the size 154 needed to complete the request. 155 156 **/ 157 alias EFI_FILE_READ = EFI_STATUS function(EFI_FILE_PROTOCOL* This, UINTN* BufferSize, 158 void* Buffer) @nogc nothrow; 159 /** 160 Writes data to a file. 161 162 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 163 handle to write data to. 164 @param BufferSize On input, the size of the Buffer. On output, the amount of data 165 actually written. In both cases, the size is measured in bytes. 166 @param Buffer The buffer of data to write. 167 168 @retval EFI_SUCCESS Data was written. 169 @retval EFI_UNSUPPORTED Writes to open directory files are not supported. 170 @retval EFI_NO_MEDIA The device has no medium. 171 @retval EFI_DEVICE_ERROR The device reported an error. 172 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file. 173 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 174 @retval EFI_WRITE_PROTECTED The file or medium is write-protected. 175 @retval EFI_ACCESS_DENIED The file was opened read only. 176 @retval EFI_VOLUME_FULL The volume is full. 177 178 **/ 179 alias EFI_FILE_WRITE = EFI_STATUS function(EFI_FILE_PROTOCOL* This, UINTN* BufferSize, 180 void* Buffer) @nogc nothrow; 181 /** 182 Sets a file's current position. 183 184 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the 185 file handle to set the requested position on. 186 @param Position The byte position from the start of the file to set. 187 188 @retval EFI_SUCCESS The position was set. 189 @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open 190 directories. 191 @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted file. 192 193 **/ 194 alias EFI_FILE_SET_POSITION = EFI_STATUS function(EFI_FILE_PROTOCOL* This, UINT64 Position) @nogc nothrow; 195 /** 196 Returns a file's current position. 197 198 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 199 handle to get the current position on. 200 @param Position The address to return the file's current position value. 201 202 @retval EFI_SUCCESS The position was returned. 203 @retval EFI_UNSUPPORTED The request is not valid on open directories. 204 @retval EFI_DEVICE_ERROR An attempt was made to get the position from a deleted file. 205 206 **/ 207 alias EFI_FILE_GET_POSITION = EFI_STATUS function(EFI_FILE_PROTOCOL* This, UINT64* Position) @nogc nothrow; 208 /** 209 Returns information about a file. 210 211 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 212 handle the requested information is for. 213 @param InformationType The type identifier for the information being requested. 214 @param BufferSize On input, the size of Buffer. On output, the amount of data 215 returned in Buffer. In both cases, the size is measured in bytes. 216 @param Buffer A pointer to the data buffer to return. The buffer's type is 217 indicated by InformationType. 218 219 @retval EFI_SUCCESS The information was returned. 220 @retval EFI_UNSUPPORTED The InformationType is not known. 221 @retval EFI_NO_MEDIA The device has no medium. 222 @retval EFI_DEVICE_ERROR The device reported an error. 223 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 224 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory entry. 225 BufferSize has been updated with the size needed to complete 226 the request. 227 **/ 228 alias EFI_FILE_GET_INFO = EFI_STATUS function(EFI_FILE_PROTOCOL* This, 229 EFI_GUID* InformationType, UINTN* BufferSize, void* Buffer) @nogc nothrow; 230 /** 231 Sets information about a file. 232 233 @param File A pointer to the EFI_FILE_PROTOCOL instance that is the file 234 handle the information is for. 235 @param InformationType The type identifier for the information being set. 236 @param BufferSize The size, in bytes, of Buffer. 237 @param Buffer A pointer to the data buffer to write. The buffer's type is 238 indicated by InformationType. 239 240 @retval EFI_SUCCESS The information was set. 241 @retval EFI_UNSUPPORTED The InformationType is not known. 242 @retval EFI_NO_MEDIA The device has no medium. 243 @retval EFI_DEVICE_ERROR The device reported an error. 244 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 245 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media is 246 read-only. 247 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID 248 and the media is read only. 249 @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID 250 and the media is read-only. 251 @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file to a 252 file that is already present. 253 @retval EFI_ACCESS_DENIED An attempt is being made to change the EFI_FILE_DIRECTORY 254 Attribute. 255 @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a directory. 256 @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file was opened 257 read-only and an attempt is being made to modify a field 258 other than Attribute. 259 @retval EFI_VOLUME_FULL The volume is full. 260 @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type indicated 261 by InformationType. 262 263 **/ 264 alias EFI_FILE_SET_INFO = EFI_STATUS function(EFI_FILE_PROTOCOL* This, 265 EFI_GUID* InformationType, UINTN BufferSize, void* Buffer) @nogc nothrow; 266 /** 267 Flushes all modified data associated with a file to a device. 268 269 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 270 handle to flush. 271 272 @retval EFI_SUCCESS The data was flushed. 273 @retval EFI_NO_MEDIA The device has no medium. 274 @retval EFI_DEVICE_ERROR The device reported an error. 275 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 276 @retval EFI_WRITE_PROTECTED The file or medium is write-protected. 277 @retval EFI_ACCESS_DENIED The file was opened read-only. 278 @retval EFI_VOLUME_FULL The volume is full. 279 280 **/ 281 alias EFI_FILE_FLUSH = EFI_STATUS function(EFI_FILE_PROTOCOL* This) @nogc nothrow; 282 struct EFI_FILE_IO_TOKEN 283 { 284 // 285 // If Event is NULL, then blocking I/O is performed. 286 // If Event is not NULL and non-blocking I/O is supported, then non-blocking I/O is performed, 287 // and Event will be signaled when the read request is completed. 288 // The caller must be prepared to handle the case where the callback associated with Event 289 // occurs before the original asynchronous I/O request call returns. 290 // 291 EFI_EVENT Event; 292 // 293 // Defines whether or not the signaled event encountered an error. 294 // 295 EFI_STATUS Status; 296 // 297 // For OpenEx(): Not Used, ignored. 298 // For ReadEx(): On input, the size of the Buffer. On output, the amount of data returned in Buffer. 299 // In both cases, the size is measured in bytes. 300 // For WriteEx(): On input, the size of the Buffer. On output, the amount of data actually written. 301 // In both cases, the size is measured in bytes. 302 // For FlushEx(): Not used, ignored. 303 // 304 UINTN BufferSize; 305 // 306 // For OpenEx(): Not Used, ignored. 307 // For ReadEx(): The buffer into which the data is read. 308 // For WriteEx(): The buffer of data to write. 309 // For FlushEx(): Not Used, ignored. 310 // 311 VOID* Buffer; 312 } 313 /** 314 Opens a new file relative to the source directory's location. 315 316 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 317 handle to the source location. 318 @param NewHandle A pointer to the location to return the opened handle for the new 319 file. 320 @param FileName The Null-terminated string of the name of the file to be opened. 321 The file name may contain the following path modifiers: "\", ".", 322 and "..". 323 @param OpenMode The mode to open the file. The only valid combinations that the 324 file may be opened with are: Read, Read/Write, or Create/Read/Write. 325 @param Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the 326 attribute bits for the newly created file. 327 @param Token A pointer to the token associated with the transaction. 328 329 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully. 330 If Event is not NULL (asynchronous I/O): The request was successfully 331 queued for processing. 332 @retval EFI_NOT_FOUND The specified file could not be found on the device. 333 @retval EFI_NO_MEDIA The device has no medium. 334 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no 335 longer supported. 336 @retval EFI_DEVICE_ERROR The device reported an error. 337 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 338 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write 339 when the media is write-protected. 340 @retval EFI_ACCESS_DENIED The service denied access to the file. 341 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. 342 @retval EFI_VOLUME_FULL The volume is full. 343 344 **/ 345 alias EFI_FILE_OPEN_EX = EFI_STATUS function(EFI_FILE_PROTOCOL* This, 346 EFI_FILE_PROTOCOL** NewHandle, CHAR16* FileName, UINT64 OpenMode, 347 UINT64 Attributes, EFI_FILE_IO_TOKEN* Token) @nogc nothrow; 348 /** 349 Reads data from a file. 350 351 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to read data from. 352 @param Token A pointer to the token associated with the transaction. 353 354 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully. 355 If Event is not NULL (asynchronous I/O): The request was successfully 356 queued for processing. 357 @retval EFI_NO_MEDIA The device has no medium. 358 @retval EFI_DEVICE_ERROR The device reported an error. 359 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file. 360 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file. 361 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 362 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources. 363 **/ 364 alias EFI_FILE_READ_EX = EFI_STATUS function(EFI_FILE_PROTOCOL* This, EFI_FILE_IO_TOKEN* Token) @nogc nothrow; 365 /** 366 Writes data to a file. 367 368 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to write data to. 369 @param Token A pointer to the token associated with the transaction. 370 371 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully. 372 If Event is not NULL (asynchronous I/O): The request was successfully 373 queued for processing. 374 @retval EFI_UNSUPPORTED Writes to open directory files are not supported. 375 @retval EFI_NO_MEDIA The device has no medium. 376 @retval EFI_DEVICE_ERROR The device reported an error. 377 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file. 378 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 379 @retval EFI_WRITE_PROTECTED The file or medium is write-protected. 380 @retval EFI_ACCESS_DENIED The file was opened read only. 381 @retval EFI_VOLUME_FULL The volume is full. 382 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources. 383 **/ 384 alias EFI_FILE_WRITE_EX = EFI_STATUS function(EFI_FILE_PROTOCOL* This, EFI_FILE_IO_TOKEN* Token) @nogc nothrow; 385 /** 386 Flushes all modified data associated with a file to a device. 387 388 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the file 389 handle to flush. 390 @param Token A pointer to the token associated with the transaction. 391 392 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read successfully. 393 If Event is not NULL (asynchronous I/O): The request was successfully 394 queued for processing. 395 @retval EFI_NO_MEDIA The device has no medium. 396 @retval EFI_DEVICE_ERROR The device reported an error. 397 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. 398 @retval EFI_WRITE_PROTECTED The file or medium is write-protected. 399 @retval EFI_ACCESS_DENIED The file was opened read-only. 400 @retval EFI_VOLUME_FULL The volume is full. 401 @retval EFI_OUT_OF_RESOURCES Unable to queue the request due to lack of resources. 402 403 **/ 404 alias EFI_FILE_FLUSH_EX = EFI_STATUS function(EFI_FILE_PROTOCOL* This, EFI_FILE_IO_TOKEN* Token) @nogc nothrow; 405 enum EFI_FILE_PROTOCOL_REVISION = 0x00010000; 406 enum EFI_FILE_PROTOCOL_REVISION2 = 0x00020000; 407 enum EFI_FILE_PROTOCOL_LATEST_REVISION = EFI_FILE_PROTOCOL_REVISION2; 408 enum EFI_FILE_REVISION = EFI_FILE_PROTOCOL_REVISION; 409 /// The EFI_FILE_PROTOCOL provides file IO access to supported file systems. 410 /// An EFI_FILE_PROTOCOL provides access to a file's or directory's contents, 411 /// and is also a reference to a location in the directory tree of the file system 412 /// in which the file resides. With any given file handle, other files may be opened 413 /// relative to this file's location, yielding new file handles. 414 struct _EFI_FILE_PROTOCOL 415 { 416 /// 417 /// The version of the EFI_FILE_PROTOCOL interface. The version specified 418 /// by this specification is EFI_FILE_PROTOCOL_LATEST_REVISION. 419 /// Future versions are required to be backward compatible to version 1.0. 420 /// 421 UINT64 Revision; 422 EFI_FILE_OPEN Open; 423 EFI_FILE_CLOSE Close; 424 EFI_FILE_DELETE Delete; 425 EFI_FILE_READ Read; 426 EFI_FILE_WRITE Write; 427 EFI_FILE_GET_POSITION GetPosition; 428 EFI_FILE_SET_POSITION SetPosition; 429 EFI_FILE_GET_INFO GetInfo; 430 EFI_FILE_SET_INFO SetInfo; 431 EFI_FILE_FLUSH Flush; 432 EFI_FILE_OPEN_EX OpenEx; 433 EFI_FILE_READ_EX ReadEx; 434 EFI_FILE_WRITE_EX WriteEx; 435 EFI_FILE_FLUSH_EX FlushEx; 436 437 }