Operations on open files. More...
Operations on open files.
Similar, but not equal, to struct file_operations in Linux
#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... | |
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.
-EINTR
a special return code, the file is still considered closed.[in] | filp | pointer to open file |
int(* vfs_file_ops::fcntl) (vfs_file_t *filp, int cmd, int arg) |
int(* vfs_file_ops::fstat) (vfs_file_t *filp, struct stat *buf) |
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
[in] | filp | pointer to open file |
[in] | off | seek offset |
[in] | whence | determines the seek method, see detailed description |
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.
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[in] | filp | pointer to open file |
[in] | name | null-terminated name of the file to open, relative to the file system root, including a leading slash |
[in] | flags | flags for opening, see man 2 open, man 3p open |
[in] | mode | mode for creating a new file, see man 2 open, man 3p open |
[in] | abs_path | null-terminated name of the file to open, relative to the VFS root ("/") |
ssize_t(* vfs_file_ops::read) (vfs_file_t *filp, void *dest, size_t nbytes) |
ssize_t(* vfs_file_ops::write) (vfs_file_t *filp, const void *src, size_t nbytes) |