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
,
26 size_t size
EXT2FS_ATTR((unused
)),
27 int actual
EXT2FS_ATTR((unused
)),
32 ext2_filsys fs
= (ext2_filsys
) channel
->app_data
;
35 ctx
= (e2fsck_t
) fs
->priv_data
;
36 if (ctx
->flags
& E2F_FLAG_EXITING
)
39 * If more than one block was read, try reading each block
40 * separately. We could use the actual bytes read to figure
41 * out where to start, but we don't bother.
45 for (i
=0; i
< count
; i
++, p
+= channel
->block_size
, block
++) {
46 error
= io_channel_read_blk64(channel
, block
,
54 printf(_("Error reading block %lu (%s) while %s. "), block
,
55 error_message(error
), operation
);
57 printf(_("Error reading block %lu (%s). "), block
,
58 error_message(error
));
60 if (ask(ctx
, _("Ignore error"), 1)) {
61 if (ask(ctx
, _("Force rewrite"), 1))
62 io_channel_write_blk64(channel
, block
, 1, data
);
69 static errcode_t
e2fsck_handle_write_error(io_channel channel
,
73 size_t size
EXT2FS_ATTR((unused
)),
74 int actual
EXT2FS_ATTR((unused
)),
79 ext2_filsys fs
= (ext2_filsys
) channel
->app_data
;
82 ctx
= (e2fsck_t
) fs
->priv_data
;
83 if (ctx
->flags
& E2F_FLAG_EXITING
)
87 * If more than one block was written, try writing each block
88 * separately. We could use the actual bytes read to figure
89 * out where to start, but we don't bother.
92 p
= (const char *) data
;
93 for (i
=0; i
< count
; i
++, p
+= channel
->block_size
, block
++) {
94 error
= io_channel_write_blk64(channel
, block
,
103 printf(_("Error writing block %lu (%s) while %s. "), block
,
104 error_message(error
), operation
);
106 printf(_("Error writing block %lu (%s). "), block
,
107 error_message(error
));
109 if (ask(ctx
, _("Ignore error"), 1))
115 const char *ehandler_operation(const char *op
)
117 const char *ret
= operation
;
123 void ehandler_init(io_channel channel
)
125 channel
->read_error
= e2fsck_handle_read_error
;
126 channel
->write_error
= e2fsck_handle_write_error
;