ls.c revision 50e1e10fa0ac12a3e2a9d20a75ee9041873cda96
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 *
83839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * This file can be redistributed under the terms of the GNU Library General
93839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o * Public License
103839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o */
113839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
1250e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o#include <sys/types.h>
13f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#include <grp.h>
14f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#include <pwd.h>
153839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include <stdio.h>
163839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include <time.h>
173839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
183839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include <linux/ext2_fs.h>
193839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
203839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o#include "e2p.h"
213839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
22f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'ostatic void print_user (unsigned short uid)
23f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
24f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	struct passwd *pw;
25f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
26f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	printf ("%u ", uid);
27f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	pw = getpwuid (uid);
28f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	if (pw == NULL)
29f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o		printf ("(user unknown)\n");
30f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	else
31f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o		printf ("(user %s)\n", pw->pw_name);
32f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
33f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
34f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'ostatic void print_group (unsigned short gid)
35f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o{
36f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	struct group *gr;
37f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
38f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	printf ("%u ", gid);
39f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	gr = getgrgid (gid);
40f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	if (gr == NULL)
41f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o		printf ("(group unknown)\n");
42f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	else
43f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o		printf ("(group %s)\n", gr->gr_name);
44f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o}
45f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o
463839e65723771b85975f4263102dd3ceec4523cTheodore Ts'ovoid list_super (struct ext2_super_block * s)
473839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o{
483839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Filesystem magic number:  0x%04X\n", s->s_magic);
493839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Filesystem state:        ");
503839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	print_fs_state (stdout, s->s_state);
513839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("\n");
523839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Errors behavior:          ");
533839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	print_fs_errors (stdout, s->s_errors);
543839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("\n");
5550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Inode count:              %u\n", s->s_inodes_count);
5650e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Block count:              %u\n", s->s_blocks_count);
5750e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Reserved block count:     %u\n", s->s_r_blocks_count);
5850e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Free blocks:              %u\n", s->s_free_blocks_count);
5950e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Free inodes:              %u\n", s->s_free_inodes_count);
6050e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("First block:              %u\n", s->s_first_data_block);
613839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Block size:               %u\n", EXT2_BLOCK_SIZE(s));
623839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Fragment size:            %u\n", EXT2_FRAG_SIZE(s));
6350e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Blocks per group:         %u\n", s->s_blocks_per_group);
6450e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Fragments per group:      %u\n", s->s_frags_per_group);
6550e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Inodes per group:         %u\n", s->s_inodes_per_group);
663839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Last mount time:          %s", ctime ((time_t *) &s->s_mtime));
673839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Last write time:          %s", ctime ((time_t *) &s->s_wtime));
683839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Mount count:              %u\n", s->s_mnt_count);
693839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Maximum mount count:      %d\n", s->s_max_mnt_count);
703839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	printf ("Last checked:             %s", ctime ((time_t *) &s->s_lastcheck));
7150e1e10fa0ac12a3e2a9d20a75ee9041873cda96Theodore Ts'o	printf ("Check interval:           %u\n", s->s_checkinterval);
723839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	if (s->s_checkinterval)
733839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	{
743839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		time_t next;
753839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o
763839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		next = s->s_lastcheck + s->s_checkinterval;
773839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o		printf ("Next check after:         %s", ctime (&next));
783839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o	}
79f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#ifdef	EXT2_DEF_RESUID
80f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	printf ("Reserved blocks uid:      ");
81f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	print_user (s->s_def_resuid);
82f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	printf ("Reserved blocks gid:      ");
83f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o	print_group (s->s_def_resuid);
84f3db3566b5e1342e49dffc5ec3f418a838584194Theodore Ts'o#endif
853839e65723771b85975f4263102dd3ceec4523cTheodore Ts'o}
86