atomic open+create added
diff --git a/lib/fuse.c b/lib/fuse.c
index 6b3b6ae..5dad478 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -994,6 +994,66 @@
reply_entry(req, &e, err);
}
+static void fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name,
+ mode_t mode, struct fuse_file_info *fi)
+{
+ struct fuse *f = req_fuse_prepare(req);
+ struct fuse_entry_param e;
+ char *path;
+ int err;
+
+ err = -ENOENT;
+ pthread_rwlock_rdlock(&f->tree_lock);
+ path = get_path_name(f, parent, name);
+ if (path != NULL) {
+ err = -ENOSYS;
+ if (f->op.create && f->op.getattr) {
+ err = f->op.create(path, mode, fi);
+ if (!err) {
+ if (f->flags & FUSE_DEBUG) {
+ printf("CREATE[%lu] flags: 0x%x %s\n", fi->fh, fi->flags,
+ path);
+ fflush(stdout);
+ }
+ err = lookup_path(f, parent, name, path, &e);
+ if (err) {
+ if (f->op.release)
+ f->op.release(path, fi);
+ } else if (!S_ISREG(e.attr.st_mode)) {
+ err = -EIO;
+ if (f->op.release)
+ f->op.release(path, fi);
+ forget_node(f, e.ino, 1);
+ }
+ }
+ }
+ }
+
+ if (!err) {
+ if (f->flags & FUSE_DIRECT_IO)
+ fi->direct_io = 1;
+ if (f->flags & FUSE_KERNEL_CACHE)
+ fi->keep_cache = 1;
+
+ pthread_mutex_lock(&f->lock);
+ if (fuse_reply_create(req, &e, fi) == -ENOENT) {
+ /* The open syscall was interrupted, so it must be cancelled */
+ if(f->op.release)
+ f->op.release(path, fi);
+ forget_node(f, e.ino, 1);
+ } else {
+ struct node *node = get_node(f, e.ino);
+ node->open_count ++;
+ }
+ pthread_mutex_unlock(&f->lock);
+ } else
+ reply_err(req, err);
+
+ if (path)
+ free(path);
+ pthread_rwlock_unlock(&f->tree_lock);
+}
+
static void fuse_open(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
@@ -1654,6 +1714,7 @@
.symlink = fuse_symlink,
.rename = fuse_rename,
.link = fuse_link,
+ .create = fuse_create,
.open = fuse_open,
.read = fuse_read,
.write = fuse_write,
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 22dc41d..9379968 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -70,6 +70,7 @@
case FUSE_RELEASEDIR: return "RELEASEDIR";
case FUSE_FSYNCDIR: return "FSYNCDIR";
case FUSE_ACCESS: return "ACCESS";
+ case FUSE_CREATE: return "CREATE";
default: return "???";
}
}
@@ -265,6 +266,20 @@
return send_reply_ok(req, &arg, sizeof(arg));
}
+int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
+ const struct fuse_file_info *f)
+{
+ struct {
+ struct fuse_entry_out e;
+ struct fuse_open_out o;
+ } arg;
+
+ memset(&arg, 0, sizeof(arg));
+ fill_entry(&arg.e, e);
+ fill_open(&arg.o, f);
+ return send_reply_ok(req, &arg, sizeof(arg));
+}
+
int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
double attr_timeout)
{
@@ -443,6 +458,20 @@
fuse_reply_err(req, ENOSYS);
}
+static void do_create(fuse_req_t req, fuse_ino_t nodeid,
+ struct fuse_open_in *arg)
+{
+ if (req->f->op.create) {
+ struct fuse_file_info fi;
+
+ memset(&fi, 0, sizeof(fi));
+ fi.flags = arg->flags;
+
+ req->f->op.create(req, nodeid, PARAM(arg), arg->mode, &fi);
+ } else
+ fuse_reply_err(req, ENOSYS);
+}
+
static void do_open(fuse_req_t req, fuse_ino_t nodeid,
struct fuse_open_in *arg)
{
@@ -825,6 +854,10 @@
do_access(req, in->nodeid, (struct fuse_access_in *) inarg);
break;
+ case FUSE_CREATE:
+ do_create(req, in->nodeid, (struct fuse_open_in *) inarg);
+ break;
+
default:
fuse_reply_err(req, ENOSYS);
}