Minor cleanups.
[bluesky.git] / nfs3 / nfs3.c
index 1b83181..2c0d150 100644 (file)
@@ -16,7 +16,7 @@ static void *null_result = (void *)&null_int;
  * UTF-8, that it not be empty, and that it not contain embedded forward
  * slashes.  Also checks that the length of the string is not more than the
  * maximum allowed length.  This function does allow the names "." and "..".
- * Returns TRUE if te string is allowed as a filename. */
+ * Returns TRUE if the string is allowed as a filename. */
 gboolean validate_filename(const char *filename)
 {
     if (filename == NULL || filename[0] == '\0')
@@ -130,6 +130,7 @@ void encode_pre_wcc(struct wcc_data *wcc, BlueSkyInode *inode)
     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)
 {
@@ -376,7 +377,7 @@ nfsproc3_create_3_svc(create3args *argp, struct svc_req *rqstp)
     file->nlink = 1;
     file->mode = 0755;
     int64_t time = bluesky_get_current_time();
-    printf("time: %lld\n", time);
+    printf("time: %"PRIi64"\n", time);
     file->mtime = time;
     file->ctime = time;
     file->atime = time;
@@ -488,7 +489,31 @@ nfsproc3_remove_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;
+    }
+
+    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;
 }
@@ -548,7 +573,7 @@ nfsproc3_readdir_3_svc(readdir3args *argp, struct svc_req *rqstp)
     static entry3 dirents[MAX_READDIR_DIRENTS];
     int count = 0;
 
-    BlueSkyDirent start = {NULL, argp->cookie, 0};
+    BlueSkyDirent start = {NULL, NULL, argp->cookie, 0};
     GSequenceIter *i = g_sequence_search(dir->dirents, &start,
                                          bluesky_dirent_compare, NULL);