Whamcloud - gitweb
Many files:
[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 void list_super (struct ext2_super_block * s)
47 {
48         printf ("Filesystem magic number:  0x%04X\n", s->s_magic);
49         printf ("Filesystem state:        ");
50         print_fs_state (stdout, s->s_state);
51         printf ("\n");
52         printf ("Errors behavior:          ");
53         print_fs_errors (stdout, s->s_errors);
54         printf ("\n");
55         printf ("Inode count:              %u\n", s->s_inodes_count);
56         printf ("Block count:              %u\n", s->s_blocks_count);
57         printf ("Reserved block count:     %u\n", s->s_r_blocks_count);
58         printf ("Free blocks:              %u\n", s->s_free_blocks_count);
59         printf ("Free inodes:              %u\n", s->s_free_inodes_count);
60         printf ("First block:              %u\n", s->s_first_data_block);
61         printf ("Block size:               %u\n", EXT2_BLOCK_SIZE(s));
62         printf ("Fragment size:            %u\n", EXT2_FRAG_SIZE(s));
63         printf ("Blocks per group:         %u\n", s->s_blocks_per_group);
64         printf ("Fragments per group:      %u\n", s->s_frags_per_group);
65         printf ("Inodes per group:         %u\n", s->s_inodes_per_group);
66         printf ("Last mount time:          %s", ctime ((time_t *) &s->s_mtime));
67         printf ("Last write time:          %s", ctime ((time_t *) &s->s_wtime));
68         printf ("Mount count:              %u\n", s->s_mnt_count);
69         printf ("Maximum mount count:      %d\n", s->s_max_mnt_count);
70         printf ("Last checked:             %s", ctime ((time_t *) &s->s_lastcheck));
71         printf ("Check interval:           %u\n", s->s_checkinterval);
72         if (s->s_checkinterval)
73         {
74                 time_t next;
75
76                 next = s->s_lastcheck + s->s_checkinterval;
77                 printf ("Next check after:         %s", ctime (&next));
78         }
79 #ifdef  EXT2_DEF_RESUID
80         printf ("Reserved blocks uid:      ");
81         print_user (s->s_def_resuid);
82         printf ("Reserved blocks gid:      ");
83         print_group (s->s_def_resuid);
84 #endif
85 }