plan 9 kernel history: overview | file list | diff list

1990/0617/port/sysfile.c (diff list | history)

1990/0227/sys/src/9/port/sysfile.c:126,1321990/0321/sys/src/9/port/sysfile.c:126,132 (short | long)
1990/0227    
	mnt = c->mnt; 
	lock(pg); 
	if(c->mountid != mnt->mountid){ 
		print("unionread: changed underfoot?\n"); 
1990/0321    
		pprint("unionread: changed underfoot?\n"); 
1990/0227    
		unlock(pg); 
		return 0; 
	} 
1990/0321/sys/src/9/port/sysfile.c:406,4151990/03292/sys/src/9/port/sysfile.c:406,411 (short | long)
1990/0227    
	c[1] = (*d->clone)(c[0], 0); 
	c[0] = (*d->open)(c[0], ORDWR); 
	c[1] = (*d->open)(c[1], ORDWR); 
	c[0]->mode = 2; 
	c[1]->mode = 2; 
	c[0]->flag |= COPEN; 
	c[1]->flag |= COPEN; 
	fd[0] = newfd(); 
	u->fd[fd[0]] = c[0]; 
	fd[1] = newfd(); 
1990/03292/sys/src/9/port/sysfile.c:283,2881990/0513/sys/src/9/port/sysfile.c:283,289 (short | long)
1990/0227    
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Aaccess, 0, 0); 
	if(waserror()){ 
1990/0513    
print("stat error\n"); 
1990/0227    
		close(c); 
		nexterror(); 
	} 
1990/0513/sys/src/9/port/sysfile.c:283,2891990/0617/sys/src/9/port/sysfile.c:283,288 (short | long)
1990/0227    
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Aaccess, 0, 0); 
	if(waserror()){ 
1990/0513    
print("stat error\n"); 
1990/0227    
		close(c); 
		nexterror(); 
	} 
1990/0617/sys/src/9/port/sysfile.c:457,4621990/0703/sys/src/9/port/sysfile.c:457,463 (short | long)
1990/0227    
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Aaccess, 0, 0); 
	if(waserror()){ 
1990/0703    
		c->type = 0;	/* see below */ 
1990/0227    
		close(c); 
		nexterror(); 
	} 
1990/0703/sys/src/9/port/sysfile.c:44,531990/08141/sys/src/9/port/sysfile.c:44,53 (short | long)
1990/0227    
int 
openmode(ulong o) 
{ 
	if(o >= (OTRUNC|OEXEC)) 
1990/08141    
	if(o >= (OTRUNC|OCEXEC|ORCLOSE|OEXEC)) 
1990/0227    
    Err: 
		error(0, Ebadarg); 
	o &= ~OTRUNC; 
1990/08141    
	o &= ~(OTRUNC|OCEXEC|ORCLOSE); 
1990/0227    
	if(o > OEXEC) 
		goto Err; 
	if(o == OEXEC) 
1990/08141/sys/src/9/port/sysfile.c:148,1531990/0821/sys/src/9/port/sysfile.c:148,154 (short | long)
1990/0227    
	nc = (*devtab[nc->type].open)(nc, OREAD); 
	nc->offset = c->offset; 
	nr = (*devtab[nc->type].read)(nc, va, n); 
1990/0821    
	c->offset = nc->offset;		/* devdirread e.g. changes it */ 
1990/0227    
	close(nc); 
	poperror(); 
	if(nr > 0) 
1990/08141/sys/src/9/port/sysfile.c:192,1981990/0821/sys/src/9/port/sysfile.c:193,199
1990/0227    
		if(c->offset%DIRLEN || n==0) 
			error(0, Ebaddirread); 
	} 
	if((c->qid&CHDIR) && c->flag&CMOUNT) 
1990/0821    
	if((c->qid&CHDIR) && (c->flag&CMOUNT)) 
1990/0227    
		n = unionread(c, (void*)arg[1], n); 
	else 
		n = (*devtab[c->type].read)(c, (void*)arg[1], n); 
1990/0821/sys/src/9/port/sysfile.c:299,3091990/0822/sys/src/9/port/sysfile.c:299,305 (short | long)
1990/0227    
	Chan *c; 
	long mode; 
 
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Aaccess, 0, 0); 
	mode = c->mode; 
	close(c); 
	/* BUG: check modes */ 
1990/0822    
	postnote(u->p, 1, "access is deprecated", NDebug); 
1990/0227    
	return 0; 
} 
 
1990/0822/sys/src/9/port/sysfile.c:321,3261990/0918/sys/src/9/port/sysfile.c:321,328 (short | long)
1990/0227    
	Chan *c0, *c1; 
	ulong flag; 
	long ret; 
1990/0918    
	char *p; 
	int t; 
