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
27static int norcpu;27static int norcpu;
28static int nokbd;28static int nokbd;
29static int nogfx;29static int nogfx;
30static int nineflag;
30 31
31static char *ealgs = "rc4_256 sha1";32static char *ealgs = "rc4_256 sha1";
32 33
@@ -176,7 +177,7 @@ rcpu(char *host, char *cmd) · 143 unmodified lines
176 atexit(rcpuexit);177 atexit(rcpuexit);
177 178
178 /* Begin serving the namespace */179 /* Begin serving the namespace */
179 exportfs(fd);180 exportfs(fd, fd);
180}181}
181 182
182void183void
@@ -236,13 +237,13 @@ ncpu(char *host, char *cmd) · 53 unmodified lines
236 write(fd, "OK", 2);237 write(fd, "OK", 2);
237 238
238 /* Begin serving the gnot namespace */239 /* Begin serving the gnot namespace */
239 exportfs(fd);240 exportfs(fd, fd);
240}241}
241 242
242void243void
243usage(void)244usage(void)
244{245{
245 fprint(2, "usage: %s [-GBO] "246 fprint(2, "usage: %s [-9GBO] "
246 "[-h host] [-u user] [-a authserver] [-s secstore] "247 "[-h host] [-u user] [-a authserver] [-s secstore] "
247 "[-e 'crypt hash'] [-k keypattern] "248 "[-e 'crypt hash'] [-k keypattern] "
248 "[-p] [-t timeout] "249 "[-p] [-t timeout] "
@@ -262,12 +263,13 @@ cpumain(int argc, char **argv) · 13 unmodified lines
262 char *s;263 char *s;
263 264
264 user = getenv("USER");265 user = getenv("USER");
265 if((pass = getenv("PASS")) != nil)
266 remove("/env/PASS");
267 host = getenv("cpu");266 host = getenv("cpu");
268 authserver = getenv("auth");267 authserver = getenv("auth");
269 268
270 ARGBEGIN{269 ARGBEGIN{
270 case '9':
271 nineflag = 1;
272 /* wet floor */
271 case 'G':273 case 'G':
272 nogfx = 1;274 nogfx = 1;
273 /* wet floor */275 /* wet floor */
@@ -320,8 +322,8 @@ cpumain(int argc, char **argv) · 46 unmodified lines
320 break;322 break;
321 case 'g':323 case 'g':
322 /* X11 geometry string324 /* X11 geometry string
323 [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]325 * [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]
324 */326 */
325 geometry = EARGF(usage());327 geometry = EARGF(usage());
326 break;328 break;
327 default:329 default:
@@ -331,6 +333,14 @@ cpumain(int argc, char **argv) · 3 unmodified lines
331 if(argc != 0)333 if(argc != 0)
332 usage();334 usage();
333 335
336 if(nineflag){
337 exportfs(lfdfd(0), lfdfd(1));
338 return;
339 }
340
341 if((pass = getenv("PASS")) != nil)
342 remove("/env/PASS");
343
334 if(!nogfx)344 if(!nogfx)
335 guimain();345 guimain();
336 else346 else
drawterm.1+7−1
@@ -6,7 +6,7 @@ drawterm \- connection to cpu, fs, and auth servers · 5 unmodified lines
6.SH SYNOPSIS6.SH SYNOPSIS
7.B drawterm7.B drawterm
8[8[
9.B -GBO9.B -9GBO
10] [10] [
11.B -h11.B -h
12.I host12.I host
@@ -50,6 +50,12 @@ The goal of drawterm is to provide an abstraction layer from the client operatin · 37 unmodified lines
50The options are:50The options are:
51.PD51.PD
52 52
53.TP
54.B -9
55Start drawterm in 9P mode;
56exporting the namespace over 9P on standard input and output.
57Graphics and keyboard input are disabled.
58
53.TP59.TP
54.B -G60.B -G
55Start drawterm in text-only mode (no graphics).61Start 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
2extern char *secstore;2extern char *secstore;
3extern char *secstorefetch(char *addr, char *owner, char *passwd);3extern char *secstorefetch(char *addr, char *owner, char *passwd);
4extern char *authserver;4extern char *authserver;
5extern int exportfs(int);5extern int exportfs(int, int);
6extern int dialfactotum(void);6extern int dialfactotum(void);
7extern char *getuser(void);7extern char *getuser(void);
8extern void cpumain(int, char**);8extern void cpumain(int, char**);
exportfs/exportfs.c+8−12
@@ -9,7 +9,6 @@ · 8 unmodified lines
9#define Extern9#define Extern
10#include "exportfs.h"10#include "exportfs.h"
11 11
12/* #define QIDPATH ((1LL<<48)-1) */
13#define QIDPATH ((((vlong)1)<<48)-1)12#define QIDPATH ((((vlong)1)<<48)-1)
14vlong newqid = 0;13vlong newqid = 0;
15 14
@@ -21,15 +20,16 @@ int freecnt; · 5 unmodified lines
21int qidcnt;20int qidcnt;
22int qfreecnt;21int qfreecnt;
23int ncollision;22int ncollision;
24int netfd;23int netfd[2];
25 24
26int25int
27exportfs(int fd)26exportfs(int rfd, int wfd)
28{27{
29 char buf[ERRMAX], ebuf[ERRMAX];28 char buf[ERRMAX], ebuf[ERRMAX];
30 Fsrpc *r;29 Fsrpc *r;
31 int i, n;30 int i, n;
32 31
32
33 fcalls[Tversion] = Xversion;33 fcalls[Tversion] = Xversion;
34 fcalls[Tauth] = Xauth;34 fcalls[Tauth] = Xauth;
35 fcalls[Tflush] = Xflush;35 fcalls[Tflush] = Xflush;
@@ -45,22 +45,18 @@ exportfs(int fd) · 9 unmodified lines
45 fcalls[Twstat] = Xwstat;45 fcalls[Twstat] = Xwstat;
46 46
47 srvfd = -1;47 srvfd = -1;
48 netfd = fd;48 netfd[0] = rfd;
49 //dbg = 1;49 netfd[1] = wfd;
50 50
51 strcpy(buf, "this is buf");51 strcpy(buf, "this is buf");
52 strcpy(ebuf, "this is ebuf");52 strcpy(ebuf, "this is ebuf");
53 DEBUG(DFD, "exportfs: started\n");53 DEBUG(DFD, "exportfs: started\n");
54 54
55// rfork(RFNOTEG);55 messagesize = iounit(rfd);
56
57 messagesize = iounit(netfd);
58 if(messagesize == 0)56 if(messagesize == 0)
59 messagesize = IOUNIT+IOHDRSZ;57 messagesize = IOUNIT+IOHDRSZ;
60 58
61 Workq = emallocz(sizeof(Fsrpc)*Nr_workbufs);59 Workq = emallocz(sizeof(Fsrpc)*Nr_workbufs);
62// for(i=0; i<Nr_workbufs; i++)
63// Workq[i].buf = emallocz(messagesize);
64 fhash = emallocz(sizeof(Fid*)*FHASHSIZE);60 fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
65 61
66 fmtinstall('F', fcallfmt);62 fmtinstall('F', fcallfmt);
@@ -78,7 +74,7 @@ exportfs(int fd) · 11 unmodified lines
78 fatal("Out of service buffers");74 fatal("Out of service buffers");
79 75
80 DEBUG(DFD, "read9p...");76 DEBUG(DFD, "read9p...");
81 n = read9pmsg(netfd, r->buf, messagesize);77 n = read9pmsg(netfd[0], r->buf, messagesize);
82 if(n <= 0)78 if(n <= 0)
83 fatal(nil);79 fatal(nil);
84 80
@@ -122,7 +118,7 @@ if(0) iprint("-> %F\n", t); · 37 unmodified lines
122 if(data == nil)118 if(data == nil)
123 fatal(Enomem);119 fatal(Enomem);
124 n = convS2M(t, data, messagesize);120 n = convS2M(t, data, messagesize);
125 if((m=write(netfd, data, n))!=n){121 if((m=write(netfd[1], data, n))!=n){
126 iprint("wrote %d got %d (%r)\n", n, m);122 iprint("wrote %d got %d (%r)\n", n, m);
127 fatal("write");123 fatal("write");
128 }124 }
exportfs/exportsrv.c+1−1
@@ -15,7 +15,7 @@ char Enomem[] = "No memory"; · 14 unmodified lines
15char Eversion[] = "Bad 9P2000 version";15char Eversion[] = "Bad 9P2000 version";
16 16
17void*17void*
18emallocz(ulong n)18emallocz(uint n)
19{19{
20 void *v;20 void *v;
21 21
kern/devlfd-win32.c+20−0
@@ -23,6 +23,26 @@ lfdchan(void *fd) · 22 unmodified lines
23 return c;23 return c;
24}24}
25 25
26/*
27 * only good for stdin/stdout/stderr
28 */
29int
30lfdfd(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
26static Chan*46static Chan*
27lfdattach(char *x)47lfdattach(char *x)
28{48{

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