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
));
62 /* Don't rewrite a block past the end of the FS. */
63 if (block
>= ext2fs_blocks_count(fs
->super
))
66 if (ask(ctx
, _("Ignore error"), 1)) {
67 if (ask(ctx
, _("Force rewrite"), 1))
68 io_channel_write_blk64(channel
, block
, count
, data
);
75 static errcode_t
e2fsck_handle_write_error(io_channel channel
,
79 size_t size
EXT2FS_ATTR((unused
)),
80 int actual
EXT2FS_ATTR((unused
)),
85 ext2_filsys fs
= (ext2_filsys
) channel
->app_data
;
88 ctx
= (e2fsck_t
) fs
->priv_data
;
89 if (ctx
->flags
& E2F_FLAG_EXITING
)
93 * If more than one block was written, try writing each block
94 * separately. We could use the actual bytes read to figure
95 * out where to start, but we don't bother.
98 p
= (const char *) data
;
99 for (i
=0; i
< count
; i
++, p
+= channel
->block_size
, block
++) {
100 error
= io_channel_write_blk64(channel
, block
,
109 printf(_("Error writing block %lu (%s) while %s. "), block
,
110 error_message(error
), operation
);
112 printf(_("Error writing block %lu (%s). "), block
,
113 error_message(error
));
115 if (ask(ctx
, _("Ignore error"), 1))
121 const char *ehandler_operation(const char *op
)
123 const char *ret
= operation
;
129 void ehandler_init(io_channel channel
)
131 channel
->read_error
= e2fsck_handle_read_error
;
132 channel
->write_error
= e2fsck_handle_write_error
;