2 #include "../port/lib.h"
6 #include "../port/error.h"
14 static struct Chanalloc
22 typedef struct Elemlist Elemlist;
26 char *aname; /* original name */
27 char *name; /* copy of name, so '/' can be overwritten */
36 #define SEP(c) ((c) == 0 || (c) == '/')
46 return "<nil path.s>";
53 return p[0]=='.' && p[1]=='.' && p[2]=='\0';
64 } while(!cmpswap(&r->ref, old, new));
76 panic("decref pc=%#p", getcallerpc(&r));
78 } while(!cmpswap(&r->ref, old, new));
83 * Rather than strncpy, which zeros the rest of the buffer, kstrcpy
84 * truncates if necessary, always zero terminates, does not zero fill,
85 * and puts ... at the end of the string if it's too long. Usually used to
86 * save a string in up->genbuf;
89 kstrcpy(char *s, char *t, int ns)
99 /* too long, truncate */
103 /* append ... if there is space */
107 /* look for first byte of UTF-8 sequence by skipping continuation bytes */
108 while(ns>0 && (s[--ns]&0xC0)==0x80)
124 * Atomically replace *p with copy of s
127 kstrdup(char **p, char *s)
133 /* if it's a user, we can wait for memory; if not, something's very wrong */
139 panic("kstrdup: no memory");
141 setmalloctag(t, getcallerpc(&p));
154 todinit(); /* avoid later reentry causing infinite recursion */
155 for(i=0; devtab[i] != nil; i++)
159 static void closeproc(void*);
166 for(i=0; devtab[i] != nil; i++)
168 kproc("closeproc", closeproc, nil);
172 chandevshutdown(void)
176 /* shutdown in reverse order */
177 for(i=0; devtab[i] != nil; i++)
179 for(i--; i >= 0; i--)
180 devtab[i]->shutdown();
191 chanalloc.free = c->next;
195 c = smalloc(sizeof(Chan));
197 c->link = chanalloc.list;
201 c->fid = ++chanalloc.fid;
204 /* if you get an error before associating with a dev,
205 close calls rootclose, a nop */
225 memset(&c->mqid, 0, sizeof(c->mqid));
237 p = smalloc(sizeof(Path));
240 p->alen = i+PATHSLOP;
241 p->s = smalloc(p->alen);
242 memmove(p->s, s, i+1);
246 * Cannot use newpath for arbitrary names because the mtpt
247 * array will not be populated correctly. The names #/ and / are
248 * allowed, but other names with / in them draw warnings.
250 if(strchr(s, '/') != nil && strcmp(s, "#/") != 0 && strcmp(s, "/") != 0)
251 print("newpath: %s from %#p\n", s, getcallerpc(&s));
254 p->malen = PATHMSLOP;
255 p->mtpt = smalloc(p->malen*sizeof p->mtpt[0]);
265 pp = smalloc(sizeof(Path));
270 pp->s = smalloc(p->alen);
271 memmove(pp->s, p->s, p->len+1);
274 pp->malen = p->malen;
275 pp->mtpt = smalloc(p->malen*sizeof pp->mtpt[0]);
276 for(i=0; i<pp->mlen; i++){
277 pp->mtpt[i] = p->mtpt[i];
278 if(pp->mtpt[i] != nil)
290 if(p == nil || decref(p))
292 for(i=0; i<p->mlen; i++)
293 if(p->mtpt[i] != nil)
301 * In place, rewrite name to compress multiple /, eliminate ., and process ..
302 * (Really only called to remove a trailing .. that has been added.
303 * Otherwise would need to update n->mtpt as well.)
306 fixdotdotname(Path *p)
311 r = strchr(p->s, '/');
317 * The correct name is #i rather than #i/,
318 * but the correct name of #/ is #/.
320 if(strcmp(r, "/")==0 && p->s[1] != '/')
324 p->len = strlen(p->s);
342 addelem(Path *p, char *s, Chan *from)
348 if(s[0]=='.' && s[1]=='\0')
358 memmove(t, p->s, p->len+1);
363 /* don't insert extra slash if one is present */
364 if(p->len>0 && p->s[p->len-1]!='/' && s[0]!='/')
365 p->s[p->len++] = '/';
366 memmove(p->s+p->len, s, i+1);
370 if(p->mlen > 1 && (c = p->mtpt[--p->mlen]) != nil){
371 p->mtpt[p->mlen] = nil;
375 if(p->mlen >= p->malen){
376 p->malen = p->mlen+1+PATHMSLOP;
377 tt = smalloc(p->malen*sizeof tt[0]);
378 memmove(tt, p->mtpt, p->mlen*sizeof tt[0]);
382 p->mtpt[p->mlen++] = from;
394 if(c->dirrock != nil){
421 c->next = chanalloc.free;
427 * Queue a chan to be closed by one of the clunk procs.
442 return clunkq.head != nil;
451 if(clunkq.head != nil)
452 clunkq.tail->next = c;
468 clunkq.head = c->next;
485 tsleep(&clunkq.r, clunkwork, nil, 500);
490 if(clunkq.q.head != nil) {
497 if(clunkq.q.head == nil) {
499 kproc("closeproc", closeproc, nil);
506 devtab[c->type]->close(c);
516 if(c == nil || c->ref < 1 || c->flag&CFREE)
517 panic("cclose %#p", getcallerpc(&c));
522 if(devtab[c->type]->dc == L'M')
523 if((c->flag&(CRCLOSE|CCACHE)) == CCACHE)
524 if((c->qid.type&(QTEXCL|QTMOUNT|QTAUTH)) == 0)
525 if((clunkq.nqueued - clunkq.nclosed) < 64){
531 devtab[c->type]->close(c);
540 if(c == nil || c->ref < 1 || c->flag&CFREE)
541 panic("ccloseq %#p", getcallerpc(&c));
548 * Make sure we have the only copy of c. (Copy on write.)
567 return a.path==b.path && a.vers==b.vers;
571 eqchan(Chan *a, Chan *b, int skipvers)
573 if(a->qid.path != b->qid.path)
575 if(!skipvers && a->qid.vers!=b->qid.vers)
577 if(a->type != b->type)
585 eqchantdqid(Chan *a, int type, int dev, Qid qid, int skipvers)
587 if(a->qid.path != qid.path)
589 if(!skipvers && a->qid.vers!=qid.vers)
603 mh = smalloc(sizeof(Mhead));
611 * This is necessary because there are many
612 * pointers to the top of a given mount list:
614 * - the mhead in the namespace hash table
615 * - the mhead in chans returned from findmount:
616 * used in namec and then by unionread.
617 * - the mhead in chans returned from createdir:
618 * used in the open/create race protect, which is gone.
620 * The RWlock in the Mhead protects the mount list it contains.
621 * The mount list is deleted in cunmount() and closepgrp().
622 * The RWlock ensures that nothing is using the mount list at that time.
624 * It is okay to replace c->mh with whatever you want as
625 * long as you are sure you have a unique reference to it.
627 * This comment might belong somewhere else.
632 if(m != nil && decref(m) == 0){
633 assert(m->mount == nil);
640 cmount(Chan **newp, Chan *old, int flag, char *spec)
645 Mount *nm, *f, *um, **h;
648 if(QTDIR & (old->qid.type^(*newp)->qid.type))
652 print("cmount: unexpected umh, caller %#p\n", getcallerpc(&newp));
656 if((old->qid.type&QTDIR) == 0 && order != MREPL)
663 * Not allowed to bind when the old directory is itself a union.
664 * (Maybe it should be allowed, but I don't see what the semantics
667 * We need to check mh->mount->next to tell unions apart from
668 * simple mount points, so that things like
673 * The check of mount->mflag allows things like
677 * This is far more complicated than it should be, but I don't
678 * see an easier way at the moment.
680 if((flag&MCREATE) != 0 && mh != nil && mh->mount != nil
681 && (mh->mount->next != nil || (mh->mount->mflag&MCREATE) == 0))
687 l = &MOUNTH(pg, old->qid);
688 for(m = *l; m != nil; m = m->hash){
689 if(eqchan(m->from, old, 1))
696 * nothing mounted here yet. create a mount
697 * head and add to the hash table.
703 * if this is a union mount, add the old
704 * node to the mount chain.
707 m->mount = newmount(old, 0, nil);
716 nm = newmount(new, flag, spec);
717 if(mh != nil && mh->mount != nil){
719 * copy a union when binding it onto a directory
726 for(um = um->next; um != nil; um = um->next){
727 f = newmount(um->to, flg, um->spec);
733 if(m->mount != nil && order == MREPL){
739 nm->mflag |= MCREATE;
741 if(m->mount != nil && order == MAFTER){
742 for(f = m->mount; f->next != nil; f = f->next)
746 for(f = nm; f->next != nil; f = f->next)
757 cunmount(Chan *mnt, Chan *mounted)
763 if(mnt->umh != nil) /* should not happen */
764 print("cunmount newp extra umh %p has %p\n", mnt, mnt->umh);
767 * It _can_ happen that mounted->umh is non-nil,
768 * because mounted is the result of namec(Aopen)
769 * (see sysfile.c:/^sysunmount).
770 * If we open a union directory, it will have a umh.
771 * Although surprising, this is okay, since the
772 * cclose will take care of freeing the umh.
778 l = &MOUNTH(pg, mnt->qid);
779 for(m = *l; m != nil; m = m->hash){
780 if(eqchan(m->from, mnt, 1))
801 for(p = &m->mount; f != nil; f = f->next){
802 if(eqchan(f->to, mounted, 1) ||
803 (f->to->mchan != nil && eqchan(f->to->mchan, mounted, 1))){
832 if(c == nil || c->ref < 1 || c->flag&CFREE)
833 panic("cclone: %#p", getcallerpc(&c));
834 wq = devtab[c->type]->walk(c, nil, nil, 0);
836 error("clone failed");
839 if((nc->path = c->path) != nil)
844 /* also used by sysfile.c:/^mountfix */
846 findmount(Chan **cp, Mhead **mp, int type, int dev, Qid qid)
854 for(m = MOUNTH(pg, qid); m != nil; m = m->hash){
855 if(eqchantdqid(m->from, type, dev, qid, 1)){
878 * Calls findmount but also updates path.
881 domount(Chan **cp, Mhead **mp, Path **path)
886 if(findmount(cp, mp, (*cp)->type, (*cp)->dev, (*cp)->qid) == 0)
893 print("domount: path %s has mlen==%d\n", p->s, p->mlen);
897 lc = &p->mtpt[p->mlen-1];
908 * If c is the right-hand-side of a mount point, returns the left hand side.
909 * Changes name to reflect the fact that we've uncrossed the mountpoint,
910 * so name had better be ours to change!
913 undomount(Chan *c, Path *path)
917 if(path->ref != 1 || path->mlen == 0)
918 print("undomount: path %s ref %ld mlen %d caller %#p\n",
919 path->s, path->ref, path->mlen, getcallerpc(&c));
921 if(path->mlen > 0 && (nc = path->mtpt[path->mlen-1]) != nil){
923 path->mtpt[path->mlen-1] = nil;
930 * Call dev walk but catch errors.
933 ewalk(Chan *c, Chan *nc, char **name, int nname)
939 wq = devtab[c->type]->walk(c, nc, name, nname);
945 * Either walks all the way or not at all. No partial results in *cp.
946 * *nerror is the number of names to display in an error message.
948 static char Edoesnotexist[] = "does not exist";
950 walk(Chan **cp, char **names, int nnames, int nomount, int *nerror)
952 int dev, didmount, dotdot, i, n, nhave, ntry, type;
966 * While we haven't gotten all the way down the path:
967 * 1. step through a mount point, if any
968 * 2. send a walk request for initial dotdot or initial prefix without dotdot
969 * 3. move to the first mountpoint along the way.
972 * Each time through the loop:
974 * If didmount==0, c is on the undomount side of the mount point.
975 * If didmount==1, c is on the domount side of the mount point.
976 * Either way, c's full path is path.
979 for(nhave=0; nhave<nnames; nhave+=n){
980 if((c->qid.type&QTDIR) == 0){
985 kstrcpy(up->errstr, Enotdir, ERRMAX);
989 ntry = nnames - nhave;
993 for(i=0; i<ntry; i++){
994 if(isdotdot(names[nhave+i])){
1004 if(!dotdot && !nomount && !didmount)
1005 domount(&c, &mh, &path);
1010 if((wq = ewalk(c, nil, names+nhave, ntry)) == nil){
1011 /* try a union mount, if any */
1012 if(mh != nil && !nomount){
1014 * mh->mount->to == c, so start at mh->mount->next
1017 if((f = mh->mount) != nil)
1019 for(; f != nil; f = f->next)
1020 if((wq = ewalk(f->to, nil, names+nhave, ntry)) != nil){
1039 assert(wq->nqid == 1);
1040 assert(wq->clone != nil);
1042 path = addelem(path, "..", nil);
1043 nc = undomount(wq->clone, path);
1050 for(i=0; i<wq->nqid && i<ntry-1; i++){
1051 if(findmount(&nc, &nmh, type, dev, wq->qid[i])){
1057 if(nc == nil){ /* no mount points along path */
1058 if(wq->clone == nil){
1061 if(wq->nqid == 0 || (wq->qid[wq->nqid-1].type&QTDIR) != 0){
1063 *nerror = nhave+wq->nqid+1;
1064 kstrcpy(up->errstr, Edoesnotexist, ERRMAX);
1067 *nerror = nhave+wq->nqid;
1068 kstrcpy(up->errstr, Enotdir, ERRMAX);
1076 }else{ /* stopped early, at a mount point */
1078 if(wq->clone != nil){
1086 if(i==n-1 && nmh!=nil)
1088 path = addelem(path, names[nhave+i], mtpt);
1099 if(c->umh != nil){ //BUG
1100 print("walk umh\n");
1116 * c is a mounted non-creatable directory. find a creatable one.
1119 createdir(Chan *c, Mhead *m)
1129 for(f = m->mount; f != nil; f = f->next){
1130 if((f->mflag&MCREATE) != 0){
1148 growparse(Elemlist *e)
1154 if((e->nelems % Delta) == 0){
1155 new = smalloc((e->nelems+Delta) * sizeof(char*));
1156 memmove(new, e->elems, e->nelems*sizeof(char*));
1159 inew = smalloc((e->nelems+Delta+1) * sizeof(int));
1160 memmove(inew, e->off, (e->nelems+1)*sizeof(int));
1167 * The name is known to be valid.
1168 * Copy the name so slashes can be overwritten.
1169 * An empty string will set nelem=0.
1170 * A path ending in / or /. or /.//./ etc. will have
1171 * e.mustbedir = 1, so that we correctly
1172 * reject, e.g., "/adm/users/." when /adm/users is a file
1173 * rather than a directory.
1176 parsename(char *aname, Elemlist *e)
1180 kstrdup(&e->name, aname);
1184 e->off = smalloc(sizeof(int));
1185 e->off[0] = skipslash(name) - name;
1187 name = skipslash(name);
1189 e->off[e->nelems] = name+strlen(name) - e->name;
1194 e->elems[e->nelems++] = name;
1195 slash = utfrune(name, '/');
1197 e->off[e->nelems] = name+strlen(name) - e->name;
1201 e->off[e->nelems] = slash - e->name;
1208 memrchr(void *va, int c, long n)
1213 for(e=a+n-1; e>a; e--)
1220 namelenerror(char *aname, int len, char *err)
1222 char *ename, *name, *next;
1226 * If the name is short enough, just use the whole thing.
1228 errlen = strlen(err);
1229 if(len < ERRMAX/3 || len+errlen < 2*ERRMAX/3)
1230 snprint(up->genbuf, sizeof up->genbuf, "%.*s",
1231 utfnlen(aname, len), aname);
1234 * Print a suffix of the name, but try to get a little info.
1240 next = memrchr(aname, '/', name-aname);
1244 }while(len < ERRMAX/3 || len + errlen < 2*ERRMAX/3);
1247 * If the name is ridiculously long, chop it.
1250 name = ename-ERRMAX/4;
1252 panic("bad math in namelenerror");
1253 /* walk out of current UTF sequence */
1254 for(i=0; (*name&0xC0)==0x80 && i<UTFmax; i++)
1257 snprint(up->genbuf, sizeof up->genbuf, "...%.*s",
1258 utfnlen(name, ename-name), name);
1260 snprint(up->errstr, ERRMAX, "%#q %s", up->genbuf, err);
1265 nameerror(char *name, char *err)
1267 namelenerror(name, strlen(name), err);
1271 * Turn a name into a channel.
1272 * &name[0] is known to be a valid address. It may be a kernel address.
1274 * Opening with amode Aopen, Acreate, Aremove, or Aaccess guarantees
1275 * that the result will be the only reference to that particular fid.
1276 * This is necessary since we might pass the result to
1277 * devtab[]->remove().
1279 * Opening Atodir or Amount does not guarantee this.
1281 * Under certain circumstances, opening Aaccess will cause
1282 * an unnecessary clone in order to get a cunique Chan so it
1283 * can attach the correct name. Sysstat and sys_stat need the
1284 * correct name so they can rewrite the stat info.
1287 namec(char *aname, int amode, int omode, ulong perm)
1289 int len, n, t, nomount;
1295 char *createerr, tmperrbuf[ERRMAX];
1298 if(aname[0] == '\0')
1299 error("empty file name");
1300 aname = validnamedup(aname, 1);
1308 * Find the starting off point (the current slash, the root of
1309 * a device tree, or the current dot) as well as the name to
1310 * evaluate starting there.
1321 up->genbuf[0] = '\0';
1323 while(*name != '\0' && (*name != '/' || n < 2)){
1324 if(n >= sizeof(up->genbuf)-1)
1326 up->genbuf[n++] = *name++;
1328 up->genbuf[n] = '\0';
1330 * noattach is sandboxing.
1332 * the OK exceptions are:
1333 * | it only gives access to pipes you create
1334 * d this process's file descriptors
1335 * e this process's environment
1336 * the iffy exceptions are:
1337 * c time and pid, but also cons and consctl
1338 * p control of your own processes (and unfortunately
1339 * any others left unprotected)
1341 n = chartorune(&r, up->genbuf+1)+1;
1342 if(up->pgrp->noattach && utfrune("|decp", r)==nil)
1347 c = devtab[t]->attach(up->genbuf+n);
1357 e.prefix = name - aname;
1368 * Prepare nice error, showing first e.nerror elements of name.
1372 strcpy(tmperrbuf, up->errstr);
1373 if(e.off[e.nerror]==0)
1374 print("nerror=%d but off=%d\n",
1375 e.nerror, e.off[e.nerror]);
1376 len = e.prefix+e.off[e.nerror];
1378 namelenerror(aname, len, tmperrbuf);
1382 * Build a list of elements in the name.
1384 parsename(name, &e);
1389 if(amode == Acreate){
1390 /* perm must have DMDIR if last element is / or /. */
1391 if(e.mustbedir && !(perm&DMDIR)){
1392 e.nerror = e.nelems;
1393 error("create without DMDIR");
1396 /* don't try to walk the last path element just yet. */
1402 if(walk(&c, e.elems, e.nelems, nomount, &e.nerror) < 0){
1403 if(e.nerror < 0 || e.nerror > e.nelems){
1404 print("namec %s walk error nerror=%d\n", aname, e.nerror);
1410 if(e.mustbedir && (c->qid.type&QTDIR) == 0)
1411 error("not a directory");
1413 if(amode == Aopen && (omode&3) == OEXEC && (c->qid.type&QTDIR) != 0)
1414 error("cannot exec directory");
1418 /* no need to maintain path - cannot dotdot an Abind */
1421 domount(&c, &m, nil);
1430 /* save&update the name; domount might change c */
1439 domount(&c, &m, &path);
1441 /* our own copy to open or remove */
1444 /* now it's our copy anyway, we can put the name back */
1449 /* record whether c is on a mount point */
1461 print("cunique umh Open\n");
1465 /* only save the mount head if it's a multiple element union */
1466 if(m != nil && m->mount != nil && m->mount->next != nil)
1471 /* save registers else error() in open has wrong value of c saved */
1474 c = devtab[c->type]->open(c, omode&~OCEXEC);
1486 * Directories (e.g. for cd) are left before the mount point,
1487 * so one may mount on / or . and see the effect.
1489 if((c->qid.type&QTDIR) == 0)
1495 * When mounting on an already mounted upon directory,
1496 * one wants subsequent mounts to be attached to the
1497 * original directory, not the replacement. Don't domount.
1503 * We've already walked all but the last element.
1504 * If the last exists, try to open it OTRUNC.
1505 * If omode&OEXCL is set, just give up.
1509 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) == 0){
1517 * The semantics of the create(2) system call are that if the
1518 * file exists and can be written, it is to be opened with truncation.
1519 * On the other hand, the create(5) message fails if the file exists.
1520 * If we get two create(2) calls happening simultaneously,
1521 * they might both get here and send create(5) messages, but only
1522 * one of the messages will succeed. To provide the expected create(2)
1523 * semantics, the call with the failed message needs to try the above
1524 * walk again, opening for truncation. This correctly solves the
1525 * create/create race, in the sense that any observable outcome can
1526 * be explained as one happening before the other.
1527 * The create/create race is quite common. For example, it happens
1528 * when two rc subshells simultaneously update the same
1529 * environment variable.
1531 * The implementation still admits a create/create/remove race:
1532 * (A) walk to file, fails
1533 * (B) walk to file, fails
1534 * (A) create file, succeeds, returns
1535 * (B) create file, fails
1536 * (A) remove file, succeeds, returns
1537 * (B) walk to file, return failure.
1539 * This is hardly as common as the create/create race, and is really
1540 * not too much worse than what might happen if (B) got a hold of a
1541 * file descriptor and then the file was removed -- either way (B) can't do
1542 * anything with the result of the create call. So we don't care about this race.
1544 * Applications that care about more fine-grained decision of the races
1545 * can use the OEXCL flag to get at the underlying create(5) semantics;
1546 * by default we provide the common case.
1548 * We need to stay behind the mount point in case we
1549 * need to do the first walk again (should the create fail).
1551 * We also need to cross the mount point and find the directory
1552 * in the union in which we should be creating.
1554 * The channel staying behind is c, the one moving forward is cnew.
1557 cnew = nil; /* is this assignment necessary? */
1558 if(!waserror()){ /* try create */
1559 if(!nomount && findmount(&cnew, &m, c->type, c->dev, c->qid))
1560 cnew = createdir(cnew, m);
1567 * We need our own copy of the Chan because we're
1568 * about to send a create, which will move it. Once we have
1569 * our own copy, we can fix the name, which might be wrong
1570 * if findmount gave us a new Chan.
1572 cnew = cunique(cnew);
1573 pathclose(cnew->path);
1574 cnew->path = c->path;
1577 cnew = devtab[cnew->type]->create(cnew, e.elems[e.nelems-1], omode&~(OEXCL|OCEXEC), perm);
1580 cnew->flag |= CCEXEC;
1582 cnew->flag |= CRCLOSE;
1586 c->path = addelem(c->path, e.elems[e.nelems-1], nil);
1596 createerr = up->errstr;
1597 up->errstr = tmperrbuf;
1598 /* note: we depend that walk does not error */
1599 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) < 0){
1600 up->errstr = createerr;
1601 error(createerr); /* report true error */
1603 up->errstr = createerr;
1608 panic("unknown namec access %d", amode);
1611 /* place final element in genbuf for e.g. exec */
1613 kstrcpy(up->genbuf, e.elems[e.nelems-1], sizeof up->genbuf);
1615 kstrcpy(up->genbuf, ".", sizeof up->genbuf);
1619 poperror(); /* e c */
1621 poperror(); /* aname */
1627 * name is valid. skip leading / and ./ as much as possible
1630 skipslash(char *name)
1632 while(name[0]=='/' || (name[0]=='.' && (name[1]==0 || name[1]=='/')))
1638 /*NUL*/ 1, 1, 1, 1, 1, 1, 1, 1,
1639 /*BKS*/ 1, 1, 1, 1, 1, 1, 1, 1,
1640 /*DLE*/ 1, 1, 1, 1, 1, 1, 1, 1,
1641 /*CAN*/ 1, 1, 1, 1, 1, 1, 1, 1,
1647 * Check that the name
1648 * a) is in valid memory.
1649 * b) is shorter than 2^16 bytes, so it can fit in a 9P string field.
1650 * c) contains no frogs.
1651 * The first byte is known to be addressible by the requester, so the
1652 * routine works for kernel and user memory both.
1653 * The parameter slashok flags whether a slash character is an error
1654 * or a valid character.
1656 * The parameter dup flags whether the string should be copied
1657 * out of user space before being scanned the second time.
1658 * (Otherwise a malicious thread could remove the NUL, causing us
1659 * to access unchecked addresses.)
1662 validname0(char *aname, int slashok, int dup, uintptr pc)
1664 char *ename, *name, *s;
1669 if((uintptr)name < KZERO){
1671 print("warning: validname called from %#p with user pointer", pc);
1672 ename = vmemchr(name, 0, (1<<16));
1674 ename = memchr(name, 0, (1<<16));
1676 if(ename==nil || ename-name>=(1<<16))
1683 memmove(s, name, n);
1687 setmalloctag(s, pc);
1691 /* all characters above '~' are ok */
1694 name += chartorune(&r, name);
1697 if(!slashok || c!='/'){
1698 snprint(up->genbuf, sizeof(up->genbuf), "%s: %q", Ebadchar, aname);
1709 validname(char *aname, int slashok)
1711 validname0(aname, slashok, 0, getcallerpc(&aname));
1715 validnamedup(char *aname, int slashok)
1717 return validname0(aname, slashok, 1, getcallerpc(&aname));
1723 if(c->qid.type & QTDIR)