]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
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 | * | |
19c78dc0 TT |
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% | |
3839e657 TT |
15 | */ |
16 | ||
17 | /* | |
18 | * History: | |
19 | * 94/01/09 - Creation | |
20 | * 94/02/27 - Ported to use the ext2fs library | |
21 | */ | |
22 | ||
d1154eb4 | 23 | #include "config.h" |
a418d3ad | 24 | #ifdef HAVE_GETOPT_H |
3839e657 | 25 | #include <getopt.h> |
373b8337 TT |
26 | #else |
27 | extern char *optarg; | |
28 | extern int optind; | |
a418d3ad | 29 | #endif |
3839e657 TT |
30 | #include <fcntl.h> |
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | #include <string.h> | |
34 | #include <unistd.h> | |
35 | ||
54c637d4 | 36 | #include "ext2fs/ext2_fs.h" |
3839e657 TT |
37 | |
38 | #include "ext2fs/ext2fs.h" | |
39 | #include "e2p/e2p.h" | |
16ed5b3a | 40 | #include "jfs_user.h" |
4ea7bd04 | 41 | #include <uuid/uuid.h> |
3839e657 TT |
42 | |
43 | #include "../version.h" | |
d9c56d3c | 44 | #include "nls-enable.h" |
3839e657 | 45 | |
74becf3c | 46 | #define in_use(m, x) (ext2fs_test_bit ((x), (m))) |
3839e657 TT |
47 | |
48 | const char * program_name = "dumpe2fs"; | |
49 | char * device_name = NULL; | |
9b9a780f | 50 | int hex_format = 0; |
ce10c313 | 51 | int blocks64 = 0; |
3839e657 | 52 | |
818180cd | 53 | static void usage(void) |
3839e657 | 54 | { |
77f464fb TT |
55 | fprintf (stderr, _("Usage: %s [-bfhixV] [-o superblock=<num>] " |
56 | "[-o blocksize=<num>] device\n"), program_name); | |
3839e657 TT |
57 | exit (1); |
58 | } | |
59 | ||
ce10c313 | 60 | static void print_number(unsigned long long num) |
54434927 | 61 | { |
ce10c313 TT |
62 | if (hex_format) { |
63 | if (blocks64) | |
64 | printf("0x%08llx", num); | |
65 | else | |
66 | printf("0x%04llx", num); | |
67 | } else | |
68 | printf("%llu", num); | |
9b9a780f TT |
69 | } |
70 | ||
295c3e03 | 71 | static void print_range(unsigned long long a, unsigned long long b) |
9b9a780f | 72 | { |
ce10c313 TT |
73 | if (hex_format) { |
74 | if (blocks64) | |
75 | printf("0x%08llx-0x%08llx", a, b); | |
76 | else | |
77 | printf("0x%04llx-0x%04llx", a, b); | |
78 | } else | |
295c3e03 | 79 | printf("%llu-%llu", a, b); |
54434927 TT |
80 | } |
81 | ||
bcb942c2 TT |
82 | static void print_free(unsigned long group, char * bitmap, |
83 | unsigned long num, unsigned long offset, int ratio) | |
3839e657 TT |
84 | { |
85 | int p = 0; | |
86 | unsigned long i; | |
87 | unsigned long j; | |
88 | ||
bcb942c2 TT |
89 | offset /= ratio; |
90 | offset += group * num; | |
91 | for (i = 0; i < num; i++) | |
3839e657 TT |
92 | if (!in_use (bitmap, i)) |
93 | { | |
94 | if (p) | |
95 | printf (", "); | |
bcb942c2 TT |
96 | print_number((i + offset) * ratio); |
97 | for (j = i; j < num && !in_use (bitmap, j); j++) | |
a5f0bb9d TT |
98 | ; |
99 | if (--j != i) { | |
100 | fputc('-', stdout); | |
bcb942c2 | 101 | print_number((j + offset) * ratio); |
a5f0bb9d | 102 | i = j; |
3839e657 TT |
103 | } |
104 | p = 1; | |
105 | } | |
106 | } | |
107 | ||
f5fa2007 TT |
108 | static void print_bg_opt(int bg_flags, int mask, |
109 | const char *str, int *first) | |
110 | { | |
111 | if (bg_flags & mask) { | |
112 | if (*first) { | |
113 | fputs(" [", stdout); | |
114 | *first = 0; | |
115 | } else | |
116 | fputs(", ", stdout); | |
117 | fputs(str, stdout); | |
118 | } | |
119 | } | |
120 | static void print_bg_opts(ext2_filsys fs, dgrp_t i) | |
121 | { | |
16b851cd | 122 | int first = 1, bg_flags = 0; |
f5fa2007 | 123 | |
16b851cd | 124 | if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) |
732c8cd5 | 125 | bg_flags = ext2fs_bg_flags(fs, i); |
f5fa2007 | 126 | |
b89fc30d | 127 | print_bg_opt(bg_flags, EXT2_BG_INODE_UNINIT, "INODE_UNINIT", |
f5fa2007 | 128 | &first); |
b89fc30d TT |
129 | print_bg_opt(bg_flags, EXT2_BG_BLOCK_UNINIT, "BLOCK_UNINIT", |
130 | &first); | |
131 | print_bg_opt(bg_flags, EXT2_BG_INODE_ZEROED, "ITABLE_ZEROED", | |
f5fa2007 TT |
132 | &first); |
133 | if (!first) | |
134 | fputc(']', stdout); | |
135 | fputc('\n', stdout); | |
136 | } | |
137 | ||
0e2afdba AD |
138 | static void print_bg_rel_offset(ext2_filsys fs, blk64_t block, int itable, |
139 | blk64_t first_block, blk64_t last_block) | |
140 | { | |
141 | if ((block >= first_block) && (block <= last_block)) { | |
142 | if (itable && block == first_block) | |
143 | return; | |
144 | printf(" (+%u)", (unsigned)(block - first_block)); | |
145 | } else if (fs->super->s_feature_incompat & | |
146 | EXT4_FEATURE_INCOMPAT_FLEX_BG) { | |
4dbfd79d | 147 | dgrp_t flex_grp = ext2fs_group_of_blk2(fs, block); |
0e2afdba | 148 | printf(" (bg #%u + %u)", flex_grp, |
26da6614 | 149 | (unsigned)(block-ext2fs_group_first_block2(fs,flex_grp))); |
0e2afdba AD |
150 | } |
151 | } | |
152 | ||
3839e657 TT |
153 | static void list_desc (ext2_filsys fs) |
154 | { | |
155 | unsigned long i; | |
295c3e03 TT |
156 | blk64_t first_block, last_block; |
157 | blk64_t super_blk, old_desc_blk, new_desc_blk; | |
d90a23e2 | 158 | char *block_bitmap=NULL, *inode_bitmap=NULL; |
2418dfd7 | 159 | const char *units = _("blocks"); |
35238dd1 | 160 | int inode_blocks_per_group, old_desc_blocks, reserved_gdt; |
f1f115a7 | 161 | int block_nbytes, inode_nbytes; |
ef344e13 | 162 | int has_super; |
6a6337c3 | 163 | blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); |
f1f115a7 TT |
164 | ext2_ino_t ino_itr = 1; |
165 | ||
2418dfd7 TT |
166 | if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, |
167 | EXT4_FEATURE_RO_COMPAT_BIGALLOC)) | |
168 | units = _("clusters"); | |
169 | ||
bcb942c2 | 170 | block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; |
f1f115a7 | 171 | inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; |
80c22c90 | 172 | |
d90a23e2 | 173 | if (fs->block_map) |
f1f115a7 | 174 | block_bitmap = malloc(block_nbytes); |
d90a23e2 | 175 | if (fs->inode_map) |
f1f115a7 | 176 | inode_bitmap = malloc(inode_nbytes); |
d90a23e2 | 177 | |
80c22c90 TT |
178 | inode_blocks_per_group = ((fs->super->s_inodes_per_group * |
179 | EXT2_INODE_SIZE(fs->super)) + | |
180 | EXT2_BLOCK_SIZE(fs->super) - 1) / | |
181 | EXT2_BLOCK_SIZE(fs->super); | |
35238dd1 | 182 | reserved_gdt = fs->super->s_reserved_gdt_blocks; |
a5f0bb9d | 183 | fputc('\n', stdout); |
bb1a46a4 | 184 | first_block = fs->super->s_first_data_block; |
76dd5e5c TT |
185 | if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) |
186 | old_desc_blocks = fs->super->s_first_meta_bg; | |
187 | else | |
188 | old_desc_blocks = fs->desc_blocks; | |
521e3685 | 189 | for (i = 0; i < fs->group_desc_count; i++) { |
b49f78fe TT |
190 | first_block = ext2fs_group_first_block2(fs, i); |
191 | last_block = ext2fs_group_last_block2(fs, i); | |
abf23439 | 192 | |
295c3e03 TT |
193 | ext2fs_super_and_bgd_loc2(fs, i, &super_blk, |
194 | &old_desc_blk, &new_desc_blk, 0); | |
bb1a46a4 | 195 | |
a5f0bb9d | 196 | printf (_("Group %lu: (Blocks "), i); |
bb1a46a4 | 197 | print_range(first_block, last_block); |
f5fa2007 TT |
198 | fputs(")", stdout); |
199 | print_bg_opts(fs, i); | |
87141781 TT |
200 | if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { |
201 | unsigned csum = ext2fs_bg_checksum(fs, i); | |
202 | unsigned exp_csum = ext2fs_group_desc_csum(fs, i); | |
203 | ||
204 | printf(_(" Checksum 0x%04x"), csum); | |
205 | if (csum != exp_csum) | |
206 | printf(_(" (EXPECTED 0x%04x)"), exp_csum); | |
207 | printf(_(", unused inodes %u\n"), | |
d7cca6b0 | 208 | ext2fs_bg_itable_unused(fs, i)); |
87141781 | 209 | } |
ef344e13 | 210 | has_super = ((i==0) || super_blk); |
c046ac7f TT |
211 | if (has_super) { |
212 | printf (_(" %s superblock at "), | |
a5f0bb9d | 213 | i == 0 ? _("Primary") : _("Backup")); |
54434927 | 214 | print_number(super_blk); |
c046ac7f | 215 | } |
ef344e13 TT |
216 | if (old_desc_blk) { |
217 | printf(_(", Group descriptors at ")); | |
efc6f628 | 218 | print_range(old_desc_blk, |
9b9a780f | 219 | old_desc_blk + old_desc_blocks - 1); |
35238dd1 TT |
220 | if (reserved_gdt) { |
221 | printf(_("\n Reserved GDT blocks at ")); | |
9b9a780f | 222 | print_range(old_desc_blk + old_desc_blocks, |
efc6f628 | 223 | old_desc_blk + old_desc_blocks + |
9b9a780f | 224 | reserved_gdt - 1); |
35238dd1 | 225 | } |
ef344e13 TT |
226 | } else if (new_desc_blk) { |
227 | fputc(has_super ? ',' : ' ', stdout); | |
228 | printf(_(" Group descriptor at ")); | |
54434927 | 229 | print_number(new_desc_blk); |
ef344e13 | 230 | has_super++; |
a5f0bb9d | 231 | } |
ef344e13 TT |
232 | if (has_super) |
233 | fputc('\n', stdout); | |
a5f0bb9d | 234 | fputs(_(" Block bitmap at "), stdout); |
d7cca6b0 | 235 | print_number(ext2fs_block_bitmap_loc(fs, i)); |
0358c9f9 | 236 | print_bg_rel_offset(fs, ext2fs_block_bitmap_loc(fs, i), 0, |
0e2afdba | 237 | first_block, last_block); |
a5f0bb9d | 238 | fputs(_(", Inode bitmap at "), stdout); |
d7cca6b0 | 239 | print_number(ext2fs_inode_bitmap_loc(fs, i)); |
0358c9f9 | 240 | print_bg_rel_offset(fs, ext2fs_inode_bitmap_loc(fs, i), 0, |
0e2afdba | 241 | first_block, last_block); |
a5f0bb9d | 242 | fputs(_("\n Inode table at "), stdout); |
d7cca6b0 VAH |
243 | print_range(ext2fs_inode_table_loc(fs, i), |
244 | ext2fs_inode_table_loc(fs, i) + | |
9b9a780f | 245 | inode_blocks_per_group - 1); |
0358c9f9 | 246 | print_bg_rel_offset(fs, ext2fs_inode_table_loc(fs, i), 1, |
0e2afdba | 247 | first_block, last_block); |
2418dfd7 | 248 | printf (_("\n %u free %s, %u free inodes, " |
777a8c1b | 249 | "%u directories%s"), |
2418dfd7 | 250 | ext2fs_bg_free_blocks_count(fs, i), units, |
d7cca6b0 VAH |
251 | ext2fs_bg_free_inodes_count(fs, i), |
252 | ext2fs_bg_used_dirs_count(fs, i), | |
253 | ext2fs_bg_itable_unused(fs, i) ? "" : "\n"); | |
254 | if (ext2fs_bg_itable_unused(fs, i)) | |
777a8c1b | 255 | printf (_(", %u unused inodes\n"), |
d7cca6b0 | 256 | ext2fs_bg_itable_unused(fs, i)); |
d90a23e2 TT |
257 | if (block_bitmap) { |
258 | fputs(_(" Free blocks: "), stdout); | |
3c041a51 | 259 | ext2fs_get_block_bitmap_range2(fs->block_map, |
f1f115a7 | 260 | blk_itr, block_nbytes << 3, block_bitmap); |
bcb942c2 TT |
261 | print_free(i, block_bitmap, |
262 | fs->super->s_clusters_per_group, | |
263 | fs->super->s_first_data_block, | |
264 | EXT2FS_CLUSTER_RATIO(fs)); | |
d90a23e2 | 265 | fputc('\n', stdout); |
bcb942c2 | 266 | blk_itr += fs->super->s_clusters_per_group; |
d90a23e2 TT |
267 | } |
268 | if (inode_bitmap) { | |
269 | fputs(_(" Free inodes: "), stdout); | |
3c041a51 | 270 | ext2fs_get_inode_bitmap_range2(fs->inode_map, |
f1f115a7 | 271 | ino_itr, inode_nbytes << 3, inode_bitmap); |
bcb942c2 TT |
272 | print_free(i, inode_bitmap, |
273 | fs->super->s_inodes_per_group, 1, 1); | |
d90a23e2 | 274 | fputc('\n', stdout); |
f1f115a7 | 275 | ino_itr += fs->super->s_inodes_per_group; |
d90a23e2 | 276 | } |
3839e657 | 277 | } |
1acde2b2 TT |
278 | if (block_bitmap) |
279 | free(block_bitmap); | |
280 | if (inode_bitmap) | |
281 | free(inode_bitmap); | |
3839e657 TT |
282 | } |
283 | ||
0655b104 | 284 | static void list_bad_blocks(ext2_filsys fs, int dump) |
3839e657 TT |
285 | { |
286 | badblocks_list bb_list = 0; | |
287 | badblocks_iterate bb_iter; | |
288 | blk_t blk; | |
289 | errcode_t retval; | |
0655b104 | 290 | const char *header, *fmt; |
3839e657 TT |
291 | |
292 | retval = ext2fs_read_bb_inode(fs, &bb_list); | |
293 | if (retval) { | |
9b9a780f | 294 | com_err("ext2fs_read_bb_inode", retval, 0); |
0655b104 | 295 | return; |
3839e657 | 296 | } |
cbbf031b | 297 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
3839e657 | 298 | if (retval) { |
cbbf031b | 299 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
d9c56d3c | 300 | _("while printing bad block list")); |
0655b104 | 301 | return; |
3839e657 | 302 | } |
0655b104 | 303 | if (dump) { |
d0ff90d5 | 304 | header = fmt = "%u\n"; |
0655b104 | 305 | } else { |
d0ff90d5 ES |
306 | header = _("Bad blocks: %u"); |
307 | fmt = ", %u"; | |
f3db3566 | 308 | } |
0655b104 TT |
309 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) { |
310 | printf(header ? header : fmt, blk); | |
311 | header = 0; | |
f3db3566 | 312 | } |
cbbf031b | 313 | ext2fs_badblocks_list_iterate_end(bb_iter); |
0655b104 TT |
314 | if (!dump) |
315 | fputc('\n', stdout); | |
1acde2b2 | 316 | ext2fs_badblocks_list_free(bb_list); |
1e3472c5 | 317 | } |
f3db3566 | 318 | |
6515a6f1 TT |
319 | static void print_inline_journal_information(ext2_filsys fs) |
320 | { | |
1d9b8183 | 321 | journal_superblock_t *jsb; |
6515a6f1 | 322 | struct ext2_inode inode; |
1d9b8183 | 323 | ext2_file_t journal_file; |
6515a6f1 TT |
324 | errcode_t retval; |
325 | ino_t ino = fs->super->s_journal_inum; | |
1d9b8183 TT |
326 | char buf[1024]; |
327 | __u32 *mask_ptr, mask, m; | |
328 | int i, j, size, printed = 0; | |
efc6f628 | 329 | |
6515a6f1 TT |
330 | retval = ext2fs_read_inode(fs, ino, &inode); |
331 | if (retval) { | |
332 | com_err(program_name, retval, | |
333 | _("while reading journal inode")); | |
334 | exit(1); | |
335 | } | |
1d9b8183 TT |
336 | retval = ext2fs_file_open2(fs, ino, &inode, 0, &journal_file); |
337 | if (retval) { | |
338 | com_err(program_name, retval, | |
339 | _("while opening journal inode")); | |
340 | exit(1); | |
341 | } | |
342 | retval = ext2fs_file_read(journal_file, buf, sizeof(buf), 0); | |
343 | if (retval) { | |
344 | com_err(program_name, retval, | |
345 | _("while reading journal super block")); | |
346 | exit(1); | |
347 | } | |
348 | ext2fs_file_close(journal_file); | |
349 | jsb = (journal_superblock_t *) buf; | |
350 | if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) { | |
351 | fprintf(stderr, | |
352 | "Journal superblock magic number invalid!\n"); | |
353 | exit(1); | |
354 | } | |
355 | printf(_("Journal features: ")); | |
356 | for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) { | |
357 | mask = be32_to_cpu(*mask_ptr); | |
358 | for (j=0,m=1; j < 32; j++, m<<=1) { | |
359 | if (mask & m) { | |
360 | printf(" %s", e2p_jrnl_feature2string(i, m)); | |
361 | printed++; | |
362 | } | |
363 | } | |
364 | } | |
365 | if (printed == 0) | |
366 | printf(" (none)"); | |
367 | printf("\n"); | |
6515a6f1 | 368 | fputs(_("Journal size: "), stdout); |
1ca1059f TT |
369 | if ((fs->super->s_feature_ro_compat & |
370 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE) && | |
371 | (inode.i_flags & EXT4_HUGE_FILE_FL)) | |
372 | size = inode.i_blocks / (fs->blocksize / 1024); | |
373 | else | |
374 | size = inode.i_blocks >> 1; | |
6515a6f1 TT |
375 | if (size < 8192) |
376 | printf("%uk\n", size); | |
377 | else | |
378 | printf("%uM\n", size >> 10); | |
1d9b8183 TT |
379 | printf(_("Journal length: %u\n" |
380 | "Journal sequence: 0x%08x\n" | |
381 | "Journal start: %u\n"), | |
382 | (unsigned int)ntohl(jsb->s_maxlen), | |
383 | (unsigned int)ntohl(jsb->s_sequence), | |
384 | (unsigned int)ntohl(jsb->s_start)); | |
9906409e TT |
385 | if (jsb->s_errno != 0) |
386 | printf(_("Journal errno: %d\n"), | |
387 | (int) ntohl(jsb->s_errno)); | |
6515a6f1 TT |
388 | } |
389 | ||
16ed5b3a TT |
390 | static void print_journal_information(ext2_filsys fs) |
391 | { | |
392 | errcode_t retval; | |
393 | char buf[1024]; | |
394 | char str[80]; | |
54434927 | 395 | unsigned int i; |
16ed5b3a TT |
396 | journal_superblock_t *jsb; |
397 | ||
398 | /* Get the journal superblock */ | |
24a117ab | 399 | if ((retval = io_channel_read_blk64(fs->io, fs->super->s_first_data_block+1, -1024, buf))) { |
16ed5b3a TT |
400 | com_err(program_name, retval, |
401 | _("while reading journal superblock")); | |
402 | exit(1); | |
403 | } | |
404 | jsb = (journal_superblock_t *) buf; | |
405 | if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || | |
406 | (jsb->s_header.h_blocktype != | |
407 | (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { | |
408 | com_err(program_name, 0, | |
409 | _("Couldn't find journal superblock magic numbers")); | |
410 | exit(1); | |
411 | } | |
412 | ||
8deb80a5 TS |
413 | printf(_("\nJournal block size: %u\n" |
414 | "Journal length: %u\n" | |
415 | "Journal first block: %u\n" | |
a5f0bb9d | 416 | "Journal sequence: 0x%08x\n" |
8deb80a5 | 417 | "Journal start: %u\n" |
f6567a88 MA |
418 | "Journal number of users: %u\n"), |
419 | (unsigned int)ntohl(jsb->s_blocksize), (unsigned int)ntohl(jsb->s_maxlen), | |
420 | (unsigned int)ntohl(jsb->s_first), (unsigned int)ntohl(jsb->s_sequence), | |
421 | (unsigned int)ntohl(jsb->s_start), (unsigned int)ntohl(jsb->s_nr_users)); | |
a5f0bb9d | 422 | |
16ed5b3a | 423 | for (i=0; i < ntohl(jsb->s_nr_users); i++) { |
16ed5b3a | 424 | uuid_unparse(&jsb->s_users[i*16], str); |
a5f0bb9d | 425 | printf(i ? " %s\n" |
bb145b01 | 426 | : _("Journal users: %s\n"), |
a5f0bb9d | 427 | str); |
16ed5b3a TT |
428 | } |
429 | } | |
430 | ||
295c3e03 | 431 | static void parse_extended_opts(const char *opts, blk64_t *superblock, |
db197a81 TT |
432 | int *blocksize) |
433 | { | |
2d328bb7 | 434 | char *buf, *token, *next, *p, *arg, *badopt = 0; |
db197a81 | 435 | int len; |
2d328bb7 | 436 | int do_usage = 0; |
db197a81 TT |
437 | |
438 | len = strlen(opts); | |
439 | buf = malloc(len+1); | |
440 | if (!buf) { | |
441 | fprintf(stderr, | |
442 | _("Couldn't allocate memory to parse options!\n")); | |
443 | exit(1); | |
444 | } | |
445 | strcpy(buf, opts); | |
446 | for (token = buf; token && *token; token = next) { | |
447 | p = strchr(token, ','); | |
448 | next = 0; | |
449 | if (p) { | |
450 | *p = 0; | |
451 | next = p+1; | |
452 | } | |
453 | arg = strchr(token, '='); | |
454 | if (arg) { | |
455 | *arg = 0; | |
456 | arg++; | |
457 | } | |
458 | if (strcmp(token, "superblock") == 0 || | |
459 | strcmp(token, "sb") == 0) { | |
460 | if (!arg) { | |
2d328bb7 | 461 | do_usage++; |
db197a81 TT |
462 | badopt = token; |
463 | continue; | |
464 | } | |
465 | *superblock = strtoul(arg, &p, 0); | |
466 | if (*p) { | |
467 | fprintf(stderr, | |
468 | _("Invalid superblock parameter: %s\n"), | |
469 | arg); | |
2d328bb7 | 470 | do_usage++; |
db197a81 TT |
471 | continue; |
472 | } | |
473 | } else if (strcmp(token, "blocksize") == 0 || | |
474 | strcmp(token, "bs") == 0) { | |
475 | if (!arg) { | |
2d328bb7 | 476 | do_usage++; |
db197a81 TT |
477 | badopt = token; |
478 | continue; | |
479 | } | |
480 | *blocksize = strtoul(arg, &p, 0); | |
481 | if (*p) { | |
482 | fprintf(stderr, | |
483 | _("Invalid blocksize parameter: %s\n"), | |
484 | arg); | |
2d328bb7 | 485 | do_usage++; |
db197a81 TT |
486 | continue; |
487 | } | |
488 | } else { | |
2d328bb7 | 489 | do_usage++; |
db197a81 TT |
490 | badopt = token; |
491 | } | |
492 | } | |
2d328bb7 | 493 | if (do_usage) { |
db197a81 TT |
494 | fprintf(stderr, _("\nBad extended option(s) specified: %s\n\n" |
495 | "Extended options are separated by commas, " | |
496 | "and may take an argument which\n" | |
497 | "\tis set off by an equals ('=') sign.\n\n" | |
498 | "Valid extended options are:\n" | |
499 | "\tsuperblock=<superblock number>\n" | |
500 | "\tblocksize=<blocksize>\n"), | |
2d328bb7 | 501 | badopt ? badopt : ""); |
db197a81 TT |
502 | free(buf); |
503 | exit(1); | |
504 | } | |
505 | free(buf); | |
efc6f628 | 506 | } |
db197a81 | 507 | |
00e5433e | 508 | int main (int argc, char ** argv) |
3839e657 TT |
509 | { |
510 | errcode_t retval; | |
511 | ext2_filsys fs; | |
f3db3566 | 512 | int print_badblocks = 0; |
295c3e03 | 513 | blk64_t use_superblock = 0; |
02e7dd9a | 514 | int use_blocksize = 0; |
348e43dc | 515 | int image_dump = 0; |
2740156b | 516 | int force = 0; |
16ed5b3a | 517 | int flags; |
2740156b | 518 | int header_only = 0; |
519149fb | 519 | int c; |
3839e657 | 520 | |
d9c56d3c TT |
521 | #ifdef ENABLE_NLS |
522 | setlocale(LC_MESSAGES, ""); | |
14308a53 | 523 | setlocale(LC_CTYPE, ""); |
d9c56d3c TT |
524 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
525 | textdomain(NLS_CAT_NAME); | |
9d4507c5 | 526 | set_com_err_gettext(gettext); |
d9c56d3c | 527 | #endif |
a6d8302b | 528 | add_error_table(&et_ext2_error_table); |
0f8973fb TT |
529 | fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION, |
530 | E2FSPROGS_DATE); | |
3839e657 TT |
531 | if (argc && *argv) |
532 | program_name = *argv; | |
efc6f628 | 533 | |
348e43dc | 534 | while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) { |
f3db3566 TT |
535 | switch (c) { |
536 | case 'b': | |
537 | print_badblocks++; | |
538 | break; | |
2740156b TT |
539 | case 'f': |
540 | force++; | |
541 | break; | |
542 | case 'h': | |
543 | header_only++; | |
544 | break; | |
348e43dc TT |
545 | case 'i': |
546 | image_dump++; | |
547 | break; | |
02e7dd9a | 548 | case 'o': |
efc6f628 | 549 | parse_extended_opts(optarg, &use_superblock, |
db197a81 | 550 | &use_blocksize); |
02e7dd9a | 551 | break; |
5c576477 TT |
552 | case 'V': |
553 | /* Print version number and exit */ | |
d9c56d3c | 554 | fprintf(stderr, _("\tUsing %s\n"), |
5c576477 TT |
555 | error_message(EXT2_ET_BASE)); |
556 | exit(0); | |
80c22c90 | 557 | case 'x': |
9b9a780f | 558 | hex_format++; |
80c22c90 | 559 | break; |
f3db3566 | 560 | default: |
818180cd | 561 | usage(); |
f3db3566 TT |
562 | } |
563 | } | |
564 | if (optind > argc - 1) | |
818180cd | 565 | usage(); |
f3db3566 | 566 | device_name = argv[optind++]; |
295c3e03 | 567 | flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; |
16ed5b3a TT |
568 | if (force) |
569 | flags |= EXT2_FLAG_FORCE; | |
348e43dc TT |
570 | if (image_dump) |
571 | flags |= EXT2_FLAG_IMAGE_FILE; | |
efc6f628 | 572 | |
db197a81 TT |
573 | if (use_superblock && !use_blocksize) { |
574 | for (use_blocksize = EXT2_MIN_BLOCK_SIZE; | |
575 | use_blocksize <= EXT2_MAX_BLOCK_SIZE; | |
576 | use_blocksize *= 2) { | |
577 | retval = ext2fs_open (device_name, flags, | |
578 | use_superblock, | |
579 | use_blocksize, unix_io_manager, | |
580 | &fs); | |
581 | if (!retval) | |
582 | break; | |
583 | } | |
584 | } else | |
585 | retval = ext2fs_open (device_name, flags, use_superblock, | |
586 | use_blocksize, unix_io_manager, &fs); | |
f3db3566 | 587 | if (retval) { |
d9c56d3c | 588 | com_err (program_name, retval, _("while trying to open %s"), |
3839e657 | 589 | device_name); |
d9c56d3c | 590 | printf (_("Couldn't find valid filesystem superblock.\n")); |
3839e657 TT |
591 | exit (1); |
592 | } | |
24dea554 | 593 | fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; |
ce10c313 TT |
594 | if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) |
595 | blocks64 = 1; | |
f3db3566 | 596 | if (print_badblocks) { |
0655b104 | 597 | list_bad_blocks(fs, 1); |
f3db3566 | 598 | } else { |
2740156b | 599 | list_super (fs->super); |
16ed5b3a TT |
600 | if (fs->super->s_feature_incompat & |
601 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { | |
602 | print_journal_information(fs); | |
603 | ext2fs_close(fs); | |
604 | exit(0); | |
605 | } | |
a11d0746 TT |
606 | if ((fs->super->s_feature_compat & |
607 | EXT3_FEATURE_COMPAT_HAS_JOURNAL) && | |
608 | (fs->super->s_journal_inum != 0)) | |
6515a6f1 | 609 | print_inline_journal_information(fs); |
0655b104 | 610 | list_bad_blocks(fs, 0); |
2740156b TT |
611 | if (header_only) { |
612 | ext2fs_close (fs); | |
613 | exit (0); | |
614 | } | |
f3db3566 | 615 | retval = ext2fs_read_bitmaps (fs); |
d90a23e2 | 616 | list_desc (fs); |
f3db3566 | 617 | if (retval) { |
d90a23e2 TT |
618 | printf(_("\n%s: %s: error reading bitmaps: %s\n"), |
619 | program_name, device_name, | |
620 | error_message(retval)); | |
f3db3566 | 621 | } |
3839e657 | 622 | } |
3839e657 | 623 | ext2fs_close (fs); |
a6d8302b | 624 | remove_error_table(&et_ext2_error_table); |
3839e657 TT |
625 | exit (0); |
626 | } |