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.
19 #include <sys/resource.h>
21 static const char *operation;
23 static errcode_t e2fsck_handle_read_error(io_channel channel,
27 size_t size EXT2FS_ATTR((unused)),
28 int actual EXT2FS_ATTR((unused)),
33 ext2_filsys fs = (ext2_filsys) channel->app_data;
36 ctx = (e2fsck_t) fs->priv_data;
37 if (ctx->flags & E2F_FLAG_EXITING)
40 * If more than one block was read, try reading each block
41 * separately. We could use the actual bytes read to figure
42 * out where to start, but we don't bother.
46 for (i=0; i < count; i++, p += channel->block_size, block++) {
47 error = io_channel_read_blk64(channel, block,
55 printf(_("Error reading block %lu (%s) while %s. "), block,
56 error_message(error), operation);
58 printf(_("Error reading block %lu (%s). "), block,
59 error_message(error));
61 if (ask(ctx, _("Ignore error"), 1)) {
62 if (ask(ctx, _("Force rewrite"), 1))
63 io_channel_write_blk64(channel, block, 1, data);
70 static errcode_t e2fsck_handle_write_error(io_channel channel,
74 size_t size EXT2FS_ATTR((unused)),
75 int actual EXT2FS_ATTR((unused)),
80 ext2_filsys fs = (ext2_filsys) channel->app_data;
83 ctx = (e2fsck_t) fs->priv_data;
84 if (ctx->flags & E2F_FLAG_EXITING)
88 * If more than one block was written, try writing each block
89 * separately. We could use the actual bytes read to figure
90 * out where to start, but we don't bother.
93 p = (const char *) data;
94 for (i=0; i < count; i++, p += channel->block_size, block++) {
95 error = io_channel_write_blk64(channel, block,
104 printf(_("Error writing block %lu (%s) while %s. "), block,
105 error_message(error), operation);
107 printf(_("Error writing block %lu (%s). "), block,
108 error_message(error));
110 if (ask(ctx, _("Ignore error"), 1))
116 const char *ehandler_operation(const char *op)
118 const char *ret = operation;
124 void ehandler_init(io_channel channel)
126 channel->read_error = e2fsck_handle_read_error;
127 channel->write_error = e2fsck_handle_write_error;