Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / lib / e2p / ls.c
index 02388ff..a7ea38a 100644 (file)
@@ -6,12 +6,16 @@
  *                                 Universite Pierre et Marie Curie (Paris VI)
  *
  * Copyright (C) 1995, 1996, 1997  Theodore Ts'o <tytso@mit.edu>
- * 
- * This file can be redistributed under the terms of the GNU Library General
- * Public License
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <string.h>
 #include <grp.h>
@@ -112,7 +116,77 @@ static void print_features(struct ext2_super_block * s, FILE *f)
 #endif
 }
 
+static void print_mntopts(struct ext2_super_block * s, FILE *f)
+{
+#ifdef EXT2_DYNAMIC_REV
+       int     i, printed=0;
+       __u32   mask = s->s_default_mount_opts, m;
 
+       fprintf(f, "Default mount options:   ");
+       if (mask & EXT3_DEFM_JMODE) {
+               fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE));
+               printed++;
+       }
+       for (i=0,m=1; i < 32; i++, m<<=1) {
+               if (m & EXT3_DEFM_JMODE)
+                       continue;
+               if (mask & m) {
+                       fprintf(f, " %s", e2p_mntopt2string(m));
+                       printed++;
+               }
+       }
+       if (printed == 0)
+               fprintf(f, " (none)");
+       fprintf(f, "\n");
+#endif
+}
+
+static void print_super_flags(struct ext2_super_block * s, FILE *f)
+{
+       int     flags_found = 0;
+
+       if (s->s_flags == 0)
+               return;
+
+       fputs("Filesystem flags:         ", f);
+       if (s->s_flags & EXT2_FLAGS_SIGNED_HASH) {
+               fputs("signed_directory_hash ", f);
+               flags_found++;
+       }
+       if (s->s_flags & EXT2_FLAGS_UNSIGNED_HASH) {
+               fputs("unsigned_directory_hash ", f);
+               flags_found++;
+       }
+       if (s->s_flags & EXT2_FLAGS_TEST_FILESYS) {
+               fputs("test_filesystem ", f);
+               flags_found++;
+       }
+       if (flags_found)
+               fputs("\n", f);
+       else
+               fputs("(none)\n", f);
+}
+
+static __u64 e2p_blocks_count(struct ext2_super_block *super)
+{
+       return super->s_blocks_count |
+               (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+               (__u64) super->s_blocks_count_hi << 32 : 0);
+}
+
+static __u64 e2p_r_blocks_count(struct ext2_super_block *super)
+{
+       return super->s_r_blocks_count |
+               (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+               (__u64) super->s_r_blocks_count_hi << 32 : 0);
+}
+
+static __u64 e2p_free_blocks_count(struct ext2_super_block *super)
+{
+       return super->s_free_blocks_count |
+               (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+               (__u64) super->s_free_blocks_hi << 32 : 0);
+}
 
 #ifndef EXT2_INODE_SIZE
 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
@@ -122,11 +196,20 @@ static void print_features(struct ext2_super_block * s, FILE *f)
 #define EXT2_GOOD_OLD_REV 0
 #endif
 
