From 100d26f5046eae26b999a149c417022dd9fa2eed Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 12 Feb 2024 18:56:57 -0500 Subject: [PATCH] devfs: add devfs stubs --- fs/devfs.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ include/fs/devfs.h | 5 ++++ 2 files changed, 67 insertions(+) create mode 100644 fs/devfs.c create mode 100644 include/fs/devfs.h diff --git a/fs/devfs.c b/fs/devfs.c new file mode 100644 index 0000000..9c4f8c3 --- /dev/null +++ b/fs/devfs.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include +#include + +static int devfs_read(struct vnode *vnode, void *buf, size_t offset, size_t size) +{ + return 0; +} + +static int devfs_write(struct vnode *vnode, void *buf, size_t offset, size_t size) +{ + return 0; +} + +/* devfs does not support unlink */ +static int devfs_unlink(struct fs *fs, const char *path) +{ + return -EINVAL; +} + +/* vnodes are permanent and therefore these functions should never be called */ +static int devfs_open_vno(struct fs *fs, struct vnode *out, ino_t ino_num) +{ + return -EINVAL; +} + +static int devfs_readdir(struct vnode *vnode, struct dirent **dir) +{ + return -EINVAL; +} + +static int devfs_open_dir(struct fs *fs, struct vnode *out) +{ + return -EINVAL; +} + +void devfs_init() +{ + struct fs *fs = vfs_create(); + if (!fs) + goto out; + + struct fs_ops *ops = kmalloc(sizeof(struct fs_ops), ALLOC_KERN); + if (!ops) + goto out_ops; + + ops->read = devfs_read; + ops->write = devfs_write; + ops->unlink = devfs_unlink; + ops->open_vno = devfs_open_vno; + ops->readdir = devfs_readdir; + ops->open_dir = devfs_open_dir; + + return; + +out_ops: + vfs_dealloc(fs); +out: + kprintf(LOG_ERROR "devfs: failed to mount devfs\n"); + panic(); +} diff --git a/include/fs/devfs.h b/include/fs/devfs.h new file mode 100644 index 0000000..2452baa --- /dev/null +++ b/include/fs/devfs.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DEVFS_H_ +#define _DEVFS_H_ + +#endif /* _DEVFS_H_ */