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

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


## diffname gnot/dev.c 1990/03091
## diff -e /dev/null /n/bootesdump/1990/03091/sys/src/9/68020/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;
	nc->mchan = c->mchan;
	nc->mqid = c->mqid;
	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 gnot/dev.c 1990/0329
## diff -e /n/bootesdump/1990/03091/sys/src/9/68020/dev.c /n/bootesdump/1990/0329/sys/src/9/68020/dev.c
69a
	if(c->flag & COPEN)
		panic("clone of open file type %c\n", devchar[c->type]);
.
## diffname gnot/dev.c 1990/0821
## diff -e /n/bootesdump/1990/0329/sys/src/9/68020/dev.c /n/bootesdump/1990/0821/sys/src/9/68020/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 gnot/dev.c 1990/11211
## diff -e /n/bootesdump/1990/0821/sys/src/9/68020/dev.c /n/bootesdump/1990/11211/sys/src/9/68020/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 gnot/dev.c 1990/1210 # deleted
## diff -e /n/bootesdump/1990/11211/sys/src/9/68020/dev.c /n/bootesdump/1990/1210/sys/src/9/68020/dev.c
1,194d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.