Skip to content

Commit 55020c2

Browse files
committed
Support the FUSE 3 build on macOS with macFUSE 5
macFUSE 5 ships a libfuse 3 whose operation signatures default to Darwin-specific types (struct fuse_darwin_attr, struct statfs, a Darwin directory filler). Define FUSE_DARWIN_ENABLE_EXTENSIONS=0 in ltfs_fuse_version.h so the upstream-compatible signatures are used; the library exports both symbol flavors. The macFUSE position argument of the xattr handlers exists only in the fuse2 API and the Darwin-extension mode, so the FUSE 3 build now uses the upstream xattr signatures (LTFS_XATTR_POSITION). Verified on macOS 26 (arm64) against the macFUSE 5.2.0 SDK (libfuse 3.18.2): autotools (--with-fuse2=no) and CMake (-DLTFS_WITH_FUSE2=OFF) both build without new warnings, link libfuse3.4.dylib, and the binaries run; parallel_direct_writes is detected. The macOS fuse2 builds and the Linux test suites (autotools make check and ctest, 14/14) are unaffected.
1 parent c37a6cf commit 55020c2

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ make install
201201
On Linux the build uses libfuse 3 (package `libfuse3-dev` on Debian/Ubuntu,
202202
`fuse3-devel` on Fedora/RHEL). Pass `--with-fuse2` to build against the
203203
legacy libfuse 2 API instead; macOS, FreeBSD, and NetBSD currently use the
204-
libfuse 2 API by default.
204+
libfuse 2 API by default. On macOS with macFUSE 5 or later, which ships a
205+
libfuse 3, the FUSE 3 build can be selected with `--with-fuse2=no`
206+
(autotools) or `-DLTFS_WITH_FUSE2=OFF` (CMake).
205207

206208
FUSE 3 builds negotiate request sizes up to 1 MiB (tunable with
207209
`-o max_write=<bytes>`), serve directory listings through readdirplus, and

src/libltfs/ltfs_fuse_version.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
* (default on Linux; --with-fuse2 selects the libfuse 2 API). */
5555
#ifdef HAVE_FUSE3
5656
#define FUSE_USE_VERSION 31
57+
/* macFUSE 5's libfuse3 defaults to Darwin-specific operation signatures
58+
* (struct fuse_darwin_attr, struct statfs, ...). Request the upstream-
59+
* compatible API instead; the library exports both symbol flavors. */
60+
#ifdef __APPLE__
61+
#define FUSE_DARWIN_ENABLE_EXTENSIONS 0
62+
#endif
5763
#else
5864
#define FUSE_USE_VERSION 26
5965
#endif

src/ltfs_fuse.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ static struct fuse_context *context;
104104
int ltfs_fuse_fgetattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi);
105105
int ltfs_fuse_ftruncate(const char *path, off_t length, struct fuse_file_info *fi);
106106

107+
/* The fuse2 macFUSE API adds a position argument to the xattr handlers; the
108+
* fuse3 build uses the upstream signatures (Darwin extensions disabled in
109+
* ltfs_fuse_version.h). */
110+
#if defined(__APPLE__) && !defined(HAVE_FUSE3)
111+
#define LTFS_XATTR_POSITION 1
112+
#endif
113+
107114
#if !defined(__APPLE__) && FUSE_VERSION > 27
108115
/* Per-open cache policy. With -o direct_io every read and write bypasses
109116
* the kernel page cache: requests arrive at the application's I/O size
@@ -1135,13 +1142,13 @@ int ltfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struc
11351142
return errormap_fuse_error(ret);
11361143
}
11371144

1138-
#ifdef __APPLE__
1145+
#ifdef LTFS_XATTR_POSITION
11391146
int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size,
11401147
int flags, uint32_t position)
11411148
#else
11421149
int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, size_t size,
11431150
int flags)
1144-
#endif /* __APPLE__ */
1151+
#endif /* LTFS_XATTR_POSITION */
11451152
{
11461153
struct ltfs_fuse_data *priv = fuse_get_context()->private_data;
11471154
ltfs_file_id id;
@@ -1155,14 +1162,14 @@ int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, si
11551162
* on OS X, and we have no resource forks
11561163
* TODO: is it correct to behave this way?
11571164
*/
1158-
#ifdef __APPLE__
1165+
#ifdef LTFS_XATTR_POSITION
11591166
if (position) {
11601167
/* Position argument must be zero */
11611168
ltfsmsg(LTFS_ERR, 14023E);
11621169
ltfs_request_trace(FUSE_REQ_EXIT(REQ_SETXATTR), -EINVAL, 0);
11631170
return -EINVAL;
11641171
}
1165-
#endif /* __APPLE__ */
1172+
#endif /* LTFS_XATTR_POSITION */
11661173

11671174
ret = ltfs_fsops_setxattr(path, name, value, size, flags, &id, priv->data);
11681175

@@ -1171,12 +1178,12 @@ int ltfs_fuse_setxattr(const char *path, const char *name, const char *value, si
11711178
return errormap_fuse_error(ret);
11721179
}
11731180

1174-
#ifdef __APPLE__
1181+
#ifdef LTFS_XATTR_POSITION
11751182
int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size,
11761183
uint32_t position)
11771184
#else
11781185
int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t size)
1179-
#endif /* __APPLE__ */
1186+
#endif /* LTFS_XATTR_POSITION */
11801187
{
11811188
struct ltfs_fuse_data *priv = fuse_get_context()->private_data;
11821189
ltfs_file_id id;
@@ -1190,7 +1197,7 @@ int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t s
11901197
* on OS X, and we have no resource forks
11911198
* TODO: is it correct to behave this way?
11921199
*/
1193-
#ifdef __APPLE__
1200+
#ifdef LTFS_XATTR_POSITION
11941201
if (position) {
11951202
/* Position argument must be zero */
11961203
ltfsmsg(LTFS_ERR, 14024E);
@@ -1204,7 +1211,7 @@ int ltfs_fuse_getxattr(const char *path, const char *name, char *value, size_t s
12041211
ltfs_request_trace(FUSE_REQ_EXIT(REQ_GETXATTR), -LTFS_NO_XATTR, 0);
12051212
return errormap_fuse_error(-LTFS_NO_XATTR);
12061213
}
1207-
#endif /* __APPLE__ */
1214+
#endif /* LTFS_XATTR_POSITION */
12081215

12091216
ret = ltfs_fsops_getxattr(path, name, value, size, &id, priv->data);
12101217

0 commit comments

Comments
 (0)