Whamcloud - gitweb
e2fsck: check the checksum seed feature flag is set correctly
[tools/e2fsprogs.git] / e2fsck / ehandler.c
index 131a0ab..71ca301 100644 (file)
@@ -1,11 +1,12 @@
 /*
  * ehandler.c --- handle bad block errors which come up during the
  *     course of an e2fsck session.
- * 
+ *
  * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
  * under the terms of the GNU Public License.
  */
 
+#include "config.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -23,13 +24,18 @@ static errcode_t e2fsck_handle_read_error(io_channel channel,
                                          unsigned long block,
                                          int count,
                                          void *data,
-                                         size_t size,
-                                         int actual,
+                                         size_t size EXT2FS_ATTR((unused)),
+                                         int actual EXT2FS_ATTR((unused)),
                                          errcode_t error)
 {
        int     i;
        char    *p;
+       ext2_filsys fs = (ext2_filsys) channel->app_data;
+       e2fsck_t ctx;
 
+       ctx = (e2fsck_t) fs->priv_data;
+       if (ctx->flags & E2F_FLAG_EXITING)
+               return 0;
        /*
         * If more than one block was read, try reading each block
         * separately.  We could use the actual bytes read to figure
@@ -38,7 +44,7 @@ static errcode_t e2fsck_handle_read_error(io_channel channel,
        if (count > 1) {
                p = (char *) data;
                for (i=0; i < count; i++, p += channel->block_size, block++) {
-                       error = io_channel_read_blk(channel, block,
+                       error = io_channel_read_blk64(channel, block,
                                                    1, p);
                        if (error)
                                return error;
@@ -46,15 +52,23 @@ static errcode_t e2fsck_handle_read_error(io_channel channel,
                return 0;
        }
        if (operation)
-               printf("Error reading block %lu (%s) while %s.  ", block,
+               printf(_("Error reading block %lu (%s) while %s.  "), block,
                       error_message(error), operation);
        else
-               printf("Error reading block %lu (%s).  ", block,
+               printf(_("Error reading block %lu (%s).  "), block,
                       error_message(error));
-       preenhalt(NULL);
-       if (ask("Ignore error", 1))
+       preenhalt(ctx);
+
+       /* Don't rewrite a block past the end of the FS. */
+       if (block >= ext2fs_blocks_count(fs->super))
                return 0;
 
+       if (ask(ctx, _("Ignore error"), 1)) {
+               if (ask(ctx, _("Force rewrite"), 1))
+                       io_channel_write_blk64(channel, block, count, data);
+               return 0;
+       }
+
        return error;
 }
 
@@ -62,13 +76,19 @@ static errcode_t e2fsck_handle_write_error(io_channel channel,
                                            unsigned long block,
                                            int count,
                                            const void *data,
-                                           size_t size,
-                                           int actual,
+                                           size_t size EXT2FS_ATTR((unused)),
+                                           int actual EXT2FS_ATTR((unused)),
                                            errcode_t error)
 {
        int             i;
        const char      *p;
-       
+       ext2_filsys fs = (ext2_filsys) channel->app_data;
+       e2fsck_t ctx;
+
+       ctx = (e2fsck_t) fs->priv_data;
+       if (ctx->flags & E2F_FLAG_EXITING)
+               return 0;
+
        /*
         * If more than one block was written, try writing each block
         * separately.  We could use the actual bytes read to figure
@@ -77,22 +97,22 @@ static errcode_t e2fsck_handle_write_error(io_channel channel,
        if (count > 1) {
                p = (const char *) data;
                for (i=0; i < count; i++, p += channel->block_size, block++) {
-                       error = io_channel_write_blk(channel, block,
+                       error = io_channel_write_blk64(channel, block,
                                                     1, p);
                        if (error)
                                return error;
                }
                return 0;
        }
-       
+
        if (operation)
-               printf("Error writing block %lu (%s) while %s.  ", block,
+               printf(_("Error writing block %lu (%s) while %s.  "), block,
                       error_message(error), operation);
        else
-               printf("Error writing block %lu (%s).  ", block,
+               printf(_("Error writing block %lu (%s).  "), block,
                       error_message(error));
-       preenhalt(NULL);
-       if (ask("Ignore error", 1))
+       preenhalt(ctx);
+       if (ask(ctx, _("Ignore error"), 1))
                return 0;
 
        return error;