git: 9front

Download patch

ref: ddcf0dcbfddc1a22028306eaa9f070702f4a6f44
parent: 7d7eee91f16e01b0a73dc78ddd5a0a621adf2e51
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Aug 17 19:27:31 EDT 2011

change definition of Chan.create to return a chan like open

--- a/sys/src/9/bitsy/devpenmouse.c
+++ b/sys/src/9/bitsy/devpenmouse.c
@@ -214,12 +214,13 @@
 	return c;
 }
 
-static void
+static Chan*
 penmousecreate(Chan*, char*, int, ulong)
 {
 	if(!conf.monitor)
 		error(Egreg);
 	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/boot/boot.c
+++ b/sys/src/9/boot/boot.c
@@ -33,6 +33,7 @@
 			print("%lux %s ", (ulong)argv[i], argv[i]);
 		print("\n");
 	}
+	USED(argc);
 
 	readfile("#e/cputype", cputype, sizeof(cputype));
 	setenv("bootdisk", bootdisk, 0);
--- a/sys/src/9/ip/devip.c
+++ b/sys/src/9/ip/devip.c
@@ -506,10 +506,11 @@
 	return c;
 }
 
-static void
+static Chan*
 ipcreate(Chan*, char*, int, ulong)
 {
 	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/kw/devether.c
+++ b/sys/src/9/kw/devether.c
@@ -61,9 +61,11 @@
 	return netifopen(etherxx[chan->dev], chan, omode);
 }
 
-static void
+static Chan*
 ethercreate(Chan*, char*, int, ulong)
 {
+	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/kw/mkfile
+++ b/sys/src/9/kw/mkfile
@@ -68,6 +68,8 @@
 	/$objtype/lib/libip.a\
 	/$objtype/lib/libsec.a\
 	/$objtype/lib/libc.a\
+	/$objtype/lib/libmp.a\
+	/$objtype/lib/libfis.a\
 
 9:V: $p$CONF s$p$CONF
 
--- a/sys/src/9/kw/plug
+++ b/sys/src/9/kw/plug
@@ -8,6 +8,7 @@
 	proc
 	mnt
 	srv
+	shr
 	dup
 	rtc
 	arch
--- a/sys/src/9/mtx/devether.c
+++ b/sys/src/9/mtx/devether.c
@@ -53,9 +53,11 @@
 	return netifopen(etherxx[chan->dev], chan, omode);
 }
 
-static void
+static Chan*
 ethercreate(Chan*, char*, int, ulong)
 {
+	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/omap/beagle
+++ b/sys/src/9/omap/beagle
@@ -7,6 +7,7 @@
 	proc
 	mnt
 	srv
+	shr
 	dup
 	arch
 	ssl
--- a/sys/src/9/omap/devether.c
+++ b/sys/src/9/omap/devether.c
@@ -61,9 +61,11 @@
 	return netifopen(etherxx[chan->dev], chan, omode);
 }
 
-static void
+static Chan*
 ethercreate(Chan*, char*, int, ulong)
 {
+	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/pc/devether.c
+++ b/sys/src/9/pc/devether.c
@@ -59,9 +59,11 @@
 	return netifopen(etherxx[chan->dev], chan, omode);
 }
 
-static void
+static Chan*
 ethercreate(Chan*, char*, int, ulong)
 {
+	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -1592,7 +1592,7 @@
 			cnew->path = c->path;
 			incref(cnew->path);
 
-			devtab[cnew->type]->create(cnew, e.elems[e.nelems-1], omode&~(OEXCL|OCEXEC), perm);
+			cnew = devtab[cnew->type]->create(cnew, e.elems[e.nelems-1], omode&~(OEXCL|OCEXEC), perm);
 			poperror();
 			if(omode & OCEXEC)
 				cnew->flag |= CCEXEC;
--- a/sys/src/9/port/dev.c
+++ b/sys/src/9/port/dev.c
@@ -383,10 +383,11 @@
 	return c;
 }
 
-void
+Chan*
 devcreate(Chan*, char*, int, ulong)
 {
 	error(Eperm);
+	return 0;
 }
 
 Block*
--- a/sys/src/9/port/devenv.c
+++ b/sys/src/9/port/devenv.c
@@ -137,7 +137,7 @@
 	return c;
 }
 
-static void
+static Chan*
 envcreate(Chan *c, char *name, int omode, ulong)
 {
 	Egrp *eg;
@@ -183,6 +183,7 @@
 	c->offset = 0;
 	c->mode = omode;
 	c->flag |= COPEN;
+	return c;
 }
 
 static void
