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.
13 static void *null_result = (void *)&null_int;
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 te string is allowed as a filename. */
20 gboolean validate_filename(const char *filename)
22 if (filename == NULL || filename[0] == '\0')
24 if (strlen(filename) > 255)
26 if (!g_utf8_validate(filename, -1, NULL))
28 if (strchr(filename, '/') != NULL)
33 /* Look up a BlueSkyInode given an NFS filehandle. Returns NULL if the
34 * filehandle is invalid. */
35 BlueSkyInode *lookup_fh(nfs_fh3 *fh)
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);
45 /* Copy inode attributes into NFS response. The BlueSkyInode should be locked
47 void encode_fattr3(struct fattr3 *result, BlueSkyInode *inode)
49 result->type = inode->type;
50 result->mode = inode->mode;
51 result->nlink = inode->nlink;
52 result->uid = inode->uid;
53 result->gid = inode->gid;
54 result->size = inode->size;
56 result->rdev.major = 0;
57 result->rdev.minor = 0;
59 result->fileid = inode->inum;
60 result->atime.seconds = inode->atime / 1000000;
61 result->atime.nseconds = (inode->atime % 1000000) * 1000;
62 result->mtime.seconds = inode->mtime / 1000000;
63 result->mtime.nseconds = (inode->mtime % 1000000) * 1000;
64 result->ctime.seconds = inode->ctime / 1000000;
65 result->ctime.nseconds = (inode->ctime % 1000000) * 1000;
69 nfsproc3_null_3_svc(void *argp, struct svc_req *rqstp)
75 nfsproc3_getattr_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
77 static getattr3res result;
79 BlueSkyInode *inode = lookup_fh(argp);
81 result.status = NFS3_OK;
82 encode_fattr3(&result.getattr3res_u.attributes, inode);
84 result.status = NFS3ERR_STALE;
91 nfsproc3_setattr_3_svc(setattr3args *argp, struct svc_req *rqstp)
93 static wccstat3 result;
95 result.status = NFS3ERR_NOTSUPP;
101 nfsproc3_lookup_3_svc(diropargs3 *argp, struct svc_req *rqstp)
103 static lookup3res result;
105 BlueSkyInode *dir = lookup_fh(&argp->dir);
107 result.status = NFS3ERR_STALE;
108 result.lookup3res_u.resfail.present = FALSE;
112 result.lookup3res_u.resfail.present = TRUE;
113 encode_fattr3(&result.lookup3res_u.resfail.post_op_attr_u.attributes, dir);
114 if (!validate_filename(argp->name)) {
115 if (strlen(argp->name) > 255)
116 result.status = NFS3ERR_NAMETOOLONG;
118 result.status = NFS3ERR_NOENT;
122 /* TODO: Special-case "." and "..". */
123 uint64_t inum = bluesky_directory_lookup(dir, argp->name);
125 result.status = NFS3ERR_NOENT;
128 BlueSkyInode *inode = bluesky_get_inode(fs, inum);
130 result.status = NFS3ERR_NOENT;
134 result.lookup3res_u.resok.dir_attributes.present = TRUE;
135 encode_fattr3(&result.lookup3res_u.resok.dir_attributes.post_op_attr_u.attributes, dir);
136 result.lookup3res_u.resok.obj_attributes.present = TRUE;
137 encode_fattr3(&result.lookup3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
139 static uint64_t fh_bytes;
140 fh_bytes = GUINT64_TO_BE(inum);
141 result.lookup3res_u.resok.object.data.data_len = 8;
142 result.lookup3res_u.resok.object.data.data_val = (char *)&fh_bytes;
148 nfsproc3_access_3_svc(access3args *argp, struct svc_req *rqstp)
150 static access3res result;
152 result.status = NFS3ERR_NOTSUPP;
158 nfsproc3_readlink_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
160 static readlink3res result;
162 result.status = NFS3ERR_NOTSUPP;
168 nfsproc3_read_3_svc(read3args *argp, struct svc_req *rqstp)
170 static read3res result;
172 result.status = NFS3ERR_NOTSUPP;
178 nfsproc3_write_3_svc(write3args *argp, struct svc_req *rqstp)
180 static write3res result;
182 result.status = NFS3ERR_NOTSUPP;
188 nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
190 static diropres3 result;
192 result.status = NFS3ERR_NOTSUPP;
198 nfsproc3_mkdir_3_svc(mkdir3args *argp, struct svc_req *rqstp)
200 static diropres3 result;
202 result.status = NFS3ERR_NOTSUPP;
208 nfsproc3_symlink_3_svc(symlink3args *argp, struct svc_req *rqstp)
210 static diropres3 result;
212 result.status = NFS3ERR_NOTSUPP;
218 nfsproc3_mknod_3_svc(mknod3args *argp, struct svc_req *rqstp)
220 static diropres3 result;
222 result.status = NFS3ERR_NOTSUPP;
228 nfsproc3_remove_3_svc(diropargs3 *argp, struct svc_req *rqstp)
230 static wccstat3 result;
232 result.status = NFS3ERR_NOTSUPP;
238 nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
240 static wccstat3 result;
242 result.status = NFS3ERR_NOTSUPP;
248 nfsproc3_rename_3_svc(rename3args *argp, struct svc_req *rqstp)
250 static rename3res result;
252 result.status = NFS3ERR_NOTSUPP;
258 nfsproc3_link_3_svc(link3args *argp, struct svc_req *rqstp)
260 static link3res result;
262 result.status = NFS3ERR_NOTSUPP;
268 nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
270 static readdir3res result;
272 result.status = NFS3ERR_NOTSUPP;
278 nfsproc3_readdirplus_3_svc(readdirplus3args *argp, struct svc_req *rqstp)
280 static readdirplus3res result;
282 result.status = NFS3ERR_NOTSUPP;
288 nfsproc3_fsstat_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
290 static fsstat3res result;
292 result.status = NFS3ERR_NOTSUPP;
298 nfsproc3_fsinfo_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
300 static fsinfo3res result;
302 BlueSkyInode *inode = bluesky_get_inode(fs, 1);
303 result.status = NFS3_OK;
304 result.fsinfo3res_u.resok.obj_attributes.present = TRUE;
305 encode_fattr3(&result.fsinfo3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
306 result.fsinfo3res_u.resok.rtmax = 32768;
307 result.fsinfo3res_u.resok.rtpref = 32768;
308 result.fsinfo3res_u.resok.rtmult = 4096;
309 result.fsinfo3res_u.resok.wtmax = 32768;
310 result.fsinfo3res_u.resok.wtpref = 32768;
311 result.fsinfo3res_u.resok.wtmult = 4096;
312 result.fsinfo3res_u.resok.dtpref = 4096;
313 result.fsinfo3res_u.resok.maxfilesize = 0x7fffffffffffffffULL;
314 result.fsinfo3res_u.resok.time_delta.seconds = 0;
315 result.fsinfo3res_u.resok.time_delta.nseconds = 1000;
316 result.fsinfo3res_u.resok.properties
317 = FSF3_LINK | FSF3_SYMLINK | FSF3_HOMOGENEOUS | FSF3_CANSETTIME;
323 nfsproc3_pathconf_3_svc(nfs_fh3 *argp, struct svc_req *rqstp)
325 static pathconf3res result;
327 BlueSkyInode *inode = bluesky_get_inode(fs, 1);
328 result.status = NFS3_OK;
329 result.pathconf3res_u.resok.obj_attributes.present = TRUE;
330 encode_fattr3(&result.pathconf3res_u.resok.obj_attributes.post_op_attr_u.attributes, inode);
331 result.pathconf3res_u.resok.linkmax = 0xffffffff;
332 result.pathconf3res_u.resok.name_max = 255;
333 result.pathconf3res_u.resok.no_trunc = TRUE;
334 result.pathconf3res_u.resok.chown_restricted = TRUE;
335 result.pathconf3res_u.resok.case_insensitive = FALSE;
336 result.pathconf3res_u.resok.case_preserving = TRUE;
342 nfsproc3_commit_3_svc(commit3args *argp, struct svc_req *rqstp)
344 static commit3res result;
346 result.status = NFS3ERR_NOTSUPP;