2011-03-30 12:46:40 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include <fcall.h>
|
|
|
|
#define Extern
|
|
|
|
#include "exportfs.h"
|
|
|
|
|
|
|
|
int srvfd = -1;
|
|
|
|
int readonly;
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
2021-08-18 17:51:40 +00:00
|
|
|
fprint(2, "usage: %s [-dsR] [-m msize] [-r root] "
|
|
|
|
"[-P patternfile] [-S srvfile]\n", argv0);
|
2011-03-30 12:46:40 +00:00
|
|
|
fatal("usage");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2021-08-18 17:51:40 +00:00
|
|
|
char *srv, *srvfdfile;
|
2011-03-30 12:46:40 +00:00
|
|
|
|
|
|
|
srv = nil;
|
|
|
|
srvfd = -1;
|
|
|
|
srvfdfile = nil;
|
|
|
|
|
|
|
|
ARGBEGIN{
|
|
|
|
case 'd':
|
|
|
|
dbg++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
messagesize = strtoul(EARGF(usage()), nil, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
srv = EARGF(usage());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
srv = "/";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'F':
|
|
|
|
/* accepted but ignored, for backwards compatibility */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
patternfile = EARGF(usage());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R':
|
|
|
|
readonly = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
2014-08-02 13:07:29 +00:00
|
|
|
if(srvfdfile != nil)
|
2011-03-30 12:46:40 +00:00
|
|
|
usage();
|
|
|
|
srvfdfile = EARGF(usage());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}ARGEND
|
|
|
|
USED(argc, argv);
|
|
|
|
|
2014-08-02 13:07:29 +00:00
|
|
|
if(srvfdfile != nil){
|
2020-12-13 19:09:03 +00:00
|
|
|
if(srv != nil){
|
|
|
|
fprint(2, "exportfs: -S cannot be used with -r or -s\n");
|
|
|
|
usage();
|
|
|
|
}
|
2011-03-30 12:46:40 +00:00
|
|
|
if((srvfd = open(srvfdfile, ORDWR)) < 0)
|
2012-06-25 07:38:19 +00:00
|
|
|
fatal("open %s: %r", srvfdfile);
|
2020-12-13 19:09:03 +00:00
|
|
|
} else if(srv == nil)
|
|
|
|
usage();
|
2011-03-30 12:46:40 +00:00
|
|
|
|
|
|
|
exclusions();
|
|
|
|
|
2021-08-18 17:51:40 +00:00
|
|
|
DEBUG(2, "exportfs: started\n");
|
2011-03-30 12:46:40 +00:00
|
|
|
|
2014-02-21 04:23:21 +00:00
|
|
|
rfork(RFNOTEG|RFREND);
|
2011-03-30 12:46:40 +00:00
|
|
|
|
|
|
|
if(messagesize == 0){
|
2014-08-13 22:11:14 +00:00
|
|
|
messagesize = iounit(0);
|
2011-03-30 12:46:40 +00:00
|
|
|
if(messagesize == 0)
|
|
|
|
messagesize = 8192+IOHDRSZ;
|
|
|
|
}
|
|
|
|
fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
|
|
|
|
|
|
|
|
fmtinstall('F', fcallfmt);
|
|
|
|
|
2020-12-13 19:09:03 +00:00
|
|
|
if(srvfd == -1) {
|
2013-02-10 22:31:26 +00:00
|
|
|
if(chdir(srv) < 0) {
|
2020-12-13 19:09:03 +00:00
|
|
|
char ebuf[ERRMAX];
|
2016-02-14 03:48:48 +00:00
|
|
|
ebuf[0] = '\0';
|
2013-02-10 22:31:26 +00:00
|
|
|
errstr(ebuf, sizeof ebuf);
|
2021-08-18 17:51:40 +00:00
|
|
|
DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
|
2020-12-13 19:09:03 +00:00
|
|
|
mounterror(ebuf);
|
2013-02-10 22:31:26 +00:00
|
|
|
}
|
2021-08-18 17:51:40 +00:00
|
|
|
DEBUG(2, "invoked as server for %s", srv);
|
2011-03-30 12:46:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 17:51:40 +00:00
|
|
|
DEBUG(2, "\niniting root\n");
|
2011-03-30 12:46:40 +00:00
|
|
|
initroot();
|
2020-12-13 19:09:03 +00:00
|
|
|
io();
|
2011-03-30 12:46:40 +00:00
|
|
|
}
|