From 70388bb096a90ad8660d23fa109369f7f01e9045 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 25 Feb 2026 08:31:59 +0100 Subject: [PATCH] Use fuse3 This patch uses fuse3 instead of fuse2 in order to support afuse in Debian forky. A lot of the utility funcions use an additional parameter which is not used and ignored (fi). The rename function has an extra flags parameter which make it possible to not overwrite if a file exists or make the rename atomic. We return an error if the flags parameter is set, since neither is implemented. fuse_main takes an extra parameter for private data. Since we don't use that, we pass a zero. The extra parameter for the filler allows the kernel to prefill the values, since we don't use that, we pass a zero. utime was replaced by utimens which takes now a struct timespec tv[2] parameter instead of the old struct utimebuf *buf pointer. It also takes an extra parameter fi which is ignored, since it is not used in the implementation. In the utimens function the case PROC_PATH_PROXY_DIR is adopted to utimensat which was taken from the example documentation directory /usr/share/doc/libfuse3-dev/examples/passthrough_ll.c:278 Otherwise is unchanged. ftruncate and fgetattr callbacks are dropped due to being provided by fuse3. Signed-off-by: Thomas Glanzmann --- configure.ac | 4 ++-- src/afuse.c | 60 +++++++++++++++++++++++----------------------------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/configure.ac b/configure.ac index ef07d70..1fb6f36 100644 --- a/configure.ac +++ b/configure.ac @@ -15,8 +15,8 @@ AC_PROG_CC # Checks for libraries. export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH -PKG_CHECK_MODULES([FUSE], [fuse >= 2.3]) -CFLAGS="$CFLAGS -Wall -Wextra $FUSE_CFLAGS -DFUSE_USE_VERSION=25" +PKG_CHECK_MODULES([FUSE], [fuse3]) +CFLAGS="$CFLAGS -Wall -Wextra $FUSE_CFLAGS -DFUSE_USE_VERSION=31" LIBS="$FUSE_LIBS" # Check if we need to enable compatibility code for old FUSE versions diff --git a/src/afuse.c b/src/afuse.c index a0cc426..8f27dc5 100644 --- a/src/afuse.c +++ b/src/afuse.c @@ -19,7 +19,6 @@ #endif #include -#include #ifndef __USE_BSD // for mkdtemp #define __USE_BSD @@ -631,8 +630,9 @@ proc_result_t process_path(const char *path_in, char *path_out, char *root_name, return PROC_PATH_ROOT_DIR; } -static int afuse_getattr(const char *path, struct stat *stbuf) +static int afuse_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) { + (void) fi; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); int retval; @@ -822,7 +822,7 @@ int populate_root_dir(char *pop_cmd, struct list_t **dir_entry_listptr, } if (strlen(dir_entry) != 0) - filler(buf, dir_entry, NULL, 0); + filler(buf, dir_entry, NULL, 0, 0); } free(dir_entry); @@ -840,8 +840,10 @@ int populate_root_dir(char *pop_cmd, struct list_t **dir_entry_listptr, } static int afuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi, + enum fuse_readdir_flags flags) { + (void) flags; DIR *dp = get_dirp(fi); struct dirent *de; char *root_name = alloca(strlen(path)); @@ -857,8 +859,8 @@ static int afuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, break; case PROC_PATH_ROOT_DIR: - filler(buf, ".", NULL, 0); - filler(buf, "..", NULL, 0); + filler(buf, ".", NULL, 0, 0); + filler(buf, "..", NULL, 0, 0); insert_sorted_if_unique(&dir_entry_list, "."); insert_sorted_if_unique(&dir_entry_list, ".."); for (mount = mount_list; mount; mount = next) { @@ -870,7 +872,7 @@ static int afuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, if (insert_sorted_if_unique (&dir_entry_list, mount->root_name)) retval = -1; - filler(buf, mount->root_name, NULL, 0); + filler(buf, mount->root_name, NULL, 0, 0); } } populate_root_dir(user_options.populate_root_command, @@ -892,7 +894,7 @@ static int afuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; st.st_mode = de->d_type << 12; - if (filler(buf, de->d_name, &st, telldir(dp))) + if (filler(buf, de->d_name, &st, telldir(dp), 0)) break; } retval = 0; @@ -1107,8 +1109,10 @@ static int afuse_symlink(const char *from, const char *to) return retval; } -static int afuse_rename(const char *from, const char *to) +static int afuse_rename(const char *from, const char *to, unsigned int flags) { + if (flags) + return -EINVAL; char *root_name_from = alloca(strlen(from)); char *root_name_to = alloca(strlen(to)); char *real_from_path = alloca(max_path_out_len(from)); @@ -1214,8 +1218,9 @@ static int afuse_link(const char *from, const char *to) return retval; } -static int afuse_chmod(const char *path, mode_t mode) +static int afuse_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) { + (void) fi; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; @@ -1243,8 +1248,9 @@ static int afuse_chmod(const char *path, mode_t mode) return retval; } -static int afuse_chown(const char *path, uid_t uid, gid_t gid) +static int afuse_chown(const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi) { + (void) fi; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; @@ -1272,8 +1278,9 @@ static int afuse_chown(const char *path, uid_t uid, gid_t gid) return retval; } -static int afuse_truncate(const char *path, off_t size) +static int afuse_truncate(const char *path, off_t size, struct fuse_file_info *fi) { + (void) fi; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; @@ -1301,8 +1308,9 @@ static int afuse_truncate(const char *path, off_t size) return retval; } -static int afuse_utime(const char *path, struct utimbuf *buf) +static int afuse_utimens(const char *path, const struct timespec tv[2], struct fuse_file_info *fi) { + (void) fi; char *root_name = alloca(strlen(path)); char *real_path = alloca(max_path_out_len(path)); mount_list_t *mount; @@ -1322,7 +1330,7 @@ static int afuse_utime(const char *path, struct utimbuf *buf) break; } case PROC_PATH_PROXY_DIR: - retval = get_retval(utime(real_path, buf)); + retval = get_retval(utimensat(AT_FDCWD, real_path, tv, AT_SYMLINK_NOFOLLOW)); break; default: @@ -1472,13 +1480,6 @@ static int afuse_access(const char *path, int mask) return retval; } -static int afuse_ftruncate(const char *path, off_t size, - struct fuse_file_info *fi) -{ - (void)path; - return get_retval(ftruncate(fi->fh, size)); -} - static int afuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { @@ -1516,13 +1517,6 @@ static int afuse_create(const char *path, mode_t mode, return retval; } -static int afuse_fgetattr(const char *path, struct stat *stbuf, - struct fuse_file_info *fi) -{ - (void)path; - - return get_retval(fstat(fi->fh, stbuf)); -} #endif #if FUSE_VERSION >= 25 @@ -1736,7 +1730,7 @@ static struct fuse_operations afuse_oper = { .chmod = afuse_chmod, .chown = afuse_chown, .truncate = afuse_truncate, - .utime = afuse_utime, + .utimens = afuse_utimens, .open = afuse_open, .read = afuse_read, .write = afuse_write, @@ -1746,8 +1740,6 @@ static struct fuse_operations afuse_oper = { #if FUSE_VERSION >= 25 .access = afuse_access, .create = afuse_create, - .ftruncate = afuse_ftruncate, - .fgetattr = afuse_fgetattr, #endif .destroy = afuse_destroy, #ifdef HAVE_SETXATTR @@ -1838,7 +1830,7 @@ static int afuse_opt_proc(void *data, const char *arg, int key, case KEY_HELP: usage(outargs->argv[0]); fuse_opt_add_arg(outargs, "-ho"); - fuse_main(outargs->argc, outargs->argv, &afuse_oper); + fuse_main(outargs->argc, outargs->argv, &afuse_oper, NULL); exit(1); case KEY_FLUSHWRITES: @@ -1905,7 +1897,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "(Un)Mount command templates missing.\n\n"); usage(argv[0]); fuse_opt_add_arg(&args, "-ho"); - fuse_main(args.argc, args.argv, &afuse_oper); + fuse_main(args.argc, args.argv, &afuse_oper, NULL); return 1; } @@ -1932,5 +1924,5 @@ int main(int argc, char *argv[]) umask(0); // !!FIXME!! death by signal doesn't unmount fs - return fuse_main(args.argc, args.argv, &afuse_oper); + return fuse_main(args.argc, args.argv, &afuse_oper, NULL); } -- 2.51.0