Whamcloud - gitweb
misc/create_inode.c: copy files recursively
[tools/e2fsprogs.git] / e2fsck / e2fsck.c
index de2e532..0ec1540 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * e2fsck.c - a consistency checker for the new extended file system.
- * 
+ *
  * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
  *
  * %Begin-Header%
@@ -9,13 +9,14 @@
  * %End-Header%
  */
 
+#include "config.h"
 #include <errno.h>
 
 #include "e2fsck.h"
 #include "problem.h"
 
 /*
- * This function allocates an e2fsck context 
+ * This function allocates an e2fsck context
  */
 errcode_t e2fsck_allocate_context(e2fsck_t *ret)
 {
@@ -26,18 +27,22 @@ errcode_t e2fsck_allocate_context(e2fsck_t *ret)
        retval = ext2fs_get_mem(sizeof(struct e2fsck_struct), &context);
        if (retval)
                return retval;
-       
+
        memset(context, 0, sizeof(struct e2fsck_struct));
 
        context->process_inode_size = 256;
        context->ext_attr_ver = 2;
        context->blocks_per_page = 1;
-       
+       context->htree_slack_percentage = 255;
+
        time_env = getenv("E2FSCK_TIME");
        if (time_env)
                context->now = strtoul(time_env, NULL, 0);
-       else
+       else {
                context->now = time(0);
+               if (context->now < 1262322000) /* January 1 2010 */
+                       context->flags |= E2F_FLAG_TIME_INSANE;
+       }
 
        *ret = context;
        return 0;
@@ -51,7 +56,7 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
 {
        int     i;
 
-       ctx->flags = 0;
+       ctx->flags &= E2F_RESET_FLAGS;
        ctx->lost_and_found = 0;
        ctx->bad_lost_and_found = 0;
        if (ctx->inode_used_map) {
@@ -152,6 +157,7 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
        ctx->fs_dind_count = 0;
        ctx->fs_tind_count = 0;
        ctx->fs_fragmented = 0;
+       ctx->fs_fragmented_dir = 0;
        ctx->large_files = 0;
 
        for (i=0; i < MAX_EXTENT_DEPTH_COUNT; i++)
@@ -159,7 +165,7 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
 
        /* Reset the superblock to the user's requested value */
        ctx->superblock = ctx->use_superblock;
-       
+
        return 0;
 }
 
@@ -167,7 +173,7 @@ void e2fsck_free_context(e2fsck_t ctx)
 {
        if (!ctx)
                return;
-       
+
        e2fsck_reset_context(ctx);
        if (ctx->blkid)
                blkid_put_cache(ctx->blkid);
@@ -177,10 +183,13 @@ void e2fsck_free_context(e2fsck_t ctx)
 
        if (ctx->filesystem_name)
                ext2fs_free_mem(&ctx->filesystem_name);
-                       
+
        if (ctx->device_name)
                ext2fs_free_mem(&ctx->device_name);
-                       
+
+       if (ctx->log_fn)
+               free(ctx->log_fn);
+
        ext2fs_free_mem(&ctx);
 }
 
@@ -190,7 +199,7 @@ void e2fsck_free_context(e2fsck_t ctx)
  */
 typedef void (*pass_t)(e2fsck_t ctx);
 
-pass_t e2fsck_passes[] = {
+static pass_t e2fsck_passes[] = {
        e2fsck_pass1, e2fsck_pass2, e2fsck_pass3, e2fsck_pass4,
        e2fsck_pass5, 0 };
 
@@ -208,16 +217,18 @@ int e2fsck_run(e2fsck_t ctx)
        }
        ctx->flags |= E2F_FLAG_SETJMP_OK;
 #endif
-               
+
        for (i=0; (e2fsck_pass = e2fsck_passes[i]); i++) {
                if (ctx->flags & E2F_FLAG_RUN_RETURN)
                        break;
+               if (e2fsck_mmp_update(ctx->fs))
+                       fatal_error(ctx, 0);
                e2fsck_pass(ctx);
                if (ctx->progress)
                        (void) (ctx->progress)(ctx, 0, 0, 0);
        }
        ctx->flags &= ~E2F_FLAG_SETJMP_OK;
-       
+
        if (ctx->flags & E2F_FLAG_RUN_RETURN)
                return (ctx->flags & E2F_FLAG_RUN_RETURN);
        return 0;