All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file
@ 2023-01-21 20:31 Eric Biggers
  2023-01-21 20:31 ` [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows Eric Biggers
                   ` (38 more replies)
  0 siblings, 39 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

The last patch of this series adds a workflow file for GitHub Actions
that builds and tests e2fsprogs on Ubuntu, macOS, and Windows.  It's
enforced that the build does not produce warnings with -Wall.

(For now, the Windows build is much more basic than the others; only
mke2fs is built, and the unit tests are not run.)

The workflow will run on pushes to any fork of e2fsprogs that has GitHub
Actions enabled.  I'm hoping that Ted will enable it for the "official"
fork at https://github.com/tytso/e2fsprogs, but anyone can use it in
their own fork too.  The results for this patch series are at
https://github.com/ebiggers/e2fsprogs/actions/runs/3976382057

As a prerequisite to actually getting everything to pass, patches 1-37
of this series fix a large number of miscellaneous issues, mainly
pertaining to warnings with -Wall or to the Windows build.

Some patches in this series I've already sent out individually.  This
series supersedes all my previous patches.

Eric Biggers (38):
  configure.ac: only use Windows I/O manager on native Windows
  configure.ac: disable tdb by default on Windows
  configure.ac: automatically add include/mingw/ headers
  configure: regenerate
  config/install-sh: update to latest version
  lib, misc: eliminate dependency on Winsock
  lib/blkid: remove 32-bit x86 byteswap assembly
  lib/blkid: fix unaligned access to hfs_mdb
  lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size()
  lib/blkid: suppress -Wunused-result warning in blkid_flush_cache()
  lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup()
  lib/e2p: fix a -Wunused-variable warning in getflags()
  lib/{e2p,ss}: remove manual declarations of errno
  lib/et: fix "unused variable" warnings when !HAVE_FCNTL
  lib/ext2fs: remove 32-bit x86 bitops assembly
  lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics()
  lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode()
  lib/ext2fs: fix a printf format specifier in file_test()
  lib/ext2fs: fix two compiler warnings in windows_io.c
  lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start()
  lib/{ext2fs,support}: fix 32-bit Windows build
  lib/ss: fix 'make install' by creating man1dir
  lib/support: remove unused label in get_devname()
  lib/support: clean up definition of flags_array
  lib/uuid: remove conflicting Windows implementation of gettimeofday()
  e2fsck: use real functions for kernel slab functions
  misc/create_inode: fix -Wunused-variable warnings in __populate_fs()
  misc/create_inode: simplify logic in scandir()
  misc/e4defrag: fix -Wstringop-truncation warnings
  misc/fuse2fs: avoid error-prone strncpy() pattern
  misc/mk_hugefiles: simplify get_partition_start()
  misc/mke2fs: fix Windows build
  misc/mke2fs: fix a -Wunused-variable warning in PRS()
  misc/tune2fs: fix setting fsuuid::fsu_len
  misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel()
  misc/util.c: enable MinGW alarm() when building for Windows
  resize2fs: remove unused variable from adjust_superblock()
  Add a configuration file for GitHub Actions

 .github/workflows/ci.yml      | 116 ++++++
 aclocal.m4                    | 180 +++++----
 config/install-sh             | 683 ++++++++++++++++++++++++----------
 configure                     | 105 ++++--
 configure.ac                  |  50 ++-
 e2fsck/jfs_user.h             |  62 ++-
 include/mingw/arpa/inet.h     |   5 +
 include/mingw/sys/sysmacros.h |   8 +-
 lib/blkid/Android.bp          |   1 -
 lib/blkid/devno.c             |  10 +
 lib/blkid/getsize.c           |   2 +-
 lib/blkid/probe.c             |  10 +-
 lib/blkid/probe.h             |  43 ---
 lib/blkid/save.c              |   8 +
 lib/config.h.in               | 100 ++++-
 lib/e2p/Android.bp            |   4 -
 lib/e2p/fgetversion.c         |   2 -
 lib/e2p/fsetversion.c         |   1 -
 lib/e2p/getflags.c            |   3 +-
 lib/e2p/getversion.c          |   1 -
 lib/e2p/setversion.c          |   1 -
 lib/et/Android.bp             |   3 -
 lib/et/error_message.c        |  10 +-
 lib/ext2fs/Android.bp         |   2 -
 lib/ext2fs/bitops.c           |  14 +-
 lib/ext2fs/bitops.h           |  97 -----
 lib/ext2fs/ext2_io.h          |   2 +
 lib/ext2fs/ext_attr.c         |   2 -
 lib/ext2fs/gen_bitmap64.c     |   6 +-
 lib/ext2fs/getsectsize.c      |  12 +-
 lib/ext2fs/inline_data.c      |   2 +-
 lib/ext2fs/jfs_compat.h       |   4 -
 lib/ext2fs/mmp.c              |   2 +-
 lib/ext2fs/windows_io.c       |  12 +-
 lib/ss/Makefile.in            |   5 +-
 lib/ss/execute_cmd.c          |   2 -
 lib/ss/help.c                 |   2 -
 lib/ss/pager.c                |   2 -
 lib/support/devname.c         |   1 -
 lib/support/plausible.c       |   7 +-
 lib/support/print_fs_flags.c  |  60 +--
 lib/uuid/gen_uuid.c           |  21 --
 misc/Android.bp               |   3 -
 misc/create_inode.c           |  36 +-
 misc/e4defrag.c               |  30 +-
 misc/fuse2fs.c                |   5 +-
 misc/mk_hugefiles.c           | 134 +------
 misc/mke2fs.c                 |  22 +-
 misc/tune2fs.c                |   7 +-
 misc/util.c                   |   5 +
 resize/resize2fs.c            |   4 -
 util/android_config.h         |   1 -
 util/subst.c                  |   4 +-
 53 files changed, 1102 insertions(+), 812 deletions(-)
 create mode 100644 .github/workflows/ci.yml
 create mode 100644 include/mingw/arpa/inet.h


base-commit: aad34909b6648579f42dade5af5b46821aa4d845
-- 
2.39.0


^ permalink raw reply	[flat|nested] 41+ messages in thread

* [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 02/38] configure.ac: disable tdb by default on Windows Eric Biggers
                   ` (37 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Cygwin and MSYS2 are UNIX-compatible platforms on top of Windows, so
they should use the UNIX I/O manager, not the Windows I/O manager.

(Note that "cygwin" was misspelled as "cigwin", so the code did not have
the intended effect anyway.)

Fixes: d1d44c146a5e ("ext2fs: compile the io implementation according to os")
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 78f71fd8e..5f440f1fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1826,7 +1826,7 @@ dnl Adjust the compiled files if we are on windows vs everywhere else
 dnl
 OS_IO_FILE=""
 [case "$host_os" in
-  cigwin*|mingw*|msys*)
+  mingw*)
     OS_IO_FILE=windows_io
   ;;
   *)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 02/38] configure.ac: disable tdb by default on Windows
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
  2023-01-21 20:31 ` [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 03/38] configure.ac: automatically add include/mingw/ headers Eric Biggers
                   ` (36 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

The tdb support does not build for Windows, due to the use of various
UNIX-isms, so disable it by default when building for Windows.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 configure.ac | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index 5f440f1fc..e3884db60 100644
--- a/configure.ac
+++ b/configure.ac
@@ -845,23 +845,39 @@ dnl
 AH_TEMPLATE([CONFIG_TDB], [Define to 1 to enable tdb support])
 AC_ARG_ENABLE([tdb],
 AS_HELP_STRING([--disable-tdb],[disable tdb support]),
+[
 if test "$enableval" = "no"
 then
 	AC_MSG_RESULT([Disabling tdb support])
-	TDB_CMT="#"
-	TDB_MAN_COMMENT='.\"'
+	CONFIG_TDB=0
 else
 	AC_MSG_RESULT([Enabling tdb support])
+	CONFIG_TDB=1
+fi
+]
+,
+[
+case "$host_os" in
+mingw*)
+	AC_MSG_RESULT([Disabling tdb support by default])
+	CONFIG_TDB=0
+	;;
+*)
+	AC_MSG_RESULT([Enabling tdb support by default])
+	CONFIG_TDB=1
+	;;
+esac
+]
+)
+if test "$CONFIG_TDB" = "1"
+then
 	AC_DEFINE(CONFIG_TDB, 1)
 	TDB_CMT=""
 	TDB_MAN_COMMENT=""
+else
+	TDB_CMT="#"
+	TDB_MAN_COMMENT='.\"'
 fi
-,
-AC_MSG_RESULT([Enabling mmp support by default])
-AC_DEFINE(CONFIG_TDB, 1)
-TDB_CMT=""
-TDB_MAN_COMMENT=""
-)
 AC_SUBST(TDB_CMT)
 AC_SUBST(TDB_MAN_COMMENT)
 dnl
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 03/38] configure.ac: automatically add include/mingw/ headers
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
  2023-01-21 20:31 ` [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows Eric Biggers
  2023-01-21 20:31 ` [PATCH 02/38] configure.ac: disable tdb by default on Windows Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 04/38] configure: regenerate Eric Biggers
                   ` (35 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Since the include/mingw/ directory needs to be on the include path when
building for Windows with MinGW, add it to INCLUDES automatically, and
AC_DEFINE the corresponding HAVE_*_H constants.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 configure.ac | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/configure.ac b/configure.ac
index e3884db60..d62d99dc8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1036,6 +1036,17 @@ AC_CHECK_HEADERS(m4_flatten([
 	sys/wait.h
 	sys/xattr.h
 ]))
+case "$host_os" in
+mingw*)
+	# The above checks only detect system headers, not the headers in
+	# ./include/mingw/, so explicitly define them to be available.
+	AC_DEFINE(HAVE_LINUX_TYPES_H, 1)
+	AC_DEFINE(HAVE_SYS_STAT_H, 1)
+	AC_DEFINE(HAVE_SYS_SYSMACROS_H, 1)
+	AC_DEFINE(HAVE_SYS_TYPES_H, 1)
+	AC_DEFINE(HAVE_UNISTD_H, 1)
+	;;
+esac
 dnl Check where to find a dd(1) that supports iflag=fullblock
 dnl and oflag=append
 AC_MSG_CHECKING([for a dd(1) program that supports iflag=fullblock])
@@ -1710,6 +1721,11 @@ fi
 if test -n "$WITH_DIET_LIBC" ; then
 	INCLUDES="$INCLUDES -D_REENTRANT"
 fi
+case "$host_os" in
+mingw*)
+	INCLUDES=$INCLUDES' -I$(top_srcdir)/include/mingw'
+	;;
+esac
 AC_SUBST(INCLUDES)
 dnl
 dnl Build CFLAGS
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 04/38] configure: regenerate
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (2 preceding siblings ...)
  2023-01-21 20:31 ` [PATCH 03/38] configure.ac: automatically add include/mingw/ headers Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 05/38] config/install-sh: update to latest version Eric Biggers
                   ` (34 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Run autoreconf.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 aclocal.m4      | 180 ++++++++++++++++++++++++++----------------------
 configure       | 105 +++++++++++++++++++++-------
 lib/config.h.in | 100 ++++++++++++++++++++++-----
 3 files changed, 262 insertions(+), 123 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index bd5778d57..af10b6afe 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -535,7 +535,7 @@ fi
 AC_LANG_POP
 ])dnl AX_PTHREAD
 
-# gettext.m4 serial 71 (gettext-0.20.2)
+# gettext.m4 serial 72 (gettext-0.21.1)
 dnl Copyright (C) 1995-2014, 2016, 2018-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -592,22 +592,22 @@ dnl
 AC_DEFUN([AM_GNU_GETTEXT],
 [
   dnl Argument checking.
-  ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [use-libtool], ,
+  m4_if([$1], [], , [m4_if([$1], [external], , [m4_if([$1], [use-libtool], ,
     [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
 ])])])])
-  ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old],
+  m4_if(m4_if([$1], [], [old])[]m4_if([$1], [no-libtool], [old]), [old],
     [errprint([ERROR: Use of AM_GNU_GETTEXT without [external] argument is no longer supported.
 ])])
-  ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
+  m4_if([$2], [], , [m4_if([$2], [need-ngettext], , [m4_if([$2], [need-formatstring-macros], ,
     [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
 ])])])])
   define([gt_included_intl],
-    ifelse([$1], [external], [no], [yes]))
+    m4_if([$1], [external], [no], [yes]))
   gt_NEEDS_INIT
   AM_GNU_GETTEXT_NEED([$2])
 
   AC_REQUIRE([AM_PO_SUBDIRS])dnl
