| plan 9 kernel history: overview | file list | diff list |
2000/0817/port/dev.c (diff list | history)
| 2000/0817/sys/src/9/port/dev.c:7,12 – 2001/0527/sys/src/9/port/dev.c:7,20 (short | long | prev | next) | ||
|
Convert to 9P2000. XXX.
rsc Fri Mar 4 12:44:25 2005 | ||
| 1990/0227 | ||
| 1991/1220 | extern ulong kerndate; | |
| 2001/0527 | void mkqid(Qid *q, vlong path, ulong vers, int type) { q->type = type; q->vers = vers; q->path = path; } | |
| 1990/0227 | int devno(int c, int user) { | |
| 2000/0817/sys/src/9/port/dev.c:25,57 – 2001/0527/sys/src/9/port/dev.c:33,66 | ||
| 1990/0227 | void | |
| 1998/0326 | devdir(Chan *c, Qid qid, char *n, vlong length, char *user, long perm, Dir *db) | |
| 1990/0227 | { | |
| 2001/0527 | db->name = n; if(c->flag&CMSG) qid.type |= QTMOUNT; | |
| 1990/0227 | db->qid = qid; | |
| 1997/0408 | db->type = devtab[c->type]->dc; | |
| 1990/0227 | db->dev = c->dev; | |
| 1990/11211 |
| |
| 1990/0227 |
| |
| 1993/0323 |
| |
| 2001/0527 | db->mode = perm; db->mode |= qid.type << 24; | |
| 1990/0227 | db->atime = seconds(); | |
| 1991/1220 | db->mtime = kerndate; | |
| 1998/0326 | db->length = length; | |
| 1993/1210 |
| |
| 2001/0527 | db->uid = user; db->gid = eve; db->muid = user; | |
| 1990/0227 | } | |
| 1999/1230 |
| |
| 2001/0527 | /* * the zeroth element of the table MUST be the directory itself for .. */ | |
| 1990/0227 | int | |
| 2001/0527 | devgen(Chan *c, char*, Dirtab *tab, int ntab, int i, Dir *dp) | |
| 1990/0227 | { | |
| 1999/1230 |
| |
| 2001/0527 | if(tab == 0) | |
| 1990/0227 | return -1; | |
| 1999/1230 |
| |
| 2001/0527 | if(i != DEVDOTDOT){ /* skip over the first element, that for . itself */ i++; if(i >= ntab) | |
| 1999/1230 | return -1; tab += i; } | |
| 2000/0817/sys/src/9/port/dev.c:73,96 – 2001/0527/sys/src/9/port/dev.c:82,111 | ||
| 1990/0227 | devattach(int tc, char *spec) { Chan *c; | |
| 1993/0501 |
| |
| 2001/0527 | char *buf; | |
| 1990/0227 | c = newchan(); | |
| 1990/11211 |
| |
| 2001/0527 | mkqid(&c->qid, 0, 0, QTDIR); | |
| 1990/0227 | c->type = devno(tc, 0); | |
| 1999/0629 |
| |
| 2001/0527 | if(spec == nil) spec = ""; buf = smalloc(4+strlen(spec)+1); sprint(buf, "#%C%s", tc, spec); | |
| 1999/0629 | c->name = newcname(buf); | |
| 2001/0527 | free(buf); | |
| 1990/0227 | return c; } | |
| 2001/0527 | ||
| 1997/0327 | Chan* | |
| 1990/0227 |
| |
| 2001/0527 | devclone(Chan *c) | |
| 1990/0227 | { | |
| 2001/0527 | Chan *nc; | |
| 1990/0329 | if(c->flag & COPEN) | |
| 1997/0408 | panic("clone of open file type %C\n", devtab[c->type]->dc); | |
| 1993/0501 | ||
| 1990/0227 |
| |
| 2001/0527 | nc = newchan(); | |
| 1993/0501 | ||
| 1990/0227 | nc->type = c->type; | |
| 1991/0421 | nc->dev = c->dev; | |
| 2000/0817/sys/src/9/port/dev.c:97,106 – 2001/0527/sys/src/9/port/dev.c:112,118 | ||
| 1990/0227 | nc->mode = c->mode; nc->qid = c->qid; nc->offset = c->offset; | |
| 1998/0829 |
| |
| 2001/0527 | nc->umh = nil; | |
| 1991/0427 | nc->mountid = c->mountid; | |
| 1991/0421 | nc->aux = c->aux; | |
| 1990/0303 | nc->mchan = c->mchan; | |
| 2000/0817/sys/src/9/port/dev.c:109,148 – 2001/0527/sys/src/9/port/dev.c:121,220 | ||
| 1990/0227 | return nc; } | |
| 2001/0527 | Walkqid* devwalk(Chan *c, Chan *nc, char **name, int nname, Dirtab *tab, int ntab, Devgen *gen) | |
| 1990/0227 | { | |
| 2001/0527 | int i, j, alloc; Walkqid *wq; char *n; | |
| 1990/0227 | Dir dir; | |
| 1999/1230 |
| |
| 2001/0527 | if(nname > 0) isdir(c); // print("devwalk (%d:%c:%p) ", nname, devtab[c->type]->dc, nc); // for(i=0; i<nname; i++) // print("%s/", name[i]); // print("\n"); //delay(500); alloc = 0; wq = smalloc(sizeof(Walkqid)+(nname-1)*sizeof(Qid)); if(waserror()){ if(alloc && wq->clone!=nil) cclose(wq->clone); free(wq); return nil; } if(nc == nil){ nc = devclone(c); nc->type = 0; /* device doesn't know about this channel yet */ alloc = 1; | |
| 1999/1230 | } | |
| 1993/0501 |
| |
| 1990/0227 |
| |
| 1993/0501 |
| |
| 1990/0227 |
| |
| 2001/0527 | wq->clone = nc; for(j=0; j<nname; j++){ isdir(nc); n = name[j]; if(strcmp(n, ".") == 0){ Accept: wq->qid[wq->nqid++] = nc->qid; | |
| 1990/0227 | continue; | |
| 2001/0527 | } if(strcmp(n, "..") == 0){ (*gen)(nc, nil, tab, ntab, DEVDOTDOT, &dir); nc->qid = dir.qid; goto Accept; } /* * Ugly problem: If we're using devgen, make sure we're * walking the directory itself, represented by the first * entry in the table, and not trying to step into a sub- * directory of the table, e.g. /net/net. Devgen itself * should take care of the problem, but it doesn't have * the necessary information (that we're doing a walk). */ if(gen==devgen && nc->qid.path!=tab[0].qid.path) goto Notfound; for(i=0;; i++) { switch((*gen)(nc, n, tab, ntab, i, &dir)){ case -1: Notfound: if(j == 0) error(Enonexist); strncpy(up->error, Enonexist, ERRMAX); goto Done; case 0: continue; case 1: if(strcmp(n, dir.name) == 0){ nc->qid = dir.qid; goto Accept; } continue; | |
| 1990/0227 | } | |
| 1993/0501 | } | |
| 1997/0327 |
| |
| 2001/0527 | /* * We processed at least one name, so will return some data. * If we didn't process all nname entries succesfully, we drop * the cloned channel and return just the Qids of the walks. */ Done: poperror(); if(wq->nqid < nname){ if(alloc) cclose(wq->clone); wq->clone = nil; }else if(wq->clone){ /* attach cloned channel to same device */ wq->clone->type = c->type; } return wq; | |
| 1991/0411 | } | |
| 1990/0227 |
| |
| 2001/0527 | int devstat(Chan *c, uchar *db, int n, Dirtab *tab, int ntab, Devgen *gen) | |
| 1990/0227 | { int i; Dir dir; | |
| 2000/0817/sys/src/9/port/dev.c:149,157 – 2001/0527/sys/src/9/port/dev.c:221,229 | ||
| 1999/0629 | char *p, *elem; | |
| 1990/0227 | ||
| 1993/0330 | for(i=0;; i++) | |
| 1990/0227 |
| |
| 2001/0527 | switch((*gen)(c, nil, tab, ntab, i, &dir)){ | |
| 1990/0227 | case -1: | |
| 1990/11211 |
| |
| 2001/0527 | if(c->qid.type & QTDIR){ | |
| 1999/0629 | if(c->name == nil) elem = "???"; | |
| 1999/0710 | else if(strcmp(c->name->s, "/") == 0) | |
| 2000/0817/sys/src/9/port/dev.c:160,170 – 2001/0527/sys/src/9/port/dev.c:232,244 | ||
| 1999/0629 | for(elem=p=c->name->s; *p; p++) | |
| 1999/0724 | if(*p == '/') | |
| 1999/0629 | elem = p+1; | |
| 2000/0716 |
| |
| 1990/0227 |
| |
| 2001/0527 | devdir(c, c->qid, elem, 0, eve, DMDIR|0555, &dir); n = convD2M(&dir, db, n); if(n == 0) error(Ebadarg); return n; | |
| 1990/0227 | } | |
| 1997/0327 |
| |
| 2001/0527 | print("%s %s: devstat %C %llux\n", | |
| 1997/0327 | up->text, up->user, | |
| 1997/0408 | devtab[c->type]->dc, c->qid.path); | |
| 1997/0327 | ||
| 2000/0817/sys/src/9/port/dev.c:174,207 – 2001/0527/sys/src/9/port/dev.c:248,293 | ||
| 1990/0227 | case 1: | |
| 1999/0122 | if(c->qid.path == dir.qid.path) { | |
| 1993/0323 | if(c->flag&CMSG) | |
| 1990/0227 |
| |
| 2001/0527 | dir.mode |= DMMOUNT; n = convD2M(&dir, db, n); if(n == 0) error(Ebadarg); return n; | |
| 1990/0227 | } break; } | |
| 2001/0527 | error(Egreg); /* not reached? */ return -1; | |
| 1990/0227 | } long devdirread(Chan *c, char *d, long n, Dirtab *tab, int ntab, Devgen *gen) { | |
| 1990/0821 |
| |
| 1990/0227 |
| |
| 2001/0527 | long k, m, dsz; struct{ Dir; char slop[100]; }dir; | |
| 1990/0227 |
| |
| 2001/0527 | k = c->offset; | |
| 1993/0501 | for(m=0; m<n; k++) { | |
| 1990/0227 |
| |
| 2001/0527 | switch((*gen)(c, nil, tab, ntab, k, &dir)){ | |
| 1990/0227 | case -1: | |
| 1990/0821 | return m; | |
| 1990/0227 | case 0: | |
| 2001/0527 | c->offset++; /* BUG??? (was DIRLEN: skip entry) */ | |
| 1990/0227 | break; case 1: | |
| 1990/0821 |
| |
| 1990/0227 |
| |
| 2001/0527 | dsz = convD2M(&dir, (uchar*)d, n-m); if(dsz <= BIT16SZ){ /* <= not < because this isn't stat; read is stuck */ if(m == 0) return -1; return m; } m += dsz; d += dsz; | |
| 1990/0227 | break; } | |
| 1993/0501 | } | |
| 2000/0817/sys/src/9/port/dev.c:238,244 – 2001/0527/sys/src/9/port/dev.c:324,330 | ||
| 1990/0227 | Dir dir; | |
| 1993/0501 | for(i=0;; i++) { | |
| 1990/0227 |
| |
| 2001/0527 | switch((*gen)(c, nil, tab, ntab, i, &dir)){ | |
| 1990/0227 | case -1: goto Return; case 0: | |
| 2000/0817/sys/src/9/port/dev.c:253,259 – 2001/0527/sys/src/9/port/dev.c:339,345 | ||
| 1993/0501 | } Return: | |
| 1990/0227 | c->offset = 0; | |
| 1990/11211 |
| |
| 2001/0527 | if((c->qid.type&QTDIR) && omode!=OREAD) | |
| 1990/11211 | error(Eperm); | |
| 1990/0227 | c->mode = openmode(omode); c->flag |= COPEN; | |
| 2000/0817/sys/src/9/port/dev.c:305,312 – 2001/0527/sys/src/9/port/dev.c:391,399 | ||
| 1997/0327 | error(Eperm); } | |
| 2001/0527 | int devwstat(Chan*, uchar*, int) | |
| 1997/0327 | { error(Eperm); | |
| 2001/0527 | return 0; | |
| 1997/0327 | } | |