In debug mode, print the differences between the superblock and

alternate superblock when the values disagree and we're going to
reject it.

Differential Revision: https://reviews.freebsd.org/D11589
This commit is contained in:
Warner Losh 2017-08-07 21:23:59 +00:00
parent bb10d553af
commit e9e9182841

View File

@ -294,7 +294,7 @@ int
readsb(int listerr)
{
ufs2_daddr_t super;
int i;
int i, bad;
if (bflag) {
super = bflag;
@ -344,43 +344,53 @@ readsb(int listerr)
dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
sblk.b_bno = super / dev_bsize;
sblk.b_size = SBLOCKSIZE;
if (bflag)
goto out;
/*
* Compare all fields that should not differ in alternate super block.
* When an alternate super-block is specified this check is skipped.
*/
if (bflag)
goto out;
getblk(&asblk, cgsblock(&sblock, sblock.fs_ncg - 1), sblock.fs_sbsize);
if (asblk.b_errs)
return (0);
if (altsblock.fs_sblkno != sblock.fs_sblkno ||
altsblock.fs_cblkno != sblock.fs_cblkno ||
altsblock.fs_iblkno != sblock.fs_iblkno ||
altsblock.fs_dblkno != sblock.fs_dblkno ||
altsblock.fs_ncg != sblock.fs_ncg ||
altsblock.fs_bsize != sblock.fs_bsize ||
altsblock.fs_fsize != sblock.fs_fsize ||
altsblock.fs_frag != sblock.fs_frag ||
altsblock.fs_bmask != sblock.fs_bmask ||
altsblock.fs_fmask != sblock.fs_fmask ||
altsblock.fs_bshift != sblock.fs_bshift ||
altsblock.fs_fshift != sblock.fs_fshift ||
altsblock.fs_fragshift != sblock.fs_fragshift ||
altsblock.fs_fsbtodb != sblock.fs_fsbtodb ||
altsblock.fs_sbsize != sblock.fs_sbsize ||
altsblock.fs_nindir != sblock.fs_nindir ||
altsblock.fs_inopb != sblock.fs_inopb ||
altsblock.fs_cssize != sblock.fs_cssize ||
altsblock.fs_ipg != sblock.fs_ipg ||
altsblock.fs_fpg != sblock.fs_fpg ||
altsblock.fs_magic != sblock.fs_magic) {
bad = 0;
#define CHK(x, y) \
if (altsblock.x != sblock.x) { \
bad++; \
if (listerr && debug) \
printf("SUPER BLOCK VS ALTERNATE MISMATCH %s: " y " vs " y "\n", \
#x, (intmax_t)sblock.x, (intmax_t)altsblock.x); \
}
CHK(fs_sblkno, "%jd");
CHK(fs_cblkno, "%jd");
CHK(fs_iblkno, "%jd");
CHK(fs_dblkno, "%jd");
CHK(fs_ncg, "%jd");
CHK(fs_bsize, "%jd");
CHK(fs_fsize, "%jd");
CHK(fs_frag, "%jd");
CHK(fs_bmask, "%#jx");
CHK(fs_fmask, "%#jx");
CHK(fs_bshift, "%jd");
CHK(fs_fshift, "%jd");
CHK(fs_fragshift, "%jd");
CHK(fs_fsbtodb, "%jd");
CHK(fs_sbsize, "%jd");
CHK(fs_nindir, "%jd");
CHK(fs_inopb, "%jd");
CHK(fs_cssize, "%jd");
CHK(fs_ipg, "%jd");
CHK(fs_fpg, "%jd");
CHK(fs_magic, "%#jx");
#undef CHK
if (bad) {
if (listerr == 0)
return (0);
if (preen)
printf("%s: ", cdevname);
printf(
"VALUES IN SUPER BLOCK LSB=%jd DISAGREE WITH THOSE IN\n"
"FIRST ALTERNATE LSB=%jd\n",
"LAST ALTERNATE LSB=%jd\n",
sblk.b_bno, asblk.b_bno);
if (reply("IGNORE ALTERNATE SUPER BLOCK") == 0)
return (0);