-  ifelse(gt_included_intl, yes, [
+  m4_if(gt_included_intl, yes, [
     AC_REQUIRE([AM_INTL_SUBDIR])dnl
   ])
 
@@ -625,7 +625,7 @@ AC_DEFUN([AM_GNU_GETTEXT],
   dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
   dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
   dnl Since AC_PROVIDE_IFELSE is not documented, we avoid it.
-  ifelse(gt_included_intl, yes, , [
+  m4_if(gt_included_intl, yes, , [
     AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
   ])
 
@@ -635,7 +635,7 @@ AC_DEFUN([AM_GNU_GETTEXT],
   dnl Set USE_NLS.
   AC_REQUIRE([AM_NLS])
 
-  ifelse(gt_included_intl, yes, [
+  m4_if(gt_included_intl, yes, [
     BUILD_INCLUDED_LIBINTL=no
     USE_INCLUDED_LIBINTL=no
   ])
@@ -655,7 +655,7 @@ AC_DEFUN([AM_GNU_GETTEXT],
   dnl If we use NLS figure out what method
   if test "$USE_NLS" = "yes"; then
     gt_use_preinstalled_gnugettext=no
-    ifelse(gt_included_intl, yes, [
+    m4_if(gt_included_intl, yes, [
       AC_MSG_CHECKING([whether included gettext is requested])
       AC_ARG_WITH([included-gettext],
         [  --with-included-gettext use the GNU gettext library included here],
@@ -711,7 +711,7 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
 
         if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
           dnl Sometimes libintl requires libiconv, so first search for libiconv.
-          ifelse(gt_included_intl, yes, , [
+          m4_if(gt_included_intl, yes, , [
             AM_ICONV_LINK
           ])
           dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
@@ -798,7 +798,7 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
           INCINTL=
         fi
 
-    ifelse(gt_included_intl, yes, [
+    m4_if(gt_included_intl, yes, [
         if test "$gt_use_preinstalled_gnugettext" != "yes"; then
           dnl GNU gettext is not found in the C library.
           dnl Fall back on included GNU gettext library.
@@ -810,8 +810,8 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
         dnl Mark actions used to generate GNU NLS library.
         BUILD_INCLUDED_LIBINTL=yes
         USE_INCLUDED_LIBINTL=yes
-        LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
-        LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
+        LIBINTL="m4_if([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
+        LTLIBINTL="m4_if([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
         LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
       fi
 
@@ -878,7 +878,7 @@ return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
     POSUB=po
   fi
 
-  ifelse(gt_included_intl, yes, [
+  m4_if(gt_included_intl, yes, [
     dnl In GNU gettext we have to set BUILD_INCLUDED_LIBINTL to 'yes'
     dnl because some of the testsuite requires it.
     BUILD_INCLUDED_LIBINTL=yes
@@ -922,8 +922,8 @@ AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
 dnl Usage: AM_GNU_GETTEXT_REQUIRE_VERSION([gettext-version])
 AC_DEFUN([AM_GNU_GETTEXT_REQUIRE_VERSION], [])
 
-# host-cpu-c-abi.m4 serial 13
-dnl Copyright (C) 2002-2020 Free Software Foundation, Inc.
+# host-cpu-c-abi.m4 serial 15
+dnl Copyright (C) 2002-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -1135,7 +1135,7 @@ changequote([,])dnl
          # be generating 64-bit code.
          AC_COMPILE_IFELSE(
            [AC_LANG_SOURCE(
-              [[#if defined __powerpc64__ || defined _ARCH_PPC64
+              [[#if defined __powerpc64__ || defined __LP64__
                  int ok;
                 #else
                  error fail
@@ -1306,6 +1306,9 @@ EOF
 #ifndef __ia64__
 #undef __ia64__
 #endif
+#ifndef __loongarch64__
+#undef __loongarch64__
+#endif
 #ifndef __m68k__
 #undef __m68k__
 #endif
@@ -1529,7 +1532,7 @@ changequote([,])dnl
            # be generating 64-bit code.
            AC_COMPILE_IFELSE(
              [AC_LANG_SOURCE(
-                [[#if defined __powerpc64__ || defined _ARCH_PPC64
+                [[#if defined __powerpc64__ || defined __LP64__
                    int ok;
                   #else
                    error fail
@@ -1598,8 +1601,8 @@ changequote([,])dnl
   HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit"
 ])
 
-# iconv.m4 serial 21
-dnl Copyright (C) 2000-2002, 2007-2014, 2016-2020 Free Software Foundation,
+# iconv.m4 serial 24
+dnl Copyright (C) 2000-2002, 2007-2014, 2016-2022 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -1607,6 +1610,12 @@ dnl with or without modifications, as long as this notice is preserved.
 
 dnl From Bruno Haible.
 
+AC_PREREQ([2.64])
+
+dnl Note: AM_ICONV is documented in the GNU gettext manual
+dnl <https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html>.
+dnl Don't make changes that are incompatible with that documentation!
+
 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
 [
   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
@@ -1686,8 +1695,9 @@ AC_DEFUN([AM_ICONV_LINK],
 #endif
              ]],
              [[int result = 0;
-  /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
-     returns.  */
+  /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
+     successful returns.  This is even documented in
+     <https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
   {
     iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
     if (cd_utf8_to_88591 != (iconv_t)(-1))
@@ -1825,8 +1835,7 @@ AC_DEFUN([AM_ICONV_LINK],
   AC_SUBST([LTLIBICONV])
 ])
 
-dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
-dnl avoid warnings like
+dnl Define AM_ICONV using AC_DEFUN_ONCE, in order to avoid warnings like
 dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
 dnl This is tricky because of the way 'aclocal' is implemented:
 dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
@@ -1834,61 +1843,50 @@ dnl   Otherwise aclocal's initial scan pass would miss the macro definition.
 dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
 dnl   Otherwise aclocal would emit many "Use of uninitialized value $1"
 dnl   warnings.
-m4_define([gl_iconv_AC_DEFUN],
-  m4_version_prereq([2.64],
-    [[AC_DEFUN_ONCE(
-        [$1], [$2])]],
-    [m4_ifdef([gl_00GNULIB],
-       [[AC_DEFUN_ONCE(
-           [$1], [$2])]],
-       [[AC_DEFUN(
-           [$1], [$2])]])]))
-gl_iconv_AC_DEFUN([AM_ICONV],
+AC_DEFUN_ONCE([AM_ICONV],
 [
   AM_ICONV_LINK
   if test "$am_cv_func_iconv" = yes; then
-    AC_MSG_CHECKING([for iconv declaration])
-    AC_CACHE_VAL([am_cv_proto_iconv], [
-      AC_COMPILE_IFELSE(
-        [AC_LANG_PROGRAM(
-           [[
+    AC_CACHE_CHECK([whether iconv is compatible with its POSIX signature],
+      [gl_cv_iconv_nonconst],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[
 #include <stdlib.h>
 #include <iconv.h>
 extern
 #ifdef __cplusplus
 "C"
 #endif
-#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
-#else
-size_t iconv();
-#endif
-           ]],
-           [[]])],
-        [am_cv_proto_iconv_arg1=""],
-        [am_cv_proto_iconv_arg1="const"])
-      am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
-    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
-    AC_MSG_RESULT([
-         $am_cv_proto_iconv])
+            ]],
+            [[]])],
+         [gl_cv_iconv_nonconst=yes],
+         [gl_cv_iconv_nonconst=no])
+      ])
   else
     dnl When compiling GNU libiconv on a system that does not have iconv yet,
     dnl pick the POSIX compliant declaration without 'const'.
-    am_cv_proto_iconv_arg1=""
+    gl_cv_iconv_nonconst=yes
   fi
-  AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
+  if test $gl_cv_iconv_nonconst = yes; then
+    iconv_arg1=""
+  else
+    iconv_arg1="const"
+  fi
+  AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1],
     [Define as const if the declaration of iconv() needs const.])
   dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
   m4_ifdef([gl_ICONV_H_DEFAULTS],
     [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
-     if test -n "$am_cv_proto_iconv_arg1"; then
+     if test $gl_cv_iconv_nonconst != yes; then
        ICONV_CONST="const"
      fi
     ])
 ])
 
 # intlmacosx.m4 serial 8 (gettext-0.20.2)
-dnl Copyright (C) 2004-2014, 2016, 2019-2020 Free Software Foundation, Inc.
+dnl Copyright (C) 2004-2014, 2016, 2019-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -1953,8 +1951,8 @@ AC_DEFUN([gt_INTL_MACOSX],
   AC_SUBST([INTL_MACOSX_LIBS])
 ])
 
-# lib-ld.m4 serial 9
-dnl Copyright (C) 1996-2003, 2009-2020 Free Software Foundation, Inc.
+# lib-ld.m4 serial 10
+dnl Copyright (C) 1996-2003, 2009-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -2077,7 +2075,7 @@ else
       *-*-aix*)
         AC_COMPILE_IFELSE(
           [AC_LANG_SOURCE(
-             [[#if defined __powerpc64__ || defined _ARCH_PPC64
+             [[#if defined __powerpc64__ || defined __LP64__
                 int ok;
                #else
                 error fail
@@ -2122,8 +2120,8 @@ fi
 AC_LIB_PROG_LD_GNU
 ])
 
-# lib-link.m4 serial 31
-dnl Copyright (C) 2001-2020 Free Software Foundation, Inc.
+# lib-link.m4 serial 33
+dnl Copyright (C) 2001-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -2320,8 +2318,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
     eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
   ])
   AC_ARG_WITH(PACK[-prefix],
-[[  --with-]]PACK[[-prefix[=DIR]  search for ]PACKLIBS[ in DIR/include and DIR/lib
-  --without-]]PACK[[-prefix     don't search for ]PACKLIBS[ in includedir and libdir]],
+[[  --with-]]PACK[[-prefix[=DIR]  search for ]]PACKLIBS[[ in DIR/include and DIR/lib
+  --without-]]PACK[[-prefix     don't search for ]]PACKLIBS[[ in includedir and libdir]],
 [
     if test "X$withval" = "Xno"; then
       use_additional=no
@@ -2755,7 +2753,20 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
                     ;;
                   -l*)
                     dnl Handle this in the next round.
-                    names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                    dnl But on GNU systems, ignore -lc options, because
+                    dnl   - linking with libc is the default anyway,
+                    dnl   - linking with libc.a may produce an error
+                    dnl     "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie"
+                    dnl     or may produce an executable that always crashes, see
+                    dnl     <https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.
+                    dep=`echo "X$dep" | sed -e 's/^X-l//'`
+                    if test "X$dep" != Xc \
+                       || case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) false ;;
+                            *)                          true ;;
+                          esac; then
+                      names_next_round="$names_next_round $dep"
+                    fi
                     ;;
                   *.la)
                     dnl Handle this in the next round. Throw away the .la's
@@ -2923,8 +2934,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
   AC_SUBST([$1])
 ])
 
-# lib-prefix.m4 serial 17
-dnl Copyright (C) 2001-2005, 2008-2020 Free Software Foundation, Inc.
+# lib-prefix.m4 serial 20
+dnl Copyright (C) 2001-2005, 2008-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -3099,14 +3110,14 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
 
   AC_CACHE_CHECK([for ELF binary format], [gl_cv_elf],
     [AC_EGREP_CPP([Extensible Linking Format],
-       [#ifdef __ELF__
+       [#if defined __ELF__ || (defined __linux__ && defined __EDG__)
         Extensible Linking Format
         #endif
        ],
        [gl_cv_elf=yes],
        [gl_cv_elf=no])
-     ])
-  if test $gl_cv_elf; then
+    ])
+  if test $gl_cv_elf = yes; then
     # Extract the ELF class of a file (5th byte) in decimal.
     # Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
     if od -A x < /dev/null >/dev/null 2>/dev/null; then
@@ -3123,20 +3134,23 @@ AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
         echo
       }
     fi
+    # Use 'expr', not 'test', to compare the values of func_elfclass, because on
+    # Solaris 11 OpenIndiana and Solaris 11 OmniOS, the result is 001 or 002,
+    # not 1 or 2.
 changequote(,)dnl
     case $HOST_CPU_C_ABI_32BIT in
       yes)
         # 32-bit ABI.
         acl_is_expected_elfclass ()
         {
-          test "`func_elfclass | sed -e 's/[ 	]//g'`" = 1
+          expr "`func_elfclass | sed -e 's/[ 	]//g'`" = 1 > /dev/null
         }
         ;;
       no)
         # 64-bit ABI.
         acl_is_expected_elfclass ()
         {
-          test "`func_elfclass | sed -e 's/[ 	]//g'`" = 2
+          expr "`func_elfclass | sed -e 's/[ 	]//g'`" = 2 > /dev/null
         }
         ;;
       *)
@@ -3245,7 +3259,7 @@ changequote([,])dnl
 ])
 
 # nls.m4 serial 6 (gettext-0.20.2)
-dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014, 2016, 2019-2020 Free
+dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014, 2016, 2019-2022 Free
 dnl Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -3621,8 +3635,8 @@ AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
         [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
 ])dnl PKG_HAVE_DEFINE_WITH_MODULES
 
-# po.m4 serial 31 (gettext-0.20.2)
-dnl Copyright (C) 1995-2014, 2016, 2018-2020 Free Software Foundation, Inc.
+# po.m4 serial 32 (gettext-0.21.1)
+dnl Copyright (C) 1995-2014, 2016, 2018-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -3802,7 +3816,9 @@ changequote([,])dnl
                 #      presentlang can be used as a fallback for messages
                 #      which are not translated in the desiredlang catalog).
                 case "$desiredlang" in
-                  "$presentlang"*) useit=yes;;
+                  "$presentlang" | "$presentlang"_* | "$presentlang".* | "$presentlang"@*)
+                    useit=yes
+                    ;;
                 esac
               done
               if test $useit = yes; then
@@ -4002,7 +4018,9 @@ changequote([,])dnl
         #      presentlang can be used as a fallback for messages
         #      which are not translated in the desiredlang catalog).
         case "$desiredlang" in
-          "$presentlang"*) useit=yes;;
+          "$presentlang" | "$presentlang"_* | "$presentlang".* | "$presentlang"@*)
+            useit=yes
+            ;;
         esac
       done
       if test $useit = yes; then
@@ -4072,8 +4090,8 @@ AC_DEFUN([AM_XGETTEXT_OPTION],
   XGETTEXT_EXTRA_OPTIONS="$XGETTEXT_EXTRA_OPTIONS $1"
 ])
 
-# progtest.m4 serial 8 (gettext-0.20.2)
-dnl Copyright (C) 1996-2003, 2005, 2008-2020 Free Software Foundation, Inc.
+# progtest.m4 serial 9 (gettext-0.21.1)
+dnl Copyright (C) 1996-2003, 2005, 2008-2022 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -4090,7 +4108,7 @@ dnl They are *not* in the public domain.
 dnl Authors:
 dnl   Ulrich Drepper <drepper@cygnus.com>, 1996.
 
-AC_PREREQ([2.50])
+AC_PREREQ([2.53])
 
 # Search path for a program which passes the given test.
 
@@ -4135,7 +4153,7 @@ AC_CACHE_VAL([ac_cv_path_$1],
     ;;
   *)
     ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
-    for ac_dir in ifelse([$5], , $PATH, [$5]); do
+    for ac_dir in m4_if([$5], , $PATH, [$5]); do
       IFS="$ac_save_IFS"
       test -z "$ac_dir" && ac_dir=.
       for ac_exec_ext in '' $ac_executable_extensions; do
@@ -4151,12 +4169,12 @@ AC_CACHE_VAL([ac_cv_path_$1],
     IFS="$ac_save_IFS"
 dnl If no 4th arg is given, leave the cache variable unset,
 dnl so AC_PATH_PROGS will keep looking.
-ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
+m4_if([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
 ])dnl
     ;;
 esac])dnl
 $1="$ac_cv_path_$1"
-if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
+if test m4_if([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
   AC_MSG_RESULT([$][$1])
 else
   AC_MSG_RESULT([no])
diff --git a/configure b/configure
index 493542367..eaeb3d305 100755
--- a/configure
+++ b/configure
@@ -7956,31 +7956,47 @@ fi
 # Check whether --enable-tdb was given.
 if test ${enable_tdb+y}
 then :
-  enableval=$enable_tdb; if test "$enableval" = "no"
+  enableval=$enable_tdb;
+if test "$enableval" = "no"
 then
 	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Disabling tdb support" >&5
 printf "%s\n" "Disabling tdb support" >&6; }
-	TDB_CMT="#"
-	TDB_MAN_COMMENT='.\"'
+	CONFIG_TDB=0
 else
 	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Enabling tdb support" >&5
 printf "%s\n" "Enabling tdb support" >&6; }
-	printf "%s\n" "#define CONFIG_TDB 1" >>confdefs.h
-
-	TDB_CMT=""
-	TDB_MAN_COMMENT=""
+	CONFIG_TDB=1
 fi
 
+
 else $as_nop
-  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Enabling mmp support by default" >&5
-printf "%s\n" "Enabling mmp support by default" >&6; }
-printf "%s\n" "#define CONFIG_TDB 1" >>confdefs.h
 
-TDB_CMT=""
-TDB_MAN_COMMENT=""
+case "$host_os" in
+mingw*)
+	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Disabling tdb support by default" >&5
+printf "%s\n" "Disabling tdb support by default" >&6; }
+	CONFIG_TDB=0
+	;;
+*)
+	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Enabling tdb support by default" >&5
+printf "%s\n" "Enabling tdb support by default" >&6; }
+	CONFIG_TDB=1
+	;;
+esac
+
 
 fi
 
+if test "$CONFIG_TDB" = "1"
+then
+	printf "%s\n" "#define CONFIG_TDB 1" >>confdefs.h
+
+	TDB_CMT=""
+	TDB_MAN_COMMENT=""
+else
+	TDB_CMT="#"
+	TDB_MAN_COMMENT='.\"'
+fi
 
 
 
@@ -8660,7 +8676,7 @@ else $as_nop
       *-*-aix*)
         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#if defined __powerpc64__ || defined _ARCH_PPC64
+#if defined __powerpc64__ || defined __LP64__
                 int ok;
                #else
                 error fail
@@ -8951,7 +8967,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
            # be generating 64-bit code.
            cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#if defined __powerpc64__ || defined _ARCH_PPC64
+#if defined __powerpc64__ || defined __LP64__
                    int ok;
                   #else
                    error fail
@@ -9058,7 +9074,7 @@ then :
 else $as_nop
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#ifdef __ELF__
+#if defined __ELF__ || (defined __linux__ && defined __EDG__)
         Extensible Linking Format
         #endif
 
@@ -9076,7 +9092,7 @@ rm -rf conftest*
 fi
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $gl_cv_elf" >&5
 printf "%s\n" "$gl_cv_elf" >&6; }
-  if test $gl_cv_elf; then
+  if test $gl_cv_elf = yes; then
     # Extract the ELF class of a file (5th byte) in decimal.
     # Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
     if od -A x < /dev/null >/dev/null 2>/dev/null; then
@@ -9093,19 +9109,22 @@ printf "%s\n" "$gl_cv_elf" >&6; }
         echo
       }
     fi
+    # Use 'expr', not 'test', to compare the values of func_elfclass, because on
+    # Solaris 11 OpenIndiana and Solaris 11 OmniOS, the result is 001 or 002,
+    # not 1 or 2.
     case $HOST_CPU_C_ABI_32BIT in
       yes)
         # 32-bit ABI.
         acl_is_expected_elfclass ()
         {
-          test "`func_elfclass | sed -e 's/[ 	]//g'`" = 1
+          expr "`func_elfclass | sed -e 's/[ 	]//g'`" = 1 > /dev/null
         }
         ;;
       no)
         # 64-bit ABI.
         acl_is_expected_elfclass ()
         {
-          test "`func_elfclass | sed -e 's/[ 	]//g'`" = 2
+          expr "`func_elfclass | sed -e 's/[ 	]//g'`" = 2 > /dev/null
         }
         ;;
       *)
@@ -9635,7 +9654,14 @@ fi
                     fi
                     ;;
                   -l*)
-                                        names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                                                                                                                                                                dep=`echo "X$dep" | sed -e 's/^X-l//'`
+                    if test "X$dep" != Xc \
+                       || case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) false ;;
+                            *)                          true ;;
+                          esac; then
+                      names_next_round="$names_next_round $dep"
+                    fi
                     ;;
                   *.la)
                                                                                 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
@@ -9997,8 +10023,9 @@ int
 main (void)
 {
 int result = 0;
-  /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
-     returns.  */
+  /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
+     successful returns.  This is even documented in
+     <https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
   {
     iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
     if (cd_utf8_to_88591 != (iconv_t)(-1))
@@ -10580,7 +10607,14 @@ fi
                     fi
                     ;;
                   -l*)
-                                        names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
+                                                                                                                                                                dep=`echo "X$dep" | sed -e 's/^X-l//'`
+                    if test "X$dep" != Xc \
+                       || case $host_os in
+                            linux* | gnu* | k*bsd*-gnu) false ;;
+                            *)                          true ;;
+                          esac; then
+                      names_next_round="$names_next_round $dep"
+                    fi
                     ;;
                   *.la)
                                                                                 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
@@ -12117,6 +12151,22 @@ then :
 
 fi
 
+case "$host_os" in
+mingw*)
+	# The above checks only detect system headers, not the headers in
+	# ./include/mingw/, so explicitly define them to be available.
+	printf "%s\n" "#define HAVE_LINUX_TYPES_H 1" >>confdefs.h
+
+	printf "%s\n" "#define HAVE_SYS_STAT_H 1" >>confdefs.h
+
+	printf "%s\n" "#define HAVE_SYS_SYSMACROS_H 1" >>confdefs.h
+
+	printf "%s\n" "#define HAVE_SYS_TYPES_H 1" >>confdefs.h
+
+	printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h
+
+	;;
+esac
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a dd(1) program that supports iflag=fullblock" >&5
 printf %s "checking for a dd(1) program that supports iflag=fullblock... " >&6; }
 DD=
@@ -14963,6 +15013,11 @@ fi
 if test -n "$WITH_DIET_LIBC" ; then
 	INCLUDES="$INCLUDES -D_REENTRANT"
 fi
+case "$host_os" in
+mingw*)
+	INCLUDES=$INCLUDES' -I$(top_srcdir)/include/mingw'
+	;;
+esac
 
 if test $cross_compiling = no; then
    BUILD_CFLAGS="$CFLAGS $CPPFLAGS $INCLUDES -DHAVE_CONFIG_H"
@@ -15268,7 +15323,7 @@ fi
 
 OS_IO_FILE=""
 case "$host_os" in
-  cigwin*|mingw*|msys*)
+  mingw*)
     OS_IO_FILE=windows_io
   ;;
   *)
@@ -16692,7 +16747,9 @@ printf "%s\n" "$as_me: executing $ac_file commands" >&6;}
                 #      presentlang can be used as a fallback for messages
                 #      which are not translated in the desiredlang catalog).
                 case "$desiredlang" in
-                  "$presentlang"*) useit=yes;;
+                  "$presentlang" | "$presentlang"_* | "$presentlang".* | "$presentlang"@*)
+                    useit=yes
+                    ;;
                 esac
               done
               if test $useit = yes; then
diff --git a/lib/config.h.in b/lib/config.h.in
index b5856bb57..cba347b49 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -220,12 +220,12 @@
 /* Define to 1 if you have the `memalign' function. */
 #undef HAVE_MEMALIGN
 
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
 /* Define to 1 if you have the `mempcpy' function. */
 #undef HAVE_MEMPCPY
 
+/* Define to 1 if you have the <minix/config.h> header file. */
+#undef HAVE_MINIX_CONFIG_H
+
 /* Define to 1 if you have the `mmap' function. */
 #undef HAVE_MMAP
 
@@ -343,6 +343,9 @@
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
+
 /* Define to 1 if you have the <stdlib.h> header file. */
 #undef HAVE_STDLIB_H
 
@@ -478,6 +481,9 @@
 /* Define to 1 if you have the `vprintf' function. */
 #undef HAVE_VPRINTF
 
+/* Define to 1 if you have the <wchar.h> header file. */
+#undef HAVE_WCHAR_H
+
 /* Define to 1 if you have the `__secure_getenv' function. */
 #undef HAVE___SECURE_GETENV
 
@@ -524,7 +530,9 @@
 /* The size of `time_t', as computed by sizeof. */
 #undef SIZEOF_TIME_T
 
-/* Define to 1 if you have the ANSI C header files. */
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
 #undef STDC_HEADERS
 
 /* If the compiler supports a TLS storage class define it to that here */
@@ -534,21 +542,87 @@
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
+/* Enable general extensions on macOS.  */
+#ifndef _DARWIN_C_SOURCE
+# undef _DARWIN_C_SOURCE
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
 #endif
-/* Enable threading extensions on Solaris.  */
+/* Enable X/Open compliant socket functions that do not require linking
+   with -lxnet on HP-UX 11.11.  */
+#ifndef _HPUX_ALT_XOPEN_SOCKET_API
+# undef _HPUX_ALT_XOPEN_SOCKET_API
+#endif
+/* Identify the host operating system as Minix.
+   This macro does not affect the system headers' behavior.
+   A future release of Autoconf may stop defining this macro.  */
+#ifndef _MINIX
+# undef _MINIX
+#endif
+/* Enable general extensions on NetBSD.
+   Enable NetBSD compatibility extensions on Minix.  */
+#ifndef _NETBSD_SOURCE
+# undef _NETBSD_SOURCE
+#endif
+/* Enable OpenBSD compatibility extensions on NetBSD.
+   Oddly enough, this does nothing on OpenBSD.  */
+#ifndef _OPENBSD_SOURCE
+# undef _OPENBSD_SOURCE
+#endif
+/* Define to 1 if needed for POSIX-compatible behavior.  */
+#ifndef _POSIX_SOURCE
+# undef _POSIX_SOURCE
+#endif
+/* Define to 2 if needed for POSIX-compatible behavior.  */
+#ifndef _POSIX_1_SOURCE
+# undef _POSIX_1_SOURCE
+#endif
+/* Enable POSIX-compatible threading on Solaris.  */
 #ifndef _POSIX_PTHREAD_SEMANTICS
 # undef _POSIX_PTHREAD_SEMANTICS
 #endif
