193 lines
5.2 KiB
C
Executable File

/** @file
Copyright (C) 2016 - 2017, The HermitCrabs Lab. All rights reserved.
All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef OC_FILE_LIB_H
#define OC_FILE_LIB_H
// Include the abstracted protocol for its definitions
#include <Guid/FileInfo.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/DevicePath.h>
/**
Locate file system from Device handle or path.
@param[in] DeviceHandle Device handle.
@param[in] FilePath Device path.
@retval simple file system protocol or NULL.
**/
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *
LocateFileSystem (
IN EFI_HANDLE DeviceHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
);
/**
Locate root volume from Device handle or path.
@param[in] DeviceHandle Device handle.
@param[in] FilePath Device path.
@retval opened file protocol or NULL.
**/
EFI_FILE_PROTOCOL *
LocateRootVolume (
IN EFI_HANDLE DeviceHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
);
/**
@param[in] FileSystem A pointer to the file system protocol of the volume.
@retval A pointer to the NULL terminated unicode volume label.
**/
CHAR16 *
GetVolumeLabel (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem
);
/**
Read file from device path with implicit double (2 byte) null termination.
Null termination does not affect the returned file size.
Depending on the implementation 0 byte files may return null.
@param[in] FileSystem A pointer to the file system protocol of the volume.
@param[in] FilePath The full path to the file on the device.
@param[out] FileSize The size of the file read (optional).
@retval A pointer to a buffer containing file read or NULL.
**/
VOID *
ReadFile (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINT32 *FileSize OPTIONAL
);
/**
Determine file size if it is less than 4 GB.
@param[in] File A pointer to the file protocol.
@param[out] Size 32-bit file size.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
ReadFileSize (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINT32 *Size
);
/**
Read exact amount of bytes from EFI_FILE_PROTOCOL at specified position.
@param[in] File A pointer to the file protocol.
@param[in] Position Position to read data from.
@param[in] Size The size of the data read.
@param[out] Buffer A pointer to previously allocated buffer to read data to.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
GetFileData (
IN EFI_FILE_PROTOCOL *File,
IN UINT32 Position,
IN UINT32 Size,
OUT UINT8 *Buffer
);
/**
Write exact amount of bytes to a newly created file in EFI_FILE_PROTOCOL.
Please note, that several filesystems (or drivers) may limit file name length.
@param[in] WritableFs A pointer to the file protocol, any will be tried if NULL.
@param[in] FileName File name (possibly with path) to write.
@param[in] Buffer A pointer with the data to be written.
@param[in] Size Amount of data to be written.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
SetFileData (
IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL,
IN CONST CHAR16 *FileName,
IN CONST VOID *Buffer,
IN UINT32 Size
);
/**
Get file information of specified type.
@param[in] FileHandle A pointer to file handle.
@param[in] InformationType A pointer to file info GUID.
@param[in] MinFileInfoSize Minimal size of the info provided.
@param[out] RealFileInfoSize Actual info size read (optional).
@retval read file info or NULL.
**/
VOID *
GetFileInfo (
IN EFI_FILE_PROTOCOL *File,
IN EFI_GUID *InformationType,
IN UINTN MinFileInfoSize,
OUT UINTN *RealFileInfoSize OPTIONAL
);
/**
Determine file size if it is less than 4 GB.
@param[in] File A pointer to the file protocol.
@param[out] Size 32-bit file size.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
GetFileSize (
IN EFI_FILE_PROTOCOL *File,
OUT UINT32 *Size
);
/**
Determine file modification time.
@param[in] File A pointer to the file protocol.
@param[out] Time Modification time.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
GetFileModifcationTime (
IN EFI_FILE_PROTOCOL *File,
OUT EFI_TIME *Time
);
/**
Determine writeable filesystem.
@param[in,out] WritableFs First found writeable file system.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
FindWritableFileSystem (
IN OUT EFI_FILE_PROTOCOL **WritableFs
);
#endif // OC_FILE_LIB_H