[PATCH 2/4] fuse2fs: wrap the fuse_set_feature_flag helper for older libfuse

Darrick J. Wong
2025-11-06T22:42:32Z

Create a compatibility wrapper for fuse_set_feature_flag if the libfuse
version is older than the one where that function was introduced (3.17).

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 51e6b3b1969d62..2468e7e1017d59 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1542,6 +1542,19 @@ static int fuse2fs_read_bitmaps(struct fuse2fs *ff)
return 0;
}

+#if FUSE_VERSION < FUSE_MAKE_VERSION(3, 17)
+static inline int fuse_set_feature_flag(struct fuse_conn_info *conn,
+ uint64_t flag)
+{
+ if (conn->capable & flag) {
+ conn->want |= flag;
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
static void *op_init(struct fuse_conn_info *conn
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
, struct fuse_config *cfg EXT2FS_ATTR((unused))
@@ -1566,14 +1579,14 @@ static void *op_init(struct fuse_conn_info *conn
fs = ff->fs;
dbg_printf(ff, "%s: dev=%s\n", __func__, fs->device_name);
#ifdef FUSE_CAP_IOCTL_DIR
- conn->want |= FUSE_CAP_IOCTL_DIR;
+ fuse_set_feature_flag(conn, FUSE_CAP_IOCTL_DIR);
#endif
#ifdef FUSE_CAP_POSIX_ACL
if (ff->acl)
- conn->want |= FUSE_CAP_POSIX_ACL;
+ fuse_set_feature_flag(conn, FUSE_CAP_POSIX_ACL);
#endif
#ifdef FUSE_CAP_CACHE_SYMLINKS
- conn->want |= FUSE_CAP_CACHE_SYMLINKS;
+ fuse_set_feature_flag(conn, FUSE_CAP_CACHE_SYMLINKS);
#endif
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
conn->time_gran = 1;
@@ -1593,6 +1606,19 @@ static void *op_init(struct fuse_conn_info *conn
*/
fuse2fs_mmp_start(ff);

+#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 17)
+ /*
+ * THIS MUST GO LAST!
+ *
+ * fuse_set_feature_flag in 3.17.0 has a strange bug: it sets feature
+ * flags in conn->want_ext, but not conn->want. Upon return to
+ * libfuse, the lower level library observes that want and want_ext
+ * have gotten out of sync, and refuses to mount. Therefore,
+ * synchronize the two. This bug went away in 3.17.3, but we're stuck
+ * with this forever because Debian trixie released with 3.17.2.
+ */
+ conn->want = conn->want_ext & 0xFFFFFFFF;
+#endif
return ff;
}