2 * ehandler.c --- handle bad block errors which come up during the
3 * course of an e2fsck session.
5 * Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
6 * under the terms of the GNU Public License.
18 #include <sys/resource.h>
20 static const char *operation;
22 static errcode_t e2fsck_handle_read_error(io_channel channel,
32 ext2_filsys fs = (ext2_filsys) channel->app_data;
35 ctx = (e2fsck_t) fs->priv_data;
38 * If more than one block was read, try reading each block
39 * separately. We could use the actual bytes read to figure
40 * out where to start, but we don't bother.
44 for (i=0; i < count; i++, p += channel->block_size, block++) {
45 error = io_channel_read_blk(channel, block,
53 printf(_("Error reading block %lu (%s) while %s. "), block,
54 error_message(error), operation);
56 printf(_("Error reading block %lu (%s). "), block,
57 error_message(error));
59 if (ask(ctx, _("Ignore error"), 1)) {
60 if (ask(ctx, _("Force rewrite"), 1))
61 io_channel_write_blk(channel, block, 1, data);
68 static errcode_t e2fsck_handle_write_error(io_channel channel,
78 ext2_filsys fs = (ext2_filsys) channel->app_data;
81 ctx = (e2fsck_t) fs->priv_data;
84 * If more than one block was written, try writing each block
85 * separately. We could use the actual bytes read to figure
86 * out where to start, but we don't bother.
89 p = (const char *) data;
90 for (i=0; i < count; i++, p += channel->block_size, block++) {
91 error = io_channel_write_blk(channel, block,
100 printf(_("Error writing block %lu (%s) while %s. "), block,
101 error_message(error), operation);
103 printf(_("Error writing block %lu (%s). "), block,
104 error_message(error));
106 if (ask(ctx, _("Ignore error"), 1))
112 const char *ehandler_operation(const char *op)
114 const char *ret = operation;
120 void ehandler_init(io_channel channel)
122 channel->read_error = e2fsck_handle_read_error;
123 channel->write_error = e2fsck_handle_write_error;