+static const char *checksum_type(__u8 type)
+{
+       switch (type) {
+       case EXT2_CRC32C_CHKSUM:
+               return "crc32c";
+       default:
+               return "unknown";
+       }
+}
+
 void list_super2(struct ext2_super_block * sb, FILE *f)
 {
        int inode_blocks_per_group;
-       char buf[80];
-       const char *os;
+       char buf[80], *str;
        time_t  tm;
 
        inode_blocks_per_group = (((sb->s_inodes_per_group *
@@ -157,33 +240,68 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
        } else
                fprintf(f, " (unknown)\n");
        print_features(sb, f);
+       print_super_flags(sb, f);
+       print_mntopts(sb, f);
+       if (sb->s_mount_opts[0])
+               fprintf(f, "Mount options:            %s\n", sb->s_mount_opts);
        fprintf(f, "Filesystem state:        ");
        print_fs_state (f, sb->s_state);
        fprintf(f, "\n");
        fprintf(f, "Errors behavior:          ");
        print_fs_errors(f, sb->s_errors);
        fprintf(f, "\n");
-       switch (sb->s_creator_os) {
-           case EXT2_OS_LINUX: os = "Linux"; break;
-           case EXT2_OS_HURD:  os = "GNU/Hurd"; break;
-           case EXT2_OS_MASIX: os = "Masix"; break;
-           default:            os = "unknown"; break;
-       }
-       fprintf(f, "Filesystem OS type:       %s\n", os);
+       str = e2p_os2string(sb->s_creator_os);
+       fprintf(f, "Filesystem OS type:       %s\n", str);
+       free(str);
        fprintf(f, "Inode count:              %u\n", sb->s_inodes_count);
-       fprintf(f, "Block count:              %u\n", sb->s_blocks_count);
-       fprintf(f, "Reserved block count:     %u\n", sb->s_r_blocks_count);
-       fprintf(f, "Free blocks:              %u\n", sb->s_free_blocks_count);
+       fprintf(f, "Block count:              %llu\n", e2p_blocks_count(sb));
+       fprintf(f, "Reserved block count:     %llu\n", e2p_r_blocks_count(sb));
+       if (sb->s_overhead_blocks)
+               fprintf(f, "Overhead blocks:          %u\n",
+                       sb->s_overhead_blocks);
+       fprintf(f, "Free blocks:              %llu\n", e2p_free_blocks_count(sb));
        fprintf(f, "Free inodes:              %u\n", sb->s_free_inodes_count);
        fprintf(f, "First block:              %u\n", sb->s_first_data_block);
        fprintf(f, "Block size:               %u\n", EXT2_BLOCK_SIZE(sb));
-       fprintf(f, "Fragment size:            %u\n", EXT2_FRAG_SIZE(sb));
+       if (sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC)
+               fprintf(f, "Cluster size:             %u\n",
+                       EXT2_CLUSTER_SIZE(sb));
+       else
+               fprintf(f, "Fragment size:            %u\n",
+                       EXT2_CLUSTER_SIZE(sb));
+       if (sb->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+               fprintf(f, "Group descriptor size:    %u\n", sb->s_desc_size);
+       if (sb->s_reserved_gdt_blocks)
+               fprintf(f, "Reserved GDT blocks:      %u\n",
+                       sb->s_reserved_gdt_blocks);
        fprintf(f, "Blocks per group:         %u\n", sb->s_blocks_per_group);
-       fprintf(f, "Fragments per group:      %u\n", sb->s_frags_per_group);
+       if (sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC)
+               fprintf(f, "Clusters per group:       %u\n",
+                       sb->s_clusters_per_group);
+       else
+               fprintf(f, "Fragments per group:      %u\n",
+                       sb->s_clusters_per_group);
        fprintf(f, "Inodes per group:         %u\n", sb->s_inodes_per_group);
        fprintf(f, "Inode blocks per group:   %u\n", inode_blocks_per_group);
+       if (sb->s_raid_stride)
+               fprintf(f, "RAID stride:              %u\n",
+                       sb->s_raid_stride);
+       if (sb->s_raid_stripe_width)
+               fprintf(f, "RAID stripe width:        %u\n",
+                       sb->s_raid_stripe_width);
+       if (sb->s_first_meta_bg)
+               fprintf(f, "First meta block group:   %u\n",
+                       sb->s_first_meta_bg);
+       if (sb->s_log_groups_per_flex)
+               fprintf(f, "Flex block group size:    %u\n",
+                       1 << sb->s_log_groups_per_flex);
+       if (sb->s_mkfs_time) {
+               tm = sb->s_mkfs_time;
+               fprintf(f, "Filesystem created:       %s", ctime(&tm));
+       }
        tm = sb->s_mtime;
-       fprintf(f, "Last mount time:          %s", ctime(&tm));
+       fprintf(f, "Last mount time:          %s",
+               sb->s_mtime ? ctime(&tm) : "n/a\n");
        tm = sb->s_wtime;
        fprintf(f, "Last write time:          %s", ctime(&tm));
        fprintf(f, "Mount count:              %u\n", sb->s_mnt_count);
@@ -199,26 +317,135 @@ void list_super2(struct ext2_super_block * sb, FILE *f)
                next = sb->s_lastcheck + sb->s_checkinterval;
                fprintf(f, "Next check after:         %s", ctime(&next));
        }
+#define POW2(x) ((__u64) 1 << (x))
+       if (sb->s_kbytes_written) {
+               fprintf(f, "Lifetime writes:          ");
+               if (sb->s_kbytes_written < POW2(13))
+                       fprintf(f, "%llu kB\n", sb->s_kbytes_written);
+               else if (sb->s_kbytes_written < POW2(23))
+                       fprintf(f, "%llu MB\n",
+                               (sb->s_kbytes_written + POW2(9)) >> 10);
+               else if (sb->s_kbytes_written < POW2(33))
+                       fprintf(f, "%llu GB\n",
+                               (sb->s_kbytes_written + POW2(19)) >> 20);
+               else if (sb->s_kbytes_written < POW2(43))
+                       fprintf(f, "%llu TB\n",
+                               (sb->s_kbytes_written + POW2(29)) >> 30);
+               else
+                       fprintf(f, "%llu PB\n",
+                               (sb->s_kbytes_written + POW2(39)) >> 40);
+       }
        fprintf(f, "Reserved blocks uid:      ");
        print_user(sb->s_def_resuid, f);
        fprintf(f, "Reserved blocks gid:      ");
        print_group(sb->s_def_resgid, f);
        if (sb->s_rev_level >= EXT2_DYNAMIC_REV) {
                fprintf(f, "First inode:              %d\n", sb->s_first_ino);
-               fprintf(f, "Inode size:           %d\n", sb->s_inode_size);
+               fprintf(f, "Inode size:           %d\n", sb->s_inode_size);
+               if (sb->s_min_extra_isize)
+                       fprintf(f, "Required extra isize:     %d\n",
+                               sb->s_min_extra_isize);
+               if (sb->s_want_extra_isize)
+                       fprintf(f, "Desired extra isize:      %d\n",
+                               sb->s_want_extra_isize);
        }
-       if (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
+       if (!e2p_is_null_uuid(sb->s_journal_uuid))
                fprintf(f, "Journal UUID:             %s\n",
                        e2p_uuid2str(sb->s_journal_uuid));
-               fprintf(f, "Journal inode:            %u\n", sb->s_journal_inum);
-               fprintf(f, "Journal device:               0x%04x\n", sb->s_journal_dev);
-               fprintf(f, "First orphan inode:       %u\n", sb->s_last_orphan);
-       }
-       if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
+       if (sb->s_journal_inum)
+               fprintf(f, "Journal inode:            %u\n",
+                       sb->s_journal_inum);
+       if (sb->s_journal_dev)
+               fprintf(f, "Journal device:               0x%04x\n",
+                       sb->s_journal_dev);
+       if (sb->s_last_orphan)
+               fprintf(f, "First orphan inode:       %u\n",
+                       sb->s_last_orphan);
+       if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) ||
+           sb->s_def_hash_version)
                fprintf(f, "Default directory hash:   %s\n",
                        e2p_hash2string(sb->s_def_hash_version));
+       if (!e2p_is_null_uuid(sb->s_hash_seed))
                fprintf(f, "Directory Hash Seed:      %s\n",
                        e2p_uuid2str(sb->s_hash_seed));
+       if (sb->s_jnl_backup_type) {
+               fprintf(f, "Journal backup:           ");
+               switch (sb->s_jnl_backup_type) {
+               case 1:
+                       fprintf(f, "inode blocks\n");
+                       break;
+               default:
+                       fprintf(f, "type %u\n", sb->s_jnl_backup_type);
+               }
+       }
+       if (sb->s_backup_bgs[0] || sb->s_backup_bgs[1]) {
+               fprintf(f, "Backup block groups:      ");
+               if (sb->s_backup_bgs[0])
+                       fprintf(f, "%u ", sb->s_backup_bgs[0]);
+               if (sb->s_backup_bgs[1])
+                       fprintf(f, "%u ", sb->s_backup_bgs[1]);
+               fputc('\n', f);
+       }
+       if (sb->s_snapshot_inum) {
+               fprintf(f, "Snapshot inode:           %u\n",
+                       sb->s_snapshot_inum);
+               fprintf(f, "Snapshot ID:              %u\n",
+                       sb->s_snapshot_id);
+               fprintf(f, "Snapshot reserved blocks: %llu\n",
+                       sb->s_snapshot_r_blocks_count);
+       }
+       if (sb->s_snapshot_list)
+               fprintf(f, "Snapshot list head:       %u\n",
+                       sb->s_snapshot_list);
+       if (sb->s_error_count)
+               fprintf(f, "FS Error count:           %u\n",
+                       sb->s_error_count);
+       if (sb->s_first_error_time) {
+               tm = sb->s_first_error_time;
+               fprintf(f, "First error time:         %s", ctime(&tm));
+               memset(buf, 0, sizeof(buf));
+               strncpy(buf, (char *)sb->s_first_error_func,
+                       sizeof(sb->s_first_error_func));
+               fprintf(f, "First error function:     %s\n", buf);
+               fprintf(f, "First error line #:       %u\n",
+                       sb->s_first_error_line);
+               fprintf(f, "First error inode #:      %u\n",
+                       sb->s_first_error_ino);
+               fprintf(f, "First error block #:      %llu\n",
+                       sb->s_first_error_block);
+       }
+       if (sb->s_last_error_time) {
+               tm = sb->s_last_error_time;
+               fprintf(f, "Last error time:          %s", ctime(&tm));
+               memset(buf, 0, sizeof(buf));
+               strncpy(buf, (char *)sb->s_last_error_func,
+                       sizeof(sb->s_last_error_func));
+               fprintf(f, "Last error function:      %s\n", buf);
+               fprintf(f, "Last error line #:        %u\n",
+                       sb->s_last_error_line);
+               fprintf(f, "Last error inode #:       %u\n",
+                       sb->s_last_error_ino);
+               fprintf(f, "Last error block #:       %llu\n",
+                       sb->s_last_error_block);
+       }
+       if (sb->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) {
+               fprintf(f, "MMP block number:         %llu\n",
+                       (long long)sb->s_mmp_block);
+               fprintf(f, "MMP update interval:      %u\n",
+                       sb->s_mmp_update_interval);
+       }
+       if (sb->s_usr_quota_inum)
+               fprintf(f, "User quota inode:         %u\n",
+                       sb->s_usr_quota_inum);
+       if (sb->s_grp_quota_inum)
+               fprintf(f, "Group quota inode:        %u\n",
+                       sb->s_grp_quota_inum);
+
+       if (sb->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
+               fprintf(f, "Checksum type:            %s\n",
+                       checksum_type(sb->s_checksum_type));
+               fprintf(f, "Checksum:                 0x%08x\n",
+                       sb->s_checksum);
        }
 }