1990/0227    
	struct{ 
		Chan	*chan; 
		char	*spec; 
1990/0822/sys/src/9/port/sysfile.c:331,3381990/0918/sys/src/9/port/sysfile.c:333,344
1990/0227    
		error(0, Ebadarg); 
	if(ismount){ 
		bogus.chan = fdtochan(arg[0], 2); 
/*BUG: check validaddr for ALL of arg[3]!! */ 
		validaddr(arg[3], 1, 0); 
1990/0918    
		p = (char*)arg[3]; 
		t = BY2PG-((ulong)p&(BY2PG-1)); 
		while(vmemchr(p, 0, t) == 0){ 
			p += t; 
			t = BY2PG; 
		} 
1990/0227    
		bogus.spec = (char*)arg[3]; 
		ret = devno('M', 0); 
		c0 = (*devtab[ret].attach)((char*)&bogus); 
1990/0918/sys/src/9/port/sysfile.c:181,1871990/1004/sys/src/9/port/sysfile.c:181,187 (short | long)
1990/0227    
	long n; 
 
	c = fdtochan(arg[0], 0); 
	validaddr(arg[1], arg[2], 0); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1990/0227    
	qlock(c); 
	if(waserror()){ 
		qunlock(c); 
1990/1004/sys/src/9/port/sysfile.c:31,421990/1009/sys/src/9/port/sysfile.c:31,42 (short | long)
1990/0227    
 
	if(fd<0 || NFD<=fd || (c=u->fd[fd])==0) 
		error(0, Ebadfd); 
	if(mode<0 || c->mode == 2) 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1990/0227    
		return c; 
	if((mode&16) && c->mode==0) 
1990/1009    
	if((mode&OTRUNC) && c->mode==OREAD) 
1990/0227    
    err: 
		error(0, Ebadusefd); 
	if((mode&~16) != c->mode) 
1990/1009    
	if((mode&~OTRUNC) != c->mode) 
1990/0227    
		goto err; 
	return c; 
} 
1990/1004/sys/src/9/port/sysfile.c:56,611990/1009/sys/src/9/port/sysfile.c:56,100
1990/0227    
} 
 
long 
1990/1009    
syspipe(ulong *arg) 
{ 
	int fd[2]; 
	Chan *c[2]; 
	Dev *d; 
 
	validaddr(arg[0], 2*BY2WD, 1); 
	evenaddr(arg[0]); 
	d = &devtab[devno('|', 0)]; 
	c[0] = (*d->attach)(0); 
	c[1] = 0; 
	fd[0] = -1; 
	fd[1] = -1; 
	if(waserror()){ 
		close(c[0]); 
		if(c[1]) 
			close(c[1]); 
		if(fd[0] >= 0) 
			u->fd[fd[0]]=0; 
		if(fd[1] >= 0) 
			u->fd[fd[1]]=0; 
		nexterror(); 
	} 
	c[1] = (*d->clone)(c[0], 0); 
	(*d->walk)(c[0], "data"); 
	(*d->walk)(c[1], "data1"); 
	c[0] = (*d->open)(c[0], ORDWR); 
	c[1] = (*d->open)(c[1], ORDWR); 
	fd[0] = newfd(); 
	u->fd[fd[0]] = c[0]; 
	fd[1] = newfd(); 
	u->fd[fd[1]] = c[1]; 
	((long*)arg[0])[0] = fd[0]; 
	((long*)arg[0])[1] = fd[1]; 
	poperror(); 
	return 0; 
} 
 
long 
1990/0227    
sysdup(ulong *arg) 
{ 
	int fd; 
1990/1004/sys/src/9/port/sysfile.c:180,1861990/1009/sys/src/9/port/sysfile.c:219,225
1990/0227    
	Chan *c; 
	long n; 
 
	c = fdtochan(arg[0], 0); 
1990/1009    
	c = fdtochan(arg[0], OREAD); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1990/0227    
	qlock(c); 
	if(waserror()){ 
1990/1004/sys/src/9/port/sysfile.c:208,2141990/1009/sys/src/9/port/sysfile.c:247,253
1990/0227    
	Chan *c; 
	long n; 
 
	c = fdtochan(arg[0], 1); 
1990/1009    
	c = fdtochan(arg[0], OWRITE); 
1990/0227    
	validaddr(arg[1], arg[2], 0); 
	qlock(c); 
	if(waserror()){ 
1990/1004/sys/src/9/port/sysfile.c:380,4221990/1009/sys/src/9/port/sysfile.c:419,424
1990/0227    
sysmount(ulong *arg) 
{ 
	return bindmount(arg, 1); 
} 
                 
long 
syspipe(ulong *arg) 
{ 
	int fd[2]; 
	Chan *c[2]; 
	Dev *d; 
                 
	validaddr(arg[0], 2*BY2WD, 1); 
	evenaddr(arg[0]); 
	d = &devtab[devno('|', 0)]; 
	c[0] = (*d->attach)(0); 
	c[1] = 0; 
	fd[0] = -1; 
	fd[1] = -1; 
	if(waserror()){ 
		close(c[0]); 
		if(c[1]) 
			close(c[1]); 
		if(fd[0] >= 0) 
			u->fd[fd[0]]=0; 
		if(fd[1] >= 0) 
			u->fd[fd[1]]=0; 
		nexterror(); 
	} 
	c[1] = (*d->clone)(c[0], 0); 
	c[0] = (*d->open)(c[0], ORDWR); 
	c[1] = (*d->open)(c[1], ORDWR); 
	fd[0] = newfd(); 
	u->fd[fd[0]] = c[0]; 
	fd[1] = newfd(); 
	u->fd[fd[1]] = c[1]; 
	((long*)arg[0])[0] = fd[0]; 
	((long*)arg[0])[1] = fd[1]; 
	poperror(); 
	return 0; 
} 
 
long 
1990/1009/sys/src/9/port/sysfile.c:21,271990/11211/sys/src/9/port/sysfile.c:21,27 (short | long)
1990/0227    
				u->maxfd = i; 
			return i; 
		} 
	error(0, Enofd); 
1990/11211    
	error(Enofd); 
1990/0227    
} 
 
Chan* 
1990/1009/sys/src/9/port/sysfile.c:30,411990/11211/sys/src/9/port/sysfile.c:30,41
1990/0227    
	Chan *c; 
 
	if(fd<0 || NFD<=fd || (c=u->fd[fd])==0) 
		error(0, Ebadfd); 
1990/11211    
		error(Ebadfd); 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1990/0227    
		return c; 
1990/1009    
	if((mode&OTRUNC) && c->mode==OREAD) 
1990/0227    
    err: 
		error(0, Ebadusefd); 
1990/11211    
		error(Ebadusefd); 
1990/1009    
	if((mode&~OTRUNC) != c->mode) 
1990/0227    
		goto err; 
	return c; 
1990/1009/sys/src/9/port/sysfile.c:46,521990/11211/sys/src/9/port/sysfile.c:46,52
1990/0227    
{ 
1990/08141    
	if(o >= (OTRUNC|OCEXEC|ORCLOSE|OEXEC)) 
1990/0227    
    Err: 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/08141    
	o &= ~(OTRUNC|OCEXEC|ORCLOSE); 
1990/0227    
	if(o > OEXEC) 
		goto Err; 
1990/1009/sys/src/9/port/sysfile.c:227,2381990/11211/sys/src/9/port/sysfile.c:227,238
1990/0227    
		nexterror(); 
	} 
	n = arg[2]; 
	if(c->qid&CHDIR){ 
1990/11211    
	if(c->qid.path & CHDIR){ 
1990/0227    
		n -= n%DIRLEN; 
		if(c->offset%DIRLEN || n==0) 
			error(0, Ebaddirread); 
1990/11211    
			error(Ebaddirread); 
1990/0227    
	} 
1990/0821    
	if((c->qid&CHDIR) && (c->flag&CMOUNT)) 
1990/11211    
	if((c->qid.path&CHDIR) && (c->flag&CMOUNT)) 
1990/0227    
		n = unionread(c, (void*)arg[1], n); 
	else 
		n = (*devtab[c->type].read)(c, (void*)arg[1], n); 
1990/1009/sys/src/9/port/sysfile.c:254,2611990/11211/sys/src/9/port/sysfile.c:254,261
1990/0227    
		qunlock(c); 
		nexterror(); 
	} 
	if(c->qid & CHDIR) 
		error(0, Eisdir); 
1990/11211    
	if(c->qid.path & CHDIR) 
		error(Eisdir); 
1990/0227    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2]); 
	c->offset += n; 
	qunlock(c); 
1990/1009/sys/src/9/port/sysfile.c:271,2781990/11211/sys/src/9/port/sysfile.c:271,278
1990/0227    
	long off; 
 
	c = fdtochan(arg[0], -1); 
	if(c->qid & CHDIR) 
		error(0, Eisdir); 
1990/11211    
	if(c->qid.path & CHDIR) 
		error(Eisdir); 
1990/0227    
	qlock(c); 
	if(waserror()){ 
		qunlock(c); 
1990/1009/sys/src/9/port/sysfile.c:365,3771990/11211/sys/src/9/port/sysfile.c:365,379
1990/0227    
	struct{ 
		Chan	*chan; 
		char	*spec; 
1990/11211    
		char	*auth; 
1990/0227    
	}bogus; 
 
	flag = arg[2]; 
	if(flag>MMASK || (flag&MORDER)==(MBEFORE|MAFTER)) 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0227    
	if(ismount){ 
		bogus.chan = fdtochan(arg[0], 2); 
1990/11211    
		validaddr(arg[3], 1, 0); 
1990/0918    
		p = (char*)arg[3]; 
		t = BY2PG-((ulong)p&(BY2PG-1)); 
		while(vmemchr(p, 0, t) == 0){ 
1990/1009/sys/src/9/port/sysfile.c:379,3841990/11211/sys/src/9/port/sysfile.c:381,394
1990/0918    
			t = BY2PG; 
		} 
1990/0227    
		bogus.spec = (char*)arg[3]; 
1990/11211    
		validaddr(arg[4], 1, 0); 
		p = (char*)arg[4]; 
		t = BY2PG-((ulong)p&(BY2PG-1)); 
		while(vmemchr(p, 0, t) == 0){ 
			p += t; 
			t = BY2PG; 
		} 
		bogus.auth = (char*)arg[4]; 
1990/0227    
		ret = devno('M', 0); 
		c0 = (*devtab[ret].attach)((char*)&bogus); 
	}else{ 
1990/1009/sys/src/9/port/sysfile.c:395,4041990/11211/sys/src/9/port/sysfile.c:405,414
1990/0227    
		close(c1); 
		nexterror(); 
	} 
	if((c0->qid^c1->qid) & CHDIR) 
		error(0, Ebadmount); 
	if(flag && !(c0->qid&CHDIR)) 
		error(0, Ebadmount); 
1990/11211    
	if((c0->qid.path^c1->qid.path) & CHDIR) 
		error(Ebadmount); 
	if(flag && !(c0->qid.path&CHDIR)) 
		error(Ebadmount); 
1990/0227    
	ret = mount(c0, c1, flag); 
	close(c0); 
	close(c1); 
1990/1009/sys/src/9/port/sysfile.c:433,4571990/11211/sys/src/9/port/sysfile.c:443,448
1990/0227    
	c = namec((char*)arg[0], Acreate, arg[1], arg[2]); 
	u->fd[fd] = c; 
	return fd; 
} 
                 
long 
sysuserstr(ulong *arg) 
{ 
	Error err; 
	char buf[NAMELEN]; 
                 
	validaddr(arg[0], sizeof(Error), 0); 
	validaddr(arg[1], NAMELEN, 1); 
	err = *(Error*)arg[0]; 
	err.type = devno(err.type, 1); 
	if(err.type == -1) 
		strcpy((char*)arg[1], "*gok*"); 
	else{ 
		(*devtab[err.type].userstr)(&err, buf); 
		memcpy((char*)arg[1], buf, sizeof buf); 
	} 
	return 0; 
} 
 
