diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-07 12:38:22 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-07 12:38:22 -0400 |
commit | eb2c3f0f8b2e50adc3f5e008d72c32a8a3059569 (patch) | |
tree | 11ada1ef8f6ab77016ff24200057587436e0ebb2 /src/sys/os | |
parent | a612e3237157e3141634951dc63048eab295e1e9 (diff) |
os: vnode: Add refcounts to vnodes
Keep track of how many referencing are on a vnode so one isn't freed
early while another object is still using it.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/os')
-rw-r--r-- | src/sys/os/vfs_subr.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/sys/os/vfs_subr.c b/src/sys/os/vfs_subr.c index 6cb542c..64c7492 100644 --- a/src/sys/os/vfs_subr.c +++ b/src/sys/os/vfs_subr.c @@ -29,6 +29,7 @@ #include <sys/types.h> #include <sys/errno.h> +#include <sys/atomic.h> #include <os/vnode.h> #include <os/kalloc.h> #include <os/vfs.h> @@ -77,6 +78,7 @@ vfs_valloc(struct vnode **resp, vtype_t type, int flags) } memset(vp, 0, sizeof(*vp)); + vp->refcount = 1; vp->type = type; *resp = vp; return 0; @@ -89,6 +91,9 @@ vfs_vrel(struct vnode *vp, int flags) return -EINVAL; } + if (atomic_dec_int(&vp->refcount) > 1) { + return 0; + } kfree(vp); return 0; } |