Struct riot_sys::vfs_file_ops

source ·
#[repr(C)]
pub struct vfs_file_ops { pub close: Option<unsafe extern "C" fn(filp: *mut vfs_file_t) -> c_int>, pub fcntl: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, cmd: c_int, arg: c_int) -> c_int>, pub fstat: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, buf: *mut stat) -> c_int>, pub lseek: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, off: off_t, whence: c_int) -> off_t>, pub open: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, name: *const c_char, flags: c_int, mode: mode_t) -> c_int>, pub read: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, dest: *mut c_void, nbytes: size_t) -> ssize_t>, pub write: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, src: *const c_void, nbytes: size_t) -> ssize_t>, pub fsync: Option<unsafe extern "C" fn(filp: *mut vfs_file_t) -> c_int>, }
Expand description

@brief Operations on open files

Similar, but not equal, to struct file_operations in Linux

Fields§

§close: Option<unsafe extern "C" fn(filp: *mut vfs_file_t) -> c_int>

@brief Close an open file

This function must perform any necessary clean ups and flush any internal buffers in the file system driver.

If an error occurs, the file will still be considered closed by the VFS layer. Therefore, the proper clean up must still be performed by the file system driver before returning any error code.

@note This implementation does not consider @c -EINTR a special return code, the file is still considered closed.

@param[in] filp pointer to open file

@return 0 on success @return <0 on error, the file is considered closed anyway

§fcntl: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, cmd: c_int, arg: c_int) -> c_int>

@brief Query/set options on an open file

@param[in] filp pointer to open file @param[in] cmd fcntl command, see man 3p fcntl @param[in] arg argument to fcntl command, see man 3p fcntl

@return 0 on success @return <0 on error

§fstat: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, buf: *mut stat) -> c_int>

@brief Get status of an open file

@param[in] filp pointer to open file @param[out] buf pointer to stat struct to fill

@return 0 on success @return <0 on error

§lseek: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, off: off_t, whence: c_int) -> off_t>

@brief Seek to position in file

@p whence determines the function of the seek and should be set to one of the following values:

  • @c SEEK_SET: Seek to absolute offset @p off
  • @c SEEK_CUR: Seek to current location + @p off
  • @c SEEK_END: Seek to end of file + @p off

@param[in] filp pointer to open file @param[in] off seek offset @param[in] whence determines the seek method, see detailed description

@return the new seek location in the file on success @return <0 on error

§open: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, name: *const c_char, flags: c_int, mode: mode_t) -> c_int>

@brief Attempt to open a file in the file system at rel_path

A file system driver should perform the necessary checks for file existence etc in this function.

The VFS layer will initialize the contents of @p *filp so that @c filp->f_op points to the mounted file system’s @c vfs_file_ops_t. @c filp->private_data.ptr will be initialized to NULL, @c filp->pos will be set to 0.

@note @p name is an absolute path inside the file system, @p abs_path is the path to the file in the VFS, example: @p abs_path = “/mnt/hd/foo/bar”, @p name = “/foo/bar”

@note @p name and @p abs_path may point to different locations within the same const char array and the strings may overlap

@param[in] filp pointer to open file @param[in] name null-terminated name of the file to open, relative to the file system root, including a leading slash @param[in] flags flags for opening, see man 2 open, man 3p open @param[in] mode mode for creating a new file, see man 2 open, man 3p open

@return 0 on success @return <0 on error

§read: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, dest: *mut c_void, nbytes: size_t) -> ssize_t>

@brief Read bytes from an open file

@param[in] filp pointer to open file @param[in] dest pointer to destination buffer @param[in] nbytes maximum number of bytes to read

@return number of bytes read on success @return <0 on error

§write: Option<unsafe extern "C" fn(filp: *mut vfs_file_t, src: *const c_void, nbytes: size_t) -> ssize_t>

@brief Write bytes to an open file

@param[in] filp pointer to open file @param[in] src pointer to source buffer @param[in] nbytes maximum number of bytes to write

@return number of bytes written on success @return <0 on error

§fsync: Option<unsafe extern "C" fn(filp: *mut vfs_file_t) -> c_int>

@brief Synchronize a file on storage Any pending writes are written out to storage.

@param[in] filp pointer to open file

@return 0 on success @return <0 on error

Trait Implementations§

source§

impl Clone for vfs_file_ops

source§

fn clone(&self) -> vfs_file_ops

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for vfs_file_ops

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for vfs_file_ops

source§

fn default() -> vfs_file_ops

Returns the “default value” for a type. Read more
source§

impl Copy for vfs_file_ops

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.