pub struct File { /* private fields */ }Expand description
A handle to an open file.
This is a wrapper around an osal_id_t that will automatically call
OS_close when it goes out of scope, preventing resource leaks.
Implementations§
Source§impl File
impl File
Sourcepub fn open(path: &str, access: AccessMode) -> Result<Self>
pub fn open(path: &str, access: AccessMode) -> Result<Self>
Opens a file with the specified access mode.
§Arguments
path: The virtual path to the file (e.g., “/ram/my_file.txt”).access: The access mode, e.g.,ffi::OS_READ_ONLY,ffi::OS_WRITE_ONLY, orffi::OS_READ_WRITE.
Sourcepub fn create(path: &str) -> Result<Self>
pub fn create(path: &str) -> Result<Self>
Creates a new file, or truncates an existing one, with read/write access.
§Arguments
path: The virtual path to the file to create (e.g., “/ram/new_file.dat”).
Sourcepub fn sync_read(&mut self, buf: &mut [u8]) -> Result<usize>
pub fn sync_read(&mut self, buf: &mut [u8]) -> Result<usize>
Reads some bytes from the file into the specified buffer.
Returns the number of bytes read.
Sourcepub fn sync_write(&mut self, buf: &[u8]) -> Result<usize>
pub fn sync_write(&mut self, buf: &[u8]) -> Result<usize>
Writes a buffer to the file.
Returns the number of bytes written.
Sourcepub fn seek(&mut self, pos: SeekFrom) -> Result<u32>
pub fn seek(&mut self, pos: SeekFrom) -> Result<u32>
Seeks to an offset, in bytes, in a stream.
Returns the new position from the start of the file.
Sourcepub fn read_header(&mut self) -> Result<FsHeader>
pub fn read_header(&mut self) -> Result<FsHeader>
Reads the standard cFE File Header from the file.
Sourcepub fn write_header(&mut self, hdr: &mut FsHeader) -> Result<()>
pub fn write_header(&mut self, hdr: &mut FsHeader) -> Result<()>
Writes the standard cFE File Header to the file.
Sourcepub fn set_timestamp(&mut self, time: SysTime) -> Result<()>
pub fn set_timestamp(&mut self, time: SysTime) -> Result<()>
Modifies the timestamp field in the cFE File Header.
Sourcepub fn timed_read(&mut self, buf: &mut [u8], timeout_ms: i32) -> Result<usize>
pub fn timed_read(&mut self, buf: &mut [u8], timeout_ms: i32) -> Result<usize>
Reads from the file with a relative timeout.
Sourcepub fn timed_read_abs(
&mut self,
buf: &mut [u8],
abstime: OsTime,
) -> Result<usize>
pub fn timed_read_abs( &mut self, buf: &mut [u8], abstime: OsTime, ) -> Result<usize>
Reads from the file with an absolute timeout.