aboutsummaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/passthrough.c9
-rw-r--r--example/passthrough_fh.c11
-rw-r--r--example/passthrough_helpers.h17
-rw-r--r--example/passthrough_hp.cc13
-rw-r--r--example/passthrough_ll.c16
5 files changed, 27 insertions, 39 deletions
diff --git a/example/passthrough.c b/example/passthrough.c
index a5ac4b3..7e5c9aa 100644
--- a/example/passthrough.c
+++ b/example/passthrough.c
@@ -399,7 +399,6 @@ static int xmp_fsync(const char *path, int isdatasync,
return 0;
}
-#ifdef HAVE_POSIX_FALLOCATE
static int xmp_fallocate(const char *path, int mode,
off_t offset, off_t length, struct fuse_file_info *fi)
{
@@ -408,9 +407,6 @@ static int xmp_fallocate(const char *path, int mode,
(void) fi;
- if (mode)
- return -EOPNOTSUPP;
-
if(fi == NULL)
fd = open(path, O_WRONLY);
else
@@ -419,13 +415,12 @@ static int xmp_fallocate(const char *path, int mode,
if (fd == -1)
return -errno;
- res = -posix_fallocate(fd, offset, length);
+ res = do_fallocate(fd, mode, offset, length);
if(fi == NULL)
close(fd);
return res;
}
-#endif
#ifdef HAVE_SETXATTR
/* xattr operations are optional and can safely be left unimplemented */
@@ -554,9 +549,7 @@ static const struct fuse_operations xmp_oper = {
.statfs = xmp_statfs,
.release = xmp_release,
.fsync = xmp_fsync,
-#ifdef HAVE_POSIX_FALLOCATE
.fallocate = xmp_fallocate,
-#endif
#ifdef HAVE_SETXATTR
.setxattr = xmp_setxattr,
.getxattr = xmp_getxattr,
diff --git a/example/passthrough_fh.c b/example/passthrough_fh.c
index 7bbdb70..6764554 100644
--- a/example/passthrough_fh.c
+++ b/example/passthrough_fh.c
@@ -47,6 +47,8 @@
#endif
#include <sys/file.h> /* flock(2) */
+#include "passthrough_helpers.h"
+
static void *xmp_init(struct fuse_conn_info *conn,
struct fuse_config *cfg)
{
@@ -514,18 +516,13 @@ static int xmp_fsync(const char *path, int isdatasync,
return 0;
}
-#ifdef HAVE_POSIX_FALLOCATE
static int xmp_fallocate(const char *path, int mode,
off_t offset, off_t length, struct fuse_file_info *fi)
{
(void) path;
- if (mode)
- return -EOPNOTSUPP;
-
- return -posix_fallocate(fi->fh, offset, length);
+ return do_fallocate(fi->fh, mode, offset, length);
}
-#endif
#ifdef HAVE_SETXATTR
/* xattr operations are optional and can safely be left unimplemented */
@@ -650,9 +647,7 @@ static const struct fuse_operations xmp_oper = {
.flush = xmp_flush,
.release = xmp_release,
.fsync = xmp_fsync,
-#ifdef HAVE_POSIX_FALLOCATE
.fallocate = xmp_fallocate,
-#endif
#ifdef HAVE_SETXATTR
.setxattr = xmp_setxattr,
.getxattr = xmp_getxattr,
diff --git a/example/passthrough_helpers.h b/example/passthrough_helpers.h
index 6b77c33..aca796a 100644
--- a/example/passthrough_helpers.h
+++ b/example/passthrough_helpers.h
@@ -23,6 +23,23 @@
* SUCH DAMAGE
*/
+static inline int do_fallocate(int fd, int mode, off_t offset, off_t length)
+{
+#ifdef HAVE_FALLOCATE
+ if (fallocate(fd, mode, offset, length) == -1)
+ return -errno;
+ return 0;
+#else // HAVE_FALLOCATE
+
+#ifdef HAVE_POSIX_FALLOCATE
+ if (mode == 0)
+ return -posix_fallocate(fd, offset, length);
+#endif
+
+ return -EOPNOTSUPP;
+#endif // HAVE_FALLOCATE
+}
+
/*
* Creates files on the underlying file system in response to a FUSE_MKNOD
* operation
diff --git a/example/passthrough_hp.cc b/example/passthrough_hp.cc
index cc6b7e8..a0bf0d5 100644
--- a/example/passthrough_hp.cc
+++ b/example/passthrough_hp.cc
@@ -79,6 +79,8 @@
#include <mutex>
#include <syslog.h>
+#include "passthrough_helpers.h"
+
using namespace std;
#define SFS_DEFAULT_THREADS "-1" // take libfuse value as default
@@ -1216,20 +1218,15 @@ static void sfs_statfs(fuse_req_t req, fuse_ino_t ino)
fuse_reply_statfs(req, &stbuf);
}
-#ifdef HAVE_POSIX_FALLOCATE
static void sfs_fallocate(fuse_req_t req, fuse_ino_t ino, int mode,
off_t offset, off_t length, fuse_file_info *fi)
{
(void)ino;
- if (mode) {
- fuse_reply_err(req, EOPNOTSUPP);
- return;
- }
- auto err = posix_fallocate(fi->fh, offset, length);
+ auto err = -do_fallocate(fi->fh, mode, offset, length);
+
fuse_reply_err(req, err);
}
-#endif
static void sfs_flock(fuse_req_t req, fuse_ino_t ino, fuse_file_info *fi,
int op)
@@ -1389,9 +1386,7 @@ static void assign_operations(fuse_lowlevel_ops &sfs_oper)
sfs_oper.read = sfs_read;
sfs_oper.write_buf = sfs_write_buf;
sfs_oper.statfs = sfs_statfs;
-#ifdef HAVE_POSIX_FALLOCATE
sfs_oper.fallocate = sfs_fallocate;
-#endif
sfs_oper.flock = sfs_flock;
#ifdef HAVE_SETXATTR
sfs_oper.setxattr = sfs_setxattr;
diff --git a/example/passthrough_ll.c b/example/passthrough_ll.c
index 59f43c5..9e027b4 100644
--- a/example/passthrough_ll.c
+++ b/example/passthrough_ll.c
@@ -1006,22 +1006,10 @@ static void lo_statfs(fuse_req_t req, fuse_ino_t ino)
static void lo_fallocate(fuse_req_t req, fuse_ino_t ino, int mode,
off_t offset, off_t length, struct fuse_file_info *fi)
{
- int err = EOPNOTSUPP;
+ int err;
(void) ino;
-#ifdef HAVE_FALLOCATE
- err = fallocate(fi->fh, mode, offset, length);
- if (err < 0)
- err = errno;
-
-#elif defined(HAVE_POSIX_FALLOCATE)
- if (mode) {
- fuse_reply_err(req, EOPNOTSUPP);
- return;
- }
-
- err = posix_fallocate(fi->fh, offset, length);
-#endif
+ err = -do_fallocate(fi->fh, mode, offset, length);
fuse_reply_err(req, err);
}