Calculate size of symlinks.
[bluesky.git] / nfs3 / nfs3.c
1 /*
2  * This is sample code generated by rpcgen.
3  * These are only templates and you can use them
4  * as a guideline for developing your own functions.
5  */
6
7 #include "nfs3_prot.h"
8 #include "bluesky.h"
9
10 extern BlueSkyFS *fs;
11
12 static int null_int;
13 static void *null_result = (void *)&null_int;
14
15 /* Check that a string is a valid file name.  We require that it be valid
16  * UTF-8, that it not be empty, and that it not contain embedded forward
17  * slashes.  Also checks that the length of the string is not more than the
18  * maximum allowed length.  This function does allow the names "." and "..".
19  * Returns TRUE if the string is allowed as a filename. */
20 gboolean validate_filename(const char *filename)
21 {
22     if (filename == NULL || filename[0] == '\0')
23         return FALSE;
24     if (strlen(filename) > 255)
25         return FALSE;
26     if (!g_utf8_validate(filename, -1, NULL))
27         return FALSE;
28     if (strchr(filename, '/') != NULL)
29         return FALSE;
30     return TRUE;
31 }
32
33 /* Look up a BlueSkyInode given an NFS filehandle.  Returns NULL if the
34  * filehandle is invalid. */
35 BlueSkyInode *lookup_fh(nfs_fh3 *fh)
36 {
37     BlueSkyInode *inode = NULL;
38     if (fh->data.data_len == 8) {
39         uint64_t inum = GUINT64_FROM_BE(*(uint64_t *)(fh->data.data_val));
40         inode = bluesky_get_inode(fs, inum);
41     }
42     return inode;
43 }
44
45 int64_t decode_nfstime3(nfstime3 *time)
46 {
47     int64_t result = (int64_t)time->seconds * 1000000;
48     result += time->nseconds / 1000;
49     return result;
50 }
51
52 void set_attributes(BlueSkyInode *inode, sattr3 *attributes)
53 {
54     int64_t now = bluesky_get_current_time();
55
56     if (attributes->mode.set) {
57         inode->mode = attributes->mode.set_uint32_u.val;
58     }
59
60     if (attributes->uid.set) {
61         inode->uid = attributes->uid.set_uint32_u.val;
62     }
63
64     if (attributes->gid.set) {
65         inode->gid = attributes->gid.set_uint32_u.val;
66     }
67
68     if (attributes->size.set) {
69         if (inode->type == BLUESKY_REGULAR) {
70             bluesky_file_truncate(inode, attributes->size.set_uint64_u.val);
71             inode->mtime = now;
72         }
73     }
74
75     switch (attributes->atime.set) {
76     case DONT_CHANGE:
77         break;
78     case SET_TO_SERVER_TIME:
79         inode->atime = now;
80         break;
81     case SET_TO_CLIENT_TIME:
82         inode->atime = decode_nfstime3(&attributes->atime.set_time_u.time);
83         break;
84     }
85
86     switch (attributes->mtime.set) {
87     case DONT_CHANGE:
88         break;
89     case SET_TO_SERVER_TIME:
90         inode->mtime = now;
91         break;
92     case SET_TO_CLIENT_TIME:
93         inode->mtime = decode_nfstime3(&attributes->mtime.set_time_u.time);
94         break;
95     }
96
97     inode->ctime = now;
98     inode->change_count++;
99 }
100
101 /* Copy inode attributes into NFS response.  The BlueSkyInode should be locked
102  * by the caller. */
103 void encode_fattr3(struct fattr3 *result, BlueSkyInode *inode)
104 {
105     result->type = inode->type;
106     result->mode = inode->mode;
107     result->nlink = inode->nlink;
108     result->uid = inode->uid;
109     result->gid = inode->gid;
110     result->size = inode->size;
111     result->used = 0;
112     result->rdev.major = 0;
113     result->rdev.minor = 0;
114     result->fsid = 0;
115     result->fileid = inode->inum;
116     result->atime.seconds = inode->atime / 1000000;
117     result->atime.nseconds = (inode->atime % 1000000) * 1000;
118     result->mtime.seconds = inode->mtime / 1000000;
119     result->mtime.nseconds = (inode->mtime % 1000000) * 1000;
120     result->ctime.seconds = inode->ctime / 1000000;
121     result->ctime.nseconds = (inode->ctime % 1000000) * 1000;
122
123     switch (inode->type) {
124     case BLUESKY_SYMLINK:
125         result->size = strlen(inode->symlink_contents);
126         break;
127     default:
128         break;
129     }
130 }
131
132 void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode)
133 {
134     wcc->before.present = TRUE;
135     wcc->before.pre_op_attr_u.attributes.size = inode->size;
136     wcc->before.pre_op_attr_u.attributes.mtime.seconds = inode->mtime / 1000000;
137     wcc->before.pre_op_attr_u.attributes.mtime.nseconds = (inode->mtime % 1000000) * 1000;
138     wcc->before.pre_op_attr_u.attributes.ctime.seconds = inode->ctime / 1000000;
139     wcc->before.pre_op_attr_u.attributes.ctime.nseconds = (inode->ctime % 1000000) * 1000;
140 }
141
142 void *
143 nfsproc3_null_3_svc(void *argp, struct svc_req *rqstp)
144 {
145     return null_result;
146 }
147
148 getattr3res *
149 nfsproc3_getattr_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
150 {
151     static getattr3res result;
152
153     BlueSkyInode *inode = lookup_fh(argp);
154     if (inode != NULL) {
155         result.status = NFS3_OK;
156         encode_fattr3(&result.getattr3res_u.attributes, inode);
157     } else {
158         result.status = NFS3ERR_STALE;
159     }
160
161     return &result;
162 }
163
164 wccstat3 *
165 nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
166 {
167     static wccstat3 result;
168
169     result.wccstat3_u.wcc.before.present = FALSE;
170     result.wccstat3_u.wcc.after.present = FALSE;
171     BlueSkyInode *inode = lookup_fh(&argp->object);
172     if (inode == NULL) {
173         result.status = NFS3ERR_STALE;
174         return &result;
175     }
176
177     encode_pre_wcc(&result.wccstat3_u.wcc, inode);
178     if (argp->guard.check) {
179         if (inode->ctime != decode_nfstime3(&argp->guard.sattrguard3_u.ctime)) {
180             result.status = NFS3ERR_NOT_SYNC;
181             result.wccstat3_u.wcc.after.present = TRUE;
182             encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes, inode);
183             return &result;
184         }
185     }
186
187     set_attributes(inode, &argp->new_attributes);
188
189     result.wccstat3_u.wcc.after.present = TRUE;
190     encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
191                   inode);
192     result.status = NFS3_OK;
193
194     return &result;
195 }
196
197 lookup3res *
198 nfsproc3_lookup_3_svc(diropargs3 *argp, struct svc_req *rqstp)
199 {
200     static lookup3res result;
201
202     BlueSkyInode *dir = lookup_fh(&argp->dir);
203     if (dir == NULL) {
204         result.status = NFS3ERR_STALE;
205         result.lookup3res_u.resfail.present = FALSE;
206         return &result;
207     }
208
209     result.lookup3res_u.resfail.present = TRUE;
210     encode_fattr3(&result.lookup3res_u.resfail.post_op_attr_u.attributes, dir);
211     if (!validate_filename(argp->name)) {
212         if (strlen(argp->name) > 255)
213             result.status = NFS3ERR_NAMETOOLONG;
214         else
215             result.status = NFS3ERR_NOENT;
216         return &result;
217     }
218
219     /* TODO: Special-case "." and "..". */
220     uint64_t inum = bluesky_directory_lookup(dir, argp->name);
221     if (inum == 0) {
222         result.status = NFS3ERR_NOENT;
223         return &result;
224     }
225     BlueSkyInode *inode = bluesky_get_inode(fs, inum);
226     if (inode == NULL) {
227         result.status = NFS3ERR_NOENT;
228         return &result;
229     }
230
231     result.status = NFS3_OK;
232     result.lookup3res_u.resok.dir_attributes.present = TRUE;
233     encode_fattr3(&result.lookup3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir);
234     result.lookup3res_u.resok.obj_attributes.present = TRUE;
235     encode_fattr3(&result.lookup3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
236
237     static uint64_t fh_bytes;
238     fh_bytes = GUINT64_TO_BE(inum);
239     result.lookup3res_u.resok.object.data.data_len = 8;
240     result.lookup3res_u.resok.object.data.data_val = (char *)&fh_bytes;
241
242     return &result;
243 }
244
245 access3res *
246 nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp)
247 {
248     static access3res result;
249
250     BlueSkyInode *inode = lookup_fh(&argp->object);
251     if (inode == NULL) {
252         result.status = NFS3ERR_STALE;
253         result.access3res_u.resfail.present = FALSE;
254         return &result;
255     }
256
257     result.status = NFS3_OK;
258     result.access3res_u.resok.obj_attributes.present = TRUE;
259     encode_fattr3(&result.access3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
260     result.access3res_u.resok.access = argp->access;
261
262     return &result;
263 }
264
265 readlink3res *
266 nfsproc3_readlink_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
267 {
268     static readlink3res result;
269     memset(&result, 0, sizeof(result));
270
271     BlueSkyInode *inode = lookup_fh(argp);
272     if (inode != NULL) {
273         if (inode->type == BLUESKY_SYMLINK) {
274             result.status = NFS3_OK;
275             result.readlink3res_u.resok.symlink_attributes.present = TRUE;
276             encode_fattr3(&result.readlink3res_u.resok.symlink_attributes.post_op_attr_u.attributes, inode);
277             result.readlink3res_u.resok.data = inode->symlink_contents;
278         } else {
279             result.status = NFS3ERR_INVAL;
280             result.readlink3res_u.resfail.present = TRUE;
281             encode_fattr3(&result.readlink3res_u.resfail.post_op_attr_u.attributes, inode);
282         }
283     } else {
284         result.status = NFS3ERR_STALE;
285     }
286
287     return &result;
288 }
289
290 read3res *
291 nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
292 {
293     static read3res result;
294     static char buf[32768];
295
296     BlueSkyInode *inode = lookup_fh(&argp->file);
297     if (inode == NULL) {
298         result.status = NFS3ERR_STALE;
299         result.read3res_u.resfail.present = FALSE;
300         return &result;
301     }
302
303     int count = argp->count;
304     if (argp->offset >= inode->size) {
305         count = 0;
306         result.read3res_u.resok.eof = TRUE;
307     } else {
308         count = MIN(count, inode->size - argp->offset);
309         if (argp->offset + count == inode->size)
310             result.read3res_u.resok.eof = TRUE;
311         else
312             result.read3res_u.resok.eof = FALSE;
313
314         bluesky_file_read(inode, argp->offset, buf, count);
315     }
316
317     result.status = NFS3_OK;
318     result.read3res_u.resok.file_attributes.present = TRUE;
319     encode_fattr3(&result.read3res_u.resok.file_attributes.post_op_attr_u.attributes, inode);
320     result.read3res_u.resok.count = count;
321     result.read3res_u.resok.data.data_val = buf;
322     result.read3res_u.resok.data.data_len = count;
323
324     return &result;
325 }
326
327 write3res *
328 nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
329 {
330     static write3res result;
331     struct wcc_data wcc;
332     memset(&wcc, 0, sizeof(wcc));
333
334     BlueSkyInode *inode = lookup_fh(&argp->file);
335     if (inode == NULL) {
336         result.status = NFS3ERR_STALE;
337         result.write3res_u.resfail = wcc;
338         return &result;
339     }
340
341     encode_pre_wcc(&wcc, inode);
342     if (inode->type != BLUESKY_REGULAR) {
343         result.status = NFS3ERR_INVAL;
344         result.write3res_u.resfail = wcc;
345         return &result;
346     }
347
348     uint64_t lastbyte = argp->offset + argp->count;
349     if (lastbyte > inode->size) {
350         bluesky_file_truncate(inode, lastbyte);
351     }
352
353     if (argp->data.data_len < argp->count) {
354         /* ??? */
355     } else {
356         bluesky_file_write(inode, argp->offset,
357                            argp->data.data_val, argp->count);
358     }
359
360     encode_fattr3(&wcc.after.post_op_attr_u.attributes, inode);
361     result.write3res_u.resok.file_wcc = wcc;
362     result.write3res_u.resok.count = argp->count;
363     result.write3res_u.resok.committed = FILE_SYNC;
364
365     return &result;
366 }
367
368 diropres3 *
369 nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
370 {
371     static diropres3 result;
372     struct wcc_data wcc;
373     memset(&wcc, 0, sizeof(wcc));
374
375     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
376     if (dir == NULL) {
377         result.status = NFS3ERR_STALE;
378         result.diropres3_u.resfail = wcc;
379         return &result;
380     }
381
382     encode_pre_wcc(&wcc, dir);
383     if (dir->type != BLUESKY_DIRECTORY) {
384         result.status = NFS3ERR_NOTDIR;
385         result.diropres3_u.resfail = wcc;
386         return &result;
387     }
388
389     if (!validate_filename(argp->where.name)
390         || strcmp(argp->where.name, ".") == 0
391         || strcmp(argp->where.name, "..") == 0)
392     {
393         result.status = NFS3ERR_EXIST;
394         result.diropres3_u.resfail = wcc;
395         return &result;
396     }
397
398     BlueSkyInode *file;
399     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_REGULAR);
400     file->nlink = 1;
401     file->mode = 0755;
402     int64_t time = bluesky_get_current_time();
403     printf("time: %"PRIi64"\n", time);
404     file->mtime = time;
405     file->ctime = time;
406     file->atime = time;
407     file->ntime = time;
408     bluesky_insert_inode(fs, file);
409     bluesky_directory_insert(dir, argp->where.name, file->inum);
410
411     dir->mtime = dir->ctime = bluesky_get_current_time();
412     dir->change_count++;
413
414     wcc.after.present = TRUE;
415     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
416     result.diropres3_u.resok.obj_attributes.present = TRUE;
417     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
418     result.diropres3_u.resok.dir_wcc = wcc;
419
420     static uint64_t fh_bytes;
421     fh_bytes = GUINT64_TO_BE(file->inum);
422     result.diropres3_u.resok.obj.present = TRUE;
423     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
424     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
425
426     return &result;
427 }
428
429 diropres3 *
430 nfsproc3_mkdir_3_svc(mkdir3args *argp, struct svc_req *rqstp)
431 {
432     static diropres3 result;
433     struct wcc_data wcc;
434     memset(&wcc, 0, sizeof(wcc));
435
436     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
437     if (dir == NULL) {
438         result.status = NFS3ERR_STALE;
439         result.diropres3_u.resfail = wcc;
440         return &result;
441     }
442
443     encode_pre_wcc(&wcc, dir);
444     if (dir->type != BLUESKY_DIRECTORY) {
445         result.status = NFS3ERR_NOTDIR;
446         result.diropres3_u.resfail = wcc;
447         return &result;
448     }
449
450     if (!validate_filename(argp->where.name)
451         || strcmp(argp->where.name, ".") == 0
452         || strcmp(argp->where.name, "..") == 0)
453     {
454         result.status = NFS3ERR_EXIST;
455         result.diropres3_u.resfail = wcc;
456         return &result;
457     }
458
459     BlueSkyInode *file;
460     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_DIRECTORY);
461     file->nlink = 1;
462     file->mode = 0755;
463     int64_t time = bluesky_get_current_time();
464     file->mtime = time;
465     file->ctime = time;
466     file->atime = time;
467     file->ntime = time;
468     bluesky_insert_inode(fs, file);
469     bluesky_directory_insert(dir, argp->where.name, file->inum);
470     set_attributes(file, &argp->attributes);
471
472     dir->mtime = dir->ctime = bluesky_get_current_time();
473     dir->change_count++;
474
475     wcc.after.present = TRUE;
476     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
477     result.diropres3_u.resok.obj_attributes.present = TRUE;
478     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
479     result.diropres3_u.resok.dir_wcc = wcc;
480
481     static uint64_t fh_bytes;
482     fh_bytes = GUINT64_TO_BE(file->inum);
483     result.diropres3_u.resok.obj.present = TRUE;
484     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
485     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
486
487     return &result;
488 }
489
490 diropres3 *
491 nfsproc3_symlink_3_svc(symlink3args *argp, struct svc_req *rqstp)
492 {
493     static diropres3 result;
494     struct wcc_data wcc;
495     memset(&wcc, 0, sizeof(wcc));
496
497     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
498     if (dir == NULL) {
499         result.status = NFS3ERR_STALE;
500         result.diropres3_u.resfail = wcc;
501         return &result;
502     }
503
504     encode_pre_wcc(&wcc, dir);
505     if (dir->type != BLUESKY_DIRECTORY) {
506         result.status = NFS3ERR_NOTDIR;
507         result.diropres3_u.resfail = wcc;
508         return &result;
509     }
510
511     if (!validate_filename(argp->where.name)
512         || strcmp(argp->where.name, ".") == 0
513         || strcmp(argp->where.name, "..") == 0)
514     {
515         result.status = NFS3ERR_EXIST;
516         result.diropres3_u.resfail = wcc;
517         return &result;
518     }
519
520     BlueSkyInode *file;
521     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_SYMLINK);
522     file->nlink = 1;
523     file->mode = 0755;
524     int64_t time = bluesky_get_current_time();
525     file->mtime = time;
526     file->ctime = time;
527     file->atime = time;
528     file->ntime = time;
529     file->symlink_contents = g_strdup(argp->symlink.symlink_data);
530     bluesky_insert_inode(fs, file);
531     bluesky_directory_insert(dir, argp->where.name, file->inum);
532
533     dir->mtime = dir->ctime = bluesky_get_current_time();
534     dir->change_count++;
535
536     wcc.after.present = TRUE;
537     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
538     result.diropres3_u.resok.obj_attributes.present = TRUE;
539     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
540     result.diropres3_u.resok.dir_wcc = wcc;
541
542     static uint64_t fh_bytes;
543     fh_bytes = GUINT64_TO_BE(file->inum);
544     result.diropres3_u.resok.obj.present = TRUE;
545     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
546     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
547
548     return &result;
549 }
550
551 diropres3 *
552 nfsproc3_mknod_3_svc(mknod3args *argp, struct svc_req *rqstp)
553 {
554     static diropres3 result;
555
556     result.status = NFS3ERR_NOTSUPP;
557
558     return &result;
559 }
560
561 wccstat3 *
562 nfsproc3_remove_3_svc(diropargs3 *argp, struct svc_req *rqstp)
563 {
564     static wccstat3 result;
565
566     result.wccstat3_u.wcc.before.present = FALSE;
567     result.wccstat3_u.wcc.after.present = FALSE;
568
569     BlueSkyInode *dir = lookup_fh(&argp->dir);
570     if (dir == NULL) {
571         result.status = NFS3ERR_STALE;
572         return &result;
573     }
574
575     encode_pre_wcc(&result.wccstat3_u.wcc, dir);
576
577     if (!validate_filename(argp->name)
578         || strcmp(argp->name, ".") == 0
579         || strcmp(argp->name, "..") == 0)
580     {
581         result.status = NFS3ERR_NOENT;
582         return &result;
583     }
584
585     /* TODO: Decrement link count, deallocate inode if needed. */
586
587     bluesky_directory_remove(dir, argp->name);
588
589     result.status = NFS3_OK;
590     result.wccstat3_u.wcc.after.present = TRUE;
591     encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
592                   dir);
593
594     return &result;
595 }
596
597 wccstat3 *
598 nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
599 {
600     static wccstat3 result;
601
602     result.status = NFS3ERR_NOTSUPP;
603
604     return &result;
605 }
606
607 rename3res *
608 nfsproc3_rename_3_svc(rename3args *argp, struct svc_req *rqstp)
609 {
610     static rename3res result;
611
612     result.status = NFS3ERR_NOTSUPP;
613
614     return &result;
615 }
616
617 link3res *
618 nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp)
619 {
620     static link3res result;
621     struct wcc_data wcc;
622     memset(&wcc, 0, sizeof(wcc));
623
624     BlueSkyInode *inode = lookup_fh(&argp->file);
625     if (inode == NULL) {
626         result.status = NFS3ERR_STALE;
627         result.link3res_u.res.linkdir_wcc = wcc;
628         return &result;
629     }
630
631     BlueSkyInode *dir = lookup_fh(&argp->link.dir);
632     if (dir == NULL) {
633         result.status = NFS3ERR_STALE;
634         result.link3res_u.res.linkdir_wcc = wcc;
635         return &result;
636     }
637
638     encode_pre_wcc(&wcc, dir);
639     if (dir->type != BLUESKY_DIRECTORY) {
640         result.status = NFS3ERR_NOTDIR;
641         result.link3res_u.res.linkdir_wcc = wcc;
642         return &result;
643     }
644
645     if (!validate_filename(argp->link.name)
646         || strcmp(argp->link.name, ".") == 0
647         || strcmp(argp->link.name, "..") == 0
648         || bluesky_directory_lookup(dir, argp->link.name) != 0)
649     {
650         result.status = NFS3ERR_EXIST;
651         result.link3res_u.res.linkdir_wcc = wcc;
652         return &result;
653     }
654
655     if (!bluesky_directory_insert(dir, argp->link.name, inode->inum)) {
656         result.status = NFS3ERR_EXIST;
657         result.link3res_u.res.linkdir_wcc = wcc;
658         return &result;
659     }
660     inode->nlink++;
661     bluesky_inode_update_ctime(inode, 0);
662
663     result.status = NFS3_OK;
664     wcc.after.present = TRUE;
665     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
666     result.link3res_u.res.file_attributes.present = TRUE;
667     encode_fattr3(&result.link3res_u.res.file_attributes.post_op_attr_u.attributes, inode);
668     result.link3res_u.res.linkdir_wcc = wcc;
669
670     return &result;
671 }
672
673 gint bluesky_dirent_compare(gconstpointer a, gconstpointer b,
674                             gpointer unused);
675
676 readdir3res *
677 nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
678 {
679     static readdir3res result;
680
681     BlueSkyInode *dir = lookup_fh(&argp->dir);
682     if (dir == NULL) {
683         result.status = NFS3ERR_STALE;
684         result.readdir3res_u.resfail.present = FALSE;
685         return &result;
686     }
687
688     result.status = NFS3_OK;
689     result.readdir3res_u.resok.dir_attributes.present = TRUE;
690     encode_fattr3(&result.readdir3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir);
691     memset(result.readdir3res_u.resok.cookieverf, 0,
692            sizeof(result.readdir3res_u.resok.cookieverf));
693
694 #define MAX_READDIR_DIRENTS 4
695     static entry3 dirents[MAX_READDIR_DIRENTS];
696     int count = 0;
697
698     BlueSkyDirent start = {NULL, NULL, argp->cookie, 0};
699     GSequenceIter *i = g_sequence_search(dir->dirents, &start,
700                                          bluesky_dirent_compare, NULL);
701
702     while (count < MAX_READDIR_DIRENTS && !g_sequence_iter_is_end(i)) {
703         BlueSkyDirent *d = g_sequence_get(i);
704         dirents[count].fileid = d->inum;
705         dirents[count].name = d->name;
706         dirents[count].cookie = d->cookie;
707         dirents[count].nextentry = NULL;
708         if (count > 0)
709             dirents[count - 1].nextentry = &dirents[count];
710         i = g_sequence_iter_next(i);
711         count++;
712     }
713
714     if (count > 0)
715         result.readdir3res_u.resok.reply.entries = &dirents[0];
716     else
717         result.readdir3res_u.resok.reply.entries = NULL;
718     result.readdir3res_u.resok.reply.eof = g_sequence_iter_is_end(i);
719
720     return &result;
721 }
722
723 readdirplus3res *
724 nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
725 {
726     static readdirplus3res result;
727
728     result.status = NFS3ERR_NOTSUPP;
729
730     return &result;
731 }
732
733 fsstat3res *
734 nfsproc3_fsstat_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
735 {
736     static fsstat3res result;
737
738     result.status = NFS3ERR_NOTSUPP;
739
740     return &result;
741 }
742
743 fsinfo3res *
744 nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
745 {
746     static fsinfo3res result;
747
748     BlueSkyInode *inode = bluesky_get_inode(fs, 1);
749     result.status = NFS3_OK;
750     result.fsinfo3res_u.resok.obj_attributes.present = TRUE;
751     encode_fattr3(&result.fsinfo3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
752     result.fsinfo3res_u.resok.rtmax = 32768;
753     result.fsinfo3res_u.resok.rtpref = 32768;
754     result.fsinfo3res_u.resok.rtmult = 4096;
755     result.fsinfo3res_u.resok.wtmax = 32768;
756     result.fsinfo3res_u.resok.wtpref = 32768;
757     result.fsinfo3res_u.resok.wtmult = 4096;
758     result.fsinfo3res_u.resok.dtpref = 4096;
759     result.fsinfo3res_u.resok.maxfilesize = 0x7fffffffffffffffULL;
760     result.fsinfo3res_u.resok.time_delta.seconds = 0;
761     result.fsinfo3res_u.resok.time_delta.nseconds = 1000;
762     result.fsinfo3res_u.resok.properties
763         = FSF3_LINK | FSF3_SYMLINK | FSF3_HOMOGENEOUS | FSF3_CANSETTIME;
764
765     return &result;
766 }
767
768 pathconf3res *
769 nfsproc3_pathconf_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
770 {
771     static pathconf3res result;
772
773     BlueSkyInode *inode = bluesky_get_inode(fs, 1);
774     result.status = NFS3_OK;
775     result.pathconf3res_u.resok.obj_attributes.present = TRUE;
776     encode_fattr3(&result.pathconf3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
777     result.pathconf3res_u.resok.linkmax = 0xffffffff;
778     result.pathconf3res_u.resok.name_max = 255;
779     result.pathconf3res_u.resok.no_trunc = TRUE;
780     result.pathconf3res_u.resok.chown_restricted = TRUE;
781     result.pathconf3res_u.resok.case_insensitive = FALSE;
782     result.pathconf3res_u.resok.case_preserving = TRUE;
783
784     return &result;
785 }
786
787 commit3res *
788 nfsproc3_commit_3_svc(commit3args *argp, struct svc_req *rqstp)
789 {
790     static commit3res result;
791
792     result.status = NFS3ERR_NOTSUPP;
793
794     return &result;
795 }