#include "e2fsck.h"
-e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
+extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
#include <sys/time.h>
#include <sys/resource.h>
return ret;
}
+char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)),
+ const char *str, int len)
+{
+ char *ret;
+
+ if (!str)
+ return NULL;
+ if (!len)
+ len = strlen(str);
+ ret = malloc(len+1);
+ if (ret) {
+ strncpy(ret, str, len);
+ ret[len] = 0;
+ }
+ return ret;
+}
+
+#ifndef HAVE_STRNLEN
+/*
+ * Incredibly, libc5 doesn't appear to have strnlen. So we have to
+ * provide our own.
+ */
+int e2fsck_strnlen(const char * s, int count)
+{
+ const char *cp = s;
+
+ while (count-- && *cp)
+ cp++;
+ return cp - s;
+}
+#endif
+
#ifndef HAVE_CONIO_H
-int read_a_char(void)
+static int read_a_char(void)
{
char c;
int r;
{
ext2_filsys fs = ctx->fs;
errcode_t retval;
+ const char *old_op;
if (ctx->invalid_bitmaps) {
com_err(ctx->program_name, 0,
fatal_error(ctx, 0);
}
- ehandler_operation(_("reading inode and block bitmaps"));
+ old_op = ehandler_operation(_("reading inode and block bitmaps"));
retval = ext2fs_read_bitmaps(fs);
- ehandler_operation(0);
+ ehandler_operation(old_op);
if (retval) {
com_err(ctx->program_name, retval,
_("while retrying to read bitmaps for %s"),
{
ext2_filsys fs = ctx->fs;
errcode_t retval;
+ const char *old_op;
if (ext2fs_test_bb_dirty(fs)) {
- ehandler_operation(_("writing block bitmaps"));
+ old_op = ehandler_operation(_("writing block bitmaps"));
retval = ext2fs_write_block_bitmap(fs);
- ehandler_operation(0);
+ ehandler_operation(old_op);
if (retval) {
com_err(ctx->program_name, retval,
_("while retrying to write block bitmaps for %s"),
}
if (ext2fs_test_ib_dirty(fs)) {
- ehandler_operation(_("writing inode bitmaps"));
+ old_op = ehandler_operation(_("writing inode bitmaps"));
retval = ext2fs_write_inode_bitmap(fs);
- ehandler_operation(0);
+ ehandler_operation(old_op);
if (retval) {
com_err(ctx->program_name, retval,
_("while retrying to write inode bitmaps for %s"),
}
}
+extern void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
+ struct ext2_inode * inode, int bufsize,
+ const char *proc)
+{
+ int retval;
+
+ retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize);
+ if (retval) {
+ com_err("ext2fs_write_inode", retval,
+ _("while writing inode %ld in %s"), ino, proc);
+ fatal_error(ctx, 0);
+ }
+}
+
extern void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
struct ext2_inode * inode, const char *proc)
{
ext2fs_swap_super(sb);
#endif
if (sb->s_magic == EXT2_SUPER_MAGIC) {
- ret_sb = ctx->superblock = superblock;
- ctx->blocksize = blocksize;
+ ret_sb = superblock;
+ if (ctx) {
+ ctx->superblock = superblock;
+ ctx->blocksize = blocksize;
+ }
break;
}
}