From d6104baa618686f7f0f0f36216394b60553ac14a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 21 May 2024 22:18:52 -0400 Subject: kernel: devfs: Add support for close hook Signed-off-by: Ian Moffett --- sys/fs/devfs.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'sys/fs') diff --git a/sys/fs/devfs.c b/sys/fs/devfs.c index d7944aa..7fcdbad 100644 --- a/sys/fs/devfs.c +++ b/sys/fs/devfs.c @@ -177,6 +177,26 @@ vop_open(struct vnode *vp) return dev->open(dev); } +static int +vop_close(struct vnode *vp) +{ + struct device_node *node; + struct device *dev; + + if (vp == NULL) { + return -EIO; + } + + node = vp->data; + dev = device_fetch(node->major, node->minor); + + if (dev->close == NULL) { + return -EIO; + } + + return dev->close(dev); +} + static int devfs_init(struct fs_info *info, struct vnode *source) { @@ -270,5 +290,6 @@ struct vfsops g_devfs_ops = { struct vops g_devfs_vops = { .vget = vop_vget, .read = vop_read, - .open = vop_open + .open = vop_open, + .close = vop_close }; -- cgit v1.2.3