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++){
156 //print("%c: %s: reset\n", devtab[i]->dc, devtab[i]->name);
161 static void closeproc(void*);
168 for(i=0; devtab[i] != nil; i++)
170 kproc("closeproc", closeproc, nil);
174 chandevshutdown(void)
178 /* shutdown in reverse order */
179 for(i=0; devtab[i] != nil; i++)
181 for(i--; i >= 0; i--)
182 devtab[i]->shutdown();
193 chanalloc.free = c->next;
197 c = smalloc(sizeof(Chan));
199 c->link = chanalloc.list;
203 c->fid = ++chanalloc.fid;
206 /* if you get an error before associating with a dev,
207 close calls rootclose, a nop */
227 memset(&c->mqid, 0, sizeof(c->mqid));
239 p = smalloc(sizeof(Path));
242 p->alen = i+PATHSLOP;
243 p->s = smalloc(p->alen);
244 memmove(p->s, s, i+1);
248 * Cannot use newpath for arbitrary names because the mtpt
249 * array will not be populated correctly. The names #/ and / are
250 * allowed, but other names with / in them draw warnings.
252 if(strchr(s, '/') != nil && strcmp(s, "#/") != 0 && strcmp(s, "/") != 0)
253 print("newpath: %s from %#p\n", s, getcallerpc(&s));
256 p->malen = PATHMSLOP;
257 p->mtpt = smalloc(p->malen*sizeof p->mtpt[0]);
267 pp = smalloc(sizeof(Path));
272 pp->s = smalloc(p->alen);
273 memmove(pp->s, p->s, p->len+1);
276 pp->malen = p->malen;
277 pp->mtpt = smalloc(p->malen*sizeof pp->mtpt[0]);
278 for(i=0; i<pp->mlen; i++){
279 pp->mtpt[i] = p->mtpt[i];
280 if(pp->mtpt[i] != nil)
292 if(p == nil || decref(p))
294 for(i=0; i<p->mlen; i++)
295 if(p->mtpt[i] != nil)
303 * In place, rewrite name to compress multiple /, eliminate ., and process ..
304 * (Really only called to remove a trailing .. that has been added.
305 * Otherwise would need to update n->mtpt as well.)
308 fixdotdotname(Path *p)
313 r = strchr(p->s, '/');
319 * The correct name is #i rather than #i/,
320 * but the correct name of #/ is #/.
322 if(strcmp(r, "/")==0 && p->s[1] != '/')
326 p->len = strlen(p->s);
344 addelem(Path *p, char *s, Chan *from)
350 if(s[0]=='.' && s[1]=='\0')
360 memmove(t, p->s, p->len+1);
365 /* don't insert extra slash if one is present */
366 if(p->len>0 && p->s[p->len-1]!='/' && s[0]!='/')
367 p->s[p->len++] = '/';
368 memmove(p->s+p->len, s, i+1);
372 if(p->mlen > 1 && (c = p->mtpt[--p->mlen]) != nil){
373 p->mtpt[p->mlen] = nil;
377 if(p->mlen >= p->malen){
378 p->malen = p->mlen+1+PATHMSLOP;
379 tt = smalloc(p->malen*sizeof tt[0]);
380 memmove(tt, p->mtpt, p->mlen*sizeof tt[0]);
384 p->mtpt[p->mlen++] = from;
396 if(c->dirrock != nil){
423 c->next = chanalloc.free;
429 * Queue a chan to be closed by one of the clunk procs.
444 return clunkq.head != nil;
453 if(clunkq.head != nil)
454 clunkq.tail->next = c;
470 clunkq.head = c->next;
487 tsleep(&clunkq.r, clunkwork, nil, 500);
492 if(clunkq.q.head != nil) {
499 if(clunkq.q.head == nil) {
501 kproc("closeproc", closeproc, nil);
508 devtab[c->type]->close(c);
518 if(c == nil || c->ref < 1 || c->flag&CFREE)
519 panic("cclose %#p", getcallerpc(&c));
524 if(devtab[c->type]->dc == L'M')
525 if((c->flag&(CRCLOSE|CCACHE)) == CCACHE)
526 if((c->qid.type&(QTEXCL|QTMOUNT|QTAUTH)) == 0)
527 if((clunkq.nqueued - clunkq.nclosed) < 64){
533 devtab[c->type]->close(c);
542 if(c == nil || c->ref < 1 || c->flag&CFREE)
543 panic("ccloseq %#p", getcallerpc(&c));
550 * Make sure we have the only copy of c. (Copy on write.)
569 return a.path==b.path && a.vers==b.vers;
573 eqchan(Chan *a, Chan *b, int skipvers)
575 if(a->qid.path != b->qid.path)
577 if(!skipvers && a->qid.vers!=b->qid.vers)
579 if(a->type != b->type)
587 eqchantdqid(Chan *a, int type, int dev, Qid qid, int skipvers)
589 if(a->qid.path != qid.path)
591 if(!skipvers && a->qid.vers!=qid.vers)
605 mh = smalloc(sizeof(Mhead));
613 * This is necessary because there are many
614 * pointers to the top of a given mount list:
616 * - the mhead in the namespace hash table
617 * - the mhead in chans returned from findmount:
618 * used in namec and then by unionread.
619 * - the mhead in chans returned from createdir:
620 * used in the open/create race protect, which is gone.
622 * The RWlock in the Mhead protects the mount list it contains.
623 * The mount list is deleted in cunmount() and closepgrp().
624 * The RWlock ensures that nothing is using the mount list at that time.
626 * It is okay to replace c->mh with whatever you want as
627 * long as you are sure you have a unique reference to it.
629 * This comment might belong somewhere else.
634 if(m != nil && decref(m) == 0){
635 assert(m->mount == nil);
642 cmount(Chan **newp, Chan *old, int flag, char *spec)
647 Mount *nm, *f, *um, **h;
650 if(QTDIR & (old->qid.type^(*newp)->qid.type))
654 print("cmount: unexpected umh, caller %#p\n", getcallerpc(&newp));
658 if((old->qid.type&QTDIR) == 0 && order != MREPL)
665 * Not allowed to bind when the old directory is itself a union.
666 * (Maybe it should be allowed, but I don't see what the semantics
669 * We need to check mh->mount->next to tell unions apart from
670 * simple mount points, so that things like
675 * The check of mount->mflag allows things like
679 * This is far more complicated than it should be, but I don't
680 * see an easier way at the moment.
682 if((flag&MCREATE) != 0 && mh != nil && mh->mount != nil
683 && (mh->mount->next != nil || (mh->mount->mflag&MCREATE) == 0))
689 l = &MOUNTH(pg, old->qid);
690 for(m = *l; m != nil; m = m->hash){
691 if(eqchan(m->from, old, 1))
698 * nothing mounted here yet. create a mount
699 * head and add to the hash table.
705 * if this is a union mount, add the old
706 * node to the mount chain.
709 m->mount = newmount(old, 0, nil);
718 nm = newmount(new, flag, spec);
719 if(mh != nil && mh->mount != nil){
721 * copy a union when binding it onto a directory
728 for(um = um->next; um != nil; um = um->next){
729 f = newmount(um->to, flg, um->spec);
735 if(m->mount != nil && order == MREPL){
741 nm->mflag |= MCREATE;
743 if(m->mount != nil && order == MAFTER){
744 for(f = m->mount; f->next != nil; f = f->next)
748 for(f = nm; f->next != nil; f = f->next)
759 cunmount(Chan *mnt, Chan *mounted)
765 if(mnt->umh != nil) /* should not happen */
766 print("cunmount newp extra umh %p has %p\n", mnt, mnt->umh);
769 * It _can_ happen that mounted->umh is non-nil,
770 * because mounted is the result of namec(Aopen)
771 * (see sysfile.c:/^sysunmount).
772 * If we open a union directory, it will have a umh.
773 * Although surprising, this is okay, since the
774 * cclose will take care of freeing the umh.
780 l = &MOUNTH(pg, mnt->qid);
781 for(m = *l; m != nil; m = m->hash){
782 if(eqchan(m->from, mnt, 1))
803 for(p = &m->mount; f != nil; f = f->next){
804 if(eqchan(f->to, mounted, 1) ||
805 (f->to->mchan != nil && eqchan(f->to->mchan, mounted, 1))){
834 if(c == nil || c->ref < 1 || c->flag&CFREE)
835 panic("cclone: %#p", getcallerpc(&c));
836 wq = devtab[c->type]->walk(c, nil, nil, 0);
838 error("clone failed");
841 if((nc->path = c->path) != nil)
846 /* also used by sysfile.c:/^mountfix */
848 findmount(Chan **cp, Mhead **mp, int type, int dev, Qid qid)
856 for(m = MOUNTH(pg, qid); m != nil; m = m->hash){
857 if(eqchantdqid(m->from, type, dev, qid, 1)){
880 * Calls findmount but also updates path.
883 domount(Chan **cp, Mhead **mp, Path **path)
888 if(findmount(cp, mp, (*cp)->type, (*cp)->dev, (*cp)->qid) == 0)
895 print("domount: path %s has mlen==%d\n", p->s, p->mlen);
899 lc = &p->mtpt[p->mlen-1];
910 * If c is the right-hand-side of a mount point, returns the left hand side.
911 * Changes name to reflect the fact that we've uncrossed the mountpoint,
912 * so name had better be ours to change!
915 undomount(Chan *c, Path *path)
919 if(path->ref != 1 || path->mlen == 0)
920 print("undomount: path %s ref %ld mlen %d caller %#p\n",
921 path->s, path->ref, path->mlen, getcallerpc(&c));
923 if(path->mlen > 0 && (nc = path->mtpt[path->mlen-1]) != nil){
925 path->mtpt[path->mlen-1] = nil;
932 * Call dev walk but catch errors.
935 ewalk(Chan *c, Chan *nc, char **name, int nname)
941 wq = devtab[c->type]->walk(c, nc, name, nname);
947 * Either walks all the way or not at all. No partial results in *cp.
948 * *nerror is the number of names to display in an error message.
950 static char Edoesnotexist[] = "does not exist";
952 walk(Chan **cp, char **names, int nnames, int nomount, int *nerror)
954 int dev, didmount, dotdot, i, n, nhave, ntry, type;
968 * While we haven't gotten all the way down the path:
969 * 1. step through a mount point, if any
970 * 2. send a walk request for initial dotdot or initial prefix without dotdot
971 * 3. move to the first mountpoint along the way.
974 * Each time through the loop:
976 * If didmount==0, c is on the undomount side of the mount point.
977 * If didmount==1, c is on the domount side of the mount point.
978 * Either way, c's full path is path.
981 for(nhave=0; nhave<nnames; nhave+=n){
982 if((c->qid.type&QTDIR) == 0){
987 kstrcpy(up->errstr, Enotdir, ERRMAX);
991 ntry = nnames - nhave;
995 for(i=0; i<ntry; i++){
996 if(isdotdot(names[nhave+i])){
1006 if(!dotdot && !nomount && !didmount)
1007 domount(&c, &mh, &path);
1012 if((wq = ewalk(c, nil, names+nhave, ntry)) == nil){
1013 /* try a union mount, if any */
1014 if(mh != nil && !nomount){
1016 * mh->mount->to == c, so start at mh->mount->next
1019 if((f = mh->mount) != nil)
1021 for(; f != nil; f = f->next)
1022 if((wq = ewalk(f->to, nil, names+nhave, ntry)) != nil){
1041 assert(wq->nqid == 1);
1042 assert(wq->clone != nil);
1044 path = addelem(path, "..", nil);
1045 nc = undomount(wq->clone, path);
1052 for(i=0; i<wq->nqid && i<ntry-1; i++){
1053 if(findmount(&nc, &nmh, type, dev, wq->qid[i])){
1059 if(nc == nil){ /* no mount points along path */
1060 if(wq->clone == nil){
1063 if(wq->nqid == 0 || (wq->qid[wq->nqid-1].type&QTDIR) != 0){
1065 *nerror = nhave+wq->nqid+1;
1066 kstrcpy(up->errstr, Edoesnotexist, ERRMAX);
1069 *nerror = nhave+wq->nqid;
1070 kstrcpy(up->errstr, Enotdir, ERRMAX);
1078 }else{ /* stopped early, at a mount point */
1080 if(wq->clone != nil){
1088 if(i==n-1 && nmh!=nil)
1090 path = addelem(path, names[nhave+i], mtpt);
1101 if(c->umh != nil){ //BUG
1102 print("walk umh\n");
1118 * c is a mounted non-creatable directory. find a creatable one.
1121 createdir(Chan *c, Mhead *m)
1131 for(f = m->mount; f != nil; f = f->next){
1132 if((f->mflag&MCREATE) != 0){
1150 growparse(Elemlist *e)
1156 if((e->nelems % Delta) == 0){
1157 new = smalloc((e->nelems+Delta) * sizeof(char*));
1158 memmove(new, e->elems, e->nelems*sizeof(char*));
1161 inew = smalloc((e->nelems+Delta+1) * sizeof(int));
1162 memmove(inew, e->off, (e->nelems+1)*sizeof(int));
1169 * The name is known to be valid.
1170 * Copy the name so slashes can be overwritten.
1171 * An empty string will set nelem=0.
1172 * A path ending in / or /. or /.//./ etc. will have
1173 * e.mustbedir = 1, so that we correctly
1174 * reject, e.g., "/adm/users/." when /adm/users is a file
1175 * rather than a directory.
1178 parsename(char *aname, Elemlist *e)
1182 kstrdup(&e->name, aname);
1186 e->off = smalloc(sizeof(int));
1187 e->off[0] = skipslash(name) - name;
1189 name = skipslash(name);
1191 e->off[e->nelems] = name+strlen(name) - e->name;
1196 e->elems[e->nelems++] = name;
1197 slash = utfrune(name, '/');
1199 e->off[e->nelems] = name+strlen(name) - e->name;
1203 e->off[e->nelems] = slash - e->name;
1210 memrchr(void *va, int c, long n)
1215 for(e=a+n-1; e>a; e--)
1222 namelenerror(char *aname, int len, char *err)
1224 char *ename, *name, *next;
1228 * If the name is short enough, just use the whole thing.
1230 errlen = strlen(err);
1231 if(len < ERRMAX/3 || len+errlen < 2*ERRMAX/3)
1232 snprint(up->genbuf, sizeof up->genbuf, "%.*s",
1233 utfnlen(aname, len), aname);
1236 * Print a suffix of the name, but try to get a little info.
1242 next = memrchr(aname, '/', name-aname);
1246 }while(len < ERRMAX/3 || len + errlen < 2*ERRMAX/3);
1249 * If the name is ridiculously long, chop it.
1252 name = ename-ERRMAX/4;
1254 panic("bad math in namelenerror");
1255 /* walk out of current UTF sequence */
1256 for(i=0; (*name&0xC0)==0x80 && i<UTFmax; i++)
1259 snprint(up->genbuf, sizeof up->genbuf, "...%.*s",
1260 utfnlen(name, ename-name), name);
1262 snprint(up->errstr, ERRMAX, "%#q %s", up->genbuf, err);
1267 nameerror(char *name, char *err)
1269 namelenerror(name, strlen(name), err);
1273 * Turn a name into a channel.
1274 * &name[0] is known to be a valid address. It may be a kernel address.
1276 * Opening with amode Aopen, Acreate, Aremove, or Aaccess guarantees
1277 * that the result will be the only reference to that particular fid.
1278 * This is necessary since we might pass the result to
1279 * devtab[]->remove().
1281 * Opening Atodir or Amount does not guarantee this.
1283 * Under certain circumstances, opening Aaccess will cause
1284 * an unnecessary clone in order to get a cunique Chan so it
1285 * can attach the correct name. Sysstat and sys_stat need the
1286 * correct name so they can rewrite the stat info.
1289 namec(char *aname, int amode, int omode, ulong perm)
1291 int len, n, t, nomount;
1297 char *createerr, tmperrbuf[ERRMAX];
1300 if(aname[0] == '\0')
1301 error("empty file name");
1302 aname = validnamedup(aname, 1);
1310 * Find the starting off point (the current slash, the root of
1311 * a device tree, or the current dot) as well as the name to
1312 * evaluate starting there.
1323 up->genbuf[0] = '\0';
1325 while(*name != '\0' && (*name != '/' || n < 2)){
1326 if(n >= sizeof(up->genbuf)-1)
1328 up->genbuf[n++] = *name++;
1330 up->genbuf[n] = '\0';
1332 * noattach is sandboxing.
1334 * the OK exceptions are:
1335 * | it only gives access to pipes you create
1336 * d this process's file descriptors
1337 * e this process's environment
1338 * the iffy exceptions are:
1339 * c time and pid, but also cons and consctl
1340 * p control of your own processes (and unfortunately
1341 * any others left unprotected)
1343 n = chartorune(&r, up->genbuf+1)+1;
1344 if(up->pgrp->noattach && utfrune("|decp", r)==nil)
1349 c = devtab[t]->attach(up->genbuf+n);
1359 e.prefix = name - aname;
1370 * Prepare nice error, showing first e.nerror elements of name.
1374 strcpy(tmperrbuf, up->errstr);
1375 if(e.off[e.nerror]==0)
1376 print("nerror=%d but off=%d\n",
1377 e.nerror, e.off[e.nerror]);
1378 len = e.prefix+e.off[e.nerror];
1380 namelenerror(aname, len, tmperrbuf);
1384 * Build a list of elements in the name.
1386 parsename(name, &e);
1391 if(amode == Acreate){
1392 /* perm must have DMDIR if last element is / or /. */
1393 if(e.mustbedir && !(perm&DMDIR)){
1394 e.nerror = e.nelems;
1395 error("create without DMDIR");
1398 /* don't try to walk the last path element just yet. */
1404 if(walk(&c, e.elems, e.nelems, nomount, &e.nerror) < 0){
1405 if(e.nerror < 0 || e.nerror > e.nelems){
1406 print("namec %s walk error nerror=%d\n", aname, e.nerror);
1412 if(e.mustbedir && (c->qid.type&QTDIR) == 0)
1413 error("not a directory");
1415 if(amode == Aopen && (omode&3) == OEXEC && (c->qid.type&QTDIR) != 0)
1416 error("cannot exec directory");
1420 /* no need to maintain path - cannot dotdot an Abind */
1423 domount(&c, &m, nil);
1432 /* save&update the name; domount might change c */
1441 domount(&c, &m, &path);
1443 /* our own copy to open or remove */
1446 /* now it's our copy anyway, we can put the name back */
1451 /* record whether c is on a mount point */
1463 print("cunique umh Open\n");
1467 /* only save the mount head if it's a multiple element union */
1468 if(m != nil && m->mount != nil && m->mount->next != nil)
1473 /* save registers else error() in open has wrong value of c saved */
1476 c = devtab[c->type]->open(c, omode&~OCEXEC);
1488 * Directories (e.g. for cd) are left before the mount point,
1489 * so one may mount on / or . and see the effect.
1491 if((c->qid.type&QTDIR) == 0)
1497 * When mounting on an already mounted upon directory,
1498 * one wants subsequent mounts to be attached to the
1499 * original directory, not the replacement. Don't domount.
1505 * We've already walked all but the last element.
1506 * If the last exists, try to open it OTRUNC.
1507 * If omode&OEXCL is set, just give up.
1511 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) == 0){
1519 * The semantics of the create(2) system call are that if the
1520 * file exists and can be written, it is to be opened with truncation.
1521 * On the other hand, the create(5) message fails if the file exists.
1522 * If we get two create(2) calls happening simultaneously,
1523 * they might both get here and send create(5) messages, but only
1524 * one of the messages will succeed. To provide the expected create(2)
1525 * semantics, the call with the failed message needs to try the above
1526 * walk again, opening for truncation. This correctly solves the
1527 * create/create race, in the sense that any observable outcome can
1528 * be explained as one happening before the other.
1529 * The create/create race is quite common. For example, it happens
1530 * when two rc subshells simultaneously update the same
1531 * environment variable.
1533 * The implementation still admits a create/create/remove race:
1534 * (A) walk to file, fails
1535 * (B) walk to file, fails
1536 * (A) create file, succeeds, returns
1537 * (B) create file, fails
1538 * (A) remove file, succeeds, returns
1539 * (B) walk to file, return failure.
1541 * This is hardly as common as the create/create race, and is really
1542 * not too much worse than what might happen if (B) got a hold of a
1543 * file descriptor and then the file was removed -- either way (B) can't do
1544 * anything with the result of the create call. So we don't care about this race.
1546 * Applications that care about more fine-grained decision of the races
1547 * can use the OEXCL flag to get at the underlying create(5) semantics;
1548 * by default we provide the common case.
1550 * We need to stay behind the mount point in case we
1551 * need to do the first walk again (should the create fail).
1553 * We also need to cross the mount point and find the directory
1554 * in the union in which we should be creating.
1556 * The channel staying behind is c, the one moving forward is cnew.
1559 cnew = nil; /* is this assignment necessary? */
1560 if(!waserror()){ /* try create */
1561 if(!nomount && findmount(&cnew, &m, c->type, c->dev, c->qid))
1562 cnew = createdir(cnew, m);
1569 * We need our own copy of the Chan because we're
1570 * about to send a create, which will move it. Once we have
1571 * our own copy, we can fix the name, which might be wrong
1572 * if findmount gave us a new Chan.
1574 cnew = cunique(cnew);
1575 pathclose(cnew->path);
1576 cnew->path = c->path;
1579 cnew = devtab[cnew->type]->create(cnew, e.elems[e.nelems-1], omode&~(OEXCL|OCEXEC), perm);
1582 cnew->flag |= CCEXEC;
1584 cnew->flag |= CRCLOSE;
1588 c->path = addelem(c->path, e.elems[e.nelems-1], nil);
1598 createerr = up->errstr;
1599 up->errstr = tmperrbuf;
1600 /* note: we depend that walk does not error */
1601 if(walk(&c, e.elems+e.nelems-1, 1, nomount, nil) < 0){
1602 up->errstr = createerr;
1603 error(createerr); /* report true error */
1605 up->errstr = createerr;
1610 panic("unknown namec access %d", amode);
1613 /* place final element in genbuf for e.g. exec */
1615 kstrcpy(up->genbuf, e.elems[e.nelems-1], sizeof up->genbuf);
1617 kstrcpy(up->genbuf, ".", sizeof up->genbuf);
1621 poperror(); /* e c */
1623 poperror(); /* aname */
1629 * name is valid. skip leading / and ./ as much as possible
1632 skipslash(char *name)
1634 while(name[0]=='/' || (name[0]=='.' && (name[1]==0 || name[1]=='/')))
1640 /*NUL*/ 1, 1, 1, 1, 1, 1, 1, 1,
1641 /*BKS*/ 1, 1, 1, 1, 1, 1, 1, 1,
1642 /*DLE*/ 1, 1, 1, 1, 1, 1, 1, 1,
1643 /*CAN*/ 1, 1, 1, 1, 1, 1, 1, 1,
1649 * Check that the name
1650 * a) is in valid memory.
1651 * b) is shorter than 2^16 bytes, so it can fit in a 9P string field.
1652 * c) contains no frogs.
1653 * The first byte is known to be addressible by the requester, so the
1654 * routine works for kernel and user memory both.
1655 * The parameter slashok flags whether a slash character is an error
1656 * or a valid character.
1658 * The parameter dup flags whether the string should be copied
1659 * out of user space before being scanned the second time.
1660 * (Otherwise a malicious thread could remove the NUL, causing us
1661 * to access unchecked addresses.)
1664 validname0(char *aname, int slashok, int dup, uintptr pc)
1666 char *ename, *name, *s;
1671 if((uintptr)name < KZERO){
1673 print("warning: validname called from %#p with user pointer", pc);
1674 ename = vmemchr(name, 0, (1<<16));
1676 ename = memchr(name, 0, (1<<16));
1678 if(ename==nil || ename-name>=(1<<16))
1685 memmove(s, name, n);
1689 setmalloctag(s, pc);
1693 /* all characters above '~' are ok */
1696 name += chartorune(&r, name);
1699 if(!slashok || c!='/'){
1700 snprint(up->genbuf, sizeof(up->genbuf), "%s: %q", Ebadchar, aname);
1711 validname(char *aname, int slashok)
1713 validname0(aname, slashok, 0, getcallerpc(&aname));
1717 validnamedup(char *aname, int slashok)
1719 return validname0(aname, slashok, 1, getcallerpc(&aname));
1725 if(c->qid.type & QTDIR)