long 
1990/11211/sys/src/9/port/sysfile.c:29,341990/1126/sys/src/9/port/sysfile.c:29,35 (short | long)
1990/0227    
{ 
	Chan *c; 
 
1990/1126    
	c = 0;	/* set */ 
1990/0227    
	if(fd<0 || NFD<=fd || (c=u->fd[fd])==0) 
1990/11211    
		error(Ebadfd); 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1990/11211/sys/src/9/port/sysfile.c:329,3441990/1126/sys/src/9/port/sysfile.c:330,335
1990/0227    
	(*devtab[c->type].stat)(c, (char*)arg[1]); 
	poperror(); 
	close(c); 
	return 0; 
} 
                 
long 
sysaccess(ulong *arg) 
{ 
	Chan *c; 
	long mode; 
                 
1990/0822    
	postnote(u->p, 1, "access is deprecated", NDebug); 
1990/0227    
	return 0; 
} 
 
1990/1126/sys/src/9/port/sysfile.c:29,351990/1210/sys/src/9/port/sysfile.c:29,35 (short | long)
Created.
rsc Fri Mar 4 12:44:25 2005
1990/0227    
{ 
	Chan *c; 
 
1990/1126    
	c = 0;	/* set */ 
1990/1210    
	c = 0;		/* set */ 
1990/0227    
	if(fd<0 || NFD<=fd || (c=u->fd[fd])==0) 
1990/11211    
		error(Ebadfd); 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1990/1126/sys/src/9/port/sysfile.c:490,4921990/1210/sys/src/9/port/sysfile.c:490,508
1990/0227    
	(*devtab[c->type].wstat)(c, (char*)arg[1]); 
	return 0; 
} 
1990/1210    
 
#ifdef asdf 
long 
sysfilsys(ulong *arg) 
{ 
	Chan *cin, *cout; 
 
	cin = fdtochan(arg[0], OREAD); 
	cout = fdtochan(arg[1], OWRITE); 
	validaddr(arg[2], 1, 0); 
	if((cin->qid.path&CHDIR) || (cout->qid.path&CHDIR)) 
		error(Ebadarg); 
	service((char *)arg[2], cin, cout, filsys); 
	return 0; 
} 
#endif 
1990/1210/sys/src/9/port/sysfile.c:106,1141991/0221/sys/src/9/port/sysfile.c:106,118 (short | long)
Bug fix: check for invalid file descriptors.
rsc Fri Mar 4 17:11:41 2005
1990/0227    
	 */ 
	c = fdtochan(arg[0], -1); 
	fd = arg[1]; 
	if(fd != -1) 
1991/0221    
	if(fd != -1){ 
		if(fd<0 || NFD<=fd) 
			error(Ebadfd); 
		if(fd > u->maxfd) 
			u->maxfd = fd; 
1990/0227    
		oc = u->fd[fd]; 
	else{ 
1991/0221    
	}else{ 
1990/0227    
		oc = 0; 
		fd = newfd(); 
	} 
1991/0221/sys/src/9/port/sysfile.c:278,2831991/0319/sys/src/9/port/sysfile.c:278,285 (short | long)
Disallow seek on pipe.
rsc Fri Mar 4 17:11:42 2005
1990/0227    
	c = fdtochan(arg[0], -1); 
1990/11211    
	if(c->qid.path & CHDIR) 
		error(Eisdir); 
1991/0319    
	if(devchar[c->type] == '|') 
		error(Eisstream); 
1990/0227    
	qlock(c); 
	if(waserror()){ 
		qunlock(c); 
1991/0319/sys/src/9/port/sysfile.c:191,1971991/0411/sys/src/9/port/sysfile.c:191,197 (short | long)
Bug fix: add explicit read lock and write lock instead of using channel's qlock. This way a process can write even if another process is blocked doing a read. Add explicit offset to dev read and write to accomodate this.
rsc Fri Mar 4 17:11:43 2005
1990/0227    
	} 
	nc = (*devtab[nc->type].open)(nc, OREAD); 
	nc->offset = c->offset; 
	nr = (*devtab[nc->type].read)(nc, va, n); 
1991/0411    
	nr = (*devtab[nc->type].read)(nc, va, n, nc->offset); 
1990/0821    
	c->offset = nc->offset;		/* devdirread e.g. changes it */ 
1990/0227    
	close(nc); 
	poperror(); 
1991/0319/sys/src/9/port/sysfile.c:226,2341991/0411/sys/src/9/port/sysfile.c:226,234
1990/0227    
 
1990/1009    
	c = fdtochan(arg[0], OREAD); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1990/0227    
	qlock(c); 
1991/0411    
	qlock(&c->rdl); 
1990/0227    
	if(waserror()){ 
		qunlock(c); 
1991/0411    
		qunlock(&c->rdl); 
1990/0227    
		nexterror(); 
	} 
	n = arg[2]; 
1991/0319/sys/src/9/port/sysfile.c:240,2481991/0411/sys/src/9/port/sysfile.c:240,248
1990/11211    
	if((c->qid.path&CHDIR) && (c->flag&CMOUNT)) 
1990/0227    
		n = unionread(c, (void*)arg[1], n); 
	else 
		n = (*devtab[c->type].read)(c, (void*)arg[1], n); 
1991/0411    
		n = (*devtab[c->type].read)(c, (void*)arg[1], n, c->offset); 
1990/0227    
	c->offset += n; 
	qunlock(c); 
1991/0411    
	qunlock(&c->rdl); 
1990/0227    
	return n; 
} 
 
