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