示例#1
0
文件: devlfd.c 项目: 99years/plan9
Chan*
lfdchan(int fd)
{
	Chan *c;
	
	c = newchan();
	c->type = devno('L', 0);
	c->aux = (void*)(uintptr)fd;
	c->name = newcname("fd");
	c->mode = ORDWR;
	c->qid.type = 0;
	c->qid.path = 0;
	c->qid.vers = 0;
	c->dev = 0;
	c->offset = 0;
	return c;
}
示例#2
0
文件: dev.c 项目: 99years/plan9
Chan*
devattach(int tc, char *spec)
{
	Chan *c;
	char *buf;

	c = newchan();
	mkqid(&c->qid, 0, 0, QTDIR);
	c->type = devno(tc, 0);
	if(spec == nil)
		spec = "";
	buf = smalloc(4+strlen(spec)+1);
	sprint(buf, "#%C%s", tc, spec);
	c->name = newcname(buf);
	free(buf);
	return c;
}
示例#3
0
int syspipe(int fd[2])
{
	ERRSTACK(1);
	struct dev *d;
	struct chan *c[2];
	static char *names[] = { "data", "data1" };

	d = &devtab[devno("pipe", 0)];
	c[0] = 0;
	c[1] = 0;
	fd[0] = -1;
	fd[1] = -1;
	if (waserror()) {
		/* need to remove from the fd table and make sure the chan is closed
		 * exactly once.  if fd[i] >= 0, then the fd is valid (or it was!) and
		 * the fd table has the only ref (newfd() currently decrefs/consumes the
		 * reference).  cclose() doesn't care if you pass it 0 (like kfree()). */
		if (fd[0] >= 0)
			close_fd(&current->open_files, fd[0]);
		else
			cclose(c[0]);
		if (fd[1] >= 0)
			close_fd(&current->open_files, fd[1]);
		else
			cclose(c[1]);
		poperror();
		return -1;
	}
	c[0] = namec("#pipe", Atodir, 0, 0);
	c[1] = cclone(c[0]);
	if (walk(&c[0], &names[0], 1, FALSE, NULL) < 0)
		error(EINVAL, ERROR_FIXME);
	if (walk(&c[1], &names[1], 1, FALSE, NULL) < 0)
		error(EINVAL, ERROR_FIXME);
	c[0] = d->open(c[0], O_RDWR);
	c[1] = d->open(c[1], O_RDWR);
	fd[0] = newfd(c[0], 0);
	if (fd[0] < 0)
		error(-fd[0], ERROR_FIXME);
	fd[1] = newfd(c[1], 0);
	if (fd[1] < 0)
		error(-fd[1], ERROR_FIXME);
	poperror();
	return 0;
}
示例#4
0
文件: dev.c 项目: anandab/akaros
struct chan *devattach(const char *name, char *spec)
{
	struct chan *c;
	char *buf;
	size_t buflen;