1991/0319/sys/src/9/port/sysfile.c:254,2691991/0411/sys/src/9/port/sysfile.c:254,269
1990/0227    
 
1990/1009    
	c = fdtochan(arg[0], OWRITE); 
1990/0227    
	validaddr(arg[1], arg[2], 0); 
	qlock(c); 
1991/0411    
	qlock(&c->wrl); 
1990/0227    
	if(waserror()){ 
		qunlock(c); 
1991/0411    
		qunlock(&c->wrl); 
1990/0227    
		nexterror(); 
	} 
1990/11211    
	if(c->qid.path & CHDIR) 
		error(Eisdir); 
1990/0227    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2]); 
1991/0411    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2], c->offset); 
1990/0227    
	c->offset += n; 
	qunlock(c); 
1991/0411    
	qunlock(&c->wrl); 
1990/0227    
	return n; 
} 
 
1991/0319/sys/src/9/port/sysfile.c:280,2881991/0411/sys/src/9/port/sysfile.c:280,290
1990/11211    
		error(Eisdir); 
1991/0319    
	if(devchar[c->type] == '|') 
		error(Eisstream); 
1990/0227    
	qlock(c); 
1991/0411    
	qlock(&c->rdl); 
	qlock(&c->wrl); 
1990/0227    
	if(waserror()){ 
		qunlock(c); 
1991/0411    
		qunlock(&c->rdl); 
		qunlock(&c->wrl); 
1990/0227    
		nexterror(); 
	} 
	switch(arg[2]){ 
1991/0319/sys/src/9/port/sysfile.c:301,3071991/0411/sys/src/9/port/sysfile.c:303,310
1990/0227    
		break; 
	} 
	off = c->offset; 
	qunlock(c); 
1991/0411    
	qunlock(&c->rdl); 
	qunlock(&c->wrl); 
1990/0227    
	poperror(); 
	return off; 
} 
1991/0411/sys/src/9/port/sysfile.c:227,2341991/0417/sys/src/9/port/sysfile.c:227,236 (short | long)
Debugging: acquire both locks during read and write.
rsc Fri Mar 4 17:11:43 2005
1990/1009    
	c = fdtochan(arg[0], OREAD); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1991/0411    
	qlock(&c->rdl); 
1991/0417    
	qlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
	if(waserror()){ 
1991/0411    
		qunlock(&c->rdl); 
1991/0417    
		qunlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
		nexterror(); 
	} 
	n = arg[2]; 
1991/0411/sys/src/9/port/sysfile.c:243,2481991/0417/sys/src/9/port/sysfile.c:245,251
1991/0411    
		n = (*devtab[c->type].read)(c, (void*)arg[1], n, c->offset); 
1990/0227    
	c->offset += n; 
1991/0411    
	qunlock(&c->rdl); 
1991/0417    
	qunlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
	return n; 
} 
 
1991/0411/sys/src/9/port/sysfile.c:254,2611991/0417/sys/src/9/port/sysfile.c:257,266
1990/0227    
 
1990/1009    
	c = fdtochan(arg[0], OWRITE); 
1990/0227    
	validaddr(arg[1], arg[2], 0); 
1991/0417    
	qlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
	qlock(&c->wrl); 
1990/0227    
	if(waserror()){ 
1991/0417    
		qunlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
		qunlock(&c->wrl); 
1990/0227    
		nexterror(); 
	} 
1991/0411/sys/src/9/port/sysfile.c:263,2681991/0417/sys/src/9/port/sysfile.c:268,274
1990/11211    
		error(Eisdir); 
1991/0411    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2], c->offset); 
1990/0227    
	c->offset += n; 
1991/0417    
	qunlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
	qunlock(&c->wrl); 
1990/0227    
	return n; 
} 
1991/0417/sys/src/9/port/sysfile.c:227,2361991/0419/sys/src/9/port/sysfile.c:227,234 (short | long)
Remove debugging.
rsc Fri Mar 4 17:11:43 2005
1990/1009    
	c = fdtochan(arg[0], OREAD); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1991/0411    
	qlock(&c->rdl); 
1991/0417    
	qlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
	if(waserror()){ 
1991/0411    
		qunlock(&c->rdl); 
1991/0417    
		qunlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
		nexterror(); 
	} 
	n = arg[2]; 
1991/0417/sys/src/9/port/sysfile.c:245,2511991/0419/sys/src/9/port/sysfile.c:243,248
1991/0411    
		n = (*devtab[c->type].read)(c, (void*)arg[1], n, c->offset); 
1990/0227    
	c->offset += n; 
1991/0411    
	qunlock(&c->rdl); 
1991/0417    
	qunlock(&c->wrl);		/* BUG BUG BUG */ 
1990/0227    
	return n; 
} 
 
1991/0417/sys/src/9/port/sysfile.c:257,2661991/0419/sys/src/9/port/sysfile.c:254,261
1990/0227    
 
1990/1009    
	c = fdtochan(arg[0], OWRITE); 
1990/0227    
	validaddr(arg[1], arg[2], 0); 
1991/0417    
	qlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
	qlock(&c->wrl); 
1990/0227    
	if(waserror()){ 
1991/0417    
		qunlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
		qunlock(&c->wrl); 
1990/0227    
		nexterror(); 
	} 
