Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/dev.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/dev.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/dev.c
0a
#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
devdir(Chan *c, long qid, char *n, long length, long perm, Dir *db)
{
	strcpy(db->name, n);
	db->qid = qid;
	db->type = devchar[c->type];
	db->dev = c->dev;
	if(qid & CHDIR)
		db->mode = CHDIR|perm;
	else
		db->mode = perm;
	db->atime = seconds();
	db->mtime = db->atime;
	db->hlength = 0;
	db->length = length;
	db->uid = 0;
	db->gid = 0;
}

int
devgen(Chan *c, Dirtab *tab, int ntab, int i, Dir *dp)
{
	if(tab==0 || i>=ntab)
		return -1;
	tab += i;
	devdir(c, tab->qid, tab->name, tab->length, tab->perm, dp);
	return 1;
}

Chan *
devattach(int tc, char *spec)
{
	Chan *c;

	c = newchan();
	c->qid = CHDIR;
	c->type = devno(tc, 0);
	return c;
}

Chan *
devclone(Chan *c, Chan *nc)
{
	if(nc == 0)
		nc = newchan();
	nc->type = c->type;
	nc->mode = c->mode;
	nc->qid = c->qid;
	nc->offset = c->offset;
	nc->dev = c->dev;
	nc->flag = c->flag;
	nc->mnt = c->mnt;
	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:
			u->error.type = 0;
			u->error.dev = 0;
			u->error.code = Enonexist;
			return 0;
		case 0:
			continue;
		case 1:
			if(strcmp(name, dir.name) == 0){
				c->qid = dir.qid;
				return 1;
			}
			continue;
		}
}

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.
			 */
			if(c->qid & CHDIR){
				devdir(c, c->qid, ".", 0L, CHDIR|0700, &dir);
				convD2M(&dir, db);
				return;
			}
			panic("devstat");
		case 0:
			break;
		case 1:
			if(c->qid == dir.qid){
				convD2M(&dir, db);
				return;
			}
			break;
		}
}

long
devdirread(Chan *c, char *d, long n, Dirtab *tab, int ntab, Devgen *gen)
{
	long k, l, m;
	Dir dir;

	k = c->offset/DIRLEN;
	l = (c->offset+n)/DIRLEN;
	n = 0;
	for(m=k; m<l; k++)
		switch((*gen)(c, tab, ntab, k, &dir)){
		case -1:
			return n;

		case 0:
			c->offset += DIRLEN;
			break;

		case 1:
			convD2M(&dir, d);
			n += DIRLEN;
			d += DIRLEN;
			m++;
			break;
		}
	return n;
}

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:
			if(c->qid == dir.qid){
				if((access[omode&3] & dir.mode) == access[omode&3])
					goto Return;
				error(0, Eperm);
			}
			break;
		}
    Return:
	c->offset = 0;
	if((c->qid&CHDIR) && omode!=OREAD)
		error(0, Eperm);
	c->mode = openmode(omode);
	c->flag |= COPEN;
	return c;
}
.
## diffname port/dev.c 1990/0303
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/dev.c /n/bootesdump/1990/0303/sys/src/9/mips/dev.c
78a
	nc->mchan = c->mchan;
	nc->mqid = c->mqid;
.
## diffname port/dev.c 1990/0329
## diff -e /n/bootesdump/1990/0303/sys/src/9/mips/dev.c /n/bootesdump/1990/0329/sys/src/9/mips/dev.c
69a
	if(c->flag & COPEN)
		panic("clone of open file type %c\n", devchar[c->type]);
.
## diffname port/dev.c 1990/0821
## diff -e /n/bootesdump/1990/0329/sys/src/9/mips/dev.c /n/bootesdump/1990/0821/sys/src/9/mips/dev.c
168c
	return m;
.
165d
163c
			m += DIRLEN;
.
155c
			return m;
.
150,152c
	for(m=0; m<n; k++)
.
146c
	long k, m;
