Struct tartan_uefi::proto::File
source · #[repr(C)]pub struct File {
pub revision: u64,
/* private fields */
}
Expand description
Protocol for accessing a file or directory.
Fields§
§revision: u64
Implemented revision of the File protocol.
Implementations§
source§impl File
impl File
sourcepub const MIN_REVISION: u32 = 65_536u32
pub const MIN_REVISION: u32 = 65_536u32
Minimum supported SimpleFileSystem::revision
. Future versions are
guaranteed to be backwards-compatible.
sourcepub fn open(
&self,
path: &[u16],
mode: FileMode,
attributes: FileAttributes,
) -> Result<&File, Status>
pub fn open( &self, path: &[u16], mode: FileMode, attributes: FileAttributes, ) -> Result<&File, Status>
Get a handle to a new file, relative to the directory represented by the current instance.
path
uses the Windows path format without a drive name, e.g. \FOO\BAR.TXT
or ..\QUUX.DAT
.
attributes
is only used if the file is created.
§Errors
This method can fail for many reasons, including standard I/O issues like device errors or resource exhaustion. It can also fail if access is denied or there was an attempt to write to read-only media.
§Panics
Panics if path
is empty or does not end in a null character.
sourcepub fn close(&self)
pub fn close(&self)
Flush and close the file or directory represented by the current instance.
§Panics
Panics if the firmware does not behave according to the spec.
sourcepub fn delete(&self) -> Status
pub fn delete(&self) -> Status
Delete the file or directory represented by the current instance.
§Errors
This method cannot fail with an error, but it will return
Status::WarnDeleteFailure
if the file could not be deleted.
sourcepub fn read(&self, buffer: &mut [u8]) -> Result<usize, Status>
pub fn read(&self, buffer: &mut [u8]) -> Result<usize, Status>
Read file contents or a directory entry into the buffer.
If this is a file, it will read up to buffer.len()
bytes. If it is a
directory, it will read a single directory entry if that entry can fit in the
buffer.
On success, returns the number of bytes actually read.
§Errors
This method can fail for many reasons, including standard I/O issues like device errors or resource exhaustion. In addition, it will return:
Status::BufferTooSmall
if this is a directory and the next entry could not fit into the buffer.Status::DeviceError
if the current position was already EOF.
sourcepub fn write(&self, buffer: &[u8]) -> Result<usize, Status>
pub fn write(&self, buffer: &[u8]) -> Result<usize, Status>
Write the contents of buffer
out to the current position.
On success, returns the number of bytes actually written, which will always be the full buffer.
§Errors
This method can fail for many reasons, including standard I/O issues like device errors or resource exhaustion. It addition, it will return:
Status::Unsupported
if this is a directory.Status::AccessDenied
if the file is in read-only mode.
sourcepub fn get_position(&self) -> Result<u64, Status>
pub fn get_position(&self) -> Result<u64, Status>
Get the handle’s current position in the file.
§Errors
This function will fail with:
Status::DeviceError
if the file has been deleted.Status::Unsupported
if this is a directory.
sourcepub fn set_position(&self, position: u64) -> Result
pub fn set_position(&self, position: u64) -> Result
Set the handle’s current position in the file.
If the position is u64::MAX
, this will seek to the end of the file.
Otherwise, it seeks to the absolute position in bytes. If the position is
greater than the current file size, the file will grow to the given size.
§Errors
This function will fail with:
Status::DeviceError
if the file has been deleted.Status::Unsupported
if this is a directory.