]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: refactor namecheck functions
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 6 Jun 2019 13:58:55 +0000 (08:58 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 6 Jun 2019 13:58:55 +0000 (08:58 -0500)
Now that we have name check functions in libxfs, use them instead of our
custom versions.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_api_defs.h
repair/attr_repair.c
repair/da_util.c
repair/da_util.h
repair/dir2.c

index 34bb552d89ba15d63695343a78b527594b847b78..71a7ef53fe5c6c3393fcd8dfd5c3f862c61a3824 100644 (file)
 #define xfs_default_ifork_ops          libxfs_default_ifork_ops
 #define xfs_fs_geometry                        libxfs_fs_geometry
 #define xfs_init_local_fork            libxfs_init_local_fork
+#define xfs_dir2_namecheck             libxfs_dir2_namecheck
+#define xfs_attr_namecheck             libxfs_attr_namecheck
 
 #define LIBXFS_ATTR_ROOT               ATTR_ROOT
 #define LIBXFS_ATTR_SECURE             ATTR_SECURE
index 5ad81c091ea4d3317d1288ee07166ea6e700a52b..9a44f61042df4d683a6c9506e8e99fb4353c3eec 100644 (file)
@@ -122,14 +122,6 @@ set_da_freemap(xfs_mount_t *mp, da_freemap_t *map, int start, int stop)
  * fork being emptied and put in shortform format.
  */
 
-static int
-attr_namecheck(
-       uint8_t *name,
-       int     length)
-{
-       return namecheck((char *)name, length, false);
-}
-
 /*
  * This routine just checks what security needs are for attribute values
  * only called when root flag is set, otherwise these names could exist in
@@ -301,8 +293,8 @@ process_shortform_attr(
                }
 
                /* namecheck checks for null chars in attr names. */
-               if (attr_namecheck(currententry->nameval,
-                                               currententry->namelen)) {
+               if (!libxfs_attr_namecheck(currententry->nameval,
+                                          currententry->namelen)) {
                        do_warn(
        _("entry contains illegal character in shortform attribute name\n"));
                        junkit = 1;
@@ -464,8 +456,9 @@ process_leaf_attr_local(
        xfs_attr_leaf_name_local_t *local;
 
        local = xfs_attr3_leaf_name_local(leaf, i);
-       if (local->namelen == 0 || attr_namecheck(local->nameval,
-                                                       local->namelen)) {
+       if (local->namelen == 0 ||
+           !libxfs_attr_namecheck(local->nameval,
+                                  local->namelen)) {
                do_warn(
        _("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),
                        i, da_bno, ino, local->namelen);
@@ -519,13 +512,14 @@ process_leaf_attr_remote(
 
        remotep = xfs_attr3_leaf_name_remote(leaf, i);
 
-       if (remotep->namelen == 0 || attr_namecheck(remotep->name,
-                                               remotep->namelen) ||
-                       be32_to_cpu(entry->hashval) !=
-                               libxfs_da_hashname((unsigned char *)&remotep->name[0],
-                                               remotep->namelen) ||
-                       be32_to_cpu(entry->hashval) < last_hashval ||
-                       be32_to_cpu(remotep->valueblk) == 0) {
+       if (remotep->namelen == 0 ||
+           !libxfs_attr_namecheck(remotep->name,
+                                  remotep->namelen) ||
+           be32_to_cpu(entry->hashval) !=
+                       libxfs_da_hashname((unsigned char *)&remotep->name[0],
+                                          remotep->namelen) ||
+           be32_to_cpu(entry->hashval) < last_hashval ||
+           be32_to_cpu(remotep->valueblk) == 0) {
                do_warn(
        _("inconsistent remote attribute entry %d in attr block %u, ino %" PRIu64 "\n"), i, da_bno, ino);
                return -1;
index 4a258e584e2a1b3a486e0db8c766ec223f83c052..8c818ea1a9e77b243f742e735816f2ec0033d5dd 100644 (file)
 #include "bmap.h"
 #include "da_util.h"
 
-/*
- * Takes a name and length (name need not be null-terminated) and whether
- * we are checking a dir (as opposed to an attr).
- * Returns 1 if the name contains a NUL or if a directory entry contains a '/'.
- * Returns 0 if the name checks out.
- */
-int
-namecheck(
-       char    *name,
-       int     length,
-       bool    isadir)
-{
-       char    *c;
-       int     i;
-
-       ASSERT(length < MAXNAMELEN);
-
-       for (c = name, i = 0; i < length; i++, c++) {
-               if (isadir && *c == '/')
-                       return 1;
-               if (*c == '\0')
-                       return 1;
-       }
-
-       return 0;
-}
-
 /*
  * the cursor gets passed up and down the da btree processing
  * routines.  The interior block processing routines use the
index 041dff748d8e758689883cd907b59a6ce259c740..90fec00c7addec87bfacca9b4d9cd04ffee086f1 100644 (file)
@@ -24,12 +24,6 @@ typedef struct da_bt_cursor {
        struct blkmap           *blkmap;
 } da_bt_cursor_t;
 
-int
-namecheck(
-       char            *name,
-       int             length,
-       bool            isadir);
-
 struct xfs_buf *
 da_read_buf(
        xfs_mount_t     *mp,
index 094ecb3deb2aa66237c48883f73fe7ba3d96bfdd..4ac0084e1480bbd1162b6a0cced805dda7258e22 100644 (file)
@@ -44,14 +44,6 @@ _("malloc failed (%zu bytes) dir2_add_badlist:ino %" PRIu64 "\n"),
        l->ino = ino;
 }
 
-static int
-dir_namecheck(
-       uint8_t *name,
-       int     length)
-{
-       return namecheck((char *)name, length, true);
-}
-
 int
 dir2_is_badino(
        xfs_ino_t       ino)
@@ -318,7 +310,7 @@ _("entry #%d %s in shortform dir %" PRIu64),
                 * the length value is stored in a byte
                 * so it can't be too big, it can only wrap
                 */
-               if (dir_namecheck(sfep->name, namelen)) {
+               if (!libxfs_dir2_namecheck(sfep->name, namelen)) {
                        /*
                         * junk entry
                         */
@@ -789,7 +781,7 @@ _("\twould clear inode number in entry at offset %" PRIdPTR "...\n"),
                 * during phase 4.
                 */
                junkit = dep->name[0] == '/';
-               nm_illegal = dir_namecheck(dep->name, dep->namelen);
+               nm_illegal = !libxfs_dir2_namecheck(dep->name, dep->namelen);
                if (ino_discovery && nm_illegal) {
                        do_warn(
 _("entry at block %u offset %" PRIdPTR " in directory inode %" PRIu64 " has illegal name \"%*.*s\": "),