--- a/sys/src/9/port/devmnt.c
+++ b/sys/src/9/port/devmnt.c
@@ -534,10 +534,10 @@
 	return mntopencreate(Topen, c, nil, omode, 0);
 }
 
-static void
+static Chan*
 mntcreate(Chan *c, char *name, int omode, ulong perm)
 {
-	mntopencreate(Tcreate, c, name, omode, perm);
+	return mntopencreate(Tcreate, c, name, omode, perm);
 }
 
 static void
--- a/sys/src/9/port/devmouse.c
+++ b/sys/src/9/port/devmouse.c
@@ -208,12 +208,13 @@
 	return c;
 }
 
-static void
+static Chan*
 mousecreate(Chan*, char*, int, ulong)
 {
 	if(!conf.monitor)
 		error(Egreg);
 	error(Eperm);
+	return 0;
 }
 
 static void
--- a/sys/src/9/port/devshr.c
+++ b/sys/src/9/port/devshr.c
@@ -418,7 +418,10 @@
 	return c;
 }
 
-static void
+/* chan.c */
+Chan* createdir(Chan *c, Mhead *m);
+
+static Chan*
 shrcreate(Chan *c, char *name, int omode, ulong perm)
 {
 	Sch *sch;
@@ -426,11 +429,10 @@
 	Mpt *mpt;
 	Mhead *h;
 	Mount *m;
+	Chan *nc;
 
 	sch = tosch(c);
 	switch(sch->level){
-	default:
-		error(Enocreate);
 	case Qcroot:
 	case Qcshr:
 		if(strcmp(up->user, "none") == 0)
@@ -437,6 +439,24 @@
 			error(Eperm);
 	}
 	switch(sch->level){
+	default:
+		error(Eperm);
+	case Qshr:
+		incref(c);
+		if(waserror()){
+			cclose(c);
+			nexterror();
+		}
+		nc = createdir(c, &sch->shr->umh);
+		poperror();
+		if(waserror()){
+			cclose(nc);
+			nexterror();
+		}
+		nc = devtab[nc->type]->create(nc, name, omode, perm);
+		poperror();
+		cclose(c);
+		return nc;	
 	case Qcroot:
 		if((perm & DMDIR) == 0 || openmode(omode) != OREAD)
 			error(Eperm);
@@ -498,6 +518,7 @@
 		mpt->perm = perm;
 
 		incref(mpt);
+		mpt->m.mflag = (h->mount == nil) ? MCREATE : 0;
 		mpt->m.head = h;
 		mpt->m.next = h->mount;
 		h->mount = &mpt->m;
@@ -511,6 +532,7 @@
 	}
 	c->flag |= COPEN;
 	c->mode = openmode(omode);
+	return c;
 }
 
 static void
--- a/sys/src/9/port/devsrv.c
+++ b/sys/src/9/port/devsrv.c
@@ -136,7 +136,7 @@
 	return sp->chan;
 }
 
-static void
+static Chan*
 srvcreate(Chan *c, char *name, int omode, ulong perm)
 {
 	char *sname;
@@ -175,6 +175,7 @@
 
 	c->flag |= COPEN;
 	c->mode = OWRITE;
+	return c;
 }
 
 static void
--- a/sys/src/9/port/portdat.h
+++ b/sys/src/9/port/portdat.h
@@ -209,7 +209,7 @@
 	Walkqid*(*walk)(Chan*, Chan*, char**, int);
 	int	(*stat)(Chan*, uchar*, int);
 	Chan*	(*open)(Chan*, int);
-	void	(*create)(Chan*, char*, int, ulong);
+	Chan*	(*create)(Chan*, char*, int, ulong);
 	void	(*close)(Chan*);
 	long	(*read)(Chan*, void*, long, vlong);
 	Block*	(*bread)(Chan*, long, ulong);
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -61,7 +61,7 @@
 long		devbwrite(Chan*, Block*, ulong);
 Chan*		devclone(Chan*);
 int		devconfig(int, char *, DevConf *);
-void		devcreate(Chan*, char*, int, ulong);
+Chan*		devcreate(Chan*, char*, int, ulong);
 void		devdir(Chan*, Qid, char*, vlong, char*, long, Dir*);
 long		devdirread(Chan*, char*, long, Dirtab*, int, Devgen*);
 Devgen		devgen;
--- a/sys/src/9/ppc/devether.c
+++ b/sys/src/9/ppc/devether.c
@@ -54,9 +54,11 @@
 	return netifopen(etherxx[chan->dev], chan, omode);
 }
 
-static void
+static Chan*
 ethercreate(Chan*, char*, int, ulong)
 {
+	error(Eperm);
+	return 0;
 }
 
 static void
--