+/* Enable extensions specified by ISO/IEC TS 18661-5:2014.  */
+#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
+# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-1:2014.  */
+#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
+# undef __STDC_WANT_IEC_60559_BFP_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-2:2015.  */
+#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
+# undef __STDC_WANT_IEC_60559_DFP_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-4:2015.  */
+#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
+# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TS 18661-3:2015.  */
+#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
+# undef __STDC_WANT_IEC_60559_TYPES_EXT__
+#endif
+/* Enable extensions specified by ISO/IEC TR 24731-2:2010.  */
+#ifndef __STDC_WANT_LIB_EXT2__
+# undef __STDC_WANT_LIB_EXT2__
+#endif
+/* Enable extensions specified by ISO/IEC 24747:2009.  */
+#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
+# undef __STDC_WANT_MATH_SPEC_FUNCS__
+#endif
 /* Enable extensions on HP NonStop.  */
 #ifndef _TANDEM_SOURCE
 # undef _TANDEM_SOURCE
 #endif
-/* Enable general extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
+/* Enable X/Open extensions.  Define to 500 only if necessary
+   to make mbstate_t available.  */
+#ifndef _XOPEN_SOURCE
+# undef _XOPEN_SOURCE
 #endif
 
 
@@ -573,14 +647,4 @@
 /* Define to 1 if Apple Darwin libintl workaround is needed */
 #undef _INTL_REDIRECT_MACROS
 
-/* Define to 1 if on MINIX. */
-#undef _MINIX
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
-   this defined. */
-#undef _POSIX_1_SOURCE
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-#undef _POSIX_SOURCE
-
 #include <dirpaths.h>
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 05/38] config/install-sh: update to latest version
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (3 preceding siblings ...)
  2023-01-21 20:31 ` [PATCH 04/38] configure: regenerate Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 06/38] lib, misc: eliminate dependency on Winsock Eric Biggers
                   ` (33 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

The version of install-sh in the source tree is extremely old and
doesn't work when passed multiple path arguments, which breaks
'make install' on macOS.

Therefore, delete this file and run 'autoreconf -i' to update it to the
latest version.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 config/install-sh | 683 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 493 insertions(+), 190 deletions(-)

diff --git a/config/install-sh b/config/install-sh
index 89fc9b098..ec298b537 100755
--- a/config/install-sh
+++ b/config/install-sh
@@ -1,238 +1,541 @@
-#! /bin/sh
-#
+#!/bin/sh
 # install - install a program, script, or datafile
-# This comes from X11R5.
+
+scriptversion=2020-11-14.01; # UTC
+
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
+# later released in X11R6 (xc/config/util/install.sh) with the
+# following copyright and license.
+#
+# Copyright (C) 1994 X Consortium
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# Except as contained in this notice, the name of the X Consortium shall not
+# be used in advertising or otherwise to promote the sale, use or other deal-
+# ings in this Software without prior written authorization from the X Consor-
+# tium.
+#
+#
+# FSF changes to this file are in the public domain.
 #
 # Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
+# 'make' implicit rules from creating a file called install from it
 # when there is no Makefile.
 #
 # This script is compatible with the BSD install script, but was written
 # from scratch.
-#
 
+tab='	'
+nl='
+'
+IFS=" $tab$nl"
+
+# Set DOITPROG to "echo" to test this script.
+
+doit=${DOITPROG-}
+doit_exec=${doit:-exec}
 
-# set DOITPROG to echo to test this script
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
 
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
+chgrpprog=${CHGRPPROG-chgrp}
+chmodprog=${CHMODPROG-chmod}
+chownprog=${CHOWNPROG-chown}
+cmpprog=${CMPPROG-cmp}
+cpprog=${CPPROG-cp}
+mkdirprog=${MKDIRPROG-mkdir}
+mvprog=${MVPROG-mv}
+rmprog=${RMPROG-rm}
+stripprog=${STRIPPROG-strip}
 
+posix_mkdir=
 
-# put in absolute paths if you don't have them in your path; or use env. vars.
+# Desired mode of installed file.
+mode=0755
 
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
+# Create dirs (including intermediate dirs) using mode 755.
+# This is like GNU 'install' as of coreutils 8.32 (2020).
+mkdir_umask=22
 
-tranformbasename=""
-transform_arg=""
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
-chowncmd=""
-chgrpcmd=""
-stripcmd=""
+backupsuffix=
+chgrpcmd=
+chmodcmd=$chmodprog
+chowncmd=
+mvcmd=$mvprog
 rmcmd="$rmprog -f"
-mvcmd="$mvprog"
-src=""
-dst=""
-dir_arg=""
-
-while [ x"$1" != x ]; do
-    case $1 in
-	-c) instcmd="$cpprog"
-	    shift
-	    continue;;
-
-	-d) dir_arg=true
-	    shift
-	    continue;;
-
-	-m) chmodcmd="$chmodprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-o) chowncmd="$chownprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-g) chgrpcmd="$chgrpprog $2"
-	    shift
-	    shift
-	    continue;;
-
-	-s) stripcmd="$stripprog"
-	    shift
-	    continue;;
-
-	-t=*) transformarg=`echo $1 | sed 's/-t=//'`
-	    shift
-	    continue;;
-
-	-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-	    shift
-	    continue;;
-
-	*)  if [ x"$src" = x ]
-	    then
-		src=$1
-	    else
-		# this colon is to work around a 386BSD /bin/sh bug
-		:
-		dst=$1
-	    fi
-	    shift
-	    continue;;
-    esac
-done
+stripcmd=
 
-if [ x"$src" = x ]
-then
-	echo "install:	no input file specified"
-	exit 1
-else
-	true
-fi
+src=
+dst=
+dir_arg=
+dst_arg=
 
-if [ x"$dir_arg" != x ]; then
-	dst=$src
-	src=""
-	
-	if [ -d $dst ]; then
-		instcmd=:
-	else
-		instcmd=mkdir
-	fi
-else
+copy_on_change=false
+is_target_a_directory=possibly
 
-# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-# might cause directories to be created, which would be especially bad 
-# if $src (and thus $dsttmp) contains '*'.
+usage="\
+Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
 
-	if [ -f $src -o -d $src ]
-	then
-		true
-	else
-		echo "install:  $src does not exist"
-		exit 1
-	fi
-	
-	if [ x"$dst" = x ]
-	then
-		echo "install:	no destination specified"
-		exit 1
-	else
-		true
-	fi
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
 
-# If destination is a directory, append the input filename; if your system
-# does not like double slashes in filenames, you may need to add some logic
+Options:
+     --help     display this help and exit.
+     --version  display version info and exit.
 
-	if [ -d $dst ]
-	then
-		dst="$dst"/`basename $src`
-	else
-		true
-	fi
-fi
+  -c            (ignored)
+  -C            install only if different (preserve data modification time)
+  -d            create directories instead of installing files.
+  -g GROUP      $chgrpprog installed files to GROUP.
+  -m MODE       $chmodprog installed files to MODE.
+  -o USER       $chownprog installed files to USER.
+  -p            pass -p to $cpprog.
+  -s            $stripprog installed files.
+  -S SUFFIX     attempt to back up existing files, with suffix SUFFIX.
+  -t DIRECTORY  install into DIRECTORY.
+  -T            report an error if DSTFILE is a directory.
 
-## this sed command emulates the dirname command
-dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+Environment variables override the default commands:
+  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
+  RMPROG STRIPPROG
 
-# Make sure that the destination directory exists.
-#  this part is taken from Noah Friedman's mkinstalldirs script
+By default, rm is invoked with -f; when overridden with RMPROG,
+it's up to you to specify -f if you want it.
 
-# Skip lots of stat calls in the usual case.
-if [ ! -d "$dstdir" ]; then
-defaultIFS='	
-'
-IFS="${IFS-${defaultIFS}}"
+If -S is not specified, no backups are attempted.
 
-oIFS="${IFS}"
-# Some sh's can't handle IFS=/ for some reason.
-IFS='%'
-set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
-IFS="${oIFS}"
+Email bug reports to bug-automake@gnu.org.
+Automake home page: https://www.gnu.org/software/automake/
+"
 
-pathcomp=''
+while test $# -ne 0; do
+  case $1 in
+    -c) ;;
 
-while [ $# -ne 0 ] ; do
-	pathcomp="${pathcomp}${1}"
-	shift
+    -C) copy_on_change=true;;
 
-	if [ ! -d "${pathcomp}" ] ;
-        then
-		$mkdirprog "${pathcomp}"
-	else
-		true
-	fi
+    -d) dir_arg=true;;
 
-	pathcomp="${pathcomp}/"
-done
-fi
+    -g) chgrpcmd="$chgrpprog $2"
+        shift;;
 
-if [ x"$dir_arg" != x ]
-then
-	$doit $instcmd $dst &&
+    --help) echo "$usage"; exit $?;;
 
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
-else
+    -m) mode=$2
+        case $mode in
+          *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
+            echo "$0: invalid mode: $mode" >&2
+            exit 1;;
+        esac
+        shift;;
 
-# If we're going to rename the final executable, determine the name now.
+    -o) chowncmd="$chownprog $2"
+        shift;;
 
-	if [ x"$transformarg" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		dstfile=`basename $dst $transformbasename | 
-			sed $transformarg`$transformbasename
-	fi
+    -p) cpprog="$cpprog -p";;
 
-# don't allow the sed command to completely eliminate the filename
+    -s) stripcmd=$stripprog;;
 
-	if [ x"$dstfile" = x ] 
-	then
-		dstfile=`basename $dst`
-	else
-		true
-	fi
+    -S) backupsuffix="$2"
+        shift;;
 
-# Make a temp file name in the proper directory.
+    -t)
+        is_target_a_directory=always
+        dst_arg=$2
+        # Protect names problematic for 'test' and other utilities.
+        case $dst_arg in
+          -* | [=\(\)!]) dst_arg=./$dst_arg;;
+        esac
+        shift;;
 
-	dsttmp=$dstdir/#inst.$$#
+    -T) is_target_a_directory=never;;
 
-# Move or copy the file name to the temp name
+    --version) echo "$0 $scriptversion"; exit $?;;
 
-	$doit $instcmd $src $dsttmp &&
+    --) shift
+        break;;
 
-	trap "rm -f ${dsttmp}" 0 &&
+    -*) echo "$0: invalid option: $1" >&2
+        exit 1;;
 
-# and set any options; do chmod last to preserve setuid bits
+    *)  break;;
+  esac
+  shift
+done
 
-# If any of these fail, we abort the whole thing.  If we want to
-# ignore errors from any of these, just make sure not to ignore
-# errors from the above "$doit $instcmd $src $dsttmp" command.
+# We allow the use of options -d and -T together, by making -d
+# take the precedence; this is for compatibility with GNU install.
 
-	if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
-	if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
-	if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
-	if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+if test -n "$dir_arg"; then
+  if test -n "$dst_arg"; then
+    echo "$0: target directory not allowed when installing a directory." >&2
+    exit 1
+  fi
+fi
 
-# Now rename the file to the real destination.
+if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dst_arg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dst_arg"
+      shift # fnord
+    fi
+    shift # arg
+    dst_arg=$arg
+    # Protect names problematic for 'test' and other utilities.
+    case $dst_arg in
+      -* | [=\(\)!]) dst_arg=./$dst_arg;;
+    esac
+  done
+fi
 
-	$doit $rmcmd -f $dstdir/$dstfile &&
-	$doit $mvcmd $dsttmp $dstdir/$dstfile 
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
+  fi
+  # It's OK to call 'install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
 
-fi &&
+if test -z "$dir_arg"; then
+  if test $# -gt 1 || test "$is_target_a_directory" = always; then
+    if test ! -d "$dst_arg"; then
+      echo "$0: $dst_arg: Is not a directory." >&2
+      exit 1
+    fi
+  fi
+fi
+
+if test -z "$dir_arg"; then
+  do_exit='(exit $ret); exit $ret'
+  trap "ret=129; $do_exit" 1
+  trap "ret=130; $do_exit" 2
+  trap "ret=141; $do_exit" 13
+  trap "ret=143; $do_exit" 15
+
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
+
+    *[0-7])
+      if test -z "$stripcmd"; then
+        u_plus_rw=
+      else
+        u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+        u_plus_rw=
+      else
+        u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
 
+for src
+do
+  # Protect names problematic for 'test' and other utilities.
+  case $src in
+    -* | [=\(\)!]) src=./$src;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+    # Don't chown directories that already exist.
+    if test $dstdir_status = 0; then
+      chowncmd=""
+    fi
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
+    fi
+
+    if test -z "$dst_arg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
+    dst=$dst_arg
+
+    # If destination is a directory, append the input filename.
+    if test -d "$dst"; then
+      if test "$is_target_a_directory" = never; then
+        echo "$0: $dst_arg: Is a directory" >&2
+        exit 1
+      fi
+      dstdir=$dst
+      dstbase=`basename "$src"`
+      case $dst in
+	*/) dst=$dst$dstbase;;
+	*)  dst=$dst/$dstbase;;
+      esac
+      dstdir_status=0
+    else
+      dstdir=`dirname "$dst"`
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  case $dstdir in
+    */) dstdirslash=$dstdir;;
+    *)  dstdirslash=$dstdir/;;
+  esac
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+        # With -d, create the new directory with the user-specified mode.
+        # Otherwise, rely on $mkdir_umask.
+        if test -n "$dir_arg"; then
+          mkdir_mode=-m$mode
+        else
+          mkdir_mode=
+        fi
+
+        posix_mkdir=false
+	# The $RANDOM variable is not portable (e.g., dash).  Use it
+	# here however when possible just to lower collision chance.
+	tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+
+	trap '
+	  ret=$?
+	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
+	  exit $ret
+	' 0
+
+	# Because "mkdir -p" follows existing symlinks and we likely work
+	# directly in world-writeable /tmp, make sure that the '$tmpdir'
+	# directory is successfully created first before we actually test
+	# 'mkdir -p'.
+	if (umask $mkdir_umask &&
+	    $mkdirprog $mkdir_mode "$tmpdir" &&
+	    exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
+	then
+	  if test -z "$dir_arg" || {
+	       # Check for POSIX incompatibilities with -m.
+	       # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+	       # other-writable bit of parent directory when it shouldn't.
+	       # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+	       test_tmpdir="$tmpdir/a"
+	       ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
+	       case $ls_ld_tmpdir in
+		 d????-?r-*) different_mode=700;;
+		 d????-?--*) different_mode=755;;
+		 *) false;;
+	       esac &&
+	       $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
+		 ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
+		 test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+	       }
+	     }
+	  then posix_mkdir=:
+	  fi
+	  rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
+	else
+	  # Remove any dirs left behind by ancient mkdir implementations.
+	  rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
+	fi
+	trap '' 0;;
+    esac
+
+    if
+      $posix_mkdir && (
+        umask $mkdir_umask &&
+        $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+        /*) prefix='/';;
+        [-=\(\)!]*) prefix='./';;
+        *)  prefix='';;
+      esac
+
+      oIFS=$IFS
+      IFS=/
+      set -f
+      set fnord $dstdir
+      shift
+      set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+        test X"$d" = X && continue
+
+        prefix=$prefix$d
+        if test -d "$prefix"; then
+          prefixes=
+        else
+          if $posix_mkdir; then
+            (umask $mkdir_umask &&
+             $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+            # Don't fail if two instances are running concurrently.
+            test -d "$prefix" || exit 1
+          else
+            case $prefix in
+              *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+              *) qprefix=$prefix;;
+            esac
+            prefixes="$prefixes '$qprefix'"
+          fi
+        fi
+        prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+        # Don't fail if two instances are running concurrently.
+        (umask $mkdir_umask &&
+         eval "\$doit_exec \$mkdirprog $prefixes") ||
+          test -d "$dstdir" || exit 1
+        obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=${dstdirslash}_inst.$$_
+    rmtmp=${dstdirslash}_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask &&
+     { test -z "$stripcmd" || {
+	 # Create $dsttmp read-write so that cp doesn't create it read-only,
+	 # which would cause strip to fail.
+	 if test -z "$doit"; then
+	   : >"$dsttmp" # No need to fork-exec 'touch'.
+	 else
+	   $doit touch "$dsttmp"
+	 fi
+       }
+     } &&
+     $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
+    { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+    { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # If -C, don't bother to copy if it wouldn't change the file.
+    if $copy_on_change &&
+       old=`LC_ALL=C ls -dlL "$dst"     2>/dev/null` &&
+       new=`LC_ALL=C ls -dlL "$dsttmp"  2>/dev/null` &&
+       set -f &&
+       set X $old && old=:$2:$4:$5:$6 &&
+       set X $new && new=:$2:$4:$5:$6 &&
+       set +f &&
+       test "$old" = "$new" &&
+       $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
+    then
+      rm -f "$dsttmp"
+    else
+      # If $backupsuffix is set, and the file being installed
+      # already exists, attempt a backup.  Don't worry if it fails,
+      # e.g., if mv doesn't support -f.
+      if test -n "$backupsuffix" && test -f "$dst"; then
+        $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
+      fi
+
+      # Rename the file to the real destination.
+      $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
+
+      # The rename failed, perhaps because mv can't rename something else
+      # to itself, or perhaps because mv is so ancient that it does not
+      # support -f.
+      {
+        # Now remove or move aside any old file at destination location.
+        # We try this two ways since rm can't unlink itself on some
+        # systems and the destination file might be busy for other
+        # reasons.  In this case, the final cleanup might fail but the new
+        # file should still install successfully.
+        {
+          test ! -f "$dst" ||
+          $doit $rmcmd "$dst" 2>/dev/null ||
+          { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
+            { $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
+          } ||
+          { echo "$0: cannot unlink or rename $dst" >&2
+            (exit 1); exit 1
+          }
+        } &&
+
+        # Now rename the file to the real destination.
+        $doit $mvcmd "$dsttmp" "$dst"
+      }
+    fi || exit 1
+
+    trap '' 0
+  fi
+done
 
-exit 0
+# Local variables:
+# eval: (add-hook 'before-save-hook 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC0"
+# time-stamp-end: "; # UTC"
+# End:
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 06/38] lib, misc: eliminate dependency on Winsock
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (4 preceding siblings ...)
  2023-01-21 20:31 ` [PATCH 05/38] config/install-sh: update to latest version Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-21 20:31 ` [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly Eric Biggers
                   ` (32 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Currently Windows builds of e2fsprogs rely on the Windows Socket API
(Winsock) to provide htonl() and ntohl().  For this to actually work,
though, HAVE_WINSOCK_H needs to be defined, and the binaries need to be
linked to -lws2_32.  The Android.bp files do this; however, the
autotools-based build system does not.

Since htonl() and ntohl() are trivial, let's instead just add a file
include/mingw/arpa/inet.h with definitions for these.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 include/mingw/arpa/inet.h | 5 +++++
 lib/e2p/Android.bp        | 4 ----
 lib/ext2fs/Android.bp     | 2 --
 lib/ext2fs/jfs_compat.h   | 4 ----
 misc/Android.bp           | 1 -
 util/android_config.h     | 1 -
 6 files changed, 5 insertions(+), 12 deletions(-)
 create mode 100644 include/mingw/arpa/inet.h

diff --git a/include/mingw/arpa/inet.h b/include/mingw/arpa/inet.h
new file mode 100644
index 000000000..55dfa3691
--- /dev/null
+++ b/include/mingw/arpa/inet.h
@@ -0,0 +1,5 @@
+#pragma once
+
+/* Windows is always little endian. */
+#define htonl	__builtin_bswap32
+#define ntohl	__builtin_bswap32
diff --git a/lib/e2p/Android.bp b/lib/e2p/Android.bp
index 6f0620af0..050d869b3 100644
--- a/lib/e2p/Android.bp
+++ b/lib/e2p/Android.bp
@@ -59,10 +59,6 @@ cc_library {
                 "-Wno-unused-variable",
                 "-Wno-error=typedef-redefinition",
             ],
-
-            host_ldlibs: [
-                "-lws2_32",
-            ],
         },
     },
 
