MOS Source Code
Loading...
Searching...
No Matches
vfs.c File Reference
#include "mos/assert.h"
#include "mos/device/timer.h"
#include "mos/filesystem/inode.h"
#include "mos/filesystem/mount.h"
#include "mos/filesystem/page_cache.h"
#include "mos/filesystem/sysfs/sysfs.h"
#include "mos/filesystem/sysfs/sysfs_autoinit.h"
#include "mos/mm/mm.h"
#include "mos/mm/mmstat.h"
#include "mos/mm/physical/pmm.h"
#include "mos/mm/slab_autoinit.h"
#include <dirent.h>
#include <errno.h>
#include <mos/filesystem/dentry.h>
#include <mos/filesystem/fs_types.h>
#include <mos/filesystem/vfs.h>
#include <mos/filesystem/vfs_types.h>
#include <mos/io/io.h>
#include <mos/lib/structures/list.h>
#include <mos/lib/structures/tree.h>
#include <mos/lib/sync/spinlock.h>
#include <mos/mos_global.h>
#include <mos/platform/platform.h>
#include <mos/syslog/printk.h>
#include <mos/tasks/process.h>
#include <mos/types.h>
#include <mos_stdlib.h>
#include <mos_string.h>
+ Include dependency graph for vfs.c:

Go to the source code of this file.

Functions

 SLAB_AUTOINIT ("superblock", superblock_cache, superblock_t)
 
 SLAB_AUTOINIT ("mount", mount_cache, mount_t)
 
 SLAB_AUTOINIT ("file", file_cache, file_t)
 
static long do_pagecache_flush (file_t *file, off_t pgoff, size_t npages)
 
static long do_sync_inode (file_t *file)
 
static void vfs_io_ops_close (io_t *io)
 
static void vfs_io_ops_close_dir (io_t *io)
 
static size_t vfs_io_ops_read (io_t *io, void *buf, size_t count)
 
static size_t vfs_io_ops_write (io_t *io, const void *buf, size_t count)
 
static off_t vfs_io_ops_seek (io_t *io, off_t offset, io_seek_whence_t whence)
 
static vmfault_result_t vfs_fault_handler (vmap_t *vmap, ptr_t fault_addr, pagefault_t *info)
 
static bool vfs_io_ops_mmap (io_t *io, vmap_t *vmap, off_t offset)
 
static bool vfs_io_ops_munmap (io_t *io, vmap_t *vmap, bool *unmapped)
 
static void vfs_io_ops_getname (const io_t *io, char *buf, size_t size)
 
static void vfs_flusher_entry (void *arg)
 
static void vfs_flusher_init (void)
 
 MOS_INIT (KTHREAD, vfs_flusher_init)
 
static void vfs_copy_stat (file_stat_t *statbuf, inode_t *inode)
 
static filesystem_tvfs_find_filesystem (const char *name)
 
static bool vfs_verify_permissions (dentry_t *file_dentry, bool open, bool read, bool create, bool execute, bool write)
 
static file_tvfs_do_open (dentry_t *base, const char *path, open_flags flags)
 
file_tvfs_do_open_dentry (dentry_t *entry, bool created, bool read, bool write, bool exec, bool truncate)
 Open an directory dentry.
 
void vfs_register_filesystem (filesystem_t *fs)
 
long vfs_mount (const char *device, const char *path, const char *fs, const char *options)
 Mount a filesystem at a given existing path.
 
long vfs_unmount (const char *path)
 Unmount a filesystem at a given path.
 
file_tvfs_openat (int fd, const char *path, open_flags flags)
 Open a file at a given path.
 
long vfs_fstatat (fd_t fd, const char *path, file_stat_t *restrict statbuf, fstatat_flags flags)
 Stat a file.
 
size_t vfs_readlinkat (fd_t dirfd, const char *path, char *buf, size_t size)
 Read a symbolic link.
 
long vfs_symlink (const char *path, const char *target)
 Create a symbolic link.
 
long vfs_mkdir (const char *path)
 Create a directory.
 
long vfs_rmdir (const char *path)
 
size_t vfs_list_dir (io_t *io, void *user_buf, size_t user_size)
 Get the content of a directory.
 
long vfs_chdirat (fd_t dirfd, const char *path)
 Change the current working directory.
 
ssize_t vfs_getcwd (char *buf, size_t size)
 Get the current working directory.
 
long vfs_fchmodat (fd_t fd, const char *path, int perm, int flags)
 Change the permissions of a file.
 
long vfs_unlinkat (fd_t dirfd, const char *path)
 Remove the name of a file, and possibly the file itself.
 
