|
AquilaOS documentation
How it works, and its code
|
#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 |
| #define ISDEV | ( | vnode | ) |
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().
| #define VFS_R 4 |
Definition at line 295 of file vfs.h.
Referenced by do_faccessat(), and vfs_perms_check().
| #define VFS_W 2 |
Definition at line 296 of file vfs.h.
Referenced by do_faccessat(), vfs_link(), vfs_mknod(), vfs_perms_check(), vfs_remove(), vfs_rename(), and vfs_utimens().
| #define VFS_X 1 |
Definition at line 297 of file vfs.h.
Referenced by binfmt_load(), cwd_set(), do_faccessat(), exec_script(), vfs_access(), vfs_link(), vfs_mknod(), vfs_perms_check(), vfs_remove(), vfs_rename(), and walk().
Holds an open file for the current system call, until it returns.
| file | the 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().
| struct file * file_new | ( | void | ) |
Makes a new open file, with one reference.
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().
| int file_put | ( | struct file * | file | ) |
Drops a reference to an open file.
The last one closes and frees it.
| file | the file |
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().
Adds a reference to an open file.
| file | the 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 | ( | vfs_log | ) |
References LOGGER_DECLARE.
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.
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().
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.
| dir | the directory to mount on |
| root | the root directory of the filesystem to mount |
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().
Changes a vnode's permission bits.
Only its owner, or root, may do it.
| vnode | the vnode |
| mode | the new permissions (the file type is kept) |
| uio | who is asking |
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().
Changes a vnode's owner and group.
Root may change both; a file's owner may only change its group, to their own group.
| vnode | the vnode |
| uid | the new owner, or (uid_t) -1 to keep it |
| gid | the new group, or (gid_t) -1 to keep it |
| uio | who is asking |
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().
| 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.
| vnode | the vnode |
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().
Makes a regular file at a path.
| path | the new file's path |
| mode | its permissions |
| uio | who is asking |
| ref | if not NULL, set to the new vnode (the caller closes it) |
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().
| 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 ...
| dir | the directory |
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().
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.
| file | the open file |
| size | how many bytes would be read |
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().
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.
| file | the open file |
| size | how many bytes would be written |
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().
Closes an open file, when its last reference goes: its lock is released, then its socket, device or filesystem closes it.
| file | the open file |
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().
| 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.
| file | the open file |
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().
| 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.
| file | the open file |
| op | LOCK_SH (shared), LOCK_EX (exclusive) or LOCK_UN (release), with LOCK_NB not to wait |
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().
| int vfs_file_ioctl | ( | struct file * | file, |
| int | request, | ||
| void * | argp ) |
Passes an ioctl() request to an open file's device or filesystem.
| file | the open file |
| request | the request |
| argp | its argument |
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().
| void vfs_file_lock_release | ( | struct file * | file | ) |
Releases an open file's lock when the file is closed.
| file | the 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().
Moves an open file's offset.
| file | the open file |
| offset | the offset, or the distance to move it |
| whence | SEEK_SET, SEEK_CUR or SEEK_END |
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().
| 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.
| file | the file, its vnode and flags set |
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().
Reads from an open file, at its offset.
| file | the open file |
| io | where the data goes, and how much is wanted |
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().
Reads the next entry of an open directory.
| file | the open directory |
| dirent | the entry, filled in |
Definition at line 162 of file fops.c.
References vfs_file_readdir().
Referenced by sys_readdir(), and vfs_file_readdir().
Changes the length of an open file.
| file | the open file |
| len | the new length, in bytes |
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().
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).
| file | the open file |
| write | whether it's the writers' queue, rather than the readers' |
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().
Writes to an open file, at its offset.
| file | the open file |
| io | the data, and how much of it |
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().
| int vfs_finddir | ( | struct vnode * | dir, |
| const char * | name, | ||
| struct dirent * | dirent ) |
Finds the entry of a directory that has a name.
| dir | the directory |
| name | the name |
| dirent | the entry, filled in |
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().
| int vfs_fssync | ( | struct vnode * | super, |
| int | mode ) |
Would write a filesystem's data and metadata to its disk.
Not implemented.
| super | the filesystem's root vnode |
| mode | what to sync |
Definition at line 31 of file sync.c.
References vfs_fssync().
Referenced by vfs_fssync().
| 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().
| int vfs_install | ( | struct fs * | fs | ) |
Installs a filesystem, so that it can be mounted by name.
| fs | the filesystem |
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().
| 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.
| vnode | the vnode |
| request | the request |
| argp | its argument, often a pointer to user memory |
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().
Makes a hard link: a new name for an existing file, in the same mounted filesystem.
Directories can't be linked.
| oldpath | the file's path, followed if it's a symbolic link unless ouio has O_NOFOLLOW |
| ouio | who is asking, and the directory oldpath is relative to |
| newpath | the new name's path |
| nuio | who is asking, and the directory newpath is relative to |
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().
Finds the vnode a path names.
A symbolic link at the end is followed, unless the uio has O_NOFOLLOW.
| path | the path |
| uio | who is asking, and where relative paths start |
| ref | if not NULL, set to the vnode (with a reference for the caller), on success only |
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().
| 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.
| path | the path |
| uio | who is asking, and where relative paths start |
| ref | set to the vnode (with a reference for the caller) |
| dir | set to its directory (with a reference), or to the vnode again if the path ends with no name (/) |
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().
Finds the directory of a path's last component, and the component's name, to make or remove an entry there.
| path | the path |
| uio | who is asking, and where relative paths start |
| dir | set to the directory (with a reference for the caller) |
| name | set to the last component's name (the caller frees it) |
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().
Maps a file into an address space, for mmap(): a device's own mapping, or the filesystem's.
| vm_space | the address space |
| vm_entry | the mapping, whose object is the file |
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().
Makes a directory at a path.
| path | the new directory's path |
| mode | its permissions |
| uio | who is asking |
| ref | if not NULL, set to the new vnode (the caller closes it) |
Definition at line 55 of file mknod.c.
References vnode::mode, vnode::ref, vfs_mkdir(), and vfs_mknod().
Referenced by vfs_mkdir().
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.
| path | the new node's path |
| mode | its type (S_IF*) and permissions |
| dev | its device number, for a device node |
| uio | who is asking (for permissions and the umask) |
| ref | if not NULL, set to the new vnode (the caller closes it) |
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().
| 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().
| type | the filesystem's name ("ext2", "procfs", ...) |
| dir | the directory's path |
| flags | passed on to the filesystem |
| data | the filesystem's arguments (its device, its options) |
| uio | who is asking |
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().
| int vfs_mount_root | ( | struct vnode * | vnode | ) |
Makes a vnode the root of the filesystem tree.
| vnode | the root directory of a filesystem |
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().
| 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.
| name | the partition's name, /dev/hda1 to /dev/hdd4 |
| type | the filesystem's type (rootfstype=), or NULL for ext2 |
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().
Finds the root of the mounted filesystem a vnode is in.
| vnode | the vnode |
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().
References vfs_pagein().
Referenced by vfs_pagein().
Finds a directory's parent in its own filesystem, through its .. entry.
| dir | the directory |
| ref | set to the parent, with a reference for the caller, or to NULL at the filesystem's root |
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().
Checks whether a user may open a file the way it's being opened (read, write, execute, as its flags say).
| file | the file being opened, its flags set |
| uio | who is opening it |
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().
Reads from a vnode into a kernel buffer.
| vnode | the vnode |
| off | where to read from |
| size | how many bytes to read |
| buf | the buffer |
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().
Reads from a vnode into an iobuf (user or kernel memory).
| vnode | the vnode |
| off | where to read from |
| io | where the data goes, and how much is wanted |
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().
Reads a directory's entry at an offset.
Offsets count entries, starting at 0.
| dir | the directory |
| off | which entry |
| dirent | the entry, filled in |
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().
Reads what a symbolic link contains.
| path | the link's path (not followed) |
| uio | who is asking |
| buf | where the contents go, not NUL-terminated |
| size | the buffer's size |
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().
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.
| oldpath | the path it has |
| ouio | who is asking, and the directory oldpath is relative to |
| newpath | the path it gets |
| nuio | the directory newpath is relative to |
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().
| int vfs_rmdir | ( | const char * | path, |
| struct uio * | uio ) |
Removes an empty directory at a path.
| path | the path |
| uio | who is asking |
Definition at line 74 of file unlink.c.
References vfs_remove(), and vfs_rmdir().
Referenced by do_unlinkat(), and vfs_rmdir().
| int vfs_setattr | ( | struct vnode * | vnode | ) |
Has the filesystem store a vnode's attributes (mode, owner, times) after they were changed in memory.
| vnode | the vnode |
Definition at line 156 of file vops.c.
References vnode::fs, vops::setattr, vfs_setattr(), and fs::vops.
Referenced by store(), and vfs_setattr().
| int vfs_stat | ( | struct vnode * | vnode, |
| struct aquila_stat * | buf ) |
Fills a stat structure with a vnode's attributes.
| vnode | the vnode |
| buf | the structure to fill, in kernel memory |
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().
| int vfs_symlink | ( | const char * | target, |
| const char * | path, | ||
| struct uio * | uio ) |
Makes a symbolic link.
| target | what the link contains (not checked: it may not exist) |
| path | the link's path |
| uio | who is asking |
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().
| int vfs_sync | ( | int | mode | ) |
Would write every filesystem's data and metadata to its disk.
Not implemented.
| mode | what to sync |
Definition at line 43 of file sync.c.
References vfs_sync().
Referenced by vfs_sync().
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.
| vnode | the file |
| len | the new length, in bytes |
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().
Says whether a vnode is a directory or under it, in the same filesystem: rename() can't move a directory under itself.
| vnode | the vnode |
| dir | the directory |
Definition at line 473 of file lookup.c.
References vfs_close(), vfs_parent(), vfs_under(), and vref().
Referenced by vfs_rename(), and vfs_under().
| 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.
| path | the path |
| uio | who is asking |
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().
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.
| vnode | the vnode |
| times | the access and modification times (each may be UTIME_NOW or UTIME_OMIT), or NULL for now |
| uio | who is asking |
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().
Makes a regular file in a directory, with no permissions set.
| dir | the directory |
| name | the new file's name |
| uio | who is asking |
| ref | if not NULL, set to the new vnode (the caller closes it) |
Definition at line 52 of file vops.c.
References vfs_vcreat(), and vfs_vmknod().
Referenced by vfs_vcreat().
Gets the vnode of an inode, by its number.
On success it has a reference for the caller.
| super | any vnode of the filesystem (it names the filesystem) |
| ino | the inode number |
| ref | if not NULL, set to the vnode (the caller closes it) |
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().
Adds a name for an existing file (a hard link) to a directory of the same filesystem.
| dir | the directory |
| fn | the new name |
| vnode | the file |
| uio | who is asking |
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().
Makes a directory in a directory, with no permissions set.
| dir | the directory |
| name | the new directory's name |
| uio | who is asking |
| ref | if not NULL, set to the new vnode (the caller closes it) |
Definition at line 66 of file vops.c.
References vfs_vmkdir(), and vfs_vmknod().
Referenced by vfs_vmkdir().
| 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.
| dir | the directory |
| name | the new node's name |
| mode | its type (S_IF*) and permissions |
| dev | its device number, for a device node |
| uio | who is asking |
| ref | if not NULL, set to the new vnode (the caller closes it) |
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().
Computes a vnode's path, for getcwd() and /proc/mounts: it goes up through .., and finds each directory's name in its parent.
| vnode | the vnode |
| root | where the path starts, or NULL for the system's root |
| buf | where the path goes |
| size | the buffer's size |
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().
| 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.
| odir | the directory it's in |
| ofn | its name |
| ndir | the directory it goes to |
| nfn | its new name |
| uio | who is asking |
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().
| int vfs_vsync | ( | struct vnode * | vnode, |
| int | mode ) |
Would write a vnode's data and metadata to its disk.
Not implemented.
| vnode | the vnode |
| mode | what to sync |
Definition at line 18 of file sync.c.
References vfs_vsync().
Referenced by vfs_vsync().
Removes a name from a directory.
| dir | the directory |
| fn | the name |
| uio | who is asking |
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().
Writes to a vnode from a kernel buffer.
| vnode | the vnode |
| off | where to write |
| size | how many bytes to write |
| buf | the buffer |
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().
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.
| vnode | the vnode |
| off | where to write |
| io | the data, and how much of it |
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().
|
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().
|
extern |
Definition at line 29 of file vfs.c.
Referenced by sched_init_spawn(), vfs_bind(), vfs_mount_root(), vfs_mount_root_of(), vfs_vnode_path(), and walk_root().