summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-21 22:15:27 -0400
committerIan Moffett <ian@osmora.org>2024-05-21 22:15:27 -0400
commit9a4ec7539041f9ff25b947b2716aded028c0291f (patch)
tree2873062f44972cc4e023df8a481357cb9288802d
parent8d49b45994abba0257a2ae351297bea33d51c07a (diff)
kernel: vfs: Add support for close VOP
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/vfs.h1
-rw-r--r--sys/include/sys/vnode.h1
-rw-r--r--sys/kern/kern_filedesc.c4
-rw-r--r--sys/kern/vfs_subr.c9
4 files changed, 15 insertions, 0 deletions
diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h
index 98aef3f..1f7e423 100644
--- a/sys/include/sys/vfs.h
+++ b/sys/include/sys/vfs.h
@@ -60,6 +60,7 @@ ssize_t vfs_write(struct vnode *vp, struct sio_txn *sio);
int vfs_getattr(struct vnode *vp, struct vattr *vattr);
int vfs_open(struct vnode *vp);
+int vfs_close(struct vnode *vp);
uint64_t sys_mount(struct syscall_args *args);
#endif /* defined(_KERNEL) */
diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h
index 71fc5c2..8201f94 100644
--- a/sys/include/sys/vnode.h
+++ b/sys/include/sys/vnode.h
@@ -45,6 +45,7 @@ struct vops {
int(*write)(struct vnode *vp, struct sio_txn *sio);
int(*getattr)(struct vnode *vp, struct vattr *vattr);
int(*open)(struct vnode *vp);
+ int(*close)(struct vnode *vp);
};
struct vattr {
diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c
index 74ab859..ec0aee7 100644
--- a/sys/kern/kern_filedesc.c
+++ b/sys/kern/kern_filedesc.c
@@ -211,6 +211,10 @@ fd_close_fdnum(struct proc *td, int fdno)
return;
}
+ if (fd->vnode != NULL) {
+ vfs_close(fd->vnode);
+ }
+
dynfree(fd);
td->fds[fdno] = NULL;
}
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index f760831..60afa31 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -247,3 +247,12 @@ int vfs_open(struct vnode *vp)
return vp->vops->open(vp);
}
+
+int
+vfs_close(struct vnode *vp)
+{
+ if (vp->vops->close == NULL)
+ return -EIO;
+
+ return vp->vops->close(vp);
+}