]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - db/btblock.c
Merge branch 'progs-cleanup' into for-next
[thirdparty/xfsprogs-dev.git] / db / btblock.c
index 37b990387b71b5744e229c8d124a2fe0418c944a..1953e05a97f093592d0c16c14478caa597942cfc 100644 (file)
@@ -16,7 +16,7 @@
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <xfs/libxfs.h>
+#include "xfs/libxfs.h"
 #include "type.h"
 #include "faddr.h"
 #include "fprint.h"
 #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),
+       },
+       {       XFS_FIBT_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),
        },
-
+       {       XFS_FIBT_CRC_MAGIC,
+               XFS_BTREE_SBLOCK_CRC_LEN,
+               sizeof(xfs_inobt_key_t),
+               sizeof(xfs_inobt_rec_t),
+               sizeof(__be32),
+       },
+       {       0,
+       },
 };
 
 /*
@@ -93,8 +106,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
@@ -282,7 +307,7 @@ const field_t       bmapbta_crc_flds[] = {
        { "lsn", FLDT_UINT64X, OI(OFF(u.l.bb_lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(u.l.bb_uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_INO, OI(OFF(u.l.bb_owner)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(u.l.bb_crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.l.bb_crc)), C1, 0, TYP_NONE },
        { "recs", FLDT_BMAPBTAREC, btblock_rec_offset, btblock_rec_count,
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
        { "keys", FLDT_BMAPBTAKEY, btblock_key_offset, btblock_key_count,
@@ -301,7 +326,7 @@ const field_t       bmapbtd_crc_flds[] = {
        { "lsn", FLDT_UINT64X, OI(OFF(u.l.bb_lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(u.l.bb_uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_INO, OI(OFF(u.l.bb_owner)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(u.l.bb_crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.l.bb_crc)), C1, 0, TYP_NONE },
        { "recs", FLDT_BMAPBTDREC, btblock_rec_offset, btblock_rec_count,
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
        { "keys", FLDT_BMAPBTDKEY, btblock_key_offset, btblock_key_count,
@@ -367,6 +392,11 @@ const field_t      inobt_crc_hfld[] = {
        { NULL }
 };
 
+const field_t  inobt_spcrc_hfld[] = {
+       { "", FLDT_INOBT_SPCRC, OI(0), C1, 0, TYP_NONE },
+       { NULL }
+};
+
 #define        OFF(f)  bitize(offsetof(struct xfs_btree_block, bb_ ## f))
 const field_t  inobt_flds[] = {
        { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
@@ -392,7 +422,7 @@ const field_t       inobt_crc_flds[] = {
        { "lsn", FLDT_UINT64X, OI(OFF(u.s.bb_lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(u.s.bb_uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_AGNUMBER, OI(OFF(u.s.bb_owner)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
        { "recs", FLDT_INOBTREC, btblock_rec_offset, btblock_rec_count,
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
        { "keys", FLDT_INOBTKEY, btblock_key_offset, btblock_key_count,
@@ -401,6 +431,26 @@ const field_t      inobt_crc_flds[] = {
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_INOBT },
        { NULL }
 };
+const field_t  inobt_spcrc_flds[] = {
+       { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
+       { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
+       { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
+       { "leftsib", FLDT_AGBLOCK, OI(OFF(u.s.bb_leftsib)), C1, 0, TYP_INOBT },
+       { "rightsib", FLDT_AGBLOCK, OI(OFF(u.s.bb_rightsib)), C1, 0, TYP_INOBT },
+       { "bno", FLDT_DFSBNO, OI(OFF(u.s.bb_blkno)), C1, 0, TYP_INOBT },
+       { "lsn", FLDT_UINT64X, OI(OFF(u.s.bb_lsn)), C1, 0, TYP_NONE },
+       { "uuid", FLDT_UUID, OI(OFF(u.s.bb_uuid)), C1, 0, TYP_NONE },
+       { "owner", FLDT_AGNUMBER, OI(OFF(u.s.bb_owner)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
+       { "recs", FLDT_INOBTSPREC, btblock_rec_offset, btblock_rec_count,
+         FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
+       { "keys", FLDT_INOBTKEY, btblock_key_offset, btblock_key_count,
+         FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
+       { "ptrs", FLDT_INOBTPTR, btblock_ptr_offset, btblock_key_count,
+         FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_INOBT },
+       { NULL }
+};
+
 #undef OFF
 
 #define        KOFF(f) bitize(offsetof(xfs_inobt_key_t, ir_ ## f))
@@ -410,11 +460,22 @@ const field_t     inobt_key_flds[] = {
 };
 #undef KOFF
 
-#define        ROFF(f) bitize(offsetof(xfs_inobt_rec_t, ir_ ## f))
+#define        ROFF(f) bitize(offsetof(xfs_inobt_rec_t, f))
 const field_t  inobt_rec_flds[] = {
-       { "startino", FLDT_AGINO, OI(ROFF(startino)), C1, 0, TYP_INODE },
-       { "freecount", FLDT_INT32D, OI(ROFF(freecount)), C1, 0, TYP_NONE },
-       { "free", FLDT_INOFREE, OI(ROFF(free)), C1, 0, TYP_NONE },
+       { "startino", FLDT_AGINO, OI(ROFF(ir_startino)), C1, 0, TYP_INODE },
+       { "freecount", FLDT_INT32D, OI(ROFF(ir_u.f.ir_freecount)), C1, 0, TYP_NONE },
+       { "free", FLDT_INOFREE, OI(ROFF(ir_free)), C1, 0, TYP_NONE },
+       { NULL }
+};
+/* sparse inode on-disk format */
+const field_t  inobt_sprec_flds[] = {
+       { "startino", FLDT_AGINO, OI(ROFF(ir_startino)), C1, 0, TYP_INODE },
+       { "holemask", FLDT_UINT16X, OI(ROFF(ir_u.sp.ir_holemask)), C1, 0,
+         TYP_NONE },
+       { "count", FLDT_UINT8D, OI(ROFF(ir_u.sp.ir_count)), C1, 0, TYP_NONE },
+       { "freecount", FLDT_INT8D, OI(ROFF(ir_u.sp.ir_freecount)), C1, 0,
+         TYP_NONE },
+       { "free", FLDT_INOFREE, OI(ROFF(ir_free)), C1, 0, TYP_NONE },
        { NULL }
 };
 #undef ROFF
@@ -458,7 +519,7 @@ const field_t       bnobt_crc_flds[] = {
        { "lsn", FLDT_UINT64X, OI(OFF(u.s.bb_lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(u.s.bb_uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_AGNUMBER, OI(OFF(u.s.bb_owner)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
        { "recs", FLDT_BNOBTREC, btblock_rec_offset, btblock_rec_count,
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
        { "keys", FLDT_BNOBTKEY, btblock_key_offset, btblock_key_count,
@@ -520,7 +581,7 @@ const field_t       cntbt_crc_flds[] = {
        { "lsn", FLDT_UINT64X, OI(OFF(u.s.bb_lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(u.s.bb_uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_AGNUMBER, OI(OFF(u.s.bb_owner)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(u.s.bb_crc)), C1, 0, TYP_NONE },
        { "recs", FLDT_CNTBTREC, btblock_rec_offset, btblock_rec_count,
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
        { "keys", FLDT_CNTBTKEY, btblock_key_offset, btblock_key_count,