History

Add -9 flag for 9p-mode (just exportfs on standard input/output)

With the -9 flag, we can run drawterm on a remote system over ssh, and have it export the remotes namespace. Thru the /cmd interface (see os(1)), one can launch native programs on the remote host and access the remote file system.

cinap_lenrek committed 2 years ago

Commit bcf1eb41 parent f9ae0c86 files · +54 −22Browse files

Unified · Split

6 files
  1. cpu.c +17 −7
  2. drawterm.1 +7 −1
  3. drawterm.h +1 −1
  4. exportfs/exportfs.c +8 −12
  5. exportfs/exportsrv.c +1 −1
  6. kern/devlfd-win32.c +20 −0
cpu.c+17−7
@@ -27,6 +27,7 @@ static int aanto = 3600 * 24; · 26 unmodified lines
2727 static int norcpu;
2828 static int nokbd;
2929 static int nogfx;
30+static int nineflag;
3031
3132 static char *ealgs = "rc4_256 sha1";
3233
@@ -176,7 +177,7 @@ rcpu(char *host, char *cmd) · 143 unmodified lines
176177 atexit(rcpuexit);
177178
178179 /* Begin serving the namespace */
179− exportfs(fd);
180+ exportfs(fd, fd);
180181 }
181182
182183 void
@@ -236,13 +237,13 @@ ncpu(char *host, char *cmd) · 53 unmodified lines
236237 write(fd, "OK", 2);
237238
238239 /* Begin serving the gnot namespace */
239− exportfs(fd);
240+ exportfs(fd, fd);
240241 }
241242
242243 void
243244 usage(void)
244245 {
245− fprint(2, "usage: %s [-GBO] "
246+ fprint(2, "usage: %s [-9GBO] "
246247 "[-h host] [-u user] [-a authserver] [-s secstore] "
247248 "[-e 'crypt hash'] [-k keypattern] "
248249 "[-p] [-t timeout] "
@@ -262,12 +263,13 @@ cpumain(int argc, char **argv) · 13 unmodified lines
262263 char *s;
263264
264265 user = getenv("USER");
265− if((pass = getenv("PASS")) != nil)
266− remove("/env/PASS");
267266 host = getenv("cpu");
268267 authserver = getenv("auth");
269268
270269 ARGBEGIN{
270+ case '9':
271+ nineflag = 1;
272+ /* wet floor */
271273 case 'G':
272274 nogfx = 1;
273275 /* wet floor */
@@ -320,8 +322,8 @@ cpumain(int argc, char **argv) · 46 unmodified lines
320322 break;
321323 case 'g':
322324 /* X11 geometry string
323− [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]
324− */
325+ * [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]
326+ */
325327 geometry = EARGF(usage());
326328 break;
327329 default:
@@ -331,6 +333,14 @@ cpumain(int argc, char **argv) · 3 unmodified lines
331333 if(argc != 0)
332334 usage();
333335
336+ if(nineflag){
337+ exportfs(lfdfd(0), lfdfd(1));
338+ return;
339+ }
340+
341+ if((pass = getenv("PASS")) != nil)
342+ remove("/env/PASS");
343+
334344 if(!nogfx)
335345 guimain();
336346 else
drawterm.1+7−1
@@ -6,7 +6,7 @@ drawterm \- connection to cpu, fs, and auth servers · 5 unmodified lines
66 .SH SYNOPSIS
77 .B drawterm
88 [
9−.B -GBO
9+.B -9GBO
1010 ] [
1111 .B -h
1212 .I host
@@ -50,6 +50,12 @@ The goal of drawterm is to provide an abstraction layer from the client operatin · 37 unmodified lines
5050 The options are:
5151 .PD
5252
53+.TP
54+.B -9
55+Start drawterm in 9P mode;
56+exporting the namespace over 9P on standard input and output.
57+Graphics and keyboard input are disabled.
58+
5359 .TP
5460 .B -G
5561 Start drawterm in text-only mode (no graphics).
drawterm.h+1−1
@@ -2,7 +2,7 @@ extern int havesecstore(char *addr, char *owner); · 1 unmodified line
22 extern char *secstore;
33 extern char *secstorefetch(char *addr, char *owner, char *passwd);
44 extern char *authserver;
5−extern int exportfs(int);
5+extern int exportfs(int, int);
66 extern int dialfactotum(void);
77 extern char *getuser(void);
88 extern void cpumain(int, char**);
exportfs/exportfs.c+8−12
@@ -9,7 +9,6 @@ · 8 unmodified lines
99 #define Extern
1010 #include "exportfs.h"
1111
12−/* #define QIDPATH ((1LL<<48)-1) */
1312 #define QIDPATH ((((vlong)1)<<48)-1)
1413 vlong newqid = 0;
1514
@@ -21,15 +20,16 @@ int freecnt; · 5 unmodified lines
2120 int qidcnt;
2221 int qfreecnt;
2322 int ncollision;
24−int netfd;
23+int netfd[2];
2524
2625 int
27−exportfs(int fd)
26+exportfs(int rfd, int wfd)
2827 {
2928 char buf[ERRMAX], ebuf[ERRMAX];
3029 Fsrpc *r;
3130 int i, n;
3231
32+
3333 fcalls[Tversion] = Xversion;
3434 fcalls[Tauth] = Xauth;
3535 fcalls[Tflush] = Xflush;
@@ -45,22 +45,18 @@ exportfs(int fd) · 9 unmodified lines
4545 fcalls[Twstat] = Xwstat;
4646
4747 srvfd = -1;
48− netfd = fd;
49− //dbg = 1;
48+ netfd[0] = rfd;
49+ netfd[1] = wfd;
5050
5151 strcpy(buf, "this is buf");
5252 strcpy(ebuf, "this is ebuf");
5353 DEBUG(DFD, "exportfs: started\n");
5454
55−// rfork(RFNOTEG);
56−
57− messagesize = iounit(netfd);
55+ messagesize = iounit(rfd);
5856 if(messagesize == 0)
5957 messagesize = IOUNIT+IOHDRSZ;
6058
6159 Workq = emallocz(sizeof(Fsrpc)*Nr_workbufs);
62−// for(i=0; i<Nr_workbufs; i++)
63−// Workq[i].buf = emallocz(messagesize);
6460 fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
6561
6662 fmtinstall('F', fcallfmt);
@@ -78,7 +74,7 @@ exportfs(int fd) · 11 unmodified lines
7874 fatal("Out of service buffers");
7975
8076 DEBUG(DFD, "read9p...");
81− n = read9pmsg(netfd, r->buf, messagesize);
77+ n = read9pmsg(netfd[0], r->buf, messagesize);
8278 if(n <= 0)
8379 fatal(nil);
8480
@@ -122,7 +118,7 @@ if(0) iprint("-> %F\n", t); · 37 unmodified lines
122118 if(data == nil)
123119 fatal(Enomem);
124120 n = convS2M(t, data, messagesize);
125− if((m=write(netfd, data, n))!=n){
121+ if((m=write(netfd[1], data, n))!=n){
126122 iprint("wrote %d got %d (%r)\n", n, m);
127123 fatal("write");
128124 }
exportfs/exportsrv.c+1−1
@@ -15,7 +15,7 @@ char Enomem[] = "No memory"; · 14 unmodified lines
1515 char Eversion[] = "Bad 9P2000 version";
1616
1717 void*
18−emallocz(ulong n)
18+emallocz(uint n)
1919 {
2020 void *v;
2121
kern/devlfd-win32.c+20−0
@@ -23,6 +23,26 @@ lfdchan(void *fd) · 22 unmodified lines
2323 return c;
2424 }
2525
26+/*
27+ * only good for stdin/stdout/stderr
28+ */
29+int
30+lfdfd(int fd)
31+{
32+ HANDLE h;
33+
34+ switch(fd){
35+ case 0: h = GetStdHandle(STD_INPUT_HANDLE); break;
36+ case 1: h = GetStdHandle(STD_OUTPUT_HANDLE); break;
37+ case 2: h = GetStdHandle(STD_ERROR_HANDLE); break;
38+ default:
39+ return -1;
40+ }
41+ if(h == INVALID_HANDLE_VALUE)
42+ return -1;
43+ return newfd(lfdchan((void*)h));
44+}
45+
2646 static Chan*
2747 lfdattach(char *x)
2848 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t