Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * dumpe2fs.c - List the control structures of a second |
| 3 | * extended filesystem |
| 4 | * |
| 5 | * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr> |
| 6 | * Laboratoire MASI, Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | * |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 9 | * Copyright 1995, 1996, 1997 by Theodore Ts'o. |
| 10 | * |
| 11 | * %Begin-Header% |
| 12 | * This file may be redistributed under the terms of the GNU Public |
| 13 | * License. |
| 14 | * %End-Header% |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * History: |
| 19 | * 94/01/09 - Creation |
| 20 | * 94/02/27 - Ported to use the ext2fs library |
| 21 | */ |
| 22 | |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 23 | #ifdef HAVE_GETOPT_H |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 24 | #include <getopt.h> |
Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 25 | #else |
| 26 | extern char *optarg; |
| 27 | extern int optind; |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 28 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 29 | #include <fcntl.h> |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include <unistd.h> |
| 34 | |
Theodore Ts'o | 54c637d | 2001-05-14 11:45:38 +0000 | [diff] [blame] | 35 | #include "ext2fs/ext2_fs.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 36 | |
| 37 | #include "ext2fs/ext2fs.h" |
| 38 | #include "e2p/e2p.h" |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 39 | #include "jfs_user.h" |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 40 | #include <uuid/uuid.h> |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 41 | |
| 42 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 43 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 44 | |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 45 | #define in_use(m, x) (ext2fs_test_bit ((x), (m))) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 46 | |
| 47 | const char * program_name = "dumpe2fs"; |
| 48 | char * device_name = NULL; |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 49 | int hex_format = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 50 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 51 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 52 | { |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 53 | fprintf (stderr, _("Usage: %s [-bfhixV] [-ob superblock] " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 54 | "[-oB blocksize] device\n"), program_name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 55 | exit (1); |
| 56 | } |
| 57 | |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 58 | static void print_number(unsigned long num) |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 59 | { |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 60 | if (hex_format) |
| 61 | printf("0x%04lx", num); |
| 62 | else |
| 63 | printf("%lu", num); |
| 64 | } |
| 65 | |
| 66 | static void print_range(unsigned long a, unsigned long b) |
| 67 | { |
| 68 | if (hex_format) |
| 69 | printf("0x%04lx-0x%04lx", a, b); |
| 70 | else |
| 71 | printf("%lu-%lu", a, b); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 72 | } |
| 73 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 74 | static void print_free (unsigned long group, char * bitmap, |
| 75 | unsigned long nbytes, unsigned long offset) |
| 76 | { |
| 77 | int p = 0; |
| 78 | unsigned long i; |
| 79 | unsigned long j; |
| 80 | |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 81 | offset += group * nbytes; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 82 | for (i = 0; i < nbytes; i++) |
| 83 | if (!in_use (bitmap, i)) |
| 84 | { |
| 85 | if (p) |
| 86 | printf (", "); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 87 | print_number(i + offset); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 88 | for (j = i; j < nbytes && !in_use (bitmap, j); j++) |
| 89 | ; |
| 90 | if (--j != i) { |
| 91 | fputc('-', stdout); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 92 | print_number(j + offset); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 93 | i = j; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 94 | } |
| 95 | p = 1; |
| 96 | } |
| 97 | } |
| 98 | |
Theodore Ts'o | f5fa200 | 2006-05-08 20:17:26 -0400 | [diff] [blame] | 99 | static void print_bg_opt(int bg_flags, int mask, |
| 100 | const char *str, int *first) |
| 101 | { |
| 102 | if (bg_flags & mask) { |
| 103 | if (*first) { |
| 104 | fputs(" [", stdout); |
| 105 | *first = 0; |
| 106 | } else |
| 107 | fputs(", ", stdout); |
| 108 | fputs(str, stdout); |
| 109 | } |
| 110 | } |
| 111 | static void print_bg_opts(ext2_filsys fs, dgrp_t i) |
| 112 | { |
| 113 | int first = 1, bg_flags; |
| 114 | |
| 115 | if (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_LAZY_BG) |
| 116 | bg_flags = fs->group_desc[i].bg_flags; |
| 117 | else |
| 118 | bg_flags = 0; |
| 119 | |
| 120 | print_bg_opt(bg_flags, EXT2_BG_INODE_UNINIT, "Inode not init", |
| 121 | &first); |
| 122 | print_bg_opt(bg_flags, EXT2_BG_BLOCK_UNINIT, "Block not init", |
| 123 | &first); |
| 124 | if (!first) |
| 125 | fputc(']', stdout); |
| 126 | fputc('\n', stdout); |
| 127 | } |
| 128 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 129 | static void list_desc (ext2_filsys fs) |
| 130 | { |
| 131 | unsigned long i; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 132 | long diff; |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 133 | blk_t first_block, last_block; |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 134 | blk_t super_blk, old_desc_blk, new_desc_blk; |
Theodore Ts'o | d90a23e | 2002-10-25 17:07:11 -0400 | [diff] [blame] | 135 | char *block_bitmap=NULL, *inode_bitmap=NULL; |
Theodore Ts'o | 35238dd | 2004-12-23 13:54:28 -0500 | [diff] [blame] | 136 | int inode_blocks_per_group, old_desc_blocks, reserved_gdt; |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 137 | int has_super; |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 138 | |
Theodore Ts'o | d90a23e | 2002-10-25 17:07:11 -0400 | [diff] [blame] | 139 | if (fs->block_map) |
| 140 | block_bitmap = fs->block_map->bitmap; |
| 141 | if (fs->inode_map) |
| 142 | inode_bitmap = fs->inode_map->bitmap; |
| 143 | |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 144 | inode_blocks_per_group = ((fs->super->s_inodes_per_group * |
| 145 | EXT2_INODE_SIZE(fs->super)) + |
| 146 | EXT2_BLOCK_SIZE(fs->super) - 1) / |
| 147 | EXT2_BLOCK_SIZE(fs->super); |
Theodore Ts'o | 35238dd | 2004-12-23 13:54:28 -0500 | [diff] [blame] | 148 | reserved_gdt = fs->super->s_reserved_gdt_blocks; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 149 | fputc('\n', stdout); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 150 | first_block = fs->super->s_first_data_block; |
Theodore Ts'o | 76dd5e5 | 2002-10-30 23:07:21 -0500 | [diff] [blame] | 151 | if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) |
| 152 | old_desc_blocks = fs->super->s_first_meta_bg; |
| 153 | else |
| 154 | old_desc_blocks = fs->desc_blocks; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 155 | for (i = 0; i < fs->group_desc_count; i++) { |
Eric Sandeen | abf2343 | 2006-09-12 14:56:16 -0400 | [diff] [blame^] | 156 | first_block = ext2fs_group_first_block(fs, i); |
| 157 | last_block = ext2fs_group_last_block(fs, i); |
| 158 | |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 159 | ext2fs_super_and_bgd_loc(fs, i, &super_blk, |
| 160 | &old_desc_blk, &new_desc_blk, 0); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 161 | |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 162 | printf (_("Group %lu: (Blocks "), i); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 163 | print_range(first_block, last_block); |
Theodore Ts'o | f5fa200 | 2006-05-08 20:17:26 -0400 | [diff] [blame] | 164 | fputs(")", stdout); |
| 165 | print_bg_opts(fs, i); |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 166 | has_super = ((i==0) || super_blk); |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 167 | if (has_super) { |
| 168 | printf (_(" %s superblock at "), |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 169 | i == 0 ? _("Primary") : _("Backup")); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 170 | print_number(super_blk); |
Theodore Ts'o | c046ac7 | 2002-10-20 00:38:57 -0400 | [diff] [blame] | 171 | } |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 172 | if (old_desc_blk) { |
| 173 | printf(_(", Group descriptors at ")); |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 174 | print_range(old_desc_blk, |
| 175 | old_desc_blk + old_desc_blocks - 1); |
Theodore Ts'o | 35238dd | 2004-12-23 13:54:28 -0500 | [diff] [blame] | 176 | if (reserved_gdt) { |
| 177 | printf(_("\n Reserved GDT blocks at ")); |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 178 | print_range(old_desc_blk + old_desc_blocks, |
| 179 | old_desc_blk + old_desc_blocks + |
| 180 | reserved_gdt - 1); |
Theodore Ts'o | 35238dd | 2004-12-23 13:54:28 -0500 | [diff] [blame] | 181 | } |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 182 | } else if (new_desc_blk) { |
| 183 | fputc(has_super ? ',' : ' ', stdout); |
| 184 | printf(_(" Group descriptor at ")); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 185 | print_number(new_desc_blk); |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 186 | has_super++; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 187 | } |
Theodore Ts'o | ef344e1 | 2003-11-21 09:02:21 -0500 | [diff] [blame] | 188 | if (has_super) |
| 189 | fputc('\n', stdout); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 190 | fputs(_(" Block bitmap at "), stdout); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 191 | print_number(fs->group_desc[i].bg_block_bitmap); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 192 | diff = fs->group_desc[i].bg_block_bitmap - first_block; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 193 | if (diff >= 0) |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 194 | printf(" (+%ld)", diff); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 195 | fputs(_(", Inode bitmap at "), stdout); |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 196 | print_number(fs->group_desc[i].bg_inode_bitmap); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 197 | diff = fs->group_desc[i].bg_inode_bitmap - first_block; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 198 | if (diff >= 0) |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 199 | printf(" (+%ld)", diff); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 200 | fputs(_("\n Inode table at "), stdout); |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 201 | print_range(fs->group_desc[i].bg_inode_table, |
| 202 | fs->group_desc[i].bg_inode_table + |
| 203 | inode_blocks_per_group - 1); |
Eric Sandeen | bb1a46a | 2006-09-12 14:55:22 -0400 | [diff] [blame] | 204 | diff = fs->group_desc[i].bg_inode_table - first_block; |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 205 | if (diff > 0) |
Theodore Ts'o | 4ea7bd0 | 2001-12-16 23:23:37 -0500 | [diff] [blame] | 206 | printf(" (+%ld)", diff); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 207 | printf (_("\n %d free blocks, %d free inodes, " |
Theodore Ts'o | d90a23e | 2002-10-25 17:07:11 -0400 | [diff] [blame] | 208 | "%d directories\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 209 | fs->group_desc[i].bg_free_blocks_count, |
| 210 | fs->group_desc[i].bg_free_inodes_count, |
| 211 | fs->group_desc[i].bg_used_dirs_count); |
Theodore Ts'o | d90a23e | 2002-10-25 17:07:11 -0400 | [diff] [blame] | 212 | if (block_bitmap) { |
| 213 | fputs(_(" Free blocks: "), stdout); |
| 214 | print_free (i, block_bitmap, |
| 215 | fs->super->s_blocks_per_group, |
| 216 | fs->super->s_first_data_block); |
| 217 | fputc('\n', stdout); |
| 218 | block_bitmap += fs->super->s_blocks_per_group / 8; |
| 219 | } |
| 220 | if (inode_bitmap) { |
| 221 | fputs(_(" Free inodes: "), stdout); |
| 222 | print_free (i, inode_bitmap, |
| 223 | fs->super->s_inodes_per_group, 1); |
| 224 | fputc('\n', stdout); |
| 225 | inode_bitmap += fs->super->s_inodes_per_group / 8; |
| 226 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 230 | static void list_bad_blocks(ext2_filsys fs, int dump) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 231 | { |
| 232 | badblocks_list bb_list = 0; |
| 233 | badblocks_iterate bb_iter; |
| 234 | blk_t blk; |
| 235 | errcode_t retval; |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 236 | const char *header, *fmt; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 237 | |
| 238 | retval = ext2fs_read_bb_inode(fs, &bb_list); |
| 239 | if (retval) { |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 240 | com_err("ext2fs_read_bb_inode", retval, 0); |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 241 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 242 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 243 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 244 | if (retval) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 245 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 246 | _("while printing bad block list")); |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 247 | return; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 248 | } |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 249 | if (dump) { |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 250 | header = fmt = "%u\n"; |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 251 | } else { |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 252 | header = _("Bad blocks: %u"); |
| 253 | fmt = ", %u"; |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 254 | } |
| 255 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) { |
| 256 | printf(header ? header : fmt, blk); |
| 257 | header = 0; |
| 258 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 259 | ext2fs_badblocks_list_iterate_end(bb_iter); |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 260 | if (!dump) |
| 261 | fputc('\n', stdout); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 262 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 263 | |
Theodore Ts'o | 6515a6f | 2006-03-29 14:03:07 -0500 | [diff] [blame] | 264 | static void print_inline_journal_information(ext2_filsys fs) |
| 265 | { |
| 266 | struct ext2_inode inode; |
| 267 | errcode_t retval; |
| 268 | ino_t ino = fs->super->s_journal_inum; |
| 269 | int size; |
| 270 | |
| 271 | retval = ext2fs_read_inode(fs, ino, &inode); |
| 272 | if (retval) { |
| 273 | com_err(program_name, retval, |
| 274 | _("while reading journal inode")); |
| 275 | exit(1); |
| 276 | } |
| 277 | fputs(_("Journal size: "), stdout); |
| 278 | size = inode.i_blocks >> 1; |
| 279 | if (size < 8192) |
| 280 | printf("%uk\n", size); |
| 281 | else |
| 282 | printf("%uM\n", size >> 10); |
| 283 | } |
| 284 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 285 | static void print_journal_information(ext2_filsys fs) |
| 286 | { |
| 287 | errcode_t retval; |
| 288 | char buf[1024]; |
| 289 | char str[80]; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 290 | unsigned int i; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 291 | journal_superblock_t *jsb; |
| 292 | |
| 293 | /* Get the journal superblock */ |
Theodore Ts'o | 0208886 | 2001-01-18 01:44:19 +0000 | [diff] [blame] | 294 | if ((retval = io_channel_read_blk(fs->io, fs->super->s_first_data_block+1, -1024, buf))) { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 295 | com_err(program_name, retval, |
| 296 | _("while reading journal superblock")); |
| 297 | exit(1); |
| 298 | } |
| 299 | jsb = (journal_superblock_t *) buf; |
| 300 | if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || |
| 301 | (jsb->s_header.h_blocktype != |
| 302 | (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { |
| 303 | com_err(program_name, 0, |
| 304 | _("Couldn't find journal superblock magic numbers")); |
| 305 | exit(1); |
| 306 | } |
| 307 | |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 308 | printf(_("\nJournal block size: %u\n" |
| 309 | "Journal length: %u\n" |
| 310 | "Journal first block: %u\n" |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 311 | "Journal sequence: 0x%08x\n" |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 312 | "Journal start: %u\n" |
Matthias Andree | f6567a8 | 2006-05-30 16:26:29 +0200 | [diff] [blame] | 313 | "Journal number of users: %u\n"), |
| 314 | (unsigned int)ntohl(jsb->s_blocksize), (unsigned int)ntohl(jsb->s_maxlen), |
| 315 | (unsigned int)ntohl(jsb->s_first), (unsigned int)ntohl(jsb->s_sequence), |
| 316 | (unsigned int)ntohl(jsb->s_start), (unsigned int)ntohl(jsb->s_nr_users)); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 317 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 318 | for (i=0; i < ntohl(jsb->s_nr_users); i++) { |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 319 | uuid_unparse(&jsb->s_users[i*16], str); |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 320 | printf(i ? " %s\n" |
Theodore Ts'o | bb145b0 | 2005-06-20 08:35:27 -0400 | [diff] [blame] | 321 | : _("Journal users: %s\n"), |
Theodore Ts'o | a5f0bb9 | 2001-12-02 19:29:35 +0100 | [diff] [blame] | 322 | str); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Theodore Ts'o | 00e5433 | 1997-09-16 02:13:52 +0000 | [diff] [blame] | 326 | int main (int argc, char ** argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 327 | { |
| 328 | errcode_t retval; |
| 329 | ext2_filsys fs; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 330 | int print_badblocks = 0; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 331 | int use_superblock = 0; |
| 332 | int use_blocksize = 0; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 333 | int image_dump = 0; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 334 | int force = 0; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 335 | int flags; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 336 | int header_only = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 337 | int big_endian; |
Theodore Ts'o | 519149f | 1997-10-25 03:49:49 +0000 | [diff] [blame] | 338 | int c; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 339 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 340 | #ifdef ENABLE_NLS |
| 341 | setlocale(LC_MESSAGES, ""); |
Theodore Ts'o | 14308a5 | 2002-03-05 03:26:52 -0500 | [diff] [blame] | 342 | setlocale(LC_CTYPE, ""); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 343 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 344 | textdomain(NLS_CAT_NAME); |
| 345 | #endif |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 346 | initialize_ext2_error_table(); |
Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame] | 347 | fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION, |
| 348 | E2FSPROGS_DATE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 349 | if (argc && *argv) |
| 350 | program_name = *argv; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 351 | |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 352 | while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 353 | switch (c) { |
| 354 | case 'b': |
| 355 | print_badblocks++; |
| 356 | break; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 357 | case 'f': |
| 358 | force++; |
| 359 | break; |
| 360 | case 'h': |
| 361 | header_only++; |
| 362 | break; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 363 | case 'i': |
| 364 | image_dump++; |
| 365 | break; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 366 | case 'o': |
| 367 | if (optarg[0] == 'b') |
| 368 | use_superblock = atoi(optarg+1); |
| 369 | else if (optarg[0] == 'B') |
| 370 | use_blocksize = atoi(optarg+1); |
| 371 | else |
| 372 | usage(); |
| 373 | break; |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 374 | case 'V': |
| 375 | /* Print version number and exit */ |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 376 | fprintf(stderr, _("\tUsing %s\n"), |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 377 | error_message(EXT2_ET_BASE)); |
| 378 | exit(0); |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 379 | case 'x': |
Theodore Ts'o | 9b9a780 | 2005-12-10 21:50:30 -0500 | [diff] [blame] | 380 | hex_format++; |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 381 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 382 | default: |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 383 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | if (optind > argc - 1) |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 387 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 388 | device_name = argv[optind++]; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 389 | if (use_superblock && !use_blocksize) |
| 390 | use_blocksize = 1024; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 391 | flags = EXT2_FLAG_JOURNAL_DEV_OK; |
| 392 | if (force) |
| 393 | flags |= EXT2_FLAG_FORCE; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 394 | if (image_dump) |
| 395 | flags |= EXT2_FLAG_IMAGE_FILE; |
| 396 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 397 | retval = ext2fs_open (device_name, flags, use_superblock, |
| 398 | use_blocksize, unix_io_manager, &fs); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 399 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 400 | com_err (program_name, retval, _("while trying to open %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 401 | device_name); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 402 | printf (_("Couldn't find valid filesystem superblock.\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 403 | exit (1); |
| 404 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 405 | if (print_badblocks) { |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 406 | list_bad_blocks(fs, 1); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 407 | } else { |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 408 | big_endian = ((fs->flags & EXT2_FLAG_SWAP_BYTES) != 0); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 409 | #ifdef WORDS_BIGENDIAN |
| 410 | big_endian = !big_endian; |
| 411 | #endif |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 412 | if (big_endian) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 413 | printf(_("Note: This is a byte-swapped filesystem\n")); |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 414 | list_super (fs->super); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 415 | if (fs->super->s_feature_incompat & |
| 416 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 417 | print_journal_information(fs); |
| 418 | ext2fs_close(fs); |
| 419 | exit(0); |
| 420 | } |
Theodore Ts'o | 6515a6f | 2006-03-29 14:03:07 -0500 | [diff] [blame] | 421 | if (fs->super->s_feature_compat & |
| 422 | EXT3_FEATURE_COMPAT_HAS_JOURNAL) |
| 423 | print_inline_journal_information(fs); |
Theodore Ts'o | 0655b10 | 2001-12-21 23:59:46 -0500 | [diff] [blame] | 424 | list_bad_blocks(fs, 0); |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 425 | if (header_only) { |
| 426 | ext2fs_close (fs); |
| 427 | exit (0); |
| 428 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 429 | retval = ext2fs_read_bitmaps (fs); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 430 | list_desc (fs); |
Theodore Ts'o | d90a23e | 2002-10-25 17:07:11 -0400 | [diff] [blame] | 431 | if (retval) { |
| 432 | printf(_("\n%s: %s: error reading bitmaps: %s\n"), |
| 433 | program_name, device_name, |
| 434 | error_message(retval)); |
| 435 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 436 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 437 | ext2fs_close (fs); |
| 438 | exit (0); |
| 439 | } |