diff --git a/lib/ext2fs/Android.bp b/lib/ext2fs/Android.bp
index 365ca709f..eb4482d79 100644
--- a/lib/ext2fs/Android.bp
+++ b/lib/ext2fs/Android.bp
@@ -126,8 +126,6 @@ cc_library {
                 "-Wno-unused-variable",
                 "-Wno-error=typedef-redefinition",
             ],
-
-            host_ldlibs: ["-lws2_32"],
         },
     },
 
diff --git a/lib/ext2fs/jfs_compat.h b/lib/ext2fs/jfs_compat.h
index e11cf494e..0e96b56c1 100644
--- a/lib/ext2fs/jfs_compat.h
+++ b/lib/ext2fs/jfs_compat.h
@@ -7,11 +7,7 @@
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
-#ifdef HAVE_WINSOCK_H
-#include <winsock.h>
-#else
 #include <arpa/inet.h>
-#endif
 #include <stdbool.h>
 
 #define printk printf
diff --git a/misc/Android.bp b/misc/Android.bp
index 78e18e420..2baeac2ad 100644
--- a/misc/Android.bp
+++ b/misc/Android.bp
@@ -91,7 +91,6 @@ cc_binary {
                 "-Wno-error"
             ],
             ldflags: ["-static"],
-            host_ldlibs: ["-lws2_32"],
             enabled: true
         },
         android: {
diff --git a/util/android_config.h b/util/android_config.h
index 6ac16fec1..90b8f8a8f 100644
--- a/util/android_config.h
+++ b/util/android_config.h
@@ -36,7 +36,6 @@
 
 #if defined(_WIN32)
 # define HAVE_LINUX_TYPES_H 1
-# define HAVE_WINSOCK_H 1
 #endif
 #if defined(__APPLE__) || defined(__linux__)
 # define HAVE_FCNTL 1
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (5 preceding siblings ...)
  2023-01-21 20:31 ` [PATCH 06/38] lib, misc: eliminate dependency on Winsock Eric Biggers
@ 2023-01-21 20:31 ` Eric Biggers
  2023-01-24 18:21   ` Andreas Dilger
  2023-01-21 20:32 ` [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb Eric Biggers
                   ` (31 subsequent siblings)
  38 siblings, 1 reply; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:31 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

libblkid contains 32-bit x86 assembly language implementations of 16-bit
and 32-bit byteswaps.  However, modern compilers can easily generate the
bswap instruction automatically from the corresponding C expression.
And no one ever bothered to add assembly for x86_64 or other
architectures, anyway.  So let's just remove this outdated code, which
was maybe useful in the 90s, but is no longer useful.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/blkid/probe.h | 43 -------------------------------------------
 1 file changed, 43 deletions(-)

diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h
index dea4081d0..063a5b5c0 100644
--- a/lib/blkid/probe.h
+++ b/lib/blkid/probe.h
@@ -814,46 +814,6 @@ struct exfat_entry_label {
 #define _INLINE_ static inline
 #endif
 
-static __u16 blkid_swab16(__u16 val);
-static __u32 blkid_swab32(__u32 val);
-static __u64 blkid_swab64(__u64 val);
-
-#if ((defined __GNUC__) && \
-     (defined(__i386__) || defined(__i486__) || defined(__i586__)))
-
-#define _BLKID_HAVE_ASM_BITOPS_
-
-_INLINE_ __u32 blkid_swab32(__u32 val)
-{
-#ifdef EXT2FS_REQUIRE_486
-	__asm__("bswap %0" : "=r" (val) : "0" (val));
-#else
-	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
-		"rorl $16,%0\n\t"	/* swap words		*/
-		"xchgb %b0,%h0"		/* swap higher bytes	*/
-		:"=q" (val)
-		: "0" (val));
-#endif
-	return val;
-}
-
-_INLINE_ __u16 blkid_swab16(__u16 val)
-{
-	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
-		: "=q" (val) \
-		:  "0" (val)); \
-		return val;
-}
-
-_INLINE_ __u64 blkid_swab64(__u64 val)
-{
-	return (blkid_swab32(val >> 32) |
-		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
-}
-#endif
-
-#if !defined(_BLKID_HAVE_ASM_BITOPS_)
-
 _INLINE_  __u16 blkid_swab16(__u16 val)
 {
 	return (val >> 8) | (val << 8);
@@ -870,9 +830,6 @@ _INLINE_ __u64 blkid_swab64(__u64 val)
 	return (blkid_swab32(val >> 32) |
 		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
 }
-#endif
-
-
 
 #ifdef WORDS_BIGENDIAN
 #define blkid_le16(x) blkid_swab16(x)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (6 preceding siblings ...)
  2023-01-21 20:31 ` [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 09/38] lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size() Eric Biggers
                   ` (30 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

With -Wall, gcc warns:

      ./probe.c:1209:42: error: taking address of packed member of
               'struct hfs_mdb' may result in an unaligned pointer value

This seems to be a real unaligned memory access bug, as the offset of
the 64-bit value from the start of the buffer is 116, which is not a
multiple of 8.  Fix it by using memcpy().

Do the same for hfsplus to fix the same warning, though in that case the
offset is a multiple of 8 so it was defined behavior.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/blkid/probe.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index b8b6558e3..6a3bb2478 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -1198,7 +1198,6 @@ static int probe_hfs(struct blkid_probe *probe __BLKID_ATTR((unused)),
 			 unsigned char *buf)
 {
 	struct hfs_mdb *hfs = (struct hfs_mdb *)buf;
-	unsigned long long *uuid_ptr;
 	char	uuid_str[17];
 	__u64	uuid;
 
@@ -1206,8 +1205,8 @@ static int probe_hfs(struct blkid_probe *probe __BLKID_ATTR((unused)),
 	    (memcmp(hfs->embed_sig, "HX", 2) == 0))
 		return 1;	/* Not hfs, but an embedded HFS+ */
 
-	uuid_ptr = (unsigned long long *)hfs->finder_info.id;
-	uuid = blkid_le64(*uuid_ptr);
+	memcpy(&uuid, hfs->finder_info.id, 8);
+	uuid = blkid_le64(uuid);
 	if (uuid) {
 		sprintf(uuid_str, "%016llX", uuid);
 		blkid_set_tag(probe->dev, "UUID", uuid_str, 0);
@@ -1243,7 +1242,6 @@ static int probe_hfsplus(struct blkid_probe *probe,
 	unsigned int leaf_node_size;
 	unsigned int leaf_block;
 	unsigned int label_len;
-	unsigned long long *uuid_ptr;
 	__u64 leaf_off, uuid;
 	char	uuid_str[17], label[512];
 	int ext;
@@ -1274,8 +1272,8 @@ static int probe_hfsplus(struct blkid_probe *probe,
 	    (memcmp(hfsplus->signature, "HX", 2) != 0))
 		return 1;
 
-	uuid_ptr = (unsigned long long *)hfsplus->finder_info.id;
-	uuid = blkid_le64(*uuid_ptr);
+	memcpy(&uuid, hfsplus->finder_info.id, 8);
+	uuid = blkid_le64(uuid);
 	if (uuid) {
 		sprintf(uuid_str, "%016llX", uuid);
 		blkid_set_tag(probe->dev, "UUID", uuid_str, 0);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 09/38] lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (7 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 10/38] lib/blkid: suppress -Wunused-result warning in blkid_flush_cache() Eric Biggers
                   ` (29 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

This showed up when building for Windows.  It's hard to conditionally
define this variable, so use the 'unused' attribute.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/blkid/Android.bp | 1 -
 lib/blkid/getsize.c  | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/blkid/Android.bp b/lib/blkid/Android.bp
index a40113193..f5d25da4f 100644
--- a/lib/blkid/Android.bp
+++ b/lib/blkid/Android.bp
@@ -42,7 +42,6 @@ cc_library {
             include_dirs: ["external/e2fsprogs/include/mingw"],
             cflags: [
                 "-Wno-pointer-to-int-cast",
-                "-Wno-unused-variable",
                 "-Wno-error=typedef-redefinition",
             ],
 
diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c
index 75f21d5c1..7a6e6fd86 100644
--- a/lib/blkid/getsize.c
+++ b/lib/blkid/getsize.c
@@ -75,7 +75,7 @@ static int valid_offset(int fd, blkid_loff_t offset)
  */
 blkid_loff_t blkid_get_dev_size(int fd)
 {
-	unsigned long long size64;
+	unsigned long long size64 __BLKID_ATTR((unused));
 	blkid_loff_t high, low;
 
 #if defined DKIOCGETBLOCKCOUNT && defined DKIOCGETBLOCKSIZE	/* For Apple Darwin */
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 10/38] lib/blkid: suppress -Wunused-result warning in blkid_flush_cache()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (8 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 09/38] lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup() Eric Biggers
                   ` (28 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

When _FORTIFY_SOURCE is defined, glibc annotates link() with the
warn_unused_result function attribute.  With gcc, that makes
'(void) link()' cause a -Wunused-result warning, despite the explicit
cast to void.  That's annoying, since the use case in lib/blkid/save.c
is legitimate (opportunistic backup).  So let's suppress this warning.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/blkid/save.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/blkid/save.c b/lib/blkid/save.c
index 036f07a4a..6f4499cfd 100644
--- a/lib/blkid/save.c
+++ b/lib/blkid/save.c
@@ -154,7 +154,15 @@ int blkid_flush_cache(blkid_cache cache)
 			if (backup) {
 				sprintf(backup, "%s.old", filename);
 				unlink(backup);
+#if defined(__GNUC__) && __GNUC__ >= 5
+/* explicit (void) cast is not enough with glibc and _FORTIFY_SOURCE */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
+#endif
 				(void) link(filename, backup);
+#if defined(__GNUC__) && __GNUC__ >= 5
+#pragma GCC diagnostic pop
+#endif
 				free(backup);
 			}
 			if (rename(opened, filename) < 0)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (9 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 10/38] lib/blkid: suppress -Wunused-result warning in blkid_flush_cache() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 12/38] lib/e2p: fix a -Wunused-variable warning in getflags() Eric Biggers
                   ` (27 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Unfortunately, gcc gets confused by blkid_strndup() and incorrectly
thinks the destination string is not being null-terminated.  This is
part of -Wstringop-truncation, enabled automatically by -Wall in gcc 8
and later.  Let's just suppress this warning here.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/blkid/devno.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/blkid/devno.c b/lib/blkid/devno.c
index 34ceb3c48..b1cadc9df 100644
--- a/lib/blkid/devno.c
+++ b/lib/blkid/devno.c
@@ -37,6 +37,12 @@
 
 #include "blkidP.h"
 
+#if defined(__GNUC__) && __GNUC__ >= 8
+/* gcc incorrectly thinks the destination string is not being null-terminated */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
+
 char *blkid_strndup(const char *s, int length)
 {
 	char *ret;
@@ -55,6 +61,10 @@ char *blkid_strndup(const char *s, int length)
 	return ret;
 }
 
+#if defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC diagnostic pop
+#endif
+
 char *blkid_strdup(const char *s)
 {
 	return blkid_strndup(s, 0);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 12/38] lib/e2p: fix a -Wunused-variable warning in getflags()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (10 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 13/38] lib/{e2p,ss}: remove manual declarations of errno Eric Biggers
                   ` (26 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

This affected Windows builds.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/e2p/getflags.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/e2p/getflags.c b/lib/e2p/getflags.c
index e4e2ad735..6708cd68b 100644
--- a/lib/e2p/getflags.c
+++ b/lib/e2p/getflags.c
@@ -30,8 +30,8 @@
 
 int getflags (int fd, unsigned long * flags)
 {
-	struct stat buf;
 #if HAVE_STAT_FLAGS
+	struct stat buf;
 
 	if (fstat (fd, &buf) == -1)
 		return -1;
@@ -53,6 +53,7 @@ int getflags (int fd, unsigned long * flags)
 	return 0;
 #else
 #if HAVE_EXT2_IOCTLS
+	struct stat buf;
 	int r, f;
 
 	if (!fstat(fd, &buf) &&
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 13/38] lib/{e2p,ss}: remove manual declarations of errno
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (11 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 12/38] lib/e2p: fix a -Wunused-variable warning in getflags() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 14/38] lib/et: fix "unused variable" warnings when !HAVE_FCNTL Eric Biggers
                   ` (25 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

As per 'man 3 errno':

    On some ancient systems, <errno.h> was not present or did not
    declare errno, so that it was necessary to declare errno manually
    (i.e., extern int errno).   **Do not do this**.  It long ago ceased
    to be necessary, and it will cause problems with modern versions of
    the C library.

One of the platforms it causes a problem on is Windows:

    In file included from fgetversion.c:28:
    fgetversion.c: In function ‘fgetversion’:
    fgetversion.c:68:20: warning: ‘_errno’ redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
       68 |         extern int errno;
          |                    ^~~~~

Just remove these obsolete manual declarations of errno.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/e2p/fgetversion.c | 2 --
 lib/e2p/fsetversion.c | 1 -
 lib/e2p/getversion.c  | 1 -
 lib/e2p/setversion.c  | 1 -
 lib/ss/execute_cmd.c  | 2 --
 lib/ss/help.c         | 2 --
 lib/ss/pager.c        | 2 --
 7 files changed, 11 deletions(-)

diff --git a/lib/e2p/fgetversion.c b/lib/e2p/fgetversion.c
index a65e9a5c5..f3a5b4cdf 100644
--- a/lib/e2p/fgetversion.c
+++ b/lib/e2p/fgetversion.c
@@ -65,8 +65,6 @@ int fgetversion(const char *name, unsigned long *version)
 	rc = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0);
 # endif /* !APPLE_DARWIN */
 #else /* ! HAVE_EXT2_IOCTLS */
-	extern int errno;
-
 	errno = EOPNOTSUPP;
 #endif /* ! HAVE_EXT2_IOCTLS */
 	if (rc == 0)
diff --git a/lib/e2p/fsetversion.c b/lib/e2p/fsetversion.c
index c2e045591..5f844b55e 100644
--- a/lib/e2p/fsetversion.c
+++ b/lib/e2p/fsetversion.c
@@ -65,7 +65,6 @@ int fsetversion (const char * name, unsigned long version)
    return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0);
 #endif
 #else /* ! HAVE_EXT2_IOCTLS */
-	extern int errno;
 	errno = EOPNOTSUPP;
 	return -1;
 #endif /* ! HAVE_EXT2_IOCTLS */
diff --git a/lib/e2p/getversion.c b/lib/e2p/getversion.c
index 9f719b4a9..d374a0ea7 100644
--- a/lib/e2p/getversion.c
+++ b/lib/e2p/getversion.c
@@ -35,7 +35,6 @@ int getversion (int fd, unsigned long * version)
 	*version = ver;
 	return r;
 #else /* ! HAVE_EXT2_IOCTLS */
-	extern int errno;
 	errno = EOPNOTSUPP;
 	return -1;
 #endif /* ! HAVE_EXT2_IOCTLS */
diff --git a/lib/e2p/setversion.c b/lib/e2p/setversion.c
index 2bc933749..dd4a3f06b 100644
--- a/lib/e2p/setversion.c
+++ b/lib/e2p/setversion.c
@@ -34,7 +34,6 @@ int setversion (int fd, unsigned long version)
 	ver = (int) version;
 	return ioctl (fd, EXT2_IOC_SETVERSION, &ver);
 #else /* ! HAVE_EXT2_IOCTLS */
-	extern int errno;
 	errno = EOPNOTSUPP;
 	return -1;
 #endif /* ! HAVE_EXT2_IOCTLS */
diff --git a/lib/ss/execute_cmd.c b/lib/ss/execute_cmd.c
index 2e2c8cfa0..d092134a3 100644
--- a/lib/ss/execute_cmd.c
+++ b/lib/ss/execute_cmd.c
@@ -17,8 +17,6 @@
 #endif
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
-#else
-extern int errno;
 #endif
 #include "ss_internal.h"
 #include <stdio.h>
diff --git a/lib/ss/help.c b/lib/ss/help.c
index a22b40178..54c78f239 100644
--- a/lib/ss/help.c
+++ b/lib/ss/help.c
@@ -20,8 +20,6 @@
 #endif
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
-#else
-extern int errno;
 #endif
 #include <fcntl.h>
 #include <sys/param.h>
diff --git a/lib/ss/pager.c b/lib/ss/pager.c
index b9b889962..ba32b2019 100644
--- a/lib/ss/pager.c
+++ b/lib/ss/pager.c
@@ -20,8 +20,6 @@
 #endif
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
-#else
-extern int errno;
 #endif
 
 #include "ss_internal.h"
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 14/38] lib/et: fix "unused variable" warnings when !HAVE_FCNTL
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (12 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 13/38] lib/{e2p,ss}: remove manual declarations of errno Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 15/38] lib/ext2fs: remove 32-bit x86 bitops assembly Eric Biggers
                   ` (24 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

In init_debug(), avoid -Wunused-variable and -Wunused-but-set-variable
warnings when HAVE_FCNTL is not defined by only declaring 'fd' and
'flags' when HAVE_FCNTL is defined.  This affected Windows builds.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/et/Android.bp      |  3 ---
 lib/et/error_message.c | 10 +++++-----
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/et/Android.bp b/lib/et/Android.bp
index 07f3c277e..565feb594 100644
--- a/lib/et/Android.bp
+++ b/lib/et/Android.bp
@@ -31,9 +31,6 @@ cc_library {
     target: {
         windows: {
             enabled: true,
-            cflags: [
-                "-Wno-unused-variable",
-            ],
         },
     },
 
diff --git a/lib/et/error_message.c b/lib/et/error_message.c
index cd9f57f56..8b9474ffa 100644
--- a/lib/et/error_message.c
+++ b/lib/et/error_message.c
@@ -235,7 +235,6 @@ static FILE *debug_f = 0;
 static void init_debug(void)
 {
 	char	*dstr, *fn, *tmp;
-	int	fd, flags;
 
 	if (debug_mask & DEBUG_INIT)
 		return;
@@ -257,10 +256,12 @@ static void init_debug(void)
 	if (!debug_f)
 		debug_f = fopen("/dev/tty", "a");
 	if (debug_f) {
-		fd = fileno(debug_f);
-#if defined(HAVE_FCNTL)
+#ifdef HAVE_FCNTL
+		int fd = fileno(debug_f);
+
 		if (fd >= 0) {
-			flags = fcntl(fd, F_GETFD);
+			int flags = fcntl(fd, F_GETFD);
+
 			if (flags >= 0)
 				flags = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
 			if (flags < 0) {
@@ -274,7 +275,6 @@ static void init_debug(void)
 #endif
 	} else
 		debug_mask = DEBUG_INIT;
-
 }
 
 /*
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 15/38] lib/ext2fs: remove 32-bit x86 bitops assembly
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (13 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 14/38] lib/et: fix "unused variable" warnings when !HAVE_FCNTL Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 16/38] lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics() Eric Biggers
                   ` (23 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

The EXT2FS_ADDR() macro is causing -Warray-bounds warnings because it
(sort of) dereferences past the end of the input array.  It's not a
"real" dereference, since the result is passed as a memory operand to
inline asm.  But in the C language sense, it is a dereference.

Instead of trying to fix this code, let's consider that libext2fs *only*
implements the bit operations in assembly for 32-bit x86, which is
rarely used anymore.  The fact that compilers have also improved, and no
one has implemented these for another architecture, even x86_64,
suggests it's not useful either.  So, let's just remove this outdated
code, which was maybe useful in the 90s, but now just causes problems.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/bitops.c | 14 +------
 lib/ext2fs/bitops.h | 97 ---------------------------------------------
 2 files changed, 2 insertions(+), 109 deletions(-)

diff --git a/lib/ext2fs/bitops.c b/lib/ext2fs/bitops.c
index c4a1d4e09..ce2acc460 100644
--- a/lib/ext2fs/bitops.c
+++ b/lib/ext2fs/bitops.c
@@ -19,14 +19,8 @@
 #include "ext2_fs.h"
 #include "ext2fs.h"
 
-#ifndef _EXT2_HAVE_ASM_BITOPS_
-
 /*
- * For the benefit of those who are trying to port Linux to another
- * architecture, here are some C-language equivalents.  You should
- * recode these in the native assembly language, if at all possible.
- *
- * C language equivalents written by Theodore Ts'o, 9/26/92.
+ * C language bitmap functions written by Theodore Ts'o, 9/26/92.
  * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
  * systems, as well as non-32 bit systems.
  */
@@ -65,8 +59,6 @@ int ext2fs_test_bit(unsigned int nr, const void * addr)
 	return (mask & *ADDR);
 }
 
-#endif	/* !_EXT2_HAVE_ASM_BITOPS_ */
-
 void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
 			const char *description)
 {
@@ -78,9 +70,7 @@ void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
 #endif
 }
 
-/*
- * C-only 64 bit ops.
- */
+/* Bitmap functions that take a 64-bit offset */
 
 int ext2fs_set_bit64(__u64 nr, void * addr)
 {
diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h
index 505b3c9c3..9edf59447 100644
--- a/lib/ext2fs/bitops.h
+++ b/lib/ext2fs/bitops.h
@@ -219,14 +219,6 @@ extern errcode_t ext2fs_find_first_set_generic_bmap(ext2fs_generic_bitmap bitmap
  * functions at all; they will be included as normal functions in
  * inline.c
  */
-#ifdef NO_INLINE_FUNCS
-#if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \
-			   defined(__i586__)))
-	/* This prevents bitops.c from trying to include the C */
-	/* function version of these functions */
-#define _EXT2_HAVE_ASM_BITOPS_
-#endif
-#endif /* NO_INLINE_FUNCS */
 
 #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
 #ifdef INCLUDE_INLINE_FUNCS
@@ -285,90 +277,6 @@ _INLINE_ void ext2fs_fast_clear_bit64(__u64 nr, void * addr)
 	*ADDR &= (unsigned char) ~(1 << (nr & 0x07));
 }
 
