ls.c revision 53d3955001593b668b15e2d10b3a191f689f9779
13839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o/* 23839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * ls.c - List the contents of an ext2fs superblock 33839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * 43839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> 53839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Laboratoire MASI, Institut Blaise Pascal 63839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Universite Pierre et Marie Curie (Paris VI) 73839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * 821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * Copyright (C) 1995, 1996, 1997 Theodore Ts'o <tytso@mit.edu> 921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o * 103839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * This file can be redistributed under the terms of the GNU Library General 113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Public License 123839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */ 133839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 141e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#include <stdio.h> 1550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#include <sys/types.h> 161e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#include <string.h> 17f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#include <grp.h> 18f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#include <pwd.h> 193839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include <time.h> 203839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 213839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "e2p.h" 223839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 231e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/* 241e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * The ext2fs library private definition of the ext2 superblock, so we 251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * don't have to depend on the kernel's definition of the superblock, 261e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * which might not have the latest features. 271e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */ 281e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'ostruct ext2fs_sb { 291e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_inodes_count; /* Inodes count */ 301e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_blocks_count; /* Blocks count */ 311e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_r_blocks_count; /* Reserved blocks count */ 321e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_free_blocks_count; /* Free blocks count */ 331e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_free_inodes_count; /* Free inodes count */ 341e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_first_data_block; /* First Data Block */ 351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_log_block_size; /* Block size */ 361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __s32 s_log_frag_size; /* Fragment size */ 371e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_blocks_per_group; /* # Blocks per group */ 381e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_frags_per_group; /* # Fragments per group */ 391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_inodes_per_group; /* # Inodes per group */ 401e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_mtime; /* Mount time */ 411e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_wtime; /* Write time */ 421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_mnt_count; /* Mount count */ 431e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __s16 s_max_mnt_count; /* Maximal mount count */ 441e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_magic; /* Magic signature */ 451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_state; /* File system state */ 461e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_errors; /* Behaviour when detecting errors */ 471e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_minor_rev_level; /* minor revision level */ 481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_lastcheck; /* time of last check */ 491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_checkinterval; /* max. time between checks */ 501e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_creator_os; /* OS */ 511e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_rev_level; /* Revision level */ 521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_def_resuid; /* Default uid for reserved blocks */ 531e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_def_resgid; /* Default gid for reserved blocks */ 541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o /* 551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * These fields are for EXT2_DYNAMIC_REV superblocks only. 561e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * 571e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * Note: the difference between the compatible feature set and 581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * the incompatible feature set is that if there is a bit set 591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * in the incompatible feature set that the kernel doesn't 601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * know about, it should refuse to mount the filesystem. 611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * 621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * e2fsck's requirements are more strict; if it doesn't know 631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * about a feature in either the compatible or incompatible 641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * feature set, it must abort and not try to meddle with 651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * things it doesn't understand... 661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */ 671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_first_ino; /* First non-reserved inode */ 681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_inode_size; /* size of inode structure */ 691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u16 s_block_group_nr; /* block group # of this superblock */ 701e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_feature_compat; /* compatible feature set */ 711e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_feature_incompat; /* incompatible feature set */ 721e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u32 s_feature_ro_compat; /* readonly-compatible feature set */ 731e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o __u8 s_uuid[16]; /* 128-bit uuid for volume */ 741e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o char s_volume_name[16]; /* volume name */ 751e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o char s_last_mounted[64]; /* directory where last mounted */ 7619c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u32 s_algorithm_usage_bitmap; /* For compression */ 7719c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o /* 7819c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o * Performance hints. Directory preallocation should only 7919c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on. 8019c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o */ 8119c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ 8219c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ 8319c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u16 s_padding1; 8419c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o /* 8519c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o * Journaling support. 8619c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o */ 8719c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u8 s_journal_uuid[16]; /* uuid of journal superblock */ 8819c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u32 s_journal_inum; /* inode number of journal file */ 8919c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u32 s_journal_dev; /* device number of journal file */ 9019c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u32 s_last_orphan; /* start of list of inodes to delete */ 9119c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o 9219c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o __u32 s_reserved[197]; /* Padding to the end of the block */ 931e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}; 941e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 95521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o#ifndef EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 96521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 97521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o#endif 98521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o 9953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'ostatic void print_user (unsigned short uid, FILE *f) 100f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{ 101f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o struct passwd *pw; 102f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o 10353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "%u ", uid); 104f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o pw = getpwuid (uid); 105f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o if (pw == NULL) 10653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "(user unknown)\n"); 107f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o else 10853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "(user %s)\n", pw->pw_name); 109f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o} 110f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o 11153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'ostatic void print_group (unsigned short gid, FILE *f) 112f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{ 113f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o struct group *gr; 114f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o 11553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "%u ", gid); 116f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o gr = getgrgid (gid); 117f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o if (gr == NULL) 11853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "(group unknown)\n"); 119f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o else 12053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "(group %s)\n", gr->gr_name); 121f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o} 122f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o 1231e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#define MONTH_INT (86400 * 30) 1241e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#define WEEK_INT (86400 * 7) 1251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#define DAY_INT (86400) 1261e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#define HOUR_INT (60 * 60) 1271e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#define MINUTE_INT (60) 1281e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 12921c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'ostatic const char *interval_string(unsigned int secs) 1301e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{ 1311e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o static char buf[256], tmp[80]; 1321e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o int hr, min, num; 1331e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 1341e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o buf[0] = 0; 1351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 13621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o if (secs == 0) 13721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o return "<none>"; 13821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o 1391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (secs >= MONTH_INT) { 1401e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o num = secs / MONTH_INT; 1411e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o secs -= num*MONTH_INT; 1421e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o sprintf(buf, "%d month%s", num, (num>1) ? "s" : ""); 1431e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o } 1441e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (secs >= WEEK_INT) { 1451e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o num = secs / WEEK_INT; 1461e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o secs -= num*WEEK_INT; 1471e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "", 1481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o num, (num>1) ? "s" : ""); 1491e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o strcat(buf, tmp); 1501e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o } 1511e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (secs >= DAY_INT) { 1521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o num = secs / DAY_INT; 1531e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o secs -= num*DAY_INT; 1541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "", 1551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o num, (num>1) ? "s" : ""); 1561e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o strcat(buf, tmp); 1571e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o } 1581e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (secs > 0) { 1591e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o hr = secs / HOUR_INT; 1601e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o secs -= hr*HOUR_INT; 1611e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o min = secs / MINUTE_INT; 1621e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o secs -= min*MINUTE_INT; 1631e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "", 1641e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o hr, min, secs); 1651e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o strcat(buf, tmp); 1661e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o } 1671e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o return buf; 1681e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o} 1691e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 17053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'ostatic void print_features(struct ext2_super_block * s, FILE *f) 171d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o{ 172d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o#ifdef EXT2_DYNAMIC_REV 173d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o int i, j, printed=0; 174d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o __u32 *mask = &s->s_feature_compat, m; 175d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o 17653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem features: "); 177d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o for (i=0; i <3; i++,mask++) { 178d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o for (j=0,m=1; j < 32; j++, m<<=1) { 179d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o if (*mask & m) { 18053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, " %s", e2p_feature2string(i, m)); 181d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o printed++; 182d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o } 183d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o } 184d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o } 185d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o if (printed == 0) 18653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "(none)"); 18753d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "\n"); 188d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o#endif 189d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o} 190d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o 191d7b701ded6fda284d7c77cd5ac48c2607ff72b13Theodore Ts'o 1921e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 1937f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o#ifndef EXT2_INODE_SIZE 1947f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) 1957f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o#endif 1967f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o 197a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o#ifndef EXT2_GOOD_OLD_REV 198a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o#define EXT2_GOOD_OLD_REV 0 199a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o#endif 200a29f4d30f24d68f1f1c75548e020689ede532c05Theodore Ts'o 20153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'ovoid list_super2(struct ext2_super_block * s, FILE *f) 2023839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{ 2037f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o int inode_blocks_per_group; 2041e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o struct ext2fs_sb *sb = (struct ext2fs_sb *) s; 2051e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o char buf[80]; 2061e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o const char *os; 20721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o time_t tm; 2087f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o 2097f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o inode_blocks_per_group = (((s->s_inodes_per_group * 2107f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o EXT2_INODE_SIZE(s)) + 2117f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o EXT2_BLOCK_SIZE(s) - 1) / 2127f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o EXT2_BLOCK_SIZE(s)); 2131e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (sb->s_volume_name[0]) { 2141e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o memset(buf, 0, sizeof(buf)); 2151e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name)); 21621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o } else 21721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o strcpy(buf, "<none>"); 21853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem volume name: %s\n", buf); 2191e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (sb->s_last_mounted[0]) { 2201e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o memset(buf, 0, sizeof(buf)); 2211e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted)); 22221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o } else 22321c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o strcpy(buf, "<not available>"); 22453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Last mounted on: %s\n", buf); 2251e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o if (!e2p_is_null_uuid(sb->s_uuid)) { 2261e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o e2p_uuid_to_str(sb->s_uuid, buf); 22721c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o } else 22821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o strcpy(buf, "<none>"); 22953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem UUID: %s\n", buf); 23053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem magic number: 0x%04X\n", s->s_magic); 23153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem revision #: %d", s->s_rev_level); 232521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o if (s->s_rev_level == EXT2_GOOD_OLD_REV) { 23353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, " (original)\n"); 234521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o#ifdef EXT2_DYNAMIC_REV 235521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o } else if (s->s_rev_level == EXT2_DYNAMIC_REV) { 23653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, " (dynamic)\n"); 237521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o#endif 238521e36857227b21e7ab47b0a97f788d2af9f9717Theodore Ts'o } else 23953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "\n"); 24053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o print_features(s, f); 24153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem state: "); 24253d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o print_fs_state (f, s->s_state); 24353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "\n"); 24453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Errors behavior: "); 24553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o print_fs_errors(f, s->s_errors); 24653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "\n"); 2471e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o switch (s->s_creator_os) { 2481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o case EXT2_OS_LINUX: os = "Linux"; break; 2494ea0a1109d761e9caaa53f6fa9e036321826c5faTheodore Ts'o case EXT2_OS_HURD: os = "GNU/Hurd"; break; 2501e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o case EXT2_OS_MASIX: os = "Masix"; break; 2511e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o default: os = "unknown"; break; 2521e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o } 25353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Filesystem OS type: %s\n", os); 25453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Inode count: %u\n", s->s_inodes_count); 25553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Block count: %u\n", s->s_blocks_count); 25653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Reserved block count: %u\n", s->s_r_blocks_count); 25753d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Free blocks: %u\n", s->s_free_blocks_count); 25853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Free inodes: %u\n", s->s_free_inodes_count); 25953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "First block: %u\n", s->s_first_data_block); 26053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Block size: %u\n", EXT2_BLOCK_SIZE(s)); 26153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Fragment size: %u\n", EXT2_FRAG_SIZE(s)); 26253d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Blocks per group: %u\n", s->s_blocks_per_group); 26353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Fragments per group: %u\n", s->s_frags_per_group); 26453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Inodes per group: %u\n", s->s_inodes_per_group); 26553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Inode blocks per group: %u\n", inode_blocks_per_group); 26621c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o tm = s->s_mtime; 26753d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Last mount time: %s", ctime(&tm)); 26821c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o tm = s->s_wtime; 26953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Last write time: %s", ctime(&tm)); 27053d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Mount count: %u\n", s->s_mnt_count); 27153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Maximum mount count: %d\n", s->s_max_mnt_count); 27221c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o tm = s->s_lastcheck; 27353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Last checked: %s", ctime(&tm)); 27453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Check interval: %u (%s)\n", s->s_checkinterval, 27521c84b71e205b5ab13f14343da5645dcc985856dTheodore Ts'o interval_string(s->s_checkinterval)); 2763839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o if (s->s_checkinterval) 2773839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o { 2783839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o time_t next; 2793839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o 2803839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o next = s->s_lastcheck + s->s_checkinterval; 28153d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Next check after: %s", ctime(&next)); 2823839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o } 28353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Reserved blocks uid: "); 28453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o print_user(s->s_def_resuid, f); 28553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Reserved blocks gid: "); 28653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o print_group(s->s_def_resgid, f); 2877f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o if (s->s_rev_level >= EXT2_DYNAMIC_REV) { 28853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "First inode: %d\n", s->s_first_ino); 28953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Inode size: %d\n", s->s_inode_size); 2907f88b04341d88c5df0360d930832c38040303b61Theodore Ts'o } 29119c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o if (s->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) { 29219c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o if (e2p_is_null_uuid(sb->s_journal_uuid)) { 29319c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o strcpy(buf, "<none>"); 29419c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o } else 29519c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o e2p_uuid_to_str(sb->s_uuid, buf); 29653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Journal UUID: %s\n", buf); 29753d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Journal inode: %u\n", s->s_journal_inum); 29853d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "Journal device: 0x%04x\n", s->s_journal_dev); 29953d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o fprintf(f, "First orphan inode: %u\n", s->s_last_orphan); 30019c689196bcd90510070b50cd08d0e962fe8311cTheodore Ts'o } 3013839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o} 3021e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 30353d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'ovoid list_super (struct ext2_super_block * s) 30453d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o{ 30553d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o list_super2(s, stdout); 30653d3955001593b668b15e2d10b3a191f689f9779Theodore Ts'o} 3071e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o 308