From 988bf74dd44cd57d0b67aa2a7f1bf77e09c24484 Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Sun, 23 Aug 2009 16:30:43 -0700 Subject: [PATCH] CREATE working (sort of). --- nfs3/nfs3.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/nfs3/nfs3.c b/nfs3/nfs3.c index f13a6f2..e464684 100644 --- a/nfs3/nfs3.c +++ b/nfs3/nfs3.c @@ -65,6 +65,15 @@ void encode_fattr3(struct fattr3 *result, BlueSkyInode *inode) result->ctime.nseconds = (inode->ctime % 1000000) * 1000; } +void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode) +{ + wcc->before.present = TRUE; + wcc->before.pre_op_attr_u.attributes.size = inode->size; + wcc->before.pre_op_attr_u.attributes.mtime.seconds = inode->mtime / 1000000; + wcc->before.pre_op_attr_u.attributes.mtime.nseconds = (inode->mtime % 1000000) * 1000; + wcc->before.pre_op_attr_u.attributes.ctime.seconds = inode->ctime / 1000000; + wcc->before.pre_op_attr_u.attributes.ctime.nseconds = (inode->ctime % 1000000) * 1000; +} void * nfsproc3_null_3_svc(void *argp, struct svc_req *rqstp) { @@ -198,8 +207,50 @@ diropres3 * nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp) { static diropres3 result; + struct wcc_data wcc; + memset(&wcc, 0, sizeof(wcc)); - result.status = NFS3ERR_NOTSUPP; + BlueSkyInode *dir = lookup_fh(&argp->where.dir); + if (dir == NULL) { + result.status = NFS3ERR_STALE; + result.diropres3_u.resfail = wcc; + return &result; + } + + encode_pre_wcc(&wcc, dir); + if (dir->type != BLUESKY_DIRECTORY) { + result.status = NFS3ERR_NOTDIR; + result.diropres3_u.resfail = wcc; + return &result; + } + + if (!validate_filename(argp->where.name) + || strcmp(argp->where.name, ".") == 0 + || strcmp(argp->where.name, "..") == 0) + { + result.status = NFS3ERR_EXIST; + result.diropres3_u.resfail = wcc; + return &result; + } + + BlueSkyInode *file; + file = bluesky_new_inode(bluesky_fs_alloc_inode(fs), BLUESKY_REGULAR); + file->nlink = 1; + file->mode = 0755; + bluesky_insert_inode(fs, file); + bluesky_directory_insert(dir, argp->where.name, file->inum); + + wcc.after.present = TRUE; + encode_fattr3(&wcc.after.post_op_attr_u.attributes, dir); + result.diropres3_u.resok.obj_attributes.present = TRUE; + encode_fattr3(&result.diropres3_u.resok.obj_attributes.post_op_attr_u.attributes, file); + result.diropres3_u.resok.dir_wcc = wcc; + + static uint64_t fh_bytes; + fh_bytes = GUINT64_TO_BE(file->inum); + result.diropres3_u.resok.obj.present = TRUE; + result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_len = 8; + result.diropres3_u.resok.obj.post_op_fh3_u.handle.data.data_val = (char *)&fh_bytes; return &result; } -- 2.20.1