disknfs.c (2623B)
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" 9 10 Disk *disk; 11 Fsys *fsys; 12 13 void 14 usage(void) 15 { 16 fprint(2, "usage: disknfs [-RTr] disk\n"); 17 threadexitsall("usage"); 18 } 19 20 extern int _threaddebuglevel; 21 22 void 23 threadmain(int argc, char **argv) 24 { 25 char *addr; 26 SunSrv *srv; 27 Channel *nfs3chan; 28 Channel *mountchan; 29 Nfs3Handle h; 30 31 fmtinstall('B', sunrpcfmt); 32 fmtinstall('C', suncallfmt); 33 fmtinstall('H', encodefmt); 34 fmtinstall('I', eipfmt); 35 sunfmtinstall(&nfs3prog); 36 sunfmtinstall(&nfsmount3prog); 37 38 srv = sunsrv(); 39 addr = "*"; 40 41 ARGBEGIN{ 42 default: 43 usage(); 44 case 'L': 45 if(srv->localonly == 0) 46 srv->localonly = 1; 47 else 48 srv->localparanoia = 1; 49 break; 50 case 'R': 51 srv->chatty++; 52 break; 53 case 'T': 54 _threaddebuglevel = 0xFFFFFFFF; 55 break; 56 case 'r': 57 srv->alwaysreject++; 58 break; 59 }ARGEND 60 61 if(argc != 1 && argc != 2) 62 usage(); 63 64 if((disk = diskopenfile(argv[0])) == nil) 65 sysfatal("diskopen: %r"); 66 if((disk = diskcache(disk, 16384, 256)) == nil) 67 sysfatal("diskcache: %r"); 68 69 if((fsys = fsysopen(disk)) == nil) 70 sysfatal("fsysopen: %r"); 71 72 nfs3chan = chancreate(sizeof(SunMsg*), 0); 73 mountchan = chancreate(sizeof(SunMsg*), 0); 74 75 if(argc > 1) 76 addr = argv[1]; 77 addr = netmkaddr(addr, "udp", "2049"); 78 79 if(sunsrvudp(srv, addr) < 0) 80 sysfatal("starting server: %r"); 81 82 sunsrvthreadcreate(srv, nfs3proc, nfs3chan); 83 sunsrvthreadcreate(srv, mount3proc, mountchan); 84 85 sunsrvprog(srv, &nfs3prog, nfs3chan); 86 sunsrvprog(srv, &nfsmount3prog, mountchan); 87 fsgetroot(&h); 88 89 print("vmount0 -h %.*H %s /mnt\n", h.len, h.h, addr); 90 91 threadexits(nil); 92 } 93 94 void 95 fsgetroot(Nfs3Handle *h) 96 { 97 fsysroot(fsys, h); 98 } 99 100 Nfs3Status 101 fsgetattr(SunAuthUnix *au, Nfs3Handle *h, Nfs3Attr *attr) 102 { 103 return fsysgetattr(fsys, au, h, attr); 104 } 105 106 Nfs3Status 107 fslookup(SunAuthUnix *au, Nfs3Handle *h, char *name, Nfs3Handle *nh) 108 { 109 return fsyslookup(fsys, au, h, name, nh); 110 } 111 112 Nfs3Status 113 fsaccess(SunAuthUnix *au, Nfs3Handle *h, u32int want, u32int *got, Nfs3Attr *attr) 114 { 115 return fsysaccess(fsys, au, h, want, got, attr); 116 } 117 118 Nfs3Status 119 fsreadlink(SunAuthUnix *au, Nfs3Handle *h, char **link) 120 { 121 return fsysreadlink(fsys, au, h, link); 122 } 123 124 Nfs3Status 125 fsreadfile(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int offset, uchar **data, u32int *pcount, u1int *peof) 126 { 127 return fsysreadfile(fsys, au, h, count, offset, data, pcount, peof); 128 } 129 130 Nfs3Status 131 fsreaddir(SunAuthUnix *au, Nfs3Handle *h, u32int count, u64int cookie, uchar **data, u32int *pcount, u1int *peof) 132 { 133 return fsysreaddir(fsys, au, h, count, cookie, data, pcount, peof); 134 }