Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <ip.h>
4 #include <thread.h>
5 #include <sunrpc.h>
6 #include <nfs3.h>
7 #include <diskfs.h>
8 #include "nfs3srv.h"
10 Disk *disk;
11 Fsys *fsys;
13 void
14 usage(void)
15 {
16 fprint(2, "usage: disknfs [-RTr] disk\n");
17 threadexitsall("usage");
18 }
20 extern int _threaddebuglevel;
22 void
23 threadmain(int argc, char **argv)
24 {
25 char *addr;
26 SunSrv *srv;
27 Channel *nfs3chan;
28 Channel *mountchan;
29 Nfs3Handle h;
31 fmtinstall('B', sunrpcfmt);
32 fmtinstall('C', suncallfmt);
33 fmtinstall('H', encodefmt);
34 fmtinstall('I', eipfmt);
35 sunfmtinstall(&nfs3prog);
36 sunfmtinstall(&nfsmount3prog);
38 srv = sunsrv();
39 addr = "*";
41 ARGBEGIN{
42 case 'R':
43 srv->chatty++;
44 break;
45 case 'T':
46 _threaddebuglevel = 0xFFFFFFFF;
47 break;
48 case 'r':
49 srv->alwaysreject++;
50 break;
51 }ARGEND
53 if(argc != 1 && argc != 2)
54 usage();
56 if((disk = diskopenfile(argv[0])) == nil)
57 sysfatal("diskopen: %r");
58 if((disk = diskcache(disk, 16384, 256)) == nil)
59 sysfatal("diskcache: %r");
61 if((fsys = fsysopen(disk)) == nil)
62 sysfatal("ffsopen: %r");
64 nfs3chan = chancreate(sizeof(SunMsg*), 0);
65 mountchan = chancreate(sizeof(SunMsg*), 0);
67 if(argc > 1)
68 addr = argv[1];
69 addr = netmkaddr(addr, "udp", "2049");
71 if(sunsrvudp(srv, addr) < 0)
72 sysfatal("starting server: %r");
73 sunsrvprog(srv, &nfs3prog, nfs3chan);
74 sunsrvprog(srv, &nfsmount3prog, mountchan);
76 sunsrvthreadcreate(srv, nfs3proc, nfs3chan);
77 sunsrvthreadcreate(srv, mount3proc, mountchan);
79 fsgetroot(&h);
80 print("mountbackups -h %.*H %s /mountpoint\n", h.len, h.h, addr);
82 threadexits(nil);
83 }
85 void
86 fsgetroot(Nfs3Handle *h)
87 {
88 fsysroot(fsys, h);
89 }
91 Nfs3Status
92 fsgetattr(SunAuthUnix *au, Nfs3Handle *h, Nfs3Attr *attr)
93 {
94 return fsysgetattr(fsys, au, h, attr);
95 }
97 Nfs3Status
98 fslookup(SunAuthUnix *au, Nfs3Handle *h, char *name, Nfs3Handle *nh)
99 {
100 return fsyslookup(fsys, au, h, name, nh);
103 Nfs3Status
104 fsaccess(SunAuthUnix *au, Nfs3Handle *h, u32int want, u32int *got, Nfs3Attr *attr)
106 return fsysaccess(fsys, au, h, want, got, attr);
109 Nfs3Status
110 fsreadlink(SunAuthUnix *au, Nfs3Handle *h, char **link)
112 return fsysreadlink(fsys, au, h, link);
115 Nfs3Status
116 fsreadfile(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int offset, uchar **data, u32int *pcount, u1int *peof)
118 return fsysreadfile(fsys, au, h, count, offset, data, pcount, peof);
121 Nfs3Status
122 fsreaddir(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int cookie, uchar **data, u32int *pcount, u1int *peof)
124 return fsysreaddir(fsys, au, h, count, cookie, data, pcount, peof);