summaryrefslogtreecommitdiff
path: root/sys/src/cmd/exportfs/exportfs.c
blob: 86680e1f602016dc7d049a76cc283573b4359816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <u.h>
#include <libc.h>
#include <fcall.h>
#define Extern
#include "exportfs.h"

int	srvfd = -1;
int	readonly;

void
usage(void)
{
	fprint(2, "usage: %s [-dsR] [-m msize] [-r root] "
		"[-P patternfile] [-S srvfile]\n", argv0);
	fatal("usage");
}

void
main(int argc, char **argv)
{
	char *srv, *srvfdfile;

	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':
		if(srvfdfile != nil)
			usage();
		srvfdfile = EARGF(usage());
		break;

	default:
		usage();
	}ARGEND
	USED(argc, argv);

	if(srvfdfile != nil){
		if(srv != nil){
			fprint(2, "exportfs: -S cannot be used with -r or -s\n");
			usage();
		}
		if((srvfd = open(srvfdfile, ORDWR)) < 0)
			fatal("open %s: %r", srvfdfile);
	} else if(srv == nil)
		usage();

	exclusions();

	DEBUG(2, "exportfs: started\n");

	rfork(RFNOTEG|RFREND);

	if(messagesize == 0){
		messagesize = iounit(0);
		if(messagesize == 0)
			messagesize = 8192+IOHDRSZ;
	}
	fhash = emallocz(sizeof(Fid*)*FHASHSIZE);

	fmtinstall('F', fcallfmt);

	if(srvfd == -1) {
		if(chdir(srv) < 0) {
			char ebuf[ERRMAX];
			ebuf[0] = '\0';
			errstr(ebuf, sizeof ebuf);
			DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
			mounterror(ebuf);
		}
		DEBUG(2, "invoked as server for %s", srv);
	}

	DEBUG(2, "\niniting root\n");
	initroot();
	io();
}