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 */
44 return "<nil path.s>";
51 return p[0]=='.' && p[1]=='.' && p[2]=='\0';
62 } while(!cmpswap(&r->ref, old, new));
74 panic("decref pc=%#p", getcallerpc(&r));
76 } while(!cmpswap(&r->ref, old, new));
81 * Rather than strncpy, which zeros the rest of the buffer, kstrcpy
82 * truncates if necessary, always zero terminates, does not zero fill,
83 * and puts ... at the end of the string if it's too long. Usually used to
84 * save a string in up->genbuf;
87 kstrcpy(char *s, char *t, int ns)
97 /* too long, truncate */
101 /* append ... if there is space */
105 /* look for first byte of UTF-8 sequence by skipping continuation bytes */
106 while(ns>0 && (s[--ns]&0xC0)==0x80)
122 * Atomically replace *p with copy of s
125 kstrdup(char **p, char *s)
131 /* if it's a user, we can wait for memory; if not, something's very wrong */
137 panic("kstrdup: no memory");
139 setmalloctag(t, getcallerpc(&p));
152 todinit(); /* avoid later reentry causing infinite recursion */
153 for(i=0; devtab[i] != nil; i++)
157 static void closeproc(void*);
164 for(i=0; devtab[i] != nil; i++)
166 kproc("closeproc", closeproc, nil);
170 chandevshutdown(void)
174 /* shutdown in reverse order */
175 for(i=0; devtab[i] != nil; i++)
177 for(i--; i >= 0; i--)
178 devtab[i]->shutdown();
189 chanalloc.free = c->next;
193 c = smalloc(sizeof(Chan));
195 c->link = chanalloc.list;
199 c->fid = ++chanalloc.fid;
202 /* if you get an error before associating with a dev,
203 close calls rootclose, a nop */
223 memset(&c->mqid, 0, sizeof(c->mqid));
235 p = smalloc(sizeof(Path));
238 p->alen = i+PATHSLOP;
239 p->s = smalloc(p->alen);
240 memmove(p->s, s, i+1);
244 * Cannot use newpath for arbitrary names because the mtpt
245 * array will not be populated correctly. The names #/ and / are
246 * allowed, but other names with / in them draw warnings.
248 if(strchr(s, '/') != nil && strcmp(s, "#/") != 0 && strcmp(s, "/") != 0)
249 print("newpath: %s from %#p\n", s, getcallerpc(&s));
252 p->malen = PATHMSLOP;
253 p->mtpt = smalloc(p->malen*sizeof p->mtpt[0]);
263 pp = smalloc(sizeof(Path));
268 pp->s = smalloc(p->alen);
269 memmove(pp->s, p->s, p->len+1);
272 pp->malen = p->malen;
273 pp->mtpt = smalloc(p->malen*sizeof pp->mtpt[0]);
274 for(i=0; i<pp->mlen; i++){
275 pp->mtpt[i] = p->mtpt[i];
276 if(pp->mtpt[i] != nil)
288 if(p == nil || decref(p))
290 for(i=0; i<p->mlen; i++)
291 if(p->mtpt[i] != nil)
299 * In place, rewrite name to compress multiple /, eliminate ., and process ..
300 * (Really only called to remove a trailing .. that has been added.
301 * Otherwise would need to update n->mtpt as well.)
304 fixdotdotname(Path *p)
309 r = strchr(p->s, '/');
315 * The correct name is #i rather than #i/,
316 * but the correct name of #/ is #/.
318 if(strcmp(r, "/")==0 && p->s[1] != '/')
322 p->len = strlen(p->s);
340 addelem(Path *p, char *s, Chan *from)
346 if(s[0]=='.' && s[1]=='\0')
356 memmove(t, p->s, p->len+1);
361 /* don't insert extra slash if one is present */
362 if(p->len>0 && p->s[p->len-1]!='/' && s[0]!='/')
363 p->s[p->len++] = '/';
364 memmove(p->s+p->len, s, i+1);
368 if(p->mlen > 1 && (c = p->mtpt[--p->mlen]) != nil){
369 p->mtpt[p->mlen] = nil;
373 if(p->mlen >= p->malen){
374 p->malen = p->mlen+1+PATHMSLOP;
375 tt = smalloc(p->malen*sizeof tt[0]);
376 memmove(tt, p->mtpt, p->mlen*sizeof tt[0]);
380 p->mtpt[p->mlen++] = from;
392 if(c->dirrock != nil){
419 c->next = chanalloc.free;
425 * Queue a chan to be closed by one of the clunk procs.
440 return clunkq.head != nil;
449 if(clunkq.head != nil)
450 clunkq.tail->next = c;
466 clunkq.head = c->next;
483 tsleep(&clunkq.r, clunkwork, nil, 500);
488 if(clunkq.q.head != nil) {
495 if(clunkq.q.head == nil) {
497 kproc("closeproc", closeproc, nil);
504 devtab[c->type]->close(c);
514 if(c == nil || c->ref < 1 || c->flag&CFREE)
515 panic("cclose %#p", getcallerpc(&c));
520 if(devtab[c->type]->dc == L'M')
521 if((c->flag&COPEN) == 0 || (c->flag&(CRCLOSE|CCACHE)) == CCACHE)
522 if((c->qid.type&(QTEXCL|QTMOUNT|QTAUTH)) == 0)
523 if((clunkq.nqueued - clunkq.nclosed) < 64){
529 devtab[c->type]->close(c);
538 if(c == nil || c->ref < 1 || c->flag&CFREE)
539 panic("ccloseq %#p", getcallerpc(&c));
546 * Make sure we have the only copy of c. (Copy on write.)
559 if(c->umh != nil){ //BUG
560 print("cunique umh != nil from %#p\n", getcallerpc(&c));
571 return a.path==b.path && a.vers==b.vers;
575 eqchan(Chan *a, Chan *b, int skipvers)
577 if(a->qid.path != b->qid.path)
579 if(!skipvers && a->qid.vers!=b->qid.vers)
581 if(a->type != b->type)
589 eqchantdqid(Chan *a, int type, int dev, Qid qid, int skipvers)
591 if(a->qid.path != qid.path)
593 if(!skipvers && a->qid.vers!=qid.vers)
607 mh = smalloc(sizeof(Mhead));
615 * This is necessary because there are many
616 * pointers to the top of a given mount list:
618 * - the mhead in the namespace hash table
619 * - the mhead in chans returned from findmount:
620 * used in namec and then by unionread.
621 * - the mhead in chans returned from createdir:
622 * used in the open/create race protect, which is gone.
624 * The RWlock in the Mhead protects the mount list it contains.
625 * The mount list is deleted in cunmount() and closepgrp().
626 * The RWlock ensures that nothing is using the mount list at that time.
628 * It is okay to replace c->mh with whatever you want as
629 * long as you are sure you have a unique reference to it.
631 * This comment might belong somewhere else.
636 if(m != nil && decref(m) == 0){
637 assert(m->mount == nil);
644 cmount(Chan **newp, Chan *old, int flag, char *spec)
649 Mount *nm, *f, *um, **h;
652 if(QTDIR & (old->qid.type^(*newp)->qid.type))
656 print("cmount: unexpected umh, caller %#p\n", getcallerpc(&newp));
660 if((old->qid.type&QTDIR) == 0 && order != MREPL)
667 * Not allowed to bind when the old directory is itself a union.
668 * (Maybe it should be allowed, but I don't see what the semantics
671 * We need to check mh->mount->next to tell unions apart from
672 * simple mount points, so that things like
677 * The check of mount->mflag allows things like
681 * This is far more complicated than it should be, but I don't
682 * see an easier way at the moment.
684 if((flag&MCREATE) != 0 && mh != nil && mh->mount != nil
685 && (mh->mount->next != nil || (mh->mount->mflag&MCREATE) == 0))
691 l = &MOUNTH(pg, old->qid);
692 for(m = *l; m != nil; m = m->hash){
693 if(eqchan(m->from, old, 1))
700 * nothing mounted here yet. create a mount
701 * head and add to the hash table.
707 * if this is a union mount, add the old
708 * node to the mount chain.
711 m->mount = newmount(old, 0, nil);
720 nm = newmount(new, flag, spec);
721 if(mh != nil && mh->mount != nil){
723 * copy a union when binding it onto a directory
730 for(um = um->next; um != nil; um = um->next){
731 f = newmount(um->to, flg, um->spec);
737 if(m->mount != nil && order == MREPL){
743 nm->mflag |= MCREATE;
745 if(m->mount != nil && order == MAFTER){
746 for(f = m->mount; f->next != nil; f = f->next)
750 for(f = nm; f->next != nil; f = f->next)
761 cunmount(Chan *mnt, Chan *mounted)
767 if(mnt->umh != nil) /* should not happen */
768 print("cunmount newp extra umh %p has %p\n", mnt, mnt->umh);
771 * It _can_ happen that mounted->umh is non-nil,
772 * because mounted is the result of namec(Aopen)
773 * (see sysfile.c:/^sysunmount).
774 * If we open a union directory, it will have a umh.
775 * Although surprising, this is okay, since the
776 * cclose will take care of freeing the umh.
782 l = &MOUNTH(pg, mnt->qid);
783 for(m = *l; m != nil; m = m->hash){
784 if(eqchan(m->from, mnt, 1))
805 for(p = &m->mount; f != nil; f = f->next){
806 if(eqchan(f->to, mounted, 1) ||
807 (f->to->mchan != nil && eqchan(f->to->mchan, mounted, 1))){
836 if(c == nil || c->ref < 1 || c->flag&CFREE)
837 panic("cclone: %#p", getcallerpc(&c));
838 wq = devtab[c->type]->walk(c, nil, nil, 0);
840 error("clone failed");
843 if((nc->path = c->path) != nil)
848 /* also used by sysfile.c:/^mountfix */
850 findmount(Chan **cp, Mhead **mp, int type, int dev, Qid qid)
858 for(m = MOUNTH(pg, qid); m != nil; m = m->hash){
859 if(eqchantdqid(m->from, type, dev, qid, 1)){
882 * Calls findmount but also updates path.
885 domount(Chan **cp, Mhead **mp, Path **path)
890 if(findmount(cp, mp, (*cp)->type, (*cp)->dev, (*cp)->qid) == 0)
897 print("domount: path %s has mlen==%d\n", p->s, p->mlen);
901 lc = &p->mtpt[p->mlen-1];
912 * If c is the right-hand-side of a mount point, returns the left hand side.
913 * Changes name to reflect the fact that we've uncrossed the mountpoint,
914 * so name had better be ours to change!
917 undomount(Chan *c, Path *path)
921 if(path->ref != 1 || path->mlen == 0)
922 print("undomount: path %s ref %ld mlen %d caller %#p\n",
923 path->s, path->ref, path->mlen, getcallerpc(&c));
925 if(path->mlen > 0 && (nc = path->mtpt[path->mlen-1]) != nil){
927 path->mtpt[path->mlen-1] = nil;
934 * Call dev walk but catch errors.
937 ewalk(Chan *c, Chan *nc, char **name, int nname)
943 wq = devtab[c->type]->walk(c, nc, name, nname);
949 * Either walks all the way or not at all. No partial results in *cp.
950 * *nerror is the number of names to display in an error message.
952 static char Edoesnotexist[] = "does not exist";
954 walk(Chan **cp, char **names, int nnames, int nomount, int *nerror)
956 int dev, didmount, dotdot, i, n, nhave, ntry, type;
970 * While we haven't gotten all the way down the path:
971 * 1. step through a mount point, if any
972 * 2. send a walk request for initial dotdot or initial prefix without dotdot
973 * 3. move to the first mountpoint along the way.
976 * Each time through the loop:
978 * If didmount==0, c is on the undomount side of the mount point.
979 * If didmount==1, c is on the domount side of the mount point.
980 * Either way, c's full path is path.
983 for(nhave=0; nhave<nnames; nhave+=n){
984 if((c->qid.type&QTDIR) == 0){
989 kstrcpy(up->errstr, Enotdir, ERRMAX);
993 ntry = nnames - nhave;
997 for(i=0; i<ntry; i++){
998 if(isdotdot(names[nhave+i])){
1008 if(!dotdot && !nomount && !didmount)
1009 domount(&c, &mh, &path);
1014 if((wq = ewalk(c, nil, names+nhave, ntry)) == nil){
1015 /* try a union mount, if any */
1016 if(mh != nil && !nomount){
1018 * mh->mount->to == c, so start at mh->mount->next
1021 if((f = mh->mount) != nil)
1023 for(; f != nil; f = f->next)
1024 if((wq = ewalk(f->to, nil, names+nhave, ntry)) != nil){
1043 assert(wq->nqid == 1);
1044 assert(wq->clone != nil);
1046 path = addelem(path, "..", nil);
1047 nc = undomount(wq->clone, path);
1054 for(i=0; i<wq->nqid && i<ntry-1; i++){
1055 if(findmount(&nc, &nmh, type, dev, wq->qid[i])){
1061 if(nc == nil){ /* no mount points along path */
1062 if(wq->clone == nil){
1065 if(wq->nqid == 0 || (wq->qid[wq->nqid-1].type&QTDIR) != 0){
1067 *nerror = nhave+wq->nqid+1;
1068 kstrcpy(up->errstr, Edoesnotexist, ERRMAX);
1071 *nerror = nhave+wq->nqid;
1072 kstrcpy(up->errstr, Enotdir, ERRMAX);
1080 }else{ /* stopped early, at a mount point */
1082 if(wq->clone != nil){
1090 if(i==n-1 && nmh!=nil)
1092 path = addelem(path, names[nhave+i], mtpt);
1115 * c is a mounted non-creatable directory. find a creatable one.
1118 createdir(Chan *c, Mhead *m)
1128 for(f = m->mount; f != nil; f = f->next){
1129 if((f->mflag&MCREATE) != 0){
1147 growparse(Elemlist *e)
1153 if((e->nelems % Delta) == 0){
1154 new = smalloc((e->nelems+Delta) * sizeof(char*));
1155 memmove(new, e->elems, e->nelems*sizeof(char*));
1158 inew = smalloc((e->nelems+Delta+1) * sizeof(int));
1159 memmove(inew, e->off, (e->nelems+1)*sizeof(int));
1166 * The name is known to be valid.
1167 * Copy the name so slashes can be overwritten.
1168 * An empty string will set nelem=0.
1169 * A path ending in / or /. or /.//./ etc. will have
1170 * e.mustbedir = 1, so that we correctly
1171 * reject, e.g., "/adm/users/." when /adm/users is a file
1172 * rather than a directory.
1175 parsename(char *aname, Elemlist *e)
1179 kstrdup(&e->name, aname);
1183 e->off = smalloc(sizeof(int));
1184 e->off[0] = skipslash(name) - name;
1186 name = skipslash(name);
1188 e->off[e->nelems] = name+strlen(name) - e->name;
1193 e->elems[e->nelems++] = name;
1194 slash = utfrune(name, '/');
1196 e->off[e->nelems] = name+strlen(name) - e->name;
1200 e->off[e->nelems] = slash - e->name;
1207 namelenerror(char *aname, int len, char *err)
1209 char *ename, *name, *next;
1213 * If the name is short enough, just use the whole thing.
1215 errlen = strlen(err);
1216 if(len < ERRMAX/3 || len+errlen < 2*ERRMAX/3)
1217 snprint(up->genbuf, sizeof up->genbuf, "%.*s",
1218 utfnlen(aname, len), aname);
1221 * Print a suffix of the name, but try to get a little info.
1233 }while(len < ERRMAX/3 || len + errlen < 2*ERRMAX/3);
1236 * If the name is ridiculously long, chop it.
1239 name = ename-ERRMAX/4;
1241 panic("bad math in namelenerror");
1242 /* walk out of current UTF sequence */
1243 for(i=0; (*name&0xC0)==0x80 && i<UTFmax; i++)
1246 snprint(up->genbuf, sizeof up->genbuf, "...%.*s",
1247 utfnlen(name, ename-name), name);
1249 snprint(up->errstr, ERRMAX, "%#q %s", up->genbuf, err);
1254 nameerror(char *name, char *err)
1256 namelenerror(name, strlen(name), err);
1260 * Turn a name into a channel.
1261 * &name[0] is known to be a valid address. It may be a kernel address.
1263 * Opening with amode Aopen, Acreate, Aremove, or Aaccess guarantees
1264 * that the result will be the only reference to that particular fid.
1265 * This is necessary since we might pass the result to
1266 * devtab[]->remove().
1268 * Opening Atodir or Amount does not guarantee this.
1270 * Under certain circumstances, opening Aaccess will cause
1271 * an unnecessary clone in order to get a cunique Chan so it
1272 * can attach the correct name. Sysstat and sys_stat need the
1273 * correct name so they can rewrite the stat info.
1276 namec(char *aname, int amode, int omode, ulong perm)
1278 int len, n, t, nomount;
1280 Chan *volatile cnew;
1281 Path *volatile path;
1288 if(aname[0] == '\0')
1289 error("empty file name");
1290 aname = validnamedup(aname, 1);
1298 * Find the starting off point (the current slash, the root of
1299 * a device tree, or the current dot) as well as the name to
1300 * evaluate starting there.
1311 up->genbuf[0] = '\0';
1313 while(*name != '\0' && (*name != '/' || n < 2)){
1314 if(n >= sizeof(up->genbuf)-1)
1316 up->genbuf[n++] = *name++;
1318 up->genbuf[n] = '\0';
1320 * noattach is sandboxing.
1322 * the OK exceptions are:
1323 * | it only gives access to pipes you create
1324 * d this process's file descriptors
1325 * e this process's environment
1326 * the iffy exceptions are:
1327 * c time and pid, but also cons and consctl
1328 * p control of your own processes (and unfortunately
1329 * any others left unprotected)
1331 n = chartorune(&r, up->genbuf+1)+1;
1332 if(up->pgrp->noattach && utfrune("|decp", r)==nil)
1337 c = devtab[t]->attach(up->genbuf+n);
1347 e.prefix = name - aname;
1358 * Prepare nice error, showing first e.nerror elements of name.
1362 if(e.off[e.nerror]==0)
1363 print("nerror=%d but off=%d\n",
1364 e.nerror, e.off[e.nerror]);
1365 len = e.prefix+e.off[e.nerror];
1368 up->errstr = up->syserrstr;
1369 up->syserrstr = err;
1370 namelenerror(aname, len, err);
1374 * Build a list of elements in the name.
1376 parsename(name, &e);
1381 if(amode == Acreate){
1382 /* perm must have DMDIR if last element is / or /. */
1383 if(e.mustbedir && !(perm&DMDIR)){
1384 e.nerror = e.nelems;
1385 error("create without DMDIR");
1388 /* don't try to walk the last path element just yet. */
1394 if(walk(&c, e.elems, e.nelems, nomount, &e.nerror) < 0){
1395 if(e.nerror < 0 || e.nerror > e.nelems){
1396 print("namec %s walk error nerror=%d\n", aname, e.nerror);
1402 if(e.mustbedir && (c->qid.type&QTDIR) == 0)
1403 error("not a directory");
1405 if(amode == Aopen && (omode&3) == OEXEC && (c->qid.type&QTDIR) != 0)
1406 error("cannot exec directory");
1410 /* no need to maintain path - cannot dotdot an Abind */
1413 domount(&c, &m, nil);
1427 /* save&update the name; domount might change c */
1436 domount(&c, &m, &path);
1441 /* our own copy to open or remove */
1445 /* now it's our copy anyway, we can put the name back */
1450 /* record whether c is on a mount point */
1461 /* only save the mount head if it's a multiple element union */
1462 if(m != nil && m->mount != nil && m->mount->next != nil)
1467 /* save registers else error() in open has wrong value of c saved */
1470 c = devtab[c->type]->open(c, omode&~OCEXEC);
1479 * Directories (e.g. for cd) are left before the mount point,
1480 * so one may mount on / or . and see the effect.
1482 if((c->qid.type&QTDIR) == 0)
1488 * When mounting on an already mounted upon directory,
1489 * one wants subsequent mounts to be attached to the
1490 * original directory, not the replacement. Don't domount.
1496 * We've already walked all but the last element.
1497 * If the last exists, try to open it OTRUNC.
1498 * If omode&OEXCL is set, just give up.
1502 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) == 0){
1510 * The semantics of the create(2) system call are that if the
1511 * file exists and can be written, it is to be opened with truncation.
1512 * On the other hand, the create(5) message fails if the file exists.
1513 * If we get two create(2) calls happening simultaneously,
1514 * they might both get here and send create(5) messages, but only
1515 * one of the messages will succeed. To provide the expected create(2)
1516 * semantics, the call with the failed message needs to try the above
1517 * walk again, opening for truncation. This correctly solves the
1518 * create/create race, in the sense that any observable outcome can
1519 * be explained as one happening before the other.
1520 * The create/create race is quite common. For example, it happens
1521 * when two rc subshells simultaneously update the same
1522 * environment variable.
1524 * The implementation still admits a create/create/remove race:
1525 * (A) walk to file, fails
1526 * (B) walk to file, fails
1527 * (A) create file, succeeds, returns
1528 * (B) create file, fails
1529 * (A) remove file, succeeds, returns
1530 * (B) walk to file, return failure.
1532 * This is hardly as common as the create/create race, and is really
1533 * not too much worse than what might happen if (B) got a hold of a
1534 * file descriptor and then the file was removed -- either way (B) can't do
1535 * anything with the result of the create call. So we don't care about this race.
1537 * Applications that care about more fine-grained decision of the races
1538 * can use the OEXCL flag to get at the underlying create(5) semantics;
1539 * by default we provide the common case.
1541 * We need to stay behind the mount point in case we
1542 * need to do the first walk again (should the create fail).
1544 * We also need to cross the mount point and find the directory
1545 * in the union in which we should be creating.
1547 * The channel staying behind is c, the one moving forward is cnew.
1550 cnew = nil; /* is this assignment necessary? */
1551 if(!waserror()){ /* try create */
1552 if(!nomount && findmount(&cnew, &m, c->type, c->dev, c->qid))
1553 cnew = createdir(cnew, m);
1560 * We need our own copy of the Chan because we're
1561 * about to send a create, which will move it. Once we have
1562 * our own copy, we can fix the name, which might be wrong
1563 * if findmount gave us a new Chan.
1565 cnew = cunique(cnew);
1566 pathclose(cnew->path);
1567 cnew->path = c->path;
1570 cnew = devtab[cnew->type]->create(cnew, e.elems[e.nelems-1], omode&~(OEXCL|OCEXEC), perm);
1572 cnew->flag |= CRCLOSE;
1577 c->path = addelem(c->path, e.elems[e.nelems-1], nil);
1588 up->errstr = up->syserrstr;
1589 up->syserrstr = err;
1590 /* note: we depend that walk does not error */
1591 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) < 0)
1592 error(err); /* report true error */
1594 err = up->syserrstr;
1595 up->syserrstr = up->errstr;
1601 panic("unknown namec access %d", amode);
1604 /* place final element in genbuf for e.g. exec */
1606 kstrcpy(up->genbuf, e.elems[e.nelems-1], sizeof up->genbuf);
1608 kstrcpy(up->genbuf, ".", sizeof up->genbuf);
1612 poperror(); /* e c */
1614 poperror(); /* aname */
1620 * name is valid. skip leading / and ./ as much as possible
1623 skipslash(char *name)
1625 while(name[0]=='/' || (name[0]=='.' && (name[1]==0 || name[1]=='/')))
1631 /*NUL*/ 1, 1, 1, 1, 1, 1, 1, 1,
1632 /*BKS*/ 1, 1, 1, 1, 1, 1, 1, 1,
1633 /*DLE*/ 1, 1, 1, 1, 1, 1, 1, 1,
1634 /*CAN*/ 1, 1, 1, 1, 1, 1, 1, 1,
1640 * Check that the name
1641 * a) is in valid memory.
1642 * b) is shorter than 2^16 bytes, so it can fit in a 9P string field.
1643 * c) contains no frogs.
1644 * The first byte is known to be addressible by the requester, so the
1645 * routine works for kernel and user memory both.
1646 * The parameter slashok flags whether a slash character is an error
1647 * or a valid character.
1649 * The parameter dup flags whether the string should be copied
1650 * out of user space before being scanned the second time.
1651 * (Otherwise a malicious thread could remove the NUL, causing us
1652 * to access unchecked addresses.)
1655 validname0(char *aname, int slashok, int dup, uintptr pc)
1657 char *ename, *name, *s;
1662 if((uintptr)name < KZERO){
1664 print("warning: validname called from %#p with user pointer", pc);
1665 ename = vmemchr(name, 0, (1<<16));
1667 ename = memchr(name, 0, (1<<16));
1669 if(ename==nil || ename-name>=(1<<16))
1676 memmove(s, name, n);
1680 setmalloctag(s, pc);
1684 /* all characters above '~' are ok */
1687 name += chartorune(&r, name);
1690 if(!slashok || c!='/'){
1691 snprint(up->genbuf, sizeof(up->genbuf), "%s: %q", Ebadchar, aname);
1702 validname(char *aname, int slashok)
1704 validname0(aname, slashok, 0, getcallerpc(&aname));
1708 validnamedup(char *aname, int slashok)
1710 return validname0(aname, slashok, 1, getcallerpc(&aname));
1716 if(c->qid.type & QTDIR)