1 /*
2  * ljs.c			- List the contents of an journal superblock
3  *
4  * Copyright (C) 1995, 1996, 1997  Theodore Ts'o <tytso@mit.edu>
5  *
6  * %Begin-Header%
7  * This file may be redistributed under the terms of the GNU Library
8  * General Public License, version 2.
9  * %End-Header%
10  */
11 
12 
13 #include "config.h"
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/types.h>
17 #include <string.h>
18 #include <grp.h>
19 #include <pwd.h>
20 #include <time.h>
21 
22 #include "ext2fs/ext2_fs.h"
23 #include "ext2fs/ext2fs.h"
24 #include "e2p.h"
25 #include "ext2fs/kernel-jbd.h"
26 
27 #ifdef WORDS_BIGENDIAN
28 #define e2p_be32(x) (x)
29 #else
e2p_swab32(__u32 val)30 static __u32 e2p_swab32(__u32 val)
31 {
32 	return ((val>>24) | ((val>>8)&0xFF00) |
33 		((val<<8)&0xFF0000) | (val<<24));
34 }
35 
36 #define e2p_be32(x) e2p_swab32(x)
37 #endif
38 
journal_checksum_type_str(__u8 type)39 static const char *journal_checksum_type_str(__u8 type)
40 {
41 	switch (type) {
42 	case JBD2_CRC32C_CHKSUM:
43 		return "crc32c";
44 	default:
45 		return "unknown";
46 	}
47 }
48 
e2p_list_journal_super(FILE * f,char * journal_sb_buf,int exp_block_size,int flags)49 void e2p_list_journal_super(FILE *f, char *journal_sb_buf,
50 			    int exp_block_size, int flags)
51 {
52 	journal_superblock_t *jsb = (journal_superblock_t *) journal_sb_buf;
53 	__u32 *mask_ptr, mask, m;
54 	unsigned int size;
55 	int j, printed = 0;
56 	unsigned int i, nr_users;
57 
58 	fprintf(f, "%s", "Journal features:        ");
59 	for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {
60 		mask = e2p_be32(*mask_ptr);
61 		for (j=0,m=1; j < 32; j++, m<<=1) {
62 			if (mask & m) {
63 				fprintf(f, " %s", e2p_jrnl_feature2string(i, m));
64 				printed++;
65 			}
66 		}
67 	}
68 	if (printed == 0)
69 		fprintf(f, " (none)");
70 	fputc('\n', f);
71 	fputs("Journal size:             ", f);
72 	size = (ntohl(jsb->s_blocksize) / 1024) * ntohl(jsb->s_maxlen);
73 	if (size < 8192)
74 		fprintf(f, "%uk\n", size);
75 	else
76 		fprintf(f, "%uM\n", size >> 10);
77 	nr_users = (unsigned int) ntohl(jsb->s_nr_users);
78 	if (exp_block_size != (int) ntohl(jsb->s_blocksize))
79 		fprintf(f, "Journal block size:       %u\n",
80 			(unsigned int)ntohl(jsb->s_blocksize));
81 	fprintf(f, "Journal length:           %u\n",
82 		(unsigned int)ntohl(jsb->s_maxlen));
83 	if (ntohl(jsb->s_first) != 1)
84 		fprintf(f, "Journal first block:      %u\n",
85 			(unsigned int)ntohl(jsb->s_first));
86 	fprintf(f, "Journal sequence:         0x%08x\n"
87 		"Journal start:            %u\n",
88 		(unsigned int)ntohl(jsb->s_sequence),
89 		(unsigned int)ntohl(jsb->s_start));
90 	if (nr_users != 1)
91 		fprintf(f, "Journal number of users:  %u\n", nr_users);
92 	if (jsb->s_feature_compat & e2p_be32(JFS_FEATURE_COMPAT_CHECKSUM))
93 		fprintf(f, "%s", "Journal checksum type:    crc32\n");
94 	if ((jsb->s_feature_incompat &
95 	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
96 	    (jsb->s_feature_incompat &
97 	     e2p_be32(JFS_FEATURE_INCOMPAT_CSUM_V2)))
98 		fprintf(f, "Journal checksum type:    %s\n"
99 			"Journal checksum:         0x%08x\n",
100 			journal_checksum_type_str(jsb->s_checksum_type),
101 			e2p_be32(jsb->s_checksum));
102 	if ((nr_users > 1) ||
103 	    !e2p_is_null_uuid(&jsb->s_users[0])) {
104 		for (i=0; i < nr_users && i < JFS_USERS_MAX; i++) {
105 			printf(i ? "                          %s\n"
106 			       : "Journal users:            %s\n",
107 			       e2p_uuid2str(&jsb->s_users[i * UUID_SIZE]));
108 		}
109 	}
110 	if (jsb->s_errno != 0)
111 		fprintf(f, "Journal errno:            %d\n",
112 			(int) ntohl(jsb->s_errno));
113 }
114