Whamcloud - gitweb
configure.in:
[tools/e2fsprogs.git] / e2fsck / util.c
index fdba677..9fd0114 100644 (file)
@@ -22,9 +22,8 @@
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #endif
-#else /* !HAVE_CONIO_H */
 #include <stdio.h>
-#define read_a_char    getchar()
+#define read_a_char()  getchar()
 #endif
 
 #ifdef HAVE_MALLOC_H
@@ -68,6 +67,8 @@ int ask_yn(const char * string, int def)
 {
        int             c;
        const char      *defstr;
+       char            *short_yes = _("yY");
+       char            *short_no = _("nN");
 
 #ifdef HAVE_TERMIOS_H
        struct termios  termios, tmp;
@@ -81,22 +82,21 @@ int ask_yn(const char * string, int def)
 #endif
 
        if (def == 1)
-               defstr = "<y>";
+               defstr = _("<y>");
        else if (def == 0)
-               defstr = "<n>";
+               defstr = _("<n>");
        else
-               defstr = " (y/n)";
+               defstr = _(" (y/n)");
        printf("%s%s? ", string, defstr);
        while (1) {
                fflush (stdout);
                if ((c = read_a_char()) == EOF)
                        break;
-               c = toupper(c);
-               if (c == 'Y') {
+               if (strchr(short_yes, (char) c)) {
                        def = 1;
                        break;
                }
-               else if (c == 'N') {
+               else if (strchr(short_no, (char) c)) {
                        def = 0;
                        break;
                }
@@ -116,15 +116,15 @@ 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);
@@ -137,17 +137,17 @@ void e2fsck_read_bitmaps(e2fsck_t ctx)
 
        if (ctx->invalid_bitmaps) {
                com_err(ctx->program_name, 0,
-                       "e2fsck_read_bitmaps: illegal bitmap block(s) for %s",
+                   _("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
                        ctx->device_name);
                fatal_error(ctx, 0);
        }
 
-       ehandler_operation("reading inode and block bitmaps");
+       ehandler_operation(_("reading inode and block bitmaps"));
        retval = ext2fs_read_bitmaps(fs);
        ehandler_operation(0);
        if (retval) {
                com_err(ctx->program_name, retval,
-                       "while retrying to read bitmaps for %s",
+                       _("while retrying to read bitmaps for %s"),
                        ctx->device_name);
                fatal_error(ctx, 0);
        }
@@ -159,24 +159,24 @@ void e2fsck_write_bitmaps(e2fsck_t ctx)
        errcode_t       retval;
 
        if (ext2fs_test_bb_dirty(fs)) {
-               ehandler_operation("writing block bitmaps");
+               ehandler_operation(_("writing block bitmaps"));
                retval = ext2fs_write_block_bitmap(fs);
                ehandler_operation(0);
                if (retval) {
                        com_err(ctx->program_name, retval,
-                               "while retrying to write block bitmaps for %s",
+                           _("while retrying to write block bitmaps for %s"),
                                ctx->device_name);
                        fatal_error(ctx, 0);
                }
        }
 
        if (ext2fs_test_ib_dirty(fs)) {
-               ehandler_operation("writing inode bitmaps");
+               ehandler_operation(_("writing inode bitmaps"));
                retval = ext2fs_write_inode_bitmap(fs);
                ehandler_operation(0);
                if (retval) {
                        com_err(ctx->program_name, retval,
-                               "while retrying to write inode bitmaps for %s",
+                           _("while retrying to write inode bitmaps for %s"),
                                ctx->device_name);
                        fatal_error(ctx, 0);
                }
@@ -189,8 +189,8 @@ void preenhalt(e2fsck_t ctx)
 
        if (!(ctx->options & E2F_OPT_PREEN))
                return;
-       fprintf(stderr, "\n\n%s: UNEXPECTED INCONSISTENCY; "
-               "RUN fsck MANUALLY.\n\t(i.e., without -a or -p options)\n",
+       fprintf(stderr, _("\n\n%s: UNEXPECTED INCONSISTENCY; "
+               "RUN fsck MANUALLY.\n\t(i.e., without -a or -p options)\n"),
               ctx->device_name);
        if (fs != NULL) {
                fs->super->s_state |= EXT2_ERROR_FS;
@@ -251,21 +251,25 @@ void print_resource_track(const char *desc, struct resource_track *track)
                printf("%s: ", desc);
 
 #ifdef HAVE_MALLINFO
+#define kbytes(x)      (((x) + 1023) / 1024)
+       
        malloc_info = mallinfo();
-       printf("Memory used: %d/%d, ", malloc_info.arena, malloc_info.hblkhd);
+       printf(_("Memory used: %dk/%dk (%dk/%dk), "),
+              kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
+              kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
 #else
-       printf("Memory used: %d, ",
+       printf(_("Memory used: %d, "),
               (int) (((char *) sbrk(0)) - ((char *) track->brk_start)));
 #endif 
 #ifdef HAVE_GETRUSAGE
        getrusage(RUSAGE_SELF, &r);
 
-       printf("elapsed time: %6.3f/%6.3f/%6.3f\n",
+       printf(_("time: %5.2f/%5.2f/%5.2f\n"),
               timeval_subtract(&time_end, &track->time_start),
               timeval_subtract(&r.ru_utime, &track->user_start),
               timeval_subtract(&r.ru_stime, &track->system_start));
 #else
-       printf("elapsed time: %6.3f\n",
+       printf(_("elapsed time: %6.3f\n"),
               timeval_subtract(&time_end, &track->time_start));
 #endif
 }
@@ -279,7 +283,7 @@ void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
        retval = ext2fs_read_inode(ctx->fs, ino, inode);
        if (retval) {
                com_err("ext2fs_read_inode", retval,
-                       "while reading inode %ld in %s", ino, proc);
+                       _("while reading inode %ld in %s"), ino, proc);
                fatal_error(ctx, 0);
        }
 }
@@ -292,7 +296,7 @@ extern void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
        retval = ext2fs_write_inode(ctx->fs, ino, inode);
        if (retval) {
                com_err("ext2fs_write_inode", retval,
-                       "while writing inode %ld in %s", ino, proc);
+                       _("while writing inode %ld in %s"), ino, proc);
                fatal_error(ctx, 0);
        }
 }
@@ -315,3 +319,31 @@ blk_t get_backup_sb(ext2_filsys fs)
        return fs->super->s_blocks_per_group + 1;
 }
 
+/*
+ * Given a mode, return the ext2 file type
+ */
+int ext2_file_type(unsigned int mode)
+{
+       if (LINUX_S_ISREG(mode))
+               return EXT2_FT_REG_FILE;
+
+       if (LINUX_S_ISDIR(mode))
+               return EXT2_FT_DIR;
+       
+       if (LINUX_S_ISCHR(mode))
+               return EXT2_FT_CHRDEV;
+       
+       if (LINUX_S_ISBLK(mode))
+               return EXT2_FT_BLKDEV;
+       
+       if (LINUX_S_ISLNK(mode))
+               return EXT2_FT_SYMLINK;
+
+       if (LINUX_S_ISFIFO(mode))
+               return EXT2_FT_FIFO;
+       
+       if (LINUX_S_ISSOCK(mode))
+               return EXT2_FT_SOCK;
+       
+       return 0;
+}