e2fsck: Interpret negative blkcount in file system problem reports

Non-expert users get confused when they see messages like this:

Illegal block #-1 (2291965952) in inode 176. CLEARED.

So change it to be something a little bit more understandable:

Illegal indirect block (2291965952) in inode 176.  CLEARED.

Addresses-SourceForge-Bug: #2871782

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2009-10-04 18:02:24 -04:00
parent f790bc33b2
commit 695706ca21
10 changed files with 1010 additions and 985 deletions

View File

@ -14,7 +14,7 @@
* The following % expansions are supported: * The following % expansions are supported:
* *
* %b <blk> block number * %b <blk> block number
* %B <blkcount> integer * %B <blkcount> interpret blkcount as blkcount
* %c <blk2> block number * %c <blk2> block number
* %Di <dirent>->ino inode number * %Di <dirent>->ino inode number
* %Dn <dirent>->name string * %Dn <dirent>->name string
@ -46,6 +46,7 @@
* %q ext2fs_get_pathname of directory <dir> * %q ext2fs_get_pathname of directory <dir>
* %Q ext2fs_get_pathname of directory <ino> with <dir> as * %Q ext2fs_get_pathname of directory <ino> with <dir> as
* the containing directory. * the containing directory.
* %r <blkcount> interpret blkcount as refcount
* %s <str> miscellaneous string * %s <str> miscellaneous string
* %S backup superblock * %S backup superblock
* %X <num> hexadecimal format * %X <num> hexadecimal format
@ -395,9 +396,11 @@ static _INLINE_ void expand_dirent_expression(ext2_filsys fs, char ch,
} }
static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch, static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
int *first,
struct problem_context *ctx) struct problem_context *ctx)
{ {
e2fsck_t e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL; e2fsck_t e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL;
const char *m;
if (!ctx) if (!ctx)
goto no_context; goto no_context;
@ -414,11 +417,26 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
#endif #endif
break; break;
case 'B': case 'B':
if (ctx->blkcount == BLOCK_COUNT_IND)
m = _("indirect block");
else if (ctx->blkcount == BLOCK_COUNT_DIND)
m = _("double indirect block");
else if (ctx->blkcount == BLOCK_COUNT_TIND)
m = _("triple indirect block");
else if (ctx->blkcount == BLOCK_COUNT_TRANSLATOR)
m = _("translator block");
else
m = _("block #");
if (*first && islower(m[0]))
fputc(toupper(*m++), stdout);
fputs(m, stdout);
if (ctx->blkcount >= 0) {
#ifdef EXT2_NO_64_TYPE #ifdef EXT2_NO_64_TYPE
printf("%d", ctx->blkcount); printf("%d", ctx->blkcount);
#else #else
printf("%lld", (long long)ctx->blkcount); printf("%lld", (long long) ctx->blkcount);
#endif #endif
}
break; break;
case 'c': case 'c':
#ifdef EXT2_NO_64_TYPE #ifdef EXT2_NO_64_TYPE
@ -462,6 +480,13 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
case 'Q': case 'Q':
print_pathname(fs, ctx->dir, ctx->ino); print_pathname(fs, ctx->dir, ctx->ino);
break; break;
case 'r':
#ifdef EXT2_NO_64_TYPE
printf("%d", ctx->blkcount);
#else
printf("%lld", (long long) ctx->blkcount);
#endif
break;
case 'S': case 'S':
printf("%u", get_backup_sb(NULL, fs, NULL, NULL)); printf("%u", get_backup_sb(NULL, fs, NULL, NULL));
break; break;
@ -509,7 +534,7 @@ void print_e2fsck_message(e2fsck_t ctx, const char *msg,
expand_dirent_expression(fs, *cp, pctx); expand_dirent_expression(fs, *cp, pctx);
} else if ((cp[0] == '%')) { } else if ((cp[0] == '%')) {
cp++; cp++;
expand_percent_expression(fs, *cp, pctx); expand_percent_expression(fs, *cp, &first, pctx);
} else { } else {
for (i=0; cp[i]; i++) for (i=0; cp[i]; i++)
if ((cp[i] == '@') || cp[i] == '%') if ((cp[i] == '@') || cp[i] == '%')

View File

@ -252,12 +252,12 @@ static struct e2fsck_problem problem_table[] = {
/* Illegal block found in orphaned inode */ /* Illegal block found in orphaned inode */
{ PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, { PR_0_ORPHAN_ILLEGAL_BLOCK_NUM,
N_("@I @b #%B (%b) found in @o @i %i.\n"), N_("@I %B (%b) found in @o @i %i.\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Already cleared block found in orphaned inode */ /* Already cleared block found in orphaned inode */
{ PR_0_ORPHAN_ALREADY_CLEARED_BLOCK, { PR_0_ORPHAN_ALREADY_CLEARED_BLOCK,
N_("Already cleared @b #%B (%b) found in @o @i %i.\n"), N_("Already cleared %B (%b) found in @o @i %i.\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Illegal orphan inode in superblock */ /* Illegal orphan inode in superblock */
@ -475,12 +475,12 @@ static struct e2fsck_problem problem_table[] = {
/* Illegal blocknumber in inode */ /* Illegal blocknumber in inode */
{ PR_1_ILLEGAL_BLOCK_NUM, { PR_1_ILLEGAL_BLOCK_NUM,
N_("@I @b #%B (%b) in @i %i. "), N_("@I %B (%b) in @i %i. "),
PROMPT_CLEAR, PR_LATCH_BLOCK }, PROMPT_CLEAR, PR_LATCH_BLOCK },
/* Block number overlaps fs metadata */ /* Block number overlaps fs metadata */
{ PR_1_BLOCK_OVERLAPS_METADATA, { PR_1_BLOCK_OVERLAPS_METADATA,
N_("@b #%B (%b) overlaps @f metadata in @i %i. "), N_("%B (%b) overlaps @f metadata in @i %i. "),
PROMPT_CLEAR, PR_LATCH_BLOCK }, PROMPT_CLEAR, PR_LATCH_BLOCK },
/* Inode has illegal blocks (latch question) */ /* Inode has illegal blocks (latch question) */
@ -495,7 +495,7 @@ static struct e2fsck_problem problem_table[] = {
/* Illegal block number in bad block inode */ /* Illegal block number in bad block inode */
{ PR_1_BB_ILLEGAL_BLOCK_NUM, { PR_1_BB_ILLEGAL_BLOCK_NUM,
N_("@I @b #%B (%b) in bad @b @i. "), N_("@I %B (%b) in bad @b @i. "),
PROMPT_CLEAR, PR_LATCH_BBLOCK }, PROMPT_CLEAR, PR_LATCH_BBLOCK },
/* Bad block inode has illegal blocks (latch question) */ /* Bad block inode has illegal blocks (latch question) */
@ -707,7 +707,7 @@ static struct e2fsck_problem problem_table[] = {
/* Extended attribute reference count incorrect */ /* Extended attribute reference count incorrect */
{ PR_1_EXTATTR_REFCOUNT, { PR_1_EXTATTR_REFCOUNT,
N_("@a @b %b has reference count %B, @s %N. "), N_("@a @b %b has reference count %r, @s %N. "),
PROMPT_FIX, 0 }, PROMPT_FIX, 0 },
/* Error writing Extended Attribute block while fixing refcount */ /* Error writing Extended Attribute block while fixing refcount */
@ -746,17 +746,17 @@ static struct e2fsck_problem problem_table[] = {
/* Directory too big */ /* Directory too big */
{ PR_1_TOOBIG_DIR, { PR_1_TOOBIG_DIR,
N_("@b #%B (%b) causes @d to be too big. "), N_("%B (%b) causes @d to be too big. "),
PROMPT_CLEAR, PR_LATCH_TOOBIG }, PROMPT_CLEAR, PR_LATCH_TOOBIG },
/* Regular file too big */ /* Regular file too big */
{ PR_1_TOOBIG_REG, { PR_1_TOOBIG_REG,
N_("@b #%B (%b) causes file to be too big. "), N_("%B (%b) causes file to be too big. "),
PROMPT_CLEAR, PR_LATCH_TOOBIG }, PROMPT_CLEAR, PR_LATCH_TOOBIG },
/* Symlink too big */ /* Symlink too big */
{ PR_1_TOOBIG_SYMLINK, { PR_1_TOOBIG_SYMLINK,
N_("@b #%B (%b) causes symlink to be too big. "), N_("%B (%b) causes symlink to be too big. "),
PROMPT_CLEAR, PR_LATCH_TOOBIG }, PROMPT_CLEAR, PR_LATCH_TOOBIG },
/* INDEX_FL flag set on a non-HTREE filesystem */ /* INDEX_FL flag set on a non-HTREE filesystem */
@ -943,7 +943,7 @@ static struct e2fsck_problem problem_table[] = {
/* File has duplicate blocks */ /* File has duplicate blocks */
{ PR_1D_DUP_FILE, { PR_1D_DUP_FILE,
N_("File %Q (@i #%i, mod time %IM) \n" N_("File %Q (@i #%i, mod time %IM) \n"
" has %B @m @b(s), shared with %N file(s):\n"), " has %r @m @b(s), shared with %N file(s):\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* List of files sharing duplicate blocks */ /* List of files sharing duplicate blocks */
@ -1077,17 +1077,17 @@ static struct e2fsck_problem problem_table[] = {
/* directory corrupted */ /* directory corrupted */
{ PR_2_DIR_CORRUPTED, { PR_2_DIR_CORRUPTED,
N_("@d @i %i, @b %B, offset %N: @d corrupted\n"), N_("@d @i %i, %B, offset %N: @d corrupted\n"),
PROMPT_SALVAGE, 0 }, PROMPT_SALVAGE, 0 },
/* filename too long */ /* filename too long */
{ PR_2_FILENAME_LONG, { PR_2_FILENAME_LONG,
N_("@d @i %i, @b %B, offset %N: filename too long\n"), N_("@d @i %i, %B, offset %N: filename too long\n"),
PROMPT_TRUNCATE, 0 }, PROMPT_TRUNCATE, 0 },
/* Directory inode has a missing block (hole) */ /* Directory inode has a missing block (hole) */
{ PR_2_DIRECTORY_HOLE, { PR_2_DIRECTORY_HOLE,
N_("@d @i %i has an unallocated @b #%B. "), N_("@d @i %i has an unallocated %B. "),
PROMPT_ALLOCATE, 0 }, PROMPT_ALLOCATE, 0 },
/* '.' is not NULL terminated */ /* '.' is not NULL terminated */
@ -1212,22 +1212,22 @@ static struct e2fsck_problem problem_table[] = {
/* Node in HTREE directory not referenced */ /* Node in HTREE directory not referenced */
{ PR_2_HTREE_NOTREF, { PR_2_HTREE_NOTREF,
N_("@p @h %d: node (%B) not referenced\n"), N_("@p @h %d: %B not referenced\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Node in HTREE directory referenced twice */ /* Node in HTREE directory referenced twice */
{ PR_2_HTREE_DUPREF, { PR_2_HTREE_DUPREF,
N_("@p @h %d: node (%B) referenced twice\n"), N_("@p @h %d: %B referenced twice\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Node in HTREE directory has bad min hash */ /* Node in HTREE directory has bad min hash */
{ PR_2_HTREE_MIN_HASH, { PR_2_HTREE_MIN_HASH,
N_("@p @h %d: node (%B) has bad min hash\n"), N_("@p @h %d: %B has bad min hash\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Node in HTREE directory has bad max hash */ /* Node in HTREE directory has bad max hash */
{ PR_2_HTREE_MAX_HASH, { PR_2_HTREE_MAX_HASH,
N_("@p @h %d: node (%B) has bad max hash\n"), N_("@p @h %d: %B has bad max hash\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Clear invalid HTREE directory */ /* Clear invalid HTREE directory */
@ -1251,22 +1251,22 @@ static struct e2fsck_problem problem_table[] = {
/* Invalid HTREE limit */ /* Invalid HTREE limit */
{ PR_2_HTREE_BAD_LIMIT, { PR_2_HTREE_BAD_LIMIT,
N_("@p @h %d: node (%B) has @n limit (%N)\n"), N_("@p @h %d: %B has @n limit (%N)\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK }, PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* Invalid HTREE count */ /* Invalid HTREE count */
{ PR_2_HTREE_BAD_COUNT, { PR_2_HTREE_BAD_COUNT,
N_("@p @h %d: node (%B) has @n count (%N)\n"), N_("@p @h %d: %B has @n count (%N)\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK }, PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* HTREE interior node has out-of-order hashes in table */ /* HTREE interior node has out-of-order hashes in table */
{ PR_2_HTREE_HASH_ORDER, { PR_2_HTREE_HASH_ORDER,
N_("@p @h %d: node (%B) has an unordered hash table\n"), N_("@p @h %d: %B has an unordered hash table\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK }, PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* Node in HTREE directory has invalid depth */ /* Node in HTREE directory has invalid depth */
{ PR_2_HTREE_BAD_DEPTH, { PR_2_HTREE_BAD_DEPTH,
N_("@p @h %d: node (%B) has @n depth (%N)\n"), N_("@p @h %d: %B has @n depth (%N)\n"),
PROMPT_NONE, 0 }, PROMPT_NONE, 0 },
/* Duplicate directory entry found */ /* Duplicate directory entry found */

View File

@ -8,7 +8,7 @@ Bad block inode has illegal block(s). Clear? yes
Illegal block #1 (101) in bad block inode. CLEARED. Illegal block #1 (101) in bad block inode. CLEARED.
Illegal block #2 (103) in bad block inode. CLEARED. Illegal block #2 (103) in bad block inode. CLEARED.
Illegal block #3 (234523) in bad block inode. CLEARED. Illegal block #3 (234523) in bad block inode. CLEARED.
Illegal block #-1 (200) in bad block inode. CLEARED. Illegal indirect block (200) in bad block inode. CLEARED.
Pass 2: Checking directory structure Pass 2: Checking directory structure
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity
Pass 4: Checking reference counts Pass 4: Checking reference counts

View File

@ -19,7 +19,7 @@ Clear? yes
Entry 'dot' in /test (14) is a link to '.' Clear? yes Entry 'dot' in /test (14) is a link to '.' Clear? yes
Directory inode 12, block 0, offset 0: directory corrupted Directory inode 12, block #0, offset 0: directory corrupted
Salvage? yes Salvage? yes
Missing '.' in directory inode 12. Missing '.' in directory inode 12.

View File

@ -1,6 +1,6 @@
Pass 1: Checking inodes, blocks, and sizes Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure Pass 2: Checking directory structure
Directory inode 12, block 0, offset 60: directory corrupted Directory inode 12, block #0, offset 60: directory corrupted
Salvage? yes Salvage? yes
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity

View File

@ -44,7 +44,7 @@ Clear? yes
Entry '' in ??? (12) has a zero-length name. Entry '' in ??? (12) has a zero-length name.
Clear? yes Clear? yes
Directory inode 12, block 4, offset 100: directory corrupted Directory inode 12, block #4, offset 100: directory corrupted
Salvage? yes Salvage? yes
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity

View File

@ -1,11 +1,11 @@
Pass 1: Checking inodes, blocks, and sizes Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure Pass 2: Checking directory structure
Problem in HTREE directory inode 12929: node (531) has bad max hash Problem in HTREE directory inode 12929: block #531 has bad max hash
Problem in HTREE directory inode 12929: node (993) referenced twice Problem in HTREE directory inode 12929: block #993 referenced twice
Problem in HTREE directory inode 12929: node (1061) has bad min hash Problem in HTREE directory inode 12929: block #1061 has bad min hash
Problem in HTREE directory inode 12929: node (1062) has invalid depth (2) Problem in HTREE directory inode 12929: block #1062 has invalid depth (2)
Problem in HTREE directory inode 12929: node (1062) has bad max hash Problem in HTREE directory inode 12929: block #1062 has bad max hash
Problem in HTREE directory inode 12929: node (1062) not referenced Problem in HTREE directory inode 12929: block #1062 not referenced
Invalid HTREE directory inode 12929 (/test2). Clear HTree index? yes Invalid HTREE directory inode 12929 (/test2). Clear HTree index? yes
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity

View File

@ -17,17 +17,17 @@ HTREE directory inode 66721 uses an incompatible htree root node flag.
Clear HTree index? yes Clear HTree index? yes
Pass 2: Checking directory structure Pass 2: Checking directory structure
Problem in HTREE directory inode 80065: node (0) has an unordered hash table Problem in HTREE directory inode 80065: block #0 has an unordered hash table
Clear HTree index? yes Clear HTree index? yes
Problem in HTREE directory inode 86737: node (0) has invalid limit (511) Problem in HTREE directory inode 86737: block #0 has invalid limit (511)
Clear HTree index? yes Clear HTree index? yes
Problem in HTREE directory inode 93409: node (0) has invalid count (234) Problem in HTREE directory inode 93409: block #0 has invalid count (234)
Clear HTree index? yes Clear HTree index? yes
Problem in HTREE directory inode 73393: node (1) has bad min hash Problem in HTREE directory inode 73393: block #1 has bad min hash
Problem in HTREE directory inode 73393: node (2) has bad max hash Problem in HTREE directory inode 73393: block #2 has bad max hash
Invalid HTREE directory inode 73393 (/test6). Clear HTree index? yes Invalid HTREE directory inode 73393 (/test6). Clear HTree index? yes
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
Pass 1: Checking inodes, blocks, and sizes Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure Pass 2: Checking directory structure
Directory inode 13, block 0, offset 48: directory corrupted Directory inode 13, block #0, offset 48: directory corrupted
Salvage? yes Salvage? yes
Directory inode 12, block 1, offset 0: directory corrupted Directory inode 12, block #1, offset 0: directory corrupted
Salvage? yes Salvage? yes
Setting filetype for entry 'c' in /test (12) to 1. Setting filetype for entry 'c' in /test (12) to 1.
Directory inode 12, block 1, offset 1016: directory corrupted Directory inode 12, block #1, offset 1016: directory corrupted
Salvage? yes Salvage? yes
Pass 3: Checking directory connectivity Pass 3: Checking directory connectivity