Whamcloud - gitweb
e2fsck: check extended attribute block checksums
authorDarrick J. Wong <djwong@us.ibm.com>
Fri, 3 Aug 2012 00:47:44 +0000 (20:47 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 3 Aug 2012 00:47:44 +0000 (20:47 -0400)
Verify the checksums of separate extended attribute blocks and offer
to clear it if there is a mismatch.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass1.c
e2fsck/problem.c
e2fsck/problem.h

index 06a5314..8907e75 100644 (file)
@@ -1557,6 +1557,7 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,
        struct ext2_ext_attr_entry *entry;
        int             count;
        region_t        region = 0;
+       int             failed_csum = 0;
 
        blk = ext2fs_file_acl_block(fs, inode);
        if (blk == 0)
@@ -1631,6 +1632,11 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,
         */
        pctx->blk = blk;
        pctx->errcode = ext2fs_read_ext_attr3(fs, blk, block_buf, pctx->ino);
+       if (pctx->errcode == EXT2_ET_EXT_ATTR_CSUM_INVALID) {
+               if (fix_problem(ctx, PR_1_EA_BLOCK_CSUM_INVALID, pctx))
+                       goto clear_extattr;
+               failed_csum = 1;
+       }
        if (pctx->errcode && fix_problem(ctx, PR_1_READ_EA_BLOCK, pctx))
                goto clear_extattr;
        header = (struct ext2_ext_attr_header *) block_buf;
@@ -1712,6 +1718,18 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,
        }
        region_free(region);
 
+       /*
+        * We only get here if there was no other errors that were fixed.
+        * If there was a checksum fail, ask to correct it.
+        */
+       if (failed_csum &&
+           fix_problem(ctx, PR_1_EA_BLOCK_ONLY_CSUM_INVALID, pctx)) {
+               pctx->errcode = ext2fs_write_ext_attr3(fs, blk, block_buf,
+                                                      pctx->ino);
+               if (pctx->errcode)
+                       return 0;
+       }
+
        count = header->h_refcount - 1;
        if (count)
                ea_refcount_store(ctx->refcount, blk, count);
index e6c2ebb..1f59564 100644 (file)
@@ -971,6 +971,21 @@ static struct e2fsck_problem problem_table[] = {
             "extent\n\t(logical @b %c, @n physical @b %b, len %N)\n"),
          PROMPT_FIX, 0 },
 
+       /* Extended attribute block checksum for inode does not match. */
+       { PR_1_EA_BLOCK_CSUM_INVALID,
+         N_("Extended attribute @a @b %b checksum for @i %i does not "
+            "match.  "),
+         PROMPT_CLEAR, 0 },
+
+       /*
+        * Extended attribute block passes checks, but checksum for inode does
+        * not match.
+        */
+       { PR_1_EA_BLOCK_ONLY_CSUM_INVALID,
+         N_("Extended attribute @a @b %b passes checks, but checksum for "
+            "@i %i does not match.  "),
+         PROMPT_FIX, 0 },
+
        /* Pass 1b errors */
 
        /* Pass 1B: Rescan for duplicate/bad blocks */
index 65be731..f87f4e8 100644 (file)
@@ -570,6 +570,12 @@ struct problem_context {
 /* extent block passes checks, but checksum does not match extent block */
 #define PR_1_EXTENT_ONLY_CSUM_INVALID  0x01006A
 
+/* ea block checksum invalid */
+#define PR_1_EA_BLOCK_CSUM_INVALID     0x01006B
+
+/* ea block passes checks, but checksum invalid */
+#define PR_1_EA_BLOCK_ONLY_CSUM_INVALID        0x01006C
+
 /*
  * Pass 1b errors
  */