AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vfs.c File Reference

The virtual filesystem (VFS): the filesystems that are installed, the root, mounting one filesystem on a directory of another, and permissions. More...

#include <core/system.h>
#include <core/string.h>
#include <mm/mm.h>
#include <fs/vfs.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <aquila/fcntl.h>
#include <aquila/errno.h>
#include <dev/dev.h>
#include <net/socket.h>

Go to the source code of this file.

Functions

int vfs_mount_root (struct vnode *vnode)
 Makes a vnode the root of the filesystem tree.
int vfs_bind (struct vnode *dir, struct vnode *root)
 Mounts a filesystem on a directory: a lookup that reaches dir goes on in root instead.
void vfs_init (void)
 Sets up the VFS at boot.
int vfs_install (struct fs *fs)
 Installs a filesystem, so that it can be mounted by name.
int vfs_access (struct vnode *vnode, struct uio *uio, int mode)
 Checks whether a user may access a vnode in a way: the owner's permissions apply to its owner, the group's to its group, the others' to everyone else.
int vfs_perms_check (struct file *file, struct uio *uio)
 Checks whether a user may open a file the way it's being opened (read, write, execute, as its flags say).

Variables

static int vfs_log_level = LOG_NONE
struct fs_list * registered_fs = NULL
 The installed filesystems.
struct vnode * vfs_root = NULL

Detailed Description

The virtual filesystem (VFS): the filesystems that are installed, the root, mounting one filesystem on a directory of another, and permissions.

See docs/kernel/vfs.md.

Definition in file vfs.c.

Function Documentation

◆ vfs_access()

int vfs_access ( struct vnode * vnode,
struct uio * uio,
int mode )

Checks whether a user may access a vnode in a way: the owner's permissions apply to its owner, the group's to its group, the others' to everyone else.

Root may do anything, but only execute a file that has an execute bit.

Parameters
vnodethe vnode
uiowho is asking
modethe access: VFS_R, VFS_W and VFS_X, or'ed
Returns
0 if it's allowed, or -EACCES

Definition at line 114 of file vfs.c.

References uio::gid, vnode::gid, vnode::mode, shift, uio::uid, vnode::uid, vfs_access(), and VFS_X.

Referenced by binfmt_load(), cwd_set(), do_faccessat(), exec_script(), vfs_access(), vfs_link(), vfs_mknod(), vfs_perms_check(), vfs_remove(), vfs_rename(), vfs_utimens(), and walk().

◆ vfs_bind()

int vfs_bind ( struct vnode * dir,
struct vnode * root )

Mounts a filesystem on a directory: a lookup that reaches dir goes on in root instead.

The mount keeps a reference to dir. Mounting on the root makes root the new root.

Parameters
dirthe directory to mount on
rootthe root directory of the filesystem to mount
Returns
0, -EINVAL, or -EBUSY if something is mounted on dir already, or root is mounted elsewhere

Definition at line 53 of file vfs.c.

References vnode::covered, vnode::mounted, vnode::ref, vfs_bind(), vfs_mount_root(), and vfs_root.

Referenced by devfs_mount(), devpts_mount(), ext2_mount(), minix_mount(), procfs_mount(), tmpfs_mount(), and vfs_bind().

◆ vfs_init()

void vfs_init ( void )

Sets up the VFS at boot.

Definition at line 74 of file vfs.c.

References LOG_INFO, and vfs_init().

Referenced by kmain(), and vfs_init().

◆ vfs_install()

int vfs_install ( struct fs * fs)

Installs a filesystem, so that it can be mounted by name.

Parameters
fsthe filesystem
Returns
0, or -ENOMEM

Definition at line 85 of file vfs.c.

References fs_list::fs, kmalloc(), LOG_INFO, fs::name, fs_list::name, fs_list::next, registered_fs, and vfs_install().

Referenced by devfs_init(), devpts_init(), ext2_init(), minix_init(), procfs_init(), tmpfs_init(), and vfs_install().

◆ vfs_mount_root()

int vfs_mount_root ( struct vnode * vnode)

Makes a vnode the root of the filesystem tree.

Parameters
vnodethe root directory of a filesystem
Returns
0

Definition at line 37 of file vfs.c.

References vfs_mount_root(), and vfs_root.

Referenced by load_ramdisk(), vfs_bind(), vfs_mount_root(), and vfs_mount_root_dev().

◆ vfs_perms_check()

int vfs_perms_check ( struct file * file,
struct uio * uio )

Checks whether a user may open a file the way it's being opened (read, write, execute, as its flags say).

Parameters
filethe file being opened, its flags set
uiowho is opening it
Returns
0 if it's allowed, or -EACCES

Definition at line 139 of file vfs.c.

References file::flags, vfs_access(), vfs_perms_check(), VFS_R, VFS_W, and VFS_X.

Referenced by do_openat(), and vfs_perms_check().

Variable Documentation

◆ registered_fs

struct fs_list* registered_fs = NULL

The installed filesystems.

Definition at line 25 of file vfs.c.

Referenced by procfs_filesystems(), vfs_install(), vfs_mount(), and vfs_mount_root_dev().

◆ vfs_log_level

int vfs_log_level = LOG_NONE
static

Definition at line 21 of file vfs.c.

◆ vfs_root

struct vnode* vfs_root = NULL