Whamcloud - gitweb
0bd217bcbc9f1fbfbf9b9026403740a620d732de
[tools/e2fsprogs.git] / lib / e2p / ls.c
1 /*
2  * ls.c                 - List the contents of an ext2fs superblock
3  *
4  * Copyright (C) 1992, 1993, 1994  Remy Card <card@masi.ibp.fr>
5  *                                 Laboratoire MASI, Institut Blaise Pascal
6  *                                 Universite Pierre et Marie Curie (Paris VI)
7  *
8  * This file can be redistributed under the terms of the GNU Library General
9  * Public License
10  */
11
12 #include <sys/types.h>
13 #include <grp.h>
14 #include <pwd.h>
15 #include <stdio.h>
16 #include <time.h>
17
18 #include <linux/ext2_fs.h>
19
20 #include "e2p.h"
21
22 static void print_user (unsigned short uid)
23 {
24         struct passwd *pw;
25
26         printf ("%u ", uid);
27         pw = getpwuid (uid);
28         if (pw == NULL)
29                 printf ("(user unknown)\n");
30         else
31                 printf ("(user %s)\n", pw->pw_name);
32 }
33
34 static void print_group (unsigned short gid)
35 {
36         struct group *gr;
37
38         printf ("%u ", gid);
39         gr = getgrgid (gid);
40         if (gr == NULL)
41                 printf ("(group unknown)\n");
42         else
43                 printf ("(group %s)\n", gr->gr_name);
44 }
45
46 #ifndef EXT2_INODE_SIZE
47 #define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
48 #endif
49
50 void list_super (struct ext2_super_block * s)
51 {
52         int inode_blocks_per_group;
53
54         inode_blocks_per_group = (((s->s_inodes_per_group *
55                                     EXT2_INODE_SIZE(s)) +
56                                    EXT2_BLOCK_SIZE(s) - 1) /
57                                   EXT2_BLOCK_SIZE(s));
58         
59         printf ("Filesystem magic number:  0x%04X\n", s->s_magic);
60         printf ("Filesystem revision #:    %d\n", s->s_rev_level);
61         printf ("Filesystem state:        ");
62         print_fs_state (stdout, s->s_state);
63         printf ("\n");
64         printf ("Errors behavior:          ");
65         print_fs_errors (stdout, s->s_errors);
66         printf ("\n");
67         printf ("Inode count:              %u\n", s->s_inodes_count);
68         printf ("Block count:              %u\n", s->s_blocks_count);
69         printf ("Reserved block count:     %u\n", s->s_r_blocks_count);
70         printf ("Free blocks:              %u\n", s->s_free_blocks_count);
71         printf ("Free inodes:              %u\n", s->s_free_inodes_count);
72         printf ("First block:              %u\n", s->s_first_data_block);
73         printf ("Block size:               %u\n", EXT2_BLOCK_SIZE(s));
74         printf ("Fragment size:            %u\n", EXT2_FRAG_SIZE(s));
75         printf ("Blocks per group:         %u\n", s->s_blocks_per_group);
76         printf ("Fragments per group:      %u\n", s->s_frags_per_group);
77         printf ("Inodes per group:         %u\n", s->s_inodes_per_group);
78         printf ("Inode blocks per group:   %u\n", inode_blocks_per_group);
79         printf ("Last mount time:          %s", ctime ((time_t *) &s->s_mtime));
80         printf ("Last write time:          %s", ctime ((time_t *) &s->s_wtime));
81         printf ("Mount count:              %u\n", s->s_mnt_count);
82         printf ("Maximum mount count:      %d\n", s->s_max_mnt_count);
83         printf ("Last checked:             %s", ctime ((time_t *) &s->s_lastcheck));
84         printf ("Check interval:           %u\n", s->s_checkinterval);
85         if (s->s_checkinterval)
86         {
87                 time_t next;
88
89                 next = s->s_lastcheck + s->s_checkinterval;
90                 printf ("Next check after:         %s", ctime (&next));
91         }
92 #ifdef  EXT2_DEF_RESUID
93         printf ("Reserved blocks uid:      ");
94         print_user (s->s_def_resuid);
95         printf ("Reserved blocks gid:      ");
96         print_group (s->s_def_resgid);
97 #endif
98 #ifdef EXT2_DYNAMIC_REV
99         if (s->s_rev_level >= EXT2_DYNAMIC_REV) {
100                 printf("First inode:              %d\n", s->s_first_ino);
101                 printf("Inode size:               %d\n", s->s_inode_size);
102         }
103 #endif
104 }