aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-21 22:18:52 -0400
committerIan Moffett <ian@osmora.org>2024-05-21 22:18:52 -0400
commitd6104baa618686f7f0f0f36216394b60553ac14a (patch)
tree8b99695f0f57dc45c3bbdb2b142d8ed6aedf56fd
parent8fdacd25827ea30aa71ea14f9ac52ea3d01d3701 (diff)
kernel: devfs: Add support for close hook
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/fs/devfs.c23
-rw-r--r--sys/include/sys/device.h1
2 files changed, 23 insertions, 1 deletions
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
@@ -178,6 +178,26 @@ vop_open(struct vnode *vp)
}
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)
{
if (source != NULL)
@@ -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
};
diff --git a/sys/include/sys/device.h b/sys/include/sys/device.h
index 69e367f..1bca4a8 100644
--- a/sys/include/sys/device.h
+++ b/sys/include/sys/device.h
@@ -43,6 +43,7 @@ struct device {
int(*read)(struct device *dev, struct sio_txn *sio);
int(*ioctl)(struct device *dev, uint32_t cmd, uintptr_t arg);
int(*open)(struct device *dev);
+ int(*close)(struct device *dev);
paddr_t(*mmap)(struct device *dev, off_t off, vm_prot_t prot);
TAILQ_ENTRY(device) link;
};