| plan 9 kernel history: overview | file list | diff list |
1991/1109/port/dev.c (diff list | history)
| port/dev.c on 1990/0227 | ||
| 1990/0227 | #include "u.h" #include "lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "errno.h" #define DEVTAB #include "devtab.h" #include "fcall.h" int devno(int c, int user) { char *s; s = strchr(devchar, c); if(s==0 || c==0){ if(user) return -1; panic("devno %c 0x%ux", c, c); } return s - devchar; } void | |
| 1991/1109 | devdir(Chan *c, Qid qid, char *n, long length, char *user, long perm, Dir *db) | |
| 1990/0227 | { strcpy(db->name, n); db->qid = qid; db->type = devchar[c->type]; db->dev = c->dev; | |
| 1990/11211 | if(qid.path & CHDIR) | |
| 1990/0227 | db->mode = CHDIR|perm; else db->mode = perm; db->atime = seconds(); db->mtime = db->atime; db->hlength = 0; db->length = length; | |
| 1991/0318 | memmove(db->uid, user, NAMELEN); memmove(db->gid, user, NAMELEN); | |
| 1990/0227 | } int devgen(Chan *c, Dirtab *tab, int ntab, int i, Dir *dp) { if(tab==0 || i>=ntab) return -1; tab += i; | |
| 1991/1109 | devdir(c, tab->qid, tab->name, tab->length, eve, tab->perm, dp); | |
| 1990/0227 | return 1; } Chan * devattach(int tc, char *spec) { Chan *c; c = newchan(); | |
| 1990/11211 | c->qid = (Qid){CHDIR, 0}; | |
| 1990/0227 | c->type = devno(tc, 0); return c; } Chan * devclone(Chan *c, Chan *nc) { | |
| 1990/0329 | if(c->flag & COPEN) panic("clone of open file type %c\n", devchar[c->type]); | |
| 1990/0227 | if(nc == 0) nc = newchan(); nc->type = c->type; | |
| 1991/0421 | nc->dev = c->dev; | |
| 1990/0227 | nc->mode = c->mode; nc->qid = c->qid; nc->offset = c->offset; nc->flag = c->flag; nc->mnt = c->mnt; | |
| 1991/0427 | nc->mountid = c->mountid; | |
| 1991/0421 | nc->aux = c->aux; | |
| 1990/0303 | nc->mchan = c->mchan; nc->mqid = c->mqid; | |
| 1990/0227 | return nc; } int devwalk(Chan *c, char *name, Dirtab *tab, int ntab, Devgen *gen) { long i; Dir dir; isdir(c); if(name[0]=='.' && name[1]==0) return 1; for(i=0;; i++) switch((*gen)(c, tab, ntab, i, &dir)){ case -1: | |
| 1990/11211 | strncpy(u->error, errstrtab[Enonexist], NAMELEN); | |
| 1990/0227 | return 0; case 0: continue; case 1: if(strcmp(name, dir.name) == 0){ c->qid = dir.qid; return 1; } continue; } | |
| 1991/0411 | } | |
| 1990/0227 | void devstat(Chan *c, char *db, Dirtab *tab, int ntab, Devgen *gen) { int i; Dir dir; for(i=0;; i++) switch((*gen)(c, tab, ntab, i, &dir)){ case -1: /* * devices with interesting directories usually don't get * here, which is good because we've lost the name by now. */ | |
| 1990/11211 | if(c->qid.path & CHDIR){ | |
| 1991/1109 | devdir(c, c->qid, ".", 0L, eve, CHDIR|0700, &dir); | |
| 1990/0227 | convD2M(&dir, db); return; } | |
| 1991/0626 | print("devstat %c %lux\n", devchar[c->type], c->qid.path); error(Enonexist); | |
| 1990/0227 | case 0: break; case 1: | |
| 1990/11211 | if(eqqid(c->qid, dir.qid)){ | |
| 1990/0227 | convD2M(&dir, db); return; } break; } } long devdirread(Chan *c, char *d, long n, Dirtab *tab, int ntab, Devgen *gen) { | |
| 1990/0821 | long k, m; | |
| 1990/0227 | Dir dir; k = c->offset/DIRLEN; | |
| 1990/0821 | for(m=0; m<n; k++) | |
| 1990/0227 | switch((*gen)(c, tab, ntab, k, &dir)){ case -1: | |
| 1990/0821 | return m; | |
| 1990/0227 | case 0: c->offset += DIRLEN; break; case 1: convD2M(&dir, d); | |
| 1990/0821 | m += DIRLEN; | |
| 1990/0227 | d += DIRLEN; break; } | |
| 1990/0821 | return m; | |
| 1990/0227 | } Chan * devopen(Chan *c, int omode, Dirtab *tab, int ntab, Devgen *gen) { int i; Dir dir; static int access[] = { 0400, 0200, 0600, 0100 }; for(i=0;; i++) switch((*gen)(c, tab, ntab, i, &dir)){ case -1: /* Deal with union directories? */ goto Return; case 0: break; case 1: | |
| 1990/11211 | if(eqqid(c->qid, dir.qid)){ | |
| 1990/0227 | if((access[omode&3] & dir.mode) == access[omode&3]) goto Return; | |
| 1990/11211 | error(Eperm); | |
| 1990/0227 | } break; } Return: c->offset = 0; | |
| 1990/11211 | if((c->qid.path&CHDIR) && omode!=OREAD) error(Eperm); | |
| 1990/0227 | c->mode = openmode(omode); c->flag |= COPEN; return c; } | |