Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / e2fsck / message.c
index b9f9dea..c839bbf 100644 (file)
  *
  *     %b      <blk>                   block number
  *     %B      <blkcount>              integer
+ *     %c      <blk2>                  block number
  *     %di     <dirent>->ino           inode number
  *     %dn     <dirent>->name          string
+ *     %dr     <dirent>->rec_len
+ *     %dl     <dirent>->name_len
  *     %D      <dir>                   inode number
  *     %g      <group>                 integer
  *     %i      <ino>                   inode number
@@ -29,6 +32,7 @@
  *     %If     <inode> -> i_file_acl
  *     %Id     <inode> -> i_dir_acl
  *     %j      <ino2>                  inode number
+ *     %m      <com_err error message>
  *     %N      <num>
  *     %p      ext2fs_get_pathname of directory <ino>
  *     %P      ext2fs_get_pathname of <dirent>->ino with <ino2> as
  *     %q      ext2fs_get_pathname of directory <dir>
  *     %Q      ext2fs_get_pathname of directory <ino> with <dir> as
  *                     the containing directory.
+ *     %s      <str>                   miscellaneous string
+ *     %S      backup superblock
  *
  * The following '@' expansions are supported:
  *
+ *     @A      error allocating
  *     @b      block
  *     @B      bitmap
  *     @C      conflicts with some other fs block
  *     @d      directory
  *     @e      entry
  *     @E      Entry '%Dn' in %p (%i)
+ *     @f      filesystem
  *     @F      for @i %i (%Q) is
  *     @g      group
  *     @l      lost+found
  *     @L      is a link
  *     @u      unattached
  *     @r      root inode
+ *     @s      should be 
+ *     @S      superblock
  *     @z      zero-length
  */
 