-
-#if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \
-     (defined(__i386__) || defined(__i486__) || defined(__i586__)))
-
-#define _EXT2_HAVE_ASM_BITOPS_
-#define _EXT2_HAVE_ASM_SWAB_
-
-/*
- * These are done by inline assembly for speed reasons.....
- *
- * All bitoperations return 0 if the bit was cleared before the
- * operation and != 0 if it was not.  Bit 0 is the LSB of addr; bit 32
- * is the LSB of (addr+1).
- */
-
-/*
- * Some hacks to defeat gcc over-optimizations..
- */
-struct __dummy_h { unsigned long a[100]; };
-#define EXT2FS_ADDR (*(struct __dummy_h *) addr)
-#define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr)
-
-_INLINE_ int ext2fs_set_bit(unsigned int nr, void * addr)
-{
-	int oldbit;
-
-	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
-		:"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr)
-{
-	int oldbit;
-
-	addr = (void *) (((unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit),"+m" (EXT2FS_ADDR)
-		:"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr)
-{
-	int oldbit;
-
-	addr = (const void *) (((const unsigned char *) addr) + (nr >> 3));
-	__asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0"
-		:"=r" (oldbit)
-		:"m" (EXT2FS_CONST_ADDR),"r" (nr & 7));
-	return oldbit;
-}
-
-_INLINE_ __u32 ext2fs_swab32(__u32 val)
-{
-#ifdef EXT2FS_REQUIRE_486
-	__asm__("bswap %0" : "=r" (val) : "0" (val));
-#else
-	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
-		"rorl $16,%0\n\t"	/* swap words		*/
-		"xchgb %b0,%h0"		/* swap higher bytes	*/
-		:"=q" (val)
-		: "0" (val));
-#endif
-	return val;
-}
-
-_INLINE_ __u16 ext2fs_swab16(__u16 val)
-{
-	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
-		: "=q" (val) \
-		:  "0" (val)); \
-		return val;
-}
-
-#undef EXT2FS_ADDR
-
-#endif	/* i386 */
-
-
-#if !defined(_EXT2_HAVE_ASM_SWAB_)
-
 _INLINE_ __u16 ext2fs_swab16(__u16 val)
 {
 	return (val >> 8) | (__u16) (val << 8);
@@ -380,8 +288,6 @@ _INLINE_ __u32 ext2fs_swab32(__u32 val)
 		((val<<8)&0xFF0000) | (val<<24));
 }
 
-#endif /* !_EXT2_HAVE_ASM_SWAB */
-
 _INLINE_ __u64 ext2fs_swab64(__u64 val)
 {
 	return (ext2fs_swab32((__u32) (val >> 32)) |
@@ -691,12 +597,9 @@ _INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap,
 #undef _INLINE_
 #endif
 
-#ifndef _EXT2_HAVE_ASM_BITOPS_
 extern int ext2fs_set_bit(unsigned int nr,void * addr);
 extern int ext2fs_clear_bit(unsigned int nr, void * addr);
 extern int ext2fs_test_bit(unsigned int nr, const void * addr);
-#endif
-
 extern int ext2fs_set_bit64(__u64 nr,void * addr);
 extern int ext2fs_clear_bit64(__u64 nr, void * addr);
 extern int ext2fs_test_bit64(__u64 nr, const void * addr);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 16/38] lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (14 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 15/38] lib/ext2fs: remove 32-bit x86 bitops assembly Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 17/38] lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode() Eric Biggers
                   ` (22 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

Since the 'now' variable is only used to calculate 'inuse', and 'inuse'
is only used when defined(ENABLE_BMAP_STATS_OPS), it makes sense to
guard the declaration and initialization of 'now' and 'inuse' by the
same condition, just like the '*_perc' variables in the same function.

This addresses the following compiler warning with clang -Wall:

gen_bitmap64.c:187:9: warning: variable 'inuse' set but not used [-Wunused-but-set-variable]
        double inuse;
               ^
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/gen_bitmap64.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index c860c10ed..1a1eeefeb 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -183,11 +183,9 @@ static void ext2fs_print_bmap_statistics(ext2fs_generic_bitmap_64 bitmap)
 #ifdef ENABLE_BMAP_STATS_OPS
 	float mark_seq_perc = 0.0, test_seq_perc = 0.0;
 	float mark_back_perc = 0.0, test_back_perc = 0.0;
-#endif
-	double inuse;
 	struct timeval now;
+	double inuse;
 
-#ifdef ENABLE_BMAP_STATS_OPS
 	if (stats->test_count) {
 		test_seq_perc = ((float)stats->test_seq /
 				 stats->test_count) * 100;
@@ -201,7 +199,6 @@ static void ext2fs_print_bmap_statistics(ext2fs_generic_bitmap_64 bitmap)
 		mark_back_perc = ((float)stats->mark_back /
 				  stats->mark_count) * 100;
 	}
-#endif
 
 	if (gettimeofday(&now, (struct timezone *) NULL) == -1) {
 		perror("gettimeofday");
@@ -212,6 +209,7 @@ static void ext2fs_print_bmap_statistics(ext2fs_generic_bitmap_64 bitmap)
 		(((double) now.tv_usec) * 0.000001);
 	inuse -= (double) stats->created.tv_sec + \
 		(((double) stats->created.tv_usec) * 0.000001);
+#endif /* ENABLE_BMAP_STATS_OPS */
 
 	fprintf(stderr, "\n[+] %s bitmap (type %d)\n", bitmap->description,
 		stats->type);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 17/38] lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (15 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 16/38] lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 18/38] lib/ext2fs: fix a printf format specifier in file_test() Eric Biggers
                   ` (21 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Andreas Dilger, Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

Address the following compiler warning with gcc -Wall:

ext_attr.c: In function ‘ext2fs_xattrs_read_inode’:
ext_attr.c:1000:16: warning: unused variable ‘i’ [-Wunused-variable]
 1000 |         size_t i;
      |                ^

Cc: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/ext_attr.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index d36fe68dd..359c8e3cb 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -991,13 +991,11 @@ static void xattrs_free_keys(struct ext2_xattr_handle *h)
 errcode_t ext2fs_xattrs_read_inode(struct ext2_xattr_handle *handle,
 				   struct ext2_inode_large *inode)
 {
-
 	struct ext2_ext_attr_header *header;
 	__u32 ea_inode_magic;
 	unsigned int storage_size;
 	char *start, *block_buf = NULL;
 	blk64_t blk;
-	size_t i;
 	errcode_t err = 0;
 
 	EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EA_HANDLE);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 18/38] lib/ext2fs: fix a printf format specifier in file_test()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (16 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 17/38] lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 19/38] lib/ext2fs: fix two compiler warnings in windows_io.c Eric Biggers
                   ` (20 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

size_t should be matched by %zu, not %lu.  This fixes a -Wformat warning
when building for 32-bit x86.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/inline_data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c
index b62fb6769..bd52e3770 100644
--- a/lib/ext2fs/inline_data.c
+++ b/lib/ext2fs/inline_data.c
@@ -653,7 +653,7 @@ static errcode_t file_test(ext2_filsys fs)
 
 	if (size != BUFF_SIZE) {
 		fprintf(stderr,
-			"tst_inline_data: size %lu != buflen %u\n",
+			"tst_inline_data: size %zu != buflen %u\n",
 			size, BUFF_SIZE);
 		retval = 1;
 		goto err;
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 19/38] lib/ext2fs: fix two compiler warnings in windows_io.c
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (17 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 18/38] lib/ext2fs: fix a printf format specifier in file_test() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 20/38] lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start() Eric Biggers
                   ` (19 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

init_private_data() triggers a -Wstringop-truncation warning, due to a
real bug.  Fix it.

windows_open() has a -Wunused-variable warning because some
macOS-specific code was copied there for no reason.  Remove it.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/windows_io.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/lib/ext2fs/windows_io.c b/lib/ext2fs/windows_io.c
index 68b5571bb..83aea68b6 100644
--- a/lib/ext2fs/windows_io.c
+++ b/lib/ext2fs/windows_io.c
@@ -499,9 +499,6 @@ static errcode_t windows_open_channel(struct windows_private_data *data,
 #if defined(O_DIRECT)
 	if (flags & IO_FLAG_DIRECT_IO)
 		io->align = ext2fs_get_dio_alignment(data->dev);
-#elif defined(F_NOCACHE)
-	if (flags & IO_FLAG_DIRECT_IO)
-		io->align = 4096;
 #endif
 
 	/*
@@ -609,7 +606,7 @@ static struct windows_private_data *init_private_data(const char *name, int flag
 		return NULL;
 
 	memset(data, 0, sizeof(struct windows_private_data));
-	strncpy(data->name, name, sizeof(data->name));
+	strncpy(data->name, name, sizeof(data->name) - 1);
 	data->magic = EXT2_ET_MAGIC_WINDOWS_IO_CHANNEL;
 	data->io_stats.num_fields = 2;
 	data->flags = flags;
@@ -620,7 +617,6 @@ static struct windows_private_data *init_private_data(const char *name, int flag
 
 static errcode_t windows_open(const char *name, int flags, io_channel *channel)
 {
-	int fd = -1;
 	int open_flags;
 	struct windows_private_data *data;
 
@@ -644,12 +640,6 @@ static errcode_t windows_open(const char *name, int flags, io_channel *channel)
 		return EXT2_ET_BAD_DEVICE_NAME;
 	}
 
-#if defined(F_NOCACHE) && !defined(IO_DIRECT)
-	if (flags & IO_FLAG_DIRECT_IO) {
-		if (fcntl(fd, F_NOCACHE, 1) < 0)
-			return errno;
-	}
-#endif
 	return windows_open_channel(data, flags, channel, windows_io_manager);
 }
 
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 20/38] lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (18 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 19/38] lib/ext2fs: fix two compiler warnings in windows_io.c Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 21/38] lib/{ext2fs,support}: fix 32-bit Windows build Eric Biggers
                   ` (18 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

This showed up when building for Windows.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/mmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
index 7970aac27..9491fbd5c 100644
--- a/lib/ext2fs/mmp.c
+++ b/lib/ext2fs/mmp.c
@@ -356,7 +356,7 @@ clean_seq:
 #ifdef HAVE_GETHOSTNAME
 	gethostname((char *) mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename));
 #else
-	strcpy(mmp_s->mmp_nodename, "unknown host");
+	strcpy((char *) mmp_s->mmp_nodename, "unknown host");
 #endif
 	strncpy((char *) mmp_s->mmp_bdevname, fs->device_name,
 		sizeof(mmp_s->mmp_bdevname));
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 21/38] lib/{ext2fs,support}: fix 32-bit Windows build
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (19 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 20/38] lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 22/38] lib/ss: fix 'make install' by creating man1dir Eric Biggers
                   ` (17 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Paulo Antonio Alvarez

From: Eric Biggers <ebiggers@google.com>

_WIN32 is the standard macro to detect (native) Windows, regardless of
32-bit or 64-bit.  _WIN64 is for 64-bit Windows only.  Use _WIN32 where
_WIN64 was incorrectly being used.

This fixes several 32-bit Windows build errors, for example this one:

plausible.c: In function ‘print_ext2_info’:
plausible.c:109:31: error: ‘unix_io_manager’ undeclared (first use in this function); did you mean ‘undo_io_manager’?
  109 |                               unix_io_manager,
      |                               ^~~~~~~~~~~~~~~
      |                               undo_io_manager

Fixes: 86b6db9f5a43 ("libext2fs: code adaptation to use the Windows IO manager")
Cc: Paulo Antonio Alvarez <pauloaalvarez@gmail.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/getsectsize.c | 12 ++++++------
 lib/support/plausible.c  |  2 +-
 util/subst.c             |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/ext2fs/getsectsize.c b/lib/ext2fs/getsectsize.c
index 3a461eb9c..bd978c530 100644
--- a/lib/ext2fs/getsectsize.c
+++ b/lib/ext2fs/getsectsize.c
@@ -51,10 +51,10 @@
  */
 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
 {
-#ifdef _WIN64
+#ifdef _WIN32
 	*sectsize = 512; // just guessing
 	return 0;
-#else // not _WIN64
+#else // not _WIN32
 
 	int	fd;
 
@@ -78,7 +78,7 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
 	close(fd);
 	return 0;
 
-#endif // ifdef _WIN64
+#endif // ifdef _WIN32
 }
 
 /*
@@ -117,11 +117,11 @@ int ext2fs_get_dio_alignment(int fd)
  */
 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
 {
-#ifdef _WIN64
+#ifdef _WIN32
 
 	return ext2fs_get_device_sectsize(file, sectsize);
 
-#else // not _WIN64
+#else // not _WIN32
 
 	int	fd;
 
@@ -147,5 +147,5 @@ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
 	close(fd);
 	return 0;
 
-#endif // ifdef _WIN64
+#endif // ifdef _WIN32
 }
diff --git a/lib/support/plausible.c b/lib/support/plausible.c
index bbed2a70a..349aa2c4f 100644
--- a/lib/support/plausible.c
+++ b/lib/support/plausible.c
@@ -103,7 +103,7 @@ static void print_ext2_info(const char *device)
 	time_t			tm;
 
 	retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
-#ifdef _WIN64
+#ifdef _WIN32
 			      windows_io_manager,
 #else
 			      unix_io_manager,
diff --git a/util/subst.c b/util/subst.c
index c0eda5cf8..be2a0dda4 100644
--- a/util/subst.c
+++ b/util/subst.c
@@ -434,7 +434,7 @@ int main(int argc, char **argv)
 					printf("Using original atime\n");
 				set_utimes(outfn, fileno(old), tv);
 			}
-#ifndef _WIN64
+#ifndef _WIN32
 			if (ofd >= 0)
 				(void) fchmod(ofd, 0444);
 #endif
@@ -444,7 +444,7 @@ int main(int argc, char **argv)
 		} else {
 			if (verbose)
 				printf("Creating or replacing %s.\n", outfn);
-#ifndef _WIN64
+#ifndef _WIN32
 			if (ofd >= 0)
 				(void) fchmod(ofd, 0444);
 #endif
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 22/38] lib/ss: fix 'make install' by creating man1dir
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (20 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 21/38] lib/{ext2fs,support}: fix 32-bit Windows build Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 23/38] lib/support: remove unused label in get_devname() Eric Biggers
                   ` (16 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

'make install' does not work because libss tries to install a man page
without creating the directory first.  Fix this.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ss/Makefile.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/ss/Makefile.in b/lib/ss/Makefile.in
index 40294db0b..bb5041893 100644
--- a/lib/ss/Makefile.in
+++ b/lib/ss/Makefile.in
@@ -125,10 +125,11 @@ ss.pc: $(srcdir)/ss.pc.in $(top_builddir)/config.status
 	$(Q) cd $(top_builddir); CONFIG_FILES=lib/ss/ss.pc ./config.status
 
 installdirs::
-	$(E) "	MKDIR_P $(libdir) $(includedir)/ss $(datadir)/ss $(bindir)"
+	$(E) "	MKDIR_P $(libdir) $(includedir)/ss $(datadir)/ss $(bindir) $(pkgconfigdir) $(man1dir)"
 	$(Q) $(MKDIR_P) $(DESTDIR)$(libdir) \
 		$(DESTDIR)$(includedir)/ss $(DESTDIR)$(datadir)/ss \
-		$(DESTDIR)$(bindir) $(DESTDIR)$(pkgconfigdir)
+		$(DESTDIR)$(bindir) $(DESTDIR)$(pkgconfigdir) \
+		$(DESTDIR)$(man1dir)
 
 install:: libss.a $(INSTALL_HFILES) installdirs ss_err.h mk_cmds ss.pc
 	$(E) "	INSTALL_DATA $(DESTDIR)$(libdir)/libss.a"
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 23/38] lib/support: remove unused label in get_devname()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (21 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 22/38] lib/ss: fix 'make install' by creating man1dir Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 24/38] lib/support: clean up definition of flags_array Eric Biggers
                   ` (15 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

Address the following compiler warning with gcc -Wall:

devname.c: In function ‘get_devname’:
devname.c:61:1: warning: label ‘out_strdup’ defined but not used [-Wunused-label]
   61 | out_strdup:
      | ^~~~~~~~~~

Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/support/devname.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/support/devname.c b/lib/support/devname.c
index 8c2349a32..e0306ddfb 100644
--- a/lib/support/devname.c
+++ b/lib/support/devname.c
@@ -58,7 +58,6 @@ char *get_devname(blkid_cache cache, const char *token, const char *value)
 		goto out;
 	}
 
-out_strdup:
 	if (is_file)
 		ret = strdup(token);
 out:
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 24/38] lib/support: clean up definition of flags_array
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (22 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 23/38] lib/support: remove unused label in get_devname() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 25/38] lib/uuid: remove conflicting Windows implementation of gettimeofday() Eric Biggers
                   ` (14 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

Add braces to address the following compiler warning with gcc -Wall:

print_fs_flags.c:24:42: warning: missing braces around initializer [-Wmissing-braces]
   24 | static struct flags_name flags_array[] = {
      |                                          ^

Also add 'const', and add an explicit NULL in the last entry.

Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/support/print_fs_flags.c | 60 ++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/lib/support/print_fs_flags.c b/lib/support/print_fs_flags.c
index e54acc04b..f47cd6653 100644
--- a/lib/support/print_fs_flags.c
+++ b/lib/support/print_fs_flags.c
@@ -21,40 +21,40 @@ struct flags_name {
 	const char	*name;
 };
 
-static struct flags_name flags_array[] = {
-	EXT2_FLAG_RW, "EXT2_FLAG_RW",
-	EXT2_FLAG_CHANGED, "EXT2_FLAG_CHANGED",
-	EXT2_FLAG_DIRTY, "EXT2_FLAG_DIRTY",
-	EXT2_FLAG_VALID, "EXT2_FLAG_VALID",
-	EXT2_FLAG_IB_DIRTY, "EXT2_FLAG_IB_DIRTY",
-	EXT2_FLAG_BB_DIRTY, "EXT2_FLAG_BB_DIRTY",
-	EXT2_FLAG_SWAP_BYTES, "EXT2_FLAG_SWAP_BYTES",
-	EXT2_FLAG_SWAP_BYTES_READ, "EXT2_FLAG_SWAP_BYTES_READ",
-	EXT2_FLAG_SWAP_BYTES_WRITE, "EXT2_FLAG_SWAP_BYTES_WRITE",
-	EXT2_FLAG_MASTER_SB_ONLY, "EXT2_FLAG_MASTER_SB_ONLY",
-	EXT2_FLAG_FORCE, "EXT2_FLAG_FORCE",
-	EXT2_FLAG_SUPER_ONLY, "EXT2_FLAG_SUPER_ONLY",
-	EXT2_FLAG_JOURNAL_DEV_OK, "EXT2_FLAG_JOURNAL_DEV_OK",
-	EXT2_FLAG_IMAGE_FILE, "EXT2_FLAG_IMAGE_FILE",
-	EXT2_FLAG_EXCLUSIVE, "EXT2_FLAG_EXCLUSIVE",
-	EXT2_FLAG_SOFTSUPP_FEATURES, "EXT2_FLAG_SOFTSUPP_FEATURES",
-	EXT2_FLAG_NOFREE_ON_ERROR, "EXT2_FLAG_NOFREE_ON_ERROR",
-	EXT2_FLAG_64BITS, "EXT2_FLAG_64BITS",
-	EXT2_FLAG_PRINT_PROGRESS, "EXT2_FLAG_PRINT_PROGRESS",
-	EXT2_FLAG_DIRECT_IO, "EXT2_FLAG_DIRECT_IO",
-	EXT2_FLAG_SKIP_MMP, "EXT2_FLAG_SKIP_MMP",
-	EXT2_FLAG_IGNORE_CSUM_ERRORS, "EXT2_FLAG_IGNORE_CSUM_ERRORS",
-	EXT2_FLAG_SHARE_DUP, "EXT2_FLAG_SHARE_DUP",
-	EXT2_FLAG_IGNORE_SB_ERRORS, "EXT2_FLAG_IGNORE_SB_ERRORS",
-	EXT2_FLAG_BBITMAP_TAIL_PROBLEM, "EXT2_FLAG_BBITMAP_TAIL_PROBLEM",
-	EXT2_FLAG_IBITMAP_TAIL_PROBLEM, "EXT2_FLAG_IBITMAP_TAIL_PROBLEM",
-	EXT2_FLAG_THREADS, "EXT2_FLAG_THREADS",
-	0
+static const struct flags_name flags_array[] = {
+	{ EXT2_FLAG_RW, "EXT2_FLAG_RW" },
+	{ EXT2_FLAG_CHANGED, "EXT2_FLAG_CHANGED" },
+	{ EXT2_FLAG_DIRTY, "EXT2_FLAG_DIRTY" },
+	{ EXT2_FLAG_VALID, "EXT2_FLAG_VALID" },
+	{ EXT2_FLAG_IB_DIRTY, "EXT2_FLAG_IB_DIRTY" },
+	{ EXT2_FLAG_BB_DIRTY, "EXT2_FLAG_BB_DIRTY" },
+	{ EXT2_FLAG_SWAP_BYTES, "EXT2_FLAG_SWAP_BYTES" },
+	{ EXT2_FLAG_SWAP_BYTES_READ, "EXT2_FLAG_SWAP_BYTES_READ" },
+	{ EXT2_FLAG_SWAP_BYTES_WRITE, "EXT2_FLAG_SWAP_BYTES_WRITE" },
+	{ EXT2_FLAG_MASTER_SB_ONLY, "EXT2_FLAG_MASTER_SB_ONLY" },
+	{ EXT2_FLAG_FORCE, "EXT2_FLAG_FORCE" },
+	{ EXT2_FLAG_SUPER_ONLY, "EXT2_FLAG_SUPER_ONLY" },
+	{ EXT2_FLAG_JOURNAL_DEV_OK, "EXT2_FLAG_JOURNAL_DEV_OK" },
+	{ EXT2_FLAG_IMAGE_FILE, "EXT2_FLAG_IMAGE_FILE" },
+	{ EXT2_FLAG_EXCLUSIVE, "EXT2_FLAG_EXCLUSIVE" },
+	{ EXT2_FLAG_SOFTSUPP_FEATURES, "EXT2_FLAG_SOFTSUPP_FEATURES" },
+	{ EXT2_FLAG_NOFREE_ON_ERROR, "EXT2_FLAG_NOFREE_ON_ERROR" },
+	{ EXT2_FLAG_64BITS, "EXT2_FLAG_64BITS" },
+	{ EXT2_FLAG_PRINT_PROGRESS, "EXT2_FLAG_PRINT_PROGRESS" },
+	{ EXT2_FLAG_DIRECT_IO, "EXT2_FLAG_DIRECT_IO" },
+	{ EXT2_FLAG_SKIP_MMP, "EXT2_FLAG_SKIP_MMP" },
+	{ EXT2_FLAG_IGNORE_CSUM_ERRORS, "EXT2_FLAG_IGNORE_CSUM_ERRORS" },
+	{ EXT2_FLAG_SHARE_DUP, "EXT2_FLAG_SHARE_DUP" },
+	{ EXT2_FLAG_IGNORE_SB_ERRORS, "EXT2_FLAG_IGNORE_SB_ERRORS" },
+	{ EXT2_FLAG_BBITMAP_TAIL_PROBLEM, "EXT2_FLAG_BBITMAP_TAIL_PROBLEM" },
+	{ EXT2_FLAG_IBITMAP_TAIL_PROBLEM, "EXT2_FLAG_IBITMAP_TAIL_PROBLEM" },
+	{ EXT2_FLAG_THREADS, "EXT2_FLAG_THREADS" },
+	{ 0, NULL },
 };
 
 void print_fs_flags(FILE * f, unsigned long flags)
 {
-	struct flags_name *fp;
+	const struct flags_name *fp;
 	int	first = 1, pos = 16;
 
 	for (fp = flags_array; fp->flag != 0; fp++) {
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 25/38] lib/uuid: remove conflicting Windows implementation of gettimeofday()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (23 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 24/38] lib/support: clean up definition of flags_array Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 26/38] e2fsck: use real functions for kernel slab functions Eric Biggers
                   ` (13 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

When building libuuid for Windows with MinGW with the default settings,
there is a build error in lib/uuid/gen_uuid.c because the explicit
definition of gettimeofday() conflicts with MinGW's declaration of
gettimeofday().  gen_uuid.c apparently expects USE_MINGW to be defined
to avoid that, but the build system doesn't actually do that.

Since native Windows builds of e2fsprogs are currently only supported
via MinGW anyway (in particular, Visual Studio is not supported), let's
fix this by just removing our own definition of gettimeofday().

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/uuid/gen_uuid.c | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c
index 14c98eb4a..a2225ccee 100644
--- a/lib/uuid/gen_uuid.c
+++ b/lib/uuid/gen_uuid.c
@@ -117,27 +117,6 @@
 THREAD_LOCAL unsigned short jrand_seed[3];
 #endif
 
-#ifdef _WIN32
-#ifndef USE_MINGW
-static void gettimeofday (struct timeval *tv, void *dummy)
-{
-	FILETIME	ftime;
-	uint64_t	n;
-
-	GetSystemTimeAsFileTime (&ftime);
-	n = (((uint64_t) ftime.dwHighDateTime << 32)
-	     + (uint64_t) ftime.dwLowDateTime);
-	if (n) {
-		n /= 10;
-		n -= ((369 * 365 + 89) * (uint64_t) 86400) * 1000000;
-	}
-
-	tv->tv_sec = n / 1000000;
-	tv->tv_usec = n % 1000000;
-}
-#endif
-#endif
-
 static int get_random_fd(void)
 {
 	struct timeval	tv;
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 26/38] e2fsck: use real functions for kernel slab functions
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (24 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 25/38] lib/uuid: remove conflicting Windows implementation of gettimeofday() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 27/38] misc/create_inode: fix -Wunused-variable warnings in __populate_fs() Eric Biggers
                   ` (12 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

The macros that e2fsck uses to implement kmalloc et al. use only some of
their arguments, so unlike standard function calls, they can cause
compiler warnings like:

./../e2fsck/revoke.c:141:8: warning: variable 'gfp_mask' set but not used [-Wunused-but-set-variable]

Fix this by providing a proper definition for each function, making sure
to match the function prototypes used in the kernel.

Remove the kmem_cache_t typedef, as it doesn't exist in the kernel.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 e2fsck/jfs_user.h | 62 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 17 deletions(-)

diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h
index 969cd1b92..1167c80d3 100644
--- a/e2fsck/jfs_user.h
+++ b/e2fsck/jfs_user.h
@@ -82,16 +82,9 @@ struct kdev_s {
 #define buffer_req(bh) 1
 #define do_readahead(journal, start) do {} while (0)
 
-typedef struct kmem_cache {
-	int	object_length;
-} kmem_cache_t;
-
-#define kmem_cache_alloc(cache, flags) malloc((cache)->object_length)
-#define kmem_cache_free(cache, obj) free(obj)
-#define kmem_cache_create(name, len, a, b, c) do_cache_create(len)
-#define kmem_cache_destroy(cache) do_cache_destroy(cache)
-#define kmalloc(len, flags) malloc(len)
-#define kfree(p) free(p)
+struct kmem_cache {
+	unsigned int	object_size;
+};
 
 #define cond_resched()	do { } while (0)
 
@@ -107,8 +100,16 @@ typedef struct kmem_cache {
  * functions.
  */
 #ifdef NO_INLINE_FUNCS
-extern kmem_cache_t *do_cache_create(int len);
-extern void do_cache_destroy(kmem_cache_t *cache);
+extern struct kmem_cache *kmem_cache_create(const char *name,
+					    unsigned int size,
+					    unsigned int align,
+					    unsigned int flags,
+					    void (*ctor)(void *));
+extern void kmem_cache_destroy(struct kmem_cache *s);
+extern void *kmem_cache_alloc(struct kmem_cache *cachep, gfp_t flags);
+extern void kmem_cache_free(struct kmem_cache *s, void *objp);
+extern void *kmalloc(size_t size, gfp_t flags);
+extern void kfree(const void *objp);
 extern size_t journal_tag_bytes(journal_t *journal);
 extern __u32 __hash_32(__u32 val);
 extern __u32 hash_32(__u32 val, unsigned int bits);
@@ -139,19 +140,46 @@ extern void jbd2_descriptor_block_csum_set(journal_t *j,
 #endif /* __STDC_VERSION__ >= 199901L */
 #endif /* E2FSCK_INCLUDE_INLINE_FUNCS */
 
-_INLINE_ kmem_cache_t *do_cache_create(int len)
+_INLINE_ struct kmem_cache *
+kmem_cache_create(const char *name EXT2FS_ATTR((unused)),
+		  unsigned int size,
+		  unsigned int align EXT2FS_ATTR((unused)),
+		  unsigned int flags EXT2FS_ATTR((unused)),
+		  void (*ctor)(void *) EXT2FS_ATTR((unused)))
 {
-	kmem_cache_t *new_cache;
+	struct kmem_cache *new_cache;
 
 	new_cache = malloc(sizeof(*new_cache));
 	if (new_cache)
-		new_cache->object_length = len;
+		new_cache->object_size = size;
 	return new_cache;
 }
 
-_INLINE_ void do_cache_destroy(kmem_cache_t *cache)
+_INLINE_ void kmem_cache_destroy(struct kmem_cache *s)
+{
+	free(s);
+}
+
+_INLINE_ void *kmem_cache_alloc(struct kmem_cache *cachep,
+				gfp_t flags EXT2FS_ATTR((unused)))
+{
+	return malloc(cachep->object_size);
+}
+
+_INLINE_ void kmem_cache_free(struct kmem_cache *s EXT2FS_ATTR((unused)),
+			      void *objp)
+{
+	free(objp);
+}
+
+_INLINE_ void *kmalloc(size_t size, gfp_t flags EXT2FS_ATTR((unused)))
+{
+	return malloc(size);
+}
+
+_INLINE_ void kfree(const void *objp)
 {
-	free(cache);
+	free((void *)objp);
 }
 
 /* generic hashing taken from the Linux kernel */
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 27/38] misc/create_inode: fix -Wunused-variable warnings in __populate_fs()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (25 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 26/38] e2fsck: use real functions for kernel slab functions Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 28/38] misc/create_inode: simplify logic in scandir() Eric Biggers
                   ` (11 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

These showed up when building for Windows.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/create_inode.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index c00d54588..7ce69c2b0 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -813,11 +813,9 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
 	const char	*name;
 	struct dirent	**dent;
 	struct stat	st;
-	char		*ln_target = NULL;
 	unsigned int	save_inode;
 	ext2_ino_t	ino;
 	errcode_t	retval = 0;
-	int		read_cnt;
 	int		hdlink;
 	size_t		cur_dir_path_len;
 	int		i, num_dents;
@@ -900,7 +898,10 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
 				goto out;
 			}
 			break;
