Commit ad70328a authored by Hou Tao's avatar Hou Tao Committed by Dave Chinner

xfs: remove the magic numbers in xfs_btree_block-related len macros

replace the magic numbers by offsetof(...) and sizeof(...), and add two
extra checks on xfs_check_ondisk_structs()

[dchinner: renamed header structures to be more descriptive]
Signed-off-by: default avatarHou Tao <houtao1@huawei.com>
Reviewed-by: default avatarCarlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent fbfb24bf
...@@ -1435,12 +1435,8 @@ typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t; ...@@ -1435,12 +1435,8 @@ typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
* with the crc feature bit, and all accesses to them must be conditional on * with the crc feature bit, and all accesses to them must be conditional on
* that flag. * that flag.
*/ */
struct xfs_btree_block { /* short form block header */
__be32 bb_magic; /* magic number for block type */ struct xfs_btree_block_shdr {
__be16 bb_level; /* 0 is a leaf */
__be16 bb_numrecs; /* current # of data records */
union {
struct {
__be32 bb_leftsib; __be32 bb_leftsib;
__be32 bb_rightsib; __be32 bb_rightsib;
...@@ -1449,8 +1445,10 @@ struct xfs_btree_block { ...@@ -1449,8 +1445,10 @@ struct xfs_btree_block {
uuid_t bb_uuid; uuid_t bb_uuid;
__be32 bb_owner; __be32 bb_owner;
__le32 bb_crc; __le32 bb_crc;
} s; /* short form pointers */ };
struct {
/* long form block header */
struct xfs_btree_block_lhdr {
__be64 bb_leftsib; __be64 bb_leftsib;
__be64 bb_rightsib; __be64 bb_rightsib;
...@@ -1460,16 +1458,34 @@ struct xfs_btree_block { ...@@ -1460,16 +1458,34 @@ struct xfs_btree_block {
__be64 bb_owner; __be64 bb_owner;
__le32 bb_crc; __le32 bb_crc;
__be32 bb_pad; /* padding for alignment */ __be32 bb_pad; /* padding for alignment */
} l; /* long form pointers */ };
struct xfs_btree_block {
__be32 bb_magic; /* magic number for block type */
__be16 bb_level; /* 0 is a leaf */
__be16 bb_numrecs; /* current # of data records */
union {
struct xfs_btree_block_shdr s;
struct xfs_btree_block_lhdr l;
} bb_u; /* rest */ } bb_u; /* rest */
}; };
#define XFS_BTREE_SBLOCK_LEN 16 /* size of a short form block */ /* size of a short form block */
#define XFS_BTREE_LBLOCK_LEN 24 /* size of a long form block */ #define XFS_BTREE_SBLOCK_LEN \
(offsetof(struct xfs_btree_block, bb_u) + \
offsetof(struct xfs_btree_block_shdr, bb_blkno))
/* size of a long form block */
#define XFS_BTREE_LBLOCK_LEN \
(offsetof(struct xfs_btree_block, bb_u) + \
offsetof(struct xfs_btree_block_lhdr, bb_blkno))
/* sizes of CRC enabled btree blocks */ /* sizes of CRC enabled btree blocks */
#define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40) #define XFS_BTREE_SBLOCK_CRC_LEN \
#define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48) (offsetof(struct xfs_btree_block, bb_u) + \
sizeof(struct xfs_btree_block_shdr))
#define XFS_BTREE_LBLOCK_CRC_LEN \
(offsetof(struct xfs_btree_block, bb_u) + \
sizeof(struct xfs_btree_block_lhdr))
#define XFS_BTREE_SBLOCK_CRC_OFF \ #define XFS_BTREE_SBLOCK_CRC_OFF \
offsetof(struct xfs_btree_block, bb_u.s.bb_crc) offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
......
...@@ -34,6 +34,8 @@ xfs_check_ondisk_structs(void) ...@@ -34,6 +34,8 @@ xfs_check_ondisk_structs(void)
XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_key, 8); XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_key, 8);
XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_rec, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_bmbt_rec, 16);
XFS_CHECK_STRUCT_SIZE(struct xfs_bmdr_block, 4); XFS_CHECK_STRUCT_SIZE(struct xfs_bmdr_block, 4);
XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block_shdr, 48);
XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block_lhdr, 64);
XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block, 72); XFS_CHECK_STRUCT_SIZE(struct xfs_btree_block, 72);
XFS_CHECK_STRUCT_SIZE(struct xfs_dinode, 176); XFS_CHECK_STRUCT_SIZE(struct xfs_dinode, 176);
XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot, 104); XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot, 104);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment