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

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


## diffname port/devdup.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/devdup.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"

#include	"devtab.h"


int
dupgen(Chan *c, Dirtab *tab, int ntab, int s, Dir *dp)
{
	char buf[8];
	Chan *f;
	static int perm[] = { 0400, 0200, 0600, 0 };

	if(s >= NFD)
		return -1;
	if((f=u->fd[s]) == 0)
		return 0;
	sprint(buf, "%ld", s);
	devdir(c, s, buf, 0, perm[f->mode&3], dp);
	return 1;
}

void
dupinit(void)
{
}

void
dupreset(void)
{
}

Chan *
dupattach(char *spec)
{
	return devattach('d', spec);
}

Chan *
dupclone(Chan *c, Chan *nc)
{
	return devclone(c, nc);
}

int
dupwalk(Chan *c, char *name)
{
	return devwalk(c, name, (Dirtab *)0, 0, dupgen);
}

void
dupstat(Chan *c, char *db)
{
	devstat(c, db, (Dirtab *)0, 0L, dupgen);
}

Chan *
dupopen(Chan *c, int omode)
{
	Chan *f;

	if(c->qid == CHDIR){
		if(omode != 0)
			error(0, Eisdir);
		c->mode = 0;
		c->flag |= COPEN;
		c->offset = 0;
		return c;
	}
	fdtochan(c->qid, openmode(omode));	/* error check only */
	f = u->fd[c->qid];
	close(c);
	incref(f);
	return f;
}

void
dupcreate(Chan *c, char *name, int omode, ulong perm)
{
	error(0, Eperm);
}

void
dupremove(Chan *c)
{
	error(0, Eperm);
}

void
dupwstat(Chan *c, char *dp)
{
	error(0, Egreg);
}

void
dupclose(Chan *c)
{
}

long
dupread(Chan *c, void *va, long n)
{
	char *a = va;

	if(c->qid != CHDIR)
		panic("dupread");
	return devdirread(c, a, n, (Dirtab *)0, 0L, dupgen);
}

long
dupwrite(Chan *c, void *va, long n)
{
	panic("dupwrite");
}

void
duperrstr(Error *e, char *buf)
{
	rooterrstr(e, buf);
}

void
dupuserstr(Error *e, char *buf)
{
	consuserstr(e, buf);
}
.
## diffname port/devdup.c 1990/11211
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/devdup.c /n/bootesdump/1990/11211/sys/src/9/mips/devdup.c
118,129d
109c
	if(c->qid.path != CHDIR)
.
96c
	error(Egreg);
.
90c
	error(Eperm);
.
84c
	error(Eperm);
.
74,75c
	fdtochan(c->qid.path, openmode(omode));	/* error check only */
	f = u->fd[c->qid.path];
.
68c
			error(Eisdir);
