pub struct RegularFile(/* private fields */);
Expand description
A FileHandle
that is also a regular (data) file.
Use FileHandle::into_type
or RegularFile::new
to create a RegularFile
.
In addition to supporting the normal File
operations, RegularFile
supports direct reading and writing.
Implementations§
source§impl RegularFile
impl RegularFile
sourcepub const END_OF_FILE: u64 = 18_446_744_073_709_551_615u64
pub const END_OF_FILE: u64 = 18_446_744_073_709_551_615u64
A special position used to seek to the end of a file with set_position()
.
sourcepub unsafe fn new(handle: FileHandle) -> Self
pub unsafe fn new(handle: FileHandle) -> Self
Coverts a FileHandle
into a RegularFile
without checking the file kind.
§Safety
This function should only be called on handles which ARE NOT directories, doing otherwise is unsafe.
sourcepub fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
pub fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
Read data from file.
Try to read as much as possible into buffer
. Returns the number of bytes that were
actually read.
§Arguments
buffer
The target buffer of the read operation
§Errors
See section EFI_FILE_PROTOCOL.Read()
in the UEFI Specification for more details.
§Quirks
Some UEFI implementations have a bug where large reads will incorrectly return an error. This function avoids that bug by reading in chunks of no more than 1 MiB. This is handled internally within the function; callers can safely pass in a buffer of any size. See https://github.com/rust-osdev/uefi-rs/issues/825 for more information.
sourcepub fn write(&mut self, buffer: &[u8]) -> Result<(), usize>
pub fn write(&mut self, buffer: &[u8]) -> Result<(), usize>
Write data to file
Write buffer
to file, increment the file pointer.
If an error occurs, returns the number of bytes that were actually written. If no error occurred, the entire buffer is guaranteed to have been written successfully.
§Arguments
buffer
Buffer to write to file
§Errors
See section EFI_FILE_PROTOCOL.Write()
in the UEFI Specification for more details.
sourcepub fn get_position(&mut self) -> Result<u64>
pub fn get_position(&mut self) -> Result<u64>
Get the file’s current position
§Errors
See section EFI_FILE_PROTOCOL.GetPosition()
in the UEFI Specification for more details.
sourcepub fn set_position(&mut self, position: u64) -> Result
pub fn set_position(&mut self, position: u64) -> Result
Sets the file’s current position
Set the position of this file handle to the absolute position specified by position
.
Seeking past the end of the file is allowed, it will trigger file growth on the next write. Using a position of RegularFile::END_OF_FILE will seek to the end of the file.
§Arguments
position
The new absolution position of the file handle
§Errors
See section EFI_FILE_PROTOCOL.SetPosition()
in the UEFI Specification for more details.
Trait Implementations§
source§impl Debug for RegularFile
impl Debug for RegularFile
source§impl File for RegularFile
impl File for RegularFile
source§fn is_regular_file(&self) -> Result<bool>
fn is_regular_file(&self) -> Result<bool>
source§fn is_directory(&self) -> Result<bool>
fn is_directory(&self) -> Result<bool>
source§fn open(
&mut self,
filename: &CStr16,
open_mode: FileMode,
attributes: FileAttribute
) -> Result<FileHandle>
fn open( &mut self, filename: &CStr16, open_mode: FileMode, attributes: FileAttribute ) -> Result<FileHandle>
source§fn get_info<'buf, Info: FileProtocolInfo + ?Sized>(
&mut self,
buffer: &'buf mut [u8]
) -> Result<&'buf mut Info, Option<usize>>
fn get_info<'buf, Info: FileProtocolInfo + ?Sized>( &mut self, buffer: &'buf mut [u8] ) -> Result<&'buf mut Info, Option<usize>>
source§fn set_info<Info: FileProtocolInfo + ?Sized>(&mut self, info: &Info) -> Result
fn set_info<Info: FileProtocolInfo + ?Sized>(&mut self, info: &Info) -> Result
source§fn flush(&mut self) -> Result
fn flush(&mut self) -> Result
source§fn get_boxed_info<Info: FileProtocolInfo + ?Sized + Debug>(
&mut self
) -> Result<Box<Info>>
fn get_boxed_info<Info: FileProtocolInfo + ?Sized + Debug>( &mut self ) -> Result<Box<Info>>
alloc
only.source§fn get_boxed_info_in<Info: FileProtocolInfo + ?Sized + Debug, A: Allocator>(
&mut self,
allocator: A
) -> Result<Box<Info>>
fn get_boxed_info_in<Info: FileProtocolInfo + ?Sized + Debug, A: Allocator>( &mut self, allocator: A ) -> Result<Box<Info>>
unstable
and alloc
only.