Ejemplo n.º 1
0
Archivo: devfs.c Proyecto: 8l/inferno
void
fscreate(Chan *c, char *name, int mode, ulong perm)
{
	Dir *d;
	Cname *n;

	if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		error(Efilename);
	n = addelem(newcname(FS(c)->name->s), name);
	osenter();
	FS(c)->fd = create(n->s, mode, perm);
	osleave();
	if(FS(c)->fd < 0) {
		cnameclose(n);
		fserr(FS(c));
	}
	d = dirfstat(FS(c)->fd);
	if(d == nil) {
		cnameclose(n);
		close(FS(c)->fd);
		FS(c)->fd = -1;
		fserr(FS(c));
	}
	c->qid = d->qid;
	free(d);

	cnameclose(FS(c)->name);
	FS(c)->name = n;

	c->mode = openmode(mode);
	c->offset = 0;
	FS(c)->offset = 0;
	c->flag |= COPEN;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: 8l/inferno
void
init0(void)
{
	Osenv *o;

	up->nerrlab = 0;

	print("before spllo");

	spllo();

	print("Sun Sparc %s\n", sparam->name);
	print("bank 0: %ldM  1: %ldM\n", bank[0], bank[1]);
	print("frame buffer id %lux slot %ld %s\n",conf.monitor,fbslot,fbstr);


	if(waserror())
		panic("init0");

	/*
	 * These are o.k. because rootinit is null.
	 * Then early kproc's will have a root and dot.
	 */
	o = up->env;
	o->pgrp->slash = namec("#/", Atodir, 0, 0);
	cnameclose(o->pgrp->slash->name);
	o->pgrp->slash->name = newcname("/");
	o->pgrp->dot = cclone(o->pgrp->slash);

	chandevinit();
	poperror();
	disinit("/osinit.dis");
}
Ejemplo n.º 3
0
struct cname *addelem(struct cname *n, char *s)
{
	int i, a;
	char *t;
	struct cname *new;

	if (s[0] == '.' && s[1] == '\0')
		return n;

	if (kref_refcnt(&n->ref) > 1) {
		/* copy on write */
		new = newcname(n->s);
		cnameclose(n);
		n = new;
	}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
struct chan *devattach(int tc, char *spec)
{
    struct chan *c;
    char *buf;

    c = newchan();
    mkqid(&c->qid, 0, 0, QTDIR);
    c->type = devno(tc, 0);
    if (spec == NULL)
        spec = "";
    /* 2 for #c, 1 for \0 */
    buf = kzmalloc(2 + strlen(spec) + 1, KMALLOC_WAIT);
    snprintf(buf, sizeof(buf), "#%c%s", tc, spec);
    c->name = newcname(buf);
    kfree(buf);
    return c;
}
Ejemplo n.º 7
0
Archivo: dev.c Proyecto: 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;
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: 8l/inferno
void
init0(void)
{
	Osenv *o;
	int i;
	char buf[2*KNAMELEN];

	up->nerrlab = 0;

	spllo();

	if(waserror())
		panic("init0");
	/*
	 * These are o.k. because rootinit is null.
	 * Then early kproc's will have a root and dot.
	 */
	o = up->env;
	o->pgrp->slash = namec("#/", Atodir, 0, 0);
	cnameclose(o->pgrp->slash->name);
	o->pgrp->slash->name = newcname("/");
	o->pgrp->dot = cclone(o->pgrp->slash);

	chandevinit();

	if(!waserror()){
		ksetenv("cputype", "power", 0);
		snprint(buf, sizeof(buf), "power %s", conffile);
		ksetenv("terminal", buf, 0);
		poperror();
	}
	for(i = 0; i < nconf; i++)
		if(confname[i][0] != '*'){
			if(!waserror()){
				ksetenv(confname[i], confval[i], 0);
				poperror();
			}
		}

	poperror();
	disinit("/osinit.dis");
}
Ejemplo n.º 9
0
void
init0(void)
{
	Osenv *o;
	char buf[2*KNAMELEN];

	up->nerrlab = 0;

	//print("Starting init0()\n");
	spllo();

	if(waserror())
		panic("init0 %r");

	/* These are o.k. because rootinit is null.
	 * Then early kproc's will have a root and dot. */

	o = up->env;
	o->pgrp->slash = namec("#/", Atodir, 0, 0);
	cnameclose(o->pgrp->slash->name);
	o->pgrp->slash->name = newcname("/");
	o->pgrp->dot = cclone(o->pgrp->slash);

	chandevinit();

	if(!waserror()){
		ksetenv("cputype", "arm", 0);
		snprint(buf, sizeof(buf), "arm %s", conffile);
		ksetenv("terminal", buf, 0);
		snprint(buf, sizeof(buf), "%s", getethermac());
		ksetenv("ethermac", buf, 0);
		poperror();
	}

	poperror();

	disinit("/osinit.dis");
}
Ejemplo n.º 10
0
Archivo: devfs.c Proyecto: 8l/inferno
Chan*
fsattach(char *spec)
{
	Chan *c;
	Dir *d;
	char *root;
	Qid rootqid;
	static int devno;
	static Lock l;

	if(!emptystr(spec)){
		if(strcmp(spec, "*") != 0)
			error(Ebadspec);
		root = "/";
	}else
		root = rootdir;

	d = dirstat(root);
	if(d == nil)
		fserr(nil);
	rootqid = d->qid;
	free(d);

	c = devattach('U', spec);
	lock(&l);
	c->dev = devno++;
	c->qid = rootqid;
	unlock(&l);
	c->aux = smalloc(sizeof(Fsinfo));
	FS(c)->name = newcname(root);
	FS(c)->rootqid = rootqid;
	FS(c)->fd = -1;
	FS(c)->root = root;

	return c;
}
Ejemplo n.º 11
0
void
emuinit(void *imod)
{
	Osenv *e;
	char *wdir;

	e = up->env;
	e->pgrp = newpgrp();
	e->fgrp = newfgrp(nil);
	e->egrp = newegrp();
	e->errstr = e->errbuf0;
	e->syserrstr = e->errbuf1;
	e->user = strdup("");

	links();
	chandevinit();

	if(waserror())
		panic("setting root and dot");

	e->pgrp->slash = namec("#/", Atodir, 0, 0);
	cnameclose(e->pgrp->slash->name);
	e->pgrp->slash->name = newcname("/");
	e->pgrp->dot = cclone(e->pgrp->slash);
	poperror();

	strcpy(up->text, "main");

	if(kopen("#c/cons", OREAD) != 0)
		fprint(2, "failed to make fd0 from #c/cons: %r\n");
	kopen("#c/cons", OWRITE);
	kopen("#c/cons", OWRITE);

	/* the setid cannot precede the bind of #U */
	kbind("#U", "/", MAFTER|MCREATE);
	setid(eve, 0);
	kbind("#^", "/dev", MBEFORE);	/* snarf */
	kbind("#^", "/chan", MBEFORE);
	kbind("#m", "/dev", MBEFORE);	/* pointer */
	kbind("#c", "/dev", MBEFORE);
	kbind("#p", "/prog", MREPL);
	kbind("#d", "/fd", MREPL);
	kbind("#I", "/net", MAFTER);	/* will fail on Plan 9 */

	/* BUG: we actually only need to do these on Plan 9 */
	kbind("#U/dev", "/dev", MAFTER);
	kbind("#U/net", "/net", MAFTER);
	kbind("#U/net.alt", "/net.alt", MAFTER);

	if(cputype != nil)
		ksetenv("cputype", cputype, 1);
	putenvqv("emuargs", rebootargv, rebootargc, 1);
	putenvq("emuroot", rootdir, 1);
	ksetenv("emuhost", hosttype, 1);
	wdir = malloc(1024);
	if(wdir != nil){
		if(getwd(wdir, 1024) != nil)
			putenvq("emuwdir", wdir, 1);
		free(wdir);
	}

	kproc("main", disinit, imod, KPDUPFDG|KPDUPPG|KPDUPENVG);

	for(;;)
		ospause(); 
}