Whamcloud - gitweb
e2fsck: track errors/badness found for each inode
[tools/e2fsprogs.git] / e2fsck / problem.c
index fe3b06a..83a3703 100644 (file)
  * to fix a problem.
  */
 static const char *prompt[] = {
-       N_("(no prompt)"),      /* 0 */
-       N_("Fix"),              /* 1 */
-       N_("Clear"),            /* 2 */
-       N_("Relocate"),         /* 3 */
-       N_("Allocate"),         /* 4 */
-       N_("Expand"),           /* 5 */
-       N_("Connect to /lost+found"), /* 6 */
-       N_("Create"),           /* 7 */
-       N_("Salvage"),          /* 8 */
-       N_("Truncate"),         /* 9 */
-       N_("Clear inode"),      /* 10 */
-       N_("Abort"),            /* 11 */
-       N_("Split"),            /* 12 */
-       N_("Continue"),         /* 13 */
-       N_("Clone multiply-claimed blocks"), /* 14 */
-       N_("Delete file"),      /* 15 */
-       N_("Suppress messages"),/* 16 */
-       N_("Unlink"),           /* 17 */
-       N_("Clear HTree index"),/* 18 */
-       N_("Recreate"),         /* 19 */
-       N_("Optimize"),         /* 20 */
-       N_("Clear flag"),       /* 21 */
-       "",                     /* 22 */
+       N_("(no prompt)"),                      /* PROMPT_NONE          =  0 */
+       N_("Fix"),                              /* PROMPT_FIX           =  1 */
+       N_("Clear"),                            /* PROMPT_CLEAR         =  2 */
+       N_("Relocate"),                         /* PROMPT_RELOCATE      =  3 */
+       N_("Allocate"),                         /* PROMPT_CREATE        =  4 */
+       N_("Expand"),                           /* PROMPT_EXPAND        =  5 */
+       N_("Connect to /lost+found"),           /* PROMPT_CONNECT       =  6 */
+       N_("Create"),                           /* PROMPT_CREATE        =  7 */
+       N_("Salvage"),                          /* PROMPT_SALVAGE       =  8 */
+       N_("Truncate"),                         /* PROMPT_TRUNCATE      =  9 */
+       N_("Clear inode"),                      /* PROMPT_CLEAR_INODE   = 10 */
+       N_("Abort"),                            /* PROMPT_ABORT         = 11 */
+       N_("Split"),                            /* PROMPT_SPLIT         = 12 */
+       N_("Continue"),                         /* PROMPT_CONTINUE      = 13 */
+       N_("Clone multiply-claimed blocks"),    /* PROMPT_CLONE         = 14 */
+       N_("Delete file"),                      /* PROMPT_DELETE        = 15 */
+       N_("Suppress messages"),                /* PROMPT_SUPPRESS      = 16 */
+       N_("Unlink"),                           /* PROMPT_UNLINK        = 17 */
+       N_("Clear HTree index"),                /* PROMPT_CLEAR_HTREE   = 18 */
+       N_("Recreate"),                         /* PROMPT_RECREATE      = 19 */
+       N_("Optimize"),                         /* PROMPT_OPTIMIZE      = 20 */
+       N_("Clear flag"),                       /* PROMPT_CLEAR_FLAG    = 21 */
+       "",                                     /* PROMPT_NULL          = 22 */
 };
 
 /*
@@ -379,7 +379,7 @@ static struct e2fsck_problem problem_table[] = {
        /* group descriptor N checksum is invalid, should be yyyy. */
        { PR_0_GDT_CSUM,
          N_("@g descriptor %g checksum is %04x, should be %04y.  "),
-            PROMPT_FIX, PR_LATCH_BG_CHECKSUM, 0, 0, 0 },
+            PROMPT_FIX, PR_PREEN_OK | PR_LATCH_BG_CHECKSUM, 0, 0, 0 },
 
        /* group descriptor N marked uninitialized without feature set. */
        { PR_0_GDT_UNINIT,
@@ -526,6 +526,14 @@ static struct e2fsck_problem problem_table[] = {
             "not compatible. Resize @i should be disabled.  "),
          PROMPT_FIX, 0, 0, 0, 0 },
 
+       { PR_0_MIN_EXTRA_ISIZE_INVALID,
+         N_("@S has invalid s_min_extra_isize.  "),
+         PROMPT_FIX, PR_PREEN_OK },
+
+       { PR_0_WANT_EXTRA_ISIZE_INVALID,
+         N_("@S has invalid s_want_extra_isize.  "),
+         PROMPT_FIX, PR_PREEN_OK },
+
        /* Pass 1 errors */
 
        /* Pass 1: Checking inodes, blocks, and sizes */
