]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: rearrange the logic and remove the broken comment for xfs_dir2_isxx
authorShida Zhang <zhangshida@kylinos.cn>
Fri, 18 Nov 2022 09:46:41 +0000 (10:46 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 21 Nov 2022 14:26:48 +0000 (15:26 +0100)
Source kernel commit: c098576f5f63bc0ee2424bba50892514a71d54e8

xfs_dir2_isleaf is used to see if the directory is a single-leaf
form directory instead, as commented right above the function.

Besides getting rid of the broken comment, we rearrange the logic by
converting everything over to standard formatting and conventions,
at the same time, to make it easier to understand and self documenting.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
db/namei.c
libxfs/xfs_dir2.c
libxfs/xfs_dir2.h
repair/phase6.c

index f06ee3e9599bc6865c234e61b88a526936657c29..4186d262940bf1e8c5ff4d9e7834c6cdf73ad6b9 100644 (file)
@@ -450,7 +450,7 @@ listdir(
                .geo            = dp->i_mount->m_dir_geo,
        };
        int                     error;
-       int                     isblock;
+       bool                    isblock;
 
        if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL)
                return list_sfdir(&args);
index fac072fcb1d17fce69e28e7d140dd4d8f75e2579..d6a192963f5033f316829c28439bbccfc64af9be 100644 (file)
@@ -260,7 +260,7 @@ xfs_dir_createname(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       int                     v;              /* type-checking value */
+       bool                    v;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
 
@@ -356,7 +356,7 @@ xfs_dir_lookup(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       int                     v;        /* type-checking value */
+       bool                    v;
        int                     lock_mode;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
@@ -434,7 +434,7 @@ xfs_dir_removename(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       int                     v;              /* type-checking value */
+       bool                    v;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
        XFS_STATS_INC(dp->i_mount, xs_dir_remove);
@@ -492,7 +492,7 @@ xfs_dir_replace(
 {
        struct xfs_da_args      *args;
        int                     rval;
-       int                     v;              /* type-checking value */
+       bool                    v;
 
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
 
@@ -609,19 +609,23 @@ xfs_dir2_grow_inode(
 int
 xfs_dir2_isblock(
        struct xfs_da_args      *args,
-       int                     *vp)    /* out: 1 is block, 0 is not block */
+       bool                    *isblock)
 {
-       xfs_fileoff_t           last;   /* last file offset */
-       int                     rval;
+       struct xfs_mount        *mp = args->dp->i_mount;
+       xfs_fileoff_t           eof;
+       int                     error;
 
-       if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK)))
-               return rval;
-       rval = XFS_FSB_TO_B(args->dp->i_mount, last) == args->geo->blksize;
-       if (XFS_IS_CORRUPT(args->dp->i_mount,
-                          rval != 0 &&
-                          args->dp->i_disk_size != args->geo->blksize))
+       error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK);
+       if (error)
+               return error;
+
+       *isblock = false;
+       if (XFS_FSB_TO_B(mp, eof) != args->geo->blksize)
+               return 0;
+
+       *isblock = true;
+       if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize))
                return -EFSCORRUPTED;
-       *vp = rval;
        return 0;
 }
 
@@ -631,14 +635,20 @@ xfs_dir2_isblock(
 int
 xfs_dir2_isleaf(
        struct xfs_da_args      *args,
-       int                     *vp)    /* out: 1 is block, 0 is not block */
+       bool                    *isleaf)
 {
-       xfs_fileoff_t           last;   /* last file offset */
-       int                     rval;
+       xfs_fileoff_t           eof;
+       int                     error;
 
-       if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK)))
-               return rval;
-       *vp = last == args->geo->leafblk + args->geo->fsbcount;
+       error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK);
+       if (error)
+               return error;
+
+       *isleaf = false;
+       if (eof != args->geo->leafblk + args->geo->fsbcount)
+               return 0;
+
+       *isleaf = true;
        return 0;
 }
 
index b6df3c34b26afb8a703aece814770a283619915b..dd39f17dd9a9cac81fea1f0c76b9545f547f53b7 100644 (file)
@@ -61,8 +61,8 @@ extern int xfs_dir2_sf_to_block(struct xfs_da_args *args);
 /*
  * Interface routines used by userspace utilities
  */
-extern int xfs_dir2_isblock(struct xfs_da_args *args, int *r);
-extern int xfs_dir2_isleaf(struct xfs_da_args *args, int *r);
+extern int xfs_dir2_isblock(struct xfs_da_args *args, bool *isblock);
+extern int xfs_dir2_isleaf(struct xfs_da_args *args, bool *isleaf);
 extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db,
                                struct xfs_buf *bp);
 
index d8b23ba5286ca6f617d3477b92f8d414dc726eac..1f9f8dee46c1c144176236a6d2bc452876ef34f6 100644 (file)
@@ -1455,7 +1455,7 @@ longform_dir2_entry_check_data(
        struct dir_hash_tab     *hashtab,
        freetab_t               **freetabp,
        xfs_dablk_t             da_bno,
-       int                     isblock)
+       bool                    isblock)
 {
        xfs_dir2_dataptr_t      addr;
        xfs_dir2_leaf_entry_t   *blp;
@@ -2243,8 +2243,8 @@ longform_dir2_entry_check(
        xfs_dablk_t             da_bno;
        freetab_t               *freetab;
        int                     i;
-       int                     isblock;
-       int                     isleaf;
+       bool                    isblock;
+       bool                    isleaf;
        xfs_fileoff_t           next_da_bno;
        int                     seeval;
        int                     fixit = 0;