Preliminary symlink/readlink support.
[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
124 void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode)
125 {
126     wcc->before.present = TRUE;
127     wcc->before.pre_op_attr_u.attributes.size = inode->size;
128     wcc->before.pre_op_attr_u.attributes.mtime.seconds = inode->mtime / 1000000;
129     wcc->before.pre_op_attr_u.attributes.mtime.nseconds = (inode->mtime % 1000000) * 1000;
130     wcc->before.pre_op_attr_u.attributes.ctime.seconds = inode->ctime / 1000000;
131     wcc->before.pre_op_attr_u.attributes.ctime.nseconds = (inode->ctime % 1000000) * 1000;
132 }
133
134 void *
135 nfsproc3_null_3_svc(void *argp, struct svc_req *rqstp)
136 {
137     return null_result;
138 }
139
140 getattr3res *
141 nfsproc3_getattr_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
142 {
143     static getattr3res result;
144
145     BlueSkyInode *inode = lookup_fh(argp);
146     if (inode != NULL) {
147         result.status = NFS3_OK;
148         encode_fattr3(&result.getattr3res_u.attributes, inode);
149     } else {
150         result.status = NFS3ERR_STALE;
151     }
152
153     return &result;
154 }
155
156 wccstat3 *
157 nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
158 {
159     static wccstat3 result;
160
161     result.wccstat3_u.wcc.before.present = FALSE;
162     result.wccstat3_u.wcc.after.present = FALSE;
163     BlueSkyInode *inode = lookup_fh(&argp->object);
164     if (inode == NULL) {
165         result.status = NFS3ERR_STALE;
166         return &result;
167     }
168
169     encode_pre_wcc(&result.wccstat3_u.wcc, inode);
170     if (argp->guard.check) {
171         if (inode->ctime != decode_nfstime3(&argp->guard.sattrguard3_u.ctime)) {
172             result.status = NFS3ERR_NOT_SYNC;
173             result.wccstat3_u.wcc.after.present = TRUE;
174             encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes, inode);
175             return &result;
176         }
177     }
178
179     set_attributes(inode, &argp->new_attributes);
180
181     result.wccstat3_u.wcc.after.present = TRUE;
182     encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
183                   inode);
184     result.status = NFS3_OK;
185
186     return &result;
187 }
188
189 lookup3res *
190 nfsproc3_lookup_3_svc(diropargs3 *argp, struct svc_req *rqstp)
191 {
192     static lookup3res result;
193
194     BlueSkyInode *dir = lookup_fh(&argp->dir);
195     if (dir == NULL) {
196         result.status = NFS3ERR_STALE;
197         result.lookup3res_u.resfail.present = FALSE;
198         return &result;
199     }
200
201     result.lookup3res_u.resfail.present = TRUE;
202     encode_fattr3(&result.lookup3res_u.resfail.post_op_attr_u.attributes, dir);
203     if (!validate_filename(argp->name)) {
204         if (strlen(argp->name) > 255)
205             result.status = NFS3ERR_NAMETOOLONG;
206         else
207             result.status = NFS3ERR_NOENT;
208         return &result;
209     }
210
211     /* TODO: Special-case "." and "..". */
212     uint64_t inum = bluesky_directory_lookup(dir, argp->name);
213     if (inum == 0) {
214         result.status = NFS3ERR_NOENT;
215         return &result;
216     }
217     BlueSkyInode *inode = bluesky_get_inode(fs, inum);
218     if (inode == NULL) {
219         result.status = NFS3ERR_NOENT;
220         return &result;
221     }
222
223     result.status = NFS3_OK;
224     result.lookup3res_u.resok.dir_attributes.present = TRUE;
225     encode_fattr3(&result.lookup3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir);
226     result.lookup3res_u.resok.obj_attributes.present = TRUE;
227     encode_fattr3(&result.lookup3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
228
229     static uint64_t fh_bytes;
230     fh_bytes = GUINT64_TO_BE(inum);
231     result.lookup3res_u.resok.object.data.data_len = 8;
232     result.lookup3res_u.resok.object.data.data_val = (char *)&fh_bytes;
233
234     return &result;
235 }
236
237 access3res *
238 nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp)
239 {
240     static access3res result;
241
242     BlueSkyInode *inode = lookup_fh(&argp->object);
243     if (inode == NULL) {
244         result.status = NFS3ERR_STALE;
245         result.access3res_u.resfail.present = FALSE;
246         return &result;
247     }
248
249     result.status = NFS3_OK;
250     result.access3res_u.resok.obj_attributes.present = TRUE;
251     encode_fattr3(&result.access3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
252     result.access3res_u.resok.access = argp->access;
253
254     return &result;
255 }
256
257 readlink3res *
258 nfsproc3_readlink_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
259 {
260     static readlink3res result;
261     memset(&result, 0, sizeof(result));
262
263     BlueSkyInode *inode = lookup_fh(argp);
264     if (inode != NULL) {
265         if (inode->type == BLUESKY_SYMLINK) {
266             result.status = NFS3_OK;
267             result.readlink3res_u.resok.symlink_attributes.present = TRUE;
268             encode_fattr3(&result.readlink3res_u.resok.symlink_attributes.post_op_attr_u.attributes, inode);
269             result.readlink3res_u.resok.data = inode->symlink_contents;
270         } else {
271             result.status = NFS3ERR_INVAL;
272             result.readlink3res_u.resfail.present = TRUE;
273             encode_fattr3(&result.readlink3res_u.resfail.post_op_attr_u.attributes, inode);
274         }
275     } else {
276         result.status = NFS3ERR_STALE;
277     }
278
279     return &result;
280 }
281
282 read3res *
283 nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
284 {
285     static read3res result;
286     static char buf[32768];
287
288     BlueSkyInode *inode = lookup_fh(&argp->file);
289     if (inode == NULL) {
290         result.status = NFS3ERR_STALE;
291         result.read3res_u.resfail.present = FALSE;
292         return &result;
293     }
294
295     int count = argp->count;
296     if (argp->offset >= inode->size) {
297         count = 0;
298         result.read3res_u.resok.eof = TRUE;
299     } else {
300         count = MIN(count, inode->size - argp->offset);
301         if (argp->offset + count == inode->size)
302             result.read3res_u.resok.eof = TRUE;
303         else
304             result.read3res_u.resok.eof = FALSE;
305
306         bluesky_file_read(inode, argp->offset, buf, count);
307     }
308
309     result.status = NFS3_OK;
310     result.read3res_u.resok.file_attributes.present = TRUE;
311     encode_fattr3(&result.read3res_u.resok.file_attributes.post_op_attr_u.attributes, inode);
312     result.read3res_u.resok.count = count;
313     result.read3res_u.resok.data.data_val = buf;
314     result.read3res_u.resok.data.data_len = count;
315
316     return &result;
317 }
318
319 write3res *
320 nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
321 {
322     static write3res result;
323     struct wcc_data wcc;
324     memset(&wcc, 0, sizeof(wcc));
325
326     BlueSkyInode *inode = lookup_fh(&argp->file);
327     if (inode == NULL) {
328         result.status = NFS3ERR_STALE;
329         result.write3res_u.resfail = wcc;
330         return &result;
331     }
332
333     encode_pre_wcc(&wcc, inode);
334     if (inode->type != BLUESKY_REGULAR) {
335         result.status = NFS3ERR_INVAL;
336         result.write3res_u.resfail = wcc;
337         return &result;
338     }
339
340     uint64_t lastbyte = argp->offset + argp->count;
341     if (lastbyte > inode->size) {
342         bluesky_file_truncate(inode, lastbyte);
343     }
344
345     if (argp->data.data_len < argp->count) {
346         /* ??? */
347     } else {
348         bluesky_file_write(inode, argp->offset,
349                            argp->data.data_val, argp->count);
350     }
351
352     encode_fattr3(&wcc.after.post_op_attr_u.attributes, inode);
353     result.write3res_u.resok.file_wcc = wcc;
354     result.write3res_u.resok.count = argp->count;
355     result.write3res_u.resok.committed = FILE_SYNC;
356
357     return &result;
358 }
359
360 diropres3 *
361 nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
362 {
363     static diropres3 result;
364     struct wcc_data wcc;
365     memset(&wcc, 0, sizeof(wcc));
366
367     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
368     if (dir == NULL) {
369         result.status = NFS3ERR_STALE;
370         result.diropres3_u.resfail = wcc;
371         return &result;
372     }
373
374     encode_pre_wcc(&wcc, dir);
375     if (dir->type != BLUESKY_DIRECTORY) {
376         result.status = NFS3ERR_NOTDIR;
377         result.diropres3_u.resfail = wcc;
378         return &result;
379     }
380
381     if (!validate_filename(argp->where.name)
382         || strcmp(argp->where.name, ".") == 0
383         || strcmp(argp->where.name, "..") == 0)
384     {
385         result.status = NFS3ERR_EXIST;
386         result.diropres3_u.resfail = wcc;
387         return &result;
388     }
389
390     BlueSkyInode *file;
391     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_REGULAR);
392     file->nlink = 1;
393     file->mode = 0755;
394     int64_t time = bluesky_get_current_time();
395     printf("time: %"PRIi64"\n", time);
396     file->mtime = time;
397     file->ctime = time;
398     file->atime = time;
399     file->ntime = time;
400     bluesky_insert_inode(fs, file);
401     bluesky_directory_insert(dir, argp->where.name, file->inum);
402
403     dir->mtime = dir->ctime = bluesky_get_current_time();
404     dir->change_count++;
405
406     wcc.after.present = TRUE;
407     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
408     result.diropres3_u.resok.obj_attributes.present = TRUE;
409     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
410     result.diropres3_u.resok.dir_wcc = wcc;
411
412     static uint64_t fh_bytes;
413     fh_bytes = GUINT64_TO_BE(file->inum);
414     result.diropres3_u.resok.obj.present = TRUE;
415     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
416     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
417
418     return &result;
419 }
420
421 diropres3 *
422 nfsproc3_mkdir_3_svc(mkdir3args *argp, struct svc_req *rqstp)
423 {
424     static diropres3 result;
425     struct wcc_data wcc;
426     memset(&wcc, 0, sizeof(wcc));
427
428     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
429     if (dir == NULL) {
430         result.status = NFS3ERR_STALE;
431         result.diropres3_u.resfail = wcc;
432         return &result;
433     }
434
435     encode_pre_wcc(&wcc, dir);
436     if (dir->type != BLUESKY_DIRECTORY) {
437         result.status = NFS3ERR_NOTDIR;
438         result.diropres3_u.resfail = wcc;
439         return &result;
440     }
441
442     if (!validate_filename(argp->where.name)
443         || strcmp(argp->where.name, ".") == 0
444         || strcmp(argp->where.name, "..") == 0)
445     {
446         result.status = NFS3ERR_EXIST;
447         result.diropres3_u.resfail = wcc;
448         return &result;
449     }
450
451     BlueSkyInode *file;
452     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_DIRECTORY);
453     file->nlink = 1;
454     file->mode = 0755;
455     int64_t time = bluesky_get_current_time();
456     file->mtime = time;
457     file->ctime = time;
458     file->atime = time;
459     file->ntime = time;
460     bluesky_insert_inode(fs, file);
461     bluesky_directory_insert(dir, argp->where.name, file->inum);
462     set_attributes(file, &argp->attributes);
463
464     dir->mtime = dir->ctime = bluesky_get_current_time();
465     dir->change_count++;
466
467     wcc.after.present = TRUE;
468     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
469     result.diropres3_u.resok.obj_attributes.present = TRUE;
470     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
471     result.diropres3_u.resok.dir_wcc = wcc;
472
473     static uint64_t fh_bytes;
474     fh_bytes = GUINT64_TO_BE(file->inum);
475     result.diropres3_u.resok.obj.present = TRUE;
476     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
477     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
478
479     return &result;
480 }
481
482 diropres3 *
483 nfsproc3_symlink_3_svc(symlink3args *argp, struct svc_req *rqstp)
484 {
485     static diropres3 result;
486     struct wcc_data wcc;
487     memset(&wcc, 0, sizeof(wcc));
488
489     BlueSkyInode *dir = lookup_fh(&argp->where.dir);
490     if (dir == NULL) {
491         result.status = NFS3ERR_STALE;
492         result.diropres3_u.resfail = wcc;
493         return &result;
494     }
495
496     encode_pre_wcc(&wcc, dir);
497     if (dir->type != BLUESKY_DIRECTORY) {
498         result.status = NFS3ERR_NOTDIR;
499         result.diropres3_u.resfail = wcc;
500         return &result;
501     }
502
503     if (!validate_filename(argp->where.name)
504         || strcmp(argp->where.name, ".") == 0
505         || strcmp(argp->where.name, "..") == 0)
506     {
507         result.status = NFS3ERR_EXIST;
508         result.diropres3_u.resfail = wcc;
509         return &result;
510     }
511
512     BlueSkyInode *file;
513     file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), fs, BLUESKY_SYMLINK);
514     file->nlink = 1;
515     file->mode = 0755;
516     int64_t time = bluesky_get_current_time();
517     file->mtime = time;
518     file->ctime = time;
519     file->atime = time;
520     file->ntime = time;
521     file->symlink_contents = g_strdup(argp->symlink.symlink_data);
522     bluesky_insert_inode(fs, file);
523     bluesky_directory_insert(dir, argp->where.name, file->inum);
524
525     dir->mtime = dir->ctime = bluesky_get_current_time();
526     dir->change_count++;
527
528     wcc.after.present = TRUE;
529     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
530     result.diropres3_u.resok.obj_attributes.present = TRUE;
531     encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file);
532     result.diropres3_u.resok.dir_wcc = wcc;
533
534     static uint64_t fh_bytes;
535     fh_bytes = GUINT64_TO_BE(file->inum);
536     result.diropres3_u.resok.obj.present = TRUE;
537     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8;
538     result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes;
539
540     return &result;
541 }
542
543 diropres3 *
544 nfsproc3_mknod_3_svc(mknod3args *argp, struct svc_req *rqstp)
545 {
546     static diropres3 result;
547
548     result.status = NFS3ERR_NOTSUPP;
549
550     return &result;
551 }
552
553 wccstat3 *
554 nfsproc3_remove_3_svc(diropargs3 *argp, struct svc_req *rqstp)
555 {
556     static wccstat3 result;
557
558     result.wccstat3_u.wcc.before.present = FALSE;
559     result.wccstat3_u.wcc.after.present = FALSE;
560
561     BlueSkyInode *dir = lookup_fh(&argp->dir);
562     if (dir == NULL) {
563         result.status = NFS3ERR_STALE;
564         return &result;
565     }
566
567     encode_pre_wcc(&result.wccstat3_u.wcc, dir);
568
569     if (!validate_filename(argp->name)
570         || strcmp(argp->name, ".") == 0
571         || strcmp(argp->name, "..") == 0)
572     {
573         result.status = NFS3ERR_NOENT;
574         return &result;
575     }
576
577     /* TODO: Decrement link count, deallocate inode if needed. */
578
579     bluesky_directory_remove(dir, argp->name);
580
581     result.status = NFS3_OK;
582     result.wccstat3_u.wcc.after.present = TRUE;
583     encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
584                   dir);
585
586     return &result;
587 }
588
589 wccstat3 *
590 nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
591 {
592     static wccstat3 result;
593
594     result.status = NFS3ERR_NOTSUPP;
595
596     return &result;
597 }
598
599 rename3res *
600 nfsproc3_rename_3_svc(rename3args *argp, struct svc_req *rqstp)
601 {
602     static rename3res result;
603
604     result.status = NFS3ERR_NOTSUPP;
605
606     return &result;
607 }
608
609 link3res *
610 nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp)
611 {
612     static link3res result;
613     struct wcc_data wcc;
614     memset(&wcc, 0, sizeof(wcc));
615
616     BlueSkyInode *inode = lookup_fh(&argp->file);
617     if (inode == NULL) {
618         result.status = NFS3ERR_STALE;
619         result.link3res_u.res.linkdir_wcc = wcc;
620         return &result;
621     }
622
623     BlueSkyInode *dir = lookup_fh(&argp->link.dir);
624     if (dir == NULL) {
625         result.status = NFS3ERR_STALE;
626         result.link3res_u.res.linkdir_wcc = wcc;
627         return &result;
628     }
629
630     encode_pre_wcc(&wcc, dir);
631     if (dir->type != BLUESKY_DIRECTORY) {
632         result.status = NFS3ERR_NOTDIR;
633         result.link3res_u.res.linkdir_wcc = wcc;
634         return &result;
635     }
636
637     if (!validate_filename(argp->link.name)
638         || strcmp(argp->link.name, ".") == 0
639         || strcmp(argp->link.name, "..") == 0
640         || bluesky_directory_lookup(dir, argp->link.name) != 0)
641     {
642         result.status = NFS3ERR_EXIST;
643         result.link3res_u.res.linkdir_wcc = wcc;
644         return &result;
645     }
646
647     if (!bluesky_directory_insert(dir, argp->link.name, inode->inum)) {
648         result.status = NFS3ERR_EXIST;
649         result.link3res_u.res.linkdir_wcc = wcc;
650         return &result;
651     }
652     inode->nlink++;
653     bluesky_inode_update_ctime(inode, 0);
654
655     result.status = NFS3_OK;
656     wcc.after.present = TRUE;
657     encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir);
658     result.link3res_u.res.file_attributes.present = TRUE;
659     encode_fattr3(&result.link3res_u.res.file_attributes.post_op_attr_u.attributes, inode);
660     result.link3res_u.res.linkdir_wcc = wcc;
661
662     return &result;
663 }
664
665 gint bluesky_dirent_compare(gconstpointer a, gconstpointer b,
666                             gpointer unused);
667
668 readdir3res *
669 nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
670 {
671     static readdir3res result;
672
673     BlueSkyInode *dir = lookup_fh(&argp->dir);
674     if (dir == NULL) {
675         result.status = NFS3ERR_STALE;
676         result.readdir3res_u.resfail.present = FALSE;
677         return &result;
678     }
679
680     result.status = NFS3_OK;
681     result.readdir3res_u.resok.dir_attributes.present = TRUE;
682     encode_fattr3(&result.readdir3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir);
683     memset(result.readdir3res_u.resok.cookieverf, 0,
684            sizeof(result.readdir3res_u.resok.cookieverf));
685
686 #define MAX_READDIR_DIRENTS 4
687     static entry3 dirents[MAX_READDIR_DIRENTS];
688     int count = 0;
689
690     BlueSkyDirent start = {NULL, NULL, argp->cookie, 0};
691     GSequenceIter *i = g_sequence_search(dir->dirents, &start,
692                                          bluesky_dirent_compare, NULL);
693
694     while (count < MAX_READDIR_DIRENTS && !g_sequence_iter_is_end(i)) {
695         BlueSkyDirent *d = g_sequence_get(i);
696         dirents[count].fileid = d->inum;
697         dirents[count].name = d->name;
698         dirents[count].cookie = d->cookie;
699         dirents[count].nextentry = NULL;
700         if (count > 0)
701             dirents[count - 1].nextentry = &dirents[count];
702         i = g_sequence_iter_next(i);
703         count++;
704     }
705
706     if (count > 0)
707         result.readdir3res_u.resok.reply.entries = &dirents[0];
708     else
709         result.readdir3res_u.resok.reply.entries = NULL;
710     result.readdir3res_u.resok.reply.eof = g_sequence_iter_is_end(i);
711
712     return &result;
713 }
714
715 readdirplus3res *
716 nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
717 {
718     static readdirplus3res result;
719
720     result.status = NFS3ERR_NOTSUPP;
721
722     return &result;
723 }
724
725 fsstat3res *
726 nfsproc3_fsstat_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
727 {
728     static fsstat3res result;
729
730     result.status = NFS3ERR_NOTSUPP;
731
732     return &result;
733 }
734
735 fsinfo3res *
736 nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
737 {
738     static fsinfo3res result;
739
740     BlueSkyInode *inode = bluesky_get_inode(fs, 1);
741     result.status = NFS3_OK;
742     result.fsinfo3res_u.resok.obj_attributes.present = TRUE;
743     encode_fattr3(&result.fsinfo3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
744     result.fsinfo3res_u.resok.rtmax = 32768;
745     result.fsinfo3res_u.resok.rtpref = 32768;
746     result.fsinfo3res_u.resok.rtmult = 4096;
747     result.fsinfo3res_u.resok.wtmax = 32768;
748     result.fsinfo3res_u.resok.wtpref = 32768;
749     result.fsinfo3res_u.resok.wtmult = 4096;
750     result.fsinfo3res_u.resok.dtpref = 4096;
751     result.fsinfo3res_u.resok.maxfilesize = 0x7fffffffffffffffULL;
752     result.fsinfo3res_u.resok.time_delta.seconds = 0;
753     result.fsinfo3res_u.resok.time_delta.nseconds = 1000;
754     result.fsinfo3res_u.resok.properties
755         = FSF3_LINK | FSF3_SYMLINK | FSF3_HOMOGENEOUS | FSF3_CANSETTIME;
756
757     return &result;
758 }
759
760 pathconf3res *
761 nfsproc3_pathconf_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
762 {
763     static pathconf3res result;
764
765     BlueSkyInode *inode = bluesky_get_inode(fs, 1);
766     result.status = NFS3_OK;
767     result.pathconf3res_u.resok.obj_attributes.present = TRUE;
768     encode_fattr3(&result.pathconf3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
769     result.pathconf3res_u.resok.linkmax = 0xffffffff;
770     result.pathconf3res_u.resok.name_max = 255;
771     result.pathconf3res_u.resok.no_trunc = TRUE;
772     result.pathconf3res_u.resok.chown_restricted = TRUE;
773     result.pathconf3res_u.resok.case_insensitive = FALSE;
774     result.pathconf3res_u.resok.case_preserving = TRUE;
775
776     return &result;
777 }
778
779 commit3res *
780 nfsproc3_commit_3_svc(commit3args *argp, struct svc_req *rqstp)
781 {
782     static commit3res result;
783
784     result.status = NFS3ERR_NOTSUPP;
785
786     return &result;
787 }