long vfs_fsync (io_t *io, bool sync_metadata, off_t start, off_t end)
 Synchronize a file with the filesystem.
 
static bool vfs_sysfs_filesystems (sysfs_file_t *f)
 
static bool vfs_sysfs_mountpoints (sysfs_file_t *f)
 
static void vfs_sysfs_dentry_stats_stat_receiver (int depth, const dentry_t *dentry, bool mountroot, void *data)
 
static bool vfs_sysfs_dentry_stats (sysfs_file_t *f)
 
 SYSFS_AUTOREGISTER (vfs, vfs_sysfs_items)
 

Variables

static list_head vfs_fs_list = LIST_HEAD_INIT(vfs_fs_list)
 
static spinlock_t vfs_fs_list_lock = SPINLOCK_INIT
 
dentry_troot_dentry = NULL
 
slab_tsuperblock_cache = NULL
 
slab_tmount_cache = NULL
 
slab_tfile_cache = NULL
 
static const io_op_t file_io_ops
 
static const io_op_t dir_io_ops
 
static sysfs_item_t vfs_sysfs_items []
 

Function Documentation

◆ SLAB_AUTOINIT() [1/3]

SLAB_AUTOINIT ( "superblock" ,
superblock_cache ,
superblock_t  )

◆ SLAB_AUTOINIT() [2/3]

SLAB_AUTOINIT ( "mount" ,
mount_cache ,
mount_t  )

◆ SLAB_AUTOINIT() [3/3]

SLAB_AUTOINIT ( "file" ,
file_cache ,
file_t  )

◆ do_pagecache_flush()

static long do_pagecache_flush ( file_t * file,
off_t pgoff,
size_t npages )
static

Definition at line 44 of file vfs.c.

Referenced by vfs_fsync(), and vfs_io_ops_close().

+ Here is the call graph for this function:

◆ do_sync_inode()

static long do_sync_inode ( file_t * file)
static

Definition at line 59 of file vfs.c.

Referenced by vfs_fsync(), and vfs_io_ops_close().

◆ vfs_io_ops_close()

static void vfs_io_ops_close ( io_t * io)
static

Definition at line 69 of file vfs.c.

Referenced by vfs_io_ops_close_dir().

+ Here is the call graph for this function:

◆ vfs_io_ops_close_dir()

static void vfs_io_ops_close_dir ( io_t * io)
static

Definition at line 93 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_io_ops_read()

static size_t vfs_io_ops_read ( io_t * io,
void * buf,
size_t count )
static

Definition at line 114 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_io_ops_write()

static size_t vfs_io_ops_write ( io_t * io,
const void * buf,
size_t count )
static

Definition at line 132 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_io_ops_seek()

static off_t vfs_io_ops_seek ( io_t * io,
off_t offset,
io_seek_whence_t whence )
static

Definition at line 147 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_fault_handler()

static vmfault_result_t vfs_fault_handler ( vmap_t * vmap,
ptr_t fault_addr,
pagefault_t * info )
static

Definition at line 186 of file vfs.c.

Referenced by vfs_io_ops_mmap().

+ Here is the call graph for this function:

◆ vfs_io_ops_mmap()

static bool vfs_io_ops_mmap ( io_t * io,
vmap_t * vmap,
off_t offset )
static

Definition at line 236 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_io_ops_munmap()

static bool vfs_io_ops_munmap ( io_t * io,
vmap_t * vmap,
bool * unmapped )
static

Definition at line 250 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_io_ops_getname()

static void vfs_io_ops_getname ( const io_t * io,
char * buf,
size_t size )
static

Definition at line 261 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_flusher_entry()

static void vfs_flusher_entry ( void * arg)
static

Definition at line 285 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_flusher_init()

static void vfs_flusher_init ( void )
static

Definition at line 295 of file vfs.c.

◆ MOS_INIT()

MOS_INIT ( KTHREAD ,
vfs_flusher_init  )

◆ vfs_copy_stat()

static void vfs_copy_stat ( file_stat_t * statbuf,
inode_t * inode )
static

Definition at line 301 of file vfs.c.

Referenced by vfs_fstatat().

◆ vfs_find_filesystem()

static filesystem_t * vfs_find_filesystem ( const char * name)
static

Definition at line 318 of file vfs.c.

Referenced by vfs_mount(), and vfs_register_filesystem().

+ Here is the call graph for this function:

◆ vfs_verify_permissions()

static bool vfs_verify_permissions ( dentry_t * file_dentry,
bool open,
bool read,
bool create,
bool execute,
bool write )
static

Definition at line 334 of file vfs.c.

Referenced by vfs_do_open().

