MOS Source Code
Loading...
Searching...
No Matches
Virtual File System

The Virtual File System (VFS) is an abstraction layer that allows the kernel to interact with different filesystems in a uniform way. More...

+ Collaboration diagram for Virtual File System:

Topics

 Directory Entry
 Directory entry.
 

Functions

should_inline const file_ops_tfile_get_ops (file_t *file)
 
file_tvfs_do_open_dentry (dentry_t *entry, bool created, bool read, bool write, bool exec, bool truncate)
 Open an directory dentry.
 
void vfs_register_filesystem (filesystem_t *fs)
 
long vfs_mount (const char *device, const char *path, const char *fs, const char *options)
 Mount a filesystem at a given existing path.
 
long vfs_unmount (const char *path)
 Unmount a filesystem at a given path.
 
file_tvfs_openat (int fd, const char *path, open_flags flags)
 Open a file at a given path.
 
long vfs_fstatat (fd_t fd, const char *path, file_stat_t *restrict stat, fstatat_flags flags)
 Stat a file.
 
size_t vfs_readlinkat (fd_t dirfd, const char *path, char *buf, size_t size)
 Read a symbolic link.
 
long vfs_symlink (const char *path, const char *target)
 Create a symbolic link.
 
long vfs_mkdir (const char *path)
 Create a directory.
 
long vfs_rmdir (const char *path)
 
size_t vfs_list_dir (io_t *io, void *buf, size_t size)
 Get the content of a directory.
 
long vfs_chdirat (fd_t dirfd, const char *path)
 Change the current working directory.
 
ssize_t vfs_getcwd (char *buf, size_t size)
 Get the current working directory.
 
long vfs_fchmodat (fd_t fd, const char *path, int perm, int flags)
 Change the permissions of a file.
 
long vfs_unlinkat (fd_t dirfd, const char *path)
 Remove the name of a file, and possibly the file itself.
 
long vfs_fsync (io_t *io, bool sync_metadata, off_t start, off_t end)
 Synchronize a file with the filesystem.
 

Variables

dentry_troot_dentry
 

Detailed Description

The Virtual File System (VFS) is an abstraction layer that allows the kernel to interact with different filesystems in a uniform way.

Function Documentation

◆ file_get_ops()

◆ vfs_do_open_dentry()

file_t * vfs_do_open_dentry ( dentry_t * entry,
bool created,
bool read,
bool write,
bool exec,
bool truncate )

Open an directory dentry.

Parameters
entry
created
read
write
exec
truncate
Returns
file_t

Definition at line 413 of file vfs.c.

Referenced by memfd_create(), and vfs_do_open().

+ Here is the call graph for this function:

◆ vfs_register_filesystem()

void vfs_register_filesystem ( filesystem_t * fs)

Definition at line 452 of file vfs.c.

Referenced by MOS_INIT(), and userfs_manager_register_filesystem().

+ Here is the call graph for this function:

◆ vfs_mount()

long vfs_mount ( const char * device,
const char * path,
const char * fs,
const char * options )

Mount a filesystem at a given existing path.

Parameters
deviceThe device to mount
pathThe path to mount the filesystem at, this absolute path to a directory must exist
fsThe filesystem type, e.g. "tmpfs"
optionsThe options to pass to the filesystem
Returns
true if the filesystem was mounted successfully
false if the filesystem could not be mounted, see the kernel log for more information

Definition at line 466 of file vfs.c.

Referenced by mos_start_kernel(), MOS_STATIC_ASSERT(), and MOS_TEST_DECL_PTEST().

+ Here is the call graph for this function:

◆ vfs_unmount()

long vfs_unmount ( const char * path)

Unmount a filesystem at a given path.

Parameters
pathThe path to the filesystem
Returns
true
false

Definition at line 536 of file vfs.c.

Referenced by MOS_STATIC_ASSERT(), and MOS_TEST_DECL_PTEST().

+ Here is the call graph for this function:

◆ vfs_openat()

file_t * vfs_openat ( int fd,
const char * path,
open_flags flags )

Open a file at a given path.

Parameters
fdThe fd of an open directory, or AT_FDCWD to use the current working directory
pathThe path to the file, can be absolute or relative
flagsopen_flags flags
Returns
file_t* The file, or NULL if the file could not be opened

Definition at line 578 of file vfs.c.

