]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/FileHandleLib.h
MdeModulePkg, MdePkg, NetworkPkg, OvmfPkg, PerformancePkg, ShellPkg: Library Migration.
[mirror_edk2.git] / MdePkg / Include / Library / FileHandleLib.h
diff --git a/MdePkg/Include/Library/FileHandleLib.h b/MdePkg/Include/Library/FileHandleLib.h
new file mode 100644 (file)
index 0000000..123cc8c
--- /dev/null
@@ -0,0 +1,498 @@
+/** @file\r
+  Provides interface to EFI_FILE_HANDLE functionality.\r
+\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _FILE_HANDLE_LIBRARY_HEADER_\r
+#define _FILE_HANDLE_LIBRARY_HEADER_\r
+\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+/// The tag for use in identifying UNICODE files.\r
+/// If the file is UNICODE, the first 16 bits of the file will equal this value.\r
+extern CONST UINT16 gUnicodeFileTag;\r
+\r
+/**\r
+  This function retrieves information about the file for the handle\r
+  specified and stores it in the allocated pool memory.\r
+\r
+  This function allocates a buffer to store the file's information. It is the\r
+  caller's responsibility to free the buffer.\r
+\r
+  @param[in] FileHandle         The file handle of the file for which information is\r
+                                being requested.\r
+\r
+  @retval NULL                  Information could not be retrieved.\r
+  @retval !NULL                 The information about the file.\r
+**/\r
+EFI_FILE_INFO*\r
+EFIAPI\r
+FileHandleGetInfo (\r
+  IN EFI_FILE_HANDLE            FileHandle\r
+  );\r
+\r
+/**\r
+  This function sets the information about the file for the opened handle\r
+  specified.\r
+\r
+  @param[in]  FileHandle        The file handle of the file for which information\r
+                                is being set.\r
+\r
+  @param[in]  FileInfo          The information to set.\r
+\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
+  @retval EFI_UNSUPPORTED       The FileHandle does not support FileInfo.\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleSetInfo (\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  IN CONST EFI_FILE_INFO        *FileInfo\r
+  );\r
+\r
+/**\r
+  This function reads information from an opened file.\r
+\r
+  If FileHandle is not a directory, the function reads the requested number of\r
+  bytes from the file at the file's current position and returns them in Buffer.\r
+  If the read goes beyond the end of the file, the read length is truncated to the\r
+  end of the file. The file's current position is increased by the number of bytes\r
+  returned.  If FileHandle is a directory, the function reads the directory entry\r
+  at the file's current position and returns the entry in Buffer. If the Buffer\r
+  is not large enough to hold the current directory entry, then\r
+  EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.\r
+  BufferSize is set to be the size of the buffer needed to read the entry. On\r
+  success, the current position is updated to the next directory entry. If there\r
+  are no more directory entries, the read returns a zero-length buffer.\r
+  EFI_FILE_INFO is the structure returned as the directory entry.\r
+\r
+  @param[in] FileHandle          The opened file handle.\r
+  @param[in, out] BufferSize     On input, the size of buffer in bytes.  On return,\r
+                                 the number of bytes written.\r
+  @param[out] Buffer             The buffer to put read data into.\r
+\r
+  @retval EFI_SUCCESS         Data was read.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
+                                size.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleRead(\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  IN OUT UINTN                  *BufferSize,\r
+  OUT VOID                      *Buffer\r
+  );\r
+\r
+/**\r
+  Write data to a file.\r
+\r
+  This function writes the specified number of bytes to the file at the current\r
+  file position. The current file position is advanced the actual number of bytes\r
+  written, which is returned in BufferSize. Partial writes only occur when there\r
+  has been a data error during the write attempt (such as "volume space full").\r
+  The file is automatically grown to hold the data if required. Direct writes to\r
+  opened directories are not supported.\r
+\r
+  @param[in] FileHandle          The opened file for writing.\r
+  @param[in, out] BufferSize     On input, the number of bytes in Buffer.  On output,\r
+                                 the number of bytes written.\r
+  @param[in] Buffer              The buffer containing data to write is stored.\r
+\r
+  @retval EFI_SUCCESS         Data was written.\r
+  @retval EFI_UNSUPPORTED       Writes to an open directory are not supported.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED The device is write-protected.\r
+  @retval EFI_ACCESS_DENIED The file was opened for read only.\r
+  @retval EFI_VOLUME_FULL The volume is full.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleWrite(\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  IN OUT UINTN                  *BufferSize,\r
+  IN VOID                       *Buffer\r
+  );\r
+\r
+/**\r
+  Close an open file handle.\r
+\r
+  This function closes a specified file handle. All "dirty" cached file data is\r
+  flushed to the device, and the file is closed. In all cases the handle is\r
+  closed.\r
+\r
+  @param[in] FileHandle           The file handle to close.\r
+\r
+  @retval EFI_SUCCESS             The file handle was closed successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleClose (\r
+  IN EFI_FILE_HANDLE            FileHandle\r
+  );\r
+\r
+/**\r
+  Delete a file and close the handle.\r
+\r
+  This function closes and deletes a file. In all cases the file handle is closed.\r
+  If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
+  returned, but the handle is still closed.\r
+\r
+  @param[in] FileHandle             The file handle to delete.\r
+\r
+  @retval EFI_SUCCESS               The file was closed successfully.\r
+  @retval EFI_WARN_DELETE_FAILURE   The handle was closed, but the file was not\r
+                                    deleted.\r
+  @retval INVALID_PARAMETER         One of the parameters has an invalid value.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleDelete (\r
+  IN EFI_FILE_HANDLE    FileHandle\r
+  );\r
+\r
+/**\r
+  Set the current position in a file.\r
+\r
+  This function sets the current file position for the handle to the position\r
+  supplied. With the exception of moving to position 0xFFFFFFFFFFFFFFFF, only\r
+  absolute positioning is supported, and moving past the end of the file is\r
+  allowed (a subsequent write would grow the file). Moving to position\r
+  0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
+  If FileHandle is a directory, the only position that may be set is zero. This\r
+  has the effect of starting the read process of the directory entries over again.\r
+\r
+  @param[in] FileHandle         The file handle on which the position is being set.\r
+  @param[in] Position           The byte position from the begining of the file.\r
+\r
+  @retval EFI_SUCCESS           The operation completed sucessfully.\r
+  @retval EFI_UNSUPPORTED       The request for non-zero is not valid on\r
+                                directories.\r
+  @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleSetPosition (\r
+  IN EFI_FILE_HANDLE    FileHandle,\r
+  IN UINT64             Position\r
+  );\r
+\r
+/**\r
+  Gets a file's current position.\r
+\r
+  This function retrieves the current file position for the file handle. For\r
+  directories, the current file position has no meaning outside of the file\r
+  system driver. As such, the operation is not supported. An error is returned\r
+  if FileHandle is a directory.\r
+\r
+  @param[in] FileHandle         The open file handle on which to get the position.\r
+  @param[out] Position          The byte position from begining of file.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       The request is not valid on directories.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleGetPosition (\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  OUT UINT64                    *Position\r
+  );\r
+/**\r
+  Flushes data on a file.\r
+\r
+  This function flushes all modified data associated with a file to a device.\r
+\r
+  @param[in] FileHandle         The file handle on which to flush data.\r
+\r
+  @retval EFI_SUCCESS           The data was flushed.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened for read only.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleFlush (\r
+  IN EFI_FILE_HANDLE            FileHandle\r
+  );\r
+\r
+/**\r
+  Function to determine if a given handle is a directory handle.\r
+\r
+  If DirHandle is NULL, then ASSERT().\r
+\r
+  Open the file information on the DirHandle, and verify that the Attribute\r
+  includes EFI_FILE_DIRECTORY bit set.\r
+\r
+  @param[in] DirHandle          The handle to open the file.\r
+\r
+  @retval EFI_SUCCESS           DirHandle is a directory.\r
+  @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available.\r
+  @retval EFI_NOT_FOUND         DirHandle is not a directory.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleIsDirectory (\r
+  IN EFI_FILE_HANDLE            DirHandle\r
+  );\r
+\r
+/** Retrieve first entry from a directory.\r
+\r
+  This function takes an open directory handle and gets information from the\r
+  first entry in the directory.  A buffer is allocated to contain\r
+  the information and a pointer to the buffer is returned in *Buffer.  The\r
+  caller can use FileHandleFindNextFile() to get subsequent directory entries.\r
+\r
+  The buffer will be freed by FileHandleFindNextFile() when the last directory\r
+  entry is read.  Otherwise, the caller must free the buffer, using FreePool,\r
+  when finished with it.\r
+\r
+  @param[in]  DirHandle         The file handle of the directory to search.\r
+  @param[out] Buffer            The pointer to pointer to buffer for file's information.\r
+\r
+  @retval EFI_SUCCESS           Found the first file.\r
+  @retval EFI_NOT_FOUND         Cannot find the directory.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @return Others                The status of FileHandleGetInfo, FileHandleSetPosition,\r
+                                or FileHandleRead.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleFindFirstFile (\r
+  IN EFI_FILE_HANDLE            DirHandle,\r
+  OUT EFI_FILE_INFO             **Buffer\r
+  );\r
+\r
+/** Retrieve next entries from a directory.\r
+\r
+  To use this function, the caller must first call the FileHandleFindFirstFile()\r
+  function to get the first directory entry.  Subsequent directory entries are\r
+  retrieved by using the FileHandleFindNextFile() function.  This function can\r
+  be called several times to get each entry from the directory.  If the call of\r
+  FileHandleFindNextFile() retrieved the last directory entry, the next call of\r
+  this function will set *NoFile to TRUE and free the buffer.\r
+\r
+  @param[in]  DirHandle         The file handle of the directory.\r
+  @param[out] Buffer            The pointer to buffer for file's information.\r
+  @param[out] NoFile            The pointer to boolean when last file is found.\r
+\r
+  @retval EFI_SUCCESS           Found the next file, or reached last file.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleFindNextFile(\r
+  IN EFI_FILE_HANDLE             DirHandle,\r
+  OUT EFI_FILE_INFO              *Buffer,\r
+  OUT BOOLEAN                    *NoFile\r
+  );\r
+\r
+/**\r
+  Retrieve the size of a file.\r
+\r
+  If FileHandle is NULL then ASSERT().\r
+  If Size is NULL then ASSERT().\r
+\r
+  This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
+  data.\r
+\r
+  @param[in] FileHandle         The file handle from which size is retrieved.\r
+  @param[out] Size              The pointer to size.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR      Cannot access the file.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleGetSize (\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  OUT UINT64                    *Size\r
+  );\r
+\r
+/**\r
+  Set the size of a file.\r
+\r
+  If FileHandle is NULL then ASSERT().\r
+\r
+  This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
+  data.\r
+\r
+  @param[in] FileHandle         The file handle whose size is to be changed.\r
+  @param[in] Size               The new size.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR      Cannot access the file.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleSetSize (\r
+  IN EFI_FILE_HANDLE            FileHandle,\r
+  IN UINT64                     Size\r
+  );\r
+\r
+/**\r
+  Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
+  directory 'stack'.\r
+\r
+  @param[in] Handle             Handle to the Directory or File to create path to.\r
+  @param[out] FullFileName      Pointer to pointer to generated full file name.  It\r
+                                is the responsibility of the caller to free this memory\r
+                                with a call to FreePool().\r
+  @retval EFI_SUCCESS           The operation was successful and FullFileName is valid.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
+  @retval EFI_OUT_OF_MEMORY     A memory allocation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleGetFileName (\r
+  IN CONST EFI_FILE_HANDLE      Handle,\r
+  OUT CHAR16                    **FullFileName\r
+  );\r
+\r
+/**\r
+  Function to read a single line (up to but not including the \n) from a file.\r
+\r
+  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
+  maintained and not changed for all operations with the same file.\r
+\r
+  @param[in]       Handle        FileHandle to read from.\r
+  @param[in, out]  Buffer        The pointer to buffer to read into.\r
+  @param[in, out]  Size          The pointer to number of bytes in Buffer.\r
+  @param[in]       Truncate      If the buffer is large enough, this has no effect.\r
+                                 If the buffer is is too small and Truncate is TRUE,\r
+                                 the line will be truncated.\r
+                                 If the buffer is is too small and Truncate is FALSE,\r
+                                 then no read will occur.\r
+\r
+  @param[in, out]  Ascii         Boolean value for indicating whether the file is\r
+                                 Ascii (TRUE) or UCS2 (FALSE).\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
+                                Buffer.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER Size was NULL.\r
+  @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
+                                Size was updated to the minimum space required.\r
+  @sa FileHandleRead\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleReadLine(\r
+  IN EFI_FILE_HANDLE            Handle,\r
+  IN OUT CHAR16                 *Buffer,\r
+  IN OUT UINTN                  *Size,\r
+  IN BOOLEAN                    Truncate,\r
+  IN OUT BOOLEAN                *Ascii\r
+  );\r
+\r
+/**\r
+  Function to read a single line from a file. The \n is not included in the returned\r
+  buffer.  The returned buffer must be callee freed.\r
+\r
+  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
+  maintained and not changed for all operations with the same file.\r
+\r
+  @param[in]       Handle        FileHandle to read from.\r
+  @param[in, out]  Ascii         Boolean value for indicating whether the file is\r
+                                 Ascii (TRUE) or UCS2 (FALSE).\r
+\r
+  @return                       The line of text from the file.\r
+\r
+  @sa FileHandleReadLine\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FileHandleReturnLine(\r
+  IN EFI_FILE_HANDLE            Handle,\r
+  IN OUT BOOLEAN                *Ascii\r
+  );\r
+\r
+/**\r
+  Function to write a line of unicode text to a file.\r
+\r
+  If Handle is NULL, ASSERT.\r
+\r
+  @param[in]     Handle         FileHandle to write to.\r
+  @param[in]     Buffer         Buffer to write, if NULL the function will\r
+                                take no action and return EFI_SUCCESS.\r
+\r
+  @retval  EFI_SUCCESS          The data was written.\r
+  @retval  other                Failure.\r
+\r
+  @sa FileHandleWrite\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandleWriteLine(\r
+  IN EFI_FILE_HANDLE Handle,\r
+  IN CHAR16          *Buffer\r
+  );\r
+\r
+/**\r
+  Function to take a formatted argument and print it to a file.\r
+\r
+  @param[in] Handle   The file handle for the file to write to.\r
+  @param[in] Format   The format argument (see printlib for the format specifier).\r
+  @param[in] ...      The variable arguments for the format.\r
+\r
+  @retval EFI_SUCCESS The operation was successful.\r
+  @retval other       A return value from FileHandleWriteLine.\r
+\r
+  @sa FileHandleWriteLine\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileHandlePrintLine(\r
+  IN EFI_FILE_HANDLE  Handle,\r
+  IN CONST CHAR16     *Format,\r
+  ...\r
+  );\r
+\r
+/**\r
+  Function to determine if a FILE_HANDLE is at the end of the file.\r
+\r
+  This will NOT work on directories.\r
+\r
+  If Handle is NULL, then ASSERT().\r
+\r
+  @param[in] Handle     The file handle.\r
+\r
+  @retval TRUE          The position is at the end of the file.\r
+  @retval FALSE         The position is not at the end of the file.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+FileHandleEof(\r
+  IN EFI_FILE_HANDLE Handle\r
+  );\r
+\r
+#endif //_FILE_HANDLE_LIBRARY_HEADER_\r
+\r