.
66c
	if(c->qid.path == CHDIR){
.
23c
	devdir(c, (Qid){s, 0}, buf, 0, perm[f->mode&3], dp);
.
## diffname port/devdup.c 1991/0320
## diff -e /n/bootesdump/1990/1210/sys/src/9/mips/devdup.c /n/bootesdump/1991/0320/sys/src/9/port/devdup.c
77a
	if(omode & OCEXEC)
		f->flag |= CCEXEC;
.
## diffname port/devdup.c 1991/0411
## diff -e /n/bootesdump/1991/0320/sys/src/9/port/devdup.c /n/bootesdump/1991/0411/sys/src/9/port/devdup.c
117c
dupwrite(Chan *c, void *va, long n, ulong offset)
.
107c
dupread(Chan *c, void *va, long n, ulong offset)
.
## diffname port/devdup.c 1991/0419
## diff -e /n/bootesdump/1991/0411/sys/src/9/port/devdup.c /n/bootesdump/1991/0419/sys/src/9/port/devdup.c
48a
Chan*
dupclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

.
## diffname port/devdup.c 1991/0425
## diff -e /n/bootesdump/1991/0419/sys/src/9/port/devdup.c /n/bootesdump/1991/0425/sys/src/9/port/devdup.c
64c
	int fd;
	Chan *f;

	if(c->qid.path == CHDIR){
		devstat(c, db, (Dirtab *)0, 0L, dupgen);
	}else{
		fd = c->qid.path;
		SET(f);
		if(fd<0 || NFD<=fd || (f=u->fd[fd])==0)
			error(Ebadfd);
		(*devtab[f->type].stat)(f, (char*)db);
	}
.
## diffname port/devdup.c 1991/0426
## diff -e /n/bootesdump/1991/0425/sys/src/9/port/devdup.c /n/bootesdump/1991/0426/sys/src/9/port/devdup.c
64,75c
	devstat(c, db, (Dirtab *)0, 0L, dupgen);
.
## diffname port/devdup.c 1991/0427
## diff -e /n/bootesdump/1991/0426/sys/src/9/port/devdup.c /n/bootesdump/1991/0427/sys/src/9/port/devdup.c
49,54d
## diffname port/devdup.c 1991/0705
## diff -e /n/bootesdump/1991/0427/sys/src/9/port/devdup.c /n/bootesdump/1991/0705/sys/src/9/port/devdup.c
75c
	f = u->p->fgrp->fd[c->qid.path];
.
20c
	if((f=fgrp->fd[s]) == 0)
.
14a
	Fgrp *fgrp = u->p->fgrp;
.
## diffname port/devdup.c 1991/1011
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/devdup.c /n/bootesdump/1991/1011/sys/src/9/port/devdup.c
75c
	fdtochan(c->qid.path, openmode(omode), 0);	/* error check only */
.
## diffname port/devdup.c 1991/1109
## diff -e /n/bootesdump/1991/1011/sys/src/9/port/devdup.c /n/bootesdump/1991/1109/sys/src/9/port/devdup.c
24c
	devdir(c, (Qid){s, 0}, buf, 0, eve, perm[f->mode&3], dp);
.
## diffname port/devdup.c 1991/1115
## diff -e /n/bootesdump/1991/1109/sys/src/9/port/devdup.c /n/bootesdump/1991/1115/sys/src/9/port/devdup.c
119a
	USED(c, va, n, offset);
.
104a
	USED(c);
.
98a
	USED(c);
.
92a
	USED(c);
.
86a
	USED(c, name, omode, perm);
.
## diffname port/devdup.c 1992/0111
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/devdup.c /n/bootesdump/1992/0111/sys/src/9/port/devdup.c
6c
#include	"../port/error.h"
.
## diffname port/devdup.c 1992/0321
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/devdup.c /n/bootesdump/1992/0321/sys/src/9/port/devdup.c
2c
#include	"../port/lib.h"
.
## diffname port/devdup.c 1992/0520
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/devdup.c /n/bootesdump/1992/0520/sys/src/9/port/devdup.c
125a
	return 0;		/* not reached */
.
## diffname port/devdup.c 1992/0711
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/devdup.c /n/bootesdump/1992/0711/sys/src/9/port/devdup.c
115a
	USED(offset);
.
101a
	USED(dp);
.
18a
	USED(tab);
	USED(ntab);
.
## diffname port/devdup.c 1992/0825
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/devdup.c /n/bootesdump/1992/0825/sys/src/9/port/devdup.c
77c
	fdtochan(c->qid.path, openmode(omode), 0, 0);	/* error check only */
.
## diffname port/devdup.c 1993/0501
## diff -e /n/bootesdump/1992/0825/sys/src/9/port/devdup.c /n/fornaxdump/1993/0501/sys/src/brazil/port/devdup.c
78c
	f = up->fgrp->fd[c->qid.path];
.
15c
	Fgrp *fgrp = up->fgrp;
.
## diffname port/devdup.c 1995/0108
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/devdup.c /n/fornaxdump/1995/0108/sys/src/brazil/port/devdup.c
130a
}

