aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-08-06 07:19:41 -0400
committerJeff Garzik <jeff@garzik.org>2006-08-06 07:19:41 -0400
commit9b5287ecb52dc2aefe429b5d09b4bc33e238ba2a (patch)
tree5db9feccbb8291832169e9c3a066c377530cfbf3
parentd0ef9dd5ede6208f120cf4d8abc8561f459ac118 (diff)
downloaddbfs-9b5287ecb52dc2aefe429b5d09b4bc33e238ba2a.tar.gz
Implement rename op. dbfs is now feature-complete.
-rw-r--r--dbfs-backend.c24
-rw-r--r--dbfs.c29
-rw-r--r--dbfs.h1
3 files changed, 51 insertions, 3 deletions
diff --git a/dbfs-backend.c b/dbfs-backend.c
index 6558d1c..b794f01 100644
--- a/dbfs-backend.c
+++ b/dbfs-backend.c
@@ -601,6 +601,30 @@ err_out:
return rc;
}
+int dbfs_rename(guint64 parent, const char *name,
+ guint64 new_parent, const char *new_name)
+{
+ int rc;
+ guint64 ino_n;
+
+ if ((parent == new_parent) && (!strcmp(name, new_name)))
+ return -EINVAL;
+
+ rc = dbfs_dir_lookup(parent, name, &ino_n);
+ if (rc)
+ return rc;
+
+ rc = dbfs_dirent_del(parent, name);
+ if (rc)
+ return rc;
+
+ rc = dbfs_unlink(new_parent, new_name, 0);
+ if (rc && (rc != -ENOENT))
+ return rc;
+
+ return dbfs_dir_append(new_parent, ino_n, new_name);
+}
+
static void ext_list_free(GList *ext_list)
{
GList *tmp;
diff --git a/dbfs.c b/dbfs.c
index fe52f25..324366b 100644
--- a/dbfs.c
+++ b/dbfs.c
@@ -19,6 +19,8 @@
#define FUSE_USE_VERSION 25
+#define _BSD_SOURCE
+
#include <fuse_lowlevel.h>
#include <stdlib.h>
#include <string.h>
@@ -271,6 +273,12 @@ static void dbfs_op_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
return;
}
+ /* these have separate inode-creation hooks */
+ if (S_ISDIR(mode) || S_ISLNK(mode)) {
+ fuse_reply_err(req, EINVAL);
+ return;
+ }
+
rc = dbfs_mknod(parent, name, mode, rdev, &ino);
if (rc) {
fuse_reply_err(req, -rc);
@@ -283,10 +291,17 @@ static void dbfs_op_mknod(fuse_req_t req, fuse_ino_t parent, const char *name,
static void dbfs_op_mkdir(fuse_req_t req, fuse_ino_t parent, const char *name,
mode_t mode)
{
- mode &= (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
+ struct dbfs_inode *ino;
+ int rc;
+
+ mode &= ALLPERMS;
mode |= S_IFDIR;
- return dbfs_op_mknod(req, parent, name, mode, 0);
+ rc = dbfs_mknod(parent, name, mode, 0, &ino);
+ if (rc)
+ fuse_reply_err(req, -rc);
+ else
+ dbfs_reply_ino(req, ino);
}
static void dbfs_op_unlink(fuse_req_t req, fuse_ino_t parent, const char *name)
@@ -425,6 +440,14 @@ err_out:
fuse_reply_err(req, -rc);
}
+static void dbfs_op_rename(fuse_req_t req, fuse_ino_t parent,
+ const char *name, fuse_ino_t newparent,
+ const char *newname)
+{
+ int rc = dbfs_rename(parent, name, newparent, newname);
+ fuse_reply_err(req, -rc);
+}
+
static void dbfs_op_fsync (fuse_req_t req, fuse_ino_t ino,
int datasync, struct fuse_file_info *fi)
{
@@ -672,7 +695,7 @@ static struct fuse_lowlevel_ops dbfs_ops = {
.unlink = dbfs_op_unlink,
.rmdir = dbfs_op_rmdir,
.symlink = dbfs_op_symlink,
- .rename = NULL,
+ .rename = dbfs_op_rename,
.link = dbfs_op_link,
.open = dbfs_op_open,
.read = dbfs_op_read,
diff --git a/dbfs.h b/dbfs.h
index 2b3b186..1cb8179 100644
--- a/dbfs.h
+++ b/dbfs.h
@@ -159,6 +159,7 @@ extern int dbfs_xattr_list(guint64 ino, void **buf_out, size_t *buflen_out);
extern int dbfs_read(guint64, guint64, size_t, void **);
extern int dbfs_write(guint64, guint64, const void *, size_t);
extern int dbfs_inode_resize(struct dbfs_inode *ino, guint64 new_size);
+extern int dbfs_rename(guint64, const char *, guint64, const char *);
/* libdbfs.c */
extern int dbfs_open(struct dbfs *, unsigned int, unsigned int, const char *);