	c = newchan();
	mkqid(&c->qid, 0, 0, QTDIR);
	c->type = devno(name, 0);
	if (spec == NULL)
		spec = "";
	/* 1 for #, 1 for ., 1 for \0 */
	buflen = strlen(name) + strlen(spec) + 3;
	buf = kzmalloc(buflen, KMALLOC_WAIT);
	snprintf(buf, sizeof(buf), "#%s.%s", name, spec);
	c->name = newcname(buf);
	kfree(buf);
	return c;
}
示例#5
0
文件: sysfile.c 项目: 0intro/vx32
long
syspipe(uint32 *arg)
{
	int fd[2];
	Chan *c[2];
	Dev *d;
	static char *datastr[] = {"data", "data1"};
	int *ufd;
	
	ufd = uvalidaddr(arg[0], 2*BY2WD, 1);
	evenaddr(arg[0]);
	d = devtab[devno('|', 0)];
	c[0] = namec("#|", Atodir, 0, 0);
	c[1] = 0;
	fd[0] = -1;
	fd[1] = -1;

	if(waserror()){
		cclose(c[0]);
		if(c[1])
			cclose(c[1]);
		nexterror();
	}
	c[1] = cclone(c[0]);
	if(walk(&c[0], datastr+0, 1, 1, nil) < 0)
		error(Egreg);
	if(walk(&c[1], datastr+1, 1, 1, nil) < 0)
		error(Egreg);
	c[0] = d->open(c[0], ORDWR);
	c[1] = d->open(c[1], ORDWR);
	if(newfd2(fd, c) < 0)
		error(Enofd);
	poperror();

	ufd[0] = fd[0];
	ufd[1] = fd[1];
	return 0;
}
示例#6
0
long
syspipe(ulong *arg)
{
	int fd[2];
	Chan *c[2];
	Dev *d;
	static char *datastr[] = {"data", "data1"};

	validaddr(arg[0], sizeof(fd), 1);
	validalign(arg[0], sizeof(int));
	d = devtab[devno('|', 0)];
	c[0] = namec("#|", Atodir, 0, 0);
	c[1] = 0;
	fd[0] = -1;
	fd[1] = -1;

	if(waserror()){
		cclose(c[0]);
		if(c[1])
			cclose(c[1]);
		nexterror();
	}
	c[1] = cclone(c[0]);
	if(walk(&c[0], datastr+0, 1, 1, nil) < 0)
		error(Egreg);
	if(walk(&c[1], datastr+1, 1, 1, nil) < 0)
		error(Egreg);
	c[0] = d->open(c[0], ORDWR);
	c[1] = d->open(c[1], ORDWR);
	if(newfd2(fd, c) < 0)
		error(Enofd);
	poperror();

	((int*)arg[0])[0] = fd[0];
	((int*)arg[0])[1] = fd[1];
	return 0;
}
示例#7
0
文件: dev.c 项目: HarryR/sanos
dev_t dev_open(char *name) {
  dev_t d = devno(name);
  if (d != NODEV) devtab[d]->refcnt++;
  return d;
}
示例#8
0
文件: sysfile.c 项目: Akheon23/nix-os
long
bindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char* spec)
{
	int ret;
	Chan *c0, *c1, *ac, *bc;
	struct{
		Chan	*chan;
		Chan	*authchan;
		char	*spec;
		int	flags;
	}bogus;

	if((flag&~MMASK) || (flag&MORDER)==(MBEFORE|MAFTER))
		error(Ebadarg);

	if(ismount){
		validaddr((ulong)spec, 1, 0);
		spec = validnamedup(spec, 1);
		if(waserror()){
			free(spec);
			nexterror();
		}

		if(up->pgrp->noattach)
			error(Enoattach);

		ac = nil;
		bc = fdtochan(fd, ORDWR, 0, 1);
		if(waserror()) {
			if(ac)
				cclose(ac);
			cclose(bc);
			nexterror();
		}

		if(afd >= 0)
			ac = fdtochan(afd, ORDWR, 0, 1);

		bogus.flags = flag & MCACHE;
		bogus.chan = bc;
		bogus.authchan = ac;
		bogus.spec = spec;
		ret = devno('M', 0);
		c0 = devtab[ret]->attach((char*)&bogus);
		poperror();	/* ac bc */
		if(ac)
			cclose(ac);
		cclose(bc);
	}else{
		spec = 0;
		validaddr((ulong)arg0, 1, 0);
		c0 = namec(arg0, Abind, 0, 0);
	}

	if(waserror()){
		cclose(c0);
		nexterror();
	}

	validaddr((ulong)arg1, 1, 0);
	c1 = namec(arg1, Amount, 0, 0);
	if(waserror()){
		cclose(c1);
		nexterror();
	}

	ret = cmount(&c0, c1, flag, spec);

	poperror();
	cclose(c1);
	poperror();
	cclose(c0);
	if(ismount){
		fdclose(fd, 0);
		poperror();
		free(spec);
	}
	return ret;
}