*: remove some uses of argc
[oweals/busybox.git] / e2fsprogs / old_e2fsprogs / e2fsck.c
index a0f691606dc592cc0aa029e413607e7829725220..c715d3e9ae226d9cbc454575118496ec7e28b02d 100644 (file)
@@ -192,10 +192,10 @@ struct buffer_head {
 #define K_DEV_FS        1
 #define K_DEV_JOURNAL   2
 
-#define lock_buffer(bh) do {} while(0)
-#define unlock_buffer(bh) do {} while(0)
+#define lock_buffer(bh) do {} while (0)
+#define unlock_buffer(bh) do {} while (0)
 #define buffer_req(bh) 1
-#define do_readahead(journal, start) do {} while(0)
+#define do_readahead(journal, start) do {} while (0)
 
 static e2fsck_t e2fsck_global_ctx;  /* Try your very best not to use this! */
 
@@ -1886,7 +1886,7 @@ static void e2fsck_journal_reset_super(e2fsck_t ctx, journal_superblock_t *jsb,
        int i;
 
        /* Leave a valid existing V1 superblock signature alone.
-        * Anything unrecognisable we overwrite with a new V2
+        * Anything unrecognizable we overwrite with a new V2
         * signature. */
 
        if (jsb->s_header.h_magic != htonl(JFS_MAGIC_NUMBER) ||
@@ -2168,7 +2168,7 @@ static int e2fsck_run_ext3_journal(e2fsck_t ctx)
  * This function will move the journal inode from a visible file in
  * the filesystem directory hierarchy to the reserved inode if necessary.
  */
-static const char * const journal_names[] = {
+static const char *const journal_names[] = {
        ".journal", "journal", ".journal.dat", "journal.dat", 0 };
 
 static void e2fsck_move_ext3_journal(e2fsck_t ctx)
@@ -2179,7 +2179,7 @@ static void e2fsck_move_ext3_journal(e2fsck_t ctx)
        ext2_filsys             fs = ctx->fs;
        ext2_ino_t              ino;
        errcode_t               retval;
-       const char * const *    cpp;
+       const char *const *    cpp;
        int                     group, mount_flags;
 
        clear_problem_context(&pctx);
@@ -2270,7 +2270,7 @@ static void e2fsck_move_ext3_journal(e2fsck_t ctx)
        ext2fs_mark_super_dirty(fs);
        fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = time(NULL);
        if ((retval = ext2fs_write_inode(fs, ino, &inode)) != 0)
                goto err_out;
 
@@ -2372,7 +2372,7 @@ err_out:
  * abbreviation of the form '@<i>' is expanded by looking up the index
  * letter <i> in the table below.
  */
-static const char * const abbrevs[] = {
+static const char *const abbrevs[] = {
        N_("aextended attribute"),
        N_("Aerror allocating"),
        N_("bblock"),
@@ -2410,7 +2410,7 @@ static const char * const abbrevs[] = {
  * Give more user friendly names to the "special" inodes.
  */
 #define num_special_inodes      11
-static const char * const special_inode_name[] =
+static const char *const special_inode_name[] =
 {
        N_("<The NULL inode>"),                 /* 0 */
        N_("<The bad blocks inode>"),           /* 1 */
@@ -2443,10 +2443,10 @@ static void safe_print(const char *cp, int len)
                        ch -= 128;
                }
                if ((ch < 32) || (ch == 0x7f)) {
-                       fputc('^', stdout);
+                       bb_putchar('^');
                        ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
                }
-               fputc(ch, stdout);
+               bb_putchar(ch);
        }
 }
 
@@ -2485,7 +2485,7 @@ static void expand_at_expression(e2fsck_t ctx, char ch,
                                          struct problem_context *pctx,
                                          int *first)
 {
-       const char * const *cpp;
+       const char *const *cpp;
        const char *str;
 
        /* Search for the abbreviation */
@@ -2497,7 +2497,7 @@ static void expand_at_expression(e2fsck_t ctx, char ch,
                str = _(*cpp) + 1;
                if (*first && islower(*str)) {
                        *first = 0;
-                       fputc(toupper(*str++), stdout);
+                       bb_putchar(toupper(*str++));
                }
                print_e2fsck_message(ctx, str, pctx, *first);
        } else
@@ -2630,7 +2630,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
 
        switch (ch) {
        case '%':
-               fputc('%', stdout);
+               bb_putchar('%');
                break;
        case 'b':
                printf("%u", ctx->blk);
@@ -2654,7 +2654,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%u", ctx->ino2);
                break;
        case 'm':
-               printf("%s", error_message(ctx->errcode));
+               fputs(error_message(ctx->errcode), stdout);
                break;
        case 'N':
                printf("%"PRIi64, ctx->num);
@@ -2676,7 +2676,7 @@ static void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%d", get_backup_sb(NULL, fs, NULL, NULL));
                break;
        case 's':
-               printf("%s", ctx->str ? ctx->str : "NULL");
+               fputs((ctx->str ? ctx->str : "NULL"), stdout);
                break;
        case 'X':
                printf("0x%"PRIi64, ctx->num);
@@ -3381,7 +3381,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
                         */
                        if (!LINUX_S_ISDIR(inode->i_mode)) {
                                if (fix_problem(ctx, PR_1_ROOT_NO_DIR, &pctx)) {
-                                       inode->i_dtime = time(0);
+                                       inode->i_dtime = time(NULL);
                                        inode->i_links_count = 0;
                                        ext2fs_icount_store(ctx->inode_link_info,
                                                            ino, 0);
@@ -3475,7 +3475,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
                    inode->i_dtime < ctx->fs->super->s_inodes_count) {
                        if (fix_problem(ctx, PR_1_LOW_DTIME, &pctx)) {
                                inode->i_dtime = inode->i_links_count ?
-                                       0 : time(0);
+                                       0 : time(NULL);
                                e2fsck_write_inode(ctx, ino, inode,
                                                   "pass1");
                        }
@@ -3489,7 +3489,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
                        if (!inode->i_dtime && inode->i_mode) {
                                if (fix_problem(ctx,
                                            PR_1_ZERO_DTIME, &pctx)) {
-                                       inode->i_dtime = time(0);
+                                       inode->i_dtime = time(NULL);
                                        e2fsck_write_inode(ctx, ino, inode,
                                                           "pass1");
                                }
@@ -3659,7 +3659,7 @@ static void e2fsck_pass1(e2fsck_t ctx)
                }
                e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
                                  "recreate inode");
-               inode->i_mtime = time(0);
+               inode->i_mtime = time(NULL);
                e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
                                  "recreate inode");
                fs->block_map = save_bmap;
@@ -4169,7 +4169,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
        if (pb.clear) {
                inode->i_links_count = 0;
                ext2fs_icount_store(ctx->inode_link_info, ino, 0);
-               inode->i_dtime = time(0);
+               inode->i_dtime = time(NULL);
                dirty_inode++;
                ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
                ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
@@ -4202,7 +4202,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
                if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
                        inode->i_links_count = 0;
                        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
-                       inode->i_dtime = time(0);
+                       inode->i_dtime = time(NULL);
                        dirty_inode++;
                        ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino);
                        ext2fs_unmark_inode_bitmap(ctx->inode_reg_map, ino);
@@ -4701,7 +4701,7 @@ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk,
        else {
                di = (struct dup_inode *) e2fsck_allocate_memory(ctx,
                         sizeof(struct dup_inode), "duplicate inode header");
-               di->dir = (ino == EXT2_ROOT_INO) ? EXT2_ROOT_INO : 0 ;
+               di->dir = (ino == EXT2_ROOT_INO) ? EXT2_ROOT_INO : 0;
                di->num_dupblocks = 0;
                di->block_list = 0;
                di->inode = *inode;
@@ -5147,7 +5147,7 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
        /* Inode may have changed by block_iterate, so reread it */
        e2fsck_read_inode(ctx, ino, &inode, "delete_file");
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = time(NULL);
        if (inode.i_file_acl &&
            (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
                count = 1;
@@ -6393,7 +6393,7 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
        e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
        inode.i_links_count = 0;
-       inode.i_dtime = time(0);
+       inode.i_dtime = time(NULL);
        e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode");
        clear_problem_context(&pctx);
        pctx.ino = ino;
@@ -6890,7 +6890,7 @@ static void check_root(e2fsck_t ctx)
        memset(&inode, 0, sizeof(inode));
        inode.i_mode = 040755;
        inode.i_size = fs->blocksize;
-       inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+       inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL);
        inode.i_links_count = 2;
        inode.i_blocks = fs->blocksize / 512;
        inode.i_block[0] = blk;
@@ -7138,7 +7138,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        memset(&inode, 0, sizeof(inode));
        inode.i_mode = 040700;
        inode.i_size = fs->blocksize;
-       inode.i_atime = inode.i_ctime = inode.i_mtime = time(0);
+       inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL);
        inode.i_links_count = 2;
        inode.i_blocks = fs->blocksize / 512;
        inode.i_block[0] = blk;
@@ -7492,7 +7492,7 @@ static int disconnect_inode(e2fsck_t ctx, ext2_ino_t i)
                if (fix_problem(ctx, PR_4_ZERO_LEN_INODE, &pctx)) {
                        ext2fs_icount_store(ctx->inode_link_info, i, 0);
                        inode.i_links_count = 0;
-                       inode.i_dtime = time(0);
+                       inode.i_dtime = time(NULL);
                        e2fsck_write_inode(ctx, i, &inode,
                                           "disconnect_inode");
                        /*
@@ -8178,7 +8178,7 @@ struct latch_descr {
  * These are the prompts which are used to ask the user if they want
  * to fix a problem.
  */
-static const char * const prompt[] = {
+static const char *const prompt[] = {
        N_("(no prompt)"),      /* 0 */
        N_("Fix"),              /* 1 */
        N_("Clear"),            /* 2 */
@@ -8206,7 +8206,7 @@ static const char * const prompt[] = {
  * These messages are printed when we are preen mode and we will be
  * automatically fixing the problem.
  */
-static const char * const preen_msg[] = {
+static const char *const preen_msg[] = {
        N_("(NONE)"),           /* 0 */
        N_("FIXED"),            /* 1 */
        N_("CLEARED"),          /* 2 */
@@ -9400,7 +9400,7 @@ static const struct e2fsck_problem problem_table[] = {
 
        /* Cannot proceed without a root inode. */
        { PR_3_NO_ROOT_INODE_ABORT,
-         N_("Cannot proceed without a @r.\n"),
+         N_("can't proceed without a @r.\n"),
          PROMPT_NONE, PR_FATAL },
 
        /* Internal error: couldn't find dir_info */
@@ -10014,7 +10014,7 @@ static int do_one_pass(journal_t *journal,
                 * all of the sequence number checks.  What are we going
                 * to do with it?  That depends on the pass... */
 
-               switch(blocktype) {
+               switch (blocktype) {
                case JFS_DESCRIPTOR_BLOCK:
                        /* If it is a valid descriptor block, replay it
                         * in pass REPLAY; otherwise, just skip over the
@@ -11158,7 +11158,7 @@ int journal_init_revoke(journal_t *journal, int hash_size)
 
        shift = 0;
        tmp = hash_size;
-       while((tmp >>= 1UL) != 0UL)
+       while ((tmp >>= 1UL) != 0UL)
                shift++;
        journal->j_revoke->hash_shift = shift;
 
@@ -11558,7 +11558,7 @@ static int release_orphan_inodes(e2fsck_t ctx)
                if (!inode.i_links_count) {
                        ext2fs_inode_alloc_stats2(fs, ino, -1,
                                                  LINUX_S_ISDIR(inode.i_mode));
-                       inode.i_dtime = time(0);
+                       inode.i_dtime = time(NULL);
                } else {
                        inode.i_dtime = 0;
                }
@@ -12251,7 +12251,7 @@ static int read_a_char(void)
        int     r;
        int     fail = 0;
 
-       while(1) {
+       while (1) {
                if (e2fsck_global_ctx &&
                    (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) {
                        return 3;
@@ -12281,7 +12281,7 @@ static int ask_yn(const char * string, int def)
        tmp.c_lflag &= ~(ICANON | ECHO);
        tmp.c_cc[VMIN] = 1;
        tmp.c_cc[VTIME] = 0;
-       tcsetattr (0, TCSANOW, &tmp);
+       tcsetattr_stdin_TCSANOW(&tmp);
 #endif
 
        if (def == 1)
@@ -12297,7 +12297,7 @@ static int ask_yn(const char * string, int def)
                        break;
                if (c == 3) {
 #ifdef HAVE_TERMIOS_H
-                       tcsetattr (0, TCSANOW, &termios);
+                       tcsetattr_stdin_TCSANOW(&termios);
 #endif
                        if (e2fsck_global_ctx &&
                            e2fsck_global_ctx->flags & E2F_FLAG_SETJMP_OK) {
@@ -12323,7 +12323,7 @@ static int ask_yn(const char * string, int def)
        else
                puts ("no\n");
 #ifdef HAVE_TERMIOS_H
-       tcsetattr (0, TCSANOW, &termios);
+       tcsetattr_stdin_TCSANOW(&termios);
 #endif
        return def;
 }
@@ -12490,7 +12490,7 @@ blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
        sb = (struct ext2_super_block *) buf;
 
        for (blocksize = EXT2_MIN_BLOCK_SIZE;
-            blocksize <= EXT2_MAX_BLOCK_SIZE ; blocksize *= 2) {
+            blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
                superblock = blocksize*8;
                if (blocksize == 1024)
                        superblock++;
@@ -12632,7 +12632,7 @@ static void check_mount(e2fsck_t ctx)
        retval = ext2fs_check_if_mounted(ctx->filesystem_name,
                                         &ctx->mount_flags);
        if (retval) {
-               bb_error_msg(_("while determining whether %s is mounted."),
+               bb_error_msg(_("while determining whether %s is mounted"),
                        ctx->filesystem_name);
                return;
        }
@@ -12653,14 +12653,14 @@ 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."));
+               bb_error_msg_and_die(_("can't 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"));
-               exit (0);
+               exit(0);
        }
 }
 
@@ -12672,7 +12672,7 @@ static int is_on_batt(void)
        unsigned int    acflag;
        struct dirent*  de;
 
-       f = fopen("/proc/apm", "r");
+       f = fopen_for_read("/proc/apm");
        if (f) {
                if (fscanf(f, "%s %s %s %x", tmp, tmp, tmp, &acflag) != 4)
                        acflag = 1;
@@ -12686,7 +12686,7 @@ static int is_on_batt(void)
                                continue;
                        snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state",
                                 de->d_name);
-                       f = fopen(fname, "r");
+                       f = fopen_for_read(fname);
                        if (!f)
                                continue;
                        if (fscanf(f, "%s %s", tmp2, tmp) != 2)
@@ -12714,7 +12714,7 @@ static void check_if_skip(e2fsck_t ctx)
        unsigned int reason_arg = 0;
        long next_check;
        int batt = is_on_batt();
-       time_t now = time(0);
+       time_t now = time(NULL);
 
        if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs)
                return;
@@ -12767,7 +12767,7 @@ static void check_if_skip(e2fsck_t ctx)
                else
                        printf(_(" (check in %ld mounts)"), next_check);
        }
-       fputc('\n', stdout);
+       bb_putchar('\n');
        ext2fs_close(fs);
        ctx->fs = NULL;
        e2fsck_free_context(ctx);
@@ -12864,9 +12864,9 @@ int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent,
               bar + (sizeof(bar) - (i+1)),
               spaces + (sizeof(spaces) - (dpywidth - i + 1)));
        if (fixed_percent == 1000)
-               fputc('|', stdout);
+               bb_putchar('|');
        else
-               fputc(spinner[ctx->progress_pos & 3], stdout);
+               bb_putchar(spinner[ctx->progress_pos & 3]);
        printf(" %4.1f%%  ", percent);
        if (dpynum)
                printf("%u\r", dpynum);
@@ -12892,7 +12892,7 @@ static int e2fsck_update_progress(e2fsck_t ctx, int pass,
 
        if (ctx->progress_fd) {
                sprintf(buf, "%d %lu %lu\n", pass, cur, max);
-               write(ctx->progress_fd, buf, strlen(buf));
+               xwrite_str(ctx->progress_fd, buf);
        } else {
                percent = calc_percent(&e2fsck_tbl, pass, cur, max);
                e2fsck_simple_progress(ctx, ctx->device_name,
@@ -13001,7 +13001,7 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
 }
 
 
-static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
+static errcode_t PRS(int argc, char **argv, e2fsck_t *ret_ctx)
 {
        int             flush = 0;
        int             c, fd;
@@ -13060,7 +13060,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                case 'a':
                        if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
                        conflict_opt:
-                               bb_error_msg_and_die(_("Only one the options -p/-a, -n or -y may be specified."));
+                               bb_error_msg_and_die(_("only one the options -p/-a, -n or -y may be specified"));
                        }
                        ctx->options |= E2F_OPT_PREEN;
                        break;
@@ -13202,8 +13202,8 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 static const char my_ver_string[] = E2FSPROGS_VERSION;
 static const char my_ver_date[] = E2FSPROGS_DATE;
 
-int e2fsck_main (int argc, char *argv[]);
-int e2fsck_main (int argc, char *argv[])
+int e2fsck_main (int argc, char **argv);
+int e2fsck_main (int argc, char **argv)
 {
        errcode_t       retval;
        int             exit_value = EXIT_OK;
@@ -13373,7 +13373,7 @@ restart:
                                 * happen, unless the hardware or
                                 * device driver is being bogus.
                                 */
-                               bb_error_msg(_("cannot set superblock flags on %s"), ctx->device_name);
+                               bb_error_msg(_("can't set superblock flags on %s"), ctx->device_name);
                                bb_error_msg_and_die(0);
                        }
                        retval = e2fsck_run_ext3_journal(ctx);
@@ -13405,7 +13405,7 @@ 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."));
+               bb_error_msg(_("warning: compression support is experimental"));
 #endif
 #ifndef ENABLE_HTREE
        if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {