* [PATCH -e2fsprogs 0/3] Fix portability issues on MacOS
@ 2026-04-03 4:03 Theodore Ts'o
2026-04-03 4:03 ` [PATCH 1/3] libsupport: fix portability issues with the bthread.c Theodore Ts'o
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Theodore Ts'o @ 2026-04-03 4:03 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Darrick J. Wong, Theodore Ts'o
The recent fuse2fs changes introduced some portability issues; fix
them so that e2fsprogs can build on MacOS and create a fuse2fs binary
that works on MacOS 26.3.1 using MacFuse.
Note: the f_opt_extent test is failing on Github Actions when testing
on MacOS. All of the tests are passing clean up my MacOS laptop. So
I'm not sure where the github action failure is coming from.
Theodore Ts'o (3):
libsupport: fix portability issues with the bthread.c
libsupport: add a portable get_thread_id() function
fuse2fs: fix build failure on systems which don't define EUCLEAN
configure | 18 ++++++++++++++++++
configure.ac | 3 +++
lib/config.h.in | 30 +++++++++++++++++++++---------
lib/support/Makefile.in | 13 +++++++++++--
lib/support/bthread.c | 12 ++++++++++--
lib/support/thread.c | 36 ++++++++++++++++++++++++++++++++++++
lib/support/thread.h | 5 +++++
misc/fuse2fs.c | 5 ++++-
8 files changed, 108 insertions(+), 14 deletions(-)
create mode 100644 lib/support/thread.c
create mode 100644 lib/support/thread.h
--
2.51.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] libsupport: fix portability issues with the bthread.c
2026-04-03 4:03 [PATCH -e2fsprogs 0/3] Fix portability issues on MacOS Theodore Ts'o
@ 2026-04-03 4:03 ` Theodore Ts'o
2026-04-03 4:16 ` Darrick J. Wong
2026-04-03 4:03 ` [PATCH 2/3] libsupport: add a portable get_thread_id() function Theodore Ts'o
2026-04-03 4:03 ` [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN Theodore Ts'o
2 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2026-04-03 4:03 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Darrick J. Wong, Theodore Ts'o
The function pthread_setname_np() is non-portable; that's what the
"np" means. In particular, on Mac systems, the function takes only a
single argument, while on most other systems which have the function,
it takes two arguments.
Also fix a problem where a 1-bit signed integer can only accept values
of 0 or -1. Change it to be a 1-bit unsigned integer, which can
accept values of 0 or 1. Clang will issue a warning if 1-bit signed
integer are used incorrectly, and fail with -Werror.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
configure | 6 ++++++
configure.ac | 1 +
lib/config.h.in | 24 +++++++++++++++---------
lib/support/bthread.c | 12 ++++++++++--
4 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/configure b/configure
index 4da5439fe..b9a82dcec 100755
--- a/configure
+++ b/configure
@@ -13887,6 +13887,12 @@ if test "x$ac_cv_func_pwrite64" = xyes
then :
printf "%s\n" "#define HAVE_PWRITE64 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "pthread_setname_np" "ac_cv_func_pthread_setname_np"
+if test "x$ac_cv_func_pthread_setname_np" = xyes
+then :
+ printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "qsort_r" "ac_cv_func_qsort_r"
if test "x$ac_cv_func_qsort_r" = xyes
diff --git a/configure.ac b/configure.ac
index ecef9df39..2473879fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1269,6 +1269,7 @@ AC_CHECK_FUNCS(m4_flatten([
pwrite
pread64
pwrite64
+ pthread_setname_np
qsort_r
secure_getenv
setmntent
diff --git a/lib/config.h.in b/lib/config.h.in
index 8ea7ec2b1..c6cbced5f 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -46,9 +46,6 @@
/* Define to the version of FUSE to use */
#undef FUSE_USE_VERSION
-/* Define to 1 if fuse supports cache_readdir */
-#undef HAVE_FUSE_CACHE_READDIR
-
/* Define to 1 if you have the 'add_key' function. */
#undef HAVE_ADD_KEY
@@ -73,9 +70,6 @@
/* Define to 1 if you have the BSD-style 'qsort_r' function. */
#undef HAVE_BSD_QSORT_R
-/* Define to 1 if PR_SET_IO_FLUSHER is present */
-#undef HAVE_PR_SET_IO_FLUSHER
-
/* Define to 1 if you have the Mac OS X function
CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
#undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
@@ -87,6 +81,9 @@
/* Define to 1 if you have the 'chflags' function. */
#undef HAVE_CHFLAGS
+/* Define to 1 if CLOCK_MONOTONIC is present */
+#undef HAVE_CLOCK_MONOTONIC
+
/* Define if the GNU dcgettext() function is already present or preinstalled.
*/
#undef HAVE_DCGETTEXT
@@ -136,9 +133,15 @@
/* Define to 1 if you have the 'fsync' function. */
#undef HAVE_FSYNC
+/* Define to 1 if FS_IOC_READ_VERITY_METADATA ioctl is available */
+#undef HAVE_FS_IOC_READ_VERITY_METADATA
+
/* Define to 1 if you have the 'ftruncate64' function. */
#undef HAVE_FTRUNCATE64
+/* Define to 1 if fuse supports cache_readdir */
+#undef HAVE_FUSE_CACHE_READDIR
+
/* Define to 1 if you have the <fuse.h> header file. */
#undef HAVE_FUSE_H
@@ -313,6 +316,9 @@
/* Define to 1 if you have the 'pread64' function. */
#undef HAVE_PREAD64
+/* Define to 1 if PR_SET_IO_FLUSHER is present */
+#undef HAVE_PR_SET_IO_FLUSHER
+
/* Define if you have POSIX threads libraries and header files. */
#undef HAVE_PTHREAD
@@ -322,6 +328,9 @@
/* Have PTHREAD_PRIO_INHERIT. */
#undef HAVE_PTHREAD_PRIO_INHERIT
+/* Define to 1 if you have the 'pthread_setname_np' function. */
+#undef HAVE_PTHREAD_SETNAME_NP
+
/* Define to 1 if you have the 'pwrite' function. */
#undef HAVE_PWRITE
@@ -699,7 +708,4 @@
/* Define to 1 on platforms where this makes time_t a 64-bit type. */
#undef __MINGW_USE_VC2005_COMPAT
-/* Define to 1 if CLOCK_MONOTONIC is present */
-#undef HAVE_CLOCK_MONOTONIC
-
#include <dirpaths.h>
diff --git a/lib/support/bthread.c b/lib/support/bthread.c
index 936ca0f0f..87eeb1b3d 100644
--- a/lib/support/bthread.c
+++ b/lib/support/bthread.c
@@ -9,6 +9,7 @@
* %End-Header%
*/
#include "config.h"
+#ifdef HAVE_PTHREAD
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
@@ -33,7 +34,7 @@ struct bthread {
bthread_fn_t fn;
void *data;
unsigned int period; /* seconds */
- int can_join:1;
+ unsigned int can_join:1;
};
/* Wait for a signal or for the periodic interval */
@@ -101,7 +102,13 @@ int bthread_create(const char *name, bthread_fn_t fn, void *data,
if (error)
goto out_cond;
+#ifdef HAVE_PTHREAD_SETNAME_NP
+#ifdef __APPLE__
+ pthread_setname_np(name);
+#else
pthread_setname_np(bt->thread, name);
+#endif
+#endif
*btp = bt;
return 0;
@@ -178,7 +185,7 @@ int bthread_cancel(struct bthread *bt)
/* Ask the thread to cancel itself and wait for it */
void bthread_stop(struct bthread *bt)
{
- int need_join = 0;
+ unsigned int need_join = 0;
pthread_mutex_lock(&bt->lock);
switch (bt->state) {
@@ -199,3 +206,4 @@ void bthread_stop(struct bthread *bt)
if (need_join)
pthread_join(bt->thread, NULL);
}
+#endif /* HAVE_PTHREAD */
--
2.51.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3] libsupport: add a portable get_thread_id() function
2026-04-03 4:03 [PATCH -e2fsprogs 0/3] Fix portability issues on MacOS Theodore Ts'o
2026-04-03 4:03 ` [PATCH 1/3] libsupport: fix portability issues with the bthread.c Theodore Ts'o
@ 2026-04-03 4:03 ` Theodore Ts'o
2026-04-03 4:17 ` Darrick J. Wong
2026-04-03 4:03 ` [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN Theodore Ts'o
2 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2026-04-03 4:03 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Darrick J. Wong, Theodore Ts'o
The gettid() system call is only available on Linux. So create a new
function, get_thread_id() which implements a number of different ways
of providing a thread id as an integer.
Use get_thread_id() instead of gettid() in fuse2fs.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
configure | 12 ++++++++++++
configure.ac | 2 ++
lib/config.h.in | 6 ++++++
lib/support/Makefile.in | 13 +++++++++++--
lib/support/thread.c | 36 ++++++++++++++++++++++++++++++++++++
lib/support/thread.h | 5 +++++
misc/fuse2fs.c | 3 ++-
7 files changed, 74 insertions(+), 3 deletions(-)
create mode 100644 lib/support/thread.c
create mode 100644 lib/support/thread.h
diff --git a/configure b/configure
index b9a82dcec..b04b31aff 100755
--- a/configure
+++ b/configure
@@ -13749,6 +13749,12 @@ if test "x$ac_cv_func_getrusage" = xyes
then :
printf "%s\n" "#define HAVE_GETRUSAGE 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "gettid" "ac_cv_func_gettid"
+if test "x$ac_cv_func_gettid" = xyes
+then :
+ printf "%s\n" "#define HAVE_GETTID 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "jrand48" "ac_cv_func_jrand48"
if test "x$ac_cv_func_jrand48" = xyes
@@ -13893,6 +13899,12 @@ if test "x$ac_cv_func_pthread_setname_np" = xyes
then :
printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "pthread_threadid_np" "ac_cv_func_pthread_threadid_np"
+if test "x$ac_cv_func_pthread_threadid_np" = xyes
+then :
+ printf "%s\n" "#define HAVE_PTHREAD_THREADID_NP 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "qsort_r" "ac_cv_func_qsort_r"
if test "x$ac_cv_func_qsort_r" = xyes
diff --git a/configure.ac b/configure.ac
index 2473879fd..4921f81f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1246,6 +1246,7 @@ AC_CHECK_FUNCS(m4_flatten([
getrandom
getrlimit
getrusage
+ gettid
jrand48
keyctl
llistxattr
@@ -1270,6 +1271,7 @@ AC_CHECK_FUNCS(m4_flatten([
pread64
pwrite64
pthread_setname_np
+ pthread_threadid_np
qsort_r
secure_getenv
setmntent
diff --git a/lib/config.h.in b/lib/config.h.in
index c6cbced5f..f129abfe7 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -181,6 +181,9 @@
/* Define if the GNU gettext() function is already present or preinstalled. */
#undef HAVE_GETTEXT
+/* Define to 1 if you have the 'gettid' function. */
+#undef HAVE_GETTID
+
/* Define to 1 if you have the GNU-style 'qsort_r' function. */
#undef HAVE_GNU_QSORT_R
@@ -331,6 +334,9 @@
/* Define to 1 if you have the 'pthread_setname_np' function. */
#undef HAVE_PTHREAD_SETNAME_NP
+/* Define to 1 if you have the 'pthread_threadid_np' function. */
+#undef HAVE_PTHREAD_THREADID_NP
+
/* Define to 1 if you have the 'pwrite' function. */
#undef HAVE_PWRITE
diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
index 6383816fd..9aac9cf00 100644
--- a/lib/support/Makefile.in
+++ b/lib/support/Makefile.in
@@ -25,6 +25,7 @@ OBJS= bthread.o \
quotaio.o \
quotaio_v2.o \
quotaio_tree.o \
+ thread.o \
dict.o \
devname.o
@@ -41,6 +42,7 @@ SRCS= $(srcdir)/argv_parse.c \
$(srcdir)/quotaio.c \
$(srcdir)/quotaio_tree.c \
$(srcdir)/quotaio_v2.c \
+ $(srcdir)/thread.c \
$(srcdir)/dict.c \
$(srcdir)/devname.c
@@ -81,10 +83,15 @@ test_cstring: $(srcdir)/cstring.c
$(Q) $(CC) -o test_cstring -DDEBUG_PROGRAM $(srcdir)/cstring.c \
$(ALL_CFLAGS)
+test_thread: $(srcdir)/thread.c
+ $(E) " CC $@"
+ $(Q) $(CC) -o test_thread -DDEBUG_PROGRAM $(srcdir)/thread.c \
+ $(ALL_CFLAGS)
+
clean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \
../libsupport.a ../libsupport_p.a $(SMANPAGES) \
- prof_err.c prof_err.h test_profile test_cstring
+ prof_err.c prof_err.h test_profile test_cstring test_thread
#fullcheck check:: tst_uuid
# LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_uuid
@@ -111,7 +118,7 @@ $(OBJS):
argv_parse.o: $(srcdir)/argv_parse.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/argv_parse.h
bthread.o: $(srcdir)/bthread.c $(top_builddir)/lib/config.h \
- $(srcdir)/bthread.h
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/bthread.h
cstring.o: $(srcdir)/cstring.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/cstring.h
mkquota.o: $(srcdir)/mkquota.c $(top_builddir)/lib/config.h \
@@ -183,6 +190,8 @@ quotaio_v2.o: $(srcdir)/quotaio_v2.c $(top_builddir)/lib/config.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
$(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/dqblk_v2.h \
$(srcdir)/quotaio_tree.h
+thread.o: $(srcdir)/thread.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/thread.h
dict.o: $(srcdir)/dict.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/dict.h
devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \
diff --git a/lib/support/thread.c b/lib/support/thread.c
new file mode 100644
index 000000000..a9a10940c
--- /dev/null
+++ b/lib/support/thread.c
@@ -0,0 +1,36 @@
+/*
+ * thread.c - utility functions for Posix threads
+ */
+
+#include "config.h"
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+#endif
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "support/thread.h"
+
+uint64_t get_thread_id(void)
+{
+#if defined(HAVE_GETTID)
+ return gettid();
+#elif defined(HAVE_PTHREAD_THREADID_NP)
+ uint64_t tid;
+
+ if (pthread_threadid_np(NULL, &tid))
+ return tid;
+#elif defined(HAVE_PTHREAD)
+ return (__u64)(uintptr_t) pthread_self();
+#endif
+ return getpid();
+}
+
+#ifdef DEBUG_PROGRAM
+int main(int argc, char **argv)
+{
+ printf("Thread id: %llu\n", get_thread_id());
+ return 0;
+}
+#endif
diff --git a/lib/support/thread.h b/lib/support/thread.h
new file mode 100644
index 000000000..9a7f5c9db
--- /dev/null
+++ b/lib/support/thread.h
@@ -0,0 +1,5 @@
+/*
+ * thread.h -- header file for thread utilities
+ */
+
+uint64_t get_thread_id(void);
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 0b43ec0fb..dfbc98636 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -48,6 +48,7 @@
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fsP.h"
#include "support/bthread.h"
+#include "support/thread.h"
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
# define FUSE_PLATFORM_OPTS ""
#else
@@ -148,7 +149,7 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
#define dbg_printf(fuse2fs, format, ...) \
while ((fuse2fs)->debug) { \
- printf("FUSE2FS (%s): tid=%d " format, (fuse2fs)->shortdev, gettid(), ##__VA_ARGS__); \
+ printf("FUSE2FS (%s): tid=%llu " format, (fuse2fs)->shortdev, get_thread_id(), ##__VA_ARGS__); \
fflush(stdout); \
break; \
}
--
2.51.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN
2026-04-03 4:03 [PATCH -e2fsprogs 0/3] Fix portability issues on MacOS Theodore Ts'o
2026-04-03 4:03 ` [PATCH 1/3] libsupport: fix portability issues with the bthread.c Theodore Ts'o
2026-04-03 4:03 ` [PATCH 2/3] libsupport: add a portable get_thread_id() function Theodore Ts'o
@ 2026-04-03 4:03 ` Theodore Ts'o
2026-04-03 4:18 ` Darrick J. Wong
2 siblings, 1 reply; 10+ messages in thread
From: Theodore Ts'o @ 2026-04-03 4:03 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Darrick J. Wong, Theodore Ts'o
MacOS doesn't have EUCLEAN, so we use EIO as the closest error code.
But then we need to avoid a compile error caused by a duplicate case
labels of EUCLEAN and EIO.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
misc/fuse2fs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index dfbc98636..94e289fab 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -5870,7 +5870,9 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
#ifdef EILSEQ
case EILSEQ:
#endif
+#if EUCLEAN != EIO
case EUCLEAN:
+#endif
/* these errnos usually denote corruption or persistence fail */
is_err = 1;
ret = -err;
--
2.51.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] libsupport: fix portability issues with the bthread.c
2026-04-03 4:03 ` [PATCH 1/3] libsupport: fix portability issues with the bthread.c Theodore Ts'o
@ 2026-04-03 4:16 ` Darrick J. Wong
2026-04-03 11:53 ` Theodore Tso
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2026-04-03 4:16 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
On Fri, Apr 03, 2026 at 12:03:26AM -0400, Theodore Ts'o wrote:
> The function pthread_setname_np() is non-portable; that's what the
> "np" means. In particular, on Mac systems, the function takes only a
> single argument, while on most other systems which have the function,
> it takes two arguments.
>
> Also fix a problem where a 1-bit signed integer can only accept values
> of 0 or -1. Change it to be a 1-bit unsigned integer, which can
> accept values of 0 or 1. Clang will issue a warning if 1-bit signed
> integer are used incorrectly, and fail with -Werror.
>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> configure | 6 ++++++
> configure.ac | 1 +
> lib/config.h.in | 24 +++++++++++++++---------
> lib/support/bthread.c | 12 ++++++++++--
> 4 files changed, 32 insertions(+), 11 deletions(-)
>
> diff --git a/configure b/configure
> index 4da5439fe..b9a82dcec 100755
> --- a/configure
> +++ b/configure
> @@ -13887,6 +13887,12 @@ if test "x$ac_cv_func_pwrite64" = xyes
> then :
> printf "%s\n" "#define HAVE_PWRITE64 1" >>confdefs.h
>
> +fi
> +ac_fn_c_check_func "$LINENO" "pthread_setname_np" "ac_cv_func_pthread_setname_np"
> +if test "x$ac_cv_func_pthread_setname_np" = xyes
> +then :
> + printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
> +
> fi
> ac_fn_c_check_func "$LINENO" "qsort_r" "ac_cv_func_qsort_r"
> if test "x$ac_cv_func_qsort_r" = xyes
> diff --git a/configure.ac b/configure.ac
> index ecef9df39..2473879fd 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1269,6 +1269,7 @@ AC_CHECK_FUNCS(m4_flatten([
> pwrite
> pread64
> pwrite64
> + pthread_setname_np
> qsort_r
> secure_getenv
> setmntent
> diff --git a/lib/config.h.in b/lib/config.h.in
> index 8ea7ec2b1..c6cbced5f 100644
> --- a/lib/config.h.in
> +++ b/lib/config.h.in
> @@ -46,9 +46,6 @@
> /* Define to the version of FUSE to use */
> #undef FUSE_USE_VERSION
>
> -/* Define to 1 if fuse supports cache_readdir */
> -#undef HAVE_FUSE_CACHE_READDIR
Huh, there's a lot of churn in this file. Do you have a magic script
somewhere that regenerates config.h.in?
I don't see any problems with this file's changes, but I could also not
scatter junk everywhere :)
> -
> /* Define to 1 if you have the 'add_key' function. */
> #undef HAVE_ADD_KEY
>
> @@ -73,9 +70,6 @@
> /* Define to 1 if you have the BSD-style 'qsort_r' function. */
> #undef HAVE_BSD_QSORT_R
>
> -/* Define to 1 if PR_SET_IO_FLUSHER is present */
> -#undef HAVE_PR_SET_IO_FLUSHER
> -
> /* Define to 1 if you have the Mac OS X function
> CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
> #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES
> @@ -87,6 +81,9 @@
> /* Define to 1 if you have the 'chflags' function. */
> #undef HAVE_CHFLAGS
>
> +/* Define to 1 if CLOCK_MONOTONIC is present */
> +#undef HAVE_CLOCK_MONOTONIC
> +
> /* Define if the GNU dcgettext() function is already present or preinstalled.
> */
> #undef HAVE_DCGETTEXT
> @@ -136,9 +133,15 @@
> /* Define to 1 if you have the 'fsync' function. */
> #undef HAVE_FSYNC
>
> +/* Define to 1 if FS_IOC_READ_VERITY_METADATA ioctl is available */
> +#undef HAVE_FS_IOC_READ_VERITY_METADATA
> +
> /* Define to 1 if you have the 'ftruncate64' function. */
> #undef HAVE_FTRUNCATE64
>
> +/* Define to 1 if fuse supports cache_readdir */
> +#undef HAVE_FUSE_CACHE_READDIR
> +
> /* Define to 1 if you have the <fuse.h> header file. */
> #undef HAVE_FUSE_H
>
> @@ -313,6 +316,9 @@
> /* Define to 1 if you have the 'pread64' function. */
> #undef HAVE_PREAD64
>
> +/* Define to 1 if PR_SET_IO_FLUSHER is present */
> +#undef HAVE_PR_SET_IO_FLUSHER
> +
> /* Define if you have POSIX threads libraries and header files. */
> #undef HAVE_PTHREAD
>
> @@ -322,6 +328,9 @@
> /* Have PTHREAD_PRIO_INHERIT. */
> #undef HAVE_PTHREAD_PRIO_INHERIT
>
> +/* Define to 1 if you have the 'pthread_setname_np' function. */
> +#undef HAVE_PTHREAD_SETNAME_NP
> +
> /* Define to 1 if you have the 'pwrite' function. */
> #undef HAVE_PWRITE
>
> @@ -699,7 +708,4 @@
> /* Define to 1 on platforms where this makes time_t a 64-bit type. */
> #undef __MINGW_USE_VC2005_COMPAT
>
> -/* Define to 1 if CLOCK_MONOTONIC is present */
> -#undef HAVE_CLOCK_MONOTONIC
> -
> #include <dirpaths.h>
> diff --git a/lib/support/bthread.c b/lib/support/bthread.c
> index 936ca0f0f..87eeb1b3d 100644
> --- a/lib/support/bthread.c
> +++ b/lib/support/bthread.c
> @@ -9,6 +9,7 @@
> * %End-Header%
> */
> #include "config.h"
> +#ifdef HAVE_PTHREAD
Hmmm if we don't have pthreads, then shouldn't bthread.h also exclude
all the function declarations ifndef HAVE_PTHREAD?
> #include <stdlib.h>
> #include <errno.h>
> #include <pthread.h>
> @@ -33,7 +34,7 @@ struct bthread {
> bthread_fn_t fn;
> void *data;
> unsigned int period; /* seconds */
> - int can_join:1;
> + unsigned int can_join:1;
That works, though I suppose you could change it to bool.
--D
> };
>
> /* Wait for a signal or for the periodic interval */
> @@ -101,7 +102,13 @@ int bthread_create(const char *name, bthread_fn_t fn, void *data,
> if (error)
> goto out_cond;
>
> +#ifdef HAVE_PTHREAD_SETNAME_NP
> +#ifdef __APPLE__
> + pthread_setname_np(name);
> +#else
> pthread_setname_np(bt->thread, name);
> +#endif
> +#endif
>
> *btp = bt;
> return 0;
> @@ -178,7 +185,7 @@ int bthread_cancel(struct bthread *bt)
> /* Ask the thread to cancel itself and wait for it */
> void bthread_stop(struct bthread *bt)
> {
> - int need_join = 0;
> + unsigned int need_join = 0;
>
> pthread_mutex_lock(&bt->lock);
> switch (bt->state) {
> @@ -199,3 +206,4 @@ void bthread_stop(struct bthread *bt)
> if (need_join)
> pthread_join(bt->thread, NULL);
> }
> +#endif /* HAVE_PTHREAD */
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] libsupport: add a portable get_thread_id() function
2026-04-03 4:03 ` [PATCH 2/3] libsupport: add a portable get_thread_id() function Theodore Ts'o
@ 2026-04-03 4:17 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2026-04-03 4:17 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
On Fri, Apr 03, 2026 at 12:03:27AM -0400, Theodore Ts'o wrote:
> The gettid() system call is only available on Linux. So create a new
> function, get_thread_id() which implements a number of different ways
> of providing a thread id as an integer.
>
> Use get_thread_id() instead of gettid() in fuse2fs.
>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> configure | 12 ++++++++++++
> configure.ac | 2 ++
> lib/config.h.in | 6 ++++++
> lib/support/Makefile.in | 13 +++++++++++--
> lib/support/thread.c | 36 ++++++++++++++++++++++++++++++++++++
> lib/support/thread.h | 5 +++++
> misc/fuse2fs.c | 3 ++-
> 7 files changed, 74 insertions(+), 3 deletions(-)
> create mode 100644 lib/support/thread.c
> create mode 100644 lib/support/thread.h
>
> diff --git a/configure b/configure
> index b9a82dcec..b04b31aff 100755
> --- a/configure
> +++ b/configure
> @@ -13749,6 +13749,12 @@ if test "x$ac_cv_func_getrusage" = xyes
> then :
> printf "%s\n" "#define HAVE_GETRUSAGE 1" >>confdefs.h
>
> +fi
> +ac_fn_c_check_func "$LINENO" "gettid" "ac_cv_func_gettid"
> +if test "x$ac_cv_func_gettid" = xyes
> +then :
> + printf "%s\n" "#define HAVE_GETTID 1" >>confdefs.h
> +
> fi
> ac_fn_c_check_func "$LINENO" "jrand48" "ac_cv_func_jrand48"
> if test "x$ac_cv_func_jrand48" = xyes
> @@ -13893,6 +13899,12 @@ if test "x$ac_cv_func_pthread_setname_np" = xyes
> then :
> printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
>
> +fi
> +ac_fn_c_check_func "$LINENO" "pthread_threadid_np" "ac_cv_func_pthread_threadid_np"
> +if test "x$ac_cv_func_pthread_threadid_np" = xyes
> +then :
> + printf "%s\n" "#define HAVE_PTHREAD_THREADID_NP 1" >>confdefs.h
> +
> fi
> ac_fn_c_check_func "$LINENO" "qsort_r" "ac_cv_func_qsort_r"
> if test "x$ac_cv_func_qsort_r" = xyes
> diff --git a/configure.ac b/configure.ac
> index 2473879fd..4921f81f7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1246,6 +1246,7 @@ AC_CHECK_FUNCS(m4_flatten([
> getrandom
> getrlimit
> getrusage
> + gettid
> jrand48
> keyctl
> llistxattr
> @@ -1270,6 +1271,7 @@ AC_CHECK_FUNCS(m4_flatten([
> pread64
> pwrite64
> pthread_setname_np
> + pthread_threadid_np
> qsort_r
> secure_getenv
> setmntent
> diff --git a/lib/config.h.in b/lib/config.h.in
> index c6cbced5f..f129abfe7 100644
> --- a/lib/config.h.in
> +++ b/lib/config.h.in
> @@ -181,6 +181,9 @@
> /* Define if the GNU gettext() function is already present or preinstalled. */
> #undef HAVE_GETTEXT
>
> +/* Define to 1 if you have the 'gettid' function. */
> +#undef HAVE_GETTID
> +
> /* Define to 1 if you have the GNU-style 'qsort_r' function. */
> #undef HAVE_GNU_QSORT_R
>
> @@ -331,6 +334,9 @@
> /* Define to 1 if you have the 'pthread_setname_np' function. */
> #undef HAVE_PTHREAD_SETNAME_NP
>
> +/* Define to 1 if you have the 'pthread_threadid_np' function. */
> +#undef HAVE_PTHREAD_THREADID_NP
> +
> /* Define to 1 if you have the 'pwrite' function. */
> #undef HAVE_PWRITE
>
> diff --git a/lib/support/Makefile.in b/lib/support/Makefile.in
> index 6383816fd..9aac9cf00 100644
> --- a/lib/support/Makefile.in
> +++ b/lib/support/Makefile.in
> @@ -25,6 +25,7 @@ OBJS= bthread.o \
> quotaio.o \
> quotaio_v2.o \
> quotaio_tree.o \
> + thread.o \
> dict.o \
> devname.o
>
> @@ -41,6 +42,7 @@ SRCS= $(srcdir)/argv_parse.c \
> $(srcdir)/quotaio.c \
> $(srcdir)/quotaio_tree.c \
> $(srcdir)/quotaio_v2.c \
> + $(srcdir)/thread.c \
> $(srcdir)/dict.c \
> $(srcdir)/devname.c
>
> @@ -81,10 +83,15 @@ test_cstring: $(srcdir)/cstring.c
> $(Q) $(CC) -o test_cstring -DDEBUG_PROGRAM $(srcdir)/cstring.c \
> $(ALL_CFLAGS)
>
> +test_thread: $(srcdir)/thread.c
> + $(E) " CC $@"
> + $(Q) $(CC) -o test_thread -DDEBUG_PROGRAM $(srcdir)/thread.c \
> + $(ALL_CFLAGS)
> +
> clean::
> $(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \
> ../libsupport.a ../libsupport_p.a $(SMANPAGES) \
> - prof_err.c prof_err.h test_profile test_cstring
> + prof_err.c prof_err.h test_profile test_cstring test_thread
>
> #fullcheck check:: tst_uuid
> # LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_uuid
> @@ -111,7 +118,7 @@ $(OBJS):
> argv_parse.o: $(srcdir)/argv_parse.c $(top_builddir)/lib/config.h \
> $(top_builddir)/lib/dirpaths.h $(srcdir)/argv_parse.h
> bthread.o: $(srcdir)/bthread.c $(top_builddir)/lib/config.h \
> - $(srcdir)/bthread.h
> + $(top_builddir)/lib/dirpaths.h $(srcdir)/bthread.h
> cstring.o: $(srcdir)/cstring.c $(top_builddir)/lib/config.h \
> $(top_builddir)/lib/dirpaths.h $(srcdir)/cstring.h
> mkquota.o: $(srcdir)/mkquota.c $(top_builddir)/lib/config.h \
> @@ -183,6 +190,8 @@ quotaio_v2.o: $(srcdir)/quotaio_v2.c $(top_builddir)/lib/config.h \
> $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
> $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/dqblk_v2.h \
> $(srcdir)/quotaio_tree.h
> +thread.o: $(srcdir)/thread.c $(top_builddir)/lib/config.h \
> + $(top_builddir)/lib/dirpaths.h $(srcdir)/thread.h
> dict.o: $(srcdir)/dict.c $(top_builddir)/lib/config.h \
> $(top_builddir)/lib/dirpaths.h $(srcdir)/dict.h
> devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \
> diff --git a/lib/support/thread.c b/lib/support/thread.c
> new file mode 100644
> index 000000000..a9a10940c
> --- /dev/null
> +++ b/lib/support/thread.c
> @@ -0,0 +1,36 @@
> +/*
> + * thread.c - utility functions for Posix threads
Should these new files have an explicit license specification?
Other than that,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> + */
> +
> +#include "config.h"
> +#ifdef HAVE_PTHREAD
> +#include <pthread.h>
> +#endif
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +
> +#include "support/thread.h"
> +
> +uint64_t get_thread_id(void)
> +{
> +#if defined(HAVE_GETTID)
> + return gettid();
> +#elif defined(HAVE_PTHREAD_THREADID_NP)
> + uint64_t tid;
> +
> + if (pthread_threadid_np(NULL, &tid))
> + return tid;
> +#elif defined(HAVE_PTHREAD)
> + return (__u64)(uintptr_t) pthread_self();
> +#endif
> + return getpid();
> +}
> +
> +#ifdef DEBUG_PROGRAM
> +int main(int argc, char **argv)
> +{
> + printf("Thread id: %llu\n", get_thread_id());
> + return 0;
> +}
> +#endif
> diff --git a/lib/support/thread.h b/lib/support/thread.h
> new file mode 100644
> index 000000000..9a7f5c9db
> --- /dev/null
> +++ b/lib/support/thread.h
> @@ -0,0 +1,5 @@
> +/*
> + * thread.h -- header file for thread utilities
> + */
> +
> +uint64_t get_thread_id(void);
> diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> index 0b43ec0fb..dfbc98636 100644
> --- a/misc/fuse2fs.c
> +++ b/misc/fuse2fs.c
> @@ -48,6 +48,7 @@
> #include "ext2fs/ext2_fs.h"
> #include "ext2fs/ext2fsP.h"
> #include "support/bthread.h"
> +#include "support/thread.h"
> #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
> # define FUSE_PLATFORM_OPTS ""
> #else
> @@ -148,7 +149,7 @@ static inline uint64_t round_down(uint64_t b, unsigned int align)
>
> #define dbg_printf(fuse2fs, format, ...) \
> while ((fuse2fs)->debug) { \
> - printf("FUSE2FS (%s): tid=%d " format, (fuse2fs)->shortdev, gettid(), ##__VA_ARGS__); \
> + printf("FUSE2FS (%s): tid=%llu " format, (fuse2fs)->shortdev, get_thread_id(), ##__VA_ARGS__); \
> fflush(stdout); \
> break; \
> }
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN
2026-04-03 4:03 ` [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN Theodore Ts'o
@ 2026-04-03 4:18 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2026-04-03 4:18 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
On Fri, Apr 03, 2026 at 12:03:28AM -0400, Theodore Ts'o wrote:
> MacOS doesn't have EUCLEAN, so we use EIO as the closest error code.
> But then we need to avoid a compile error caused by a duplicate case
> labels of EUCLEAN and EIO.
>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Looks good to me,
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
--D
> ---
> misc/fuse2fs.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> index dfbc98636..94e289fab 100644
> --- a/misc/fuse2fs.c
> +++ b/misc/fuse2fs.c
> @@ -5870,7 +5870,9 @@ static int __translate_error(ext2_filsys fs, ext2_ino_t ino, errcode_t err,
> #ifdef EILSEQ
> case EILSEQ:
> #endif
> +#if EUCLEAN != EIO
> case EUCLEAN:
> +#endif
> /* these errnos usually denote corruption or persistence fail */
> is_err = 1;
> ret = -err;
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] libsupport: fix portability issues with the bthread.c
2026-04-03 4:16 ` Darrick J. Wong
@ 2026-04-03 11:53 ` Theodore Tso
2026-04-03 15:15 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Theodore Tso @ 2026-04-03 11:53 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Ext4 Developers List
On Thu, Apr 02, 2026 at 09:16:24PM -0700, Darrick J. Wong wrote:
> > -/* Define to 1 if fuse supports cache_readdir */
> > -#undef HAVE_FUSE_CACHE_READDIR
>
> Huh, there's a lot of churn in this file. Do you have a magic script
> somewhere that regenerates config.h.in?
It's "autoheader". Whenver you add or remove tests to configure.ac,
you need to run "autoconf ; autoheader". If you don't run
"autoheader", then even if the autoconf's feature test enables some
new feature test, say HAVE_PR_SET_IO_FLUSHER, the feature won't
actually be enabled in the #ifdef.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] libsupport: fix portability issues with the bthread.c
2026-04-03 11:53 ` Theodore Tso
@ 2026-04-03 15:15 ` Darrick J. Wong
2026-04-03 21:00 ` Theodore Tso
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2026-04-03 15:15 UTC (permalink / raw)
To: Theodore Tso; +Cc: Ext4 Developers List
On Fri, Apr 03, 2026 at 07:53:13AM -0400, Theodore Tso wrote:
> On Thu, Apr 02, 2026 at 09:16:24PM -0700, Darrick J. Wong wrote:
> > > -/* Define to 1 if fuse supports cache_readdir */
> > > -#undef HAVE_FUSE_CACHE_READDIR
> >
> > Huh, there's a lot of churn in this file. Do you have a magic script
> > somewhere that regenerates config.h.in?
>
> It's "autoheader". Whenver you add or remove tests to configure.ac,
> you need to run "autoconf ; autoheader". If you don't run
> "autoheader", then even if the autoconf's feature test enables some
> new feature test, say HAVE_PR_SET_IO_FLUSHER, the feature won't
> actually be enabled in the #ifdef.
Aha! Thanks for that tip; I'll go fix my dev branch.
--D
> Cheers,
>
> - Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] libsupport: fix portability issues with the bthread.c
2026-04-03 15:15 ` Darrick J. Wong
@ 2026-04-03 21:00 ` Theodore Tso
0 siblings, 0 replies; 10+ messages in thread
From: Theodore Tso @ 2026-04-03 21:00 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Ext4 Developers List
On Fri, Apr 03, 2026 at 08:15:35AM -0700, Darrick J. Wong wrote:
> > It's "autoheader". Whenver you add or remove tests to configure.ac,
> > you need to run "autoconf ; autoheader". If you don't run
> > "autoheader", then even if the autoconf's feature test enables some
> > new feature test, say HAVE_PR_SET_IO_FLUSHER, the feature won't
> > actually be enabled in the #ifdef.
>
> Aha! Thanks for that tip; I'll go fix my dev branch.
Just to give more context, there are two ways that configure scripts
can pass the feature definitions to programs. One is via the command
line of the compiler. The problem with that is if you have dozens of
options like -DHAVE_PR_SET_IO_FLUSHER for every single compile, it
bloats the MAKELOG files and makes it hard to read, and eventually you
can run into the command-line length limits.
The other way is via a config.h file which is then #included in each
source file. But for *that* to work, the config.h.in file needs to
have a template for echo variable that can be #defined. And that's
what autoheader takes care of for you. Simpler projects that don't
use a config.h file and pass everything on the compiler's command line
don't need to use autoheader.
For a demonstration, try editing lib/config.h.in to remove the lines:
-/* Define to 1 if PR_SET_IO_FLUSHER is present */
-#undef HAVE_PR_SET_IO_FLUSHER
Then "rm lib/config.h" and run "./config.status", and examine
lib/config.h. You will see that HAVE_PR_SET_IO_FLUSHER is no longer
defined in the config.h file. Then run "autoheader", and then re-run
"./config.status", and you will see that HAVE_PR_SET_IO_FLUSHER is
properly defined.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-04-03 21:00 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 4:03 [PATCH -e2fsprogs 0/3] Fix portability issues on MacOS Theodore Ts'o
2026-04-03 4:03 ` [PATCH 1/3] libsupport: fix portability issues with the bthread.c Theodore Ts'o
2026-04-03 4:16 ` Darrick J. Wong
2026-04-03 11:53 ` Theodore Tso
2026-04-03 15:15 ` Darrick J. Wong
2026-04-03 21:00 ` Theodore Tso
2026-04-03 4:03 ` [PATCH 2/3] libsupport: add a portable get_thread_id() function Theodore Ts'o
2026-04-03 4:17 ` Darrick J. Wong
2026-04-03 4:03 ` [PATCH 3/3] fuse2fs: fix build failure on systems which don't define EUCLEAN Theodore Ts'o
2026-04-03 4:18 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox