mostly style fixes
[oweals/busybox.git] / e2fsprogs / e2fsck.c
index eadb0f64dbd51bf45284a9753d0d33a1990382a9..88eedeaa6e5530b2b6a602b932ca8910dd9f9c19 100644 (file)
@@ -1,11 +1,9 @@
+/* vi: set sw=4 ts=4: */
 /*
  * e2fsck
  *
  * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
  * Copyright (C) 2006 Garrett Kajmowicz
- * This file may be
- * redistributed under the terms of the GNU Public License.
- *
  *
  * Dictionary Abstract Data Type
  * Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net>
  *
  * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
  *
- * This file is part of the Linux kernel and is made available under
- * the terms of the GNU General Public License, version 2, or at your
- * option, any later version, incorporated herein by reference.
- *
  * Journal recovery routines for the generic filesystem journaling code;
  * part of the ext2fs journaling system.
+ *
+ * Licensed under GPLv2 or later, see file License in this tarball for details.
  */
 
 #ifndef _GNU_SOURCE
@@ -39,6 +35,9 @@
 
 #include "e2fsck.h"    /*Put all of our defines here to clean things up*/
 
+#define _(x) x
+#define N_(x) x
+
 /*
  * Procedure declarations
  */
@@ -727,7 +726,7 @@ static void e2fsck_free_dir_info(e2fsck_t ctx)
 /*
  * Return the count of number of directories in the dir_info structure
  */
-static inline int e2fsck_get_num_dirinfo(e2fsck_t ctx)
+static int e2fsck_get_num_dirinfo(e2fsck_t ctx)
 {
        return ctx->dir_info_count;
 }
@@ -1364,7 +1363,7 @@ e2fsck_handle_write_error(io_channel channel, unsigned long block, int count,
        return error;
 }
 
-static inline const char *ehandler_operation(const char *op)
+static const char *ehandler_operation(const char *op)
 {
        const char *ret = operation;
 
@@ -1470,7 +1469,7 @@ static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
                                                     bh->b_blocknr,
                                                     1, bh->b_data);
                        if (retval) {
-                               bb_error_msg("while reading block %lu\n",
+                               bb_error_msg("while reading block %lu",
                                        (unsigned long) bh->b_blocknr);
                                bh->b_err = retval;
                                continue;
@@ -1481,7 +1480,7 @@ static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
                                                      bh->b_blocknr,
                                                      1, bh->b_data);
                        if (retval) {
-                               bb_error_msg("while writing block %lu\n",
+                               bb_error_msg("while writing block %lu",
                                        (unsigned long) bh->b_blocknr);
                                bh->b_err = retval;
                                continue;
@@ -1492,7 +1491,7 @@ static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
        }
 }
 
-static inline void mark_buffer_dirty(struct buffer_head *bh)
+static void mark_buffer_dirty(struct buffer_head *bh)
 {
        bh->b_dirty = 1;
 }
@@ -1509,7 +1508,7 @@ static void brelse(struct buffer_head *bh)
        ext2fs_free_mem(&bh);
 }
 
-static inline int buffer_uptodate(struct buffer_head *bh)
+static int buffer_uptodate(struct buffer_head *bh)
 {
        return bh->b_uptodate;
 }
@@ -1797,7 +1796,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
 
        ll_rw_block(READ, 1, &jbh);
        if (jbh->b_err) {
-               bb_error_msg(_("reading journal superblock\n"));
+               bb_error_msg(_("reading journal superblock"));
                return jbh->b_err;
        }
 