1991/0417/sys/src/9/port/sysfile.c:268,2741991/0419/sys/src/9/port/sysfile.c:263,268
1990/11211    
		error(Eisdir); 
1991/0411    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2], c->offset); 
1990/0227    
	c->offset += n; 
1991/0417    
	qunlock(&c->rdl);		/* BUG BUG BUG */ 
1991/0411    
	qunlock(&c->wrl); 
1990/0227    
	return n; 
} 
1991/0419/sys/src/9/port/sysfile.c:227,2321991/0501/sys/src/9/port/sysfile.c:227,233 (short | long)
Whitespace edit.
rsc Fri Mar 4 17:11:44 2005
1990/1009    
	c = fdtochan(arg[0], OREAD); 
1990/1004    
	validaddr(arg[1], arg[2], 1); 
1991/0411    
	qlock(&c->rdl); 
1991/0501    
 
1990/0227    
	if(waserror()){ 
1991/0411    
		qunlock(&c->rdl); 
1990/0227    
		nexterror(); 
1991/0419/sys/src/9/port/sysfile.c:255,2601991/0501/sys/src/9/port/sysfile.c:256,262
1990/1009    
	c = fdtochan(arg[0], OWRITE); 
1990/0227    
	validaddr(arg[1], arg[2], 0); 
1991/0411    
	qlock(&c->wrl); 
1991/0501    
 
1990/0227    
	if(waserror()){ 
1991/0411    
		qunlock(&c->wrl); 
1990/0227    
		nexterror(); 
1991/0501/sys/src/9/port/sysfile.c:243,2481991/0614/sys/src/9/port/sysfile.c:243,249 (short | long)
Possible semantics change: insert poperrors in read, write, remove, despite comment at top of file.
Bug fix: poperror bug in mount.
rsc Fri Mar 4 17:11:44 2005
1990/0227    
	else 
1991/0411    
		n = (*devtab[c->type].read)(c, (void*)arg[1], n, c->offset); 
1990/0227    
	c->offset += n; 
1991/0614    
	poperror(); 
1991/0411    
	qunlock(&c->rdl); 
1990/0227    
	return n; 
} 
1991/0501/sys/src/9/port/sysfile.c:265,2701991/0614/sys/src/9/port/sysfile.c:266,272
1990/11211    
		error(Eisdir); 
1991/0411    
	n = (*devtab[c->type].write)(c, (void*)arg[1], arg[2], c->offset); 
1990/0227    
	c->offset += n; 
1991/0614    
	poperror(); 
1991/0411    
	qunlock(&c->wrl); 
1990/0227    
	return n; 
} 
1991/0501/sys/src/9/port/sysfile.c:305,3131991/0614/sys/src/9/port/sysfile.c:307,315
1990/0227    
		break; 
	} 
	off = c->offset; 
1991/0614    
	poperror(); 
1991/0411    
	qunlock(&c->rdl); 
	qunlock(&c->wrl); 
1990/0227    
	poperror(); 
	return off; 
} 
 
1991/0501/sys/src/9/port/sysfile.c:412,4191991/0614/sys/src/9/port/sysfile.c:414,423
1990/11211    
	if(flag && !(c0->qid.path&CHDIR)) 
		error(Ebadmount); 
1990/0227    
	ret = mount(c0, c1, flag); 
	close(c0); 
1991/0614    
	poperror(); 
1990/0227    
	close(c1); 
1991/0614    
	poperror(); 
	close(c0); 
1990/0227    
	if(ismount){ 
		close(bogus.chan); 
		fdclose(arg[0]); 
1991/0501/sys/src/9/port/sysfile.c:465,4701991/0614/sys/src/9/port/sysfile.c:469,475
1990/0227    
	 * so fake it up.  rootclose() is known to be a nop. 
	 */ 
	c->type = 0; 
1991/0614    
	poperror(); 
1990/0227    
	close(c); 
	return 0; 
} 
1991/0614/sys/src/9/port/sysfile.c:364,3711991/0615/sys/src/9/port/sysfile.c:364,369 (short | long)
Semantics change: require names to be at most NAMELEN in length, instead of unlimited.
rsc Fri Mar 4 17:11:45 2005
1990/0227    
	Chan *c0, *c1; 
	ulong flag; 
	long ret; 
1990/0918    
	char *p; 
	int t; 
