aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vbackup/disknfs.c
blob: b51d0a3b8dbefbeef135b7f96d955e047280e889 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <u.h>
#include <libc.h>
#include <ip.h>
#include <thread.h>
#include <sunrpc.h>
#include <nfs3.h>
#include <diskfs.h>
#include "nfs3srv.h"

Disk *disk;
Fsys *fsys;

void
usage(void)
{
	fprint(2, "usage: disknfs [-RTr] disk\n");
	threadexitsall("usage");
}

extern int _threaddebuglevel;

void
threadmain(int argc, char **argv)
{
	char *addr;
	SunSrv *srv;
	Channel *nfs3chan;
	Channel *mountchan;
	Nfs3Handle h;

	fmtinstall('B', sunrpcfmt);
	fmtinstall('C', suncallfmt);
	fmtinstall('H', encodefmt);
	fmtinstall('I', eipfmt);
	sunfmtinstall(&nfs3prog);
	sunfmtinstall(&nfsmount3prog);

	srv = sunsrv();
	addr = "*";

	ARGBEGIN{
	default:
		usage();
	case 'L':
		if(srv->localonly == 0)
			srv->localonly = 1;
		else
			srv->localparanoia = 1;
		break;
	case 'R':
		srv->chatty++;
		break;
	case 'T':
		_threaddebuglevel = 0xFFFFFFFF;
		break;
	case 'r':
		srv->alwaysreject++;
		break;
	}ARGEND

	if(argc != 1 && argc != 2)
		usage();

	if((disk = diskopenfile(argv[0])) == nil)
		sysfatal("diskopen: %r");
	if((disk = diskcache(disk, 16384, 256)) == nil)
		sysfatal("diskcache: %r");

	if((fsys = fsysopen(disk)) == nil)
		sysfatal("fsysopen: %r");

	nfs3chan = chancreate(sizeof(SunMsg*), 0);
	mountchan = chancreate(sizeof(SunMsg*), 0);

	if(argc > 1)
		addr = argv[1];
	addr = netmkaddr(addr, "udp", "2049");

	if(sunsrvudp(srv, addr) < 0)
		sysfatal("starting server: %r");

	sunsrvthreadcreate(srv, nfs3proc, nfs3chan);
	sunsrvthreadcreate(srv, mount3proc, mountchan);

	sunsrvprog(srv, &nfs3prog, nfs3chan);
	sunsrvprog(srv, &nfsmount3prog, mountchan);
	fsgetroot(&h);

	print("vmount0 -h %.*H %s /mnt\n", h.len, h.h, addr);

	threadexits(nil);
}

void
fsgetroot(Nfs3Handle *h)
{
	fsysroot(fsys, h);
}

Nfs3Status
fsgetattr(SunAuthUnix *au, Nfs3Handle *h, Nfs3Attr *attr)
{
	return fsysgetattr(fsys, au, h, attr);
}

Nfs3Status
fslookup(SunAuthUnix *au, Nfs3Handle *h, char *name, Nfs3Handle *nh)
{
	return fsyslookup(fsys, au, h, name, nh);
}

Nfs3Status
fsaccess(SunAuthUnix *au, Nfs3Handle *h, u32int want, u32int *got, Nfs3Attr *attr)
{
	return fsysaccess(fsys, au, h, want, got, attr);
}

Nfs3Status
fsreadlink(SunAuthUnix *au, Nfs3Handle *h, char **link)
{
	return fsysreadlink(fsys, au, h, link);
}

Nfs3Status
fsreadfile(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int offset, uchar **data, u32int *pcount, u1int *peof)
{
	return fsysreadfile(fsys, au, h, count, offset, data, pcount, peof);
}

Nfs3Status
fsreaddir(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int cookie, uchar **data, u32int *pcount, u1int *peof)
{
	return fsysreaddir(fsys, au, h, count, cookie, data, pcount, peof);
}