From: Shida Zhang Date: Fri, 18 Nov 2022 09:46:41 +0000 (+0100) Subject: xfs: rearrange the logic and remove the broken comment for xfs_dir2_isxx X-Git-Tag: origin/for-next_2022-11-30~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a3bfffee3f266362ad05bb954d6e91e218739f4;p=thirdparty%2Fxfsprogs-dev.git xfs: rearrange the logic and remove the broken comment for xfs_dir2_isxx 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 Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Carlos Maiolino --- diff --git a/db/namei.c b/db/namei.c index f06ee3e95..4186d2629 100644 --- a/db/namei.c +++ b/db/namei.c @@ -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); diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index fac072fcb..d6a192963 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -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; } diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index b6df3c34b..dd39f17dd 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -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); diff --git a/repair/phase6.c b/repair/phase6.c index d8b23ba52..1f9f8dee4 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -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;