]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:37 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 31 Jul 2024 01:46:43 +0000 (18:46 -0700)
Currently, the XFS_SB_CRC_OFF macro uses the incore superblock struct
(xfs_sb) to compute the address of sb_crc within the ondisk superblock
struct (xfs_dsb).  This is a landmine if we ever change the layout of
the incore superblock (as we're about to do), so redefine the macro
to use xfs_dsb to compute the layout of xfs_dsb.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
db/sb.c
libxfs/xfs_format.h
libxfs/xfs_ondisk.h
mdrestore/xfs_mdrestore.c
repair/agheader.c

diff --git a/db/sb.c b/db/sb.c
index 7836384a1faa4b9be90d7d3eead3e0bcbb1a1e01..9fcb7340f8b02fe5924b94a918db9201d737e690 100644 (file)
--- a/db/sb.c
+++ b/db/sb.c
@@ -50,8 +50,8 @@ sb_init(void)
        add_command(&version_cmd);
 }
 
-#define        OFF(f)  bitize(offsetof(xfs_sb_t, sb_ ## f))
-#define        SZC(f)  szcount(xfs_sb_t, sb_ ## f)
+#define        OFF(f)  bitize(offsetof(struct xfs_dsb, sb_ ## f))
+#define        SZC(f)  szcount(struct xfs_dsb, sb_ ## f)
 const field_t  sb_flds[] = {
        { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE },
        { "blocksize", FLDT_UINT32D, OI(OFF(blocksize)), C1, 0, TYP_NONE },
index 61f51becff4f768198d8bb70a27cb69c66c96109..e1bfee0c3b1a8c735bc18c698fb45ccc7ce110bd 100644 (file)
@@ -90,8 +90,7 @@ struct xfs_ifork;
 #define XFSLABEL_MAX                   12
 
 /*
- * Superblock - in core version.  Must match the ondisk version below.
- * Must be padded to 64 bit alignment.
+ * Superblock - in core version.  Must be padded to 64 bit alignment.
  */
 typedef struct xfs_sb {
        uint32_t        sb_magicnum;    /* magic number == XFS_SB_MAGIC */
@@ -178,10 +177,8 @@ typedef struct xfs_sb {
        /* must be padded to 64 bit alignment */
 } xfs_sb_t;
 
-#define XFS_SB_CRC_OFF         offsetof(struct xfs_sb, sb_crc)
-
 /*
- * Superblock - on disk version.  Must match the in core version above.
+ * Superblock - on disk version.
  * Must be padded to 64 bit alignment.
  */
 struct xfs_dsb {
@@ -265,6 +262,8 @@ struct xfs_dsb {
        /* must be padded to 64 bit alignment */
 };
 
+#define XFS_SB_CRC_OFF         offsetof(struct xfs_dsb, sb_crc)
+
 /*
  * Misc. Flags - warning - these will be cleared by xfs_repair unless
  * a feature bit is set when the flag is used.
index e8cdd77d03fa83efa34bc04e012aeed38dac09f9..23c133fd36f5bb10a3f867224c028a8ba1de4178 100644 (file)
@@ -85,6 +85,7 @@ xfs_check_ondisk_structs(void)
        XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_remote_t,      12);
         */
 
+       XFS_CHECK_OFFSET(struct xfs_dsb, sb_crc,                224);
        XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, valuelen,  0);
        XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, namelen,   2);
        XFS_CHECK_OFFSET(xfs_attr_leaf_name_local_t, nameval,   3);
index 334bdd22876377c0213a291e772a114b72db9206..269edb8f89969d5401b418f80115116c0d82dc25 100644 (file)
@@ -101,10 +101,8 @@ fixup_superblock(
        memset(block_buffer, 0, sb->sb_sectsize);
        sb->sb_inprogress = 0;
        libxfs_sb_to_disk((struct xfs_dsb *)block_buffer, sb);
-       if (xfs_sb_version_hascrc(sb)) {
-               xfs_update_cksum(block_buffer, sb->sb_sectsize,
-                                offsetof(struct xfs_sb, sb_crc));
-       }
+       if (xfs_sb_version_hascrc(sb))
+               xfs_update_cksum(block_buffer, sb->sb_sectsize, XFS_SB_CRC_OFF);
 
        if (pwrite(ddev_fd, block_buffer, sb->sb_sectsize, 0) < 0)
                fatal("error writing primary superblock: %s\n", strerror(errno));
index 762901581e19f37b6c19b1e8346169cfd611bf5c..3930a0ac0919b419f1a490ff3885ba154d16d9d7 100644 (file)
@@ -358,22 +358,22 @@ secondary_sb_whack(
         * size is the size of data which is valid for this sb.
         */
        if (xfs_sb_version_hasmetauuid(sb))
-               size = offsetof(xfs_sb_t, sb_meta_uuid)
+               size = offsetof(struct xfs_dsb, sb_meta_uuid)
                        + sizeof(sb->sb_meta_uuid);
        else if (xfs_sb_version_hascrc(sb))
-               size = offsetof(xfs_sb_t, sb_lsn)
+               size = offsetof(struct xfs_dsb, sb_lsn)
                        + sizeof(sb->sb_lsn);
        else if (xfs_sb_version_hasmorebits(sb))
-               size = offsetof(xfs_sb_t, sb_bad_features2)
+               size = offsetof(struct xfs_dsb, sb_bad_features2)
                        + sizeof(sb->sb_bad_features2);
        else if (xfs_sb_version_haslogv2(sb))
-               size = offsetof(xfs_sb_t, sb_logsunit)
+               size = offsetof(struct xfs_dsb, sb_logsunit)
                        + sizeof(sb->sb_logsunit);
        else if (xfs_sb_version_hassector(sb))
-               size = offsetof(xfs_sb_t, sb_logsectsize)
+               size = offsetof(struct xfs_dsb, sb_logsectsize)
                        + sizeof(sb->sb_logsectsize);
        else /* only support dirv2 or more recent */
-               size = offsetof(xfs_sb_t, sb_dirblklog)
+               size = offsetof(struct xfs_dsb, sb_dirblklog)
                        + sizeof(sb->sb_dirblklog);
 
        /* Check the buffer we read from disk for garbage outside size */