1990/0227    
	struct{ 
		Chan	*chan; 
		char	*spec; 
1991/0614/sys/src/9/port/sysfile.c:378,3971991/0615/sys/src/9/port/sysfile.c:376,387
1990/0227    
	if(ismount){ 
		bogus.chan = fdtochan(arg[0], 2); 
1990/11211    
		validaddr(arg[3], 1, 0); 
1990/0918    
		p = (char*)arg[3]; 
		t = BY2PG-((ulong)p&(BY2PG-1)); 
		while(vmemchr(p, 0, t) == 0){ 
			p += t; 
			t = BY2PG; 
		} 
1991/0615    
		if(vmemchr((char*)arg[3], '\0', NAMELEN) == 0) 
			error(Ebadarg); 
1990/0227    
		bogus.spec = (char*)arg[3]; 
1990/11211    
		validaddr(arg[4], 1, 0); 
		p = (char*)arg[4]; 
		t = BY2PG-((ulong)p&(BY2PG-1)); 
		while(vmemchr(p, 0, t) == 0){ 
			p += t; 
			t = BY2PG; 
		} 
1991/0615    
		if(vmemchr((char*)arg[4], '\0', NAMELEN) == 0) 
			error(Ebadarg); 
1990/11211    
		bogus.auth = (char*)arg[4]; 
1990/0227    
		ret = devno('M', 0); 
		c0 = (*devtab[ret].attach)((char*)&bogus); 
1991/0615/sys/src/9/port/sysfile.c:11,261991/0705/sys/src/9/port/sysfile.c:11,31 (short | long)
1990/0227    
 */ 
 
int 
newfd(void) 
1991/0705    
newfd(Chan *c) 
1990/0227    
{ 
1991/0705    
	Fgrp *f = u->p->fgrp; 
1990/0227    
	int i; 
 
1991/0705    
	lock(f); 
1990/0227    
	for(i=0; i<NFD; i++) 
		if(u->fd[i] == 0){ 
			if(i > u->maxfd) 
				u->maxfd = i; 
1991/0705    
		if(f->fd[i] == 0){ 
			if(i > f->maxfd) 
				f->maxfd = i; 
			f->fd[i] = c; 
			unlock(f); 
1990/0227    
			return i; 
		} 
1991/0705    
	unlock(f); 
1990/11211    
	error(Enofd); 
1990/0227    
} 
 
1991/0615/sys/src/9/port/sysfile.c:29,361991/0705/sys/src/9/port/sysfile.c:34,41
1990/0227    
{ 
	Chan *c; 
 
1990/1210    
	c = 0;		/* set */ 
1990/0227    
	if(fd<0 || NFD<=fd || (c=u->fd[fd])==0) 
1991/0705    
	USED(c); 
	if(fd<0 || NFD<=fd || (c = u->p->fgrp->fd[fd])==0) 
1990/11211    
		error(Ebadfd); 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1990/0227    
		return c; 
1991/0615/sys/src/9/port/sysfile.c:62,671991/0705/sys/src/9/port/sysfile.c:67,73
1990/1009    
	int fd[2]; 
	Chan *c[2]; 
	Dev *d; 
1991/0705    
	Fgrp *f = u->p->fgrp; 
1990/1009    
 
	validaddr(arg[0], 2*BY2WD, 1); 
	evenaddr(arg[0]); 
1991/0615/sys/src/9/port/sysfile.c:75,831991/0705/sys/src/9/port/sysfile.c:81,89
1990/1009    
		if(c[1]) 
			close(c[1]); 
		if(fd[0] >= 0) 
			u->fd[fd[0]]=0; 
1991/0705    
			f->fd[fd[0]]=0; 
1990/1009    
		if(fd[1] >= 0) 
			u->fd[fd[1]]=0; 
1991/0705    
			f->fd[fd[1]]=0; 
1990/1009    
		nexterror(); 
	} 
	c[1] = (*d->clone)(c[0], 0); 
1991/0615/sys/src/9/port/sysfile.c:85,941991/0705/sys/src/9/port/sysfile.c:91,98
1990/1009    
	(*d->walk)(c[1], "data1"); 
	c[0] = (*d->open)(c[0], ORDWR); 
	c[1] = (*d->open)(c[1], ORDWR); 
	fd[0] = newfd(); 
	u->fd[fd[0]] = c[0]; 
	fd[1] = newfd(); 
	u->fd[fd[1]] = c[1]; 
1991/0705    
	fd[0] = newfd(c[0]); 
	fd[1] = newfd(c[1]); 
1990/1009    
	((long*)arg[0])[0] = fd[0]; 
	((long*)arg[0])[1] = fd[1]; 
	poperror(); 
1991/0615/sys/src/9/port/sysfile.c:100,1051991/0705/sys/src/9/port/sysfile.c:104,110
1990/0227    
{ 
	int fd; 
	Chan *c, *oc; 
1991/0705    
	Fgrp *f = u->p->fgrp; 
1990/0227    
 
	/* 
	 * Close after dup'ing, so date > #d/1 works 
1991/0615/sys/src/9/port/sysfile.c:109,1251991/0705/sys/src/9/port/sysfile.c:114,139
1991/0221    
	if(fd != -1){ 
		if(fd<0 || NFD<=fd) 
			error(Ebadfd); 
		if(fd > u->maxfd) 
			u->maxfd = fd; 
1990/0227    
		oc = u->fd[fd]; 
1991/0221    
	}else{ 
1990/0227    
		oc = 0; 
		fd = newfd(); 
1991/0705    
 
		lock(f); 
		if(fd > f->maxfd) 
			f->maxfd = fd; 
		incref(c); 
		oc = f->fd[fd]; 
		f->fd[fd] = c; 
		unlock(f); 
		if(oc) 
			close(oc); 
	}else { 
		if(waserror()) { 
			close(c); 
			nexterror(); 
		} 
		incref(c); 
		fd = newfd(c); 
		poperror(); 
1990/0227    
	} 
	u->fd[fd] = c; 
	incref(c); 
	if(oc) 
		close(oc); 
1991/0705    
 
1990/0227    
	return fd; 
} 
 
1991/0615/sys/src/9/port/sysfile.c:127,1511991/0705/sys/src/9/port/sysfile.c:141,183
1990/0227    
sysopen(ulong *arg) 
{ 
	int fd; 
	Chan *c; 
1991/0705    
	Chan *c = 0; 
1990/0227    
 
	openmode(arg[1]);	/* error check only */ 
	fd = newfd(); 
1991/0705    
	if(waserror()) { 
		if(c) 
			close(c); 
		nexterror(); 
	} 
1990/0227    
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Aopen, arg[1], 0); 
	u->fd[fd] = c; 
1991/0705    
	fd = newfd(c); 
	poperror(); 
1990/0227    
	return fd; 
} 
 
void 
fdclose(int fd) 
1991/0705    
fdclose(int fd, int flag) 
1990/0227    
{ 
	int i; 
1991/0705    
	Chan *c; 
	Fgrp *f = u->p->fgrp; 
1990/0227    
 
	u->fd[fd] = 0; 
	if(fd == u->maxfd) 
		for(i=fd; --i>=0 && u->fd[i]==0; ) 
			u->maxfd = i; 
1991/0705    
	lock(f); 
	c = f->fd[fd]; 
	if(flag){ 
		if(c==0 || !(c->flag&flag)){ 
			unlock(f); 
			return; 
		} 
	} 
	f->fd[fd] = 0; 
	if(fd == f->maxfd) 
		for(i=fd; --i>=0 && f->fd[i]==0; ) 
			f->maxfd = i; 
 
	unlock(f); 
	close(c); 
1990/0227    
} 
 
long 
1991/0615/sys/src/9/port/sysfile.c:154,1611991/0705/sys/src/9/port/sysfile.c:186,193
1990/0227    
	Chan *c; 
 
	c = fdtochan(arg[0], -1); 
	close(c); 
	fdclose(arg[0]); 
1991/0705    
	fdclose(arg[0], 0); 
 
1990/0227    
	return 0; 
} 
 
1991/0615/sys/src/9/port/sysfile.c:183,1901991/0705/sys/src/9/port/sysfile.c:215,222
1990/0227    
		nexterror(); 
	} 
	nc = clone(mc, 0); 
	close(mc); 
	poperror(); 
1991/0705    
	close(mc); 
1990/0227    
	if(waserror()){ 
		close(nc); 
		nexterror(); 
1991/0615/sys/src/9/port/sysfile.c:193,2001991/0705/sys/src/9/port/sysfile.c:225,232
1990/0227    
	nc->offset = c->offset; 
1991/0411    
	nr = (*devtab[nc->type].read)(nc, va, n, nc->offset); 
1990/0821    
	c->offset = nc->offset;		/* devdirread e.g. changes it */ 
1990/0227    
	close(nc); 
	poperror(); 
1991/0705    
	close(nc); 
1990/0227    
	if(nr > 0) 
		return nr; 
	/* 
1991/0615/sys/src/9/port/sysfile.c:364,3691991/0705/sys/src/9/port/sysfile.c:396,403
1990/0227    
	Chan *c0, *c1; 
	ulong flag; 
	long ret; 
1991/0705    
	char *p; 
	int t; 
1990/0227    
	struct{ 
		Chan	*chan; 
		char	*spec; 
1991/0615/sys/src/9/port/sysfile.c:408,4171991/0705/sys/src/9/port/sysfile.c:442,450
1990/0227    
	close(c1); 
1991/0614    
	poperror(); 
	close(c0); 
1990/0227    
	if(ismount){ 
		close(bogus.chan); 
		fdclose(arg[0]); 
	} 
1991/0705    
	if(ismount) 
		fdclose(arg[0], 0); 
 
1990/0227    
	return ret; 
} 
 
1991/0615/sys/src/9/port/sysfile.c:431,4431991/0705/sys/src/9/port/sysfile.c:464,481
1990/0227    
syscreate(ulong *arg) 
{ 
	int fd; 
	Chan *c; 
1991/0705    
	Chan *c = 0; 
1990/0227    
 
	openmode(arg[1]);	/* error check only */ 
	fd = newfd(); 
1991/0705    
	if(waserror()) { 
		if(c) 
			close(c); 
		nexterror(); 
	} 
1990/0227    
	validaddr(arg[0], 1, 0); 
	c = namec((char*)arg[0], Acreate, arg[1], arg[2]); 
	u->fd[fd] = c; 
1991/0705    
	fd = newfd(c); 
	poperror(); 
1990/0227    
	return fd; 
} 
 
1991/0705/sys/src/9/port/sysfile.c:124,1301991/0706/sys/src/9/port/sysfile.c:124,130 (short | long)
1991/0705    
		unlock(f); 
		if(oc) 
			close(oc); 
	}else { 
1991/0706    
	}else{ 
1991/0705    
		if(waserror()) { 
			close(c); 
			nexterror(); 
1991/0705/sys/src/9/port/sysfile.c:144,1501991/0706/sys/src/9/port/sysfile.c:144,150
1991/0705    
	Chan *c = 0; 
1990/0227    
 
	openmode(arg[1]);	/* error check only */ 
1991/0705    
	if(waserror()) { 
1991/0706    
	if(waserror()){ 
1991/0705    
		if(c) 
			close(c); 
		nexterror(); 
1991/0706/sys/src/9/port/sysfile.c:34,401991/0904/sys/src/9/port/sysfile.c:34,40 (short | long)
1990/0227    
{ 
	Chan *c; 
 
1991/0705    
	USED(c); 
1991/0904    
	c = 0; 
1991/0705    
	if(fd<0 || NFD<=fd || (c = u->p->fgrp->fd[fd])==0) 
1990/11211    
		error(Ebadfd); 
1990/1009    
	if(mode<0 || c->mode==ORDWR) 
1991/0706/sys/src/9/port/sysfile.c:183,1911991/0904/sys/src/9/port/sysfile.c:183,189
1990/0227    
long 
sysclose(ulong *arg) 
{ 
	Chan *c; 
                 
	c = fdtochan(arg[0], -1); 
1991/0904    
	fdtochan(arg[0], -1); 
1991/0705    
	fdclose(arg[0], 0); 
 
1990/0227    
	return 0; 
Too many diffs (26 > 25). Stopping.


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)