From db5a1b6ae9d39614154590e5b8c62702a5230ca4 Mon Sep 17 00:00:00 2001 From: CismonX Date: Wed, 9 Jul 2025 23:01:05 +0800 Subject: example/passthrough: refactor fallocate Move fallocate implementation to passthrough_helpers.h, so that it could be reused by multiple passthrough examples. Signed-off-by: CismonX --- example/passthrough_helpers.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'example/passthrough_helpers.h') 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 -- cgit v1.2.3