2 * message.c --- print e2fsck messages (with compression)
4 * Copyright 1996, 1997 by Theodore Ts'o
7 * This file may be redistributed under the terms of the GNU Public
11 * print_e2fsck_message() prints a message to the user, using
12 * compression techniques and expansions of abbreviations.
14 * The following % expansions are supported:
16 * %b <blk> block number
17 * %B <blkcount> integer
18 * %c <blk2> block number
19 * %Di <dirent>->ino inode number
20 * %Dn <dirent>->name string
21 * %Dr <dirent>->rec_len
22 * %Dl <dirent>->name_len
23 * %Dt <dirent>->filetype
24 * %d <dir> inode number
26 * %i <ino> inode number
27 * %Is <inode> -> i_size
28 * %Ib <inode> -> i_blocks
29 * %Il <inode> -> i_links_count
30 * %Im <inode> -> i_mode
31 * %IM <inode> -> i_mtime
32 * %IF <inode> -> i_faddr
33 * %If <inode> -> i_file_acl
34 * %Id <inode> -> i_dir_acl
35 * %Iu <inode> -> i_uid
36 * %Ig <inode> -> i_gid
37 * %j <ino2> inode number
38 * %m <com_err error message>
40 * %p ext2fs_get_pathname of directory <ino>
41 * %P ext2fs_get_pathname of <dirent>->ino with <ino2> as
42 * the containing directory. (If dirent is NULL
43 * then return the pathname of directory <ino2>)
44 * %q ext2fs_get_pathname of directory <dir>
45 * %Q ext2fs_get_pathname of directory <ino> with <dir> as
46 * the containing directory.
47 * %s <str> miscellaneous string
48 * %S backup superblock
49 * %X <num> hexadecimal format
51 * The following '@' expansions are supported:
53 * @a extended attribute
58 * @C conflicts with some other fs block
62 * @E Entry '%Dn' in %p (%i)
64 * @F for @i %i (%Q) is
66 * @h HTREE directory inode
93 #define _INLINE_ __inline__
99 * This structure defines the abbreviations used by the text strings
100 * below. The first character in the string is the index letter. An
101 * abbreviation of the form '@<i>' is expanded by looking up the index
102 * letter <i> in the table below.
104 static const char *abbrevs[] = {
105 N_("aextended attribute"),
106 N_("Aerror allocating"),
110 N_("Cconflicts with some other fs @b"),
117 N_("E@e '%Dn' in %p (%i)"),
119 N_("Ffor @i %i (%Q) is"),
137 * Give more user friendly names to the "special" inodes.
139 #define num_special_inodes 11
140 static const char *special_inode_name[] =
142 N_("<The NULL inode>"), /* 0 */
143 N_("<The bad blocks inode>"), /* 1 */
145 N_("<The ACL index inode>"), /* 3 */
146 N_("<The ACL data inode>"), /* 4 */
147 N_("<The boot loader inode>"), /* 5 */
148 N_("<The undelete directory inode>"), /* 6 */
149 N_("<The group descriptor inode>"), /* 7 */
150 N_("<The journal inode>"), /* 8 */
151 N_("<Reserved inode 9>"), /* 9 */
152 N_("<Reserved inode 10>"), /* 10 */
156 * This function does "safe" printing. It will convert non-printable
157 * ASCII characters using '^' and M- notation.
159 static void safe_print(const char *cp, int len)
172 if ((ch < 32) || (ch == 0x7f)) {
174 ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
182 * This function prints a pathname, using the ext2fs_get_pathname
185 static void print_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino)
190 if (!dir && (ino < num_special_inodes)) {
191 fputs(_(special_inode_name[ino]), stdout);
195 retval = ext2fs_get_pathname(fs, dir, ino, &path);
197 fputs("???", stdout);
199 safe_print(path, -1);
200 ext2fs_free_mem((void **) &path);
205 * This function handles the '@' expansion. We allow recursive
206 * expansion; an @ expression can contain further '@' and '%'
209 static _INLINE_ void expand_at_expression(e2fsck_t ctx, char ch,
210 struct problem_context *pctx,
213 const char **cpp, *str;
215 /* Search for the abbreviation */
216 for (cpp = abbrevs; *cpp; cpp++) {
222 if (*first && islower(*str)) {
224 fputc(toupper(*str++), stdout);
226 print_e2fsck_message(ctx, _(str), pctx, *first);
232 * This function expands '%IX' expressions
234 static _INLINE_ void expand_inode_expression(char ch,
235 struct problem_context *ctx)
237 struct ext2_inode *inode;
241 if (!ctx || !ctx->inode)
248 if (LINUX_S_ISDIR(inode->i_mode))
249 printf("%u", inode->i_size);
251 #ifdef EXT2_NO_64_TYPE
252 if (inode->i_size_high)
253 printf("0x%x%08x", inode->i_size_high,
256 printf("%u", inode->i_size);
258 printf("%llu", (inode->i_size |
259 ((__u64) inode->i_size_high << 32)));
264 printf("%u", inode->i_blocks);
267 printf("%d", inode->i_links_count);
270 printf("0%o", inode->i_mode);
274 time_str = ctime(&t);
275 printf("%.24s", time_str);
278 printf("%u", inode->i_faddr);
281 printf("%u", inode->i_file_acl);
284 printf("%u", (LINUX_S_ISDIR(inode->i_mode) ?
285 inode->i_dir_acl : 0));
288 printf("%d", (inode->i_uid |
289 (inode->osd2.linux2.l_i_uid_high << 16)));
292 printf("%d", (inode->i_gid |
293 (inode->osd2.linux2.l_i_gid_high << 16)));
303 * This function expands '%dX' expressions
305 static _INLINE_ void expand_dirent_expression(char ch,
306 struct problem_context *ctx)
308 struct ext2_dir_entry *dirent;
311 if (!ctx || !ctx->dirent)
314 dirent = ctx->dirent;
318 printf("%u", dirent->inode);
321 len = dirent->name_len & 0xFF;
322 if (len > EXT2_NAME_LEN)
324 if (len > dirent->rec_len)
325 len = dirent->rec_len;
326 safe_print(dirent->name, len);
329 printf("%u", dirent->rec_len);
332 printf("%u", dirent->name_len & 0xFF);
335 printf("%u", dirent->name_len >> 8);
344 static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
345 struct problem_context *ctx)
355 printf("%u", ctx->blk);
358 #ifdef EXT2_NO_64_TYPE
359 printf("%d", ctx->blkcount);
361 printf("%lld", ctx->blkcount);
365 printf("%u", ctx->blk2);
368 printf("%u", ctx->dir);
371 printf("%d", ctx->group);
374 printf("%u", ctx->ino);
377 printf("%u", ctx->ino2);
380 printf("%s", error_message(ctx->errcode));
383 #ifdef EXT2_NO_64_TYPE
384 printf("%u", ctx->num);
386 printf("%llu", ctx->num);
390 print_pathname(fs, ctx->ino, 0);
393 print_pathname(fs, ctx->ino2,
394 ctx->dirent ? ctx->dirent->inode : 0);
397 print_pathname(fs, ctx->dir, 0);
400 print_pathname(fs, ctx->dir, ctx->ino);
403 printf("%d", get_backup_sb(NULL, fs, NULL, NULL));
406 printf("%s", ctx->str ? ctx->str : "NULL");
409 #ifdef EXT2_NO_64_TYPE
410 printf("0x%x", ctx->num);
412 printf("0x%llx", ctx->num);
422 void print_e2fsck_message(e2fsck_t ctx, const char *msg,
423 struct problem_context *pctx, int first)
425 ext2_filsys fs = ctx->fs;
429 e2fsck_clear_progbar(ctx);
430 for (cp = msg; *cp; cp++) {
433 expand_at_expression(ctx, *cp, pctx, &first);
434 } else if (cp[0] == '%' && cp[1] == 'I') {
436 expand_inode_expression(*cp, pctx);
437 } else if (cp[0] == '%' && cp[1] == 'D') {
439 expand_dirent_expression(*cp, pctx);
440 } else if ((cp[0] == '%')) {
442 expand_percent_expression(fs, *cp, pctx);
444 for (i=0; cp[i]; i++)
445 if ((cp[i] == '@') || cp[i] == '%')
447 printf("%.*s", i, cp);