Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * message.c --- print e2fsck messages (with compression) |
| 3 | * |
| 4 | * Copyright 1996, 1997 by Theodore Ts'o |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
| 10 | * |
| 11 | * print_e2fsck_message() prints a message to the user, using |
| 12 | * compression techniques and expansions of abbreviations. |
| 13 | * |
| 14 | * The following % expansions are supported: |
| 15 | * |
| 16 | * %b <blk> block number |
| 17 | * %B <blkcount> integer |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 18 | * %c <blk2> block number |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 19 | * %di <dirent>->ino inode number |
| 20 | * %dn <dirent>->name string |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 21 | * %dr <dirent>->rec_len |
| 22 | * %dl <dirent>->name_len |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 23 | * %dt <dirent>->filetype |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 24 | * %D <dir> inode number |
| 25 | * %g <group> integer |
| 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 |
Theodore Ts'o | ecf1b77 | 2000-08-20 22:06:31 +0000 | [diff] [blame] | 35 | * %Iu <inode> -> i_uid |
| 36 | * %Ig <inode> -> i_gid |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 37 | * %j <ino2> inode number |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 38 | * %m <com_err error message> |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 39 | * %N <num> |
| 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. |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 47 | * %s <str> miscellaneous string |
| 48 | * %S backup superblock |
Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 49 | * %X <num> hexadecimal format |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 50 | * |
| 51 | * The following '@' expansions are supported: |
| 52 | * |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 53 | * @A error allocating |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 54 | * @b block |
| 55 | * @B bitmap |
Theodore Ts'o | 1917875 | 2000-02-11 15:55:07 +0000 | [diff] [blame] | 56 | * @c compress |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 57 | * @C conflicts with some other fs block |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 58 | * @D deleted |
| 59 | * @d directory |
| 60 | * @e entry |
| 61 | * @E Entry '%Dn' in %p (%i) |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 62 | * @f filesystem |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 63 | * @F for @i %i (%Q) is |
| 64 | * @g group |
Theodore Ts'o | d74edf4 | 2001-01-03 19:38:04 +0000 | [diff] [blame] | 65 | * @i inode |
| 66 | * @I illegal |
| 67 | * @j journal |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 68 | * @l lost+found |
| 69 | * @L is a link |
Theodore Ts'o | 80bfaa3 | 2000-08-18 15:08:37 +0000 | [diff] [blame] | 70 | * @o orphaned |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 71 | * @r root inode |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 72 | * @s should be |
| 73 | * @S superblock |
Theodore Ts'o | 80bfaa3 | 2000-08-18 15:08:37 +0000 | [diff] [blame] | 74 | * @u unattached |
Theodore Ts'o | d74edf4 | 2001-01-03 19:38:04 +0000 | [diff] [blame] | 75 | * @v device |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 76 | * @z zero-length |
| 77 | */ |
| 78 | |
| 79 | #include <stdlib.h> |
| 80 | #include <unistd.h> |
| 81 | #include <string.h> |
| 82 | #include <ctype.h> |
| 83 | #include <termios.h> |
| 84 | |
| 85 | #include "e2fsck.h" |
| 86 | |
| 87 | #include "problem.h" |
| 88 | |
| 89 | #ifdef __GNUC__ |
| 90 | #define _INLINE_ __inline__ |
| 91 | #else |
| 92 | #define _INLINE_ |
| 93 | #endif |
| 94 | |
| 95 | /* |
| 96 | * This structure defines the abbreviations used by the text strings |
| 97 | * below. The first character in the string is the index letter. An |
| 98 | * abbreviation of the form '@<i>' is expanded by looking up the index |
| 99 | * letter <i> in the table below. |
| 100 | */ |
| 101 | static const char *abbrevs[] = { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 102 | N_("Aerror allocating"), |
| 103 | N_("bblock"), |
| 104 | N_("Bbitmap"), |
Theodore Ts'o | 1917875 | 2000-02-11 15:55:07 +0000 | [diff] [blame] | 105 | N_("ccompress"), |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 106 | N_("Cconflicts with some other fs @b"), |
| 107 | N_("iinode"), |
| 108 | N_("Iillegal"), |
Theodore Ts'o | 1ce6453 | 2001-01-03 15:34:20 +0000 | [diff] [blame] | 109 | N_("jjournal"), |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 110 | N_("Ddeleted"), |
| 111 | N_("ddirectory"), |
| 112 | N_("eentry"), |
| 113 | N_("E@e '%Dn' in %p (%i)"), |
| 114 | N_("ffilesystem"), |
| 115 | N_("Ffor @i %i (%Q) is"), |
| 116 | N_("ggroup"), |
| 117 | N_("llost+found"), |
| 118 | N_("Lis a link"), |
Theodore Ts'o | 80bfaa3 | 2000-08-18 15:08:37 +0000 | [diff] [blame] | 119 | N_("oorphaned"), |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 120 | N_("rroot @i"), |
| 121 | N_("sshould be"), |
| 122 | N_("Ssuper@b"), |
Theodore Ts'o | 80bfaa3 | 2000-08-18 15:08:37 +0000 | [diff] [blame] | 123 | N_("uunattached"), |
Theodore Ts'o | d74edf4 | 2001-01-03 19:38:04 +0000 | [diff] [blame] | 124 | N_("vdevice"), |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 125 | N_("zzero-length"), |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 126 | "@@", |
| 127 | 0 |
| 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Give more user friendly names to the "special" inodes. |
| 132 | */ |
Theodore Ts'o | 721edd0 | 2001-01-12 21:05:57 +0000 | [diff] [blame] | 133 | #define num_special_inodes 11 |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 134 | static const char *special_inode_name[] = |
| 135 | { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 136 | N_("<The NULL inode>"), /* 0 */ |
| 137 | N_("<The bad blocks inode>"), /* 1 */ |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 138 | "/", /* 2 */ |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 139 | N_("<The ACL index inode>"), /* 3 */ |
| 140 | N_("<The ACL data inode>"), /* 4 */ |
| 141 | N_("<The boot loader inode>"), /* 5 */ |
Theodore Ts'o | 721edd0 | 2001-01-12 21:05:57 +0000 | [diff] [blame] | 142 | N_("<The undelete directory inode>"), /* 6 */ |
| 143 | N_("<The group descriptor inode>"), /* 7 */ |
| 144 | N_("<The journal inode>"), /* 8 */ |
| 145 | N_("<Reserved inode 9>"), /* 9 */ |
| 146 | N_("<Reserved inode 10>"), /* 10 */ |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | /* |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 150 | * This function does "safe" printing. It will convert non-printable |
| 151 | * ASCII characters using '^' and M- notation. |
| 152 | */ |
Theodore Ts'o | f68aa41 | 1999-10-26 14:20:22 +0000 | [diff] [blame] | 153 | static void safe_print(const char *cp, int len) |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 154 | { |
| 155 | unsigned char ch; |
| 156 | |
| 157 | if (len < 0) |
| 158 | len = strlen(cp); |
| 159 | |
| 160 | while (len--) { |
| 161 | ch = *cp++; |
| 162 | if (ch > 128) { |
| 163 | fputs("M-", stdout); |
| 164 | ch -= 128; |
| 165 | } |
Theodore Ts'o | ec8d2c3 | 1999-11-19 18:52:36 +0000 | [diff] [blame] | 166 | if ((ch < 32) || (ch == 0x7f)) { |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 167 | fputc('^', stdout); |
Theodore Ts'o | ec8d2c3 | 1999-11-19 18:52:36 +0000 | [diff] [blame] | 168 | ch ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */ |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 169 | } |
| 170 | fputc(ch, stdout); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | |
| 175 | /* |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 176 | * This function prints a pathname, using the ext2fs_get_pathname |
| 177 | * function |
| 178 | */ |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 179 | static void print_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino) |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 180 | { |
| 181 | errcode_t retval; |
| 182 | char *path; |
| 183 | |
| 184 | if (!dir && (ino < num_special_inodes)) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 185 | fputs(_(special_inode_name[ino]), stdout); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
| 189 | retval = ext2fs_get_pathname(fs, dir, ino, &path); |
| 190 | if (retval) |
| 191 | fputs("???", stdout); |
| 192 | else { |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 193 | safe_print(path, -1); |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 194 | ext2fs_free_mem((void **) &path); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * This function handles the '@' expansion. We allow recursive |
| 200 | * expansion; an @ expression can contain further '@' and '%' |
| 201 | * expressions. |
| 202 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 203 | static _INLINE_ void expand_at_expression(e2fsck_t ctx, char ch, |
| 204 | struct problem_context *pctx, |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 205 | int *first) |
| 206 | { |
| 207 | const char **cpp, *str; |
| 208 | |
| 209 | /* Search for the abbreviation */ |
| 210 | for (cpp = abbrevs; *cpp; cpp++) { |
| 211 | if (ch == *cpp[0]) |
| 212 | break; |
| 213 | } |
| 214 | if (*cpp) { |
| 215 | str = (*cpp) + 1; |
| 216 | if (*first && islower(*str)) { |
| 217 | *first = 0; |
| 218 | fputc(toupper(*str++), stdout); |
| 219 | } |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 220 | print_e2fsck_message(ctx, _(str), pctx, *first); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 221 | } else |
| 222 | printf("@%c", ch); |
| 223 | } |
| 224 | |
| 225 | /* |
Theodore Ts'o | ecf1b77 | 2000-08-20 22:06:31 +0000 | [diff] [blame] | 226 | * This function expands '%IX' expressions |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 227 | */ |
| 228 | static _INLINE_ void expand_inode_expression(char ch, |
| 229 | struct problem_context *ctx) |
| 230 | { |
| 231 | struct ext2_inode *inode; |
| 232 | char * time_str; |
| 233 | time_t t; |
| 234 | |
| 235 | if (!ctx || !ctx->inode) |
| 236 | goto no_inode; |
| 237 | |
| 238 | inode = ctx->inode; |
| 239 | |
| 240 | switch (ch) { |
| 241 | case 's': |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 242 | if (LINUX_S_ISDIR(inode->i_mode)) |
| 243 | printf("%u", inode->i_size); |
| 244 | else { |
| 245 | #ifdef EXT2_NO_64_TYPE |
| 246 | if (inode->i_size_high) |
| 247 | printf("0x%x%08x", inode->i_size_high, |
| 248 | inode->i_size); |
| 249 | else |
| 250 | printf("%u", inode->i_size); |
| 251 | #else |
| 252 | printf("%llu", (inode->i_size | |
| 253 | ((__u64) inode->i_size_high << 32))); |
| 254 | #endif |
| 255 | } |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 256 | break; |
| 257 | case 'b': |
| 258 | printf("%u", inode->i_blocks); |
| 259 | break; |
| 260 | case 'l': |
| 261 | printf("%d", inode->i_links_count); |
| 262 | break; |
| 263 | case 'm': |
| 264 | printf("0%o", inode->i_mode); |
| 265 | break; |
| 266 | case 'M': |
| 267 | t = inode->i_mtime; |
| 268 | time_str = ctime(&t); |
| 269 | printf("%.24s", time_str); |
| 270 | break; |
| 271 | case 'F': |
| 272 | printf("%u", inode->i_faddr); |
| 273 | break; |
| 274 | case 'f': |
| 275 | printf("%u", inode->i_file_acl); |
| 276 | break; |
| 277 | case 'd': |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 278 | printf("%u", (LINUX_S_ISDIR(inode->i_mode) ? |
| 279 | inode->i_dir_acl : 0)); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 280 | break; |
Theodore Ts'o | ecf1b77 | 2000-08-20 22:06:31 +0000 | [diff] [blame] | 281 | case 'u': |
| 282 | printf("%d", (inode->i_uid | |
| 283 | (inode->osd2.linux2.l_i_uid_high << 16))); |
| 284 | break; |
| 285 | case 'g': |
| 286 | printf("%d", (inode->i_gid | |
| 287 | (inode->osd2.linux2.l_i_gid_high << 16))); |
| 288 | break; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 289 | default: |
| 290 | no_inode: |
| 291 | printf("%%I%c", ch); |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * This function expands '%dX' expressions |
| 298 | */ |
| 299 | static _INLINE_ void expand_dirent_expression(char ch, |
| 300 | struct problem_context *ctx) |
| 301 | { |
| 302 | struct ext2_dir_entry *dirent; |
| 303 | int len; |
| 304 | |
| 305 | if (!ctx || !ctx->dirent) |
| 306 | goto no_dirent; |
| 307 | |
| 308 | dirent = ctx->dirent; |
| 309 | |
| 310 | switch (ch) { |
| 311 | case 'i': |
| 312 | printf("%u", dirent->inode); |
| 313 | break; |
| 314 | case 'n': |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 315 | len = dirent->name_len & 0xFF; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 316 | if (len > EXT2_NAME_LEN) |
| 317 | len = EXT2_NAME_LEN; |
| 318 | if (len > dirent->rec_len) |
| 319 | len = dirent->rec_len; |
Theodore Ts'o | 9e51eca | 1999-01-09 16:32:31 +0000 | [diff] [blame] | 320 | safe_print(dirent->name, len); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 321 | break; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 322 | case 'r': |
| 323 | printf("%u", dirent->rec_len); |
| 324 | break; |
| 325 | case 'l': |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 326 | printf("%u", dirent->name_len & 0xFF); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 327 | break; |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 328 | case 't': |
| 329 | printf("%u", dirent->name_len >> 8); |
| 330 | break; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 331 | default: |
| 332 | no_dirent: |
| 333 | printf("%%D%c", ch); |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch, |
| 339 | struct problem_context *ctx) |
| 340 | { |
| 341 | if (!ctx) |
| 342 | goto no_context; |
| 343 | |
| 344 | switch (ch) { |
| 345 | case '%': |
| 346 | fputc('%', stdout); |
| 347 | break; |
| 348 | case 'b': |
| 349 | printf("%u", ctx->blk); |
| 350 | break; |
| 351 | case 'B': |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 352 | #ifdef EXT2_NO_64_TYPE |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 353 | printf("%d", ctx->blkcount); |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 354 | #else |
| 355 | printf("%lld", ctx->blkcount); |
| 356 | #endif |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 357 | break; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 358 | case 'c': |
| 359 | printf("%u", ctx->blk2); |
| 360 | break; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 361 | case 'd': |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 362 | printf("%u", ctx->dir); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 363 | break; |
| 364 | case 'g': |
| 365 | printf("%d", ctx->group); |
| 366 | break; |
| 367 | case 'i': |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 368 | printf("%u", ctx->ino); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 369 | break; |
| 370 | case 'j': |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 371 | printf("%u", ctx->ino2); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 372 | break; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 373 | case 'm': |
| 374 | printf("%s", error_message(ctx->errcode)); |
| 375 | break; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 376 | case 'N': |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 377 | #ifdef EXT2_NO_64_TYPE |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 378 | printf("%u", ctx->num); |
Theodore Ts'o | 246501c | 1998-03-24 16:22:38 +0000 | [diff] [blame] | 379 | #else |
| 380 | printf("%llu", ctx->num); |
| 381 | #endif |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 382 | break; |
| 383 | case 'p': |
| 384 | print_pathname(fs, ctx->ino, 0); |
| 385 | break; |
| 386 | case 'P': |
| 387 | print_pathname(fs, ctx->ino2, |
| 388 | ctx->dirent ? ctx->dirent->inode : 0); |
| 389 | break; |
| 390 | case 'q': |
| 391 | print_pathname(fs, ctx->dir, 0); |
| 392 | break; |
| 393 | case 'Q': |
| 394 | print_pathname(fs, ctx->dir, ctx->ino); |
| 395 | break; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 396 | case 'S': |
| 397 | printf("%d", get_backup_sb(fs)); |
| 398 | break; |
| 399 | case 's': |
Theodore Ts'o | 133a56d | 2000-11-17 05:40:49 +0000 | [diff] [blame] | 400 | printf("%s", ctx->str ? ctx->str : "NULL"); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 401 | break; |
Theodore Ts'o | 3b5386d | 2000-08-14 14:25:19 +0000 | [diff] [blame] | 402 | case 'X': |
| 403 | #ifdef EXT2_NO_64_TYPE |
| 404 | printf("0x%x", ctx->num); |
| 405 | #else |
| 406 | printf("0x%llx", ctx->num); |
| 407 | #endif |
| 408 | break; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 409 | default: |
| 410 | no_context: |
| 411 | printf("%%%c", ch); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 416 | void print_e2fsck_message(e2fsck_t ctx, const char *msg, |
| 417 | struct problem_context *pctx, int first) |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 418 | { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 419 | ext2_filsys fs = ctx->fs; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 420 | const char * cp; |
| 421 | int i; |
Theodore Ts'o | 5596def | 1999-07-19 15:27:37 +0000 | [diff] [blame] | 422 | |
| 423 | e2fsck_clear_progbar(ctx); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 424 | for (cp = msg; *cp; cp++) { |
| 425 | if (cp[0] == '@') { |
| 426 | cp++; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 427 | expand_at_expression(ctx, *cp, pctx, &first); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 428 | } else if (cp[0] == '%' && cp[1] == 'I') { |
| 429 | cp += 2; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 430 | expand_inode_expression(*cp, pctx); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 431 | } else if (cp[0] == '%' && cp[1] == 'D') { |
| 432 | cp += 2; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 433 | expand_dirent_expression(*cp, pctx); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 434 | } else if ((cp[0] == '%')) { |
| 435 | cp++; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 436 | expand_percent_expression(fs, *cp, pctx); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 437 | } else { |
| 438 | for (i=0; cp[i]; i++) |
| 439 | if ((cp[i] == '@') || cp[i] == '%') |
| 440 | break; |
| 441 | printf("%.*s", i, cp); |
| 442 | cp += i-1; |
| 443 | } |
| 444 | first = 0; |
| 445 | } |
| 446 | } |