◆ vfs_do_open()

static file_t * vfs_do_open ( dentry_t * base,
const char * path,
open_flags flags )
static

Definition at line 351 of file vfs.c.

Referenced by vfs_openat().

+ Here is the call graph for this function:

◆ vfs_sysfs_filesystems()

static bool vfs_sysfs_filesystems ( sysfs_file_t * f)
static

Definition at line 855 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_sysfs_mountpoints()

static bool vfs_sysfs_mountpoints ( sysfs_file_t * f)
static

Definition at line 865 of file vfs.c.

+ Here is the call graph for this function:

◆ vfs_sysfs_dentry_stats_stat_receiver()

static void vfs_sysfs_dentry_stats_stat_receiver ( int depth,
const dentry_t * dentry,
bool mountroot,
void * data )
static

Definition at line 877 of file vfs.c.

Referenced by vfs_sysfs_dentry_stats().

+ Here is the call graph for this function:

◆ vfs_sysfs_dentry_stats()

static bool vfs_sysfs_dentry_stats ( sysfs_file_t * f)
static

Definition at line 889 of file vfs.c.

+ Here is the call graph for this function:

◆ SYSFS_AUTOREGISTER()

SYSFS_AUTOREGISTER ( vfs ,
vfs_sysfs_items  )

Variable Documentation

◆ vfs_fs_list

list_head vfs_fs_list = LIST_HEAD_INIT(vfs_fs_list)
static

Definition at line 33 of file vfs.c.

Referenced by vfs_find_filesystem(), vfs_register_filesystem(), and vfs_sysfs_filesystems().

◆ vfs_fs_list_lock

spinlock_t vfs_fs_list_lock = SPINLOCK_INIT
static

Definition at line 34 of file vfs.c.

Referenced by vfs_find_filesystem(), and vfs_register_filesystem().

◆ superblock_cache

slab_t* superblock_cache = NULL

Definition at line 38 of file vfs.c.

Referenced by cpio_mount(), MOS_INIT(), and userfs_fsop_mount().

◆ mount_cache

slab_t * mount_cache = NULL

Definition at line 38 of file vfs.c.

Referenced by dentry_mount().

◆ file_cache

slab_t * file_cache = NULL

Definition at line 38 of file vfs.c.

Referenced by vfs_do_open_dentry().

◆ file_io_ops

const io_op_t file_io_ops
static
Initial value:
= {
.read = vfs_io_ops_read,
.write = vfs_io_ops_write,
.close = vfs_io_ops_close,
.seek = vfs_io_ops_seek,
.mmap = vfs_io_ops_mmap,
.munmap = vfs_io_ops_munmap,
.get_name = vfs_io_ops_getname,
}
static bool vfs_io_ops_mmap(io_t *io, vmap_t *vmap, off_t offset)
Definition vfs.c:236
static size_t vfs_io_ops_read(io_t *io, void *buf, size_t count)
Definition vfs.c:114
static void vfs_io_ops_close(io_t *io)
Definition vfs.c:69
static off_t vfs_io_ops_seek(io_t *io, off_t offset, io_seek_whence_t whence)
Definition vfs.c:147
static bool vfs_io_ops_munmap(io_t *io, vmap_t *vmap, bool *unmapped)
Definition vfs.c:250
static size_t vfs_io_ops_write(io_t *io, const void *buf, size_t count)
Definition vfs.c:132
static void vfs_io_ops_getname(const io_t *io, char *buf, size_t size)
Definition vfs.c:261

Definition at line 267 of file vfs.c.

Referenced by vfs_do_open_dentry().

◆ dir_io_ops

const io_op_t dir_io_ops
static
Initial value:
= {
.read = vfs_list_dir,
.get_name = vfs_io_ops_getname,
}
size_t vfs_list_dir(io_t *io, void *user_buf, size_t user_size)
Get the content of a directory.
Definition vfs.c:713
static void vfs_io_ops_close_dir(io_t *io)
Definition vfs.c:93

Definition at line 277 of file vfs.c.

Referenced by vfs_do_open_dentry().

◆ vfs_sysfs_items

sysfs_item_t vfs_sysfs_items[]
static
Initial value:
= {
}
#define SYSFS_RO_ITEM(_name, _show_fn)
Definition sysfs.h:48
static bool vfs_sysfs_dentry_stats(sysfs_file_t *f)
Definition vfs.c:889
static bool vfs_sysfs_filesystems(sysfs_file_t *f)
Definition vfs.c:855
static bool vfs_sysfs_mountpoints(sysfs_file_t *f)
Definition vfs.c:865

Definition at line 895 of file vfs.c.