@@ -1279,6 +1287,46 @@ static struct e2fsck_problem problem_table[] = {
          N_("@h %i uses SipHash, but should not.  "),
          PROMPT_CLEAR_HTREE, PR_PREEN_OK, 0, 0, 0 },
 
+       /* expand inode */
+       { PR_1_EXPAND_EISIZE_WARNING,
+         N_("\ne2fsck is being run with \"expand_extra_isize\" option or\n"
+            "s_min_extra_isize of %d bytes has been set in the superblock.\n"
+            "Inode %i does not have enough free space.  Either some EAs\n"
+            "need to be deleted from this inode or the RO_COMPAT_EXTRA_ISIZE\n"
+            "flag must be cleared.\n\n"), PROMPT_NONE, PR_PREEN_OK | PR_NO_OK |
+            PR_PREEN_NOMSG },
+
+       /* expand inode */
+       { PR_1_EXPAND_EISIZE,
+         N_("Expanding @i %i.\n"),
+         PROMPT_NONE, PR_PREEN_OK | PR_NO_OK | PR_PREEN_NOMSG },
+
+       /* delete an EA so that EXTRA_ISIZE feature may be enabled */
+       { PR_1_EISIZE_DELETE_EA,
+         N_("Delete EA %s of @i %i so that EXTRA_ISIZE feature may be "
+            "enabled?\n"), PROMPT_FIX, PR_NO_OK | PR_PREEN_NO },
+
+       /* an EA needs to be deleted by e2fsck is being run with -p or -y */
+       { PR_1_EA_BLK_NOSPC,
+         N_("An EA needs to be deleted for @i %i but e2fsck is being run\n"
+            "with -p or -y mode.\n"),
+         PROMPT_ABORT, 0 },
+
+       /* disable EXTRA_ISIZE feature since inode cannot be expanded */
+       { PR_1_CLEAR_EXTRA_ISIZE,
+         N_("Disable EXTRA_ISIZE feature since @i %i cannot be expanded\n"
+            "without deletion of an EA.\n"),
+         PROMPT_FIX, 0 },
+
+       /* invalid inode creation time */
+       { PR_1_CRTIME_BAD,
+         N_("@i %i creation time (%t) invalid.\n"),
+         PROMPT_CLEAR, PR_PREEN_OK | PR_NO_OK },
+
+       /* Failed to goto block group */
+       { PR_1_SCAN_GOTO,
+         N_("failed to goto block group"),
+          PROMPT_NONE, PR_FATAL, 0, 0, 0 },
 
        /* Pass 1b errors */
 
@@ -1332,6 +1380,11 @@ static struct e2fsck_problem problem_table[] = {
          " %b--%c",
          PROMPT_NONE, PR_LATCH_DBLOCK | PR_PREEN_NOHDR, 0, 0, 0 },
 
