]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/exportfs/exportfs.c
exportfs: revert e524e8d65a7573c46d7beb49e77bfc2d55a5563d
[plan9front.git] / sys / src / cmd / exportfs / exportfs.c
1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #define Extern
5 #include "exportfs.h"
6
7 int     srvfd = -1;
8 int     readonly;
9
10 void
11 usage(void)
12 {
13         fprint(2, "usage: %s [-dsR] [-f dbgfile] [-m msize] [-r root] "
14                 "[-S srvfile] [-P exclusion-file]\n", argv0);
15         fatal("usage");
16 }
17
18 void
19 main(int argc, char **argv)
20 {
21         char *dbfile, *srv, *srvfdfile;
22         int n;
23
24         dbfile = "/tmp/exportdb";
25         srv = nil;
26         srvfd = -1;
27         srvfdfile = nil;
28
29         ARGBEGIN{
30         case 'd':
31                 dbg++;
32                 break;
33
34         case 'f':
35                 dbfile = EARGF(usage());
36                 break;
37
38         case 'm':
39                 messagesize = strtoul(EARGF(usage()), nil, 0);
40                 break;
41
42         case 'r':
43                 srv = EARGF(usage());
44                 break;
45
46         case 's':
47                 srv = "/";
48                 break;
49
50         case 'F':
51                 /* accepted but ignored, for backwards compatibility */
52                 break;
53
54         case 'P':
55                 patternfile = EARGF(usage());
56                 break;
57
58         case 'R':
59                 readonly = 1;
60                 break;
61
62         case 'S':
63                 if(srvfdfile != nil)
64                         usage();
65                 srvfdfile = EARGF(usage());
66                 break;
67
68         default:
69                 usage();
70         }ARGEND
71         USED(argc, argv);
72
73         if(srvfdfile != nil){
74                 if(srv != nil){
75                         fprint(2, "exportfs: -S cannot be used with -r or -s\n");
76                         usage();
77                 }
78                 if((srvfd = open(srvfdfile, ORDWR)) < 0)
79                         fatal("open %s: %r", srvfdfile);
80         } else if(srv == nil)
81                 usage();
82
83         exclusions();
84
85         if(dbg) {
86                 n = create(dbfile, OWRITE|OTRUNC, 0666);
87                 dup(n, DFD);
88                 close(n);
89         }
90
91         DEBUG(DFD, "exportfs: started\n");
92
93         rfork(RFNOTEG|RFREND);
94
95         if(messagesize == 0){
96                 messagesize = iounit(0);
97                 if(messagesize == 0)
98                         messagesize = 8192+IOHDRSZ;
99         }
100         fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
101
102         fmtinstall('F', fcallfmt);
103
104         if(srvfd == -1) {
105                 if(chdir(srv) < 0) {
106                         char ebuf[ERRMAX];
107                         ebuf[0] = '\0';
108                         errstr(ebuf, sizeof ebuf);
109                         DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf);
110                         mounterror(ebuf);
111                 }
112                 DEBUG(DFD, "invoked as server for %s", srv);
113         }
114
115         DEBUG(DFD, "\niniting root\n");
116         initroot();
117         io();
118 }