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 | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 40 | |
| 41 | #include "../version.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 42 | #include "nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 43 | |
Theodore Ts'o | 74becf3 | 1997-04-26 14:37:06 +0000 | [diff] [blame] | 44 | #define in_use(m, x) (ext2fs_test_bit ((x), (m))) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 45 | |
| 46 | const char * program_name = "dumpe2fs"; |
| 47 | char * device_name = NULL; |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 48 | int opt_hex = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 49 | |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 50 | static void usage(void) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 51 | { |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 52 | fprintf (stderr, _("Usage: %s [-bfhixV] [-ob superblock] " |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 53 | "[-oB blocksize] device\n"), program_name); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 54 | exit (1); |
| 55 | } |
| 56 | |
| 57 | static void print_free (unsigned long group, char * bitmap, |
| 58 | unsigned long nbytes, unsigned long offset) |
| 59 | { |
| 60 | int p = 0; |
| 61 | unsigned long i; |
| 62 | unsigned long j; |
| 63 | |
| 64 | for (i = 0; i < nbytes; i++) |
| 65 | if (!in_use (bitmap, i)) |
| 66 | { |
| 67 | if (p) |
| 68 | printf (", "); |
| 69 | if (i == nbytes - 1 || in_use (bitmap, i + 1)) |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 70 | printf (opt_hex ? "0x%04x" : "%lu", |
| 71 | group * nbytes + i + offset); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 72 | else |
| 73 | { |
| 74 | for (j = i; j < nbytes && !in_use (bitmap, j); |
| 75 | j++) |
| 76 | ; |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 77 | printf (opt_hex ? "0x%04lx-0x%04lx" : |
| 78 | "%lu-%lu", group * nbytes + i + offset, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 79 | group * nbytes + (j - 1) + offset); |
| 80 | i = j - 1; |
| 81 | } |
| 82 | p = 1; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static void list_desc (ext2_filsys fs) |
| 87 | { |
| 88 | unsigned long i; |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 89 | blk_t group_blk, next_blk; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 90 | char * block_bitmap = fs->block_map->bitmap; |
| 91 | char * inode_bitmap = fs->inode_map->bitmap; |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 92 | int inode_blocks_per_group; |
| 93 | int group_desc_blocks; |
| 94 | |
| 95 | inode_blocks_per_group = ((fs->super->s_inodes_per_group * |
| 96 | EXT2_INODE_SIZE(fs->super)) + |
| 97 | EXT2_BLOCK_SIZE(fs->super) - 1) / |
| 98 | EXT2_BLOCK_SIZE(fs->super); |
| 99 | group_desc_blocks = ((fs->super->s_blocks_count - |
| 100 | fs->super->s_first_data_block + |
| 101 | EXT2_BLOCKS_PER_GROUP(fs->super) - 1) / |
| 102 | EXT2_BLOCKS_PER_GROUP(fs->super) + |
| 103 | EXT2_DESC_PER_BLOCK(fs->super) - 1) / |
| 104 | EXT2_DESC_PER_BLOCK(fs->super); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 105 | |
| 106 | printf ("\n"); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 107 | group_blk = fs->super->s_first_data_block; |
| 108 | for (i = 0; i < fs->group_desc_count; i++) { |
| 109 | next_blk = group_blk + fs->super->s_blocks_per_group; |
| 110 | if (next_blk > fs->super->s_blocks_count) |
| 111 | next_blk = fs->super->s_blocks_count; |
Theodore Ts'o | 8b164f9 | 2001-02-08 03:24:18 +0000 | [diff] [blame] | 112 | printf (opt_hex ? _("Group %lu: (Blocks 0x%04x -- 0x%04x)\n"): |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 113 | _("Group %lu: (Blocks %u -- %u)\n"), i, |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 114 | group_blk, next_blk -1 ); |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 115 | if (ext2fs_bg_has_super (fs, i)) |
| 116 | printf (opt_hex ? _(" %s Superblock at 0x%04x," |
| 117 | " Group Descriptors at 0x%04x-0x%04x\n"): |
| 118 | _(" %s Superblock at %u," |
| 119 | " Group Descriptors at %u-%u\n"), |
| 120 | i == 0 ? _("Primary") : _("Backup"), |
| 121 | group_blk, group_blk + 1, |
| 122 | group_blk + group_desc_blocks); |
Theodore Ts'o | 8b164f9 | 2001-02-08 03:24:18 +0000 | [diff] [blame] | 123 | printf (opt_hex ? _(" Block bitmap at 0x%04x (+%d), " |
| 124 | "Inode bitmap at 0x%04x (+%d)\n " |
| 125 | "Inode table at 0x%04x-0x%04x (+%d)\n"): |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 126 | _(" Block bitmap at %u (+%d), " |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 127 | "Inode bitmap at %u (+%d)\n " |
Theodore Ts'o | d7e39b0 | 2000-09-11 17:01:35 +0000 | [diff] [blame] | 128 | "Inode table at %u-%u (+%d)\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 129 | fs->group_desc[i].bg_block_bitmap, |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 130 | fs->group_desc[i].bg_block_bitmap - group_blk, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 131 | fs->group_desc[i].bg_inode_bitmap, |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 132 | fs->group_desc[i].bg_inode_bitmap - group_blk, |
| 133 | fs->group_desc[i].bg_inode_table, |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 134 | fs->group_desc[i].bg_inode_table + |
Theodore Ts'o | 8b164f9 | 2001-02-08 03:24:18 +0000 | [diff] [blame] | 135 | inode_blocks_per_group - 1, |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 136 | fs->group_desc[i].bg_inode_table - group_blk); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 137 | printf (_(" %d free blocks, %d free inodes, %d directories\n"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 138 | fs->group_desc[i].bg_free_blocks_count, |
| 139 | fs->group_desc[i].bg_free_inodes_count, |
| 140 | fs->group_desc[i].bg_used_dirs_count); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 141 | printf (_(" Free blocks: ")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 142 | print_free (i, block_bitmap, fs->super->s_blocks_per_group, |
| 143 | fs->super->s_first_data_block); |
| 144 | block_bitmap += fs->super->s_blocks_per_group / 8; |
| 145 | printf ("\n"); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 146 | printf (_(" Free inodes: ")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 147 | print_free (i, inode_bitmap, fs->super->s_inodes_per_group, 1); |
| 148 | inode_bitmap += fs->super->s_inodes_per_group / 8; |
| 149 | printf ("\n"); |
Theodore Ts'o | 521e368 | 1997-04-29 17:48:10 +0000 | [diff] [blame] | 150 | group_blk = next_blk; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | static void list_bad_blocks(ext2_filsys fs) |
| 155 | { |
| 156 | badblocks_list bb_list = 0; |
| 157 | badblocks_iterate bb_iter; |
| 158 | blk_t blk; |
| 159 | errcode_t retval; |
| 160 | |
| 161 | retval = ext2fs_read_bb_inode(fs, &bb_list); |
| 162 | if (retval) { |
| 163 | com_err("ext2fs_read_bb_inode", retval, ""); |
| 164 | exit(1); |
| 165 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 166 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 167 | if (retval) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 168 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 169 | _("while printing bad block list")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 170 | exit(1); |
| 171 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 172 | if (ext2fs_badblocks_list_iterate(bb_iter, &blk)) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 173 | printf(_("Bad blocks: %d"), blk); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 174 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 175 | printf(", %d", blk); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 176 | ext2fs_badblocks_list_iterate_end(bb_iter); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 177 | printf("\n"); |
| 178 | } |
| 179 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 180 | static void dump_bad_blocks(ext2_filsys fs) |
| 181 | { |
| 182 | badblocks_list bb_list = 0; |
| 183 | badblocks_iterate bb_iter; |
| 184 | blk_t blk; |
| 185 | errcode_t retval; |
| 186 | |
| 187 | retval = ext2fs_read_bb_inode(fs, &bb_list); |
| 188 | if (retval) { |
| 189 | com_err("ext2fs_read_bb_inode", retval, ""); |
| 190 | exit(1); |
| 191 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 192 | retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 193 | if (retval) { |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 194 | com_err("ext2fs_badblocks_list_iterate_begin", retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 195 | _("while printing bad block list")); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 196 | exit(1); |
| 197 | } |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 198 | while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) |
Theodore Ts'o | a418d3a | 1997-04-26 14:00:26 +0000 | [diff] [blame] | 199 | printf("%d\n", blk); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 200 | ext2fs_badblocks_list_iterate_end(bb_iter); |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 201 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 202 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 203 | static void print_journal_information(ext2_filsys fs) |
| 204 | { |
| 205 | errcode_t retval; |
| 206 | char buf[1024]; |
| 207 | char str[80]; |
| 208 | int i; |
| 209 | journal_superblock_t *jsb; |
| 210 | |
| 211 | /* Get the journal superblock */ |
Theodore Ts'o | 0208886 | 2001-01-18 01:44:19 +0000 | [diff] [blame] | 212 | 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] | 213 | com_err(program_name, retval, |
| 214 | _("while reading journal superblock")); |
| 215 | exit(1); |
| 216 | } |
| 217 | jsb = (journal_superblock_t *) buf; |
| 218 | if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || |
| 219 | (jsb->s_header.h_blocktype != |
| 220 | (unsigned) ntohl(JFS_SUPERBLOCK_V2))) { |
| 221 | com_err(program_name, 0, |
| 222 | _("Couldn't find journal superblock magic numbers")); |
| 223 | exit(1); |
| 224 | } |
| 225 | |
| 226 | fputs("\n", stdout); |
| 227 | printf("Journal block size: %d\n", ntohl(jsb->s_blocksize)); |
| 228 | printf("Journal length: %d\n", ntohl(jsb->s_maxlen)); |
| 229 | printf("Journal first block: %d\n", ntohl(jsb->s_first)); |
| 230 | printf("Journal sequence: 0x%08x\n", ntohl(jsb->s_sequence)); |
| 231 | printf("Journal start: %d\n", ntohl(jsb->s_start)); |
| 232 | printf("Journal number of users: %d\n", ntohl(jsb->s_nr_users)); |
| 233 | for (i=0; i < ntohl(jsb->s_nr_users); i++) { |
| 234 | if (i) |
| 235 | printf(" "); |
| 236 | else |
| 237 | printf("Journal users: "); |
| 238 | uuid_unparse(&jsb->s_users[i*16], str); |
| 239 | printf("%s\n", str); |
| 240 | } |
| 241 | } |
| 242 | |
Theodore Ts'o | 00e5433 | 1997-09-16 02:13:52 +0000 | [diff] [blame] | 243 | int main (int argc, char ** argv) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 244 | { |
| 245 | errcode_t retval; |
| 246 | ext2_filsys fs; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 247 | int print_badblocks = 0; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 248 | int use_superblock = 0; |
| 249 | int use_blocksize = 0; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 250 | int image_dump = 0; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 251 | int force = 0; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 252 | int flags; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 253 | int header_only = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 254 | int big_endian; |
Theodore Ts'o | 519149f | 1997-10-25 03:49:49 +0000 | [diff] [blame] | 255 | int c; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 256 | |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 257 | #ifdef ENABLE_NLS |
| 258 | setlocale(LC_MESSAGES, ""); |
| 259 | bindtextdomain(NLS_CAT_NAME, LOCALEDIR); |
| 260 | textdomain(NLS_CAT_NAME); |
| 261 | #endif |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 262 | initialize_ext2_error_table(); |
Theodore Ts'o | 0f8973f | 2001-08-27 12:44:23 -0400 | [diff] [blame^] | 263 | fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION, |
| 264 | E2FSPROGS_DATE); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 265 | if (argc && *argv) |
| 266 | program_name = *argv; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 267 | |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 268 | while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) { |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 269 | switch (c) { |
| 270 | case 'b': |
| 271 | print_badblocks++; |
| 272 | break; |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 273 | case 'f': |
| 274 | force++; |
| 275 | break; |
| 276 | case 'h': |
| 277 | header_only++; |
| 278 | break; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 279 | case 'i': |
| 280 | image_dump++; |
| 281 | break; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 282 | case 'o': |
| 283 | if (optarg[0] == 'b') |
| 284 | use_superblock = atoi(optarg+1); |
| 285 | else if (optarg[0] == 'B') |
| 286 | use_blocksize = atoi(optarg+1); |
| 287 | else |
| 288 | usage(); |
| 289 | break; |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 290 | case 'V': |
| 291 | /* Print version number and exit */ |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 292 | fprintf(stderr, _("\tUsing %s\n"), |
Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 293 | error_message(EXT2_ET_BASE)); |
| 294 | exit(0); |
Theodore Ts'o | 80c22c9 | 2000-08-14 15:32:11 +0000 | [diff] [blame] | 295 | case 'x': |
| 296 | opt_hex=1; |
| 297 | break; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 298 | default: |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 299 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | if (optind > argc - 1) |
Theodore Ts'o | 818180c | 1998-06-27 05:11:14 +0000 | [diff] [blame] | 303 | usage(); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 304 | device_name = argv[optind++]; |
Theodore Ts'o | 02e7dd9 | 1999-06-18 00:48:41 +0000 | [diff] [blame] | 305 | if (use_superblock && !use_blocksize) |
| 306 | use_blocksize = 1024; |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 307 | flags = EXT2_FLAG_JOURNAL_DEV_OK; |
| 308 | if (force) |
| 309 | flags |= EXT2_FLAG_FORCE; |
Theodore Ts'o | 348e43d | 2001-05-03 14:43:43 +0000 | [diff] [blame] | 310 | if (image_dump) |
| 311 | flags |= EXT2_FLAG_IMAGE_FILE; |
| 312 | |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 313 | retval = ext2fs_open (device_name, flags, use_superblock, |
| 314 | use_blocksize, unix_io_manager, &fs); |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 315 | if (retval) { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 316 | com_err (program_name, retval, _("while trying to open %s"), |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 317 | device_name); |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 318 | printf (_("Couldn't find valid filesystem superblock.\n")); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 319 | exit (1); |
| 320 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 321 | if (print_badblocks) { |
| 322 | dump_bad_blocks(fs); |
| 323 | } else { |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 324 | big_endian = ((fs->flags & EXT2_FLAG_SWAP_BYTES) != 0); |
Theodore Ts'o | cbbf031 | 2001-06-13 00:12:04 +0000 | [diff] [blame] | 325 | #ifdef WORDS_BIGENDIAN |
| 326 | big_endian = !big_endian; |
| 327 | #endif |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 328 | if (big_endian) |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 329 | printf(_("Note: This is a byte-swapped filesystem\n")); |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 330 | list_super (fs->super); |
Theodore Ts'o | 16ed5b3 | 2001-01-16 07:47:31 +0000 | [diff] [blame] | 331 | if (fs->super->s_feature_incompat & |
| 332 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { |
| 333 | print_journal_information(fs); |
| 334 | ext2fs_close(fs); |
| 335 | exit(0); |
| 336 | } |
Theodore Ts'o | 2740156 | 1999-09-14 20:11:19 +0000 | [diff] [blame] | 337 | list_bad_blocks (fs); |
| 338 | if (header_only) { |
| 339 | ext2fs_close (fs); |
| 340 | exit (0); |
| 341 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 342 | retval = ext2fs_read_bitmaps (fs); |
| 343 | if (retval) { |
| 344 | com_err (program_name, retval, |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 345 | _("while trying to read the bitmaps"), |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 346 | device_name); |
| 347 | ext2fs_close (fs); |
| 348 | exit (1); |
| 349 | } |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 350 | list_desc (fs); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 351 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 352 | ext2fs_close (fs); |
| 353 | exit (0); |
| 354 | } |