+       /* Inode is badly corrupt (badness value = ) */
+       { PR_1B_INODE_TOOBAD,
+         N_("@i %i is badly corrupt (badness value = %N).  "),
+         PROMPT_CLEAR, PR_PREEN_OK },
+
        /* Pass 1C: Scan directories for inodes with multiply-claimed blocks. */
        { PR_1C_PASS_HEADER,
          N_("Pass 1C: Scanning directories for @is with @m @bs\n"),
@@ -1382,6 +1435,14 @@ static struct e2fsck_problem problem_table[] = {
          /* xgettext:no-c-format */
          N_("Couldn't clone file: %m\n"), PROMPT_NONE, 0, 0, 0, 0 },
 
+       /* File with shared blocks found */
+       { PR_1D_DISCONNECT_QUESTION,
+         N_("File with shared blocks found\n"), PROMPT_CONNECT, 0 },
+
+       /* Couldn't unlink file (error) */
+       { PR_1D_DISCONNECT_ERROR,
+         N_("Couldn't unlink file: %m\n"), PROMPT_NONE, 0 },
+
        /* Pass 1E Extent tree optimization     */
 
        /* Pass 1E: Optimizing extent trees */
@@ -1666,7 +1727,7 @@ static struct e2fsck_problem problem_table[] = {
        /* Filesystem contains large files, but has no such flag in sb */
        { PR_2_FEATURE_LARGE_FILES,
          N_("@f contains large files, but lacks LARGE_FILE flag in @S.\n"),
-         PROMPT_FIX, 0, 0, 0, 0 },
+         PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
 
        /* Node in HTREE directory not referenced */
        { PR_2_HTREE_NOTREF,
@@ -1692,6 +1753,11 @@ static struct e2fsck_problem problem_table[] = {
        { PR_2_HTREE_CLEAR,
          N_("@n @h %d (%q).  "), PROMPT_CLEAR_HTREE, 0, 0, 0, 0 },
 
+       /* Filesystem has large directories, but has no such flag in sb */
+       { PR_2_FEATURE_LARGE_DIRS,
+         N_("@f has large directories, but lacks LARGE_DIR flag in @S.\n"),
+         PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
+
        /* Bad block in htree interior node */
        { PR_2_HTREE_BADBLK,
          N_("@p @h %d (%q): bad @b number %b.\n"),
@@ -1702,7 +1768,7 @@ static struct e2fsck_problem problem_table[] = {
          N_("Error adjusting refcount for @a @b %b (@i %i): %m\n"),
          PROMPT_NONE, PR_FATAL, 0, 0, 0 },
 
-       /* Invalid HTREE root node */
+       /* Problem in HTREE directory inode: root node is invalid */
        { PR_2_HTREE_BAD_ROOT,
          /* xgettext:no-c-format */
          N_("@p @h %d: root node is @n\n"),
@@ -1826,6 +1892,10 @@ static struct e2fsck_problem problem_table[] = {
           N_("Duplicate filename @E found.  "),
           PROMPT_CLEAR, 0, 0, 0, 0 },
 
+       /* Inode is badly corrupt (badness value = ) */
+       { PR_2_INODE_TOOBAD,
+         N_("@i %i is badly corrupt (badness value = %N).  "),
+         PROMPT_CLEAR, PR_PREEN_OK },
 
        /* Pass 3 errors */
 
@@ -1847,7 +1917,7 @@ static struct e2fsck_problem problem_table[] = {
        /* Unconnected directory inode */
        { PR_3_UNCONNECTED_DIR,
          /* xgettext:no-c-format */
-         N_("Unconnected @d @i %i (%p)\n"),
+         N_("Unconnected @d @i %i (was in %q)\n"),
          PROMPT_CONNECT, 0, 0, 0, 0 },
 
        /* /lost+found not found */
@@ -1984,6 +2054,12 @@ static struct e2fsck_problem problem_table[] = {
          N_("/@l is encrypted\n"),
          PROMPT_CLEAR, 0, 0, 0, 0 },
 
+       /* Recursively looped directory inode */
+       { PR_3_LOOPED_DIR,
+         /* xgettext:no-c-format */
+         N_("Recursively looped @d @i %i (%p)\n"),
+         PROMPT_CONNECT, 0, 0, 0, 0 },
+
        /* Pass 3A Directory Optimization       */
 
        /* Pass 3A: Optimizing directories */
@@ -2219,6 +2295,11 @@ static struct e2fsck_problem problem_table[] = {
          N_("@g %g @b @B does not match checksum.\n"),
          PROMPT_FIX, PR_LATCH_BBITMAP | PR_PREEN_OK, 0, 0, 0 },
 
+       /* Expand inode */
+       { PR_5_EXPAND_EISIZE,
+         N_("Expanding @i %i.\n"),
+         PROMPT_NONE, PR_PREEN_OK | PR_NO_OK | PR_PREEN_NOMSG },
+
        /* Post-Pass 5 errors */
 
        /* Recreate journal if E2F_FLAG_JOURNAL_INODE flag is set */
@@ -2310,6 +2391,8 @@ int end_problem_latch(e2fsck_t ctx, int mask)
        int answer = -1;
 
        ldesc = find_latch(mask);
+       if (!ldesc)
+               return answer;
        if (ldesc->end_message && (ldesc->flags & PRL_LATCHED)) {
                clear_problem_context(&pctx);
                answer = fix_problem(ctx, ldesc->end_message, &pctx);
@@ -2381,11 +2464,11 @@ static void print_problem(FILE *f, problem_t code, int answer, int fixed,
        if (pctx->dir)
                fprintf(f, " dir=\"%u\"", pctx->dir);
        if (pctx->blk)
-               fprintf(f, " blk=\"%llu\"", pctx->blk);
+               fprintf(f, " blk=\"%llu\"", (unsigned long long) pctx->blk);
        if (pctx->blk2)
-               fprintf(f, " blk2=\"%llu\"", pctx->blk2);
+               fprintf(f, " blk2=\"%llu\"", (unsigned long long) pctx->blk2);
        if (pctx->blkcount != (e2_blkcnt_t) -1)
-               fprintf(f, " blkcount=\"%lld\"", pctx->blkcount);
+               fprintf(f, " blkcount=\"%lld\"", (unsigned long long) pctx->blkcount);
        if (pctx->group != (dgrp_t) -1)
                fprintf(f, " group=\"%u\"", pctx->group);
        if (pctx->csum1)
@@ -2393,15 +2476,16 @@ static void print_problem(FILE *f, problem_t code, int answer, int fixed,
        if (pctx->csum2)
                fprintf(f, " csum2=\"%u\"", pctx->csum2);
        if (pctx->num)
-               fprintf(f, " num=\"%llu\"", pctx->num);
+               fprintf(f, " num=\"%llu\"", (unsigned long long) pctx->num);
        if (pctx->num2)
-               fprintf(f, " num2=\"%llu\"", pctx->num2);
+               fprintf(f, " num2=\"%llu\"", (unsigned long long) pctx->num2);
        if (pctx->str)
                fprintf(f, " str=\"%s\"", pctx->str);
        fputs("/>\n", f);
 }
 
-int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
+int fix_problem_loc(e2fsck_t ctx, problem_t code, struct problem_context *pctx,
+                   int badness, const char *func, const int line)
 {
        ext2_filsys fs = ctx->fs;
        struct e2fsck_problem *ptr;
@@ -2412,6 +2496,10 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
        int             suppress = 0;
        int             fixed = 0;
 
+       /* ino is always set in pass1, where we will hit most badness */
+       if (pctx && pctx->ino != 0 && badness && code < PR_3_PASS_HEADER)
+               e2fsck_mark_inode_bad_loc(ctx, pctx, code, badness, func, line);
+
        ptr = find_problem(code);
        if (!ptr) {
                printf(_("Unhandled error code (0x%x)!\n"), code);
@@ -2456,10 +2544,11 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
         * Do special latch processing.  This is where we ask the
         * latch question, if it exists
         */
-       if (ptr->flags & PR_LATCH_MASK) {
-               ldesc = find_latch(ptr->flags & PR_LATCH_MASK);
+       if (ptr->flags & PR_LATCH_MASK &&
+           (ldesc = find_latch(ptr->flags & PR_LATCH_MASK)) != NULL) {
                if (ldesc->question && !(ldesc->flags & PRL_LATCHED)) {
-                       ans = fix_problem(ctx, ldesc->question, pctx);
+                       ans = fix_problem_loc(ctx, ldesc->question, pctx,
+                                             0, func, line);
                        if (ans == 1)
                                ldesc->flags |= PRL_YES;
                        if (ans == 0)
@@ -2481,8 +2570,7 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
                if ((ctx->options & E2F_OPT_PREEN) &&
                    (ptr->flags & PR_PREEN_OK))
                        suppress++;
-               if ((ptr->flags & PR_LATCH_MASK) &&
-                   (ldesc->flags & (PRL_YES | PRL_NO)))
+               if (ldesc && (ldesc->flags & (PRL_YES | PRL_NO)))
                        suppress++;
                if (ptr->count == ptr->max_count + 1) {
                        if (ctx->problem_logf)
@@ -2498,6 +2586,12 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
        if (*message)
                message = _(message);
        if (!suppress) {
+#ifdef HAVE_PTHREAD
+               if ((ctx->options & E2F_OPT_MULTITHREAD) && ctx->global_ctx)
+                       printf("[Thread %d] ",
+                              ctx->thread_info.et_thread_index);
+#endif
+
                if ((ctx->options & E2F_OPT_PREEN) &&
                    !(ptr->flags & PR_PREEN_NOHDR)) {
                        printf("%s: ", ctx->device_name ?
@@ -2527,8 +2621,7 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
                        answer = def_yn;
                        if (!(ptr->flags & PR_PREEN_NOMSG))
                                print_answer = 1;
-               } else if ((ptr->flags & PR_LATCH_MASK) &&
-                          (ldesc->flags & (PRL_YES | PRL_NO))) {
+               } else if (ldesc && (ldesc->flags & (PRL_YES | PRL_NO))) {
                        print_answer = 1;
                        if (ldesc->flags & PRL_YES)
                                answer = 1;
@@ -2556,7 +2649,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
                fatal_error(ctx, 0);
 
        if (ptr->flags & PR_AFTER_CODE)
-               answer = fix_problem(ctx, ptr->second_code, pctx);
+               answer = fix_problem_loc(ctx, ptr->second_code, pctx,
+                                        0, func, line);
 
        if (answer && (ptr->prompt != PROMPT_NONE) &&
            !(ptr->flags & PR_NOT_A_FIX)) {
@@ -2607,6 +2701,13 @@ void preenhalt(e2fsck_t ctx)
        return;
 }
 
+void e2fsck_mark_inode_bad_loc(e2fsck_t ctx,
+                              struct problem_context *pctx, __u32 code,
+                              int count, const char *func, const int line)
+{
+       return;
+}
+
 errcode_t
 profile_get_string(profile_t profile, const char *name, const char *subname,
                   const char *subsubname, const char *def_val,