]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: fix btree block magic number mapping
authorDave Chinner <dchinner@redhat.com>
Fri, 7 Jun 2013 00:26:08 +0000 (10:26 +1000)
committerBen Myers <bpm@sgi.com>
Tue, 6 Aug 2013 21:09:08 +0000 (16:09 -0500)
The magic numbers for generic btree blocks were modified some time
ago (before the kernel code was committed) but the xfs_repair
mapping code was not updated to match. It's no longer a simple
mapping, so just make the code a dense array and use the magic
number as the search key.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Ben Myers <bpm@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
db/btblock.c

index 37b990387b71b5744e229c8d124a2fe0418c944a..34188dbda7291c1b30414d59f42b168d750554ce 100644 (file)
 #include "bit.h"
 #include "init.h"
 
-
 /*
  * Definition of the possible btree block layouts.
  */
 struct xfs_db_btree {
+       uint32_t                magic;
        size_t                  block_len;
        size_t                  key_len;
        size_t                  rec_len;
        size_t                  ptr_len;
 } btrees[] = {
-       [/*0x424d415*/0] = { /* BMAP */
+       {       XFS_BMAP_MAGIC,
                XFS_BTREE_LBLOCK_LEN,
                sizeof(xfs_bmbt_key_t),
                sizeof(xfs_bmbt_rec_t),
                sizeof(__be64),
        },
-       [/*0x4142544*/2] = { /* ABTB */
+       {       XFS_ABTB_MAGIC,
                XFS_BTREE_SBLOCK_LEN,
                sizeof(xfs_alloc_key_t),
                sizeof(xfs_alloc_rec_t),
                sizeof(__be32),
        },
-       [/*0x4142544*/3] = { /* ABTC */
+       {       XFS_ABTC_MAGIC,
                XFS_BTREE_SBLOCK_LEN,
                sizeof(xfs_alloc_key_t),
                sizeof(xfs_alloc_rec_t),
                sizeof(__be32),
        },
-       [/*0x4941425*/4] = { /* IABT */
+       {       XFS_IBT_MAGIC,
                XFS_BTREE_SBLOCK_LEN,
                sizeof(xfs_inobt_key_t),
                sizeof(xfs_inobt_rec_t),
                sizeof(__be32),
        },
-       [/*0x424d415*/8] = { /* BMAP_CRC */
+       {       XFS_BMAP_CRC_MAGIC,
                XFS_BTREE_LBLOCK_CRC_LEN,
                sizeof(xfs_bmbt_key_t),
                sizeof(xfs_bmbt_rec_t),
                sizeof(__be64),
        },
-       [/*0x4142544*/0xa] = { /* ABTB_CRC */
+       {       XFS_ABTB_CRC_MAGIC,
                XFS_BTREE_SBLOCK_CRC_LEN,
                sizeof(xfs_alloc_key_t),
                sizeof(xfs_alloc_rec_t),
                sizeof(__be32),
        },
-       [/*0x414254*/0xb] = { /* ABTC_CRC */
+       {       XFS_ABTC_CRC_MAGIC,
                XFS_BTREE_SBLOCK_CRC_LEN,
                sizeof(xfs_alloc_key_t),
                sizeof(xfs_alloc_rec_t),
                sizeof(__be32),
        },
-       [/*0x4941425*/0xc] = { /* IABT_CRC */
+       {       XFS_IBT_CRC_MAGIC,
                XFS_BTREE_SBLOCK_CRC_LEN,
                sizeof(xfs_inobt_key_t),
                sizeof(xfs_inobt_rec_t),
                sizeof(__be32),
        },
-
+       {       0,
+       },
 };
 
 /*
@@ -93,8 +94,20 @@ struct xfs_db_btree {
  * We use the least significant bit of the magic number as index into
  * the array of block defintions.
  */
-#define block_to_bt(bb) \
-       (&btrees[be32_to_cpu((bb)->bb_magic) & 0xf])
+static struct xfs_db_btree *
+block_to_bt(
+       struct xfs_btree_block  *bb)
+{
+       struct xfs_db_btree *btp = &btrees[0];
+
+       do {
+               if (be32_to_cpu((bb)->bb_magic) == btp->magic)
+                       return btp;
+               btp++;
+       } while (btp->magic != 0);
+
+       return NULL;
+}
 
 /* calculate max records.  Only for non-leaves. */
 static int