From 18e76c1d4cb4ef3f9be1db53b2b794d8f4c16de5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 27 Oct 2024 00:53:05 -0400 Subject: kernel: devfs: Add getattr vop for device files Signed-off-by: Ian Moffett --- sys/fs/devfs.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sys/fs') diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c index 81c2a43..75cf991 100644 --- a/sys/fs/devfs.c +++ b/sys/fs/devfs.c @@ -114,6 +114,33 @@ devfs_lookup(struct vop_lookup_args *args) return 0; } +static int +devfs_getattr(struct vop_getattr_args *args) +{ + struct vnode *vp; + struct vattr *attr; + struct devfs_node *dnp; + + vp = args->vp; + if ((dnp = vp->data) == NULL) { + return -EIO; + } + if ((attr = args->res) == NULL) { + return -EIO; + } + + /* + * Set stat attributes from device node structure + * found within vnode data. + * + * XXX: Device files have no fixed size, hence why + * size is hardwired to 0. + */ + attr->mode = dnp->mode; + attr->size = 0; + return 0; +} + static int devfs_reclaim(struct vnode *vp) { @@ -204,7 +231,8 @@ devfs_create_entry(const char *name, devmajor_t major, dev_t dev, mode_t mode) const struct vops g_devfs_vops = { .lookup = devfs_lookup, .reclaim = devfs_reclaim, - .read = devfs_read + .read = devfs_read, + .getattr = devfs_getattr }; const struct vfsops g_devfs_vfsops = { -- cgit v1.2.3