Whamcloud - gitweb
Fix gcc -Wall issues in e2fsck sources
[tools/e2fsprogs.git] / e2fsck / util.c
index ec60de0..2ff3c6f 100644 (file)
@@ -31,7 +31,7 @@
 
 #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>
@@ -70,8 +70,40 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
        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;
@@ -175,6 +207,7 @@ void e2fsck_read_bitmaps(e2fsck_t ctx)
 {
        ext2_filsys fs = ctx->fs;
        errcode_t       retval;
+       const char      *old_op;
 
        if (ctx->invalid_bitmaps) {
                com_err(ctx->program_name, 0,
@@ -183,9 +216,9 @@ void e2fsck_read_bitmaps(e2fsck_t ctx)
                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"),
@@ -198,11 +231,12 @@ void e2fsck_write_bitmaps(e2fsck_t ctx)
 {
        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"),
@@ -212,9 +246,9 @@ void e2fsck_write_bitmaps(e2fsck_t ctx)
        }
 
        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"),
@@ -329,6 +363,20 @@ void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
        }
 }
 
+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)
 {
@@ -408,8 +456,11 @@ blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
                        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;
                }
        }