-		case S_IFLNK:
+		case S_IFLNK: {
+			char *ln_target;
+			int read_cnt;
+
 			ln_target = malloc(st.st_size + 1);
 			if (ln_target == NULL) {
 				com_err(__func__, retval,
@@ -935,7 +936,8 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
 				goto out;
 			}
 			break;
-#endif
+		}
+#endif /* !_WIN32 */
 		case S_IFREG:
 			retval = do_write_internal(fs, parent_ino, name, name,
 						   root);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 28/38] misc/create_inode: simplify logic in scandir()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (26 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 27/38] misc/create_inode: fix -Wunused-variable warnings in __populate_fs() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 29/38] misc/e4defrag: fix -Wstringop-truncation warnings Eric Biggers
                   ` (10 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

The control flow in scandir() (only used on Windows) confuses gcc into
thinking that *name_list is not always set on success, which causes a
-Wmaybe-uninitialized warning in __populate_fs().  As far as I can tell
it's a false positive; however, avoid it by cleanly separating the
success and failure cases in scandir().

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/create_inode.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index 7ce69c2b0..6e61d98e6 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -763,39 +763,33 @@ static int scandir(const char *dir_name, struct dirent ***name_list,
 			size_t new_list_size = temp_list_size + 32;
 			struct dirent **new_list = (struct dirent**)realloc(
 				temp_list, new_list_size * sizeof(struct dirent*));
-			if (new_list == NULL) {
-				goto out;
-			}
+			if (new_list == NULL)
+				goto out_err;
 			temp_list_size = new_list_size;
 			temp_list = new_list;
 		}
 		// add the copy of dirent to the list
 		temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
 		if (!temp_list[num_dent])
-			goto out;
+			goto out_err;
 		memcpy(temp_list[num_dent], dent, dent->d_reclen);
 		num_dent++;
 	}
+	closedir(dir);
 
 	if (compar != NULL) {
 		qsort(temp_list, num_dent, sizeof(struct dirent*),
 		      (int (*)(const void*, const void*))compar);
 	}
-
-        // release the temp list
 	*name_list = temp_list;
-	temp_list = NULL;
+	return num_dent;
 
-out:
-	if (temp_list != NULL) {
-		while (num_dent > 0) {
-			free(temp_list[--num_dent]);
-		}
-		free(temp_list);
-		num_dent = -1;
-	}
+out_err:
 	closedir(dir);
-	return num_dent;
+	while (num_dent > 0)
+		free(temp_list[--num_dent]);
+	free(temp_list);
+	return -1;
 }
 
 static int alphasort(const struct dirent **a, const struct dirent **b) {
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 29/38] misc/e4defrag: fix -Wstringop-truncation warnings
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (27 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 28/38] misc/create_inode: simplify logic in scandir() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern Eric Biggers
                   ` (9 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Fix two -Wstringop-truncation warnings in is_ext4() by simplifying how
how mnt_type is handled and by using the correct bound for mnt_fsname.

Fix a -Wstringop-truncation warning in main() by replacing the fragile
pattern 'strncpy(dst, src, strnlen(src, N))', which doesn't
null-terminate the destination string, with a standard string copy.  (It
happened to work anyway because dst happens to be zero-initialized.)

These warnings showed up when building with -Wall with gcc 8 or later.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/e4defrag.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index 9ec265f2e..33bd05d2c 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -258,12 +258,12 @@ static int get_mount_point(const char *devname, char *mount_point,
  *
  * @file:		the file's name.
  */
-static int is_ext4(const char *file, char *devname)
+static int is_ext4(const char *file, char devname[PATH_MAX + 1])
 {
 	int 	maxlen = 0;
 	int	len, ret;
+	int	type_is_ext4 = 0;
 	FILE	*fp = NULL;
-	char	*mnt_type = NULL;
 	/* Refer to /etc/mtab */
 	const char	*mtab = MOUNTED;
 	char	file_path[PATH_MAX + 1];
@@ -307,26 +307,16 @@ static int is_ext4(const char *file, char *devname)
 
 		maxlen = len;
 
-		mnt_type = realloc(mnt_type, strlen(mnt->mnt_type) + 1);
-		if (mnt_type == NULL) {
-			endmntent(fp);
-			return -1;
-		}
-		memset(mnt_type, 0, strlen(mnt->mnt_type) + 1);
-		strncpy(mnt_type, mnt->mnt_type, strlen(mnt->mnt_type));
+		type_is_ext4 = !strcmp(mnt->mnt_type, FS_EXT4);
 		strncpy(lost_found_dir, mnt->mnt_dir, PATH_MAX);
-		strncpy(devname, mnt->mnt_fsname, strlen(mnt->mnt_fsname) + 1);
+		strncpy(devname, mnt->mnt_fsname, PATH_MAX);
 	}
 
 	endmntent(fp);
-	if (mnt_type && strcmp(mnt_type, FS_EXT4) == 0) {
-		FREE(mnt_type);
+	if (type_is_ext4)
 		return 0;
-	} else {
-		FREE(mnt_type);
-		PRINT_ERR_MSG(NGMSG_EXT4);
-		return -1;
-	}
+	PRINT_ERR_MSG(NGMSG_EXT4);
+	return -1;
 }
 
 /*
@@ -1865,11 +1855,9 @@ int main(int argc, char *argv[])
 			/* fall through */
 		case DEVNAME:
 			if (arg_type == DEVNAME) {
-				strncpy(lost_found_dir, dir_name,
-					strnlen(dir_name, PATH_MAX));
+				strcpy(lost_found_dir, dir_name);
 				strncat(lost_found_dir, "/lost+found/",
-					PATH_MAX - strnlen(lost_found_dir,
-							   PATH_MAX));
+					PATH_MAX - strlen(lost_found_dir));
 			}
 
 			nftw64(dir_name, calc_entry_counts, FTW_OPEN_FD, flags);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (28 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 29/38] misc/e4defrag: fix -Wstringop-truncation warnings Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 31/38] misc/mk_hugefiles: simplify get_partition_start() Eric Biggers
                   ` (8 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

'strncpy(dst, src, strlen(src))' is usually wrong, as it doesn't copy
the null terminator.  For this reason, it causes a -Wstringop-truncation
warning with gcc 8 and later.

The code happens to be correct anyway, since the destination buffer is
zero-initialized.  But to avoid relying on this, let's just copy the
terminating null.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/fuse2fs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index c59572129..6d4bcf4fd 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -2508,9 +2508,10 @@ static int copy_names(char *name, char *value EXT2FS_ATTR((unused)),
 		      size_t value_len EXT2FS_ATTR((unused)), void *data)
 {
 	char **b = data;
+	size_t name_len = strlen(name);
 
-	strncpy(*b, name, strlen(name));
-	*b = *b + strlen(name) + 1;
+	memcpy(*b, name, name_len + 1);
+	*b = *b + name_len + 1;
 
 	return 0;
 }
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 31/38] misc/mk_hugefiles: simplify get_partition_start()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (29 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 32/38] misc/mke2fs: fix Windows build Eric Biggers
                   ` (7 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

search_sysfs_block() is causing -Wformat-truncation warnings.  These
could be fixed by checking the return value of snprintf(), instead of
doing buggy checks like 'strlen(p_de->d_name) > SYSFS_PATH_LEN -
strlen(path) - 32', which has an integer underflow bug.

However, the only purpose of search_sysfs_block() is to find the sysfs
directory for a block device by device number.  That can trivially be
done using /sys/dev/block/$major:$minor.  So just do that instead.  Also
make get_partition_start() explicitly Linux-only, as it has never worked
anywhere else.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 include/mingw/sys/sysmacros.h |   8 +-
 misc/mk_hugefiles.c           | 134 +++-------------------------------
 2 files changed, 10 insertions(+), 132 deletions(-)

diff --git a/include/mingw/sys/sysmacros.h b/include/mingw/sys/sysmacros.h
index 18fcaaa34..a790cb2f6 100644
--- a/include/mingw/sys/sysmacros.h
+++ b/include/mingw/sys/sysmacros.h
@@ -1,11 +1,5 @@
-
 #pragma once
 
-/*
- * Fall back to Linux's definitions of makedev and major are needed.
- * The search_sysfs_block() function is highly unlikely to work on
- * non-Linux systems anyway.
- */
 #ifndef makedev
 #define makedev(maj, min) (((maj) << 8) + (min))
-#endif
\ No newline at end of file
+#endif
diff --git a/misc/mk_hugefiles.c b/misc/mk_hugefiles.c
index 0280b41e7..3caaf1b68 100644
--- a/misc/mk_hugefiles.c
+++ b/misc/mk_hugefiles.c
@@ -2,13 +2,8 @@
  * mk_hugefiles.c -- create huge files
  */
 
-#define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX in Solaris */
-#define _BSD_SOURCE	  /* for makedev() and major() */
-#define _DEFAULT_SOURCE	  /* since glibc 2.20 _BSD_SOURCE is deprecated */
-
 #include "config.h"
 #include <stdio.h>
-#include <stdarg.h>
 #include <string.h>
 #include <strings.h>
 #include <fcntl.h>
@@ -68,141 +63,30 @@ static char *fn_buf;
 static char *fn_numbuf;
 int zero_hugefile = 1;
 
-#define SYSFS_PATH_LEN 300
-typedef char sysfs_path_t[SYSFS_PATH_LEN];
-
-#ifndef HAVE_SNPRINTF
-/*
- * We are very careful to avoid needing to worry about buffer
- * overflows, so we don't really need to use snprintf() except as an
- * additional safety check.  So if snprintf() is not present, it's
- * safe to fall back to vsprintf().  This provides portability since
- * vsprintf() is guaranteed by C89, while snprintf() is only
- * guaranteed by C99 --- which for example, Microsoft Visual Studio
- * has *still* not bothered to implement.  :-/  (Not that I expect
- * mke2fs to be ported to MS Visual Studio any time soon, but
- * libext2fs *does* get built on Microsoft platforms, and we might
- * want to move this into libext2fs some day.)
- */
-static int my_snprintf(char *str, size_t size, const char *format, ...)
-{
-	va_list	ap;
-	int ret;
-
-	va_start(ap, format);
-	ret = vsprintf(str, format, ap);
-	va_end(ap);
-	return ret;
-}
-
-#define snprintf my_snprintf
-#endif
-
-/*
- * Fall back to Linux's definitions of makedev and major are needed.
- * The search_sysfs_block() function is highly unlikely to work on
- * non-Linux systems anyway.
- */
-#ifndef makedev
-#define makedev(maj, min) (((maj) << 8) + (min))
-#endif
-
-static char *search_sysfs_block(dev_t devno, sysfs_path_t ret_path)
-{
-	struct dirent	*de, *p_de;
-	DIR		*dir = NULL, *p_dir = NULL;
-	FILE		*f;
-	sysfs_path_t	path, p_path;
-	unsigned int	major, minor;
-	char		*ret = ret_path;
-
-	ret_path[0] = 0;
-	if ((dir = opendir("/sys/block")) == NULL)
-		return NULL;
-	while ((de = readdir(dir)) != NULL) {
-		if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..") ||
-		    strlen(de->d_name) > sizeof(path)-32)
-			continue;
-		snprintf(path, SYSFS_PATH_LEN,
-			 "/sys/block/%s/dev", de->d_name);
-		f = fopen(path, "r");
-		if (f &&
-		    (fscanf(f, "%u:%u", &major, &minor) == 2)) {
-			fclose(f); f = NULL;
-			if (makedev(major, minor) == devno) {
-				snprintf(ret_path, SYSFS_PATH_LEN,
-					 "/sys/block/%s", de->d_name);
-				goto success;
-			}
-#ifdef major
-			if (major(devno) != major)
-				continue;
-#endif
-		}
-		if (f)
-			fclose(f);
-
-		snprintf(path, SYSFS_PATH_LEN, "/sys/block/%s", de->d_name);
-
-		if (p_dir)
-			closedir(p_dir);
-		if ((p_dir = opendir(path)) == NULL)
-			continue;
-		while ((p_de = readdir(p_dir)) != NULL) {
-			if (!strcmp(p_de->d_name, ".") ||
-			    !strcmp(p_de->d_name, "..") ||
-			    (strlen(p_de->d_name) >
-			     SYSFS_PATH_LEN - strlen(path) - 32))
-				continue;
-			snprintf(p_path, SYSFS_PATH_LEN, "%s/%s/dev",
-				 path, p_de->d_name);
-
-			f = fopen(p_path, "r");
-			if (f &&
-			    (fscanf(f, "%u:%u", &major, &minor) == 2) &&
-			    (((major << 8) + minor) == devno)) {
-				fclose(f);
-				snprintf(ret_path, SYSFS_PATH_LEN, "%s/%s",
-					 path, p_de->d_name);
-				goto success;
-			}
-			if (f)
-				fclose(f);
-		}
-	}
-	ret = NULL;
-success:
-	if (dir)
-		closedir(dir);
-	if (p_dir)
-		closedir(p_dir);
-	return ret;
-}
-
-static blk64_t get_partition_start(const char *device_name)
+static blk64_t
+get_partition_start(const char *device_name EXT2FS_ATTR((unused)))
 {
+#ifdef __linux__
 	unsigned long long start;
-	sysfs_path_t	path;
+	char		path[128];
 	struct stat	st;
 	FILE		*f;
-	char		*cp;
 	int		n;
 
 	if ((stat(device_name, &st) < 0) || !S_ISBLK(st.st_mode))
 		return 0;
 
-	cp = search_sysfs_block(st.st_rdev, path);
-	if (!cp)
-		return 0;
-	if (strlen(path) > SYSFS_PATH_LEN - sizeof("/start"))
-		return 0;
-	strcat(path, "/start");
+	sprintf(path, "/sys/dev/block/%d:%d/start",
+		major(st.st_rdev), minor(st.st_rdev));
 	f = fopen(path, "r");
 	if (!f)
 		return 0;
 	n = fscanf(f, "%llu", &start);
 	fclose(f);
 	return (n == 1) ? start : 0;
+#else
+	return 0;
+#endif
 }
 
 static errcode_t create_directory(ext2_filsys fs, char *dir,
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 32/38] misc/mke2fs: fix Windows build
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (30 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 31/38] misc/mk_hugefiles: simplify get_partition_start() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 33/38] misc/mke2fs: fix a -Wunused-variable warning in PRS() Eric Biggers
                   ` (6 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Paulo Antonio Alvarez

From: Eric Biggers <ebiggers@google.com>

unix_io_manager is no longer available on Windows.  windows_io_manager
must be used instead.

Fixes: 86b6db9f5a43 ("libext2fs: code adaptation to use the Windows IO manager")
Cc: Paulo Antonio Alvarez <pauloaalvarez@gmail.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 lib/ext2fs/ext2_io.h    |  2 ++
 lib/support/plausible.c |  7 +------
 misc/mke2fs.c           | 12 ++++++------
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index 8fe5b3235..679184e39 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -145,10 +145,12 @@ extern errcode_t io_channel_cache_readahead(io_channel io,
 #ifdef _WIN32
 /* windows_io.c */
 extern io_manager windows_io_manager;
+#define default_io_manager windows_io_manager
 #else
 /* unix_io.c */
 extern io_manager unix_io_manager;
 extern io_manager unixfd_io_manager;
+#define default_io_manager unix_io_manager
 #endif
 
 /* sparse_io.c */
diff --git a/lib/support/plausible.c b/lib/support/plausible.c
index 349aa2c4f..65a6b2e14 100644
--- a/lib/support/plausible.c
+++ b/lib/support/plausible.c
@@ -103,12 +103,7 @@ static void print_ext2_info(const char *device)
 	time_t			tm;
 
 	retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
-#ifdef _WIN32
-			      windows_io_manager,
-#else
-			      unix_io_manager,
-#endif
-                  &fs);
+			      default_io_manager, &fs);
 	if (retval)
 		return;
 	sb = fs->super;
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index bde1e582e..24cc14750 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -1950,10 +1950,10 @@ profile_error:
 #ifdef CONFIG_TESTIO_DEBUG
 		if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
 			io_ptr = test_io_manager;
-			test_io_backing_manager = unix_io_manager;
+			test_io_backing_manager = default_io_manager;
 		} else
 #endif
-			io_ptr = unix_io_manager;
+			io_ptr = default_io_manager;
 		retval = ext2fs_open(journal_device,
 				     EXT2_FLAG_JOURNAL_DEV_OK, 0,
 				     0, io_ptr, &jfs);
@@ -2736,7 +2736,7 @@ static int should_do_undo(const char *name)
 	io_channel channel;
 	__u16	s_magic;
 	struct ext2_super_block super;
-	io_manager manager = unix_io_manager;
+	io_manager manager = default_io_manager;
 	int csum_flag, force_undo;
 
 	csum_flag = ext2fs_has_feature_metadata_csum(&fs_param) ||
@@ -3041,10 +3041,10 @@ int main (int argc, char *argv[])
 #ifdef CONFIG_TESTIO_DEBUG
 	if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
 		io_ptr = test_io_manager;
-		test_io_backing_manager = unix_io_manager;
+		test_io_backing_manager = default_io_manager;
 	} else
 #endif
-		io_ptr = unix_io_manager;
+		io_ptr = default_io_manager;
 
 	if (undo_file != NULL || should_do_undo(device_name)) {
 		retval = mke2fs_setup_tdb(device_name, &io_ptr);
@@ -3449,7 +3449,7 @@ int main (int argc, char *argv[])
 
 		retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
 				     EXT2_FLAG_JOURNAL_DEV_OK, 0,
-				     fs->blocksize, unix_io_manager, &jfs);
+				     fs->blocksize, default_io_manager, &jfs);
 		if (retval) {
 			com_err(program_name, retval,
 				_("while trying to open journal device %s\n"),
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 33/38] misc/mke2fs: fix a -Wunused-variable warning in PRS()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (31 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 32/38] misc/mke2fs: fix Windows build Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 34/38] misc/tune2fs: fix setting fsuuid::fsu_len Eric Biggers
                   ` (5 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

This showed up when building for Windows.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/mke2fs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 24cc14750..7028d3935 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -1598,7 +1598,6 @@ static void PRS(int argc, char *argv[])
 	 * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs.
 	 */
 	blk64_t		fs_blocks_count = 0;
-	long		sysval;
 	int		s_opt = -1, r_opt = -1;
 	char		*fs_features = 0;
 	int		fs_features_size = 0;
@@ -1632,9 +1631,12 @@ static void PRS(int argc, char *argv[])
 #define _SC_PAGESIZE _SC_PAGE_SIZE
 #endif
 #ifdef _SC_PAGESIZE
-	sysval = sysconf(_SC_PAGESIZE);
-	if (sysval > 0)
-		sys_page_size = sysval;
+	{
+		long sysval = sysconf(_SC_PAGESIZE);
+
+		if (sysval > 0)
+			sys_page_size = sysval;
+	}
 #endif /* _SC_PAGESIZE */
 #endif /* HAVE_SYSCONF */
 
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 34/38] misc/tune2fs: fix setting fsuuid::fsu_len
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (32 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 33/38] misc/mke2fs: fix a -Wunused-variable warning in PRS() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 35/38] misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel() Eric Biggers
                   ` (4 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Jeremy Bongio, Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

Minus does not mean equals.

Besides fixing an obvious bug, this avoids the following compiler
warning with clang -Wall:

tune2fs.c:3625:20: warning: expression result unused [-Wunused-value]
                        fsuuid->fsu_len - UUID_SIZE;
                        ~~~~~~~~~~~~~~~ ^ ~~~~~~~~~

Fixes: a83e199da0ca ("tune2fs: Add support for get/set UUID ioctls.")
Reviewed-by: Jeremy Bongio <bongiojp@gmail.com>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/tune2fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 088f87e53..7937b8b56 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -3622,7 +3622,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
 		ret = -1;
 #ifdef __linux__
 		if (fsuuid) {
-			fsuuid->fsu_len - UUID_SIZE;
+			fsuuid->fsu_len = UUID_SIZE;
 			fsuuid->fsu_flags = 0;
 			memcpy(&fsuuid->fsu_uuid, new_uuid, UUID_SIZE);
 			ret = ioctl(fd, EXT4_IOC_SETFSUUID, fsuuid);
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 35/38] misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (33 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 34/38] misc/tune2fs: fix setting fsuuid::fsu_len Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 36/38] misc/util.c: enable MinGW alarm() when building for Windows Eric Biggers
                   ` (3 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

These warnings show up in non-Linux builds.  To fix them, only declare
local variables when they are needed.

While we're here, also make handle_fslabel() static.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/tune2fs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 7937b8b56..d3258149e 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -3082,14 +3082,15 @@ fs_update_journal_user(struct ext2_super_block *sb, __u8 old_uuid[UUID_SIZE])
  *		1 on error
  *		-1 when the old method should be used
  */
-int handle_fslabel(int setlabel) {
+static int handle_fslabel(int setlabel)
+{
+#ifdef __linux__
 	errcode_t ret;
 	int mnt_flags, fd;
 	char label[FSLABEL_MAX];
 	int maxlen = FSLABEL_MAX - 1;
 	char mntpt[PATH_MAX + 1];
 
-#ifdef __linux__
 	ret = ext2fs_check_mount_point(device_name, &mnt_flags,
 					  mntpt, sizeof(mntpt));
 	if (ret) {
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 36/38] misc/util.c: enable MinGW alarm() when building for Windows
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (34 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 35/38] misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 37/38] resize2fs: remove unused variable from adjust_superblock() Eric Biggers
                   ` (2 subsequent siblings)
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

To compile for Windows, this file needs MinGW's implementation of
alarm().  To expose that definition, some macros must be defined before
including the system headers.  This was done in Android.bp, but it was
not done in the autotools-based build system.  Define these macros in
the source file itself so that all build systems work.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 misc/Android.bp | 2 --
 misc/util.c     | 5 +++++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/misc/Android.bp b/misc/Android.bp
index 2baeac2ad..2b1620ac6 100644
--- a/misc/Android.bp
+++ b/misc/Android.bp
@@ -83,8 +83,6 @@ cc_binary {
         windows: {
             include_dirs: [ "external/e2fsprogs/include/mingw" ],
             cflags: [
-                "-D_POSIX",
-                "-D__USE_MINGW_ALARM",
                 // mke2fs.c has a warning from gcc which cannot be suppressed:
                 // passing argument 3 of 'ext2fs_get_device_size' from
                 // incompatible pointer type
diff --git a/misc/util.c b/misc/util.c
index e84ebab5b..3e83169f1 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -16,6 +16,11 @@
 #define _LARGEFILE64_SOURCE
 #endif
 
+#ifdef _WIN32
+#define _POSIX
+#define __USE_MINGW_ALARM
+#endif
+
 #include "config.h"
 #include <fcntl.h>
 #include <setjmp.h>
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 37/38] resize2fs: remove unused variable from adjust_superblock()
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (35 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 36/38] misc/util.c: enable MinGW alarm() when building for Windows Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-21 20:32 ` [PATCH 38/38] Add a configuration file for GitHub Actions Eric Biggers
  2023-01-24 20:59 ` [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Andreas Dilger
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: Lukas Czerner

From: Eric Biggers <ebiggers@google.com>

In adjust_superblock(), the 'group_block' variable is declared and set,
but it is never actually used.  Remove it.

This addresses the following compiler warning with clang -Wall:

resize2fs.c:1119:11: warning: variable 'group_block' set but not used [-Wunused-but-set-variable]
        blk64_t         group_block;
                        ^
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 resize/resize2fs.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 243cd777d..5eeb7d446 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -1116,7 +1116,6 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)
 	ext2_filsys	fs = rfs->new_fs;
 	int		adj = 0;
 	errcode_t	retval;
-	blk64_t		group_block;
 	unsigned long	i;
 	unsigned long	max_group;
 
@@ -1181,8 +1180,6 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)
 		goto errout;
 
 	memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group);
-	group_block = ext2fs_group_first_block2(fs,
-						rfs->old_fs->group_desc_count);
 	adj = rfs->old_fs->group_desc_count;
 	max_group = fs->group_desc_count - adj;
 	if (rfs->progress) {
@@ -1209,7 +1206,6 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size)
 			if (retval)
 				goto errout;
 		}
-		group_block += fs->super->s_blocks_per_group;
 	}
 	io_channel_flush(fs->io);
 	retval = 0;
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* [PATCH 38/38] Add a configuration file for GitHub Actions
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (36 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 37/38] resize2fs: remove unused variable from adjust_superblock() Eric Biggers
@ 2023-01-21 20:32 ` Eric Biggers
  2023-01-24 20:59 ` [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Andreas Dilger
  38 siblings, 0 replies; 41+ messages in thread
From: Eric Biggers @ 2023-01-21 20:32 UTC (permalink / raw)
  To: linux-ext4

From: Eric Biggers <ebiggers@google.com>

Add a workflow file for GitHub Actions, with jobs that build and test
e2fsprogs on various platforms with various options.

The workflow is configured to run on pushes only, since e2fsprogs does
not use GitHub pull requests.

This will work on any e2fsprogs fork on Github that has GitHub Actions
enabled.  For example, the results for the testing I've been doing are
at https://github.com/ebiggers/e2fsprogs/actions.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 .github/workflows/ci.yml | 116 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 .github/workflows/ci.yml

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 000000000..29482178d
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,116 @@
+name: CI
+on: [push]
+env:
+  DEF_CFLAGS: -O2 -g -Wall
+
+jobs:
+  gcc-build-and-test:
+    name: Build and test with gcc
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - run: ./configure CC=gcc CFLAGS="$DEF_CFLAGS"
+    - run: make -j8 check V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 install V=1 DESTDIR=$PWD/installdir
+    - run: make -j8 uninstall V=1 DESTDIR=$PWD/installdir
+
+  clang-build-and-test:
+    name: Build and test with clang
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: Install dependencies
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y clang
+    - run: ./configure CC=clang CFLAGS="$DEF_CFLAGS"
+    - run: make -j8 check V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 install V=1 DESTDIR=$PWD/installdir
+    - run: make -j8 uninstall V=1 DESTDIR=$PWD/installdir
+
+  i386-build-and-test:
+    name: Build and test with gcc -m32
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: Install dependencies
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y gcc-multilib
+    - run: ./configure CC=gcc CFLAGS="$DEF_CFLAGS -m32" LDFLAGS="-m32"
+    - run: make -j8 check V=1 CFLAGS="$DEF_CFLAGS -m32 -Werror"
+    - run: make -j8 install V=1 DESTDIR=$PWD/installdir
+    - run: make -j8 uninstall V=1 DESTDIR=$PWD/installdir
+
+  asan-build-and-test:
+    name: Build and test with ASAN enabled
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: Install dependencies
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y clang
+    - run: echo "ASAN_CFLAGS=$DEF_CFLAGS -fsanitize=address -fno-sanitize-recover=address" >> $GITHUB_ENV
+    - run: ./configure CC=clang CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
+    - run: make -j8 check V=1 CFLAGS="$ASAN_CFLAGS -Werror"
+
+  ubsan-build-and-test:
+    name: Build and test with UBSAN enabled
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v2
+    - name: Install dependencies
+      run: |
+        sudo apt-get update
+        sudo apt-get install -y clang
+    - run: echo "UBSAN_CFLAGS=$DEF_CFLAGS -fsanitize=undefined -fno-sanitize-recover=undefined" >> $GITHUB_ENV
+    - run: ./configure CC=clang CFLAGS="$UBSAN_CFLAGS" LDFLAGS="$UBSAN_CFLAGS"
+    - run: make -j8 check V=1 CFLAGS="$UBSAN_CFLAGS -Werror"
+
+  macos-build-and-test:
+    name: Build and test on macOS
+    runs-on: macos-latest
+    steps:
+    - uses: actions/checkout@v2
+    - run: ./configure CFLAGS="$DEF_CFLAGS"
+      # -Wno-error=deprecated-declarations is needed to suppress known warnings
+      # due to e2fsprogs' use of sbrk(0) and daemon().
+    - run: make -j8 check V=1 CFLAGS="$DEF_CFLAGS -Werror -Wno-error=deprecated-declarations"
+    - run: make -j8 install DESTDIR=$PWD/installdir
+    - run: make -j8 uninstall DESTDIR=$PWD/installdir
+
+  windows-msys2-build:
+    name: Build mke2fs on Windows with ${{matrix.sys}}
+    runs-on: windows-latest
+    strategy:
+      matrix:
+        include:
+        - { sys: mingw32, env: i686 }
+        - { sys: mingw64, env: x86_64 }
+    defaults:
+      run:
+        shell: msys2 {0}
+    steps:
+    - uses: actions/checkout@v2
+    - uses: msys2/setup-msys2@v2
+      with:
+        msystem: ${{matrix.sys}}
+        update: true
+        install: >
+          make
+          mingw-w64-${{matrix.env}}-cc
+    # For now the only parts that actually build for Windows are mke2fs and its
+    # dependencies: all libraries except libss.  The build system doesn't want
+    # to build just those parts, though, so do it one step at a time...
+    - run: ./configure CFLAGS="$DEF_CFLAGS"
+    - run: make -j8 subs V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/et/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/uuid/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/blkid/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/ext2fs/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/support/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C lib/e2p/ all V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: make -j8 -C misc/ mke2fs V=1 CFLAGS="$DEF_CFLAGS -Werror"
+    - run: touch image.ext4
+    - run: misc/mke2fs.exe -T ext4 image.ext4 128M
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 41+ messages in thread

* Re: [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly
  2023-01-21 20:31 ` [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly Eric Biggers
@ 2023-01-24 18:21   ` Andreas Dilger
  0 siblings, 0 replies; 41+ messages in thread
From: Andreas Dilger @ 2023-01-24 18:21 UTC (permalink / raw)
  To: Eric Biggers, Theodore Ts'o; +Cc: linux-ext4

[-- Attachment #1: Type: text/plain, Size: 2779 bytes --]

On Jan 21, 2023, at 1:31 PM, Eric Biggers <ebiggers@kernel.org> wrote:
> 
> From: Eric Biggers <ebiggers@google.com>
> 
> libblkid contains 32-bit x86 assembly language implementations of 16-bit
> and 32-bit byteswaps.  However, modern compilers can easily generate the
> bswap instruction automatically from the corresponding C expression.
> And no one ever bothered to add assembly for x86_64 or other
> architectures, anyway.  So let's just remove this outdated code, which
> was maybe useful in the 90s, but is no longer useful.

I'm not sure what Ted thinks about this, but it might be time to remove
the libblkid implementation in e2fsprogs, and instead depend on the
newer version in util-linux?  However, removing it from e2fsprogs
would add an external dependency on util-linux for non-linux platforms,
though AFAIK it should still be possible to build e2fsprogs without it.

That said, I think the current patch looks fine, and you can add:

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

Cheers, Andreas

> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> lib/blkid/probe.h | 43 -------------------------------------------
> 1 file changed, 43 deletions(-)
> 
> diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h
> index dea4081d0..063a5b5c0 100644
> --- a/lib/blkid/probe.h
> +++ b/lib/blkid/probe.h
> @@ -814,46 +814,6 @@ struct exfat_entry_label {
> #define _INLINE_ static inline
> #endif
> 
> -static __u16 blkid_swab16(__u16 val);
> -static __u32 blkid_swab32(__u32 val);
> -static __u64 blkid_swab64(__u64 val);
> -
> -#if ((defined __GNUC__) && \
> -     (defined(__i386__) || defined(__i486__) || defined(__i586__)))
> -
> -#define _BLKID_HAVE_ASM_BITOPS_
> -
> -_INLINE_ __u32 blkid_swab32(__u32 val)
> -{
> -#ifdef EXT2FS_REQUIRE_486
> -	__asm__("bswap %0" : "=r" (val) : "0" (val));
> -#else
> -	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
> -		"rorl $16,%0\n\t"	/* swap words		*/
> -		"xchgb %b0,%h0"		/* swap higher bytes	*/
> -		:"=q" (val)
> -		: "0" (val));
> -#endif
> -	return val;
> -}
> -
> -_INLINE_ __u16 blkid_swab16(__u16 val)
> -{
> -	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
> -		: "=q" (val) \
> -		:  "0" (val)); \
> -		return val;
> -}
> -
> -_INLINE_ __u64 blkid_swab64(__u64 val)
> -{
> -	return (blkid_swab32(val >> 32) |
> -		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
> -}
> -#endif
> -
> -#if !defined(_BLKID_HAVE_ASM_BITOPS_)
> -
> _INLINE_  __u16 blkid_swab16(__u16 val)
> {
> 	return (val >> 8) | (val << 8);
> @@ -870,9 +830,6 @@ _INLINE_ __u64 blkid_swab64(__u64 val)
> 	return (blkid_swab32(val >> 32) |
> 		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
> }
> -#endif
> -
> -
> 
> #ifdef WORDS_BIGENDIAN
> #define blkid_le16(x) blkid_swab16(x)
> --
> 2.39.0
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file
  2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
                   ` (37 preceding siblings ...)
  2023-01-21 20:32 ` [PATCH 38/38] Add a configuration file for GitHub Actions Eric Biggers
@ 2023-01-24 20:59 ` Andreas Dilger
  38 siblings, 0 replies; 41+ messages in thread
From: Andreas Dilger @ 2023-01-24 20:59 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-ext4

[-- Attachment #1: Type: text/plain, Size: 6015 bytes --]

On Jan 21, 2023, at 1:31 PM, Eric Biggers <ebiggers@kernel.org> wrote:
> 
> The last patch of this series adds a workflow file for GitHub Actions
> that builds and tests e2fsprogs on Ubuntu, macOS, and Windows.  It's
> enforced that the build does not produce warnings with -Wall.
> 
> (For now, the Windows build is much more basic than the others; only
> mke2fs is built, and the unit tests are not run.)
> 
> The workflow will run on pushes to any fork of e2fsprogs that has GitHub
> Actions enabled.  I'm hoping that Ted will enable it for the "official"
> fork at https://github.com/tytso/e2fsprogs, but anyone can use it in
> their own fork too.  The results for this patch series are at
> https://github.com/ebiggers/e2fsprogs/actions/runs/3976382057
> 
> As a prerequisite to actually getting everything to pass, patches 1-37
> of this series fix a large number of miscellaneous issues, mainly
> pertaining to warnings with -Wall or to the Windows build.

Thanks in advance for this patch series.  I have a kick at the cat for
e2fsprogs build/test warnings occasionally, but getting this into a
Github CI setup should keep them out of the woodwork.

I'll try to have a pass through all of the patches, but most of them
seem pretty straight forward.

Cheers, Andreas

> Some patches in this series I've already sent out individually.  This
> series supersedes all my previous patches.
> 
> Eric Biggers (38):
>  configure.ac: only use Windows I/O manager on native Windows
>  configure.ac: disable tdb by default on Windows
>  configure.ac: automatically add include/mingw/ headers
>  configure: regenerate
>  config/install-sh: update to latest version
>  lib, misc: eliminate dependency on Winsock
>  lib/blkid: remove 32-bit x86 byteswap assembly
>  lib/blkid: fix unaligned access to hfs_mdb
>  lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size()
>  lib/blkid: suppress -Wunused-result warning in blkid_flush_cache()
>  lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup()
>  lib/e2p: fix a -Wunused-variable warning in getflags()
>  lib/{e2p,ss}: remove manual declarations of errno
>  lib/et: fix "unused variable" warnings when !HAVE_FCNTL
>  lib/ext2fs: remove 32-bit x86 bitops assembly
>  lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics()
>  lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode()
>  lib/ext2fs: fix a printf format specifier in file_test()
>  lib/ext2fs: fix two compiler warnings in windows_io.c
>  lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start()
>  lib/{ext2fs,support}: fix 32-bit Windows build
>  lib/ss: fix 'make install' by creating man1dir
>  lib/support: remove unused label in get_devname()
>  lib/support: clean up definition of flags_array
>  lib/uuid: remove conflicting Windows implementation of gettimeofday()
>  e2fsck: use real functions for kernel slab functions
>  misc/create_inode: fix -Wunused-variable warnings in __populate_fs()
>  misc/create_inode: simplify logic in scandir()
>  misc/e4defrag: fix -Wstringop-truncation warnings
>  misc/fuse2fs: avoid error-prone strncpy() pattern
>  misc/mk_hugefiles: simplify get_partition_start()
>  misc/mke2fs: fix Windows build
>  misc/mke2fs: fix a -Wunused-variable warning in PRS()
>  misc/tune2fs: fix setting fsuuid::fsu_len
>  misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel()
>  misc/util.c: enable MinGW alarm() when building for Windows
>  resize2fs: remove unused variable from adjust_superblock()
>  Add a configuration file for GitHub Actions
> 
> .github/workflows/ci.yml      | 116 ++++++
> aclocal.m4                    | 180 +++++----
> config/install-sh             | 683 ++++++++++++++++++++++++----------
> configure                     | 105 ++++--
> configure.ac                  |  50 ++-
> e2fsck/jfs_user.h             |  62 ++-
> include/mingw/arpa/inet.h     |   5 +
> include/mingw/sys/sysmacros.h |   8 +-
> lib/blkid/Android.bp          |   1 -
> lib/blkid/devno.c             |  10 +
> lib/blkid/getsize.c           |   2 +-
> lib/blkid/probe.c             |  10 +-
> lib/blkid/probe.h             |  43 ---
> lib/blkid/save.c              |   8 +
> lib/config.h.in               | 100 ++++-
> lib/e2p/Android.bp            |   4 -
> lib/e2p/fgetversion.c         |   2 -
> lib/e2p/fsetversion.c         |   1 -
> lib/e2p/getflags.c            |   3 +-
> lib/e2p/getversion.c          |   1 -
> lib/e2p/setversion.c          |   1 -
> lib/et/Android.bp             |   3 -
> lib/et/error_message.c        |  10 +-
> lib/ext2fs/Android.bp         |   2 -
> lib/ext2fs/bitops.c           |  14 +-
> lib/ext2fs/bitops.h           |  97 -----
> lib/ext2fs/ext2_io.h          |   2 +
> lib/ext2fs/ext_attr.c         |   2 -
> lib/ext2fs/gen_bitmap64.c     |   6 +-
> lib/ext2fs/getsectsize.c      |  12 +-
> lib/ext2fs/inline_data.c      |   2 +-
> lib/ext2fs/jfs_compat.h       |   4 -
> lib/ext2fs/mmp.c              |   2 +-
> lib/ext2fs/windows_io.c       |  12 +-
> lib/ss/Makefile.in            |   5 +-
> lib/ss/execute_cmd.c          |   2 -
> lib/ss/help.c                 |   2 -
> lib/ss/pager.c                |   2 -
> lib/support/devname.c         |   1 -
> lib/support/plausible.c       |   7 +-
> lib/support/print_fs_flags.c  |  60 +--
> lib/uuid/gen_uuid.c           |  21 --
> misc/Android.bp               |   3 -
> misc/create_inode.c           |  36 +-
> misc/e4defrag.c               |  30 +-
> misc/fuse2fs.c                |   5 +-
> misc/mk_hugefiles.c           | 134 +------
> misc/mke2fs.c                 |  22 +-
> misc/tune2fs.c                |   7 +-
> misc/util.c                   |   5 +
> resize/resize2fs.c            |   4 -
> util/android_config.h         |   1 -
> util/subst.c                  |   4 +-
> 53 files changed, 1102 insertions(+), 812 deletions(-)
> create mode 100644 .github/workflows/ci.yml
> create mode 100644 include/mingw/arpa/inet.h
> 
> 
> base-commit: aad34909b6648579f42dade5af5b46821aa4d845
> --
> 2.39.0
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2023-01-24 20:59 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21 20:31 [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Eric Biggers
2023-01-21 20:31 ` [PATCH 01/38] configure.ac: only use Windows I/O manager on native Windows Eric Biggers
2023-01-21 20:31 ` [PATCH 02/38] configure.ac: disable tdb by default on Windows Eric Biggers
2023-01-21 20:31 ` [PATCH 03/38] configure.ac: automatically add include/mingw/ headers Eric Biggers
2023-01-21 20:31 ` [PATCH 04/38] configure: regenerate Eric Biggers
2023-01-21 20:31 ` [PATCH 05/38] config/install-sh: update to latest version Eric Biggers
2023-01-21 20:31 ` [PATCH 06/38] lib, misc: eliminate dependency on Winsock Eric Biggers
2023-01-21 20:31 ` [PATCH 07/38] lib/blkid: remove 32-bit x86 byteswap assembly Eric Biggers
2023-01-24 18:21   ` Andreas Dilger
2023-01-21 20:32 ` [PATCH 08/38] lib/blkid: fix unaligned access to hfs_mdb Eric Biggers
2023-01-21 20:32 ` [PATCH 09/38] lib/blkid: fix -Wunused-variable warning in blkid_get_dev_size() Eric Biggers
2023-01-21 20:32 ` [PATCH 10/38] lib/blkid: suppress -Wunused-result warning in blkid_flush_cache() Eric Biggers
2023-01-21 20:32 ` [PATCH 11/38] lib/blkid: suppress -Wstringop-truncation warning in blkid_strndup() Eric Biggers
2023-01-21 20:32 ` [PATCH 12/38] lib/e2p: fix a -Wunused-variable warning in getflags() Eric Biggers
2023-01-21 20:32 ` [PATCH 13/38] lib/{e2p,ss}: remove manual declarations of errno Eric Biggers
2023-01-21 20:32 ` [PATCH 14/38] lib/et: fix "unused variable" warnings when !HAVE_FCNTL Eric Biggers
2023-01-21 20:32 ` [PATCH 15/38] lib/ext2fs: remove 32-bit x86 bitops assembly Eric Biggers
2023-01-21 20:32 ` [PATCH 16/38] lib/ext2fs: consistently use #ifdefs in ext2fs_print_bmap_statistics() Eric Biggers
2023-01-21 20:32 ` [PATCH 17/38] lib/ext2fs: remove unused variable in ext2fs_xattrs_read_inode() Eric Biggers
2023-01-21 20:32 ` [PATCH 18/38] lib/ext2fs: fix a printf format specifier in file_test() Eric Biggers
2023-01-21 20:32 ` [PATCH 19/38] lib/ext2fs: fix two compiler warnings in windows_io.c Eric Biggers
2023-01-21 20:32 ` [PATCH 20/38] lib/ext2fs: fix a -Wpointer-sign warning in ext2fs_mmp_start() Eric Biggers
2023-01-21 20:32 ` [PATCH 21/38] lib/{ext2fs,support}: fix 32-bit Windows build Eric Biggers
2023-01-21 20:32 ` [PATCH 22/38] lib/ss: fix 'make install' by creating man1dir Eric Biggers
2023-01-21 20:32 ` [PATCH 23/38] lib/support: remove unused label in get_devname() Eric Biggers
2023-01-21 20:32 ` [PATCH 24/38] lib/support: clean up definition of flags_array Eric Biggers
2023-01-21 20:32 ` [PATCH 25/38] lib/uuid: remove conflicting Windows implementation of gettimeofday() Eric Biggers
2023-01-21 20:32 ` [PATCH 26/38] e2fsck: use real functions for kernel slab functions Eric Biggers
2023-01-21 20:32 ` [PATCH 27/38] misc/create_inode: fix -Wunused-variable warnings in __populate_fs() Eric Biggers
2023-01-21 20:32 ` [PATCH 28/38] misc/create_inode: simplify logic in scandir() Eric Biggers
2023-01-21 20:32 ` [PATCH 29/38] misc/e4defrag: fix -Wstringop-truncation warnings Eric Biggers
2023-01-21 20:32 ` [PATCH 30/38] misc/fuse2fs: avoid error-prone strncpy() pattern Eric Biggers
2023-01-21 20:32 ` [PATCH 31/38] misc/mk_hugefiles: simplify get_partition_start() Eric Biggers
2023-01-21 20:32 ` [PATCH 32/38] misc/mke2fs: fix Windows build Eric Biggers
2023-01-21 20:32 ` [PATCH 33/38] misc/mke2fs: fix a -Wunused-variable warning in PRS() Eric Biggers
2023-01-21 20:32 ` [PATCH 34/38] misc/tune2fs: fix setting fsuuid::fsu_len Eric Biggers
2023-01-21 20:32 ` [PATCH 35/38] misc/tune2fs: fix -Wunused-variable warnings in handle_fslabel() Eric Biggers
2023-01-21 20:32 ` [PATCH 36/38] misc/util.c: enable MinGW alarm() when building for Windows Eric Biggers
2023-01-21 20:32 ` [PATCH 37/38] resize2fs: remove unused variable from adjust_superblock() Eric Biggers
2023-01-21 20:32 ` [PATCH 38/38] Add a configuration file for GitHub Actions Eric Biggers
2023-01-24 20:59 ` [PATCH 00/38] e2fsprogs: misc fixes, and add a GitHub Actions file Andreas Dilger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.