]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: emulate deprecated attrlist functionality in libattr
authorDarrick J. Wong <djwong@kernel.org>
Tue, 1 Oct 2024 00:06:22 +0000 (17:06 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 2 Oct 2024 00:54:48 +0000 (17:54 -0700)
Break our dependence on the (deprecated) libattr by emulating the
necessary pieces in libfrog.  It's a little sketchy to open-code these
symbols, but they're originally from XFS so we trust ourselves.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
configure.ac
debian/control
include/builddefs.in
libfrog/Makefile
libfrog/fakelibattr.h [new file with mode: 0644]
libfrog/fsprops.c
m4/package_attr.m4 [deleted file]
scrub/Makefile
scrub/phase5.c

index 33b01399ae3b002135826313966a7d8416a0a9a0..d021c519d5383e22768550c263fb41fe926f5d43 100644 (file)
@@ -152,8 +152,6 @@ AC_HAVE_DEVMAPPER
 AC_HAVE_MALLINFO
 AC_HAVE_MALLINFO2
 AC_HAVE_MEMFD_CREATE
-AC_PACKAGE_WANT_ATTRIBUTES_H
-AC_HAVE_LIBATTR
 if test "$enable_scrub" = "yes"; then
         if test "$enable_libicu" = "yes" || test "$enable_libicu" = "probe"; then
                 AC_HAVE_LIBICU
index 3f05d4e3797cf929baabe0f4fd2ae1564f771030..66b0a47a36ee246188d73ced70efc5e126e6d1a6 100644 (file)
@@ -3,7 +3,7 @@ Section: admin
 Priority: optional
 Maintainer: XFS Development Team <linux-xfs@vger.kernel.org>
 Uploaders: Nathan Scott <nathans@debian.org>, Anibal Monsalve Salazar <anibal@debian.org>, Bastian Germann <bage@debian.org>
-Build-Depends: libinih-dev (>= 53), uuid-dev, debhelper (>= 12), gettext, libtool, libedit-dev, libblkid-dev (>= 2.17), linux-libc-dev, libdevmapper-dev, libattr1-dev, libicu-dev, pkg-config, liburcu-dev, systemd-dev | systemd (<< 253-2~)
+Build-Depends: libinih-dev (>= 53), uuid-dev, debhelper (>= 12), gettext, libtool, libedit-dev, libblkid-dev (>= 2.17), linux-libc-dev, libdevmapper-dev, libicu-dev, pkg-config, liburcu-dev, systemd-dev | systemd (<< 253-2~)
 Standards-Version: 4.0.0
 Homepage: https://xfs.wiki.kernel.org/
 
index 1647d2cd1690903edf2f1577a26e451e86d7fd0f..07c4a43f78a01c7c1783c5e4bde58741360a1c96 100644 (file)
@@ -102,7 +102,6 @@ HAVE_DEVMAPPER = @have_devmapper@
 HAVE_MALLINFO = @have_mallinfo@
 HAVE_MALLINFO2 = @have_mallinfo2@
 HAVE_MEMFD_CREATE = @have_memfd_create@
-HAVE_LIBATTR = @have_libattr@
 HAVE_LIBICU = @have_libicu@
 HAVE_SYSTEMD = @have_systemd@
 SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
index acddc894ee9395d53a6a37dcd3d244b534a9fe42..4da427789411a6031d2019888107f99fd2bcbfae 100644 (file)
@@ -21,6 +21,7 @@ crc32.c \
 file_exchange.c \
 fsgeom.c \
 fsproperties.c \
+fsprops.c \
 getparents.c \
 histogram.c \
 list_sort.c \
@@ -46,9 +47,11 @@ crc32defs.h \
 crc32table.h \
 dahashselftest.h \
 div64.h \
+fakelibattr.h \
 file_exchange.h \
 fsgeom.h \
 fsproperties.h \
+fsprops.h \
 getparents.h \
 histogram.h \
 logging.h \
@@ -62,11 +65,6 @@ workqueue.h
 
 LSRCFILES += gen_crc32table.c
 
-ifeq ($(HAVE_LIBATTR),yes)
-CFILES+=fsprops.c
-HFILES+=fsprops.h
-endif
-
 LDIRT = gen_crc32table crc32table.h
 
 default: ltdepend $(LTLIBRARY)
diff --git a/libfrog/fakelibattr.h b/libfrog/fakelibattr.h
new file mode 100644 (file)
index 0000000..30e0e51
--- /dev/null
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef __LIBFROG_FAKELIBATTR_H__
+#define __LIBFROG_FAKELIBATTR_H__
+
+/* This file emulates APIs from the deprecated libattr. */
+
+struct attrlist_cursor;
+
+static inline struct xfs_attrlist_ent *
+libfrog_attr_entry(
+       struct xfs_attrlist     *list,
+       unsigned int            index)
+{
+       char                    *buffer = (char *)list;
+
+       return (struct xfs_attrlist_ent *)&buffer[list->al_offset[index]];
+}
+
+static inline int
+libfrog_attr_list_by_handle(
+       void                            *hanp,
+       size_t                          hlen,
+       void                            *buf,
+       size_t                          bufsize,
+       int                             flags,
+       struct xfs_attrlist_cursor      *cursor)
+{
+       return attr_list_by_handle(hanp, hlen, buf, bufsize, flags,
+                       (struct attrlist_cursor *)cursor);
+}
+
+#endif /* __LIBFROG_FAKELIBATTR_H__ */
index a25c2726cd5868ce6124a2c4ec263854619c506f..f59fbd9c21650e31a8a71f14d636ccbaa1371596 100644 (file)
@@ -10,8 +10,7 @@
 #include "libfrog/bulkstat.h"
 #include "libfrog/fsprops.h"
 #include "libfrog/fsproperties.h"
-
-#include <attr/attributes.h>
+#include "libfrog/fakelibattr.h"
 
 /*
  * Given an xfd and a mount table path, get us the handle for the root dir so
@@ -68,21 +67,22 @@ fsprops_walk_names(
        fsprops_name_walk_fn    walk_fn,
        void                    *priv)
 {
-       struct attrlist_cursor  cur = { };
-       struct attrlist         *attrlist;
+       struct xfs_attrlist_cursor cur = { };
+       struct xfs_attrlist     *attrlist;
        int                     ret;
 
        attrlist = calloc(XFS_XATTR_LIST_MAX, 1);
        if (!attrlist)
                return -1;
 
-       while ((ret = attr_list_by_handle(fph->hanp, fph->hlen, attrlist,
-                               XFS_XATTR_LIST_MAX, XFS_IOC_ATTR_ROOT,
-                               &cur)) == 0) {
+       while ((ret = libfrog_attr_list_by_handle(fph->hanp, fph->hlen,
+                               attrlist, XFS_XATTR_LIST_MAX,
+                               XFS_IOC_ATTR_ROOT, &cur)) == 0) {
                unsigned int    i;
 
                for (i = 0; i < attrlist->al_count; i++) {
-                       struct attrlist_ent     *ent = ATTR_ENTRY(attrlist, i);
+                       struct xfs_attrlist_ent *ent =
+                               libfrog_attr_entry(attrlist, i);
                        const char              *p =
                                attr_name_to_fsprop_name(ent->a_name);
 
diff --git a/m4/package_attr.m4 b/m4/package_attr.m4
deleted file mode 100644 (file)
index 05e02b3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-AC_DEFUN([AC_PACKAGE_WANT_ATTRIBUTES_H],
-  [
-    AC_CHECK_HEADERS(attr/attributes.h)
-  ])
-
-#
-# Check if we have a ATTR_ROOT flag and libattr structures
-#
-AC_DEFUN([AC_HAVE_LIBATTR],
-  [ AC_MSG_CHECKING([for struct attrlist_cursor])
-    AC_COMPILE_IFELSE(
-    [  AC_LANG_PROGRAM([[
-#include <sys/types.h>
-#include <attr/attributes.h>
-       ]], [[
-struct attrlist_cursor *cur;
-struct attrlist *list;
-struct attrlist_ent *ent;
-int flags = ATTR_ROOT;
-       ]])
-    ], have_libattr=yes
-          AC_MSG_RESULT(yes),
-          AC_MSG_RESULT(no))
-    AC_SUBST(have_libattr)
-  ])
index 53e8cb02a92621e4c0a6715efb6b348e913218c0..1e1109048c2a83ec9b5fe9bf556fc3b4d2fd08be 100644 (file)
@@ -100,10 +100,6 @@ ifeq ($(HAVE_MALLINFO2),yes)
 LCFLAGS += -DHAVE_MALLINFO2
 endif
 
-ifeq ($(HAVE_LIBATTR),yes)
-LCFLAGS += -DHAVE_LIBATTR
-endif
-
 ifeq ($(HAVE_LIBICU),yes)
 CFILES += unicrash.c
 LCFLAGS += -DHAVE_LIBICU $(LIBICU_CFLAGS)
index d298d628a998649d61f39fc7a5468cb8222f72d6..e1d94f9a3568b14724d141199c66d5b1c9e49899 100644 (file)
@@ -8,9 +8,6 @@
 #include <dirent.h>
 #include <sys/types.h>
 #include <sys/statvfs.h>
-#ifdef HAVE_LIBATTR
-# include <attr/attributes.h>
-#endif
 #include <linux/fs.h>
 #include "handle.h"
 #include "list.h"
@@ -20,6 +17,7 @@
 #include "libfrog/scrub.h"
 #include "libfrog/bitmap.h"
 #include "libfrog/bulkstat.h"
+#include "libfrog/fakelibattr.h"
 #include "xfs_scrub.h"
 #include "common.h"
 #include "inodes.h"
@@ -164,7 +162,6 @@ out_unicrash:
        return ret;
 }
 
-#ifdef HAVE_LIBATTR
 /* Routines to scan all of an inode's xattrs for name problems. */
 struct attrns_decode {
        int                     flags;
@@ -173,8 +170,8 @@ struct attrns_decode {
 
 static const struct attrns_decode attr_ns[] = {
        {0,                     "user"},
-       {ATTR_ROOT,             "system"},
-       {ATTR_SECURE,           "secure"},
+       {XFS_IOC_ATTR_ROOT,     "system"},
+       {XFS_IOC_ATTR_SECURE,   "secure"},
        {0, NULL},
 };
 
@@ -190,9 +187,9 @@ check_xattr_ns_names(
        struct xfs_bulkstat             *bstat,
        const struct attrns_decode      *attr_ns)
 {
-       struct attrlist_cursor          cur = { };
+       struct xfs_attrlist_cursor      cur = { };
        char                            *keybuf;
-       struct attrlist                 *attrlist;
+       struct xfs_attrlist             *attrlist;
        struct unicrash                 *uc = NULL;
        int                             i;
        int                             error;
@@ -217,12 +214,13 @@ check_xattr_ns_names(
                goto out_keybuf;
        }
 
-       while ((error = attr_list_by_handle(handle, sizeof(*handle), attrlist,
-                               XFS_XATTR_LIST_MAX, attr_ns->flags,
+       while ((error = libfrog_attr_list_by_handle(handle, sizeof(*handle),
+                               attrlist, XFS_XATTR_LIST_MAX, attr_ns->flags,
                                &cur)) == 0) {
                /* Examine the xattrs. */
                for (i = 0; i < attrlist->al_count; i++) {
-                       struct attrlist_ent     *ent = ATTR_ENTRY(attrlist, i);
+                       struct xfs_attrlist_ent *ent =
+                                       libfrog_attr_entry(attrlist, i);
 
                        snprintf(keybuf, XATTR_NAME_MAX, "%s.%s", attr_ns->name,
                                        ent->a_name);
@@ -279,9 +277,6 @@ check_xattr_names(
        }
        return ret;
 }
-#else
-# define check_xattr_names(c, d, h, b) (0)
-#endif /* HAVE_LIBATTR */
 
 static int
 render_ino_from_handle(