2 * Simple read-only NFS v3 server.
3 * Runs every request in its own thread.
4 * Expects client to provide the fsxxx routines in nfs3srv.h.
14 authunixunpack(SunRpc *rpc, SunAuthUnix *au)
20 if(ai->flavor != SunAuthSys)
21 return SunAuthTooWeak;
24 if(sunauthunixunpack(p, ep, &p, au) < 0)
25 return SunGarbageArgs;
39 memset(&rx, 0, sizeof rx);
40 return sunmsgreply(m, &rx.call);
51 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
52 return sunmsgreplyerror(m, ok);
54 /* ignore file system path and return the dump tree */
56 memset(&rx, 0, sizeof rx);
59 memset(&nh, 0, sizeof nh);
64 return sunmsgreply(m, &rx.call);
74 memset(&rx, 0, sizeof rx);
75 return sunmsgreply(m, &rx.call);
85 memset(&rx, 0, sizeof rx);
86 return sunmsgreply(m, &rx.call);
96 memset(&rx, 0, sizeof rx);
98 return sunmsgreply(m, &rx.call);
107 switch(m->call->type){
109 sunmsgreplyerror(m, SunProcUnavail);
110 case NfsMount3CallTNull:
113 case NfsMount3CallTMnt:
116 case NfsMount3CallTDump:
119 case NfsMount3CallTUmnt:
122 case NfsMount3CallTUmntall:
125 case NfsMount3CallTExport:
137 threadsetname("mount1");
139 while((m=recvp(c)) != nil)
140 threadcreate(rmount3, m, SunStackSize);
144 senderror(SunMsg *m, SunCall *rc, Nfs3Status status)
146 /* knows that status is first field in all replies */
147 ((Nfs3RGetattr*)rc)->status = status;
148 return sunmsgreply(m, rc);
156 memset(&rx, 0, sizeof rx);
157 return sunmsgreply(m, &rx.call);
163 Nfs3TGetattr *tx = (Nfs3TGetattr*)m->call;
168 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
169 return sunmsgreplyerror(m, ok);
171 memset(&rx, 0, sizeof rx);
172 rx.status = fsgetattr(&au, &tx->handle, &rx.attr);
173 return sunmsgreply(m, &rx.call);
179 Nfs3TLookup *tx = (Nfs3TLookup*)m->call;
184 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
185 return sunmsgreplyerror(m, ok);
187 memset(&rx, 0, sizeof rx);
188 rx.status = fsgetattr(&au, &tx->handle, &rx.dirAttr);
189 if(rx.status != Nfs3Ok)
190 return sunmsgreply(m, &rx.call);
192 rx.status = fslookup(&au, &tx->handle, tx->name, &rx.handle);
193 if(rx.status != Nfs3Ok)
194 return sunmsgreply(m, &rx.call);
195 rx.status = fsgetattr(&au, &rx.handle, &rx.attr);
196 if(rx.status != Nfs3Ok)
197 return sunmsgreply(m, &rx.call);
199 return sunmsgreply(m, &rx.call);
205 Nfs3TAccess *tx = (Nfs3TAccess*)m->call;
210 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
211 return sunmsgreplyerror(m, ok);
213 memset(&rx, 0, sizeof rx);
215 rx.status = fsaccess(&au, &tx->handle, tx->access, &rx.access, &rx.attr);
216 return sunmsgreply(m, &rx.call);
223 Nfs3TReadlink *tx = (Nfs3TReadlink*)m->call;
227 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
228 return sunmsgreplyerror(m, ok);
230 memset(&rx, 0, sizeof rx);
233 rx.status = fsreadlink(&au, &tx->handle, &rx.data);
234 sunmsgreply(m, &rx.call);
242 Nfs3TRead *tx = (Nfs3TRead*)m->call;
247 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
248 return sunmsgreplyerror(m, ok);
250 memset(&rx, 0, sizeof rx);
253 rx.status = fsreadfile(&au, &tx->handle, tx->count, tx->offset, &rx.data, &rx.count, &rx.eof);
254 if(rx.status == Nfs3Ok)
257 sunmsgreply(m, &rx.call);
265 Nfs3TReadDir *tx = (Nfs3TReadDir*)m->call;
270 if((ok = authunixunpack(&m->rpc, &au)) != SunSuccess)
271 return sunmsgreplyerror(m, ok);
273 memset(&rx, 0, sizeof rx);
274 rx.status = fsreaddir(&au, &tx->handle, tx->count, tx->cookie, &rx.data, &rx.count, &rx.eof);
275 sunmsgreply(m, &rx.call);
281 rreaddirplus(SunMsg *m)
285 memset(&rx, 0, sizeof rx);
286 rx.status = Nfs3ErrNotSupp;
287 sunmsgreply(m, &rx.call);
296 /* just make something up */
297 memset(&rx, 0, sizeof rx);
300 rx.totalBytes = 1000000000;
303 rx.totalFiles = 100000;
307 return sunmsgreply(m, &rx.call);
315 /* just make something up */
316 memset(&rx, 0, sizeof rx);
319 rx.readMax = MaxDataSize;
320 rx.readPref = MaxDataSize;
321 rx.readMult = MaxDataSize;
322 rx.writeMax = MaxDataSize;
323 rx.writePref = MaxDataSize;
324 rx.writeMult = MaxDataSize;
325 rx.readDirPref = MaxDataSize;
326 rx.maxFileSize = 1LL<<60;
328 rx.timePrec.nsec = 0;
329 rx.flags = Nfs3FsHomogeneous|Nfs3FsCanSetTime;
330 return sunmsgreply(m, &rx.call);
338 memset(&rx, 0, sizeof rx);
344 rx.chownRestricted = 0;
345 rx.caseInsensitive = 0;
346 rx.casePreserving = 1;
347 return sunmsgreply(m, &rx.call);
353 uchar buf[512]; /* clumsy hack*/
355 memset(buf, 0, sizeof buf);
356 return senderror(m, (SunCall*)buf, Nfs3ErrRoFs);
366 switch(m->call->type){
372 case Nfs3CallTGetattr:
375 case Nfs3CallTLookup:
378 case Nfs3CallTAccess:
381 case Nfs3CallTReadlink:
387 case Nfs3CallTReadDir:
390 case Nfs3CallTReadDirPlus:
393 case Nfs3CallTFsStat:
396 case Nfs3CallTFsInfo:
399 case Nfs3CallTPathconf:
402 case Nfs3CallTSetattr:
404 case Nfs3CallTCreate:
406 case Nfs3CallTSymlink:
408 case Nfs3CallTRemove:
411 case Nfs3CallTCommit:
424 threadsetname("nfs3");
425 while((m = recvp(c)) != nil)
426 threadcreate(rnfs3, m, SunStackSize);