From 673753e8befcfbb575380ed0d23fc6741b4e50a0 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 19 May 2024 23:05:21 -0400 Subject: kernel: vfs: Add support for open hook Signed-off-by: Ian Moffett --- sys/kern/kern_filedesc.c | 7 +++++-- sys/kern/vfs_subr.c | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c index 6bce6d2..74ab859 100644 --- a/sys/kern/kern_filedesc.c +++ b/sys/kern/kern_filedesc.c @@ -291,12 +291,15 @@ open(const char *pathname, int oflag) int status; /* - * Attempt to create a vnode and allocate a - * file descriptor + * Attempt to create a vnode, call the open hook then + * allocate a file descriptor */ if ((status = vfs_path_to_node(pathname, &vp)) != 0) { return status; } + if ((status = vfs_open(vp)) != 0) { + return status; + } if ((status = fd_alloc(this_td(), &fd)) != 0) { return status; } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 5b31057..f760831 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -239,3 +239,11 @@ vfs_getattr(struct vnode *vp, struct vattr *vattr) { return vp->vops->getattr(vp, vattr); } + +int vfs_open(struct vnode *vp) +{ + if (vp->vops->open == NULL) + return -EIO; + + return vp->vops->open(vp); +} -- cgit v1.2.3