X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=e2fsck%2Fmessage.c;h=ba38038cf39bb823e0ff0cf59ef6d6d4f761ce56;hb=25ad8a431331b4d1d444a70b6079456cc612ac40;hp=82cb423e377e3720ab670c88bdce7c01518f8636;hpb=b6f7983197fe217cf20862c93d72620be3b0fcec;p=tools%2Fe2fsprogs.git diff --git a/e2fsck/message.c b/e2fsck/message.c index 82cb423..ba38038 100644 --- a/e2fsck/message.c +++ b/e2fsck/message.c @@ -14,23 +14,28 @@ * The following % expansions are supported: * * %b block number - * %B integer + * %B interpret blkcount as blkcount * %c block number - * %di ->ino inode number - * %dn ->name string - * %dr ->rec_len - * %dl ->name_len - * %D inode number + * %Di ->ino inode number + * %Dn ->name string + * %Dr ->rec_len + * %Dl ->name_len + * %Dt ->filetype + * %d inode number * %g integer * %i inode number * %Is -> i_size + * %IS -> i_extra_isize * %Ib -> i_blocks * %Il -> i_links_count * %Im -> i_mode * %IM -> i_mtime * %IF -> i_faddr * %If -> i_file_acl - * %Id -> i_dir_acl + * %Id -> i_size_high + * %Iu -> i_uid + * %Ig -> i_gid + * %It * %j inode number * %m * %N @@ -41,17 +46,22 @@ * %q ext2fs_get_pathname of directory * %Q ext2fs_get_pathname of directory with as * the containing directory. + * %r interpret blkcount as refcount * %s miscellaneous string + * %t time (in ) + * %T current time + * %U quota type (in ) * %S backup superblock + * %X hexadecimal format * * The following '@' expansions are supported: * + * @a extended attribute * @A error allocating * @b block * @B bitmap + * @c compress * @C conflicts with some other fs block - * @i inode - * @I illegal * @D deleted * @d directory * @e entry @@ -59,23 +69,35 @@ * @f filesystem * @F for @i %i (%Q) is * @g group + * @h HTREE directory inode + * @i inode + * @I illegal + * @j journal * @l lost+found * @L is a link - * @u unattached + * @m multiply-claimed + * @n invalid + * @o orphaned + * @p problem in + * @q quota * @r root inode - * @s should be + * @s should be * @S superblock + * @u unattached + * @v device + * @x extent * @z zero-length */ +#include "config.h" #include #include #include #include #include +#include "support/quotaio.h" #include "e2fsck.h" - #include "problem.h" #ifdef __GNUC__ @@ -91,26 +113,37 @@ * letter in the table below. */ static const char *abbrevs[] = { - "Aerror allocating", - "bblock", - "Bbitmap", - "Cconflicts with some other fs @b", - "iinode", - "Iillegal", - "Ddeleted", - "ddirectory", - "eentry", - "E@e '%Dn' in %p (%i)", - "ffilesystem", - "Ffor @i %i (%Q) is", - "ggroup", - "llost+found", - "Lis a link", - "uunattached", - "rroot @i", - "sshould be", - "Ssuper@b", - "zzero-length", + N_("aextended attribute"), + N_("Aerror allocating"), + N_("bblock"), + N_("Bbitmap"), + N_("ccompress"), + N_("Cconflicts with some other fs @b"), + N_("ddirectory"), + N_("Ddeleted"), + N_("eentry"), + N_("E@e '%Dn' in %p (%i)"), + N_("ffilesystem"), + N_("Ffor @i %i (%Q) is"), + N_("ggroup"), + N_("hHTREE @d @i"), + N_("iinode"), + N_("Iillegal"), + N_("jjournal"), + N_("llost+found"), + N_("Lis a link"), + N_("mmultiply-claimed"), + N_("ninvalid"), + N_("oorphaned"), + N_("pproblem in"), + N_("qquota"), + N_("rroot @i"), + N_("sshould be"), + N_("Ssuper@b"), + N_("uunattached"), + N_("vdevice"), + N_("xextent"), + N_("zzero-length"), "@@", 0 }; @@ -118,113 +151,197 @@ static const char *abbrevs[] = { /* * Give more user friendly names to the "special" inodes. */ -#define num_special_inodes 7 +#define num_special_inodes 11 static const char *special_inode_name[] = { - "", /* 0 */ - "", /* 1 */ + N_(""), /* 0 */ + N_(""), /* 1 */ "/", /* 2 */ - "", /* 3 */ - "", /* 4 */ - "", /* 5 */ - "" /* 6 */ + N_(""), /* 3 */ + N_(""), /* 4 */ + N_(""), /* 5 */ + N_(""), /* 6 */ + N_(""), /* 7 */ + N_(""), /* 8 */ + N_(""), /* 9 */ + N_(""), /* 10 */ }; /* + * This function does "safe" printing. It will convert non-printable + * ASCII characters using '^' and M- notation. + */ +static void safe_print(FILE *f, const char *cp, int len) +{ + unsigned char ch; + + if (len < 0) + len = strlen(cp); + + while (len--) { + ch = *cp++; + if (ch > 128) { + fputs("M-", f); + ch -= 128; + } + if ((ch < 32) || (ch == 0x7f)) { + fputc('^', f); + ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */ + } + fputc(ch, f); + } +} + + +/* * This function prints a pathname, using the ext2fs_get_pathname * function */ -static void print_pathname(ext2_filsys fs, ino_t dir, ino_t ino) +static void print_pathname(FILE *f, ext2_filsys fs, ext2_ino_t dir, + ext2_ino_t ino) { - errcode_t retval; + errcode_t retval = 0; char *path; if (!dir && (ino < num_special_inodes)) { - fputs(special_inode_name[ino], stdout); + fputs(_(special_inode_name[ino]), f); return; } - - retval = ext2fs_get_pathname(fs, dir, ino, &path); - if (retval) - fputs("???", stdout); + + if (fs) + retval = ext2fs_get_pathname(fs, dir, ino, &path); + if (!fs || retval) + fputs("???", f); else { - fputs(path, stdout); - ext2fs_free_mem((void **) &path); + safe_print(f, path, -1); + ext2fs_free_mem(&path); } } +static void print_time(FILE *f, time_t t) +{ + const char * time_str; + static int do_gmt = -1; + +#ifdef __dietlibc__ + /* The diet libc doesn't respect the TZ environment variable */ + if (do_gmt == -1) { + time_str = getenv("TZ"); + if (!time_str) + time_str = ""; + do_gmt = !strcmp(time_str, "GMT") || + !strcmp(time_str, "GMT0"); + } +#endif + time_str = asctime((do_gmt > 0) ? gmtime(&t) : localtime(&t)); + fprintf(f, "%.24s", time_str); +} + /* * This function handles the '@' expansion. We allow recursive * expansion; an @ expression can contain further '@' and '%' - * expressions. + * expressions. */ -static _INLINE_ void expand_at_expression(e2fsck_t ctx, char ch, +static _INLINE_ void expand_at_expression(FILE *f, e2fsck_t ctx, char ch, struct problem_context *pctx, - int *first) + int *first, int recurse) { const char **cpp, *str; - + /* Search for the abbreviation */ for (cpp = abbrevs; *cpp; cpp++) { if (ch == *cpp[0]) break; } - if (*cpp) { - str = (*cpp) + 1; + if (*cpp && recurse < 10) { + str = _(*cpp) + 1; if (*first && islower(*str)) { *first = 0; - fputc(toupper(*str++), stdout); + fputc(toupper(*str++), f); } - print_e2fsck_message(ctx, str, pctx, *first); + print_e2fsck_message(f, ctx, str, pctx, *first, recurse+1); } else - printf("@%c", ch); + fprintf(f, "@%c", ch); } /* - * This function expands '%kX' expressions + * This function expands '%IX' expressions */ -static _INLINE_ void expand_inode_expression(char ch, - struct problem_context *ctx) +static _INLINE_ void expand_inode_expression(FILE *f, ext2_filsys fs, char ch, + struct problem_context *ctx) { struct ext2_inode *inode; - char * time_str; - time_t t; + struct ext2_inode_large *large_inode; if (!ctx || !ctx->inode) goto no_inode; - + inode = ctx->inode; - + large_inode = (struct ext2_inode_large *) inode; + switch (ch) { case 's': - printf("%u", inode->i_size); + fprintf(f, "%llu", (unsigned long long) EXT2_I_SIZE(inode)); + break; + case 'S': + fprintf(f, "%u", large_inode->i_extra_isize); break; case 'b': - printf("%u", inode->i_blocks); + if (ext2fs_has_feature_huge_file(fs->super)) + fprintf(f, "%llu", inode->i_blocks + + (((long long) inode->osd2.linux2.l_i_blocks_hi) + << 32)); + else + fprintf(f, "%u", inode->i_blocks); break; case 'l': - printf("%d", inode->i_links_count); + fprintf(f, "%d", inode->i_links_count); break; case 'm': - printf("0%o", inode->i_mode); + fprintf(f, "0%o", inode->i_mode); break; case 'M': - t = inode->i_mtime; - time_str = ctime(&t); - printf("%.24s", time_str); + print_time(f, inode->i_mtime); break; case 'F': - printf("%u", inode->i_faddr); + fprintf(f, "%u", inode->i_faddr); break; case 'f': - printf("%u", inode->i_file_acl); + fprintf(f, "%llu", + (unsigned long long) ext2fs_file_acl_block(fs, inode)); break; case 'd': - printf("%u", inode->i_dir_acl); + fprintf(f, "%u", (LINUX_S_ISDIR(inode->i_mode) ? + inode->i_size_high : 0)); + break; + case 'u': + fprintf(f, "%d", inode_uid(*inode)); + break; + case 'g': + fprintf(f, "%d", inode_gid(*inode)); + break; + case 't': + if (LINUX_S_ISREG(inode->i_mode)) + fputs(_("regular file"), f); + else if (LINUX_S_ISDIR(inode->i_mode)) + fputs(_("directory"), f); + else if (LINUX_S_ISCHR(inode->i_mode)) + fputs(_("character device"), f); + else if (LINUX_S_ISBLK(inode->i_mode)) + fputs(_("block device"), f); + else if (LINUX_S_ISFIFO(inode->i_mode)) + fputs(_("named pipe"), f); + else if (LINUX_S_ISLNK(inode->i_mode)) + fputs(_("symbolic link"), f); + else if (LINUX_S_ISSOCK(inode->i_mode)) + fputs(_("socket"), f); + else + fprintf(f, _("unknown file type with mode 0%o"), + inode->i_mode); break; default: no_inode: - printf("%%I%c", ch); + fprintf(f, "%%I%c", ch); break; } } @@ -232,130 +349,206 @@ static _INLINE_ void expand_inode_expression(char ch, /* * This function expands '%dX' expressions */ -static _INLINE_ void expand_dirent_expression(char ch, +static _INLINE_ void expand_dirent_expression(FILE *f, ext2_filsys fs, char ch, struct problem_context *ctx) { struct ext2_dir_entry *dirent; - int len; - + unsigned int rec_len, len; + if (!ctx || !ctx->dirent) goto no_dirent; - + dirent = ctx->dirent; - + switch (ch) { case 'i': - printf("%u", dirent->inode); + fprintf(f, "%u", dirent->inode); break; case 'n': - len = dirent->name_len & 0xFF; - if (len > EXT2_NAME_LEN) - len = EXT2_NAME_LEN; - if (len > dirent->rec_len) - len = dirent->rec_len; - printf("%.*s", len, dirent->name); + len = ext2fs_dirent_name_len(dirent); + if ((ext2fs_get_rec_len(fs, dirent, &rec_len) == 0) && + (len > rec_len)) + len = rec_len; + safe_print(f, dirent->name, len); break; case 'r': - printf("%u", dirent->rec_len); + (void) ext2fs_get_rec_len(fs, dirent, &rec_len); + fprintf(f, "%u", rec_len); break; case 'l': - printf("%u", dirent->name_len & 0xFF); + fprintf(f, "%u", ext2fs_dirent_name_len(dirent)); + break; + case 't': + fprintf(f, "%u", ext2fs_dirent_file_type(dirent)); break; default: no_dirent: - printf("%%D%c", ch); + fprintf(f, "%%D%c", ch); break; } } -static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch, +static _INLINE_ void expand_percent_expression(FILE *f, ext2_filsys fs, + char ch, int width, int *first, struct problem_context *ctx) { + e2fsck_t e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL; + const char *m; + if (!ctx) goto no_context; - + switch (ch) { case '%': - fputc('%', stdout); + fputc('%', f); break; case 'b': - printf("%u", ctx->blk); + fprintf(f, "%*llu", width, (unsigned long long) ctx->blk); break; case 'B': - printf("%d", ctx->blkcount); + if (ctx->blkcount == BLOCK_COUNT_IND) + m = _("indirect block"); + else if (ctx->blkcount == BLOCK_COUNT_DIND) + m = _("double indirect block"); + else if (ctx->blkcount == BLOCK_COUNT_TIND) + m = _("triple indirect block"); + else if (ctx->blkcount == BLOCK_COUNT_TRANSLATOR) + m = _("translator block"); + else + m = _("block #"); + if (*first && islower(m[0])) + fputc(toupper(*m++), f); + fputs(m, f); + if (ctx->blkcount >= 0) + fprintf(f, "%lld", (long long) ctx->blkcount); break; case 'c': - printf("%u", ctx->blk2); + fprintf(f, "%*llu", width, (unsigned long long) ctx->blk2); break; case 'd': - printf("%lu", ctx->dir); + fprintf(f, "%*u", width, ctx->dir); break; case 'g': - printf("%d", ctx->group); + fprintf(f, "%*u", width, ctx->group); break; case 'i': - printf("%lu", ctx->ino); + fprintf(f, "%*u", width, ctx->ino); break; case 'j': - printf("%lu", ctx->ino2); + fprintf(f, "%*u", width, ctx->ino2); break; case 'm': - printf("%s", error_message(ctx->errcode)); + fprintf(f, "%*s", width, error_message(ctx->errcode)); break; case 'N': - printf("%u", ctx->num); + fprintf(f, "%*llu", width, (long long)ctx->num); + break; + case 'n': + fprintf(f, "%*llu", width, (long long)ctx->num2); break; case 'p': - print_pathname(fs, ctx->ino, 0); + print_pathname(f, fs, ctx->ino, 0); break; case 'P': - print_pathname(fs, ctx->ino2, + print_pathname(f, fs, ctx->ino2, ctx->dirent ? ctx->dirent->inode : 0); break; case 'q': - print_pathname(fs, ctx->dir, 0); + print_pathname(f, fs, ctx->dir, 0); break; case 'Q': - print_pathname(fs, ctx->dir, ctx->ino); + print_pathname(f, fs, ctx->dir, ctx->ino); + break; + case 'r': + fprintf(f, "%*lld", width, (long long) ctx->blkcount); break; case 'S': - printf("%d", get_backup_sb(fs)); + fprintf(f, "%llu", + (unsigned long long) get_backup_sb(NULL, fs, + NULL, NULL)); break; case 's': - printf("%s", ctx->str); + fprintf(f, "%*s", width, ctx->str ? ctx->str : "NULL"); + break; + case 't': + print_time(f, (time_t) ctx->num); + break; + case 'T': + print_time(f, e2fsck_ctx ? e2fsck_ctx->now : time(0)); + break; + case 'U': + switch (ctx->num) { + case USRQUOTA: + m = _("user"); + break; + case GRPQUOTA: + m = _("group"); + break; + case PRJQUOTA: + m = _("project"); + break; + default: + m = _("unknown quota type"); + break; + } + if (*first && islower(m[0])) + fputc(toupper(*m++), f); + fputs(m, f); + if (ctx->num > PRJQUOTA) + fprintf(f, " %d", (int) ctx->num); + break; + case 'x': + fprintf(f, "0x%0*x", width, ctx->csum1); + break; + case 'X': + fprintf(f, "0x%0*llx", width, (long long)ctx->num); + break; + case 'y': + fprintf(f, "0x%0*x", width, ctx->csum2); break; default: no_context: - printf("%%%c", ch); + fprintf(f, "%%%c", ch); break; } -} +} -void print_e2fsck_message(e2fsck_t ctx, const char *msg, - struct problem_context *pctx, int first) +void print_e2fsck_message(FILE *f, e2fsck_t ctx, const char *msg, + struct problem_context *pctx, int first, + int recurse) { ext2_filsys fs = ctx->fs; const char * cp; - int i; - + int i, width; + + e2fsck_clear_progbar(ctx); for (cp = msg; *cp; cp++) { if (cp[0] == '@') { cp++; - expand_at_expression(ctx, *cp, pctx, &first); - } else if (cp[0] == '%' && cp[1] == 'I') { - cp += 2; - expand_inode_expression(*cp, pctx); - } else if (cp[0] == '%' && cp[1] == 'D') { - cp += 2; - expand_dirent_expression(*cp, pctx); - } else if ((cp[0] == '%')) { + expand_at_expression(f, ctx, *cp, pctx, &first, + recurse); + } else if (cp[0] == '%') { cp++; - expand_percent_expression(fs, *cp, pctx); + width = 0; + while (isdigit(cp[0])) { + width = (width * 10) + cp[0] - '0'; + cp++; + } + if (cp[0] == 'I') { + cp++; + expand_inode_expression(f, fs, *cp, pctx); + } else if (cp[0] == 'D') { + cp++; + expand_dirent_expression(f, fs, *cp, pctx); + } else { + expand_percent_expression(f, fs, *cp, width, + &first, pctx); + } } else { for (i=0; cp[i]; i++) if ((cp[i] == '@') || cp[i] == '%') break; - printf("%.*s", i, cp); + fprintf(f, "%.*s", i, cp); cp += i-1; } first = 0;