mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-15 11:20:03 +00:00
126 lines
2.5 KiB
C
126 lines
2.5 KiB
C
#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{
|
|
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("ffsopen: %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");
|
|
sunsrvprog(srv, &nfs3prog, nfs3chan);
|
|
sunsrvprog(srv, &nfsmount3prog, mountchan);
|
|
|
|
sunsrvthreadcreate(srv, nfs3proc, nfs3chan);
|
|
sunsrvthreadcreate(srv, mount3proc, mountchan);
|
|
|
|
fsgetroot(&h);
|
|
print("mountbackups -h %.*H %s /mountpoint\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);
|
|
}
|
|
|