@@ -81,6 +91,7 @@
  * letter <i> in the table below.
  */
 static const char *abbrevs[] = {
+       "Aerror allocating",
        "bblock",
        "Bbitmap",
        "Cconflicts with some other fs @b",
@@ -90,6 +101,7 @@ static const char *abbrevs[] = {
        "ddirectory",
        "eentry",
        "E@e '%Dn' in %p (%i)",
+       "ffilesystem",
        "Ffor @i %i (%Q) is",
        "ggroup",
        "llost+found",
@@ -97,6 +109,7 @@ static const char *abbrevs[] = {
        "uunattached",
        "rroot @i",
        "sshould be",
+       "Ssuper@b",
        "zzero-length",
        "@@",
        0
@@ -136,7 +149,7 @@ static void print_pathname(ext2_filsys fs, ino_t dir, ino_t ino)
                fputs("???", stdout);
        else {
                fputs(path, stdout);
-               free(path);
+               ext2fs_free_mem((void **) &path);
        }
 }
 
@@ -145,8 +158,8 @@ static void print_pathname(ext2_filsys fs, ino_t dir, ino_t ino)
  * expansion; an @ expression can contain further '@' and '%'
  * expressions. 
  */
-static _INLINE_ void expand_at_expression(ext2_filsys fs, char ch,
-                                         struct problem_context *ctx,
+static _INLINE_ void expand_at_expression(e2fsck_t ctx, char ch,
+                                         struct problem_context *pctx,
                                          int *first)
 {
        const char **cpp, *str;
@@ -162,7 +175,7 @@ static _INLINE_ void expand_at_expression(ext2_filsys fs, char ch,
                        *first = 0;
                        fputc(toupper(*str++), stdout);
                }
-               print_e2fsck_message(fs, str, ctx, *first);
+               print_e2fsck_message(ctx, str, pctx, *first);
        } else
                printf("@%c", ch);
 }
@@ -184,7 +197,20 @@ static _INLINE_ void expand_inode_expression(char ch,
        
        switch (ch) {
        case 's':
-               printf("%u", inode->i_size);
+               if (LINUX_S_ISDIR(inode->i_mode))
+                       printf("%u", inode->i_size);
+               else {
+#ifdef EXT2_NO_64_TYPE
+                       if (inode->i_size_high)
+                               printf("0x%x%08x", inode->i_size_high,
+                                      inode->i_size);
+                       else
+                               printf("%u", inode->i_size);
+#else
+                       printf("%llu", (inode->i_size | 
+                                       ((__u64) inode->i_size_high << 32)));
+#endif
+               }
                break;
        case 'b':
                printf("%u", inode->i_blocks);
@@ -207,7 +233,8 @@ static _INLINE_ void expand_inode_expression(char ch,
                printf("%u", inode->i_file_acl);
                break;
        case 'd':
-               printf("%u", inode->i_dir_acl);
+               printf("%u", (LINUX_S_ISDIR(inode->i_mode) ?
+                             inode->i_dir_acl : 0));
                break;
        default:
        no_inode:
@@ -235,12 +262,18 @@ static _INLINE_ void expand_dirent_expression(char ch,
                printf("%u", dirent->inode);
                break;
        case 'n':
-               len = dirent->name_len;
+               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", dirent->name_len, dirent->name);
+               printf("%.*s", len, dirent->name);
+               break;
+       case 'r':
+               printf("%u", dirent->rec_len);
+               break;
+       case 'l':
+               printf("%u", dirent->name_len & 0xFF);
                break;
        default:
        no_dirent:
@@ -263,7 +296,14 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
                printf("%u", ctx->blk);
                break;
        case 'B':
+#ifdef EXT2_NO_64_TYPE
                printf("%d", ctx->blkcount);
+#else
+               printf("%lld", ctx->blkcount);
+#endif
+               break;
+       case 'c':
+               printf("%u", ctx->blk2);
                break;
        case 'd':
                printf("%lu", ctx->dir);
@@ -277,8 +317,15 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
        case 'j':
                printf("%lu", ctx->ino2);
                break;
+       case 'm':
+               printf("%s", error_message(ctx->errcode));
+               break;
        case 'N':
+#ifdef EXT2_NO_64_TYPE
                printf("%u", ctx->num);
+#else
+               printf("%llu", ctx->num);
+#endif
                break;
        case 'p':
                print_pathname(fs, ctx->ino, 0);
@@ -293,6 +340,12 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
        case 'Q':
                print_pathname(fs, ctx->dir, ctx->ino);
                break;
+       case 'S':
+               printf("%d", get_backup_sb(fs));
+               break;
+       case 's':
+               printf("%s", ctx->str);
+               break;
        default:
        no_context:
                printf("%%%c", ch);
@@ -300,25 +353,26 @@ static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
        }
 }      
 
-void print_e2fsck_message(ext2_filsys fs, const char *msg,
-                         struct problem_context *ctx, int first)
+void print_e2fsck_message(e2fsck_t ctx, const char *msg,
+                         struct problem_context *pctx, int first)
 {
+       ext2_filsys fs = ctx->fs;
        const char *    cp;
        int             i;
        
        for (cp = msg; *cp; cp++) {
                if (cp[0] == '@') {
                        cp++;
-                       expand_at_expression(fs, *cp, ctx, &first);
+                       expand_at_expression(ctx, *cp, pctx, &first);
                } else if (cp[0] == '%' && cp[1] == 'I') {
                        cp += 2;
-                       expand_inode_expression(*cp, ctx);
+                       expand_inode_expression(*cp, pctx);
                } else if (cp[0] == '%' && cp[1] == 'D') {
                        cp += 2;
-                       expand_dirent_expression(*cp, ctx);
+                       expand_dirent_expression(*cp, pctx);
                } else if ((cp[0] == '%')) {
                        cp++;
-                       expand_percent_expression(fs, *cp, ctx);
+                       expand_percent_expression(fs, *cp, pctx);
                } else {
                        for (i=0; cp[i]; i++)
                                if ((cp[i] == '@') || cp[i] == '%')