Module Name:    src
Committed By:   dholland
Date:           Mon Oct  8 23:43:33 UTC 2012

Modified Files:
        src/sys/kern: vfs_lookup.c
        src/sys/sys: namei.src

Log Message:
Add namei-level support for openat() and friends. The way you do it is
by calling NDAT(&nd, dirvp) after NDINIT().

Right now the implementation is vile and unspeakable to avoid changing
the kernel ABI; this way we can get openat() and friends into 6.1. I
will rectify the mess and bump the kernel once things are working.


To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/kern/vfs_lookup.c
cvs rdiff -u -r1.25 -r1.26 src/sys/sys/namei.src

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.193 src/sys/kern/vfs_lookup.c:1.194
--- src/sys/kern/vfs_lookup.c:1.193	Mon Oct  8 23:41:39 2012
+++ src/sys/kern/vfs_lookup.c	Mon Oct  8 23:43:33 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.193 2012/10/08 23:41:39 dholland Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.194 2012/10/08 23:43:33 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.193 2012/10/08 23:41:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.194 2012/10/08 23:43:33 dholland Exp $");
 
 #include "opt_magiclinks.h"
 
@@ -1468,10 +1468,20 @@ int
 namei(struct nameidata *ndp)
 {
 	struct namei_state state;
+	struct vnode *forcecwd;
 	int error;
 
+	if (ndp->ni_cnd.cn_flags & DIDNDAT) {
+		/* Gross. This is done this way so it can go into 6.1. */
+		forcecwd = ndp->ni_dvp;
+		ndp->ni_dvp = NULL;
+		KASSERT(forcecwd != NULL);
+	} else {
+		forcecwd = NULL;
+	}
+
 	namei_init(&state, ndp);
-	error = namei_tryemulroot(&state, NULL,
+	error = namei_tryemulroot(&state, forcecwd,
 				  0/*!neverfollow*/, 0/*!inhibitmagic*/,
 				  0/*isnfsd*/);
 	namei_cleanup(&state);
@@ -1504,6 +1514,8 @@ lookup_for_nfsd(struct nameidata *ndp, s
 	struct namei_state state;
 	int error;
 
+	KASSERT((ndp->ni_cnd.cn_flags & DIDNDAT) == 0); /* not allowed */
+
 	namei_init(&state, ndp);
 	error = namei_tryemulroot(&state, forcecwd,
 				  neverfollow, 1/*inhibitmagic*/, 1/*isnfsd*/);
@@ -1612,6 +1624,8 @@ lookup_for_nfsd_index(struct nameidata *
 	struct namei_state state;
 	int error;
 
+	KASSERT((ndp->ni_cnd.cn_flags & DIDNDAT) == 0); /* not allowed */
+
 	/*
 	 * Note: the name sent in here (is not|should not be) allowed
 	 * to contain a slash.

Index: src/sys/sys/namei.src
diff -u src/sys/sys/namei.src:1.25 src/sys/sys/namei.src:1.26
--- src/sys/sys/namei.src:1.25	Fri Nov 25 16:51:43 2011
+++ src/sys/sys/namei.src	Mon Oct  8 23:43:33 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: namei.src,v 1.25 2011/11/25 16:51:43 dholland Exp $	*/
+/*	$NetBSD: namei.src,v 1.26 2012/10/08 23:43:33 dholland Exp $	*/
 
 /*
  * Copyright (c) 1985, 1989, 1991, 1993
@@ -144,8 +144,9 @@ NAMEIFL	NOFOLLOW	0x00000000	/* do not fo
 					   (pseudo) */
 NAMEIFL	EMULROOTSET	0x00000080	/* emulation root already
 					   in ni_erootdir */
+NAMEIFL DIDNDAT		0x00000400	/* did NDAT() (temporary) */
 NAMEIFL	NOCHROOT	0x01000000	/* no chroot on abs path lookups */
-NAMEIFL	MODMASK		0x010000fc	/* mask of operational modifiers */
+NAMEIFL	MODMASK		0x010004fc	/* mask of operational modifiers */
 /*
  * Namei parameter descriptors.
  */
@@ -163,7 +164,7 @@ NAMEIFL	INRELOOKUP	0x0800000	/* set whil
 NAMEIFL	PARAMASK	0x0eee300	/* mask of parameter descriptors */
 
 /*
- * Initialization of an nameidata structure.
+ * Initialization of a nameidata structure.
  */
 #define NDINIT(ndp, op, flags, pathbuf) { \
 	(ndp)->ni_cnd.cn_nameiop = op; \
@@ -171,6 +172,15 @@ NAMEIFL	PARAMASK	0x0eee300	/* mask of pa
 	(ndp)->ni_pathbuf = pathbuf; \
 	(ndp)->ni_cnd.cn_cred = kauth_cred_get(); \
 }
+
+/*
+ * Use this to set the start directory for openat()-type operations.
+ */
+#define NDAT(ndp, dir) {			\
+	(ndp)->ni_cnd.cn_flags |= DIDNDAT;	\
+	(ndp)->ni_dvp = (dir);			\
+}
+
 #endif
 
 /*

Reply via email to