Referenced by elf_create_process(), elf_map_interpreter(), and process_do_execveat().

+ Here is the call graph for this function:

◆ vfs_fstatat()

long vfs_fstatat ( fd_t fd,
const char * path,
file_stat_t *restrict stat,
fstatat_flags flags )

Stat a file.

Parameters
fdThe directory, or a file if FSTATAT_FILE is set
pathThe path to the file
flagsfstat_flags flags
statThe stat struct to store the file information in

If the FSTATAT_FILE is set, the fd is a file, and the path will be ignored. If it is not set: If the path is absolute, the fd will be ignored. If the path is relative, the fd will be used as the directory to resolve the path from. If FSTATAT_NOFOLLOW is set, when the path is used, symlinks will not be followed.

Definition at line 588 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_readlinkat()

size_t vfs_readlinkat ( fd_t dirfd,
const char * path,
char * buf,
size_t size )

Read a symbolic link.

Parameters
dirfdThe file descriptor of the directory containing the symbolic link
pathThe path to the symbolic link
bufThe buffer to store the link in
sizeThe size of the buffer
Returns
size_t The size of the link, or 0 if the link could not be read, or the buffer was too small

Definition at line 623 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_symlink()

long vfs_symlink ( const char * path,
const char * target )

Create a symbolic link.

Parameters
pathThe path to the symbolic link
targetThe target of the symbolic link
Returns
true
false

Definition at line 646 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_mkdir()

long vfs_mkdir ( const char * path)

Create a directory.

Parameters
pathThe path to the directory
Returns
true
false

Definition at line 664 of file vfs.c.

Referenced by mos_start_kernel(), MOS_STATIC_ASSERT(), and MOS_TEST_DECL_PTEST().

+ Here is the call graph for this function:

◆ vfs_rmdir()

long vfs_rmdir ( const char * path)

Definition at line 689 of file vfs.c.

Referenced by MOS_TEST_DECL_PTEST().

+ Here is the call graph for this function:

◆ vfs_list_dir()

size_t vfs_list_dir ( io_t * io,
void * buf,
size_t size )

Get the content of a directory.

Parameters
ioThe io object of a file_t, must be a directory and opened with FILE_OPEN_READ
bufThe buffer to store the directory entries in
sizeThe size of the buffer
Returns
size_t The number of bytes read, or 0 if the end of the directory was reached

Definition at line 713 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_chdirat()

long vfs_chdirat ( fd_t dirfd,
const char * path )

Change the current working directory.

Parameters
dirfdThe file descriptor of the directory to change to
pathThe path to the directory, relative to the dirfd
Returns
long 0 on success, or errno on failure

Definition at line 764 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_getcwd()

ssize_t vfs_getcwd ( char * buf,
size_t size )

Get the current working directory.

Parameters
bufThe buffer to store the path in
sizeThe size of the buffer
Returns
ssize_t The size of the path, or 0 if the buffer was too small

Definition at line 780 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_fchmodat()

long vfs_fchmodat ( fd_t fd,
const char * path,
int perm,
int flags )

Change the permissions of a file.

Parameters
fdThe directory, or a file if FSTATAT_FILE is set
pathThe path to the file
permThe new permissions
flagsfstat_flags flags
Returns
long 0 on success, or errno on failure

Definition at line 789 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_unlinkat()

long vfs_unlinkat ( fd_t dirfd,
const char * path )

Remove the name of a file, and possibly the file itself.

Parameters
dirfdThe file descriptor of the directory containing the file (or the file itself if AT_EMPTY_PATH is set)
pathThe path to the file
Returns
long 0 on success, or errno on failure

Definition at line 803 of file vfs.c.

Referenced by MOS_STATIC_ASSERT().

+ Here is the call graph for this function:

◆ vfs_fsync()

long vfs_fsync ( io_t * io,
bool sync_metadata,
off_t start,
off_t end )

Synchronize a file with the filesystem.

Parameters
ioThe io object of a file_t
sync_metadataWhether to sync the metadata
startThe start of the range to sync
endThe end of the range to sync
Returns
long 0 on success, or errno on failure

Definition at line 830 of file vfs.c.

+ Here is the call graph for this function:

Variable Documentation

◆ root_dentry

dentry_t* root_dentry
extern

Definition at line 36 of file vfs.c.