]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: replace inode fork size macros with functions
authorDarrick J. Wong <djwong@kernel.org>
Wed, 24 Aug 2022 13:57:29 +0000 (15:57 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 30 Aug 2022 08:26:48 +0000 (10:26 +0200)
Source kernel commit: c01147d929899f02a0a8b15e406d12784768ca72

Replace the shouty macros here with typechecked helper functions.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
include/xfs_inode.h
libxfs/xfs_attr_leaf.c
libxfs/xfs_bmap.c
libxfs/xfs_bmap_btree.c
libxfs/xfs_dir2.c
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_sf.c
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h
mkfs/proto.c

index d3c2bb8faf709c39e5f959516412b23fd151a0e6..d160cedf4ecd2abfef9a1014390a2ae708c4aa10 100644 (file)
@@ -125,6 +125,41 @@ xfs_ifork_ptr(
        }
 }
 
+static inline unsigned int xfs_inode_fork_boff(struct xfs_inode *ip)
+{
+       return ip->i_forkoff << 3;
+}
+
+static inline unsigned int xfs_inode_data_fork_size(struct xfs_inode *ip)
+{
+       if (xfs_inode_has_attr_fork(ip))
+               return xfs_inode_fork_boff(ip);
+
+       return XFS_LITINO(ip->i_mount);
+}
+
+static inline unsigned int xfs_inode_attr_fork_size(struct xfs_inode *ip)
+{
+       if (xfs_inode_has_attr_fork(ip))
+               return XFS_LITINO(ip->i_mount) - xfs_inode_fork_boff(ip);
+       return 0;
+}
+
+static inline unsigned int
+xfs_inode_fork_size(
+       struct xfs_inode        *ip,
+       int                     whichfork)
+{
+       switch (whichfork) {
+       case XFS_DATA_FORK:
+               return xfs_inode_data_fork_size(ip);
+       case XFS_ATTR_FORK:
+               return xfs_inode_attr_fork_size(ip);
+       default:
+               return 0;
+       }
+}
+
 /* Convert from vfs inode to xfs inode */
 static inline struct xfs_inode *XFS_I(struct inode *inode)
 {
index d72e52d0210c89bb20ccc4f904c23bc1c87fc1cf..41dcaaae293ff991a4b9a19e8791f4b785e96f70 100644 (file)
@@ -587,7 +587,7 @@ xfs_attr_shortform_bytesfit(
         * to real extents, or the delalloc conversion will take care of the
         * literal area rebalancing.
         */
-       if (bytes <= XFS_IFORK_ASIZE(dp))
+       if (bytes <= xfs_inode_attr_fork_size(dp))
                return dp->i_forkoff;
 
        /*
index 11d0aa0e79034bb1c34c7e7ec4ee1a716f7eed90..123255b646f8326af63b8c48ba828c428e85ec09 100644 (file)
@@ -873,7 +873,7 @@ xfs_bmap_add_attrfork_btree(
 
        mp = ip->i_mount;
 
-       if (XFS_BMAP_BMDR_SPACE(block) <= XFS_IFORK_DSIZE(ip))
+       if (XFS_BMAP_BMDR_SPACE(block) <= xfs_inode_data_fork_size(ip))
                *flags |= XFS_ILOG_DBROOT;
        else {
                cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK);
@@ -913,7 +913,7 @@ xfs_bmap_add_attrfork_extents(
        int                     error;          /* error return value */
 
        if (ip->i_df.if_nextents * sizeof(struct xfs_bmbt_rec) <=
-           XFS_IFORK_DSIZE(ip))
+           xfs_inode_data_fork_size(ip))
                return 0;
        cur = NULL;
        error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, flags,
@@ -944,7 +944,7 @@ xfs_bmap_add_attrfork_local(
 {
        struct xfs_da_args      dargs;          /* args for dir/attr code */
 
-       if (ip->i_df.if_bytes <= XFS_IFORK_DSIZE(ip))
+       if (ip->i_df.if_bytes <= xfs_inode_data_fork_size(ip))
                return 0;
 
        if (S_ISDIR(VFS_I(ip)->i_mode)) {
index 1d1e2f5da3f58fead0cc4aed9e37e582cf04576d..f0610afdcf38b4db7c65f44d07366e15e26c167a 100644 (file)
@@ -562,7 +562,7 @@ xfs_bmbt_init_cursor(
        if (xfs_has_crc(mp))
                cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
 
-       cur->bc_ino.forksize = XFS_IFORK_SIZE(ip, whichfork);
+       cur->bc_ino.forksize = xfs_inode_fork_size(ip, whichfork);
        cur->bc_ino.ip = ip;
        cur->bc_ino.allocated = 0;
        cur->bc_ino.flags = 0;
index 9f4adb09683cd372f61be3adff03bdf4fa80590f..fac072fcb1d17fce69e28e7d140dd4d8f75e2579 100644 (file)
@@ -192,7 +192,7 @@ xfs_dir_isempty(
        ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
        if (dp->i_disk_size == 0)       /* might happen during shutdown. */
                return 1;
-       if (dp->i_disk_size > XFS_IFORK_DSIZE(dp))
+       if (dp->i_disk_size > xfs_inode_data_fork_size(dp))
                return 0;
        sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
        return !sfp->count;
index 73379b19a6449d1e2ff3bd4efdf0fe179fd8eede..bb9301b768800c98b506c9c133afb33bb2491711 100644 (file)
@@ -839,7 +839,7 @@ xfs_dir2_block_removename(
         * See if the size as a shortform is good enough.
         */
        size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
-       if (size > XFS_IFORK_DSIZE(dp))
+       if (size > xfs_inode_data_fork_size(dp))
                return 0;
 
        /*
@@ -1052,7 +1052,7 @@ xfs_dir2_leaf_to_block(
         * Now see if the resulting block can be shrunken to shortform.
         */
        size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
-       if (size > XFS_IFORK_DSIZE(dp))
+       if (size > xfs_inode_data_fork_size(dp))
                return 0;
 
        return xfs_dir2_block_to_sf(args, dbp, size, &sfh);
index 9dc42db1993684ad54d05a357b3d3917aacbdc62..e97799b96fc6323b3ae2c03141f5bcda73e3f4a6 100644 (file)
@@ -237,7 +237,7 @@ xfs_dir2_block_sfsize(
                       (i8count ?                       /* inumber */
                                count * XFS_INO64_SIZE :
                                count * XFS_INO32_SIZE);
-               if (size > XFS_IFORK_DSIZE(dp))
+               if (size > xfs_inode_data_fork_size(dp))
                        return size;            /* size value is a failure */
        }
        /*
@@ -406,7 +406,7 @@ xfs_dir2_sf_addname(
         * Won't fit as shortform any more (due to size),
         * or the pick routine says it won't (due to offset values).
         */
-       if (new_isize > XFS_IFORK_DSIZE(dp) ||
+       if (new_isize > xfs_inode_data_fork_size(dp) ||
            (pick =
             xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset)) == 0) {
                /*
@@ -1031,7 +1031,7 @@ xfs_dir2_sf_replace_needblock(
        newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF;
 
        return inum > XFS_DIR2_MAX_SHORT_INUM &&
-              sfp->i8count == 0 && newsize > XFS_IFORK_DSIZE(dp);
+              sfp->i8count == 0 && newsize > xfs_inode_data_fork_size(dp);
 }
 
 /*
index 616f31b3c1c9220db442067e7a2d834d235ce9bf..02982825b3c77a8a7eecc1332af130fb85d6b14d 100644 (file)
@@ -405,7 +405,7 @@ xfs_iroot_realloc(
                                                     (int)new_size);
                ifp->if_broot_bytes = (int)new_size;
                ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
-                       XFS_IFORK_SIZE(ip, whichfork));
+                       xfs_inode_fork_size(ip, whichfork));
                memmove(np, op, cur_max * (uint)sizeof(xfs_fsblock_t));
                return;
        }
@@ -459,7 +459,7 @@ xfs_iroot_realloc(
        ifp->if_broot_bytes = (int)new_size;
        if (ifp->if_broot)
                ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
-                       XFS_IFORK_SIZE(ip, whichfork));
+                       xfs_inode_fork_size(ip, whichfork));
        return;
 }
 
@@ -489,7 +489,7 @@ xfs_idata_realloc(
        int64_t                 new_size = ifp->if_bytes + byte_diff;
 
        ASSERT(new_size >= 0);
-       ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));
+       ASSERT(new_size <= xfs_inode_fork_size(ip, whichfork));
 
        if (byte_diff == 0)
                return;
@@ -612,7 +612,7 @@ xfs_iflush_fork(
                if ((iip->ili_fields & dataflag[whichfork]) &&
                    (ifp->if_bytes > 0)) {
                        ASSERT(ifp->if_u1.if_data != NULL);
-                       ASSERT(ifp->if_bytes <= XFS_IFORK_SIZE(ip, whichfork));
+                       ASSERT(ifp->if_bytes <= xfs_inode_fork_size(ip, whichfork));
                        memcpy(cp, ifp->if_u1.if_data, ifp->if_bytes);
                }
                break;
@@ -631,7 +631,7 @@ xfs_iflush_fork(
                    (ifp->if_broot_bytes > 0)) {
                        ASSERT(ifp->if_broot != NULL);
                        ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <=
-                               XFS_IFORK_SIZE(ip, whichfork));
+                               xfs_inode_fork_size(ip, whichfork));
                        xfs_bmbt_to_bmdr(mp, ifp->if_broot, ifp->if_broot_bytes,
                                (xfs_bmdr_block_t *)cp,
                                XFS_DFORK_SIZE(dip, mp, whichfork));
index efee1195654083697a1b8502d17be4ea1cfdf749..d3943d6ad0b94127a91a02b9cf4460de2b3b5ff2 100644 (file)
@@ -77,21 +77,8 @@ struct xfs_ifork {
 /*
  * Fork handling.
  */
-
-#define XFS_IFORK_BOFF(ip)             ((int)((ip)->i_forkoff << 3))
-
-#define XFS_IFORK_DSIZE(ip) \
-       (xfs_inode_has_attr_fork(ip) ? XFS_IFORK_BOFF(ip) : XFS_LITINO((ip)->i_mount))
-#define XFS_IFORK_ASIZE(ip) \
-       (xfs_inode_has_attr_fork(ip) ? XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : 0)
-#define XFS_IFORK_SIZE(ip,w) \
-       ((w) == XFS_DATA_FORK ? \
-               XFS_IFORK_DSIZE(ip) : \
-               ((w) == XFS_ATTR_FORK ? \
-                       XFS_IFORK_ASIZE(ip) : \
-                       0))
 #define XFS_IFORK_MAXEXT(ip, w) \
-       (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
+       (xfs_inode_fork_size(ip, w) / sizeof(xfs_bmbt_rec_t))
 
 static inline bool xfs_ifork_has_extents(struct xfs_ifork *ifp)
 {
index 127d87dd4d9445a39e54c1f79a271e4ff54cfddd..68ecdbf36325cb7c5640b42475c9eb53a2683fbe 100644 (file)
@@ -237,7 +237,7 @@ newfile(
 
        flags = 0;
        mp = ip->i_mount;
-       if (symlink && len <= XFS_IFORK_DSIZE(ip)) {
+       if (symlink && len <= xfs_inode_data_fork_size(ip)) {
                libxfs_init_local_fork(ip, XFS_DATA_FORK, buf, len);
                ip->i_df.if_format = XFS_DINODE_FMT_LOCAL;
                flags = XFS_ILOG_DDATA;