.
## diffname port/dev.c 1990/11211
## diff -e /n/bootesdump/1990/0821/sys/src/9/mips/dev.c /n/bootesdump/1990/11211/sys/src/9/mips/dev.c
192,193c
	if((c->qid.path&CHDIR) && omode!=OREAD)
		error(Eperm);
.
186c
				error(Eperm);
.
183c
			if(eqqid(c->qid, dir.qid)){
.
135c
			if(eqqid(c->qid, dir.qid)){
.
126c
			if(c->qid.path & CHDIR){
.
98,100c
			strncpy(u->error, errstrtab[Enonexist], NAMELEN);
.
62c
	c->qid = (Qid){CHDIR, 0};
.
42,43c
	memcpy(db->uid, user, NAMELEN);
	memcpy(db->gid, user, NAMELEN);
.
34c
	if(qid.path & CHDIR)
.
28c
devdir(Chan *c, Qid qid, char *n, long length, long perm, Dir *db)
.
7d
## diffname port/dev.c 1991/0318
## diff -e /n/bootesdump/1990/1210/sys/src/9/mips/dev.c /n/bootesdump/1991/0318/sys/src/9/port/dev.c
41,42c
	memmove(db->uid, user, NAMELEN);
	memmove(db->gid, user, NAMELEN);
.
## diffname port/dev.c 1991/0411
## diff -e /n/bootesdump/1991/0318/sys/src/9/port/dev.c /n/bootesdump/1991/0411/sys/src/9/port/dev.c
109a
int devclwalk(Chan *c, Chan *nc, char *name, Dirtab *tab, int ntab, Devgen *gen)
{
	c = devclone(c, nc);
	return devwalk(c, name, tab, ntab, gen);
}

.
## diffname port/dev.c 1991/0414
## diff -e /n/bootesdump/1991/0411/sys/src/9/port/dev.c /n/bootesdump/1991/0414/sys/src/9/port/dev.c
112,113c
	Chan *nc;

	nc = 0;
	if(waserror()){
		if(nc)
			close(nc);
		return 0;
	}
	nc = (*devtab[c->type].clone)(c, 0);
	(*devtab[nc->type].walk)(nc, name);
	poperror();
	return nc;
.
110c
Chan*
devclwalk(Chan *c, char *name)
.
## diffname port/dev.c 1991/0421
## diff -e /n/bootesdump/1991/0414/sys/src/9/port/dev.c /n/bootesdump/1991/0421/sys/src/9/port/dev.c
122c
	if((*devtab[nc->type].walk)(nc, name) == 0){
		close(nc);
		nc = 0;
	}
.
79a
	nc->aux = c->aux;
.
77d
73a
	nc->dev = c->dev;
.
## diffname port/dev.c 1991/0427
## diff -e /n/bootesdump/1991/0421/sys/src/9/port/dev.c /n/bootesdump/1991/0427/sys/src/9/port/dev.c
109,128d
79a
	nc->mountid = c->mountid;
.
## diffname port/dev.c 1991/0626
## diff -e /n/bootesdump/1991/0427/sys/src/9/port/dev.c /n/bootesdump/1991/0626/sys/src/9/port/dev.c
130c
			print("devstat %c %lux\n", devchar[c->type], c->qid.path);
			error(Enonexist);
.
## diffname port/dev.c 1991/1109
## diff -e /n/bootesdump/1991/0626/sys/src/9/port/dev.c /n/bootesdump/1991/1109/sys/src/9/port/dev.c
126c
				devdir(c, c->qid, ".", 0L, eve, CHDIR|0700, &dir);
.
51c
	devdir(c, tab->qid, tab->name, tab->length, eve, tab->perm, dp);
.
27c
devdir(Chan *c, Qid qid, char *n, long length, char *user, long perm, Dir *db)
.
## diffname port/dev.c 1991/1112
## diff -e /n/bootesdump/1991/1109/sys/src/9/port/dev.c /n/bootesdump/1991/1112/sys/src/9/port/dev.c
183,184c
			if(eqqid(c->qid, dir.qid)) {
				if(strcmp(u->p->user, dir.uid) == 0)	/* User */
					mode = dir.mode;
				else if(strcmp(u->p->user, eve) == 0)	/* Bootes is group */
					mode = dir.mode<<3;
				else
					mode = dir.mode<<6;		/* Other */

				t = access[omode&3];
				if((t & mode) == t)
.
172a
	ulong t, mode;
.
41,42c
	strncpy(db->uid, user, NAMELEN);
	strncpy(db->gid, eve, NAMELEN);
.
## diffname port/dev.c 1991/1120
## diff -e /n/bootesdump/1991/1112/sys/src/9/port/dev.c /n/bootesdump/1991/1120/sys/src/9/port/dev.c
130c
			print("%s %s: devstat %c %lux\n", u->p->text, u->p->user,
							devchar[c->type], c->qid.path);
.
## diffname port/dev.c 1991/1206
## diff -e /n/bootesdump/1991/1120/sys/src/9/port/dev.c /n/bootesdump/1991/1206/sys/src/9/port/dev.c
188c
				else if(strcmp(u->p->user, eve) == 0)	/* eve is group */
.
180d
122,123c
			 *  given a channel, we cannot derive the directory name
			 *  that the channel was generated from since it was lost
			 *  by namec.
.
## diffname port/dev.c 1991/1220
## diff -e /n/bootesdump/1991/1206/sys/src/9/port/dev.c /n/bootesdump/1991/1220/sys/src/9/port/dev.c
38c
	db->mtime = kerndate;
.
11a
extern ulong	kerndate;

.
## diffname port/dev.c 1992/0111
## diff -e /n/bootesdump/1991/1220/sys/src/9/port/dev.c /n/bootesdump/1992/0111/sys/src/9/port/dev.c
101c
			strncpy(u->error, Enonexist, NAMELEN);
.
6c
#include	"../port/error.h"
.
## diffname port/dev.c 1992/0321
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/dev.c /n/bootesdump/1992/0321/sys/src/9/port/dev.c
2c
#include	"../port/lib.h"
.
## diffname port/dev.c 1992/0520
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/dev.c /n/bootesdump/1992/0520/sys/src/9/port/dev.c
111a
	return 1;	/* not reached */
.
## diffname port/dev.c 1992/0619
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/dev.c /n/bootesdump/1992/0619/sys/src/9/port/dev.c
10,11d
## diffname port/dev.c 1992/0711
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/dev.c /n/bootesdump/1992/0711/sys/src/9/port/dev.c
59a
	USED(spec);
.
## diffname port/dev.c 1992/1217
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/dev.c /n/bootesdump/1992/1217/sys/src/9/port/dev.c
133c
			print("%s %s: devstat %C %lux\n", u->p->text, u->p->user,
.
71c
		panic("clone of open file type %C\n", devchar[c->type]);
.
23c

	if(user)
		return -1;
	panic("devno %C 0x%ux", c, c);
	return 0;
.
17,21c
	s = devchar;
	i = 0;
	while(*s){
		if(c == *s)
			return i;
		i++;
		s++;
.
15c
	Rune *s;
	int i;
.
## diffname port/dev.c 1993/0321
## diff -e /n/bootesdump/1992/1217/sys/src/9/port/dev.c /n/bootesdump/1993/0321/sys/src/9/port/dev.c
151a
	}
.
146c
			if(eqqid(c->qid, dir.qid)) {
.
143,144d
141c
						devchar[c->type], c->qid.path);
.
128a
		case 0:
			break;
.
127c
	for(i=0;; i++) {
.
## diffname port/dev.c 1993/0323
## diff -e /n/bootesdump/1993/0321/sys/src/9/port/dev.c /n/bootesdump/1993/0323/sys/src/9/port/dev.c
146a
				if(c->flag&CMSG)
					dir.mode |= CHMOUNT;
.
43a
	if(c->flag&CMSG)
		db->mode |= CHMOUNT;
.
## diffname port/dev.c 1993/0330
## diff -e /n/bootesdump/1993/0323/sys/src/9/port/dev.c /n/bootesdump/1993/0330/sys/src/9/port/dev.c
156d
148c
			if(eqqid(c->qid, dir.qid)){
.
146a
		case 0:
			break;
.
145c
							devchar[c->type], c->qid.path);
.
140c
				devdir(c, c->qid, ".", 0L, eve, CHDIR|0775, &dir);
.
131,132d
129c
	for(i=0;; i++)
.
## diffname port/dev.c 1993/0501
## diff -e /n/bootesdump/1993/0330/sys/src/9/port/dev.c /n/fornaxdump/1993/0501/sys/src/brazil/port/dev.c
213c
	}
Return:
.
204c
					mode = dir.mode<<6;
.
201c
				else
				if(strcmp(up->user, eve) == 0)
.
199c
				if(strcmp(up->user, dir.uid) == 0)
.
191c
	for(i=0;; i++) {
.
179a
	}

.
165c
	for(m=0; m<n; k++) {
.
148c
			if(eqqid(c->qid, dir.qid)) {
.
142,143c
			print("%s %s: devstat %C %lux\n", up->text, up->user,
						devchar[c->type], c->qid.path);
.
138c
				devdir(c, c->qid, c->path->elem, i*DIRLEN, eve, CHDIR|0700, &dir);
.
132,136c
		/*
		 *  given a channel, we cannot derive the directory name
		 *  that the channel was generated from since it was lost
		 *  by namec.
		 */
.
120c
	}
	return 0;	/* not reached */
.
115a
				op = c->path;
				c->path = ptenter(&syspt, op, name);
				decref(op);
.
109c
			strncpy(up->error, Enonexist, NAMELEN);
.
106c
	for(i=0;; i++) {
.
101a
	Path *op;
.
93a
	nc->path = c->path;
	incref(nc->path);
.
82a

.
80a

.
72a
	if(tc != 'M') {
		sprint(buf, "#%C%s", tc, spec);
		c->path = ptenter(&syspt, 0, buf);
	}
.
67a
	char buf[NAMELEN+4];
.
## diffname port/dev.c 1993/0525
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/dev.c /n/fornaxdump/1993/0525/sys/src/brazil/port/dev.c
152c
				devdir(c, c->qid, c->path->elem, i*DIRLEN, eve, CHDIR|0555, &dir);
.
## diffname port/dev.c 1993/0725
## diff -e /n/fornaxdump/1993/0525/sys/src/brazil/port/dev.c /n/fornaxdump/1993/0725/sys/src/brazil/port/dev.c
146,150d
## diffname port/dev.c 1993/1013
## diff -e /n/fornaxdump/1993/0725/sys/src/brazil/port/dev.c /n/fornaxdump/1993/1013/sys/src/brazil/port/dev.c
100a
	nc->mcp = c->mcp;
.
## diffname port/dev.c 1993/1210
## diff -e /n/fornaxdump/1993/1013/sys/src/brazil/port/dev.c /n/fornaxdump/1993/1210/sys/src/brazil/port/dev.c
50,51c
	memmove(db->uid, user, NAMELEN);
	memmove(db->gid, eve, NAMELEN);
.
## diffname port/dev.c 1995/0108
## diff -e /n/fornaxdump/1993/1210/sys/src/brazil/port/dev.c /n/fornaxdump/1995/0108/sys/src/brazil/port/dev.c
234a

Block*
devbread(Chan *c, long n, ulong offset)
{
	Block *bp;

	bp = allocb(n);
	if(bp == 0)
		error(Enomem);
	if(waserror()) {
		freeb(bp);
		nexterror();
	}
	bp->wp += devtab[c->type].read(c, bp->wp, n, offset);
	poperror();
	return bp;
}

long
devbwrite(Chan *c, Block *bp, ulong offset)
{
	long n;

	n = devtab[c->type].write(c, bp->rp, BLEN(bp), offset);
	freeb(bp);

	return n;	
}

.
## diffname port/dev.c 1995/0804
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/port/dev.c /n/fornaxdump/1995/0804/sys/src/brazil/port/dev.c
70d
## diffname port/dev.c 1995/0811
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/dev.c /n/fornaxdump/1995/0811/sys/src/brazil/port/dev.c
7d
## diffname port/dev.c 1996/0223
## diff -e /n/fornaxdump/1995/0811/sys/src/brazil/port/dev.c /n/fornaxdump/1996/0223/sys/src/brazil/port/dev.c
7d
## diffname port/dev.c 1997/0327
## diff -e /n/fornaxdump/1996/0223/sys/src/brazil/port/dev.c /n/emeliedump/1997/0327/sys/src/brazil/port/dev.c
260a
void
devremove(Chan*)
{
	error(Eperm);
}

void
devwstat(Chan*, char*)
{
	error(Eperm);
}
.
255c
	n = devtab[c->type]->write(c, bp->rp, BLEN(bp), offset);
.
245c
	bp->wp += devtab[c->type]->read(c, bp->wp, n, offset);
.
232a
void	 
devcreate(Chan*, char*, int, ulong)
{
	error(Eperm);
}

.
192c
Chan*
.
149,150c
			print("%s %s: devstat %C %lux\n",
				up->text, up->user,
				devchar[c->type], c->qid.path);

.
132c
	return 0;
.
78c
Chan*
.
62c
void
devreset(void)
{
}

void
devinit(void)
{
}

Chan*
.
## diffname port/dev.c 1997/0408
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/dev.c /n/emeliedump/1997/0408/sys/src/brazil/port/dev.c
161c
				devtab[c->type]->dc, c->qid.path);
.
92c
		panic("clone of open file type %C\n", devtab[c->type]->dc);
.
36c
	db->type = devtab[c->type]->dc;
.
25,28c
	return -1;
.
23a
	if(user == 0)
		panic("devno %C 0x%ux", c, c);
.
21,22d
16,19c
	for(i = 0; devtab[i] != nil; i++) {
		if(devtab[i]->dc == c)
.
13d
## diffname port/dev.c 1998/0319
## diff -e /n/emeliedump/1997/0408/sys/src/brazil/port/dev.c /n/emeliedump/1998/0319/sys/src/brazil/port/dev.c
40,41c
	db->length1 = length;	/* BOTCH */
	db->length2 = length;	/* BOTCH */
.
## diffname port/dev.c 1998/0326
## diff -e /n/emeliedump/1998/0319/sys/src/brazil/port/dev.c /n/emeliedump/1998/0326/sys/src/brazil/port/dev.c
40,41c
	db->length = length;
.
26c
devdir(Chan *c, Qid qid, char *n, vlong length, char *user, long perm, Dir *db)
.
## diffname port/dev.c 1998/0512
## diff -e /n/emeliedump/1998/0326/sys/src/brazil/port/dev.c /n/emeliedump/1998/0512/sys/src/brazil/port/dev.c
269c
	return n;
.
238c
void
.
## diffname port/dev.c 1998/0829
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/dev.c /n/emeliedump/1998/0829/sys/src/brazil/port/dev.c
96c
	nc->mh = c->mh;
	if(c->mh != nil)
		incref(c->mh);
.
## diffname port/dev.c 1999/0122
## diff -e /n/emeliedump/1998/0829/sys/src/brazil/port/dev.c /n/emeliedump/1999/0122/sys/src/brazil/port/dev.c
214c
			if(c->qid.path == dir.qid.path) {
.
162c
			if(c->qid.path == dir.qid.path) {
.
## diffname port/dev.c 1999/0629
## diff -e /n/emeliedump/1999/0122/sys/src/brazil/port/dev.c /n/emeliedump/1999/0629/sys/src/brazil/port/dev.c
150c
				if(c->name == nil)
					elem = "???";
				else
					for(elem=p=c->name->s; *p; p++)
						if(*p = '/')
							elem = p+1;
				devdir(c, c->qid, elem, i*DIRLEN, eve, CHDIR|0555, &dir);
.
144a
	char *p, *elem;
.
129,131d
114d
104,105c
	if(c->name)
		incref(c->name);
.
74,77c
	sprint(buf, "#%C%s", tc, spec==nil? "" : spec);
	free(c->name);
	c->name = newcname(buf);
.
## diffname port/dev.c 1999/0630
## diff -e /n/emeliedump/1999/0629/sys/src/brazil/port/dev.c /n/emeliedump/1999/0630/sys/src/brazil/port/dev.c
103,104d
75d
## diffname port/dev.c 1999/0710
## diff -e /n/emeliedump/1999/0630/sys/src/brazil/port/dev.c /n/emeliedump/1999/0710/sys/src/brazil/port/dev.c
144a
				else if(strcmp(c->name->s, "/") == 0)
					elem = "/";
.
## diffname port/dev.c 1999/0724
## diff -e /n/emeliedump/1999/0710/sys/src/brazil/port/dev.c /n/emeliedump/1999/0724/sys/src/brazil/port/dev.c
149c
						if(*p == '/')
.
## diffname port/dev.c 1999/1230
## diff -e /n/emeliedump/1999/0724/sys/src/brazil/port/dev.c /n/emeliedump/1999/1230/sys/src/9/port/dev.c
113a
	if(name[0]=='.' && name[1]=='.' && name[2]==0){
		(*gen)(c, tab, ntab, DEVDOTDOT, &dir);
		c->qid = dir.qid;
		return 1;
	}
.
50c
	if(i!=DEVDOTDOT){
		if(i>=ntab)
			return -1;
		tab += i;
	}
.
48c
	if(tab==0)
.
44a
//
// the zeroth element of the table MUST be the directory itself for ..
//
.
## diffname port/dev.c 2000/0716
## diff -e /n/emeliedump/1999/1230/sys/src/9/port/dev.c /n/emeliedump/2000/0716/sys/src/9/port/dev.c
163c
				devdir(c, c->qid, elem, 0, eve, CHDIR|0555, &dir);
.
## diffname port/dev.c 2000/0718
## diff -e /n/emeliedump/2000/0716/sys/src/9/port/dev.c /n/emeliedump/2000/0718/sys/src/9/port/dev.c
228,239c
				devpermcheck(dir.uid, dir.mode, omode);
				goto Return;
.
217,218d
211a
/*
 * error(Eperm) if open permission not granted for up->user.
 */
void
devpermcheck(char *fileuid, ulong perm, int omode)
{
	ulong t;
	static int access[] = { 0400, 0200, 0600, 0100 };

	if(strcmp(up->user, fileuid) == 0)
		perm <<= 0;
	else
	if(strcmp(up->user, eve) == 0)
		perm <<= 3;
	else
		perm <<= 6;

	t = access[omode&3];
	if((t&perm) != t)
		error(Eperm);
}

.
## diffname port/dev.c 2000/0817
## diff -e /n/emeliedump/2000/0718/sys/src/9/port/dev.c /n/emeliedump/2000/0817/sys/src/9/port/dev.c
291a
	poperror();
.
290a
	if(waserror()) {
		freeb(bp);
		nexterror();
	}
.
## diffname port/dev.c 2001/0527
## diff -e /n/emeliedump/2000/0817/sys/src/9/port/dev.c /n/emeliedump/2001/0527/sys/src/9/port/dev.c
311a
	return 0;
.
308,309c
int
devwstat(Chan*, uchar*, int)
.
256c
	if((c->qid.type&QTDIR) && omode!=OREAD)
.
241c
		switch((*gen)(c, nil, tab, ntab, i, &dir)){
.
202,204c
			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;
.
198c
			c->offset++;	/* BUG??? (was DIRLEN: skip entry) */
.
193c
		switch((*gen)(c, nil, tab, ntab, k, &dir)){
.
191c
	k = c->offset;
.
188,189c
	long k, m, dsz;
	struct{
		Dir;
		char slop[100];
	}dir;
.
182a
	error(Egreg);	/* not reached? */
	return -1;
.
177,179c
					dir.mode |= DMMOUNT;
				n = convD2M(&dir, db, n);
				if(n == 0)
					error(Ebadarg);
				return n;
.
167c
			print("%s %s: devstat %C %llux\n",
.
163,165c
				devdir(c, c->qid, elem, 0, eve, DMDIR|0555, &dir);
				n = convD2M(&dir, db, n);
				if(n == 0)
					error(Ebadarg);
				return n;
.
154c
			if(c->qid.type & QTDIR){
.
152c
		switch((*gen)(c, nil, tab, ntab, i, &dir)){
.
144,145c
int
devstat(Chan *c, uchar *db, int n, Dirtab *tab, int ntab, Devgen *gen)
.
141c
	/*
	 * 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;
.
138d
133,136c
		}
		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;
.
126,131c
	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;
.
118,124c
	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;
.
115c
	int i, j, alloc;
	Walkqid *wq;
	char *n;
.
112,113c
Walkqid*
devwalk(Chan *c, Chan *nc, char **name, int nname, Dirtab *tab, int ntab, Devgen *gen)
.
100,103c
	nc->umh = nil;
.
92,93c
	nc = newchan();
.
88a
	Chan *nc;

.
87c
devclone(Chan *c)
.
85a

.
82a
	free(buf);
.
81c
	if(spec == nil)
		spec = "";
	buf = smalloc(4+strlen(spec)+1);
	sprint(buf, "#%C%s", tc, spec);
.
79c
	mkqid(&c->qid, 0, 0, QTDIR);
.
76c
	char *buf;
.
53,54c
	if(i != DEVDOTDOT){
		/* skip over the first element, that for . itself */
		i++;
		if(i >= ntab)
.
51c
	if(tab == 0)
.
49c
devgen(Chan *c, char*, Dirtab *tab, int ntab, int i, Dir *dp)
.
45,47c
/*
 * the zeroth element of the table MUST be the directory itself for ..
*/
.
41,42c
	db->uid = user;
	db->gid = eve;
	db->muid = user;
.
32,37c
	db->mode = perm;
	db->mode |= qid.type << 24;
.
28c
	db->name = n;
	if(c->flag&CMSG)
		qid.type |= QTMOUNT;
.
9a
void
mkqid(Qid *q, vlong path, ulong vers, int type)
{
	q->type = type;
	q->vers = vers;
	q->path = path;
}

.
## diffname port/dev.c 2001/0819
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/dev.c /n/emeliedump/2001/0819/sys/src/9/port/dev.c
134,139d
118d
## diffname port/dev.c 2001/0820
## diff -e /n/emeliedump/2001/0819/sys/src/9/port/dev.c /n/emeliedump/2001/0820/sys/src/9/port/dev.c
37,38d
## diffname port/dev.c 2001/0822
## diff -e /n/emeliedump/2001/0820/sys/src/9/port/dev.c /n/emeliedump/2001/0822/sys/src/9/port/dev.c
270d
263,265c
	for(m=0; m<n; c->dri++) {
		switch((*gen)(c, nil, tab, ntab, c->dri, &dir)){
.
257c
	long m, dsz;
.
## diffname port/dev.c 2001/0904
## diff -e /n/emeliedump/2001/0822/sys/src/9/port/dev.c /n/emeliedump/2001/0904/sys/src/9/port/dev.c
36a
	if(c->flag&CMSG)
		qid.type |= QTMOUNT;
.
## diffname port/dev.c 2001/0905
## diff -e /n/emeliedump/2001/0904/sys/src/9/port/dev.c /n/emeliedump/2001/0905/sys/src/9/port/dev.c
390a

void
devpower(int)
{
	error(Eperm);
}

int
devconfig(int, char *, DevConf *)
{
	error(Eperm);
	return 0;
}
.
## diffname port/dev.c 2001/0924
## diff -e /n/emeliedump/2001/0905/sys/src/9/port/dev.c /n/emeliedump/2001/0924/sys/src/9/port/dev.c
178c
				kstrcpy(up->errstr, Enonexist, ERRMAX);
.
## diffname port/dev.c 2002/0104
## diff -e /n/emeliedump/2001/0924/sys/src/9/port/dev.c /n/emeliedump/2002/0104/sys/src/9/port/dev.c
150c
		if(!(nc->qid.type&QTDIR)){
			if(j==0)
				error(Enotdir);
			goto Done;
		}
.
## diffname port/dev.c 2002/0109
## diff -e /n/emeliedump/2002/0104/sys/src/9/port/dev.c /n/emeliedump/2002/0109/sys/src/9/port/dev.c
80a
void
devshutdown(void)
{
}

.
## diffname port/dev.c 2002/0925
## diff -e /n/emeliedump/2002/0109/sys/src/9/port/dev.c /n/emeliedump/2002/0925/sys/src/9/port/dev.c
286c
					error(Eshort);
.
## diffname port/dev.c 2002/1222
## diff -e /n/emeliedump/2002/0925/sys/src/9/port/dev.c /n/emeliedump/2002/1222/sys/src/9/port/dev.c
54a
int devdebug;
.
52a
 * (here, Devgen is the prototype; devgen is the function in dev.c.)
 * 
 * a Devgen is expected to return the directory entry for ".."
 * if you pass it s==DEVDOTDOT (-1).  otherwise...
 * 
 * there are two contradictory rules.
 * 
 * (i) if c is a directory, a Devgen is expected to list its children
 * as you iterate s.
 * 
 * (ii) whether or not c is a directory, a Devgen is expected to list
 * its siblings as you iterate s.
 * 
 * devgen always returns the list of children in the root
 * directory.  thus it follows (i) when c is the root and (ii) otherwise.
 * many other Devgens follow (i) when c is a directory and (ii) otherwise.
 * 
 * devwalk assumes (i).  it knows that devgen breaks (i)
 * for children that are themselves directories, and explicitly catches them.
 * 
 * devstat assumes (ii).  if the Devgen in question follows (i)
 * for this particular c, devstat will not find the necessary info.
 * with our particular Devgen functions, this happens only for
 * directories, so devstat makes something up, assuming
 * c->name, c->qid, eve, DMDIR|0555.
 * 
 * devdirread assumes (i).  the callers have to make sure
 * that the Devgen satisfies (i) for the chan being read.
 */
/*
.
## diffname port/dev.c 2003/0108
## diff -e /n/emeliedump/2002/1222/sys/src/9/port/dev.c /n/emeliedump/2003/0108/sys/src/9/port/dev.c
85d
## diffname port/dev.c 2003/0325
## diff -e /n/emeliedump/2003/0108/sys/src/9/port/dev.c /n/emeliedump/2003/0325/sys/src/9/port/dev.c
90c
	if(i == DEVDOTDOT){
		/* nothing */
	}else if(name){
		for(i=1; i<ntab; i++)
			if(strcmp(tab[i].name, name) == 0)
				break;
		if(i==ntab)
			return -1;
		tab += i;
	}else{
.
86c
devgen(Chan *c, char *name, Dirtab *tab, int ntab, int i, Dir *dp)
.
## diffname port/dev.c 2003/0329
## diff -e /n/emeliedump/2003/0325/sys/src/9/port/dev.c /n/emeliedump/2003/0329/sys/src/9/port/dev.c
206c
			if((*gen)(nc, nil, tab, ntab, DEVDOTDOT, &dir) != 1){
				print("devgen walk .. in dev%s %llux broken\n",
					devtab[nc->type]->name, nc->qid.path);
				error("broken devgen");
			}
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].