git: 9front

Download patch

ref: d7964e45f7d96ac57b4e6c95c06171ff698eca08
parent: af1be3bf52f4b6af40daab896dab9fa49e539f58
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sun Jan 6 21:13:54 EST 2013

hjfs: network announce/listen support

--- a/sys/man/4/hjfs
+++ b/sys/man/4/hjfs
@@ -15,6 +15,9 @@
 .B -n
 .I name
 ] [
+.B -a
+.I announce-string
+] ... [
 -r
 ] [
 .B -S
@@ -45,6 +48,9 @@
 Use
 .I name
 as the name of the service.
+.TP
+.BI "-a " announce-string
+will announce and listen on the specified network address.
 .TP
 .B -r
 Ream the file system, erasing all of the old data.
--- a/sys/src/cmd/hjfs/9p.c
+++ b/sys/src/cmd/hjfs/9p.c
@@ -135,8 +135,10 @@
 };
 
 void
-start9p(char *service, int stdio)
+start9p(char *service, char **nets, int stdio)
 {
+	while(nets && *nets)
+		threadlistensrv(&mysrv, *nets++);
 	if(stdio){
 		mysrv.infd = 1;
 		mysrv.outfd = 1;
--- a/sys/src/cmd/hjfs/fns.h
+++ b/sys/src/cmd/hjfs/fns.h
@@ -25,7 +25,7 @@
 int	permcheck(Fs *, Dentry *, short, int);
 char *	uid2name(Fs *, short, char *);
 int	name2uid(Fs *, char *, short *);
-void	start9p(char *, int);
+void	start9p(char *, char **, int);
 int	chanclunk(Chan *);
 int	chanremove(Chan *);
 int	getblk(Fs *, FLoc *, Buf *, uvlong, uvlong *, int);
--- a/sys/src/cmd/hjfs/main.c
+++ b/sys/src/cmd/hjfs/main.c
@@ -86,7 +86,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-rsS] [-m mem] [-n service] -f dev\n", argv0);
+	fprint(2, "usage: %s [-rsS] [-m mem] [-n service] [-a announce-string]... -f dev\n", argv0);
 	exits("usage");
 }
 
@@ -94,9 +94,11 @@
 threadmain(int argc, char **argv)
 {
 	Dev *d;
+	static char *nets[8];
 	char *file, *service;
-	int doream, flags, stdio, nbuf;
+	int doream, flags, stdio, nbuf, netc;
 
+	netc = 0;
 	doream = 0;
 	stdio = 0;
 	flags = FSNOAUTH;
@@ -115,6 +117,13 @@
 		if(nbuf < 10)
 			nbuf = 10;
 		break;
+	case 'a':
+		if(netc >= nelem(nets)-1){
+			fprint(2, "%s: too many networks to announce\n", argv0);
+			exits("too many nets");
+		}
+		nets[netc++] = estrdup(EARGF(usage()));
+		break;
 	default: usage();
 	} ARGEND;
 	rfork(RFNOTEG);
@@ -131,7 +140,7 @@
 		sysfatal("fsinit: %r");
 	initcons(service);
 	proccreate(syncproc, nil, mainstacksize);
-	start9p(service, stdio);
+	start9p(service, nets, stdio);
 	threadexits(nil);
 }
 
--