Change namec() and walk()'s nomount to can_mount
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 15 Sep 2015 18:35:11 +0000 (14:35 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 28 Sep 2015 19:14:00 +0000 (15:14 -0400)
The double-negative was ugly.  This changes the variable to a bool and
switches its value.

Note that the walk() changed here is 9ns's walk, not to be confused with
devtab's walk(), or any other walks.

kern/include/ns.h
kern/src/ns/chan.c
kern/src/ns/sysfile.c

index 658e9a7..ce02cdd 100644 (file)
@@ -866,7 +866,7 @@ void userinit(void);
 uint32_t userpc(void);
 void validname(char *, int);
 void validwstatname(char *);
-int walk(struct chan **, char **unused_char_pp_t, int unused_int, int, int *);
+int walk(struct chan **, char **unused_char_pp_t, int unused_int, bool, int *);
 void *xalloc(uint32_t);
 void *xallocz(uint32_t, int);
 void xfree(void *);
index 19b5225..3bd93bc 100644 (file)
@@ -656,7 +656,7 @@ struct chan *undomount(struct chan *c, struct cname *name)
  * *nerror is the number of names to display in an error message.
  */
 static char Edoesnotexist[] = "does not exist";
-int walk(struct chan **cp, char **names, int nnames, int nomount, int *nerror)
+int walk(struct chan **cp, char **names, int nnames, bool can_mount, int *nerror)
 {
        int dev, dotdot, i, n, nhave, ntry, type;
        struct chan *c, *nc, *lastmountpoint = NULL;
@@ -707,7 +707,7 @@ int walk(struct chan **cp, char **names, int nnames, int nomount, int *nerror)
                        }
                }
 
-               if (!dotdot && !nomount)
+               if (!dotdot && can_mount)
                        domount(&c, &mh);
 
                type = c->type;
@@ -715,7 +715,7 @@ int walk(struct chan **cp, char **names, int nnames, int nomount, int *nerror)
 
                if ((wq = devtab[type].walk(c, NULL, names + nhave, ntry)) == NULL) {
                        /* try a union mount, if any */
-                       if (mh && !nomount) {
+                       if (mh && can_mount) {
                                /*
                                 * mh->mount == c, so start at mh->mount->next
                                 */
@@ -752,7 +752,7 @@ int walk(struct chan **cp, char **names, int nnames, int nomount, int *nerror)
                        n = 1;
                } else {
                        nc = NULL;
-                       if (!nomount)
+                       if (can_mount)
                                for (i = 0; i < wq->nqid && i < ntry - 1; i++)
                                        if (findmount(&nc, &nmh, type, dev, wq->qid[i]))
                                                break;
@@ -969,6 +969,7 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
        char tmperrbuf[ERRMAX];
        int saved_errno;
        char *name, *devname, *devspec;
+       bool can_mount = TRUE;
        // Rune r;
 
        static_assert(!(CINTERNAL_FLAGS & CEXTERNAL_FLAGS));
@@ -982,7 +983,6 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
         * a device tree, or the current dot) as well as the name to
         * evaluate starting there.
         */
-       nomount = 0;
        switch (name[0]) {
                case '/':
                        c = current->slash;
@@ -992,7 +992,7 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
                        break;
 
                case '#':
-                       nomount = 1;
+                       can_mount = FALSE;
                        devname = get_cur_genbuf();
                        devname[0] = '\0';
                        n = 0;
@@ -1080,7 +1080,7 @@ struct chan *namec(char *aname, int amode, int omode, uint32_t perm)
                e.ARRAY_SIZEs--;
        }
 
-       if (walk(&c, e.elems, e.ARRAY_SIZEs, nomount, &npath) < 0) {
+       if (walk(&c, e.elems, e.ARRAY_SIZEs, can_mount, &npath) < 0) {
                if (npath < 0 || npath > e.ARRAY_SIZEs) {
                        printd("namec %s walk error npath=%d\n", aname, npath);
                        error("walk failed");
@@ -1122,13 +1122,13 @@ NameError:
 
        switch (amode) {
                case Aaccess:
-                       if (!nomount)
+                       if (can_mount)
                                domount(&c, NULL);
                        break;
 
                case Abind:
                        m = NULL;
-                       if (!nomount)
+                       if (can_mount)
                                domount(&c, &m);
                        if (c->umh != NULL)
                                putmhead(c->umh);
@@ -1142,7 +1142,7 @@ Open:
                        cname = c->name;
                        kref_get(&cname->ref, 1);
                        m = NULL;
-                       if (!nomount)
+                       if (can_mount)
                                domount(&c, &m);
 
                        /* our own copy to open or remove */
@@ -1219,7 +1219,7 @@ Open:
                         * If omode&OEXCL is set, just give up.
                         */
                        e.ARRAY_SIZEs++;
-                       if (walk(&c, e.elems + e.ARRAY_SIZEs - 1, 1, nomount, NULL) == 0) {
+                       if (walk(&c, e.elems + e.ARRAY_SIZEs - 1, 1, can_mount, NULL) == 0) {
                                if (omode & O_EXCL)
                                        error(Eexist);
                                omode |= O_TRUNC;
@@ -1270,7 +1270,7 @@ Open:
                        cnew = NULL;    /* is this assignment necessary? */
                        /* discard error */
                        if (!waserror()) {      /* try create */
-                               if (!nomount && findmount(&cnew, &m, c->type, c->dev, c->qid))
+                               if (can_mount && findmount(&cnew, &m, c->type, c->dev, c->qid))
                                        cnew = createdir(cnew, m);
                                else {
                                        cnew = c;
@@ -1318,7 +1318,7 @@ Open:
                        strncpy(tmperrbuf, current_errstr(), MAX_ERRSTR_LEN);
                        saved_errno = get_errno();
                        /* note: we depend that walk does not error */
-                       if (walk(&c, e.elems + e.ARRAY_SIZEs - 1, 1, nomount, NULL) < 0) {
+                       if (walk(&c, e.elems + e.ARRAY_SIZEs - 1, 1, can_mount, NULL) < 0) {
                                set_errno(saved_errno);
                                error(tmperrbuf);       /* report the error we had originally */
                        }
index 8180b27..8a0d15b 100644 (file)
@@ -358,9 +358,9 @@ int syspipe(int fd[2])
        }
        c[0] = namec("#pipe", Atodir, 0, 0);
        c[1] = cclone(c[0]);
-       if (walk(&c[0], &names[0], 1, 1, NULL) < 0)
+       if (walk(&c[0], &names[0], 1, FALSE, NULL) < 0)
                error(Egreg);
-       if (walk(&c[1], &names[1], 1, 1, NULL) < 0)
+       if (walk(&c[1], &names[1], 1, FALSE, NULL) < 0)
                error(Egreg);
        c[0] = d->open(c[0], O_RDWR);
        c[1] = d->open(c[1], O_RDWR);