Type Alias riot_sys::vfs_file_ops_t

source ·
pub type vfs_file_ops_t = vfs_file_ops;
Expand description

@brief Operations on open files

Similar, but not equal, to struct file_operations in Linux

Aliased Type§

struct vfs_file_ops_t {
    pub close: Option<unsafe extern "C" fn(_: *mut vfs_file_t) -> i32>,
    pub fcntl: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: i32, _: i32) -> i32>,
    pub fstat: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: *mut stat) -> i32>,
    pub lseek: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: i32, _: i32) -> i32>,
    pub open: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: *const u8, _: i32, _: u32) -> i32>,
    pub read: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: *mut c_void, _: u32) -> i32>,
    pub write: Option<unsafe extern "C" fn(_: *mut vfs_file_t, _: *const c_void, _: u32) -> i32>,
    pub fsync: Option<unsafe extern "C" fn(_: *mut vfs_file_t) -> i32>,
}

Fields§

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

@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(_: *mut vfs_file_t, _: i32, _: i32) -> i32>

@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(_: *mut vfs_file_t, _: *mut stat) -> i32>

@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(_: *mut vfs_file_t, _: i32, _: i32) -> i32>

@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(_: *mut vfs_file_t, _: *const u8, _: i32, _: u32) -> i32>

@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(_: *mut vfs_file_t, _: *mut c_void, _: u32) -> i32>

@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(_: *mut vfs_file_t, _: *const c_void, _: u32) -> i32>

@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(_: *mut vfs_file_t) -> i32>

@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