]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: create a predicate to determine if two xfs_names are the same
authorDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:30:49 +0000 (12:30 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:30:49 +0000 (12:30 -0800)
Create a simple predicate to determine if two xfs_names are the same
objects or have the exact same name.  The comparison is always case
sensitive.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_dir2.h
fs/xfs/scrub/dir.c

index 7d7cd8d808e4dbc7134536a6d5fe3ef7e3dd9544..8497d041f3163b1de31e0262fd0d2941a8be611c 100644 (file)
@@ -24,6 +24,18 @@ struct xfs_dir3_icleaf_hdr;
 extern const struct xfs_name   xfs_name_dotdot;
 extern const struct xfs_name   xfs_name_dot;
 
+static inline bool
+xfs_dir2_samename(
+       const struct xfs_name   *n1,
+       const struct xfs_name   *n2)
+{
+       if (n1 == n2)
+               return true;
+       if (n1->len != n2->len)
+               return false;
+       return !memcmp(n1->name, n2->name, n1->len);
+}
+
 /*
  * Convert inode mode to directory entry filetype
  */
index d86ab51af9282dac1b7f83ffde194a3c2acf54ba..076a310b8eb00aa15a0034ac213ac749169c0d03 100644 (file)
@@ -93,11 +93,11 @@ xchk_dir_actor(
                return -ECANCELED;
        }
 
-       if (!strncmp(".", name->name, name->len)) {
+       if (xfs_dir2_samename(name, &xfs_name_dot)) {
                /* If this is "." then check that the inum matches the dir. */
                if (ino != dp->i_ino)
                        xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
-       } else if (!strncmp("..", name->name, name->len)) {
+       } else if (xfs_dir2_samename(name, &xfs_name_dotdot)) {
                /*
                 * If this is ".." in the root inode, check that the inum
                 * matches this dir.