@@ -1853,7 +1852,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
         * format to be able to proceed safely, so any other checks that
         * fail we should attempt to recover from. */
        if (jsb->s_blocksize != htonl(journal->j_blocksize)) {
-               bb_error_msg(_("%s: no valid journal superblock found\n"),
+               bb_error_msg(_("%s: no valid journal superblock found"),
                        ctx->device_name);
                return EXT2_ET_CORRUPT_SUPERBLOCK;
        }
@@ -1861,7 +1860,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
        if (ntohl(jsb->s_maxlen) < journal->j_maxlen)
                journal->j_maxlen = ntohl(jsb->s_maxlen);
        else if (ntohl(jsb->s_maxlen) > journal->j_maxlen) {
-               bb_error_msg(_("%s: journal too short\n"),
+               bb_error_msg(_("%s: journal too short"),
                        ctx->device_name);
                return EXT2_ET_CORRUPT_SUPERBLOCK;
        }
@@ -2529,16 +2528,8 @@ static void expand_inode_expression(char ch,
                if (LINUX_S_ISDIR(inode->i_mode))
                        printf("%u", inode->i_size);
                else {
-#ifdef EXT2_NO_64_TYPE
-                       if (inode->i_size_high)
-                               printf("0x%x%08x", inode->i_size_high,
-                                      inode->i_size);
-                       else
-                               printf("%u", inode->i_size);
-#else
-                       printf("%llu", (inode->i_size |
-                                       ((__u64) inode->i_size_high << 32)));
-#endif
+                       printf("%"PRIu64, (inode->i_size |
+                                       ((uint64_t) inode->i_size_high << 32)));
                }
                break;
        case 'S':
@@ -2646,11 +2637,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%u", ctx->blk);
                break;
        case 'B':
-#ifdef EXT2_NO_64_TYPE
-               printf("%d", ctx->blkcount);
-#else
-               printf("%lld", ctx->blkcount);
-#endif
+               printf("%"PRIi64, ctx->blkcount);
                break;
        case 'c':
                printf("%u", ctx->blk2);
@@ -2671,11 +2658,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%s", error_message(ctx->errcode));
                break;
        case 'N':
-#ifdef EXT2_NO_64_TYPE
-               printf("%u", ctx->num);
-#else
-               printf("%llu", ctx->num);
-#endif
+               printf("%"PRIi64, ctx->num);
                break;
        case 'p':
                print_pathname(fs, ctx->ino, 0);
@@ -2697,11 +2680,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%s", ctx->str ? ctx->str : "NULL");
                break;
        case 'X':
-#ifdef EXT2_NO_64_TYPE
-               printf("0x%x", ctx->num);
-#else
-               printf("0x%llx", ctx->num);
-#endif
+               printf("0x%"PRIi64, ctx->num);
                break;
        default:
        no_context:
@@ -2891,7 +2870,7 @@ static void mark_inode_bad(e2fsck_t ctx, ino_t ino);
 static void handle_fs_bad_blocks(e2fsck_t ctx);
 static void process_inodes(e2fsck_t ctx, char *block_buf);
 static int process_inode_cmp(const void *a, const void *b);
-static errcode_t scan_callback(ext2_filsys fs, ext2_inode_scan scan,
+static errcode_t scan_callback(ext2_filsys fs,
                                  dgrp_t group, void * priv_data);
 static void adjust_extattr_refcount(e2fsck_t ctx, ext2_refcount_t refcount,
                                    char *block_buf, int adjust_sign);
@@ -3682,7 +3661,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
                e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
                                  "recreate inode");
                inode->i_mtime = time(0);
-               e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode, 
+               e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
                                  "recreate inode");
                fs->block_map = save_bmap;
                ctx->flags &= ~E2F_FLAG_RESIZE_INODE;
@@ -3721,7 +3700,6 @@ endit:
  * glock group, call process_inodes.
  */
 static errcode_t scan_callback(ext2_filsys fs,
-                              ext2_inode_scan scan FSCK_ATTR((unused)),
                               dgrp_t group, void * priv_data)
 {
        struct scan_callback_struct *scan_struct;
@@ -4434,7 +4412,7 @@ static int process_bad_block(ext2_filsys fs FSCK_ATTR((unused)),
         * inode, which is never compressed.  So we don't use HOLE_BLKADDR().
         */
 
-       printf("Unrecoverable Error: Found %lli bad blocks starting at block number: %u\n", blockcnt, *block_nr);
+       printf("Unrecoverable Error: Found %"PRIi64" bad blocks starting at block number: %u\n", blockcnt, *block_nr);
        return BLOCK_ERROR;
 }
 
@@ -5130,7 +5108,7 @@ static int delete_file_block(ext2_filsys fs,
                        p = (struct dup_block *) dnode_get(n);
                        decrement_badcount(ctx, *block_nr, p);
                } else
-                       bb_error_msg(_("internal error; can't find dup_blk for %d\n"),
+                       bb_error_msg(_("internal error; can't find dup_blk for %d"),
                                *block_nr);
        } else {
                ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr);
@@ -5263,7 +5241,7 @@ static int clone_file_block(ext2_filsys fs,
                        ext2fs_mark_block_bitmap(fs->block_map, new_block);
                        return BLOCK_CHANGED;
                } else
-                       bb_error_msg(_("internal error; can't find dup_blk for %d\n"),
+                       bb_error_msg(_("internal error; can't find dup_blk for %d"),
                                *block_nr);
        }
        return 0;
@@ -6743,7 +6721,7 @@ static int update_dir_block(ext2_filsys fs FSCK_ATTR((unused)),
  * Then, pass3 interates over all directory inodes; for each directory
  * it attempts to trace up the filesystem tree, using dirinfo.parent
  * until it reaches a directory which has been marked "done".  If it
- * can not do so, then the directory must be disconnected, and e2fsck
+ * cannot do so, then the directory must be disconnected, and e2fsck
  * will offer to reconnect it to /lost+found.  While it is chasing
  * parent pointers up the filesystem tree, if pass3 sees a directory
  * twice, then it has detected a filesystem loop, and it will again
@@ -8609,7 +8587,7 @@ static const struct e2fsck_problem problem_table[] = {
 
        /* Bad primary block */
        { PR_1_BAD_PRIMARY_BLOCK,
-         N_("\nIf the @b is really bad, the @f can not be fixed.\n"),
+         N_("\nIf the @b is really bad, the @f cannot be fixed.\n"),
          PROMPT_NONE, PR_AFTER_CODE, PR_1_BAD_PRIMARY_BLOCK_PROMPT },
 
        /* Bad primary block prompt */
@@ -8974,7 +8952,7 @@ static const struct e2fsck_problem problem_table[] = {
 
        /* File has duplicate blocks */
        { PR_1D_DUP_FILE,
-         N_("File %Q (@i #%i, mod time %IM) \n"
+         N_("File %Q (@i #%i, mod time %IM)\n"
          "  has %B @m @b(s), shared with %N file(s):\n"),
          PROMPT_NONE, 0 },
 
@@ -9154,7 +9132,7 @@ static const struct e2fsck_problem problem_table[] = {
 
        /* Internal error: couldn't find dir_info */
        { PR_2_NO_DIRINFO,
-         N_("Internal error: couldn't find dir_info for %i.\n"),
+         N_("Internal error: cannot find dir_info for %i.\n"),
          PROMPT_NONE, PR_FATAL },
 
        /* Final rec_len is wrong */
@@ -9430,7 +9408,7 @@ static const struct e2fsck_problem problem_table[] = {
 
        /* Internal error: couldn't find dir_info */
        { PR_3_NO_DIRINFO,
-         N_("Internal error: couldn't find dir_info for %i.\n"),
+         N_("Internal error: cannot find dir_info for %i.\n"),
          PROMPT_NONE, PR_FATAL },
 
        /* Lost+found not a directory */
@@ -9840,7 +9818,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
        err = journal_bmap(journal, offset, &blocknr);
 
        if (err) {
-               printf ("JBD: bad block at offset %u\n", offset);
+               printf("JBD: bad block at offset %u\n", offset);
                return err;
        }
 
@@ -9857,7 +9835,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
        }
 
        if (!buffer_uptodate(bh)) {
-               printf ("JBD: Failed to read block at offset %u\n", offset);
+               printf("JBD: Failed to read block at offset %u\n", offset);
                brelse(bh);
                return -EIO;
        }
@@ -10071,7 +10049,7 @@ static int do_one_pass(journal_t *journal,
                                        /* Recover what we can, but
                                         * report failure at the end. */
                                        success = err;
-                                       printf ("JBD: IO error %d recovering "
+                                       printf("JBD: IO error %d recovering "
                                                "block %ld in log\n",
                                                err, io_block);
                                } else {
@@ -10096,7 +10074,7 @@ static int do_one_pass(journal_t *journal,
                                                       blocknr,
                                                     journal->j_blocksize);
                                        if (nbh == NULL) {
-                                               printf ("JBD: Out of memory "
+                                               printf("JBD: Out of memory "
                                                       "during recovery.\n");
                                                err = -ENOMEM;
                                                brelse(bh);
@@ -10175,7 +10153,7 @@ static int do_one_pass(journal_t *journal,
                /* It's really bad news if different passes end up at
                 * different places (but possible due to IO errors). */
                if (info->end_transaction != next_commit_ID) {
-                       printf ("JBD: recovery pass %d ended at "
+                       printf("JBD: recovery pass %d ended at "
                                "transaction %u, expected %u\n",
                                pass, next_commit_ID, info->end_transaction);
                        if (!success)
@@ -11096,7 +11074,7 @@ struct jbd_revoke_table_s
 /* Utility functions to maintain the revoke table */
 
 /* Borrowed from buffer.c: this is a tried and tested block hash function */
-static inline int hash(journal_t *journal, unsigned long block)
+static int hash(journal_t *journal, unsigned long block)
 {
        struct jbd_revoke_table_s *table = journal->j_revoke;
        int hash_shift = table->hash_shift;
@@ -12357,15 +12335,15 @@ static int ask_yn(const char * string, int def)
 int ask (e2fsck_t ctx, const char * string, int def)
 {
        if (ctx->options & E2F_OPT_NO) {
-               printf (_("%s? no\n\n"), string);
+               printf(_("%s? no\n\n"), string);
                return 0;
        }
        if (ctx->options & E2F_OPT_YES) {
-               printf (_("%s? yes\n\n"), string);
+               printf(_("%s? yes\n\n"), string);
                return 1;
        }
        if (ctx->options & E2F_OPT_PREEN) {
-               printf ("%s? %s\n\n", string, def ? _("yes") : _("no"));
+               printf("%s? %s\n\n", string, def ? _("yes") : _("no"));
                return def;
        }
        return ask_yn(string, def);
@@ -12628,26 +12606,26 @@ static void show_stats(e2fsck_t ctx)
                       blocks_used, blocks);
                return;
        }
-       printf ("\n%8d inode%s used (%d%%)\n", P_E2("", "s", inodes_used),
+       printf("\n%8d inode%s used (%d%%)\n", P_E2("", "s", inodes_used),
                100 * inodes_used / inodes);
-       printf ("%8d non-contiguous inode%s (%0d.%d%%)\n",
+       printf("%8d non-contiguous inode%s (%0d.%d%%)\n",
                P_E2("", "s", ctx->fs_fragmented),
                frag_percent / 10, frag_percent % 10);
-       printf (_("         # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
+       printf(_("         # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
                ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
-       printf ("%8d block%s used (%d%%)\n", P_E2("", "s", blocks_used),
+       printf("%8d block%s used (%d%%)\n", P_E2("", "s", blocks_used),
                (int) ((long long) 100 * blocks_used / blocks));
-       printf ("%8d large file%s\n", P_E2("", "s", ctx->large_files));
-       printf ("\n%8d regular file%s\n", P_E2("", "s", ctx->fs_regular_count));
-       printf ("%8d director%s\n", P_E2("y", "ies", ctx->fs_directory_count));
-       printf ("%8d character device file%s\n", P_E2("", "s", ctx->fs_chardev_count));
-       printf ("%8d block device file%s\n", P_E2("", "s", ctx->fs_blockdev_count));
-       printf ("%8d fifo%s\n", P_E2("", "s", ctx->fs_fifo_count));
-       printf ("%8d link%s\n", P_E2("", "s", ctx->fs_links_count - dir_links));
-       printf ("%8d symbolic link%s", P_E2("", "s", ctx->fs_symlinks_count));
-       printf (" (%d fast symbolic link%s)\n", P_E2("", "s", ctx->fs_fast_symlinks_count));
-       printf ("%8d socket%s--------\n\n", P_E2("", "s", ctx->fs_sockets_count));
-       printf ("%8d file%s\n", P_E2("", "s", ctx->fs_total_count - dir_links));
+       printf("%8d large file%s\n", P_E2("", "s", ctx->large_files));
+       printf("\n%8d regular file%s\n", P_E2("", "s", ctx->fs_regular_count));
+       printf("%8d director%s\n", P_E2("y", "ies", ctx->fs_directory_count));
+       printf("%8d character device file%s\n", P_E2("", "s", ctx->fs_chardev_count));
+       printf("%8d block device file%s\n", P_E2("", "s", ctx->fs_blockdev_count));
+       printf("%8d fifo%s\n", P_E2("", "s", ctx->fs_fifo_count));
+       printf("%8d link%s\n", P_E2("", "s", ctx->fs_links_count - dir_links));
+       printf("%8d symbolic link%s", P_E2("", "s", ctx->fs_symlinks_count));
+       printf(" (%d fast symbolic link%s)\n", P_E2("", "s", ctx->fs_fast_symlinks_count));
+       printf("%8d socket%s--------\n\n", P_E2("", "s", ctx->fs_sockets_count));
+       printf("%8d file%s\n", P_E2("", "s", ctx->fs_total_count - dir_links));
 }
 
 static void check_mount(e2fsck_t ctx)
@@ -12679,13 +12657,13 @@ static void check_mount(e2fsck_t ctx)
 
        printf(_("%s is mounted.  "), ctx->filesystem_name);
        if (!ctx->interactive)
-               bb_error_msg_and_die(_("Cannot continue, aborting.\n\n"));
+               bb_error_msg_and_die(_("Cannot continue, aborting."));
        printf(_("\n\n\007\007\007\007WARNING!!!  "
               "Running e2fsck on a mounted filesystem may cause\n"
               "SEVERE filesystem damage.\007\007\007\n\n"));
        cont = ask_yn(_("Do you really want to continue"), -1);
        if (!cont) {
-               printf (_("check aborted.\n"));
+               printf(_("check aborted.\n"));
                exit (0);
        }
        return;
@@ -12937,7 +12915,7 @@ static void reserve_stdio_fds(void)
                if (fd > 2)
                        break;
                if (fd < 0) {
-                       fprintf(stderr, _("ERROR: Couldn't open "
+                       fprintf(stderr, _("ERROR: Cannot open "
                                "/dev/null (%s)\n"),
                                strerror(errno));
                        break;
@@ -13202,7 +13180,6 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                        fprintf(stderr, _("Incompatible options not "
                                          "allowed when byte-swapping.\n"));
                        exit(EXIT_USAGE);
-               }
        }
 #endif
        /*
@@ -13400,7 +13377,7 @@ restart:
                                 * happen, unless the hardware or
                                 * device driver is being bogus.
                                 */
-                               bb_error_msg(_("unable to set superblock flags on %s\n"), ctx->device_name);
+                               bb_error_msg(_("unable to set superblock flags on %s"), ctx->device_name);
                                bb_error_msg_and_die(0);
                        }
                        retval = e2fsck_run_ext3_journal(ctx);
@@ -13432,12 +13409,12 @@ restart:
 #ifdef ENABLE_COMPRESSION
        /* FIXME - do we support this at all? */
        if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
-               bb_error_msg(_("Warning: compression support is experimental.\n"));
+               bb_error_msg(_("Warning: compression support is experimental."));
 #endif
 #ifndef ENABLE_HTREE
        if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
                bb_error_msg(_("E2fsck not compiled with HTREE support,\n\t"
-                         "but filesystem %s has HTREE directories.\n"),
+                         "but filesystem %s has HTREE directories."),
                        ctx->device_name);
                goto get_newer;
        }