example/passthrough: support fspacectl()

FreeBSD 14 introduced a new system call, fspacectl().
Currently, it supports one operation mode, SPACECTL_DEALLOC,
which is functionally equivalent to Linux fallocate() with
FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE flags.

fspacectl() calls with SPACECTL_DEALLOC is supported on FUSE
filesystems via FUSE_FALLOCATE with the aforementioned flags.

Signed-off-by: CismonX <admin@cismon.net>
This commit is contained in:
CismonX
2025-07-09 23:10:03 +08:00
committed by Bernd Schubert
parent 21a27e371f
commit fc9888e0b2
2 changed files with 14 additions and 1 deletions
+13
View File
@@ -50,6 +50,19 @@ static inline int do_fallocate(int fd, int mode, off_t offset, off_t length)
return -posix_fallocate(fd, offset, length);
#endif
#ifdef HAVE_FSPACECTL
// 0x3 == FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE
if (mode == 0x3) {
struct spacectl_range sr;
sr.r_offset = offset;
sr.r_len = length;
if (fspacectl(fd, SPACECTL_DEALLOC, &sr, 0, NULL) == -1)
return -errno;
return 0;
}
#endif
return -EOPNOTSUPP;
#endif // HAVE_FALLOCATE
}
+1 -1
View File
@@ -74,7 +74,7 @@ private_cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
# Test for presence of some functions
test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
'splice', 'vmsplice', 'posix_fallocate', 'fdatasync',
'utimensat', 'copy_file_range', 'fallocate' ]
'utimensat', 'copy_file_range', 'fallocate', 'fspacectl' ]
foreach func : test_funcs
private_cfg.set('HAVE_' + func.to_upper(),
cc.has_function(func, prefix: include_default, args: args_default))