diff options
author | CismonX <admin@cismon.net> | 2025-07-09 23:01:05 +0800 |
---|---|---|
committer | Bernd Schubert <bernd@bsbernd.com> | 2025-07-13 15:22:29 +0200 |
commit | db5a1b6ae9d39614154590e5b8c62702a5230ca4 (patch) | |
tree | c0685f8f67bfd301ec0eb417f0cf647bc692d64a /example/passthrough_helpers.h | |
parent | 4166f2eb97da4e25a516abee3d6fe13b9ed77bc6 (diff) | |
download | libfuse-db5a1b6ae9d39614154590e5b8c62702a5230ca4.tar.gz |
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 <admin@cismon.net>
Diffstat (limited to 'example/passthrough_helpers.h')
-rw-r--r-- | example/passthrough_helpers.h | 17 |
1 files changed, 17 insertions, 0 deletions
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 |