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
39 /*
40 * This function is copied from kernel-jbd.h's function
41 * jbd2_journal_get_num_fc_blks() to avoid inter-library dependencies.
42 */
get_num_fc_blks(journal_superblock_t * jsb)43 static inline int get_num_fc_blks(journal_superblock_t *jsb)
44 {
45 int num_fc_blocks = e2p_be32(jsb->s_num_fc_blks);
46
47 return num_fc_blocks ? num_fc_blocks : JBD2_DEFAULT_FAST_COMMIT_BLOCKS;
48 }
49
journal_checksum_type_str(__u8 type)50 static const char *journal_checksum_type_str(__u8 type)
51 {
52 switch (type) {
53 case JBD2_CRC32C_CHKSUM:
54 return "crc32c";
55 default:
56 return "unknown";
57 }
58 }
59
e2p_list_journal_super(FILE * f,char * journal_sb_buf,int exp_block_size,int flags)60 void e2p_list_journal_super(FILE *f, char *journal_sb_buf,
61 int exp_block_size, int flags)
62 {
63 journal_superblock_t *jsb = (journal_superblock_t *) journal_sb_buf;
64 __u32 *mask_ptr, mask, m;
65 unsigned int size;
66 int j, printed = 0;
67 unsigned int i, nr_users;
68 int num_fc_blks = 0;
69 int journal_blks = 0;
70
71 if (flags & E2P_LIST_JOURNAL_FLAG_FC)
72 num_fc_blks = get_num_fc_blks((journal_superblock_t *)journal_sb_buf);
73 journal_blks = ntohl(jsb->s_maxlen) - num_fc_blks;
74 fprintf(f, "%s", "Journal features: ");
75 for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {
76 mask = e2p_be32(*mask_ptr);
77 for (j=0,m=1; j < 32; j++, m<<=1) {
78 if (mask & m) {
79 fprintf(f, " %s", e2p_jrnl_feature2string(i, m));
80 printed++;
81 }
82 }
83 }
84 if (printed == 0)
85 fprintf(f, " (none)");
86 fputc('\n', f);
87 fputs("Total journal size: ", f);
88 size = (ntohl(jsb->s_blocksize) / 1024) * ntohl(jsb->s_maxlen);
89 if (size < 8192)
90 fprintf(f, "%uk\n", size);
91 else
92 fprintf(f, "%uM\n", size >> 10);
93 nr_users = (unsigned int) ntohl(jsb->s_nr_users);
94 if (exp_block_size != (int) ntohl(jsb->s_blocksize))
95 fprintf(f, "Journal block size: %u\n",
96 (unsigned int)ntohl(jsb->s_blocksize));
97 fprintf(f, "Total journal blocks: %u\n",
98 (unsigned int)(journal_blks + num_fc_blks));
99 fprintf(f, "Max transaction length: %u\n",
100 (unsigned int)journal_blks);
101 fprintf(f, "Fast commit length: %u\n",
102 (unsigned int)num_fc_blks);
103
104 if (ntohl(jsb->s_first) != 1)
105 fprintf(f, "Journal first block: %u\n",
106 (unsigned int)ntohl(jsb->s_first));
107 fprintf(f, "Journal sequence: 0x%08x\n"
108 "Journal start: %u\n",
109 (unsigned int)ntohl(jsb->s_sequence),
110 (unsigned int)ntohl(jsb->s_start));
111 if (nr_users != 1)
112 fprintf(f, "Journal number of users: %u\n", nr_users);
113 if (jsb->s_feature_compat & e2p_be32(JBD2_FEATURE_COMPAT_CHECKSUM))
114 fprintf(f, "%s", "Journal checksum type: crc32\n");
115 if ((jsb->s_feature_incompat &
116 e2p_be32(JBD2_FEATURE_INCOMPAT_CSUM_V3)) ||
117 (jsb->s_feature_incompat &
118 e2p_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2)))
119 fprintf(f, "Journal checksum type: %s\n"
120 "Journal checksum: 0x%08x\n",
121 journal_checksum_type_str(jsb->s_checksum_type),
122 e2p_be32(jsb->s_checksum));
123 if ((nr_users > 1) ||
124 !e2p_is_null_uuid(&jsb->s_users[0])) {
125 for (i=0; i < nr_users && i < JBD2_USERS_MAX; i++) {
126 printf(i ? " %s\n"
127 : "Journal users: %s\n",
128 e2p_uuid2str(&jsb->s_users[i * UUID_SIZE]));
129 }
130 }
131 if (jsb->s_errno != 0)
132 fprintf(f, "Journal errno: %d\n",
133 (int) ntohl(jsb->s_errno));
134 }
135