From a3ca97d24953f7d72dc26d0627d03b673335acee Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 22 Nov 2025 17:42:50 -0500 Subject: kern: vfs: Add NAMEI_PARENT flag to NAMEI This flag allows one to get the vnode of the parent component rather than the last Signed-off-by: Ian Moffett --- sys/inc/kern/namei.h | 2 ++ sys/kern/kern_namei.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/inc/kern/namei.h b/sys/inc/kern/namei.h index a9fba7f..5dbf5ad 100644 --- a/sys/inc/kern/namei.h +++ b/sys/inc/kern/namei.h @@ -33,6 +33,8 @@ #include #include +#define NAMEI_PARENT BIT(0) + /* * Represents arguments to be passed with namei() */ diff --git a/sys/kern/kern_namei.c b/sys/kern/kern_namei.c index cc11116..703cebb 100644 --- a/sys/kern/kern_namei.c +++ b/sys/kern/kern_namei.c @@ -38,6 +38,7 @@ namei(struct nameidata *ndp) struct vops *vops; struct mount *mpoint = NULL; struct vnode *vp = NULL; + struct vnode *parent = NULL; const char *p; int error; char namebuf[NAME_MAX]; @@ -88,8 +89,13 @@ namei(struct nameidata *ndp) continue; } + parent = vp; vops = &vp->vops; error = vnode_lookup(vp, namebuf, &vp); + if (error != 0 && ISSET(ndp->flags, NAMEI_PARENT)) { + break; + } + if (error != 0) { return error; } @@ -97,6 +103,10 @@ namei(struct nameidata *ndp) namebuf_idx = 0; } - *ndp->vp_res = vp; + if (ISSET(ndp->flags, NAMEI_PARENT)) { + *ndp->vp_res = parent; + } else { + *ndp->vp_res = vp; + } return 0; } -- cgit v1.2.3