|
PatchworkOS
|
#include <kernel/fs/vfs.h>#include "sys/list.h"#include <kernel/cpu/syscalls.h>#include <kernel/fs/dentry.h>#include <kernel/fs/inode.h>#include <kernel/fs/key.h>#include <kernel/fs/mount.h>#include <kernel/fs/path.h>#include <kernel/fs/sysfs.h>#include <kernel/fs/vfs_ctx.h>#include <kernel/log/log.h>#include <kernel/log/panic.h>#include <kernel/mem/vmm.h>#include <kernel/proc/process.h>#include <kernel/sched/sched.h>#include <kernel/sched/timer.h>#include <kernel/sched/wait.h>#include <kernel/sync/mutex.h>#include <kernel/sync/rwlock.h>#include <kernel/utils/ref.h>#include <kernel/cpu/regs.h>#include <assert.h>#include <errno.h>#include <stdint.h>#include <string.h>#include <sys/io.h>Go to the source code of this file.
Data Structures | |
| struct | vfs_poll_ctx_t |
Functions | |
| static | _Atomic (uint64_t) |
| static map_key_t | dentry_cache_key (dentry_id_t parentId, const char *name) |
| static void | vfs_list_init (vfs_list_t *list) |
| static void | vfs_map_init (vfs_map_t *map) |
| void | vfs_init (void) |
| Initializes the VFS. | |
| uint64_t | vfs_get_new_id (void) |
| Generates a new unique ID. | |
| uint64_t | vfs_register_fs (filesystem_t *fs) |
| Registers a filesystem. | |
| uint64_t | vfs_unregister_fs (filesystem_t *fs) |
| Unregisters a filesystem. | |
| filesystem_t * | vfs_get_fs (const char *name) |
| Gets a filesystem by name. | |
| inode_t * | vfs_get_inode (superblock_t *superblock, inode_number_t number) |
| Get an inode for the given superblock and inode number. | |
| static dentry_t * | vfs_get_dentry_internal (map_key_t *key) |
| dentry_t * | vfs_get_dentry (const dentry_t *parent, const char *name) |
| Get a dentry for the given name. Will NOT traverse mountpoints. | |
| dentry_t * | vfs_get_or_lookup_dentry (const path_t *parent, const char *name) |
| Get or lookup a dentry for the given name. Will NOT traverse mountpoints. | |
| uint64_t | vfs_add_inode (inode_t *inode) |
| Add a inode to the inode cache. | |
| uint64_t | vfs_add_dentry (dentry_t *dentry) |
| Add a dentry to the dentry cache. | |
| void | vfs_remove_superblock (superblock_t *superblock) |
| Remove a superblock from the superblock list. | |
| void | vfs_remove_inode (inode_t *inode) |
| Remove an inode from the inode cache. | |
| void | vfs_remove_dentry (dentry_t *dentry) |
| Remove a dentry from the dentry cache. | |
| dentry_t * | vfs_get_root_dentry (void) |
| uint64_t | vfs_walk (path_t *outPath, const pathname_t *pathname, walk_flags_t flags, process_t *process) |
| Walk a pathname to a path, starting from the current process's working directory. | |
| uint64_t | vfs_walk_parent (path_t *outPath, const pathname_t *pathname, char *outLastName, walk_flags_t flags, process_t *process) |
| Walk a pathname to its parent path, starting from the current process's working directory. | |
| uint64_t | vfs_walk_parent_and_child (path_t *outParent, path_t *outChild, const pathname_t *pathname, walk_flags_t flags, process_t *process) |
| Walk a pathname to path and its parent path, starting from the current process's working directory. | |
| bool | vfs_is_name_valid (const char *name) |
| Check if a name is valid. | |
| static uint64_t | vfs_create (path_t *outPath, const pathname_t *pathname, process_t *process) |
| static uint64_t | vfs_open_lookup (path_t *outPath, const pathname_t *pathname, process_t *process) |
| file_t * | vfs_open (const pathname_t *pathname, process_t *process) |
| Open a file. | |
| SYSCALL_DEFINE (SYS_OPEN, fd_t, const char *pathString) | |
| uint64_t | vfs_open2 (const pathname_t *pathname, file_t *files[2], process_t *process) |
| Open one file, returning two file handles. | |
| SYSCALL_DEFINE (SYS_OPEN2, uint64_t, const char *pathString, fd_t fds[2]) | |
| uint64_t | vfs_read (file_t *file, void *buffer, uint64_t count) |
| Read from a file. | |
| SYSCALL_DEFINE (SYS_READ, uint64_t, fd_t fd, void *buffer, uint64_t count) | |
| uint64_t | vfs_write (file_t *file, const void *buffer, uint64_t count) |
| Write to a file. | |
| SYSCALL_DEFINE (SYS_WRITE, uint64_t, fd_t fd, const void *buffer, uint64_t count) | |
| uint64_t | vfs_seek (file_t *file, int64_t offset, seek_origin_t origin) |
| Seek in a file. | |
| SYSCALL_DEFINE (SYS_SEEK, uint64_t, fd_t fd, int64_t offset, seek_origin_t origin) | |
| uint64_t | vfs_ioctl (file_t *file, uint64_t request, void *argp, uint64_t size) |
| Perform an ioctl operation on a file. | |
| SYSCALL_DEFINE (SYS_IOCTL, uint64_t, fd_t fd, uint64_t request, void *argp, uint64_t size) | |
| void * | vfs_mmap (file_t *file, void *address, uint64_t length, pml_flags_t flags) |
| Memory map a file. | |
| SYSCALL_DEFINE (SYS_MMAP, void *, fd_t fd, void *address, uint64_t length, prot_t prot) | |
| static uint64_t | vfs_poll_ctx_init (vfs_poll_ctx_t *ctx, poll_file_t *files, uint64_t amount) |
| static uint64_t | vfs_poll_ctx_check_events (vfs_poll_ctx_t *ctx, poll_file_t *files, uint64_t amount) |
| uint64_t | vfs_poll (poll_file_t *files, uint64_t amount, clock_t timeout) |
| Poll multiple files. | |
| SYSCALL_DEFINE (SYS_POLL, uint64_t, pollfd_t *fds, uint64_t amount, clock_t timeout) | |
| uint64_t | vfs_getdents (file_t *file, dirent_t *buffer, uint64_t count) |
| Get directory entries from a directory file. | |
| SYSCALL_DEFINE (SYS_GETDENTS, uint64_t, fd_t fd, dirent_t *buffer, uint64_t count) | |
| uint64_t | vfs_stat (const pathname_t *pathname, stat_t *buffer, process_t *process) |
| Get file information. | |
| SYSCALL_DEFINE (SYS_STAT, uint64_t, const char *pathString, stat_t *buffer) | |
| uint64_t | vfs_link (const pathname_t *oldPathname, const pathname_t *newPathname, process_t *process) |
| Make the same file appear twice in the filesystem. | |
| SYSCALL_DEFINE (SYS_LINK, uint64_t, const char *oldPathString, const char *newPathString) | |
| uint64_t | vfs_remove (const pathname_t *pathname, process_t *process) |
| Remove a file or directory. | |
| SYSCALL_DEFINE (SYS_REMOVE, uint64_t, const char *pathString) | |
|
static |
Definition at line 54 of file vfs.c.
References buffer, map_key_buffer(), MAX_NAME, memset(), and strncpy_s().
Referenced by vfs_add_dentry(), vfs_get_dentry(), vfs_get_or_lookup_dentry(), and vfs_remove_dentry().
| SYSCALL_DEFINE | ( | SYS_GETDENTS | , |
| uint64_t | , | ||
| fd_t | fd, | ||
| dirent_t * | buffer, | ||
| uint64_t | count | ||
| ) |
Definition at line 1201 of file vfs.c.
References buffer, count, DEREF_DEFER, ERR, file, NULL, thread_t::process, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_t::userStack, vfs_ctx_get_file(), vfs_getdents(), and process_t::vfsCtx.
Definition at line 868 of file vfs.c.
References DEREF_DEFER, ERR, file, NULL, thread_t::process, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_t::userStack, vfs_ctx_get_file(), vfs_ioctl(), and process_t::vfsCtx.
Definition at line 1357 of file vfs.c.
References ERR, thread_t::process, sched_thread(), thread_copy_from_user_pathname(), and vfs_link().
Definition at line 918 of file vfs.c.
References address, DEREF_DEFER, EINVAL, ERR, errno, file, NULL, PML_NONE, PML_USER, sched_process(), process_t::space, space_check_access(), vfs_ctx_get_file(), vfs_mmap(), process_t::vfsCtx, and vmm_prot_to_flags().
Definition at line 572 of file vfs.c.
References DEREF_DEFER, ERR, file, NULL, thread_t::process, sched_thread(), thread_copy_from_user_pathname(), vfs_ctx_alloc_fd(), vfs_open(), and process_t::vfsCtx.
Definition at line 646 of file vfs.c.
References DEREF_DEFER, EINVAL, ERR, errno, files, NULL, thread_t::process, sched_thread(), thread_copy_from_user_pathname(), thread_copy_to_user(), vfs_ctx_alloc_fd(), vfs_ctx_free_fd(), vfs_open2(), and process_t::vfsCtx.
Definition at line 1109 of file vfs.c.
References CONFIG_MAX_FD, DEREF, EBADF, EFAULT, EINVAL, ERR, errno, pollfd_t::events, pollfd_t::fd, file, files, NULL, POLLNONE, POLLNVAL, thread_t::process, pollfd_t::revents, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_t::userStack, vfs_ctx_get_file(), vfs_poll(), and process_t::vfsCtx.
Definition at line 727 of file vfs.c.
References buffer, count, DEREF_DEFER, ERR, file, NULL, thread_t::process, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_t::userStack, vfs_ctx_get_file(), vfs_read(), and process_t::vfsCtx.
| SYSCALL_DEFINE | ( | SYS_REMOVE | , |
| uint64_t | , | ||
| const char * | pathString | ||
| ) |
Definition at line 1427 of file vfs.c.
References ERR, thread_t::process, sched_thread(), thread_copy_from_user_pathname(), and vfs_remove().
| SYSCALL_DEFINE | ( | SYS_SEEK | , |
| uint64_t | , | ||
| fd_t | fd, | ||
| int64_t | offset, | ||
| seek_origin_t | origin | ||
| ) |
Definition at line 825 of file vfs.c.
References DEREF_DEFER, ERR, file, NULL, sched_process(), vfs_ctx_get_file(), vfs_seek(), and process_t::vfsCtx.
Definition at line 1261 of file vfs.c.
References buffer, ERR, thread_t::process, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_copy_from_user_pathname(), thread_t::userStack, and vfs_stat().
Definition at line 786 of file vfs.c.
References buffer, count, DEREF_DEFER, ERR, file, NULL, thread_t::process, sched_thread(), process_t::space, space_pin(), space_unpin(), thread_t::userStack, vfs_ctx_get_file(), vfs_write(), and process_t::vfsCtx.
|
static |
Definition at line 423 of file vfs.c.
References assert, atomic_load, inode_ops_t::create, path_t::dentry, DENTRY_NEGATIVE, EEXIST, EIO, EISDIR, ENOSYS, ENOTDIR, ERR, errno, pathname_t::flags, dentry_t::inode, INODE_DIR, INODE_FILE, MAX_NAME, inode_t::mutex, MUTEX_SCOPE, NULL, inode_t::ops, path_copy(), PATH_DEFER, PATH_DIRECTORY, PATH_EMPTY, PATH_EXCLUSIVE, RFLAGS_INTERRUPT_ENABLE, rflags_read(), inode_t::type, vfs_walk_parent_and_child(), and WALK_NEGATIVE_IS_OK.
Referenced by vfs_open_lookup().
Definition at line 195 of file vfs.c.
References atomic_load, CONTAINER_OF_SAFE, ref_t::count, ENOENT, errno, ESTALE, vfs_map_t::lock, vfs_map_t::map, map_get(), NULL, dentry_t::ref, REF, and RWLOCK_READ_SCOPE.
Referenced by vfs_get_dentry(), and vfs_get_or_lookup_dentry().
|
static |
Definition at line 68 of file vfs.c.
References vfs_list_t::list, list_init(), vfs_list_t::lock, and rwlock_init().
Referenced by vfs_init().
|
static |
Definition at line 74 of file vfs.c.
References ERR, map, map_init(), NULL, panic(), and rwlock_init().
Referenced by vfs_init().
|
static |
Definition at line 490 of file vfs.c.
References path_t::dentry, EISDIR, ENOENT, ENOTDIR, ERR, errno, pathname_t::flags, dentry_t::inode, INODE_DIR, INODE_FILE, NULL, path_copy(), PATH_CREATE, PATH_DEFER, PATH_DIRECTORY, PATH_EMPTY, inode_t::type, vfs_create(), vfs_walk(), and WALK_NONE.
Referenced by vfs_open(), and vfs_open2().
|
static |
Definition at line 990 of file vfs.c.
References EIO, ERR, errno, file, files, vfs_poll_ctx_t::lookupTable, NULL, POLL_SPECIAL, POLLNONE, and vfs_poll_ctx_t::queues.
Referenced by vfs_poll().
|
static |
Definition at line 952 of file vfs.c.
References CONFIG_MAX_FD, ERR, file, files, vfs_poll_ctx_t::lookupTable, memset(), NULL, POLLNONE, vfs_poll_ctx_t::queueAmount, and vfs_poll_ctx_t::queues.
Referenced by vfs_poll().