22#include <aquila/dirent.h>
48#include <aquila/errno.h>
79 int (*
finddir) (
struct vnode *dir,
const char *name,
struct dirent *dirent);
209#define ISDEV(vnode) (S_ISCHR((vnode)->mode) || S_ISBLK((vnode)->mode))
217int vfs_mount(
const char *type,
const char *dir,
int flags,
void *data,
struct uio *
uio);
244#define FS_MSYNC 0x0001
245#define FS_DSYNC 0x0002
287int vfs_link(
const char *oldpath,
struct uio *ouio,
const char *newpath,
struct uio *nuio);
290int vfs_rename(
const char *oldpath,
struct uio *ouio,
const char *newpath,
struct uio *nuio);
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().
int vfs_chmod(struct vnode *vnode, mode_t mode, struct uio *uio)
Changes a vnode's permission bits.
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
struct file * file_hold(struct file *file)
Holds an open file for the current system call, until it returns.
struct file * file_new(void)
Makes a new open file, with one reference.
int file_put(struct file *file)
Drops a reference to an open file.
struct file * file_ref(struct file *file)
Adds a reference to an open file.
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_open(struct file *file)
Opens a file whose vnode is set: a device's driver, a FIFO's pipe, or the filesystem opens it.
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.
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,...
off_t vfs_file_lseek(struct file *file, off_t offset, int whence)
Moves an open file's offset.
ssize_t vfs_file_readdir(struct file *file, struct dirent *dirent)
Reads the next entry of an open directory.
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().
ssize_t vfs_file_close(struct file *file)
Closes an open file, when its last reference goes: its lock is released, then its socket,...
ssize_t vfs_file_write(struct file *file, struct iobuf *io)
Writes to an open file, at its offset.
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_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-blocki...
ssize_t vfs_file_read(struct file *file, struct iobuf *io)
Reads from an open file, at its offset.
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.
#define MALLOC_DECLARE(type)
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_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.
ssize_t vfs_readlink(const char *path, struct uio *uio, char *buf, size_t size)
Reads what a symbolic link contains.
int vfs_symlink(const char *target, const char *path, struct uio *uio)
Makes a symbolic link.
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.
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 ...
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 direct...
int vfs_lookup(const char *path, struct uio *uio, struct vnode **ref)
Finds the vnode a path names.
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 directo...
int vfs_parent(struct vnode *dir, struct vnode **ref)
Finds a directory's parent in its own filesystem, through its .. entry.
int vfs_mknod(const char *path, mode_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
Makes a node 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_creat(const char *path, mode_t mode, struct uio *uio, struct vnode **ref)
Makes a regular file at a path.
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_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().
#define LOGGER_DECLARE(name)
ssize_t vfs_read(struct vnode *vnode, off_t off, size_t size, void *buf)
Reads from a vnode into a kernel buffer.
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).
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.
ssize_t vfs_readdir(struct vnode *dir, off_t off, struct dirent *dirent)
Reads a directory's entry at an offset.
int vfs_stat(struct vnode *vnode, struct aquila_stat *buf)
Fills a stat structure with a vnode's attributes.
unsigned long long int uint64_t
A device driver: its operations, any of which may be NULL.
An open file (POSIX's "open file description", fs/file.c).
An open file's operations.
int(*) ioctl(struct file *file, int request, void *argp)
int(*) close(struct file *file)
int(*) can_read(struct file *file, size_t size)
int(*) trunc(struct file *file, off_t len)
uint64_t(*) read_timeout(struct file *)
ssize_t(*) read(struct file *file, struct iobuf *io)
off_t(*) lseek(struct file *file, off_t offset, int whence)
ssize_t(*) write(struct file *file, struct iobuf *io)
int(*) open(struct file *file)
int(*) eof(struct file *)
ssize_t(*) readdir(struct file *file, struct dirent *dirent)
int(*) can_write(struct file *file, size_t size)
The list of registered filesystem types.
struct fs_list * next
the next entry of the list
const char * name
the type's name
int(*) mount(struct vnode *dir, int flags, void *data)
int(*) load(struct vnode *dev, struct vnode **super)
A mount's description, as /proc/mounts shows it.
A pipe, or a FIFO's pipe.
Who does a filesystem operation: where its paths start, and its credentials and umask.
A mapping (map entry): a range of an address space, its permissions, and where its pages come from.
A page of physical memory (pages[] has one for every page of RAM).
An address space: its mappings, and its page tables.
A file in memory (a vnode): what its inode says, and the kernel's own state.
struct waitq * write_queue
size_t ref
how many references there are to it
struct vm_object * vm_object
its vm object: its pages, read in (the page cache)
struct waitq * read_queue
where its readers and writers sleep
void * p
the filesystem's own data
struct pipe * fifo
the pipe of a FIFO while it is open
struct vnode * mounted
for a directory that a filesystem is mounted on, that filesystem's root; for a mounted filesystem's r...
A filesystem's vnode operations, any of which may be NULL.
int(*) setattr(struct vnode *vnode)
int(*) close(struct vnode *vnode)
int(*) vmknod(struct vnode *dir, const char *fn, uint32_t mode, dev_t dev, struct uio *uio, struct vnode **ref)
int(*) finddir(struct vnode *dir, const char *name, struct dirent *dirent)
int(*) sync(struct vnode *super, int mode)
int(*) vget(struct vnode *super, ino_t ino, struct vnode **vnode)
int(*) vrename(struct vnode *odir, const char *ofn, struct vnode *ndir, const char *nfn, struct uio *uio)
int(*) trunc(struct vnode *vnode, off_t len)
int(*) vunlink(struct vnode *dir, const char *fn, struct uio *uio)
ssize_t(*) write(struct vnode *vnode, off_t offset, struct iobuf *io)
int(*) map(struct vm_space *vm_space, struct vm_entry *vm_entry)
ssize_t(*) read(struct vnode *vnode, off_t offset, struct iobuf *io)
ssize_t(*) readdir(struct vnode *dir, off_t offset, struct dirent *dirent)
int(*) vsync(struct vnode *vnode, int mode)
int(*) ioctl(struct vnode *vnode, int request, void *argp)
int(*) vlink(struct vnode *dir, const char *fn, struct vnode *vnode, struct uio *uio)
int vfs_sync(int mode)
Would write every filesystem's data and metadata to its disk.
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_trunc(struct vnode *vnode, off_t len)
Changes a file's length, through its filesystem.
int vfs_rmdir(const char *path, struct uio *uio)
Removes an empty directory 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_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_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,...
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,...
int vfs_mount_root(struct vnode *vnode)
Makes a vnode the root of the filesystem tree.
struct fs_list * registered_fs
The installed filesystems.
int vfs_install(struct fs *fs)
Installs a filesystem, so that it can be mounted by name.
void vfs_init(void)
Sets up the VFS at boot.
static int __vfs_can_never(struct file *f, size_t s)
static int __vfs_can_always(struct file *f, size_t s)
static int __vfs_eof_never(struct file *f)
struct vm_page * vfs_pagein(struct vnode *vnode, off_t offset)
static int __vfs_eof_always(struct file *f)
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.
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.
int vfs_vget(struct vnode *super, ino_t ino, struct vnode **ref)
Gets the vnode of an inode, by its number.
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_vunlink(struct vnode *dir, const char *fn, struct uio *uio)
Removes a name from a directory.
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_vcreat(struct vnode *dir, const char *name, struct uio *uio, struct vnode **ref)
Makes a regular file in a directory, with no permissions set.
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.
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.
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).
ssize_t vfs_write(struct vnode *vnode, off_t off, size_t size, void *buf)
Writes to a vnode from a kernel buffer.