AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vfs.h File Reference
#include <core/system.h>
#include <aquila/dirent.h>
#include <aquila/errno.h>
#include <sys/proc.h>
#include <ds/queue.h>
#include <fs/stat.h>
#include <mm/vm.h>

Go to the source code of this file.

Data Structures

struct  fops
 An open file's operations. More...
struct  uio
 Who does a filesystem operation: where its paths start, and its credentials and umask. More...
struct  vops
 A filesystem's vnode operations, any of which may be NULL. More...
struct  fs
 A filesystem type. More...
struct  vnode
 A file in memory (a vnode): what its inode says, and the kernel's own state. More...
struct  file
 An open file (POSIX's "open file description", fs/file.c). More...
struct  fs_list
 The list of registered filesystem types. More...
struct  mountpoint
 A mount's description, as /proc/mounts shows it. More...

Macros

#define ISDEV(vnode)
#define FS_MSYNC   0x0001
#define FS_DSYNC   0x0002
#define VFS_R   4
#define VFS_W   2
#define VFS_X   1

Functions

 LOGGER_DECLARE (vfs_log)
struct file * file_new (void)
 Makes a new open file, with one reference.
struct file * file_ref (struct file *file)
 Adds a reference to an open file.
int file_put (struct file *file)
 Drops a reference to an open file.
struct file * file_hold (struct file *file)
 Holds an open file for the current system call, until it returns.
static int __vfs_can_always (struct file *f, size_t s)
static int __vfs_can_never (struct file *f, size_t s)
static int __vfs_eof_always (struct file *f)
static int __vfs_eof_never (struct file *f)
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_mount_root (struct vnode *vnode)
 Makes a vnode the root of the filesystem tree.
int vfs_mount_root_dev (const char *name, const char *type)
 Mounts the root filesystem from a disk partition (the root=/dev/hda2 kernel argument).
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.
int vfs_mount (const char *type, const char *dir, int flags, void *data, struct uio *uio)
 Mounts a filesystem of a type on a directory, for mount().
int vfs_vmknod (struct vnode *dir, const char *fn, uint32_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
 Makes a node in a directory.
int vfs_vcreat (struct vnode *dir, const char *fn, struct uio *uio, struct vnode **ref)
 Makes a regular file in a directory, with no permissions set.
int vfs_vmkdir (struct vnode *dir, const char *dname, struct uio *uio, struct vnode **ref)
 Makes a directory in a directory, with no permissions set.
int vfs_vunlink (struct vnode *dir, const char *fn, struct uio *uio)
 Removes a name from a directory.
int vfs_vlink (struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
 Adds a name for an existing file (a hard link) to a directory of the same filesystem.
int vfs_vrename (struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
 Renames an entry, possibly to another directory of the same filesystem.
int vfs_setattr (struct vnode *vnode)
 Has the filesystem store a vnode's attributes (mode, owner, times) after they were changed in memory.
int vfs_vget (struct vnode *super, ino_t ino, struct vnode **vnode)
 Gets the vnode of an inode, by its number.
int vfs_map (struct vm_space *vm_space, struct vm_entry *vm_entry)
 Maps a file into an address space, for mmap(): a device's own mapping, or the filesystem's.
ssize_t vfs_read_io (struct vnode *vnode, off_t offset, struct iobuf *io)
 Reads from a vnode into an iobuf (user or kernel memory).
ssize_t vfs_write_io (struct vnode *vnode, off_t offset, struct iobuf *io)
 Writes to a vnode from an iobuf (user or kernel memory).
ssize_t vfs_read (struct vnode *vnode, off_t offset, size_t size, void *buf)
 Reads from a vnode into a kernel buffer.
ssize_t vfs_write (struct vnode *vnode, off_t offset, size_t size, void *buf)
 Writes to a vnode from a kernel buffer.
int vfs_ioctl (struct vnode *vnode, unsigned long request, void *argp)
 Passes an ioctl() request to a vnode's device driver, or to its filesystem.
int vfs_close (struct vnode *vnode)
 Drops a reference to a vnode.
int vfs_trunc (struct vnode *vnode, off_t len)
 Changes a file's length, through its filesystem.
struct vm_page * vfs_pagein (struct vnode *vnode, off_t offset)
int vfs_vsync (struct vnode *vnode, int mode)
 Would write a vnode's data and metadata to its disk.
int vfs_fssync (struct vnode *super, int mode)
 Would write a filesystem's data and metadata to its disk.
int vfs_sync (int mode)
 Would write every filesystem's data and metadata to its disk.
ssize_t vfs_readdir (struct vnode *dir, off_t offset, struct dirent *dirent)
 Reads a directory's entry at an offset.
int vfs_finddir (struct vnode *dir, const char *name, struct dirent *dirent)
 Finds the entry of a directory that has a name.
int vfs_dir_empty (struct vnode *dir)
 Says whether a directory is empty, so that it can be removed.
int vfs_file_open (struct file *file)
 Opens a file whose vnode is set: a device's driver, a FIFO's pipe, or the filesystem opens it.
ssize_t vfs_file_read (struct file *file, struct iobuf *io)
 Reads from an open file, at its offset.
ssize_t vfs_file_write (struct file *file, struct iobuf *io)
 Writes to an open file, at its offset.
ssize_t vfs_file_readdir (struct file *file, struct dirent *dirent)
 Reads the next entry of an open directory.
off_t vfs_file_lseek (struct file *file, off_t offset, int whence)
 Moves an open file's offset.
ssize_t vfs_file_close (struct file *file)
 Closes an open file, when its last reference goes: its lock is released, then its socket, device or filesystem closes it.
int vfs_file_flock (struct file *file, int op)
 Takes, changes or releases an open file's lock.
void vfs_file_lock_release (struct file *file)
 Releases an open file's lock when the file is closed.
int vfs_file_ioctl (struct file *file, int request, void *argp)
 Passes an ioctl() request to an open file's device or filesystem.
int vfs_file_trunc (struct file *file, off_t len)
 Changes the length of an open file.
int vfs_file_can_read (struct file *file, size_t size)
 Says whether a read of an open file would go on without waiting, for poll() and select().
struct waitq * vfs_file_wait_queue (struct file *file, int write)
 Finds the wait queue that a reader (or a writer) of an open file sleeps on until it can go on, which poll() and select() wait on too.
int vfs_file_can_write (struct file *file, size_t size)
 Says whether a write to an open file would go on without waiting, for poll(), select() and non-blocking writes.
int vfs_file_eof (struct file *)
 Says whether an open file is at its end, so that a read returns 0 rather than waiting.
int vfs_lookup (const char *path, struct uio *uio, struct vnode **vnode)
 Finds the vnode a path names.
int vfs_lookup_parent (const char *path, struct uio *uio, struct vnode **dir, char **name)
 Finds the directory of a path's last component, and the component's name, to make or remove an entry there.
int vfs_lookup_dir (const char *path, struct uio *uio, struct vnode **vnode, struct vnode **dir)
 Finds the vnode a path names, as vfs_lookup() does, and the directory it was found in.
int vfs_parent (struct vnode *dir, struct vnode **parent)
 Finds a directory's parent in its own filesystem, through its .. entry.
struct vnode * vfs_mount_root_of (struct vnode *vnode)
 Finds the root of the mounted filesystem a vnode is in.
int vfs_under (struct vnode *vnode, struct vnode *dir)
 Says whether a vnode is a directory or under it, in the same filesystem: rename() can't move a directory under itself.
int vfs_vnode_path (struct vnode *vnode, struct vnode *root, char *buf, size_t size)
 Computes a vnode's path, for getcwd() and /proc/mounts: it goes up through .., and finds each directory's name in its parent.
int vfs_creat (const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
 Makes a regular file at a path.
int vfs_mkdir (const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
 Makes a directory at a path.
int vfs_mknod (const char *path, uint32_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
 Makes a node at a path.
int vfs_unlink (const char *path, struct uio *uio)
 Removes the name of a file (not a directory) at a path.
int vfs_rmdir (const char *path, struct uio *uio)
 Removes an empty directory at a path.
int vfs_link (const char *oldpath, struct uio *ouio, const char *newpath, struct uio *nuio)
 Makes a hard link: a new name for an existing file, in the same mounted filesystem.
int vfs_symlink (const char *target, const char *path, struct uio *uio)
 Makes a symbolic link.
ssize_t vfs_readlink (const char *path, struct uio *uio, char *buf, size_t size)
 Reads what a symbolic link contains.
int vfs_rename (const char *oldpath, struct uio *ouio, const char *newpath, struct uio *nuio)
 Renames a file or a directory, possibly to another directory of the same mounted filesystem.
int vfs_stat (struct vnode *vnode, struct aquila_stat *buf)
 Fills a stat structure with a vnode's attributes.
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).
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_chmod (struct vnode *vnode, mode_t mode, struct uio *uio)
 Changes a vnode's permission bits.
int vfs_chown (struct vnode *vnode, uid_t uid, gid_t gid, struct uio *uio)
 Changes a vnode's owner and group.
int vfs_utimens (struct vnode *vnode, const struct aquila_timespec times[2], struct uio *uio)
 Changes a vnode's access and modification times, for utimensat().

Variables

struct fs_list * registered_fs
 The installed filesystems.
struct vnode * vfs_root

Macro Definition Documentation

◆ FS_DSYNC

#define FS_DSYNC   0x0002

Definition at line 245 of file vfs.h.

◆ FS_MSYNC

#define FS_MSYNC   0x0001

Definition at line 244 of file vfs.h.

◆ ISDEV

#define ISDEV ( vnode)
Value:
(S_ISCHR((vnode)->mode) || S_ISBLK((vnode)->mode))
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113

Definition at line 209 of file vfs.h.

Referenced by posix_file_read(), vfs_file_can_read(), vfs_file_can_write(), vfs_file_close(), vfs_file_eof(), vfs_file_ioctl(), vfs_file_lseek(), vfs_file_open(), vfs_file_read(), vfs_file_trunc(), vfs_file_write(), vfs_ioctl(), vfs_map(), vfs_read_io(), vfs_trunc(), and vfs_write_io().

◆ VFS_R

#define VFS_R   4

Definition at line 295 of file vfs.h.

Referenced by do_faccessat(), and vfs_perms_check().

◆ VFS_W

#define VFS_W   2

◆ VFS_X

#define VFS_X   1

Function Documentation

◆ __vfs_can_always()

int __vfs_can_always ( struct file * f,
size_t s )
inlinestatic

Definition at line 203 of file vfs.h.

◆ __vfs_can_never()

int __vfs_can_never ( struct file * f,
size_t s )
inlinestatic

Definition at line 204 of file vfs.h.

◆ __vfs_eof_always()

int __vfs_eof_always ( struct file * f)
inlinestatic

Definition at line 205 of file vfs.h.

◆ __vfs_eof_never()

int __vfs_eof_never ( struct file * f)
inlinestatic

Definition at line 206 of file vfs.h.

◆ file_hold()

struct file * file_hold ( struct file * file)

Holds an open file for the current system call, until it returns.

Parameters
filethe file
Returns
file

Definition at line 82 of file file.c.

References curthread, file_hold(), file_ref(), thread::files, thread::files_held, panic, and THREAD_FILES_HELD.

Referenced by fd_file(), and file_hold().

◆ file_new()

struct file * file_new ( void )

Makes a new open file, with one reference.

Returns
the file, or NULL if there was no memory

Definition at line 32 of file file.c.

References file_new(), kmalloc(), M_ZERO, and file::ref.

Referenced by do_openat(), file_new(), sys_accept(), sys_pipe(), and sys_socket().

◆ file_put()

int file_put ( struct file * file)

Drops a reference to an open file.

The last one closes and frees it.

Parameters
filethe file
Returns
0, or what closing the file returned

Definition at line 60 of file file.c.

References file_put(), kfree(), panic, file::ref, and vfs_file_close().

Referenced by file_put(), proc_fd_close(), and thread_files_release().

◆ file_ref()

struct file * file_ref ( struct file * file)

Adds a reference to an open file.

Parameters
filethe file
Returns
file

Definition at line 48 of file file.c.

References file_ref(), and file::ref.

Referenced by copy_fds(), file_hold(), file_ref(), and sys_fcntl().

◆ LOGGER_DECLARE()

LOGGER_DECLARE ( vfs_log )

References LOGGER_DECLARE.

◆ 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_chmod()

int vfs_chmod ( struct vnode * vnode,
mode_t mode,
struct uio * uio )

Changes a vnode's permission bits.

Only its owner, or root, may do it.

Parameters
vnodethe vnode
modethe new permissions (the file type is kept)
uiowho is asking
Returns
0, -EPERM, or the filesystem's error

Definition at line 38 of file attr.c.

References vnode::ctime, gettime(), uio::gid, vnode::gid, vnode::mode, store(), uio::uid, vnode::uid, and vfs_chmod().

Referenced by do_fchmodat(), sys_fchmod(), and vfs_chmod().

◆ vfs_chown()

int vfs_chown ( struct vnode * vnode,
uid_t uid,
gid_t gid,
struct uio * uio )

Changes a vnode's owner and group.

Root may change both; a file's owner may only change its group, to their own group.

Parameters
vnodethe vnode
uidthe new owner, or (uid_t) -1 to keep it
gidthe new group, or (gid_t) -1 to keep it
uiowho is asking
Returns
0, -EPERM, or the filesystem's error

Definition at line 68 of file attr.c.

References vnode::ctime, gettime(), uio::gid, vnode::gid, vnode::mode, store(), uio::uid, vnode::uid, and vfs_chown().

Referenced by do_fchownat(), sys_fchown(), and vfs_chown().

◆ vfs_close()

int vfs_close ( struct vnode * vnode)

Drops a reference to a vnode.

When the last one goes, the filesystem's close operation releases it. Closing a vnode that has no references left is a bug, and panics.

Parameters
vnodethe vnode
Returns
0, -EINVAL if vnode isn't a valid vnode, or what the filesystem's close operation returns

Definition at line 18 of file close.c.

References vops::close, vnode::fs, LOG_DEBUG, panic, vnode::ref, vfs_close(), and fs::vops.

Referenced by binfmt_load(), creat_path(), cross_down(), ctty_open(), cwd_set(), do_faccessat(), do_fchmodat(), do_fchownat(), do_fstatat(), do_openat(), entry_remove(), exec_script(), ext2_vunlink(), pipefs_close(), pipefs_fifo_open(), posix_file_close(), proc_fork(), proc_kill(), ptmx_open(), pty_free(), socket_unix_bind(), socket_unix_connect(), socket_unix_shutdown(), sys_chdir(), sys_fchdir(), sys_utimensat(), vfs_close(), vfs_link(), vfs_lookup(), vfs_lookup_dir(), vfs_lookup_parent(), vfs_mknod(), vfs_mount(), vfs_mount_root_of(), vfs_parent(), vfs_readlink(), vfs_remove(), vfs_rename(), vfs_symlink(), vfs_under(), vfs_vnode_path(), vm_object_decref(), and walk().

◆ vfs_creat()

int vfs_creat ( const char * path,
mode_t mode,
struct uio * uio,
struct vnode ** ref )

Makes a regular file at a path.

Parameters
paththe new file's path
modeits permissions
uiowho is asking
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, or a negative errno

Definition at line 69 of file mknod.c.

References vnode::mode, vnode::ref, vfs_creat(), and vfs_mknod().

Referenced by do_openat(), and vfs_creat().

◆ vfs_dir_empty()

int vfs_dir_empty ( struct vnode * dir)

Says whether a directory is empty, so that it can be removed.

An empty directory has no entries besides . and ...

Parameters
dirthe directory
Returns
1 if it's empty, 0 if it isn't or it couldn't be read

Definition at line 69 of file readdir.c.

References vfs_dir_empty(), and vfs_readdir().

Referenced by vfs_dir_empty(), vfs_remove(), and vfs_rename().

◆ vfs_file_can_read()

int vfs_file_can_read ( struct file * file,
size_t size )

Says whether a read of an open file would go on without waiting, for poll() and select().

A regular file or a directory never waits.

Parameters
filethe open file
sizehow many bytes would be read
Returns
1 if it would, 0 if it would wait, or a negative errno

Definition at line 262 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, kdev_file_can_read(), socket_can_read(), vfs_file_can_read(), and VNODE_DEV.

Referenced by fd_ready(), and vfs_file_can_read().

◆ vfs_file_can_write()

int vfs_file_can_write ( struct file * file,
size_t size )

Says whether a write to an open file would go on without waiting, for poll(), select() and non-blocking writes.

A regular file never waits.

Parameters
filethe open file
sizehow many bytes would be written
Returns
1 if it would, 0 if it would wait, or a negative errno

Definition at line 295 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, kdev_file_can_write(), socket_can_write(), vfs_file_can_write(), and VNODE_DEV.

Referenced by fd_ready(), posix_file_write(), and vfs_file_can_write().

◆ vfs_file_close()

ssize_t vfs_file_close ( struct file * file)

Closes an open file, when its last reference goes: its lock is released, then its socket, device or filesystem closes it.

Parameters
filethe open file
Returns
0, or a negative errno

Definition at line 183 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, kdev_file_close(), posix_file_close(), socket_shutdown(), vfs_file_close(), vfs_file_lock_release(), and VNODE_DEV.

Referenced by file_put(), and vfs_file_close().

◆ vfs_file_eof()

int vfs_file_eof ( struct file * file)

Says whether an open file is at its end, so that a read returns 0 rather than waiting.

Parameters
filethe open file
Returns
1 at the end, 0 otherwise, or a negative errno

Definition at line 325 of file fops.c.

References ISDEV, kdev_file_eof(), vfs_file_eof(), and VNODE_DEV.

Referenced by posix_file_read(), posix_file_write(), and vfs_file_eof().

◆ vfs_file_flock()

int vfs_file_flock ( struct file * file,
int op )

Takes, changes or releases an open file's lock.

Taking a lock waits until no other open file holds a conflicting one, unless LOCK_NB is set.

Parameters
filethe open file
opLOCK_SH (shared), LOCK_EX (exclusive) or LOCK_UN (release), with LOCK_NB not to wait
Returns
0, -EWOULDBLOCK if LOCK_NB is set and it would wait, -EINVAL, -ENOMEM, or -ERESTARTSYS if a signal came while it waited

Definition at line 67 of file flock.c.

References FILE_SOCKET, file::flags, kmalloc(), file::lock, lock_conflicts(), lock_unlock(), locks, M_ZERO, file_lock::type, vfs_file_flock(), file_lock::vnode, waiters, waitq_sleep(), and waitq_wakeup().

Referenced by sys_flock(), and vfs_file_flock().

◆ vfs_file_ioctl()

int vfs_file_ioctl ( struct file * file,
int request,
void * argp )

Passes an ioctl() request to an open file's device or filesystem.

Parameters
filethe open file
requestthe request
argpits argument
Returns
the request's result, or a negative errno

Definition at line 111 of file fops.c.

References ISDEV, kdev_file_ioctl(), vfs_file_ioctl(), and VNODE_DEV.

Referenced by sys_ioctl(), and vfs_file_ioctl().

◆ vfs_file_lock_release()

void vfs_file_lock_release ( struct file * file)

Releases an open file's lock when the file is closed.

Parameters
filethe open file

Definition at line 119 of file flock.c.

References kfree(), file::lock, lock_unlock(), NULL, and vfs_file_lock_release().

Referenced by vfs_file_close(), and vfs_file_lock_release().

◆ vfs_file_lseek()

off_t vfs_file_lseek ( struct file * file,
off_t offset,
int whence )

Moves an open file's offset.

Parameters
filethe open file
offsetthe offset, or the distance to move it
whenceSEEK_SET, SEEK_CUR or SEEK_END
Returns
the new offset, -ESPIPE for a pipe, or a negative errno

Definition at line 136 of file fops.c.

References ISDEV, kdev_file_lseek(), vfs_file_lseek(), and VNODE_DEV.

Referenced by sys_lseek(), and vfs_file_lseek().

◆ vfs_file_open()

int vfs_file_open ( struct file * file)

Opens a file whose vnode is set: a device's driver, a FIFO's pipe, or the filesystem opens it.

Parameters
filethe file, its vnode and flags set
Returns
0, -EISDIR to write to a directory, -ENOSYS, or the open's error

Definition at line 22 of file fops.c.

References file::flags, ISDEV, kdev_file_open(), pipefs_fifo_open(), vfs_file_open(), and VNODE_DEV.

Referenced by do_openat(), and vfs_file_open().

◆ vfs_file_read()

ssize_t vfs_file_read ( struct file * file,
struct iobuf * io )

Reads from an open file, at its offset.

Parameters
filethe open file
iowhere the data goes, and how much is wanted
Returns
the number of bytes read, 0 at the end, -EISDIR for a directory, or a negative errno

Definition at line 52 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, kdev_file_read(), NULL, socket_recv(), vfs_file_read(), and VNODE_DEV.

Referenced by sys_read(), and vfs_file_read().

◆ vfs_file_readdir()

ssize_t vfs_file_readdir ( struct file * file,
struct dirent * dirent )

Reads the next entry of an open directory.

Parameters
filethe open directory
direntthe entry, filled in
Returns
1 if an entry was read, 0 at the end, -ENOTDIR, or a negative errno

Definition at line 162 of file fops.c.

References vfs_file_readdir().

Referenced by sys_readdir(), and vfs_file_readdir().

◆ vfs_file_trunc()

int vfs_file_trunc ( struct file * file,
off_t len )

Changes the length of an open file.

Parameters
filethe open file
lenthe new length, in bytes
Returns
0, -EINVAL for a socket or a device, or a negative errno

Definition at line 213 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, and vfs_file_trunc().

Referenced by posix_file_open(), sys_ftruncate(), and vfs_file_trunc().

◆ vfs_file_wait_queue()

struct waitq * vfs_file_wait_queue ( struct file * file,
int write )

Finds the wait queue that a reader (or a writer) of an open file sleeps on until it can go on, which poll() and select() wait on too.

A socket says which; a device's and a pipe's are their vnode's (see fs/posix/read.c and write.c).

Parameters
filethe open file
writewhether it's the writers' queue, rather than the readers'
Returns
the wait queue, or NULL if there's none to tell

Definition at line 243 of file fops.c.

References FILE_SOCKET, file::flags, NULL, socket_wait_queue(), and vfs_file_wait_queue().

Referenced by fd_watch(), and vfs_file_wait_queue().

◆ vfs_file_write()

ssize_t vfs_file_write ( struct file * file,
struct iobuf * io )

Writes to an open file, at its offset.

Parameters
filethe open file
iothe data, and how much of it
Returns
the number of bytes written, or a negative errno

Definition at line 83 of file fops.c.

References FILE_SOCKET, file::flags, ISDEV, kdev_file_write(), NULL, socket_send(), vfs_file_write(), and VNODE_DEV.

Referenced by sys_write(), and vfs_file_write().

◆ vfs_finddir()

int vfs_finddir ( struct vnode * dir,
const char * name,
struct dirent * dirent )

Finds the entry of a directory that has a name.

Parameters
dirthe directory
namethe name
direntthe entry, filled in
Returns
0, -ENOENT if there is no such entry, -ENOTDIR if dir isn't a directory, or another negative errno

Definition at line 46 of file readdir.c.

References vops::finddir, vnode::fs, LOG_DEBUG, vnode::mode, vfs_finddir(), and fs::vops.

Referenced by entry_get(), entry_name(), lookup_name(), vfs_finddir(), vfs_lookup_parent(), vfs_parent(), and vfs_remove().

◆ vfs_fssync()

int vfs_fssync ( struct vnode * super,
int mode )

Would write a filesystem's data and metadata to its disk.

Not implemented.

Parameters
superthe filesystem's root vnode
modewhat to sync
Returns
-ENOTSUP

Definition at line 31 of file sync.c.

References vfs_fssync().

Referenced by vfs_fssync().

◆ 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_ioctl()

int vfs_ioctl ( struct vnode * vnode,
unsigned long request,
void * argp )

Passes an ioctl() request to a vnode's device driver, or to its filesystem.

Parameters
vnodethe vnode
requestthe request
argpits argument, often a pointer to user memory
Returns
the request's result, -EINVAL for an invalid vnode, or -ENOSYS if its filesystem has no ioctl operation

Definition at line 19 of file ioctl.c.

References vnode::fs, vops::ioctl, ISDEV, kdev_ioctl(), LOG_DEBUG, vfs_ioctl(), VNODE_DEV, and fs::vops.

Referenced by posix_file_ioctl(), and vfs_ioctl().

◆ vfs_link()

int vfs_link ( const char * oldpath,
struct uio * ouio,
const char * newpath,
struct uio * nuio )

Makes a hard link: a new name for an existing file, in the same mounted filesystem.

Directories can't be linked.

Parameters
oldpaththe file's path, followed if it's a symbolic link unless ouio has O_NOFOLLOW
ouiowho is asking, and the directory oldpath is relative to
newpaththe new name's path
nuiowho is asking, and the directory newpath is relative to
Returns
0, -EPERM for a directory, -EEXIST, -EXDEV across filesystems, or another negative errno

Definition at line 24 of file link.c.

References kfree(), vnode::mode, NULL, vfs_access(), vfs_close(), vfs_link(), vfs_lookup_dir(), vfs_lookup_parent(), vfs_mount_root_of(), vfs_vlink(), VFS_W, and VFS_X.

Referenced by do_linkat(), and vfs_link().

◆ vfs_lookup()

int vfs_lookup ( const char * path,
struct uio * uio,
struct vnode ** ref )

Finds the vnode a path names.

A symbolic link at the end is followed, unless the uio has O_NOFOLLOW.

Parameters
paththe path
uiowho is asking, and where relative paths start
refif not NULL, set to the vnode (with a reference for the caller), on success only
Returns
0, -ENOENT, -ENOTDIR, -EACCES, -ELOOP, or another negative errno

Definition at line 349 of file lookup.c.

References LOG_DEBUG, NULL, vnode::ref, vfs_close(), vfs_lookup(), walk(), and walk_start().

Referenced by at_lookup(), binfmt_load(), creat_path(), do_openat(), exec_script(), ext2_mount(), minix_mount(), socket_unix_bind(), socket_unix_connect(), sys_chdir(), vfs_lookup(), vfs_mount(), and vfs_readlink().

◆ vfs_lookup_dir()

int vfs_lookup_dir ( const char * path,
struct uio * uio,
struct vnode ** ref,
struct vnode ** dir )

Finds the vnode a path names, as vfs_lookup() does, and the directory it was found in.

Parameters
paththe path
uiowho is asking, and where relative paths start
refset to the vnode (with a reference for the caller)
dirset to its directory (with a reference), or to the vnode again if the path ends with no name (/)
Returns
0, or a negative errno

Definition at line 381 of file lookup.c.

References NULL, vnode::ref, vfs_close(), vfs_lookup_dir(), vref(), walk(), and walk_start().

Referenced by vfs_link(), and vfs_lookup_dir().

◆ vfs_lookup_parent()

int vfs_lookup_parent ( const char * path,
struct uio * uio,
struct vnode ** dir,
char ** name )

Finds the directory of a path's last component, and the component's name, to make or remove an entry there.

Parameters
paththe path
uiowho is asking, and where relative paths start
dirset to the directory (with a reference for the caller)
nameset to the last component's name (the caller frees it)
Returns
0, -EBUSY if the path names a mount point (or /), -EINVAL if it ends with . or .., or another negative errno

Definition at line 414 of file lookup.c.

References vnode::covered, kfree(), vnode::mounted, NULL, vfs_close(), vfs_finddir(), vfs_lookup_parent(), vfs_vget(), walk(), WALK_PARENT, and walk_start().

Referenced by vfs_link(), vfs_lookup_parent(), vfs_mknod(), vfs_remove(), and vfs_rename().

◆ vfs_map()

int vfs_map ( struct vm_space * vm_space,
struct vm_entry * vm_entry )

Maps a file into an address space, for mmap(): a device's own mapping, or the filesystem's.

Parameters
vm_spacethe address space
vm_entrythe mapping, whose object is the file
Returns
0, -EINVAL if the mapping isn't of a file, -ENOSYS, or the filesystem's error

Definition at line 205 of file vops.c.

References vnode::fs, ISDEV, kdev_map(), vops::map, vm_object::p, vm_object::type, vfs_map(), vm_entry::vm_object, VMOBJ_FILE, VNODE_DEV, and fs::vops.

Referenced by sys_mmap(), and vfs_map().

◆ vfs_mkdir()

int vfs_mkdir ( const char * path,
mode_t mode,
struct uio * uio,
struct vnode ** ref )

Makes a directory at a path.

Parameters
paththe new directory's path
modeits permissions
uiowho is asking
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, or a negative errno

Definition at line 55 of file mknod.c.

References vnode::mode, vnode::ref, vfs_mkdir(), and vfs_mknod().

Referenced by vfs_mkdir().

◆ vfs_mknod()

int vfs_mknod ( const char * path,
mode_t mode,
dev_t dev,
struct uio * uio,
struct vnode ** ref )

Makes a node at a path.

The caller's umask applies to the mode (but not for a symbolic link), and it needs write and search permission on the directory.

Parameters
paththe new node's path
modeits type (S_IF*) and permissions
devits device number, for a device node
uiowho is asking (for permissions and the umask)
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, -EEXIST if something is there already, or a negative errno

Definition at line 21 of file mknod.c.

References kfree(), uio::mask, vnode::mode, NULL, vnode::ref, vfs_access(), vfs_close(), vfs_lookup_parent(), vfs_mknod(), vfs_vmknod(), VFS_W, and VFS_X.

Referenced by do_mknodat(), kmain(), socket_unix_bind(), vfs_creat(), vfs_mkdir(), vfs_mknod(), and vfs_symlink().

◆ vfs_mount()

int vfs_mount ( const char * type,
const char * dir,
int flags,
void * data,
struct uio * uio )

Mounts a filesystem of a type on a directory, for mount().

Parameters
typethe filesystem's name ("ext2", "procfs", ...)
dirthe directory's path
flagspassed on to the filesystem
datathe filesystem's arguments (its device, its options)
uiowho is asking
Returns
0, -EINVAL for an unknown type, -ENOTDIR, -EBUSY if something is mounted there already, or the filesystem's error

Definition at line 29 of file mount.c.

References vnode::covered, mountpoint::dev, kfree(), kmalloc(), vnode::mode, fs::mount, vnode::mounted, mounts, fs_list::next, NULL, mountpoint::options, mountpoint::path, registered_fs, mountpoint::type, vfs_close(), vfs_lookup(), vfs_mount(), and vfs_vnode_path().

Referenced by kmain(), sys_mount(), and vfs_mount().

◆ 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_mount_root_dev()

int vfs_mount_root_dev ( const char * name,
const char * type )

Mounts the root filesystem from a disk partition (the root=/dev/hda2 kernel argument).

There are no device nodes yet at boot, so the partition's vnode is made here, as the RAM disk's is.

Parameters
namethe partition's name, /dev/hda1 to /dev/hdd4
typethe filesystem's type (rootfstype=), or NULL for ext2
Returns
0, -ENODEV for a bad name, -EINVAL for an unknown type, or the filesystem's error

Definition at line 120 of file mount.c.

References devfs, kfree(), kmalloc(), fs::load, M_ZERO, fs::name, fs_list::next, NULL, printk(), vnode::rdev, registered_fs, root_dev(), vfs_mount_root(), and vfs_mount_root_dev().

Referenced by kmain(), and vfs_mount_root_dev().

◆ vfs_mount_root_of()

struct vnode * vfs_mount_root_of ( struct vnode * vnode)

Finds the root of the mounted filesystem a vnode is in.

Parameters
vnodethe vnode
Returns
the root (without a reference: the mount keeps one)

Definition at line 452 of file lookup.c.

References vnode::covered, vfs_close(), vfs_mount_root_of(), vfs_parent(), vfs_root, and vref().

Referenced by vfs_link(), vfs_mount_root_of(), and vfs_rename().

◆ vfs_pagein()

struct vm_page * vfs_pagein ( struct vnode * vnode,
off_t offset )

References vfs_pagein().

Referenced by vfs_pagein().

◆ vfs_parent()

int vfs_parent ( struct vnode * dir,
struct vnode ** ref )

Finds a directory's parent in its own filesystem, through its .. entry.

Parameters
dirthe directory
refset to the parent, with a reference for the caller, or to NULL at the filesystem's root
Returns
0, or a negative errno

Definition at line 80 of file lookup.c.

References NULL, vnode::ref, vfs_close(), vfs_finddir(), vfs_parent(), and vfs_vget().

Referenced by dotdot(), vfs_mount_root_of(), vfs_parent(), vfs_under(), and vfs_vnode_path().

◆ 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().

◆ vfs_read()

ssize_t vfs_read ( struct vnode * vnode,
off_t off,
size_t size,
void * buf )

Reads from a vnode into a kernel buffer.

Parameters
vnodethe vnode
offwhere to read from
sizehow many bytes to read
bufthe buffer
Returns
the number of bytes read, or a negative errno

Definition at line 52 of file read.c.

References iobuf_init(), vfs_read(), and vfs_read_io().

Referenced by binfmt_elf_check(), binfmt_elf_load_segments(), cpio_load(), exec_script(), ext2_io(), ext2_load(), link_path(), minix_block_read(), minix_inode_read(), minix_load(), vfs_read(), vfs_readlink(), vnode_page_in(), and vnode_pages_update().

◆ vfs_read_io()

ssize_t vfs_read_io ( struct vnode * vnode,
off_t off,
struct iobuf * io )

Reads from a vnode into an iobuf (user or kernel memory).

Parameters
vnodethe vnode
offwhere to read from
iowhere the data goes, and how much is wanted
Returns
the number of bytes read, -EINVAL for an invalid vnode, -ENOSYS if its filesystem can't read, or another negative errno

Definition at line 20 of file read.c.

References vnode::fs, ISDEV, kdev_read(), LOG_DEBUG, vops::read, iobuf::resid, vfs_read_io(), VNODE_DEV, and fs::vops.

Referenced by cpio_read(), posix_file_read(), vfs_read(), and vfs_read_io().

◆ vfs_readdir()

ssize_t vfs_readdir ( struct vnode * dir,
off_t off,
struct dirent * dirent )

Reads a directory's entry at an offset.

Offsets count entries, starting at 0.

Parameters
dirthe directory
offwhich entry
direntthe entry, filled in
Returns
1 if an entry was read (the offset to add to get the next one), 0 past the last entry, -ENOTDIR if dir isn't a directory, or another negative errno

Definition at line 19 of file readdir.c.

References vnode::fs, LOG_DEBUG, vnode::mode, vops::readdir, vfs_readdir(), and fs::vops.

Referenced by entry_name(), posix_file_readdir(), vfs_dir_empty(), and vfs_readdir().

◆ vfs_readlink()

ssize_t vfs_readlink ( const char * path,
struct uio * uio,
char * buf,
size_t size )

Reads what a symbolic link contains.

Parameters
paththe link's path (not followed)
uiowho is asking
bufwhere the contents go, not NUL-terminated
sizethe buffer's size
Returns
the number of bytes read, -EINVAL if path isn't a symbolic link, or a negative errno

Definition at line 105 of file link.c.

References uio::flags, MIN, vnode::mode, NULL, vnode::size, vfs_close(), vfs_lookup(), vfs_read(), and vfs_readlink().

Referenced by creat_path(), sys_readlinkat(), and vfs_readlink().

◆ vfs_rename()

int vfs_rename ( const char * oldpath,
struct uio * ouio,
const char * newpath,
struct uio * nuio )

Renames a file or a directory, possibly to another directory of the same mounted filesystem.

An entry at the new name is replaced: a file by a file, or an empty directory by a directory.

Parameters
oldpaththe path it has
ouiowho is asking, and the directory oldpath is relative to
newpaththe path it gets
nuiothe directory newpath is relative to
Returns
0, -ENOENT, -EXDEV, -EINVAL to move a directory into itself, -ENOTDIR, -EISDIR, -ENOTEMPTY, or another negative errno

Definition at line 154 of file link.c.

References entry_get(), kfree(), NULL, vfs_access(), vfs_close(), vfs_dir_empty(), vfs_lookup_parent(), vfs_mount_root_of(), vfs_rename(), vfs_under(), vfs_vrename(), VFS_W, and VFS_X.

Referenced by sys_renameat(), and vfs_rename().

◆ vfs_rmdir()

int vfs_rmdir ( const char * path,
struct uio * uio )

Removes an empty directory at a path.

Parameters
paththe path
uiowho is asking
Returns
0, -ENOTDIR, -ENOTEMPTY, or another negative errno

Definition at line 74 of file unlink.c.

References vfs_remove(), and vfs_rmdir().

Referenced by do_unlinkat(), and vfs_rmdir().

◆ vfs_setattr()

int vfs_setattr ( struct vnode * vnode)

Has the filesystem store a vnode's attributes (mode, owner, times) after they were changed in memory.

Parameters
vnodethe vnode
Returns
0, -ENOSYS if the filesystem can't, or its error

Definition at line 156 of file vops.c.

References vnode::fs, vops::setattr, vfs_setattr(), and fs::vops.

Referenced by store(), and vfs_setattr().

◆ vfs_stat()

int vfs_stat ( struct vnode * vnode,
struct aquila_stat * buf )

Fills a stat structure with a vnode's attributes.

Parameters
vnodethe vnode
bufthe structure to fill, in kernel memory
Returns
0

Definition at line 16 of file stat.c.

References vnode::atime, vnode::ctime, vnode::dev, vnode::gid, vnode::ino, LOG_DEBUG, vnode::mode, vnode::mtime, vnode::nlink, vnode::rdev, vnode::size, timespec::tv_nsec, timespec::tv_sec, vnode::uid, and vfs_stat().

Referenced by do_fstatat(), sys_fstat(), and vfs_stat().

◆ vfs_symlink()

int vfs_symlink ( const char * target,
const char * path,
struct uio * uio )

Makes a symbolic link.

Parameters
targetwhat the link contains (not checked: it may not exist)
paththe link's path
uiowho is asking
Returns
0, -ENOENT for an empty target, or a negative errno

Definition at line 72 of file link.c.

References NULL, vfs_close(), vfs_mknod(), vfs_symlink(), vfs_unlink(), and vfs_write().

Referenced by sys_symlinkat(), and vfs_symlink().

◆ vfs_sync()

int vfs_sync ( int mode)

Would write every filesystem's data and metadata to its disk.

Not implemented.

Parameters
modewhat to sync
Returns
-ENOTSUP

Definition at line 43 of file sync.c.

References vfs_sync().

Referenced by vfs_sync().

◆ vfs_trunc()

int vfs_trunc ( struct vnode * vnode,
off_t len )

Changes a file's length, through its filesystem.

The file's pages in the page cache between the old end and the new one are refreshed.

Parameters
vnodethe file
lenthe new length, in bytes
Returns
0, -EINVAL for a device or an invalid vnode, -ENOSYS if the filesystem can't truncate, or its error

Definition at line 19 of file trunc.c.

References vnode::fs, ISDEV, LOG_DEBUG, MAX, MIN, vnode::size, vops::trunc, vfs_trunc(), vnode_pages_update(), and fs::vops.

Referenced by posix_file_trunc(), and vfs_trunc().

◆ vfs_under()

int vfs_under ( struct vnode * vnode,
struct vnode * dir )

Says whether a vnode is a directory or under it, in the same filesystem: rename() can't move a directory under itself.

Parameters
vnodethe vnode
dirthe directory
Returns
1 if vnode is dir or under it, 0 otherwise

Definition at line 473 of file lookup.c.

References vfs_close(), vfs_parent(), vfs_under(), and vref().

Referenced by vfs_rename(), and vfs_under().

◆ vfs_unlink()

int vfs_unlink ( const char * path,
struct uio * uio )

Removes the name of a file (not a directory) at a path.

The file goes when its last name is removed and nothing has it open.

Parameters
paththe path
uiowho is asking
Returns
0, -EISDIR for a directory, or another negative errno

Definition at line 62 of file unlink.c.

References vfs_remove(), and vfs_unlink().

Referenced by do_unlinkat(), socket_unix_bind(), vfs_symlink(), and vfs_unlink().

◆ vfs_utimens()

int vfs_utimens ( struct vnode * vnode,
const struct aquila_timespec times[2],
struct uio * uio )

Changes a vnode's access and modification times, for utimensat().

Setting them to the current time needs ownership or write permission; setting them to other times needs ownership.

Parameters
vnodethe vnode
timesthe access and modification times (each may be UTIME_NOW or UTIME_OMIT), or NULL for now
uiowho is asking
Returns
0, -EINVAL for a bad time, -EPERM, -EACCES, or the filesystem's error

Definition at line 124 of file attr.c.

References vnode::atime, vnode::ctime, gettime(), vnode::mtime, NULL, set_time(), store(), uio::uid, vnode::uid, vfs_access(), vfs_utimens(), and VFS_W.

Referenced by sys_utimensat(), and vfs_utimens().

◆ vfs_vcreat()

int vfs_vcreat ( struct vnode * dir,
const char * name,
struct uio * uio,
struct vnode ** ref )

Makes a regular file in a directory, with no permissions set.

Parameters
dirthe directory
namethe new file's name
uiowho is asking
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, or a negative errno

Definition at line 52 of file vops.c.

References vfs_vcreat(), and vfs_vmknod().

Referenced by vfs_vcreat().

◆ vfs_vget()

int vfs_vget ( struct vnode * super,
ino_t ino,
struct vnode ** ref )

Gets the vnode of an inode, by its number.

On success it has a reference for the caller.

Parameters
superany vnode of the filesystem (it names the filesystem)
inothe inode number
refif not NULL, set to the vnode (the caller closes it)
Returns
0, -ENOSYS if the filesystem can't, or its error

Definition at line 176 of file vops.c.

References vnode::fs, vnode::ino, NULL, vnode::ref, vfs_vget(), vops::vget, and fs::vops.

Referenced by entry_get(), lookup_name(), vfs_lookup_parent(), vfs_parent(), vfs_remove(), and vfs_vget().

◆ vfs_vlink()

int vfs_vlink ( struct vnode * dir,
const char * fn,
struct vnode * vnode,
struct uio * uio )

Adds a name for an existing file (a hard link) to a directory of the same filesystem.

Parameters
dirthe directory
fnthe new name
vnodethe file
uiowho is asking
Returns
0, -EXDEV across filesystems, -ENOTDIR, -ENOSYS, or the filesystem's error

Definition at line 103 of file vops.c.

References vnode::fs, vnode::mode, vfs_vlink(), vops::vlink, and fs::vops.

Referenced by vfs_link(), and vfs_vlink().

◆ vfs_vmkdir()

int vfs_vmkdir ( struct vnode * dir,
const char * name,
struct uio * uio,
struct vnode ** ref )

Makes a directory in a directory, with no permissions set.

Parameters
dirthe directory
namethe new directory's name
uiowho is asking
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, or a negative errno

Definition at line 66 of file vops.c.

References vfs_vmkdir(), and vfs_vmknod().

Referenced by vfs_vmkdir().

◆ vfs_vmknod()

int vfs_vmknod ( struct vnode * dir,
const char * name,
mode_t mode,
dev_t dev,
struct uio * uio,
struct vnode ** ref )

Makes a node in a directory.

On success the new vnode has a reference for the caller.

Parameters
dirthe directory
namethe new node's name
modeits type (S_IF*) and permissions
devits device number, for a device node
uiowho is asking
refif not NULL, set to the new vnode (the caller closes it)
Returns
0, -ENOTDIR, -ENOSYS if the filesystem can't, or its error

Definition at line 22 of file vops.c.

References vnode::fs, vnode::mode, vfs_vmknod(), vops::vmknod, and fs::vops.

Referenced by pts_new(), vfs_mknod(), vfs_vcreat(), vfs_vmkdir(), and vfs_vmknod().

◆ vfs_vnode_path()

int vfs_vnode_path ( struct vnode * vnode,
struct vnode * root,
char * buf,
size_t size )

Computes a vnode's path, for getcwd() and /proc/mounts: it goes up through .., and finds each directory's name in its parent.

Parameters
vnodethe vnode
rootwhere the path starts, or NULL for the system's root
bufwhere the path goes
sizethe buffer's size
Returns
0, -ENOENT if a directory on the way was removed, -ERANGE if the path doesn't fit, or another negative errno

Definition at line 532 of file lookup.c.

References vnode::covered, entry_name(), memcpy(), memmove(), NAME_MAX, vnode::size, vfs_close(), vfs_parent(), vfs_root, vfs_vnode_path(), and vref().

Referenced by procfs_proc_status(), sys_getcwd(), vfs_mount(), and vfs_vnode_path().

◆ vfs_vrename()

int vfs_vrename ( struct vnode * odir,
const char * ofn,
struct vnode * ndir,
const char * nfn,
struct uio * uio )

Renames an entry, possibly to another directory of the same filesystem.

Parameters
odirthe directory it's in
ofnits name
ndirthe directory it goes to
nfnits new name
uiowho is asking
Returns
0, -EXDEV across filesystems, -ENOTDIR, -ENOSYS, or the filesystem's error

Definition at line 132 of file vops.c.

References vnode::fs, vnode::mode, vfs_vrename(), fs::vops, and vops::vrename.

Referenced by vfs_rename(), and vfs_vrename().

◆ vfs_vsync()

int vfs_vsync ( struct vnode * vnode,
int mode )

Would write a vnode's data and metadata to its disk.

Not implemented.

Parameters
vnodethe vnode
modewhat to sync
Returns
-ENOTSUP

Definition at line 18 of file sync.c.

References vfs_vsync().

Referenced by vfs_vsync().

◆ vfs_vunlink()

int vfs_vunlink ( struct vnode * dir,
const char * fn,
struct uio * uio )

Removes a name from a directory.

Parameters
dirthe directory
fnthe name
uiowho is asking
Returns
0, -ENOSYS if the filesystem can't, or its error

Definition at line 79 of file vops.c.

References vnode::fs, vfs_vunlink(), fs::vops, and vops::vunlink.

Referenced by pty_free(), vfs_remove(), and vfs_vunlink().

◆ vfs_write()

ssize_t vfs_write ( struct vnode * vnode,
off_t off,
size_t size,
void * buf )

Writes to a vnode from a kernel buffer.

Parameters
vnodethe vnode
offwhere to write
sizehow many bytes to write
bufthe buffer
Returns
the number of bytes written, or a negative errno

Definition at line 60 of file write.c.

References iobuf_init(), vfs_write(), and vfs_write_io().

Referenced by ext2_io(), minix_block_alloc(), minix_block_free(), minix_block_write(), minix_inode_alloc(), minix_inode_free(), minix_inode_write(), minix_superblock_rewrite(), vfs_symlink(), and vfs_write().

◆ vfs_write_io()

ssize_t vfs_write_io ( struct vnode * vnode,
off_t off,
struct iobuf * io )

Writes to a vnode from an iobuf (user or kernel memory).

The file's pages in the page cache, if it's mapped, are refreshed.

Parameters
vnodethe vnode
offwhere to write
iothe data, and how much of it
Returns
the number of bytes written, -EINVAL for an invalid vnode, -ENOSYS if its filesystem can't write, or another negative errno

Definition at line 22 of file write.c.

References vnode::fs, ISDEV, kdev_write(), LOG_DEBUG, iobuf::resid, vfs_write_io(), VNODE_DEV, vnode_pages_update(), fs::vops, and vops::write.

Referenced by posix_file_write(), vfs_write(), and vfs_write_io().

Variable Documentation

◆ registered_fs

struct fs_list* registered_fs
extern

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_root

struct vnode* vfs_root
extern