Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Adjust namei internals to be able to make an extern...



details:   https://anonhg.NetBSD.org/src/rev/0192b643b66b
branches:  trunk
changeset: 984261:0192b643b66b
user:      dholland <dholland%NetBSD.org@localhost>
date:      Tue Jun 29 22:29:59 2021 +0000

description:
Adjust namei internals to be able to make an external call to parse
the pathname. (Basically, this means change the signature of
namei_getcomponent(), and thus lookup_parsepath(), to pass in the
directory vnode and to allow failures.)

diffstat:

 sys/kern/vfs_lookup.c |  46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diffs (126 lines):

diff -r 928672cea937 -r 0192b643b66b sys/kern/vfs_lookup.c
--- a/sys/kern/vfs_lookup.c     Tue Jun 29 21:33:08 2021 +0000
+++ b/sys/kern/vfs_lookup.c     Tue Jun 29 22:29:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_lookup.c,v 1.226 2021/06/16 01:51:57 dholland Exp $        */
+/*     $NetBSD: vfs_lookup.c,v 1.227 2021/06/29 22:29:59 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.226 2021/06/16 01:51:57 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.227 2021/06/29 22:29:59 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_magiclinks.h"
@@ -229,16 +229,19 @@
  * Find the end of the first path component in NAME and return its
  * length.
  */
-static size_t
-namei_getcomponent(const char *name)
+static int
+namei_getcomponent(struct vnode *dvp, const char *name, size_t *ret)
 {
        size_t pos;
 
+       (void)dvp;
+
        pos = 0;
        while (name[pos] != '\0' && name[pos] != '/') {
                pos++;
        }
-       return pos;
+       *ret = pos;
+       return 0;
 }
 
 ////////////////////////////////////////////////////////////
@@ -840,9 +843,10 @@
  * Inspect the leading path component and update the state accordingly.
  */
 static int
-lookup_parsepath(struct namei_state *state)
+lookup_parsepath(struct namei_state *state, struct vnode *searchdir)
 {
        const char *cp;                 /* pointer into pathname argument */
+       int error;
 
        struct componentname *cnp = state->cnp;
        struct nameidata *ndp = state->ndp;
@@ -861,7 +865,11 @@
         * is held.
         */
        cnp->cn_consume = 0;
-       cnp->cn_namelen = namei_getcomponent(cnp->cn_nameptr);
+       error = namei_getcomponent(searchdir, cnp->cn_nameptr,
+                                  &cnp->cn_namelen);
+       if (error) {
+               return error;
+       }
        cp = cnp->cn_nameptr + cnp->cn_namelen;
        if (cnp->cn_namelen > KERNEL_NAME_MAX) {
                return ENAMETOOLONG;
@@ -1325,7 +1333,7 @@
                 */
                KASSERT(cnp->cn_nameptr[0] != '/');
                KASSERT(cnp->cn_nameptr[0] != '\0');
-               if ((error = lookup_parsepath(state)) != 0) {
+               if ((error = lookup_parsepath(state, searchdir)) != 0) {
                        break;
                }
 
@@ -1500,9 +1508,13 @@
                        }
                        cnp->cn_nameptr = oldnameptr;
                        ndp->ni_pathlen = oldpathlen;
-                       error = lookup_parsepath(state);
-                       if (error == 0) {
+                       if (searchdir == NULL) {
                                error = EOPNOTSUPP;
+                       } else {
+                               error = lookup_parsepath(state, searchdir);
+                               if (error == 0) {
+                                       error = EOPNOTSUPP;
+                               }
                        }
                }
        } else if (plock != NULL) {
@@ -2049,7 +2061,7 @@
 static int
 do_lookup_for_nfsd_index(struct namei_state *state)
 {
-       int error = 0;
+       int error;
 
        struct componentname *cnp = state->cnp;
        struct nameidata *ndp = state->ndp;
@@ -2068,7 +2080,12 @@
        ndp->ni_dvp = NULL;
 
        cnp->cn_consume = 0;
-       cnp->cn_namelen = namei_getcomponent(cnp->cn_nameptr);
+       error = namei_getcomponent(startdir, cnp->cn_nameptr,
+                                  &cnp->cn_namelen);
+       if (error) {
+               return error;
+       }
+
        cp = cnp->cn_nameptr + cnp->cn_namelen;
        KASSERT(cnp->cn_namelen <= KERNEL_NAME_MAX);
        ndp->ni_pathlen -= cnp->cn_namelen;
@@ -2199,7 +2216,10 @@
        if ((uint32_t)newhash != (uint32_t)cnp->cn_hash)
                panic("relookup: bad hash");
 #endif
-       newlen = namei_getcomponent(cnp->cn_nameptr);
+       error = namei_getcomponent(dvp, cnp->cn_nameptr, &newlen);
+       if (error) {
+               panic("relookup: parsepath failed with error %d", error);
+       }
        if (cnp->cn_namelen != newlen)
                panic("relookup: bad len");
        cp = cnp->cn_nameptr + cnp->cn_namelen;



Home | Main Index | Thread Index | Old Index