]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
db: indicate if the CRC on a buffer is correct or not
authorDave Chinner <dchinner@redhat.com>
Wed, 13 Nov 2013 06:40:46 +0000 (06:40 +0000)
committerRich Johnston <rjohnston@sgi.com>
Wed, 13 Nov 2013 17:13:20 +0000 (11:13 -0600)
When dumping metadata that has a CRC in it, output not only the CRC
but text to tell us whether the value is correct or not. Hence we
can see at a glance if there's something wrong or not.

Do this by peeking at the buffer attached to the current IO
context. If there was a CRC error, then it will be marked with a
EFSCORRUPTED error. Use this to determine what to output.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
14 files changed:
db/agf.c
db/agfl.c
db/agi.c
db/btblock.c
db/dir2.c
db/dquot.c
db/field.c
db/field.h
db/fprint.c
db/fprint.h
db/inode.c
db/io.h
db/sb.c
db/symlink.c

index 389cb435d4e4669da00d1b7299d3a7a8b0b9ddff..d9a07cafb8f2442b512b5f033afbbdda4ebd514f 100644 (file)
--- a/db/agf.c
+++ b/db/agf.c
@@ -71,7 +71,7 @@ const field_t agf_flds[] = {
        { "btreeblks", FLDT_UINT32D, OI(OFF(btreeblks)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
        { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
        { NULL }
 };
 
index e2340e684652555a5b867e9bc09a77b128527cce..b29538f581b5b27c19f60510407d9dab8ba70d55 100644 (file)
--- a/db/agfl.c
+++ b/db/agfl.c
@@ -58,7 +58,7 @@ const field_t agfl_crc_flds[] = {
        { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
        { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
        { "bno", FLDT_AGBLOCKNZ, OI(OFF(bno)), agfl_bno_size,
          FLD_ARRAY|FLD_COUNT, TYP_DATA },
        { NULL }
index 6b2e8897c2027501ec0bc3985de8023bd66458d5..398bdbbcaef696f603a77ad554a9fc2fc689507b 100644 (file)
--- a/db/agi.c
+++ b/db/agi.c
@@ -56,7 +56,7 @@ const field_t agi_flds[] = {
          CI(XFS_AGI_UNLINKED_BUCKETS), FLD_ARRAY, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
        { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
        { NULL }
 };
 
index 34188dbda7291c1b30414d59f42b168d750554ce..1ea0cff0884308363d3c82bd32519abb36a46da4 100644 (file)
@@ -295,7 +295,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,
@@ -314,7 +314,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,
@@ -405,7 +405,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,
@@ -471,7 +471,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,
@@ -533,7 +533,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,
index 8b08d48aaacc2a5792776230f6a7cf5b6f66ffb0..2ec64e0961133d3ad707f64d74ee80adf6f749ab 100644 (file)
--- a/db/dir2.c
+++ b/db/dir2.c
@@ -922,7 +922,7 @@ const field_t       dir3_data_union_flds[] = {
 #define        DBH3OFF(f)      bitize(offsetof(struct xfs_dir3_blk_hdr, f))
 const field_t  dir3_blkhdr_flds[] = {
        { "magic", FLDT_UINT32X, OI(DBH3OFF(magic)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(DBH3OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(DBH3OFF(crc)), C1, 0, TYP_NONE },
        { "bno", FLDT_DFSBNO, OI(DBH3OFF(blkno)), C1, 0, TYP_BMAPBTD },
        { "lsn", FLDT_UINT64X, OI(DBH3OFF(lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(DBH3OFF(uuid)), C1, 0, TYP_NONE },
@@ -959,7 +959,7 @@ const field_t       dir3_free_hdr_flds[] = {
 #define        DB3OFF(f)       bitize(offsetof(struct xfs_da3_blkinfo, f))
 const field_t  da3_blkinfo_flds[] = {
        { "hdr", FLDT_DA_BLKINFO, OI(DB3OFF(hdr)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(DB3OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(DB3OFF(crc)), C1, 0, TYP_NONE },
        { "bno", FLDT_DFSBNO, OI(DB3OFF(blkno)), C1, 0, TYP_BMAPBTD },
        { "lsn", FLDT_UINT64X, OI(DB3OFF(lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(DB3OFF(uuid)), C1, 0, TYP_NONE },
index 69279566f73579b65286377d5409811cf6cf7534..2f7d463e00ec3dae5ab6ea6826a692cbaefbf038 100644 (file)
@@ -48,7 +48,7 @@ const field_t dqblk_flds[] = {
        { "diskdq", FLDT_DISK_DQUOT, OI(DDOFF(diskdq)), C1, 0, TYP_NONE },
        { "fill", FLDT_CHARS, OI(DDOFF(fill)), CI(DDSZC(fill)), FLD_SKIPALL,
          TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(DDOFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(DDOFF(crc)), C1, 0, TYP_NONE },
        { "lsn", FLDT_UINT64X, OI(DDOFF(lsn)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(DDOFF(uuid)), C1, 0, TYP_NONE },
        { NULL }
index c6d74044398c7c06d3d94cedb86e8a0d5a7cb3b4..4582097647678f897314d194cde13cfc0344a238 100644 (file)
@@ -163,6 +163,11 @@ const ftattr_t     ftattrtab[] = {
          0, fa_agblock, NULL },
        { FLDT_CNTBTREC, "cntbtrec", fp_sarray, (char *)cntbt_rec_flds,
          SI(bitsz(xfs_alloc_rec_t)), 0, NULL, cntbt_rec_flds },
+
+/* CRC field */
+       { FLDT_CRC, "crc", fp_crc, "%#x (%s)", SI(bitsz(__uint32_t)),
+         0, NULL, NULL },
+
        { FLDT_DEV, "dev", fp_num, "%#x", SI(bitsz(xfs_dev_t)), 0, NULL, NULL },
        { FLDT_DFILOFFA, "dfiloffa", fp_num, "%llu", SI(bitsz(xfs_dfiloff_t)),
          0, fa_dfiloffa, NULL },
index aecdf9fda0ad2adbc043eba29a2ea0f0e004a1c6..6343c9ae5a529d4bba76ba90244654d150556e0a 100644 (file)
@@ -80,6 +80,10 @@ typedef enum fldt    {
        FLDT_CNTBTKEY,
        FLDT_CNTBTPTR,
        FLDT_CNTBTREC,
+
+       /* CRC field type */
+       FLDT_CRC,
+
        FLDT_DEV,
        FLDT_DFILOFFA,
        FLDT_DFILOFFD,
index 1d2f29c59135f042bde4c6c0ff47fc195c636f7c..435d984f3c5b49a4a51816d8313e2fc85da53976 100644 (file)
@@ -30,6 +30,7 @@
 #include "output.h"
 #include "sig.h"
 #include "malloc.h"
+#include "io.h"
 
 int
 fp_charns(
@@ -184,3 +185,41 @@ fp_uuid(
        }
        return 1;
 }
+
+/*
+ * CRC is correct is the current buffer it is being pulled out
+ * of is not marked with a EFSCORRUPTED error.
+ */
+int
+fp_crc(
+       void    *obj,
+       int     bit,
+       int     count,
+       char    *fmtstr,
+       int     size,
+       int     arg,
+       int     base,
+       int     array)
+{
+       int             bitpos;
+       int             i;
+       __int64_t       val;
+       char            *ok;
+
+       ok = iocur_crc_valid() ? "correct" : "bad";
+
+       for (i = 0, bitpos = bit;
+            i < count && !seenint();
+            i++, bitpos += size) {
+               if (array)
+                       dbprintf("%d:", i + base);
+               val = getbitval(obj, bitpos, size, BVUNSIGNED);
+               if (size > 32)
+                       dbprintf(fmtstr, val, ok);
+               else
+                       dbprintf(fmtstr, (__int32_t)val, ok);
+               if (i < count - 1)
+                       dbprintf(" ");
+       }
+       return 1;
+}
index b032dbd505e3e8e52e33288476ffc3ffde87794a..6a6d77e25bcc972ee39254d0ecde1fadb7e55968 100644 (file)
@@ -29,3 +29,5 @@ extern int    fp_time(void *obj, int bit, int count, char *fmtstr, int size,
                        int arg, int base, int array);
 extern int     fp_uuid(void *obj, int bit, int count, char *fmtstr, int size,
                        int arg, int base, int array);
+extern int     fp_crc(void *obj, int bit, int count, char *fmtstr, int size,
+                      int arg, int base, int array);
index 634dc309f398286e23157f0874005f36a0d14c1c..ec533ee5f40f7d9a06b07a43da8403ee9ff66449 100644 (file)
@@ -168,7 +168,7 @@ const field_t       inode_core_flds[] = {
 };
 
 const field_t  inode_v3_flds[] = {
-       { "crc", FLDT_UINT32X, OI(COFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(COFF(crc)), C1, 0, TYP_NONE },
        { "change_count", FLDT_UINT64D, OI(COFF(changecount)), C1, 0, TYP_NONE },
        { "lsn", FLDT_UINT64X, OI(COFF(lsn)), C1, 0, TYP_NONE },
        { "flags2", FLDT_UINT64X, OI(COFF(flags2)), C1, 0, TYP_NONE },
diff --git a/db/io.h b/db/io.h
index 2c47ccc62327ea4fa5331c7d08e71a75b33d3c69..d647284aba91fb0edc0897591c8843fbe8027df7 100644 (file)
--- a/db/io.h
+++ b/db/io.h
@@ -58,3 +58,9 @@ extern void     write_cur(void);
 extern void    set_cur(const struct typ *t, __int64_t d, int c, int ring_add,
                        bbmap_t *bbmap);
 extern void     ring_add(void);
+
+static inline bool
+iocur_crc_valid()
+{
+       return (iocur_top->bp && iocur_top->bp->b_error != EFSCORRUPTED);
+}
diff --git a/db/sb.c b/db/sb.c
index 492915265a7157d535462486e8effe7c57f1bff5..6cb665d37a518a55fa441035c111b25c1d4c39d5 100644 (file)
--- a/db/sb.c
+++ b/db/sb.c
@@ -118,7 +118,7 @@ const field_t       sb_flds[] = {
                C1, 0, TYP_NONE },
        { "features_log_incompat", FLDT_UINT32X, OI(OFF(features_log_incompat)),
                C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
        { "pquotino", FLDT_INO, OI(OFF(pquotino)), C1, 0, TYP_INODE },
        { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
        { NULL }
index 9f3d0b95956515d5dbdf2403fb3d2ce37744386c..a4f420f49cd15ce84d54ad3722d2de47b99cdc1c 100644 (file)
@@ -69,7 +69,7 @@ const struct field    symlink_crc_flds[] = {
        { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
        { "offset", FLDT_UINT32D, OI(OFF(offset)), C1, 0, TYP_NONE },
        { "bytes", FLDT_UINT32D, OI(OFF(bytes)), C1, 0, TYP_NONE },
-       { "crc", FLDT_UINT32X, OI(OFF(crc)), C1, 0, TYP_NONE },
+       { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
        { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
        { "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE },
        { "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD },