Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add namei-level support for openat() and friends. The wa...



details:   https://anonhg.NetBSD.org/src/rev/b6c50e6d16cc
branches:  trunk
changeset: 781947:b6c50e6d16cc
user:      dholland <dholland%NetBSD.org@localhost>
date:      Mon Oct 08 23:43:33 2012 +0000

description:
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.

diffstat:

 sys/kern/vfs_lookup.c |  20 +++++++++++++++++---
 sys/sys/namei.src     |  16 +++++++++++++---
 2 files changed, 30 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r 402c3848b79f -r b6c50e6d16cc sys/kern/vfs_lookup.c
--- a/sys/kern/vfs_lookup.c     Mon Oct 08 23:41:39 2012 +0000
+++ b/sys/kern/vfs_lookup.c     Mon Oct 08 23:43:33 2012 +0000
@@ -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 @@
 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 @@
        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 @@
        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.
diff -r 402c3848b79f -r b6c50e6d16cc sys/sys/namei.src
--- a/sys/sys/namei.src Mon Oct 08 23:41:39 2012 +0000
+++ b/sys/sys/namei.src Mon Oct 08 23:43:33 2012 +0000
@@ -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 @@
                                           (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        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 @@
        (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
 
 /*



Home | Main Index | Thread Index | Old Index