From 691302ee1f22a5458c4dab3d5f85cc3de9332bb5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 18 Apr 2024 14:36:41 -0400 Subject: kernel: devfs: Add devfs_get_dev() Add helper to get a device descriptor from a vnode Signed-off-by: Ian Moffett --- sys/fs/devfs.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'sys/fs/devfs.c') diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c index 7e7fd9d..8b273db 100644 --- a/sys/fs/devfs.c +++ b/sys/fs/devfs.c @@ -199,6 +199,29 @@ devfs_add_dev(const char *name, const struct device *dev) return 0; } +/* + * Fetch a device descriptor from a vnode. + */ +int +devfs_get_dev(struct vnode *vp, struct device **res) +{ + struct device_node *n; + struct device *dev; + + /* Is this really a device? */ + if (vp->type != VBLK && vp->type != VCHR) { + return -ENODEV; + } + + n = vp->data; + if ((dev = device_fetch(n->major, n->minor)) == NULL) { + return -ENODEV; + } + + *res = dev; + return 0; +} + struct vfsops g_devfs_ops = { .init = devfs_init }; -- cgit v1.2.3