From 51a43b47fefaea46b00a74180a7d0b39022e6d11 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 24 Sep 2005 07:11:16 +0000 Subject: import the very fat e2fsck/fsck applets --- e2fsprogs/e2fsck/ehandler.c | 124 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 e2fsprogs/e2fsck/ehandler.c (limited to 'e2fsprogs/e2fsck/ehandler.c') diff --git a/e2fsprogs/e2fsck/ehandler.c b/e2fsprogs/e2fsck/ehandler.c new file mode 100644 index 000000000..16d6d4fa0 --- /dev/null +++ b/e2fsprogs/e2fsck/ehandler.c @@ -0,0 +1,124 @@ +/* + * 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 +#include +#include +#include +#include + +#include "e2fsck.h" + +#include +#include + +static const char *operation; + +static errcode_t e2fsck_handle_read_error(io_channel channel, + unsigned long block, + int count, + void *data, + 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 more than one block was read, try reading each block + * separately. We could use the actual bytes read to figure + * out where to start, but we don't bother. + */ + if (count > 1) { + p = (char *) data; + for (i=0; i < count; i++, p += channel->block_size, block++) { + error = io_channel_read_blk(channel, block, + 1, p); + if (error) + return error; + } + return 0; + } + if (operation) + printf(_("Error reading block %lu (%s) while %s. "), block, + error_message(error), operation); + else + printf(_("Error reading block %lu (%s). "), block, + error_message(error)); + preenhalt(ctx); + if (ask(ctx, _("Ignore error"), 1)) { + if (ask(ctx, _("Force rewrite"), 1)) + io_channel_write_blk(channel, block, 1, data); + return 0; + } + + return error; +} + +static errcode_t e2fsck_handle_write_error(io_channel channel, + unsigned long block, + int count, + const void *data, + 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 more than one block was written, try writing each block + * separately. We could use the actual bytes read to figure + * out where to start, but we don't bother. + */ + 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, + 1, p); + if (error) + return error; + } + return 0; + } + + if (operation) + printf(_("Error writing block %lu (%s) while %s. "), block, + error_message(error), operation); + else + printf(_("Error writing block %lu (%s). "), block, + error_message(error)); + preenhalt(ctx); + if (ask(ctx, _("Ignore error"), 1)) + return 0; + + return error; +} + +const char *ehandler_operation(const char *op) +{ + const char *ret = operation; + + operation = op; + return ret; +} + +void ehandler_init(io_channel channel) +{ + channel->read_error = e2fsck_handle_read_error; + channel->write_error = e2fsck_handle_write_error; +} -- cgit v1.2.3