Work on NFS rmdir operation.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Wed, 6 Jan 2010 19:03:15 +0000 (11:03 -0800)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Wed, 6 Jan 2010 19:03:15 +0000 (11:03 -0800)
nfs3/nfs3.c

index 0ba7f56..4b1b8c5 100644 (file)
@@ -600,7 +600,51 @@ nfsproc3_rmdir_3_svc(diropargs3 *argp, struct svc_req *rqstp)
 {
     static wccstat3 result;
 
-    result.status = NFS3ERR_NOTSUPP;
+    result.wccstat3_u.wcc.before.present = FALSE;
+    result.wccstat3_u.wcc.after.present = FALSE;
+
+    BlueSkyInode *dir = lookup_fh(&argp->dir);
+    if (dir == NULL) {
+        result.status = NFS3ERR_STALE;
+        return &result;
+    }
+
+    encode_pre_wcc(&result.wccstat3_u.wcc, dir);
+
+    if (!validate_filename(argp->name)
+        || strcmp(argp->name, ".") == 0
+        || strcmp(argp->name, "..") == 0)
+    {
+        result.status = NFS3ERR_NOENT;
+        return &result;
+    }
+
+    uint64_t inum = bluesky_directory_lookup(dir, argp->name);
+    BlueSkyInode *inode = bluesky_get_inode(fs, inum);
+    if (inode == NULL) {
+        result.status = NFS3ERR_NOENT;
+        return &result;
+    }
+
+    if (inode->type != BLUESKY_DIRECTORY) {
+        result.status = NFS3ERR_NOTDIR;
+        return &result;
+    }
+    if (g_sequence_get_length(inode->dirents) > 0) {
+        printf("Directory not empty: %d entries\n",
+               g_sequence_get_length(inode->dirents));
+        result.status = NFS3ERR_NOTEMPTY;
+        return &result;
+    }
+
+    /* TODO: Decrement link count, deallocate inode if needed. */
+
+    bluesky_directory_remove(dir, argp->name);
+
+    result.status = NFS3_OK;
+    result.wccstat3_u.wcc.after.present = TRUE;
+    encode_fattr3(&result.wccstat3_u.wcc.after.post_op_attr_u.attributes,
+                  dir);
 
     return &result;
 }