From de11e11f9bd0294c5f0f306843f4aa16da54c228 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 24 Feb 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-02-24 --- port/chan.c | 64 +++++++++++++++++++++----------------------------- port/portfns.h | 2 +- port/sysfile.c | 6 +++-- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/port/chan.c b/port/chan.c index 16e45e1df1182997cdd09e980c0d7c3e02d77c05..2b80158772f363ba522081d0fd1b619d93bf7bd8 100644 --- a/port/chan.c +++ b/port/chan.c @@ -378,36 +378,38 @@ undomount(Chan *c) return c; } -Chan* -walk(Chan *ac, char *name, int domnt) +int +walk(Chan **cp, char *name, int domnt) { Pgrp *pg; - Chan *c; + Chan *c, *ac; Mount *f; int dotdot; + ac = *cp; + if(name[0] == '\0') - return ac; + return 0; dotdot = 0; if(name[0] == '.' && name[1] == '.' && name[2] == '\0') { - ac = undomount(ac); + *cp = ac = undomount(ac); dotdot = 1; } ac->flag &= ~CCREATE; /* not inherited through a walk */ if(devtab[ac->type]->walk(ac, name) != 0) { if(dotdot) - ac = undomount(ac); + *cp = undomount(*cp); if(domnt) - ac = domount(ac); - return ac; + *cp = domount(*cp); + return 0; } - if(ac->mnt == 0) - return 0; + if(ac->mnt == nil) + return -1; - c = 0; + c = nil; pg = up->pgrp; rlock(&pg->ns); @@ -423,13 +425,13 @@ walk(Chan *ac, char *name, int domnt) if(devtab[c->type]->walk(c, name) != 0) break; cclose(c); - c = 0; + c = nil; } poperror(); runlock(&pg->ns); - if(c == 0) - return 0; + if(c == nil) + return -1; if(dotdot) c = undomount(c); @@ -444,7 +446,8 @@ walk(Chan *ac, char *name, int domnt) poperror(); } cclose(ac); - return c; + *cp = c; + return 0; } /* @@ -537,7 +540,7 @@ namec(char *name, int amode, int omode, ulong perm) char *elem; int t, n; int mntok, isdot; - Chan *c, *nc, *cc; + Chan *c, *cc; char createerr[ERRLEN]; if(name[0] == 0) @@ -611,10 +614,8 @@ namec(char *name, int amode, int omode, ulong perm) c = domount(c); /* see case Atodir below */ while(*name) { - nc = walk(c, elem, mntok); - if(nc == 0) + if(walk(&c, elem, mntok) < 0) error(Enonexist); - c = nc; name = nextelem(name, elem); } @@ -624,10 +625,8 @@ namec(char *name, int amode, int omode, ulong perm) c = domount(c); break; } - nc = walk(c, elem, mntok); - if(nc == 0) + if(walk(&c, elem, mntok) < 0) error(Enonexist); - c = nc; break; case Atodir: @@ -635,10 +634,8 @@ namec(char *name, int amode, int omode, ulong perm) * Directories (e.g. for cd) are left before the mount point, * so one may mount on / or . and see the effect. */ - nc = walk(c, elem, 0); - if(nc == 0) + if(walk(&c, elem, 0) < 0) error(Enonexist); - c = nc; if(!(c->qid.path & CHDIR)) error(Enotdir); break; @@ -647,10 +644,8 @@ namec(char *name, int amode, int omode, ulong perm) if(isdot) c = domount(c); else { - nc = walk(c, elem, mntok); - if(nc == 0) + if(walk(&c, elem, mntok) < 0) error(Enonexist); - c = nc; } Open: /* else error() in open has wrong value of c saved */ @@ -673,10 +668,8 @@ namec(char *name, int amode, int omode, ulong perm) * one wants subsequent mounts to be attached to the * original directory, not the replacement. */ - nc = walk(c, elem, 0); - if(nc == 0) + if(walk(&c, elem, 0) < 0) error(Enonexist); - c = nc; break; case Acreate: @@ -695,11 +688,10 @@ namec(char *name, int amode, int omode, ulong perm) nexterror(); } nameok(elem); - nc = walk(cc, elem, 1); - if(nc != 0) { + if(walk(&cc, elem, 1) == 0){ poperror(); cclose(c); - c = nc; + c = cc; omode |= OTRUNC; goto Open; } @@ -718,10 +710,8 @@ namec(char *name, int amode, int omode, ulong perm) */ if(waserror()) { strcpy(createerr, up->error); - nc = walk(c, elem, 1); - if(nc == 0) + if(walk(&c, elem, 1) < 0) error(createerr); - c = nc; omode |= OTRUNC; goto Open; } diff --git a/port/portfns.h b/port/portfns.h index 7b5eb6379e8fc73f413feec934a60571128e7d22..69b603ea5b4a3318af670f955092c7f68e95b199 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -297,7 +297,7 @@ void validaddr(ulong, ulong, int); void vcacheinval(Page*, ulong); void* vmemchr(void*, int, int); int wakeup(Rendez*); -Chan* walk(Chan*, char*, int); +int walk(Chan**, char*, int); void wlock(RWlock*); void wunlock(RWlock*); #define xalloc(s) xallocz(s, 1) diff --git a/port/sysfile.c b/port/sysfile.c index afdd8f1ea4aeddc39c0873a5b6aa5f35798501cc..010020be50e25b19f9e14f34699d07642fd62441 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -166,8 +166,10 @@ syspipe(ulong *arg) nexterror(); } c[1] = cclone(c[0], 0); - walk(c[0], "data", 1); - walk(c[1], "data1", 1); + if(walk(&c[0], "data", 1) < 0) + error(Egreg); + if(walk(&c[1], "data1", 1) < 0) + error(Egreg); c[0] = d->open(c[0], ORDWR); c[1] = d->open(c[1], ORDWR); fd[0] = newfd(c[0]);