long
dupbwrite(Chan *c, Block *bp, ulong offset)
{
	return devbwrite(c, bp, offset);
.
124a
Block*
dupbread(Chan *c, long n, ulong offset)
{
	return devbread(c, n, offset);
}

.
## diffname port/devdup.c 1995/0804
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/port/devdup.c /n/fornaxdump/1995/0804/sys/src/brazil/port/devdup.c
134d
132c
dupwrite(Chan*, void*, long, ulong)
.
119d
115c
dupread(Chan *c, void *va, long n, ulong)
.
111d
109c
dupclose(Chan*)
.
103,104d
101c
dupwstat(Chan*, char*)
.
96d
94c
dupremove(Chan*)
.
89d
87c
dupcreate(Chan*, char*, int, ulong)
.
19,20d
12c
dupgen(Chan *c, Dirtab*, int, int s, Dir *dp)
.
## diffname port/devdup.c 1996/0223
## diff -e /n/fornaxdump/1995/0804/sys/src/brazil/port/devdup.c /n/fornaxdump/1996/0223/sys/src/brazil/port/devdup.c
8d
## diffname port/devdup.c 1997/0327
## diff -e /n/fornaxdump/1996/0223/sys/src/brazil/port/devdup.c /n/emeliedump/1997/0327/sys/src/brazil/port/devdup.c
129,133c
Dev dupdevtab = {
	devreset,
	devinit,
	dupattach,
	devclone,
	dupwalk,
	dupstat,
	dupopen,
	devcreate,
	dupclose,
	dupread,
	devbread,
	dupwrite,
	devbwrite,
	devremove,
	devwstat,
};
.
116,122c
static long
.
106c
static long
.
83,101c
static void
.
76c
	cclose(c);
.
61c
static Chan*
.
55c
static void
.
43,49c
static int
.
27,37c
static Chan*
.
8,10c
static int
.
## diffname port/devdup.c 1997/0408
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/devdup.c /n/emeliedump/1997/0408/sys/src/brazil/port/devdup.c
87a
	'd',
	"dup",

.
## diffname port/devdup.c 1997/0603
## diff -e /n/emeliedump/1997/0408/sys/src/brazil/port/devdup.c /n/emeliedump/1997/0603/sys/src/brazil/port/devdup.c
16c
	if(s >= fgrp->maxfd)
.
## diffname port/devdup.c 1997/0606
## diff -e /n/emeliedump/1997/0603/sys/src/brazil/port/devdup.c /n/emeliedump/1997/0606/sys/src/brazil/port/devdup.c
16c
	if(s > fgrp->maxfd)
.
## diffname port/devdup.c 1998/0319
## diff -e /n/emeliedump/1997/0606/sys/src/brazil/port/devdup.c /n/emeliedump/1998/0319/sys/src/brazil/port/devdup.c
81c
dupwrite(Chan*, void*, long, vlong)
.
71c
dupread(Chan *c, void *va, long n, vlong)
.
## diffname port/devdup.c 1998/0825
## diff -e /n/emeliedump/1998/0319/sys/src/brazil/port/devdup.c /n/emeliedump/1998/0825/sys/src/brazil/port/devdup.c
20c
	sprint(buf, "%d", s);
.
## diffname port/devdup.c 1999/1230
## diff -e /n/emeliedump/1998/0825/sys/src/brazil/port/devdup.c /n/emeliedump/1999/1230/sys/src/9/port/devdup.c
15a
	if(s == DEVDOTDOT){
		devdir(c, c->qid, "#d", 0, eve, 0555, dp);
		return 1;
	}
.
## diffname port/devdup.c 2001/0527
## diff -e /n/emeliedump/1999/1230/sys/src/9/port/devdup.c /n/emeliedump/2001/0527/sys/src/9/port/devdup.c
98d
86a
	if(c->qid.path & 1){
		print("do ctl write\n");
		return -1;
	}
.
85c
dupwrite(Chan *c, void *va, long n, vlong)
.
79,81c
	if(c->qid.type == QTDIR)
		return devdirread(c, a, n, (Dirtab *)0, 0L, dupgen);
	twicefd = c->qid.path - 1;
	fd = twicefd/2;
	f = up->fgrp;
	if(twicefd & 1){
		if(fd<0 || f->nfd<=fd)
			error(Ebadfd);
		c = fdtochan(fd, -1, 0, 0);
		snprint(buf, sizeof buf, "%d %ld", fd, c->iounit);
		return readstr((ulong)offset, va, n, buf);
	}
	panic("dupread");
	return 0;
.
77a
	char buf[256];
	int fd, twicefd;
	Fgrp *f;
.
75c
dupread(Chan *c, void *va, long n, vlong offset)
.
60,63c
	twicefd = c->qid.path - 1;
	fd = twicefd/2;
	if((twicefd & 1)){
		/* ctl file */
		f = c;
	}else{
		/* fd file */
		fdtochan(fd, openmode(omode), 0, 0);	/* error check only */
		f = up->fgrp->fd[fd];
		cclose(c);
		incref(f);
	}
.
52c
	if(c->qid.type == QTDIR){
.
50a
	int fd, twicefd;
.
44c
	return devstat(c, db, n, (Dirtab *)0, 0L, dupgen);
.
41,42c
static int
dupstat(Chan *c, uchar *db, int n)
.
38c
	return devwalk(c, nc, name, nname, (Dirtab *)0, 0, dupgen);
.
35,36c
static Walkqid*
dupwalk(Chan *c, Chan *nc, char **name, int nname)
.
24,25c
	if(s & 1){
		p = 0600;
		sprint(up->genbuf, "%dctl", s/2);
	}else{
		p = perm[f->mode&3];
		sprint(up->genbuf, "%d", s/2);
	}
	mkqid(&q, s+1, 0, QTFILE);
	devdir(c, q, up->genbuf, 0, eve, p, dp);
.
22c
	if((f=fgrp->fd[s/2]) == nil)
.
20c
	if(s == 0)
		return 0;
	s--;
	if(s > 2*fgrp->maxfd)
.
17c
		devdir(c, c->qid, ".", 0, eve, DMDIR|0555, dp);
.
14a
	int p;
	Qid q;
.
11d
9c
dupgen(Chan *c, char *, Dirtab*, int, int s, Dir *dp)
.
7a
/* Qid is (2*fd + (file is ctl))+1 */

.
## diffname port/devdup.c 2001/0712
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/devdup.c /n/emeliedump/2001/0712/sys/src/9/port/devdup.c
121c
dupwrite(Chan *c, void*, long, vlong)
.
## diffname port/devdup.c 2001/0802
## diff -e /n/emeliedump/2001/0712/sys/src/9/port/devdup.c /n/emeliedump/2001/0802/sys/src/9/port/devdup.c
123c
	int fd, twicefd;

	twicefd = c->qid.path - 1;
	fd = twicefd/2;
	if(twicefd & 1){
print("writing ctl file\n");
.
78a
		f->mode = openmode(omode);
		f->flag |= COPEN;
		f->offset = 0;
.
## diffname port/devdup.c 2001/0803
## diff -e /n/emeliedump/2001/0802/sys/src/9/port/devdup.c /n/emeliedump/2001/0803/sys/src/9/port/devdup.c
126,134d
124c
dupwrite(Chan*, void*, long, vlong)
.
116c
		procfdprint(c, fd, 0, buf, sizeof buf);
.
104c
	int fd, twicefd, m;
.
31c
		p = 0400;
.
## diffname port/devdup.c 2001/0819
## diff -e /n/emeliedump/2001/0803/sys/src/9/port/devdup.c /n/emeliedump/2001/0819/sys/src/9/port/devdup.c
73a
	if(c->qid.type & QTAUTH)
		error(Eperm);
.
66c
	if(c->qid.type & QTDIR){
.
## diffname port/devdup.c 2001/0820
## diff -e /n/emeliedump/2001/0819/sys/src/9/port/devdup.c /n/emeliedump/2001/0820/sys/src/9/port/devdup.c
26c
	if(s/2 > fgrp->maxfd)
.
## diffname port/devdup.c 2001/0822
## diff -e /n/emeliedump/2001/0820/sys/src/9/port/devdup.c /n/emeliedump/2001/0822/sys/src/9/port/devdup.c
106c
	int fd, twicefd;
.
## diffname port/devdup.c 2001/1005
## diff -e /n/emeliedump/2001/0822/sys/src/9/port/devdup.c /n/emeliedump/2001/1005/sys/src/9/port/devdup.c
118a
		cclose(c);
.
115,117c
		c = fdtochan(fd, -1, 0, 1);
.
113d
107d
89d
86,87c
		f = fdtochan(fd, openmode(omode), 0, 1);
.
## diffname port/devdup.c 2002/0109
## diff -e /n/emeliedump/2001/1005/sys/src/9/port/devdup.c /n/emeliedump/2002/0109/sys/src/9/port/devdup.c
132a
	devshutdown,
.

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.