vfs_file_ops Struct Reference

Operations on open files. More...

Detailed Description

Operations on open files.

Similar, but not equal, to struct file_operations in Linux

Definition at line 328 of file vfs.h.

#include <vfs.h>

Data Fields

int(* close )(vfs_file_t *filp)
 Close an open file. More...
 
int(* fcntl )(vfs_file_t *filp, int cmd, int arg)
 Query/set options on an open file. More...
 
int(* fstat )(vfs_file_t *filp, struct stat *buf)
 Get status of an open file. More...
 
off_t(* lseek )(vfs_file_t *filp, off_t off, int whence)
 Seek to position in file. More...
 
int(* open )(vfs_file_t *filp, const char *name, int flags, mode_t mode, const char *abs_path)
 Attempt to open a file in the file system at rel_path. More...
 
ssize_t(* read )(vfs_file_t *filp, void *dest, size_t nbytes)
 Read bytes from an open file. More...
 
ssize_t(* write )(vfs_file_t *filp, const void *src, size_t nbytes)
 Write bytes to an open file. More...
 

Field Documentation

◆ close

int(* vfs_file_ops::close) (vfs_file_t *filp)

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 -EINTR a special return code, the file is still considered closed.
Parameters
[in]filppointer to open file
Returns
0 on success
<0 on error, the file is considered closed anyway

Definition at line 347 of file vfs.h.

◆ fcntl

int(* vfs_file_ops::fcntl) (vfs_file_t *filp, int cmd, int arg)

Query/set options on an open file.

Parameters
[in]filppointer to open file
[in]cmdfcntl command, see man 3p fcntl
[in]argargument to fcntl command, see man 3p fcntl
Returns
0 on success
<0 on error

Definition at line 359 of file vfs.h.

◆ fstat

int(* vfs_file_ops::fstat) (vfs_file_t *filp, struct stat *buf)

Get status of an open file.

Parameters
[in]filppointer to open file
[out]bufpointer to stat struct to fill
Returns
0 on success
<0 on error

Definition at line 370 of file vfs.h.

◆ lseek

off_t(* vfs_file_ops::lseek) (vfs_file_t *filp, off_t off, int whence)

Seek to position in file.

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

  • SEEK_SET: Seek to absolute offset off
  • SEEK_CUR: Seek to current location + off
  • SEEK_END: Seek to end of file + off
Parameters
[in]filppointer to open file
[in]offseek offset
[in]whencedetermines the seek method, see detailed description
Returns
the new seek location in the file on success
<0 on error

Definition at line 389 of file vfs.h.

◆ open

int(* vfs_file_ops::open) (vfs_file_t *filp, const char *name, int flags, mode_t mode, const char *abs_path)

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 *filp so that filp->f_op points to the mounted file system's vfs_file_ops_t. filp->private_data.ptr will be initialized to NULL, filp->pos will be set to 0.

Note
name is an absolute path inside the file system, abs_path is the path to the file in the VFS, example: abs_path = "/mnt/hd/foo/bar", name = "/foo/bar"
name and abs_path may point to different locations within the same const char array and the strings may overlap
Parameters
[in]filppointer to open file
[in]namenull-terminated name of the file to open, relative to the file system root, including a leading slash
[in]flagsflags for opening, see man 2 open, man 3p open
[in]modemode for creating a new file, see man 2 open, man 3p open
[in]abs_pathnull-terminated name of the file to open, relative to the VFS root ("/")
Returns
0 on success
<0 on error

Definition at line 418 of file vfs.h.

◆ read

ssize_t(* vfs_file_ops::read) (vfs_file_t *filp, void *dest, size_t nbytes)

Read bytes from an open file.

Parameters
[in]filppointer to open file
[in]destpointer to destination buffer
[in]nbytesmaximum number of bytes to read
Returns
number of bytes read on success
<0 on error

Definition at line 430 of file vfs.h.

◆ write

ssize_t(* vfs_file_ops::write) (vfs_file_t *filp, const void *src, size_t nbytes)

Write bytes to an open file.

Parameters
[in]filppointer to open file
[in]srcpointer to source buffer
[in]nbytesmaximum number of bytes to write
Returns
number of bytes written on success
<0 on error

Definition at line 442 of file vfs.h.


The documentation for this struct was generated from the following file: