]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
1 | /* |
2 | * debugfs.c --- a program which allows you to attach an ext2fs | |
3 | * filesystem and play with it. | |
4 | * | |
5 | * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed | |
6 | * under the terms of the GNU Public License. | |
efc6f628 | 7 | * |
3839e657 TT |
8 | * Modifications by Robert Sanders <gt8134b@prism.gatech.edu> |
9 | */ | |
10 | ||
d1154eb4 | 11 | #include "config.h" |
3839e657 TT |
12 | #include <stdio.h> |
13 | #include <unistd.h> | |
14 | #include <stdlib.h> | |
15 | #include <ctype.h> | |
16 | #include <string.h> | |
17 | #include <time.h> | |
491cc33a | 18 | #include <libgen.h> |
50e1e10f | 19 | #ifdef HAVE_GETOPT_H |
3839e657 | 20 | #include <getopt.h> |
efc6f628 | 21 | #else |
50e1e10f TT |
22 | extern int optind; |
23 | extern char *optarg; | |
24 | #endif | |
50e1e10f TT |
25 | #ifdef HAVE_ERRNO_H |
26 | #include <errno.h> | |
27 | #endif | |
28 | #include <fcntl.h> | |
3839e657 | 29 | |
3839e657 | 30 | #include "debugfs.h" |
fc6d9d51 | 31 | #include "uuid/uuid.h" |
f68aa414 | 32 | #include "e2p/e2p.h" |
3839e657 | 33 | |
ea822eeb TT |
34 | #include <ext2fs/ext2_ext_attr.h> |
35 | ||
818180cd | 36 | #include "../version.h" |
03efde8a | 37 | #include "jfs_user.h" |
99ceb8ec | 38 | #include "support/plausible.h" |
818180cd | 39 | |
355ffb2f RY |
40 | #ifndef BUFSIZ |
41 | #define BUFSIZ 8192 | |
42 | #endif | |
43 | ||
49ce6cb5 | 44 | ss_request_table *extra_cmds; |
2d328bb7 | 45 | const char *debug_prog_name; |
bee7b67c | 46 | int sci_idx; |
3839e657 | 47 | |
ba08cb99 | 48 | ext2_filsys current_fs; |
75fc42f1 | 49 | quota_ctx_t current_qctx; |
b044c2e0 | 50 | ext2_ino_t root, cwd; |
3839e657 | 51 | |
491cc33a DW |
52 | static int debugfs_setup_tdb(const char *device_name, char *undo_file, |
53 | io_manager *io_ptr) | |
54 | { | |
55 | errcode_t retval = ENOMEM; | |
56 | char *tdb_dir = NULL, *tdb_file = NULL; | |
57 | char *dev_name, *tmp_name; | |
491cc33a DW |
58 | |
59 | /* (re)open a specific undo file */ | |
60 | if (undo_file && undo_file[0] != 0) { | |
b0851392 DW |
61 | retval = set_undo_io_backing_manager(*io_ptr); |
62 | if (retval) | |
63 | goto err; | |
491cc33a DW |
64 | *io_ptr = undo_io_manager; |
65 | retval = set_undo_io_backup_file(undo_file); | |
66 | if (retval) | |
67 | goto err; | |
68 | printf("Overwriting existing filesystem; this can be undone " | |
69 | "using the command:\n" | |
70 | " e2undo %s %s\n\n", | |
71 | undo_file, device_name); | |
b0851392 | 72 | return retval; |
491cc33a DW |
73 | } |
74 | ||
75 | /* | |
76 | * Configuration via a conf file would be | |
77 | * nice | |
78 | */ | |
79 | tdb_dir = getenv("E2FSPROGS_UNDO_DIR"); | |
b0851392 DW |
80 | if (!tdb_dir) |
81 | tdb_dir = "/var/lib/e2fsprogs"; | |
491cc33a | 82 | |
b0851392 DW |
83 | if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) || |
84 | access(tdb_dir, W_OK)) | |
491cc33a | 85 | return 0; |
491cc33a DW |
86 | |
87 | tmp_name = strdup(device_name); | |
88 | if (!tmp_name) | |
89 | goto errout; | |
90 | dev_name = basename(tmp_name); | |
b0851392 | 91 | tdb_file = malloc(strlen(tdb_dir) + 9 + strlen(dev_name) + 7 + 1); |
491cc33a DW |
92 | if (!tdb_file) { |
93 | free(tmp_name); | |
94 | goto errout; | |
95 | } | |
96 | sprintf(tdb_file, "%s/debugfs-%s.e2undo", tdb_dir, dev_name); | |
97 | free(tmp_name); | |
98 | ||
99 | if ((unlink(tdb_file) < 0) && (errno != ENOENT)) { | |
100 | retval = errno; | |
b0851392 DW |
101 | com_err("debugfs", retval, |
102 | "while trying to delete %s", tdb_file); | |
491cc33a DW |
103 | goto errout; |
104 | } | |
105 | ||
b0851392 DW |
106 | retval = set_undo_io_backing_manager(*io_ptr); |
107 | if (retval) | |
108 | goto errout; | |
491cc33a DW |
109 | *io_ptr = undo_io_manager; |
110 | retval = set_undo_io_backup_file(tdb_file); | |
111 | if (retval) | |
112 | goto errout; | |
113 | printf("Overwriting existing filesystem; this can be undone " | |
114 | "using the command:\n" | |
115 | " e2undo %s %s\n\n", tdb_file, device_name); | |
116 | ||
491cc33a DW |
117 | free(tdb_file); |
118 | return 0; | |
491cc33a | 119 | errout: |
491cc33a DW |
120 | free(tdb_file); |
121 | err: | |
122 | com_err("debugfs", retval, "while trying to setup undo file\n"); | |
123 | return retval; | |
124 | } | |
125 | ||
048786d7 VAH |
126 | static void open_filesystem(char *device, int open_flags, blk64_t superblock, |
127 | blk64_t blocksize, int catastrophic, | |
491cc33a | 128 | char *data_filename, char *undo_file) |
3839e657 TT |
129 | { |
130 | int retval; | |
1ad54a94 | 131 | io_channel data_io = 0; |
491cc33a | 132 | io_manager io_ptr = unix_io_manager; |
2e8d40d5 TT |
133 | |
134 | if (superblock != 0 && blocksize == 0) { | |
135 | com_err(device, 0, "if you specify the superblock, you must also specify the block size"); | |
136 | current_fs = NULL; | |
137 | return; | |
138 | } | |
139 | ||
1ad54a94 TT |
140 | if (data_filename) { |
141 | if ((open_flags & EXT2_FLAG_IMAGE_FILE) == 0) { | |
efc6f628 | 142 | com_err(device, 0, |
1ad54a94 TT |
143 | "The -d option is only valid when reading an e2image file"); |
144 | current_fs = NULL; | |
145 | return; | |
146 | } | |
147 | retval = unix_io_manager->open(data_filename, 0, &data_io); | |
148 | if (retval) { | |
149 | com_err(data_filename, 0, "while opening data source"); | |
150 | current_fs = NULL; | |
151 | return; | |
152 | } | |
153 | } | |
154 | ||
2e8d40d5 TT |
155 | if (catastrophic && (open_flags & EXT2_FLAG_RW)) { |
156 | com_err(device, 0, | |
157 | "opening read-only because of catastrophic mode"); | |
158 | open_flags &= ~EXT2_FLAG_RW; | |
159 | } | |
0f5eba75 AD |
160 | if (catastrophic) |
161 | open_flags |= EXT2_FLAG_SKIP_MMP; | |
efc6f628 | 162 | |
491cc33a DW |
163 | if (undo_file) { |
164 | retval = debugfs_setup_tdb(device, undo_file, &io_ptr); | |
165 | if (retval) | |
166 | exit(1); | |
167 | } | |
168 | ||
2e8d40d5 | 169 | retval = ext2fs_open(device, open_flags, superblock, blocksize, |
491cc33a | 170 | io_ptr, ¤t_fs); |
3839e657 TT |
171 | if (retval) { |
172 | com_err(device, retval, "while opening filesystem"); | |
c8b20b40 DW |
173 | if (retval == EXT2_ET_BAD_MAGIC) |
174 | check_plausibility(device, CHECK_FS_EXIST, NULL); | |
fc6d9d51 | 175 | current_fs = NULL; |
3839e657 TT |
176 | return; |
177 | } | |
24dea554 | 178 | current_fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE; |
2e8d40d5 TT |
179 | |
180 | if (catastrophic) | |
181 | com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps"); | |
182 | else { | |
183 | retval = ext2fs_read_inode_bitmap(current_fs); | |
184 | if (retval) { | |
185 | com_err(device, retval, "while reading inode bitmap"); | |
186 | goto errout; | |
187 | } | |
188 | retval = ext2fs_read_block_bitmap(current_fs); | |
189 | if (retval) { | |
190 | com_err(device, retval, "while reading block bitmap"); | |
191 | goto errout; | |
192 | } | |
3839e657 | 193 | } |
1ad54a94 TT |
194 | |
195 | if (data_io) { | |
196 | retval = ext2fs_set_data_io(current_fs, data_io); | |
197 | if (retval) { | |
efc6f628 | 198 | com_err(device, retval, |
1ad54a94 TT |
199 | "while setting data source"); |
200 | goto errout; | |
201 | } | |
202 | } | |
203 | ||
3839e657 TT |
204 | root = cwd = EXT2_ROOT_INO; |
205 | return; | |
206 | ||
207 | errout: | |
47fee2ef | 208 | retval = ext2fs_close_free(¤t_fs); |
3839e657 TT |
209 | if (retval) |
210 | com_err(device, retval, "while trying to close filesystem"); | |
3839e657 TT |
211 | } |
212 | ||
213 | void do_open_filesys(int argc, char **argv) | |
214 | { | |
e1018eea | 215 | int c, err; |
2e8d40d5 | 216 | int catastrophic = 0; |
048786d7 VAH |
217 | blk64_t superblock = 0; |
218 | blk64_t blocksize = 0; | |
03b9dca6 | 219 | int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; |
b0d17e0d | 220 | char *data_filename = 0; |
491cc33a | 221 | char *undo_file = NULL; |
efc6f628 | 222 | |
88494bb6 | 223 | reset_getopt(); |
491cc33a | 224 | while ((c = getopt(argc, argv, "iwfecb:s:d:Dz:")) != EOF) { |
3839e657 | 225 | switch (c) { |
59cf7e0d TT |
226 | case 'i': |
227 | open_flags |= EXT2_FLAG_IMAGE_FILE; | |
228 | break; | |
3839e657 | 229 | case 'w': |
e88c5a33 TT |
230 | #ifdef READ_ONLY |
231 | goto print_usage; | |
232 | #else | |
d3aea7dc | 233 | open_flags |= EXT2_FLAG_RW; |
e88c5a33 | 234 | #endif /* READ_ONLY */ |
d3aea7dc TT |
235 | break; |
236 | case 'f': | |
237 | open_flags |= EXT2_FLAG_FORCE; | |
3839e657 | 238 | break; |
98eb44bd TT |
239 | case 'e': |
240 | open_flags |= EXT2_FLAG_EXCLUSIVE; | |
241 | break; | |
2e8d40d5 TT |
242 | case 'c': |
243 | catastrophic = 1; | |
244 | break; | |
1ad54a94 TT |
245 | case 'd': |
246 | data_filename = optarg; | |
247 | break; | |
0fd68e02 TT |
248 | case 'D': |
249 | open_flags |= EXT2_FLAG_DIRECT_IO; | |
250 | break; | |
2e8d40d5 | 251 | case 'b': |
e1018eea TT |
252 | blocksize = parse_ulong(optarg, argv[0], |
253 | "block size", &err); | |
254 | if (err) | |
2e8d40d5 | 255 | return; |
2e8d40d5 TT |
256 | break; |
257 | case 's': | |
a25fffae EW |
258 | err = strtoblk(argv[0], optarg, |
259 | "superblock block number", &superblock); | |
e1018eea | 260 | if (err) |
2e8d40d5 | 261 | return; |
2e8d40d5 | 262 | break; |
491cc33a DW |
263 | case 'z': |
264 | undo_file = optarg; | |
265 | break; | |
3839e657 | 266 | default: |
9b9a780f | 267 | goto print_usage; |
3839e657 TT |
268 | } |
269 | } | |
270 | if (optind != argc-1) { | |
9b9a780f | 271 | goto print_usage; |
3839e657 TT |
272 | } |
273 | if (check_fs_not_open(argv[0])) | |
274 | return; | |
2e8d40d5 | 275 | open_filesystem(argv[optind], open_flags, |
efc6f628 | 276 | superblock, blocksize, catastrophic, |
491cc33a | 277 | data_filename, undo_file); |
9b9a780f TT |
278 | return; |
279 | ||
280 | print_usage: | |
5093775a ZL |
281 | fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] " |
282 | "[-d image_filename] [-c] [-i] [-f] [-e] [-D] " | |
e88c5a33 TT |
283 | #ifndef READ_ONLY |
284 | "[-w] " | |
285 | #endif | |
286 | "<device>\n", argv[0]); | |
2e8d40d5 TT |
287 | } |
288 | ||
289 | void do_lcd(int argc, char **argv) | |
290 | { | |
57a1cbb6 TT |
291 | if (argc != 2) { |
292 | com_err(argv[0], 0, "Usage: %s %s", argv[0], "<native dir>"); | |
2e8d40d5 | 293 | return; |
57a1cbb6 | 294 | } |
2e8d40d5 TT |
295 | |
296 | if (chdir(argv[1]) == -1) { | |
297 | com_err(argv[0], errno, | |
298 | "while trying to change native directory to %s", | |
299 | argv[1]); | |
300 | return; | |
301 | } | |
3839e657 TT |
302 | } |
303 | ||
50e1e10f | 304 | static void close_filesystem(NOARGS) |
3839e657 TT |
305 | { |
306 | int retval; | |
efc6f628 | 307 | |
fc6d9d51 TT |
308 | if (current_fs->flags & EXT2_FLAG_IB_DIRTY) { |
309 | retval = ext2fs_write_inode_bitmap(current_fs); | |
3839e657 | 310 | if (retval) |
9b9a780f | 311 | com_err("ext2fs_write_inode_bitmap", retval, 0); |
3839e657 | 312 | } |
fc6d9d51 TT |
313 | if (current_fs->flags & EXT2_FLAG_BB_DIRTY) { |
314 | retval = ext2fs_write_block_bitmap(current_fs); | |
3839e657 | 315 | if (retval) |
9b9a780f | 316 | com_err("ext2fs_write_block_bitmap", retval, 0); |
3839e657 | 317 | } |
75fc42f1 TT |
318 | if (current_qctx) |
319 | quota_release_context(¤t_qctx); | |
47fee2ef | 320 | retval = ext2fs_close_free(¤t_fs); |
3839e657 | 321 | if (retval) |
9b9a780f | 322 | com_err("ext2fs_close", retval, 0); |
3839e657 TT |
323 | return; |
324 | } | |
325 | ||
326 | void do_close_filesys(int argc, char **argv) | |
327 | { | |
6dce5328 TT |
328 | int c; |
329 | ||
330 | if (check_fs_open(argv[0])) | |
3839e657 | 331 | return; |
6dce5328 TT |
332 | |
333 | reset_getopt(); | |
334 | while ((c = getopt (argc, argv, "a")) != EOF) { | |
335 | switch (c) { | |
336 | case 'a': | |
337 | current_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; | |
338 | break; | |
339 | default: | |
340 | goto print_usage; | |
341 | } | |
342 | } | |
343 | ||
344 | if (argc > optind) { | |
345 | print_usage: | |
346 | com_err(0, 0, "Usage: close_filesys [-a]"); | |
347 | return; | |
348 | } | |
349 | ||
3839e657 TT |
350 | close_filesystem(); |
351 | } | |
352 | ||
e88c5a33 | 353 | #ifndef READ_ONLY |
3839e657 TT |
354 | void do_init_filesys(int argc, char **argv) |
355 | { | |
3839e657 TT |
356 | struct ext2_super_block param; |
357 | errcode_t retval; | |
e1018eea | 358 | int err; |
fe56188b | 359 | blk64_t blocks; |
efc6f628 | 360 | |
e1018eea | 361 | if (common_args_process(argc, argv, 3, 3, "initialize", |
57d4fb66 | 362 | "<device> <blocks>", CHECK_FS_NOTOPEN)) |
3839e657 TT |
363 | return; |
364 | ||
365 | memset(¶m, 0, sizeof(struct ext2_super_block)); | |
a25fffae | 366 | err = strtoblk(argv[0], argv[2], "blocks count", &blocks); |
fe56188b DW |
367 | if (err) |
368 | return; | |
369 | ext2fs_blocks_count_set(¶m, blocks); | |
fc6d9d51 TT |
370 | retval = ext2fs_initialize(argv[1], 0, ¶m, |
371 | unix_io_manager, ¤t_fs); | |
3839e657 TT |
372 | if (retval) { |
373 | com_err(argv[1], retval, "while initializing filesystem"); | |
fc6d9d51 | 374 | current_fs = NULL; |
3839e657 TT |
375 | return; |
376 | } | |
377 | root = cwd = EXT2_ROOT_INO; | |
378 | return; | |
379 | } | |
380 | ||
5dd8f963 | 381 | static void print_features(struct ext2_super_block * s, FILE *f) |
d3aea7dc | 382 | { |
d3aea7dc | 383 | int i, j, printed=0; |
092c3dec | 384 | __u32 *mask = &s->s_feature_compat, m; |
d3aea7dc | 385 | |
777ebb3e | 386 | fputs("Filesystem features:", f); |
d3aea7dc TT |
387 | for (i=0; i <3; i++,mask++) { |
388 | for (j=0,m=1; j < 32; j++, m<<=1) { | |
389 | if (*mask & m) { | |
390 | fprintf(f, " %s", e2p_feature2string(i, m)); | |
391 | printed++; | |
392 | } | |
393 | } | |
394 | } | |
395 | if (printed == 0) | |
777ebb3e TT |
396 | fputs("(none)", f); |
397 | fputs("\n", f); | |
d3aea7dc | 398 | } |
3cebf9c1 | 399 | #endif /* READ_ONLY */ |
d3aea7dc | 400 | |
732c8cd5 | 401 | static void print_bg_opts(ext2_filsys fs, dgrp_t group, int mask, |
f5fa2007 TT |
402 | const char *str, int *first, FILE *f) |
403 | { | |
cd65a24e | 404 | if (ext2fs_bg_flags_test(fs, group, mask)) { |
f5fa2007 TT |
405 | if (*first) { |
406 | fputs(" [", f); | |
407 | *first = 0; | |
408 | } else | |
409 | fputs(", ", f); | |
410 | fputs(str, f); | |
411 | } | |
412 | } | |
413 | ||
3839e657 TT |
414 | void do_show_super_stats(int argc, char *argv[]) |
415 | { | |
2418dfd7 | 416 | const char *units ="block"; |
54434927 | 417 | dgrp_t i; |
3839e657 | 418 | FILE *out; |
d3aea7dc | 419 | int c, header_only = 0; |
8fdf2911 JS |
420 | int numdirs = 0, first, gdt_csum; |
421 | ||
88494bb6 | 422 | reset_getopt(); |
d3aea7dc TT |
423 | while ((c = getopt (argc, argv, "h")) != EOF) { |
424 | switch (c) { | |
425 | case 'h': | |
426 | header_only++; | |
427 | break; | |
428 | default: | |
9b9a780f | 429 | goto print_usage; |
d3aea7dc TT |
430 | } |
431 | } | |
432 | if (optind != argc) { | |
9b9a780f | 433 | goto print_usage; |
3839e657 TT |
434 | } |
435 | if (check_fs_open(argv[0])) | |
436 | return; | |
437 | out = open_pager(); | |
bd09eff9 | 438 | |
4ee26699 | 439 | if (ext2fs_has_feature_bigalloc(current_fs->super)) |
2418dfd7 TT |
440 | units = "cluster"; |
441 | ||
bd09eff9 | 442 | list_super2(current_fs->super, out); |
34be9609 | 443 | for (i=0; i < current_fs->group_desc_count; i++) |
048786d7 | 444 | numdirs += ext2fs_bg_used_dirs_count(current_fs, i); |
34be9609 | 445 | fprintf(out, "Directories: %d\n", numdirs); |
efc6f628 | 446 | |
d3aea7dc TT |
447 | if (header_only) { |
448 | close_pager(out); | |
449 | return; | |
450 | } | |
efc6f628 | 451 | |
5b58dc23 | 452 | gdt_csum = ext2fs_has_group_desc_csum(current_fs); |
048786d7 VAH |
453 | for (i = 0; i < current_fs->group_desc_count; i++) { |
454 | fprintf(out, " Group %2d: block bitmap at %llu, " | |
455 | "inode bitmap at %llu, " | |
456 | "inode table at %llu\n" | |
2418dfd7 | 457 | " %u free %s%s, " |
048786d7 VAH |
458 | "%u free %s, " |
459 | "%u used %s%s", | |
460 | i, ext2fs_block_bitmap_loc(current_fs, i), | |
461 | ext2fs_inode_bitmap_loc(current_fs, i), | |
462 | ext2fs_inode_table_loc(current_fs, i), | |
2418dfd7 | 463 | ext2fs_bg_free_blocks_count(current_fs, i), units, |
048786d7 | 464 | ext2fs_bg_free_blocks_count(current_fs, i) != 1 ? |
2418dfd7 | 465 | "s" : "", |
048786d7 VAH |
466 | ext2fs_bg_free_inodes_count(current_fs, i), |
467 | ext2fs_bg_free_inodes_count(current_fs, i) != 1 ? | |
468 | "inodes" : "inode", | |
469 | ext2fs_bg_used_dirs_count(current_fs, i), | |
470 | ext2fs_bg_used_dirs_count(current_fs, i) != 1 ? "directories" | |
471 | : "directory", gdt_csum ? ", " : "\n"); | |
8fdf2911 | 472 | if (gdt_csum) |
048786d7 VAH |
473 | fprintf(out, "%u unused %s\n", |
474 | ext2fs_bg_itable_unused(current_fs, i), | |
475 | ext2fs_bg_itable_unused(current_fs, i) != 1 ? | |
476 | "inodes" : "inode"); | |
f5fa2007 | 477 | first = 1; |
732c8cd5 | 478 | print_bg_opts(current_fs, i, EXT2_BG_INODE_UNINIT, "Inode not init", |
f5fa2007 | 479 | &first, out); |
732c8cd5 | 480 | print_bg_opts(current_fs, i, EXT2_BG_BLOCK_UNINIT, "Block not init", |
f5fa2007 | 481 | &first, out); |
8fdf2911 JS |
482 | if (gdt_csum) { |
483 | fprintf(out, "%sChecksum 0x%04x", | |
048786d7 | 484 | first ? " [":", ", ext2fs_bg_checksum(current_fs, i)); |
8fdf2911 JS |
485 | first = 0; |
486 | } | |
f5fa2007 TT |
487 | if (!first) |
488 | fputs("]\n", out); | |
489 | } | |
3839e657 | 490 | close_pager(out); |
9b9a780f TT |
491 | return; |
492 | print_usage: | |
493 | fprintf(stderr, "%s: Usage: show_super [-h]\n", argv[0]); | |
3839e657 TT |
494 | } |
495 | ||
e88c5a33 | 496 | #ifndef READ_ONLY |
efc6f628 | 497 | void do_dirty_filesys(int argc EXT2FS_ATTR((unused)), |
54434927 | 498 | char **argv EXT2FS_ATTR((unused))) |
21c84b71 TT |
499 | { |
500 | if (check_fs_open(argv[0])) | |
501 | return; | |
601002bd TT |
502 | if (check_fs_read_write(argv[0])) |
503 | return; | |
504 | ||
505 | if (argv[1] && !strcmp(argv[1], "-clean")) | |
506 | current_fs->super->s_state |= EXT2_VALID_FS; | |
507 | else | |
508 | current_fs->super->s_state &= ~EXT2_VALID_FS; | |
21c84b71 TT |
509 | ext2fs_mark_super_dirty(current_fs); |
510 | } | |
e88c5a33 | 511 | #endif /* READ_ONLY */ |
21c84b71 | 512 | |
3839e657 | 513 | struct list_blocks_struct { |
89e25cfd AD |
514 | FILE *f; |
515 | e2_blkcnt_t total; | |
048786d7 | 516 | blk64_t first_block, last_block; |
89e25cfd AD |
517 | e2_blkcnt_t first_bcnt, last_bcnt; |
518 | e2_blkcnt_t first; | |
3839e657 TT |
519 | }; |
520 | ||
0a3db93a TT |
521 | static void finish_range(struct list_blocks_struct *lb) |
522 | { | |
523 | if (lb->first_block == 0) | |
524 | return; | |
525 | if (lb->first) | |
526 | lb->first = 0; | |
527 | else | |
80bfaa3e | 528 | fprintf(lb->f, ", "); |
0a3db93a | 529 | if (lb->first_block == lb->last_block) |
048786d7 | 530 | fprintf(lb->f, "(%lld):%llu", |
de8f3a76 | 531 | (long long)lb->first_bcnt, lb->first_block); |
0a3db93a | 532 | else |
048786d7 | 533 | fprintf(lb->f, "(%lld-%lld):%llu-%llu", |
de8f3a76 AD |
534 | (long long)lb->first_bcnt, (long long)lb->last_bcnt, |
535 | lb->first_block, lb->last_block); | |
0a3db93a TT |
536 | lb->first_block = 0; |
537 | } | |
538 | ||
efc6f628 | 539 | static int list_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)), |
048786d7 VAH |
540 | blk64_t *blocknr, e2_blkcnt_t blockcnt, |
541 | blk64_t ref_block EXT2FS_ATTR((unused)), | |
efc6f628 | 542 | int ref_offset EXT2FS_ATTR((unused)), |
54434927 | 543 | void *private) |
3839e657 TT |
544 | { |
545 | struct list_blocks_struct *lb = (struct list_blocks_struct *) private; | |
546 | ||
0a3db93a TT |
547 | lb->total++; |
548 | if (blockcnt >= 0) { | |
549 | /* | |
550 | * See if we can add on to the existing range (if it exists) | |
551 | */ | |
552 | if (lb->first_block && | |
553 | (lb->last_block+1 == *blocknr) && | |
554 | (lb->last_bcnt+1 == blockcnt)) { | |
555 | lb->last_block = *blocknr; | |
556 | lb->last_bcnt = blockcnt; | |
557 | return 0; | |
558 | } | |
559 | /* | |
560 | * Start a new range. | |
561 | */ | |
562 | finish_range(lb); | |
563 | lb->first_block = lb->last_block = *blocknr; | |
564 | lb->first_bcnt = lb->last_bcnt = blockcnt; | |
565 | return 0; | |
566 | } | |
567 | /* | |
568 | * Not a normal block. Always force a new range. | |
569 | */ | |
570 | finish_range(lb); | |
571 | if (lb->first) | |
572 | lb->first = 0; | |
573 | else | |
2c4a5406 | 574 | fprintf(lb->f, ", "); |
a5eef73b | 575 | if (blockcnt == -1) |
048786d7 | 576 | fprintf(lb->f, "(IND):%llu", (unsigned long long) *blocknr); |
a5eef73b | 577 | else if (blockcnt == -2) |
048786d7 | 578 | fprintf(lb->f, "(DIND):%llu", (unsigned long long) *blocknr); |
a5eef73b | 579 | else if (blockcnt == -3) |
048786d7 | 580 | fprintf(lb->f, "(TIND):%llu", (unsigned long long) *blocknr); |
3839e657 TT |
581 | return 0; |
582 | } | |
583 | ||
efc6f628 | 584 | static void internal_dump_inode_extra(FILE *out, |
de8f3a76 | 585 | const char *prefix EXT2FS_ATTR((unused)), |
efc6f628 | 586 | ext2_ino_t inode_num EXT2FS_ATTR((unused)), |
9b9a780f | 587 | struct ext2_inode_large *inode) |
ea822eeb | 588 | { |
8deb80a5 | 589 | fprintf(out, "Size of extra inode fields: %u\n", inode->i_extra_isize); |
ea822eeb TT |
590 | if (inode->i_extra_isize > EXT2_INODE_SIZE(current_fs->super) - |
591 | EXT2_GOOD_OLD_INODE_SIZE) { | |
592 | fprintf(stderr, "invalid inode->i_extra_isize (%u)\n", | |
593 | inode->i_extra_isize); | |
594 | return; | |
595 | } | |
5beff1c0 DW |
596 | } |
597 | ||
5e4f0709 | 598 | static void dump_blocks(FILE *f, const char *prefix, ext2_ino_t inode) |
3839e657 TT |
599 | { |
600 | struct list_blocks_struct lb; | |
601 | ||
da81e3fc | 602 | fprintf(f, "%sBLOCKS:\n%s", prefix, prefix); |
3839e657 | 603 | lb.total = 0; |
0a3db93a | 604 | lb.first_block = 0; |
3839e657 | 605 | lb.f = f; |
0a3db93a | 606 | lb.first = 1; |
048786d7 VAH |
607 | ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL, |
608 | list_blocks_proc, (void *)&lb); | |
0a3db93a | 609 | finish_range(&lb); |
3839e657 | 610 | if (lb.total) |
de8f3a76 | 611 | fprintf(f, "\n%sTOTAL: %lld\n", prefix, (long long)lb.total); |
3839e657 TT |
612 | fprintf(f,"\n"); |
613 | } | |
614 | ||
187cb623 TT |
615 | static int int_log10(unsigned long long arg) |
616 | { | |
617 | int l = 0; | |
618 | ||
619 | arg = arg / 10; | |
620 | while (arg) { | |
621 | l++; | |
622 | arg = arg / 10; | |
623 | } | |
624 | return l; | |
625 | } | |
626 | ||
627 | #define DUMP_LEAF_EXTENTS 0x01 | |
628 | #define DUMP_NODE_EXTENTS 0x02 | |
629 | #define DUMP_EXTENT_TABLE 0x04 | |
630 | ||
631 | static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino, | |
632 | int flags, int logical_width, int physical_width) | |
633 | { | |
634 | ext2_extent_handle_t handle; | |
635 | struct ext2fs_extent extent; | |
636 | struct ext2_extent_info info; | |
637 | int op = EXT2_EXTENT_ROOT; | |
638 | unsigned int printed = 0; | |
639 | errcode_t errcode; | |
640 | ||
641 | errcode = ext2fs_extent_open(current_fs, ino, &handle); | |
642 | if (errcode) | |
643 | return; | |
644 | ||
645 | if (flags & DUMP_EXTENT_TABLE) | |
646 | fprintf(f, "Level Entries %*s %*s Length Flags\n", | |
647 | (logical_width*2)+3, "Logical", | |
648 | (physical_width*2)+3, "Physical"); | |
649 | else | |
650 | fprintf(f, "%sEXTENTS:\n%s", prefix, prefix); | |
651 | ||
652 | while (1) { | |
653 | errcode = ext2fs_extent_get(handle, op, &extent); | |
654 | ||
655 | if (errcode) | |
656 | break; | |
657 | ||
658 | op = EXT2_EXTENT_NEXT; | |
659 | ||
660 | if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) | |
661 | continue; | |
662 | ||
663 | if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) { | |
664 | if ((flags & DUMP_LEAF_EXTENTS) == 0) | |
665 | continue; | |
666 | } else { | |
667 | if ((flags & DUMP_NODE_EXTENTS) == 0) | |
668 | continue; | |
669 | } | |
670 | ||
671 | errcode = ext2fs_extent_get_info(handle, &info); | |
672 | if (errcode) | |
673 | continue; | |
674 | ||
675 | if (!(extent.e_flags & EXT2_EXTENT_FLAGS_LEAF)) { | |
676 | if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) | |
677 | continue; | |
678 | ||
679 | if (flags & DUMP_EXTENT_TABLE) { | |
680 | fprintf(f, "%2d/%2d %3d/%3d %*llu - %*llu " | |
681 | "%*llu%*s %6u\n", | |
682 | info.curr_level, info.max_depth, | |
683 | info.curr_entry, info.num_entries, | |
684 | logical_width, | |
685 | extent.e_lblk, | |
686 | logical_width, | |
687 | extent.e_lblk + (extent.e_len - 1), | |
688 | physical_width, | |
689 | extent.e_pblk, | |
690 | physical_width+3, "", extent.e_len); | |
691 | continue; | |
692 | } | |
693 | ||
a9468442 | 694 | fprintf(f, "%s(ETB%d):%lld", |
c4b87b8c | 695 | printed ? ", " : "", info.curr_level, |
187cb623 TT |
696 | extent.e_pblk); |
697 | printed = 1; | |
698 | continue; | |
699 | } | |
700 | ||
701 | if (flags & DUMP_EXTENT_TABLE) { | |
702 | fprintf(f, "%2d/%2d %3d/%3d %*llu - %*llu " | |
703 | "%*llu - %*llu %6u %s\n", | |
704 | info.curr_level, info.max_depth, | |
705 | info.curr_entry, info.num_entries, | |
706 | logical_width, | |
707 | extent.e_lblk, | |
708 | logical_width, | |
709 | extent.e_lblk + (extent.e_len - 1), | |
710 | physical_width, | |
711 | extent.e_pblk, | |
712 | physical_width, | |
713 | extent.e_pblk + (extent.e_len - 1), | |
714 | extent.e_len, | |
715 | extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ? | |
716 | "Uninit" : ""); | |
717 | continue; | |
718 | } | |
719 | ||
720 | if (extent.e_len == 0) | |
721 | continue; | |
722 | else if (extent.e_len == 1) | |
723 | fprintf(f, | |
a9468442 | 724 | "%s(%lld%s):%lld", |
187cb623 TT |
725 | printed ? ", " : "", |
726 | extent.e_lblk, | |
727 | extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ? | |
a9468442 | 728 | "[u]" : "", |
187cb623 TT |
729 | extent.e_pblk); |
730 | else | |
731 | fprintf(f, | |
a9468442 | 732 | "%s(%lld-%lld%s):%lld-%lld", |
187cb623 TT |
733 | printed ? ", " : "", |
734 | extent.e_lblk, | |
735 | extent.e_lblk + (extent.e_len - 1), | |
736 | extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ? | |
a9468442 | 737 | "[u]" : "", |
187cb623 TT |
738 | extent.e_pblk, |
739 | extent.e_pblk + (extent.e_len - 1)); | |
740 | printed = 1; | |
741 | } | |
742 | if (printed) | |
743 | fprintf(f, "\n"); | |
8a6cc1ae | 744 | ext2fs_extent_free(handle); |
187cb623 | 745 | } |
3839e657 | 746 | |
133e9462 ZL |
747 | static void dump_inline_data(FILE *out, const char *prefix, ext2_ino_t inode_num) |
748 | { | |
749 | errcode_t retval; | |
750 | size_t size; | |
751 | ||
752 | retval = ext2fs_inline_data_size(current_fs, inode_num, &size); | |
753 | if (!retval) | |
7ba5cc74 DW |
754 | fprintf(out, "%sSize of inline data: %zu\n", prefix, size); |
755 | } | |
756 | ||
757 | static void dump_fast_link(FILE *out, ext2_ino_t inode_num, | |
758 | struct ext2_inode *inode, const char *prefix) | |
759 | { | |
760 | errcode_t retval = 0; | |
761 | char *buf; | |
762 | size_t size; | |
763 | ||
764 | if (inode->i_flags & EXT4_INLINE_DATA_FL) { | |
765 | retval = ext2fs_inline_data_size(current_fs, inode_num, &size); | |
766 | if (retval) | |
767 | goto out; | |
768 | ||
769 | retval = ext2fs_get_memzero(size + 1, &buf); | |
770 | if (retval) | |
771 | goto out; | |
772 | ||
773 | retval = ext2fs_inline_data_get(current_fs, inode_num, | |
774 | inode, buf, &size); | |
775 | if (retval) | |
776 | goto out; | |
777 | fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix, | |
778 | (int)size, buf); | |
779 | ||
780 | retval = ext2fs_free_mem(&buf); | |
781 | if (retval) | |
782 | goto out; | |
783 | } else { | |
df0b907e | 784 | size_t sz = EXT2_I_SIZE(inode); |
7ba5cc74 DW |
785 | |
786 | if (sz > sizeof(inode->i_block)) | |
787 | sz = sizeof(inode->i_block); | |
df0b907e | 788 | fprintf(out, "%sFast link dest: \"%.*s\"\n", prefix, (int) sz, |
7ba5cc74 DW |
789 | (char *)inode->i_block); |
790 | } | |
791 | out: | |
792 | if (retval) | |
793 | com_err(__func__, retval, "while dumping link destination"); | |
133e9462 ZL |
794 | } |
795 | ||
5e4f0709 | 796 | void internal_dump_inode(FILE *out, const char *prefix, |
da81e3fc TT |
797 | ext2_ino_t inode_num, struct ext2_inode *inode, |
798 | int do_dump_blocks) | |
3839e657 | 799 | { |
50e1e10f | 800 | const char *i_type; |
fc6d9d51 TT |
801 | char frag, fsize; |
802 | int os = current_fs->super->s_creator_os; | |
a16031c6 TT |
803 | struct ext2_inode_large *large_inode; |
804 | int is_large_inode = 0; | |
805 | ||
806 | if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE) | |
807 | is_large_inode = 1; | |
808 | large_inode = (struct ext2_inode_large *) inode; | |
809 | ||
da81e3fc TT |
810 | if (LINUX_S_ISDIR(inode->i_mode)) i_type = "directory"; |
811 | else if (LINUX_S_ISREG(inode->i_mode)) i_type = "regular"; | |
812 | else if (LINUX_S_ISLNK(inode->i_mode)) i_type = "symlink"; | |
813 | else if (LINUX_S_ISBLK(inode->i_mode)) i_type = "block special"; | |
814 | else if (LINUX_S_ISCHR(inode->i_mode)) i_type = "character special"; | |
815 | else if (LINUX_S_ISFIFO(inode->i_mode)) i_type = "FIFO"; | |
816 | else if (LINUX_S_ISSOCK(inode->i_mode)) i_type = "socket"; | |
3839e657 | 817 | else i_type = "bad type"; |
da81e3fc | 818 | fprintf(out, "%sInode: %u Type: %s ", prefix, inode_num, i_type); |
a16031c6 TT |
819 | fprintf(out, "%sMode: %04o Flags: 0x%x\n", |
820 | prefix, inode->i_mode & 0777, inode->i_flags); | |
821 | if (is_large_inode && large_inode->i_extra_isize >= 24) { | |
efc6f628 | 822 | fprintf(out, "%sGeneration: %u Version: 0x%08x:%08x\n", |
a16031c6 TT |
823 | prefix, inode->i_generation, large_inode->i_version_hi, |
824 | inode->osd1.linux1.l_i_version); | |
825 | } else { | |
efc6f628 | 826 | fprintf(out, "%sGeneration: %u Version: 0x%08x\n", prefix, |
a16031c6 TT |
827 | inode->i_generation, inode->osd1.linux1.l_i_version); |
828 | } | |
da81e3fc | 829 | fprintf(out, "%sUser: %5d Group: %5d Size: ", |
5113a6e3 | 830 | prefix, inode_uid(*inode), inode_gid(*inode)); |
0bd0e593 AD |
831 | if (LINUX_S_ISREG(inode->i_mode)) |
832 | fprintf(out, "%llu\n", EXT2_I_SIZE(inode)); | |
833 | else | |
1a6bb627 | 834 | fprintf(out, "%d\n", inode->i_size); |
5d17119d | 835 | if (os == EXT2_OS_HURD) |
62c06f79 | 836 | fprintf(out, |
da81e3fc TT |
837 | "%sFile ACL: %d Directory ACL: %d Translator: %d\n", |
838 | prefix, | |
839 | inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0, | |
840 | inode->osd1.hurd1.h_i_translator); | |
62c06f79 | 841 | else |
81624c3c | 842 | fprintf(out, "%sFile ACL: %llu Directory ACL: %d\n", |
da81e3fc | 843 | prefix, |
81624c3c TT |
844 | inode->i_file_acl | ((long long) |
845 | (inode->osd2.linux2.l_i_file_acl_high) << 32), | |
846 | LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0); | |
efc6f628 | 847 | if (os == EXT2_OS_LINUX) |
5d17119d | 848 | fprintf(out, "%sLinks: %d Blockcount: %llu\n", |
efc6f628 TT |
849 | prefix, inode->i_links_count, |
850 | (((unsigned long long) | |
851 | inode->osd2.linux2.l_i_blocks_hi << 32)) + | |
5d17119d TT |
852 | inode->i_blocks); |
853 | else | |
854 | fprintf(out, "%sLinks: %d Blockcount: %u\n", | |
855 | prefix, inode->i_links_count, inode->i_blocks); | |
fc6d9d51 | 856 | switch (os) { |
fc6d9d51 | 857 | case EXT2_OS_HURD: |
da81e3fc TT |
858 | frag = inode->osd2.hurd2.h_i_frag; |
859 | fsize = inode->osd2.hurd2.h_i_fsize; | |
fc6d9d51 | 860 | break; |
fc6d9d51 TT |
861 | default: |
862 | frag = fsize = 0; | |
863 | } | |
da81e3fc TT |
864 | fprintf(out, "%sFragment: Address: %d Number: %d Size: %d\n", |
865 | prefix, inode->i_faddr, frag, fsize); | |
a16031c6 | 866 | if (is_large_inode && large_inode->i_extra_isize >= 24) { |
efc6f628 | 867 | fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix, |
a16031c6 | 868 | inode->i_ctime, large_inode->i_ctime_extra, |
188960ea TT |
869 | inode_time_to_string(inode->i_ctime, |
870 | large_inode->i_ctime_extra)); | |
efc6f628 | 871 | fprintf(out, "%s atime: 0x%08x:%08x -- %s", prefix, |
a16031c6 | 872 | inode->i_atime, large_inode->i_atime_extra, |
188960ea TT |
873 | inode_time_to_string(inode->i_atime, |
874 | large_inode->i_atime_extra)); | |
a16031c6 TT |
875 | fprintf(out, "%s mtime: 0x%08x:%08x -- %s", prefix, |
876 | inode->i_mtime, large_inode->i_mtime_extra, | |
188960ea TT |
877 | inode_time_to_string(inode->i_mtime, |
878 | large_inode->i_mtime_extra)); | |
a16031c6 TT |
879 | fprintf(out, "%scrtime: 0x%08x:%08x -- %s", prefix, |
880 | large_inode->i_crtime, large_inode->i_crtime_extra, | |
188960ea TT |
881 | inode_time_to_string(large_inode->i_crtime, |
882 | large_inode->i_crtime_extra)); | |
883 | if (inode->i_dtime) | |
884 | fprintf(out, "%scrtime: 0x%08x:(%08x) -- %s", prefix, | |
885 | large_inode->i_dtime, large_inode->i_ctime_extra, | |
886 | inode_time_to_string(inode->i_dtime, | |
887 | large_inode->i_ctime_extra)); | |
a16031c6 TT |
888 | } else { |
889 | fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime, | |
188960ea | 890 | time_to_string((__s32) inode->i_ctime)); |
a16031c6 | 891 | fprintf(out, "%satime: 0x%08x -- %s", prefix, inode->i_atime, |
188960ea | 892 | time_to_string((__s32) inode->i_atime)); |
a16031c6 | 893 | fprintf(out, "%smtime: 0x%08x -- %s", prefix, inode->i_mtime, |
188960ea TT |
894 | time_to_string((__s32) inode->i_mtime)); |
895 | if (inode->i_dtime) | |
896 | fprintf(out, "%sdtime: 0x%08x -- %s", prefix, | |
897 | inode->i_dtime, | |
898 | time_to_string((__s32) inode->i_dtime)); | |
a16031c6 | 899 | } |
ea822eeb TT |
900 | if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE) |
901 | internal_dump_inode_extra(out, prefix, inode_num, | |
902 | (struct ext2_inode_large *) inode); | |
5beff1c0 | 903 | dump_inode_attributes(out, inode_num); |
6d0af0c8 | 904 | if (current_fs->super->s_creator_os == EXT2_OS_LINUX && |
4ee26699 | 905 | ext2fs_has_feature_metadata_csum(current_fs->super)) { |
6d0af0c8 DW |
906 | __u32 crc = inode->i_checksum_lo; |
907 | if (is_large_inode && | |
908 | large_inode->i_extra_isize >= | |
909 | (offsetof(struct ext2_inode_large, | |
910 | i_checksum_hi) - | |
911 | EXT2_GOOD_OLD_INODE_SIZE)) | |
912 | crc |= ((__u32)large_inode->i_checksum_hi) << 16; | |
913 | fprintf(out, "Inode checksum: 0x%08x\n", crc); | |
914 | } | |
915 | ||
32873173 | 916 | if (LINUX_S_ISLNK(inode->i_mode) && |
7ba5cc74 DW |
917 | ext2fs_inode_data_blocks(current_fs, inode) == 0) |
918 | dump_fast_link(out, inode_num, inode, prefix); | |
2d10769e TT |
919 | else if (LINUX_S_ISBLK(inode->i_mode) || LINUX_S_ISCHR(inode->i_mode)) { |
920 | int major, minor; | |
921 | const char *devnote; | |
922 | ||
923 | if (inode->i_block[0]) { | |
924 | major = (inode->i_block[0] >> 8) & 255; | |
925 | minor = inode->i_block[0] & 255; | |
926 | devnote = ""; | |
927 | } else { | |
928 | major = (inode->i_block[1] & 0xfff00) >> 8; | |
efc6f628 | 929 | minor = ((inode->i_block[1] & 0xff) | |
2d10769e TT |
930 | ((inode->i_block[1] >> 12) & 0xfff00)); |
931 | devnote = "(New-style) "; | |
932 | } | |
efc6f628 | 933 | fprintf(out, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n", |
2d10769e | 934 | devnote, major, minor, major, minor); |
187cb623 TT |
935 | } else if (do_dump_blocks) { |
936 | if (inode->i_flags & EXT4_EXTENTS_FL) | |
937 | dump_extents(out, prefix, inode_num, | |
c4b87b8c | 938 | DUMP_LEAF_EXTENTS|DUMP_NODE_EXTENTS, 0, 0); |
133e9462 ZL |
939 | else if (inode->i_flags & EXT4_INLINE_DATA_FL) |
940 | dump_inline_data(out, prefix, inode_num); | |
187cb623 TT |
941 | else |
942 | dump_blocks(out, prefix, inode_num); | |
2d10769e | 943 | } |
da81e3fc TT |
944 | } |
945 | ||
ea822eeb | 946 | static void dump_inode(ext2_ino_t inode_num, struct ext2_inode *inode) |
da81e3fc TT |
947 | { |
948 | FILE *out; | |
efc6f628 | 949 | |
da81e3fc | 950 | out = open_pager(); |
ea822eeb | 951 | internal_dump_inode(out, "", inode_num, inode, 1); |
3839e657 TT |
952 | close_pager(out); |
953 | } | |
954 | ||
3839e657 TT |
955 | void do_stat(int argc, char *argv[]) |
956 | { | |
b044c2e0 | 957 | ext2_ino_t inode; |
ea822eeb | 958 | struct ext2_inode * inode_buf; |
3839e657 | 959 | |
64777391 | 960 | if (check_fs_open(argv[0])) |
8363e357 | 961 | return; |
64777391 | 962 | |
ea822eeb TT |
963 | inode_buf = (struct ext2_inode *) |
964 | malloc(EXT2_INODE_SIZE(current_fs->super)); | |
965 | if (!inode_buf) { | |
966 | fprintf(stderr, "do_stat: can't allocate buffer\n"); | |
3839e657 | 967 | return; |
ea822eeb | 968 | } |
3839e657 | 969 | |
ea822eeb TT |
970 | if (common_inode_args_process(argc, argv, &inode, 0)) { |
971 | free(inode_buf); | |
972 | return; | |
973 | } | |
974 | ||
975 | if (debugfs_read_inode_full(inode, inode_buf, argv[0], | |
976 | EXT2_INODE_SIZE(current_fs->super))) { | |
977 | free(inode_buf); | |
e1018eea | 978 | return; |
ea822eeb | 979 | } |
3839e657 | 980 | |
ea822eeb TT |
981 | dump_inode(inode, inode_buf); |
982 | free(inode_buf); | |
3839e657 TT |
983 | return; |
984 | } | |
985 | ||
cf5301d7 | 986 | void do_dump_extents(int argc, char **argv) |
187cb623 TT |
987 | { |
988 | struct ext2_inode inode; | |
989 | ext2_ino_t ino; | |
990 | FILE *out; | |
991 | int c, flags = 0; | |
992 | int logical_width; | |
993 | int physical_width; | |
994 | ||
995 | reset_getopt(); | |
996 | while ((c = getopt(argc, argv, "nl")) != EOF) { | |
997 | switch (c) { | |
998 | case 'n': | |
999 | flags |= DUMP_NODE_EXTENTS; | |
1000 | break; | |
1001 | case 'l': | |
1002 | flags |= DUMP_LEAF_EXTENTS; | |
1003 | break; | |
1004 | } | |
1005 | } | |
1006 | ||
cf5301d7 | 1007 | if (argc != optind + 1) { |
187cb623 TT |
1008 | com_err(0, 0, "Usage: dump_extents [-n] [-l] file"); |
1009 | return; | |
1010 | } | |
1011 | ||
1012 | if (flags == 0) | |
1013 | flags = DUMP_NODE_EXTENTS | DUMP_LEAF_EXTENTS; | |
1014 | flags |= DUMP_EXTENT_TABLE; | |
1015 | ||
1016 | if (check_fs_open(argv[0])) | |
1017 | return; | |
1018 | ||
1019 | ino = string_to_inode(argv[optind]); | |
1020 | if (ino == 0) | |
1021 | return; | |
1022 | ||
1023 | if (debugfs_read_inode(ino, &inode, argv[0])) | |
1024 | return; | |
1025 | ||
1026 | if ((inode.i_flags & EXT4_EXTENTS_FL) == 0) { | |
1027 | fprintf(stderr, "%s: does not uses extent block maps\n", | |
1028 | argv[optind]); | |
1029 | return; | |
1030 | } | |
1031 | ||
0bd0e593 | 1032 | logical_width = int_log10((EXT2_I_SIZE(&inode)+current_fs->blocksize-1)/ |
187cb623 TT |
1033 | current_fs->blocksize) + 1; |
1034 | if (logical_width < 5) | |
1035 | logical_width = 5; | |
4efbac6f | 1036 | physical_width = int_log10(ext2fs_blocks_count(current_fs->super)) + 1; |
187cb623 TT |
1037 | if (physical_width < 5) |
1038 | physical_width = 5; | |
1039 | ||
1040 | out = open_pager(); | |
1041 | dump_extents(out, "", ino, flags, logical_width, physical_width); | |
1042 | close_pager(out); | |
1043 | return; | |
1044 | } | |
1045 | ||
af0df2aa TT |
1046 | static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)), |
1047 | blk64_t *blocknr, | |
3cebf9c1 | 1048 | e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), |
af0df2aa TT |
1049 | blk64_t ref_block EXT2FS_ATTR((unused)), |
1050 | int ref_offset EXT2FS_ATTR((unused)), | |
1051 | void *private EXT2FS_ATTR((unused))) | |
1052 | { | |
1053 | printf("%llu ", *blocknr); | |
1054 | return 0; | |
1055 | } | |
1056 | ||
1057 | void do_blocks(int argc, char *argv[]) | |
1058 | { | |
1059 | ext2_ino_t inode; | |
1060 | ||
1061 | if (check_fs_open(argv[0])) | |
1062 | return; | |
1063 | ||
1064 | if (common_inode_args_process(argc, argv, &inode, 0)) { | |
1065 | return; | |
1066 | } | |
1067 | ||
1068 | ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL, | |
1069 | print_blocks_proc, NULL); | |
1070 | fputc('\n', stdout); | |
1071 | return; | |
1072 | } | |
1073 | ||
3839e657 TT |
1074 | void do_chroot(int argc, char *argv[]) |
1075 | { | |
b044c2e0 | 1076 | ext2_ino_t inode; |
3839e657 TT |
1077 | int retval; |
1078 | ||
e1018eea | 1079 | if (common_inode_args_process(argc, argv, &inode, 0)) |
3839e657 TT |
1080 | return; |
1081 | ||
fc6d9d51 | 1082 | retval = ext2fs_check_directory(current_fs, inode); |
3839e657 | 1083 | if (retval) { |
9b9a780f | 1084 | com_err(argv[1], retval, 0); |
3839e657 TT |
1085 | return; |
1086 | } | |
1087 | root = inode; | |
1088 | } | |
1089 | ||
e88c5a33 | 1090 | #ifndef READ_ONLY |
3839e657 TT |
1091 | void do_clri(int argc, char *argv[]) |
1092 | { | |
b044c2e0 | 1093 | ext2_ino_t inode; |
3839e657 TT |
1094 | struct ext2_inode inode_buf; |
1095 | ||
e1018eea | 1096 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW)) |
3839e657 TT |
1097 | return; |
1098 | ||
e1018eea | 1099 | if (debugfs_read_inode(inode, &inode_buf, argv[0])) |
3839e657 | 1100 | return; |
3839e657 | 1101 | memset(&inode_buf, 0, sizeof(inode_buf)); |
e1018eea | 1102 | if (debugfs_write_inode(inode, &inode_buf, argv[0])) |
3839e657 | 1103 | return; |
3839e657 TT |
1104 | } |
1105 | ||
1106 | void do_freei(int argc, char *argv[]) | |
1107 | { | |
2ae5d1fd TT |
1108 | unsigned int len = 1; |
1109 | int err = 0; | |
1110 | ext2_ino_t inode; | |
1111 | ||
1112 | if (common_args_process(argc, argv, 2, 3, argv[0], "<file> [num]", | |
1113 | CHECK_FS_RW | CHECK_FS_BITMAPS)) | |
e64e6761 | 1114 | return; |
2ae5d1fd TT |
1115 | if (check_fs_read_write(argv[0])) |
1116 | return; | |
3839e657 | 1117 | |
2ae5d1fd TT |
1118 | inode = string_to_inode(argv[1]); |
1119 | if (!inode) | |
3839e657 TT |
1120 | return; |
1121 | ||
2ae5d1fd TT |
1122 | if (argc == 3) { |
1123 | len = parse_ulong(argv[2], argv[0], "length", &err); | |
1124 | if (err) | |
1125 | return; | |
1126 | } | |
1127 | ||
1128 | if (len == 1 && | |
1129 | !ext2fs_test_inode_bitmap2(current_fs->inode_map,inode)) | |
3839e657 | 1130 | com_err(argv[0], 0, "Warning: inode already clear"); |
2ae5d1fd | 1131 | while (len-- > 0) |
a9b23fc9 | 1132 | ext2fs_unmark_inode_bitmap2(current_fs->inode_map, inode++); |
fc6d9d51 | 1133 | ext2fs_mark_ib_dirty(current_fs); |
3839e657 TT |
1134 | } |
1135 | ||
1136 | void do_seti(int argc, char *argv[]) | |
1137 | { | |
2ae5d1fd TT |
1138 | unsigned int len = 1; |
1139 | int err = 0; | |
1140 | ext2_ino_t inode; | |
3839e657 | 1141 | |
2ae5d1fd TT |
1142 | if (common_args_process(argc, argv, 2, 3, argv[0], "<file> [num]", |
1143 | CHECK_FS_RW | CHECK_FS_BITMAPS)) | |
1144 | return; | |
1145 | if (check_fs_read_write(argv[0])) | |
3839e657 TT |
1146 | return; |
1147 | ||
2ae5d1fd TT |
1148 | inode = string_to_inode(argv[1]); |
1149 | if (!inode) | |
1150 | return; | |
1151 | ||
1152 | if (argc == 3) { | |
1153 | len = parse_ulong(argv[2], argv[0], "length", &err); | |
1154 | if (err) | |
1155 | return; | |
1156 | } | |
1157 | ||
1158 | if ((len == 1) && | |
1159 | ext2fs_test_inode_bitmap2(current_fs->inode_map,inode)) | |
3839e657 | 1160 | com_err(argv[0], 0, "Warning: inode already set"); |
2ae5d1fd TT |
1161 | while (len-- > 0) |
1162 | ext2fs_mark_inode_bitmap2(current_fs->inode_map, inode++); | |
fc6d9d51 | 1163 | ext2fs_mark_ib_dirty(current_fs); |
3839e657 | 1164 | } |
e88c5a33 | 1165 | #endif /* READ_ONLY */ |
3839e657 TT |
1166 | |
1167 | void do_testi(int argc, char *argv[]) | |
1168 | { | |
b044c2e0 | 1169 | ext2_ino_t inode; |
3839e657 | 1170 | |
e1018eea | 1171 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_BITMAPS)) |
3839e657 TT |
1172 | return; |
1173 | ||
6d879a99 | 1174 | if (ext2fs_test_inode_bitmap2(current_fs->inode_map,inode)) |
b044c2e0 | 1175 | printf("Inode %u is marked in use\n", inode); |
3839e657 | 1176 | else |
b044c2e0 | 1177 | printf("Inode %u is not in use\n", inode); |
3839e657 TT |
1178 | } |
1179 | ||
e88c5a33 | 1180 | #ifndef READ_ONLY |
3839e657 TT |
1181 | void do_freeb(int argc, char *argv[]) |
1182 | { | |
048786d7 VAH |
1183 | blk64_t block; |
1184 | blk64_t count = 1; | |
3839e657 | 1185 | |
e1018eea | 1186 | if (common_block_args_process(argc, argv, &block, &count)) |
3839e657 | 1187 | return; |
fc6d9d51 | 1188 | if (check_fs_read_write(argv[0])) |
3839e657 | 1189 | return; |
e1018eea | 1190 | while (count-- > 0) { |
6d879a99 | 1191 | if (!ext2fs_test_block_bitmap2(current_fs->block_map,block)) |
048786d7 | 1192 | com_err(argv[0], 0, "Warning: block %llu already clear", |
e1018eea | 1193 | block); |
6d879a99 | 1194 | ext2fs_unmark_block_bitmap2(current_fs->block_map,block); |
e1018eea TT |
1195 | block++; |
1196 | } | |
fc6d9d51 | 1197 | ext2fs_mark_bb_dirty(current_fs); |
3839e657 TT |
1198 | } |
1199 | ||
1200 | void do_setb(int argc, char *argv[]) | |
1201 | { | |
048786d7 VAH |
1202 | blk64_t block; |
1203 | blk64_t count = 1; | |
3839e657 | 1204 | |
e1018eea | 1205 | if (common_block_args_process(argc, argv, &block, &count)) |
3839e657 | 1206 | return; |
fc6d9d51 | 1207 | if (check_fs_read_write(argv[0])) |
3839e657 | 1208 | return; |
e1018eea | 1209 | while (count-- > 0) { |
6d879a99 | 1210 | if (ext2fs_test_block_bitmap2(current_fs->block_map,block)) |
048786d7 | 1211 | com_err(argv[0], 0, "Warning: block %llu already set", |
e1018eea | 1212 | block); |
6d879a99 | 1213 | ext2fs_mark_block_bitmap2(current_fs->block_map,block); |
e1018eea TT |
1214 | block++; |
1215 | } | |
fc6d9d51 | 1216 | ext2fs_mark_bb_dirty(current_fs); |
3839e657 | 1217 | } |
e88c5a33 | 1218 | #endif /* READ_ONLY */ |
3839e657 TT |
1219 | |
1220 | void do_testb(int argc, char *argv[]) | |
1221 | { | |
048786d7 VAH |
1222 | blk64_t block; |
1223 | blk64_t count = 1; | |
3839e657 | 1224 | |
e1018eea | 1225 | if (common_block_args_process(argc, argv, &block, &count)) |
3839e657 | 1226 | return; |
e1018eea | 1227 | while (count-- > 0) { |
6d879a99 | 1228 | if (ext2fs_test_block_bitmap2(current_fs->block_map,block)) |
048786d7 | 1229 | printf("Block %llu marked in use\n", block); |
e1018eea | 1230 | else |
048786d7 | 1231 | printf("Block %llu not in use\n", block); |
e1018eea | 1232 | block++; |
3839e657 | 1233 | } |
3839e657 TT |
1234 | } |
1235 | ||
e88c5a33 | 1236 | #ifndef READ_ONLY |
50e1e10f TT |
1237 | static void modify_u8(char *com, const char *prompt, |
1238 | const char *format, __u8 *val) | |
3839e657 TT |
1239 | { |
1240 | char buf[200]; | |
21c84b71 | 1241 | unsigned long v; |
3839e657 TT |
1242 | char *tmp; |
1243 | ||
1244 | sprintf(buf, format, *val); | |
1245 | printf("%30s [%s] ", prompt, buf); | |
d9039ae0 DL |
1246 | if (!fgets(buf, sizeof(buf), stdin)) |
1247 | return; | |
3839e657 TT |
1248 | if (buf[strlen (buf) - 1] == '\n') |
1249 | buf[strlen (buf) - 1] = '\0'; | |
1250 | if (!buf[0]) | |
1251 | return; | |
21c84b71 | 1252 | v = strtoul(buf, &tmp, 0); |
3839e657 TT |
1253 | if (*tmp) |
1254 | com_err(com, 0, "Bad value - %s", buf); | |
1255 | else | |
1256 | *val = v; | |
1257 | } | |
1258 | ||
50e1e10f TT |
1259 | static void modify_u16(char *com, const char *prompt, |
1260 | const char *format, __u16 *val) | |
3839e657 TT |
1261 | { |
1262 | char buf[200]; | |
21c84b71 | 1263 | unsigned long v; |
3839e657 TT |
1264 | char *tmp; |
1265 | ||
1266 | sprintf(buf, format, *val); | |
1267 | printf("%30s [%s] ", prompt, buf); | |
d9039ae0 DL |
1268 | if (!fgets(buf, sizeof(buf), stdin)) |
1269 | return; | |
3839e657 TT |
1270 | if (buf[strlen (buf) - 1] == '\n') |
1271 | buf[strlen (buf) - 1] = '\0'; | |
1272 | if (!buf[0]) | |
1273 | return; | |
21c84b71 | 1274 | v = strtoul(buf, &tmp, 0); |
3839e657 TT |
1275 | if (*tmp) |
1276 | com_err(com, 0, "Bad value - %s", buf); | |
1277 | else | |
1278 | *val = v; | |
1279 | } | |
1280 | ||
50e1e10f TT |
1281 | static void modify_u32(char *com, const char *prompt, |
1282 | const char *format, __u32 *val) | |
3839e657 TT |
1283 | { |
1284 | char buf[200]; | |
21c84b71 | 1285 | unsigned long v; |
3839e657 TT |
1286 | char *tmp; |
1287 | ||
1288 | sprintf(buf, format, *val); | |
1289 | printf("%30s [%s] ", prompt, buf); | |
d9039ae0 DL |
1290 | if (!fgets(buf, sizeof(buf), stdin)) |
1291 | return; | |
3839e657 TT |
1292 | if (buf[strlen (buf) - 1] == '\n') |
1293 | buf[strlen (buf) - 1] = '\0'; | |
1294 | if (!buf[0]) | |
1295 | return; | |
21c84b71 | 1296 | v = strtoul(buf, &tmp, 0); |
3839e657 TT |
1297 | if (*tmp) |
1298 | com_err(com, 0, "Bad value - %s", buf); | |
1299 | else | |
1300 | *val = v; | |
1301 | } | |
1302 | ||
1303 | ||
1304 | void do_modify_inode(int argc, char *argv[]) | |
1305 | { | |
1306 | struct ext2_inode inode; | |
b044c2e0 TT |
1307 | ext2_ino_t inode_num; |
1308 | int i; | |
b044c2e0 TT |
1309 | unsigned char *frag, *fsize; |
1310 | char buf[80]; | |
7380ac90 | 1311 | int os; |
b044c2e0 TT |
1312 | const char *hex_format = "0x%x"; |
1313 | const char *octal_format = "0%o"; | |
1314 | const char *decimal_format = "%d"; | |
8deb80a5 | 1315 | const char *unsignedlong_format = "%lu"; |
efc6f628 | 1316 | |
e1018eea | 1317 | if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW)) |
3839e657 TT |
1318 | return; |
1319 | ||
7380ac90 TT |
1320 | os = current_fs->super->s_creator_os; |
1321 | ||
e1018eea | 1322 | if (debugfs_read_inode(inode_num, &inode, argv[1])) |
3839e657 | 1323 | return; |
efc6f628 | 1324 | |
50e1e10f TT |
1325 | modify_u16(argv[0], "Mode", octal_format, &inode.i_mode); |
1326 | modify_u16(argv[0], "User ID", decimal_format, &inode.i_uid); | |
1327 | modify_u16(argv[0], "Group ID", decimal_format, &inode.i_gid); | |
8deb80a5 | 1328 | modify_u32(argv[0], "Size", unsignedlong_format, &inode.i_size); |
50e1e10f TT |
1329 | modify_u32(argv[0], "Creation time", decimal_format, &inode.i_ctime); |
1330 | modify_u32(argv[0], "Modification time", decimal_format, &inode.i_mtime); | |
1331 | modify_u32(argv[0], "Access time", decimal_format, &inode.i_atime); | |
1332 | modify_u32(argv[0], "Deletion time", decimal_format, &inode.i_dtime); | |
1333 | modify_u16(argv[0], "Link count", decimal_format, &inode.i_links_count); | |
5d17119d | 1334 | if (os == EXT2_OS_LINUX) |
efc6f628 | 1335 | modify_u16(argv[0], "Block count high", unsignedlong_format, |
5d17119d | 1336 | &inode.osd2.linux2.l_i_blocks_hi); |
8deb80a5 | 1337 | modify_u32(argv[0], "Block count", unsignedlong_format, &inode.i_blocks); |
50e1e10f | 1338 | modify_u32(argv[0], "File flags", hex_format, &inode.i_flags); |
3db9305a | 1339 | modify_u32(argv[0], "Generation", hex_format, &inode.i_generation); |
50e1e10f TT |
1340 | #if 0 |
1341 | modify_u32(argv[0], "Reserved1", decimal_format, &inode.i_reserved1); | |
1342 | #endif | |
1343 | modify_u32(argv[0], "File acl", decimal_format, &inode.i_file_acl); | |
36a43d67 TT |
1344 | if (LINUX_S_ISDIR(inode.i_mode)) |
1345 | modify_u32(argv[0], "Directory acl", decimal_format, &inode.i_dir_acl); | |
1346 | else | |
1347 | modify_u32(argv[0], "High 32bits of size", decimal_format, &inode.i_size_high); | |
62c06f79 | 1348 | |
5d17119d | 1349 | if (os == EXT2_OS_HURD) |
62c06f79 TT |
1350 | modify_u32(argv[0], "Translator Block", |
1351 | decimal_format, &inode.osd1.hurd1.h_i_translator); | |
efc6f628 | 1352 | |
50e1e10f | 1353 | modify_u32(argv[0], "Fragment address", decimal_format, &inode.i_faddr); |
fc6d9d51 | 1354 | switch (os) { |
fc6d9d51 TT |
1355 | case EXT2_OS_HURD: |
1356 | frag = &inode.osd2.hurd2.h_i_frag; | |
1357 | fsize = &inode.osd2.hurd2.h_i_fsize; | |
1358 | break; | |
fc6d9d51 TT |
1359 | default: |
1360 | frag = fsize = 0; | |
1361 | } | |
1362 | if (frag) | |
1363 | modify_u8(argv[0], "Fragment number", decimal_format, frag); | |
1364 | if (fsize) | |
1365 | modify_u8(argv[0], "Fragment size", decimal_format, fsize); | |
1366 | ||
3839e657 TT |
1367 | for (i=0; i < EXT2_NDIR_BLOCKS; i++) { |
1368 | sprintf(buf, "Direct Block #%d", i); | |
50e1e10f | 1369 | modify_u32(argv[0], buf, decimal_format, &inode.i_block[i]); |
3839e657 | 1370 | } |
50e1e10f | 1371 | modify_u32(argv[0], "Indirect Block", decimal_format, |
efc6f628 | 1372 | &inode.i_block[EXT2_IND_BLOCK]); |
50e1e10f | 1373 | modify_u32(argv[0], "Double Indirect Block", decimal_format, |
3839e657 | 1374 | &inode.i_block[EXT2_DIND_BLOCK]); |
50e1e10f | 1375 | modify_u32(argv[0], "Triple Indirect Block", decimal_format, |
3839e657 | 1376 | &inode.i_block[EXT2_TIND_BLOCK]); |
e1018eea | 1377 | if (debugfs_write_inode(inode_num, &inode, argv[1])) |
3839e657 | 1378 | return; |
3839e657 | 1379 | } |
e88c5a33 | 1380 | #endif /* READ_ONLY */ |
3839e657 | 1381 | |
3839e657 TT |
1382 | void do_change_working_dir(int argc, char *argv[]) |
1383 | { | |
b044c2e0 TT |
1384 | ext2_ino_t inode; |
1385 | int retval; | |
efc6f628 | 1386 | |
e1018eea | 1387 | if (common_inode_args_process(argc, argv, &inode, 0)) |
3839e657 TT |
1388 | return; |
1389 | ||
fc6d9d51 | 1390 | retval = ext2fs_check_directory(current_fs, inode); |
3839e657 | 1391 | if (retval) { |
9b9a780f | 1392 | com_err(argv[1], retval, 0); |
3839e657 TT |
1393 | return; |
1394 | } | |
1395 | cwd = inode; | |
1396 | return; | |
1397 | } | |
1398 | ||
3839e657 TT |
1399 | void do_print_working_directory(int argc, char *argv[]) |
1400 | { | |
1401 | int retval; | |
1402 | char *pathname = NULL; | |
efc6f628 | 1403 | |
e1018eea TT |
1404 | if (common_args_process(argc, argv, 1, 1, |
1405 | "print_working_directory", "", 0)) | |
3839e657 TT |
1406 | return; |
1407 | ||
fc6d9d51 | 1408 | retval = ext2fs_get_pathname(current_fs, cwd, 0, &pathname); |
3839e657 TT |
1409 | if (retval) { |
1410 | com_err(argv[0], retval, | |
1411 | "while trying to get pathname of cwd"); | |
1412 | } | |
971fe056 BB |
1413 | printf("[pwd] INODE: %6u PATH: %s\n", |
1414 | cwd, pathname ? pathname : "NULL"); | |
1415 | if (pathname) { | |
1416 | free(pathname); | |
1417 | pathname = NULL; | |
1418 | } | |
fc6d9d51 | 1419 | retval = ext2fs_get_pathname(current_fs, root, 0, &pathname); |
3839e657 TT |
1420 | if (retval) { |
1421 | com_err(argv[0], retval, | |
1422 | "while trying to get pathname of root"); | |
1423 | } | |
971fe056 BB |
1424 | printf("[root] INODE: %6u PATH: %s\n", |
1425 | root, pathname ? pathname : "NULL"); | |
1426 | if (pathname) { | |
1427 | free(pathname); | |
1428 | pathname = NULL; | |
1429 | } | |
3839e657 TT |
1430 | return; |
1431 | } | |
1432 | ||
3cebf9c1 | 1433 | #ifndef READ_ONLY |
50e1e10f | 1434 | static void make_link(char *sourcename, char *destname) |
3839e657 | 1435 | { |
abdf84f3 TT |
1436 | ext2_ino_t ino; |
1437 | struct ext2_inode inode; | |
b044c2e0 TT |
1438 | int retval; |
1439 | ext2_ino_t dir; | |
d4e0b1c6 | 1440 | char *dest, *cp, *base_name; |
3839e657 TT |
1441 | |
1442 | /* | |
1443 | * Get the source inode | |
1444 | */ | |
abdf84f3 TT |
1445 | ino = string_to_inode(sourcename); |
1446 | if (!ino) | |
3839e657 | 1447 | return; |
d4e0b1c6 TT |
1448 | base_name = strrchr(sourcename, '/'); |
1449 | if (base_name) | |
1450 | base_name++; | |
3839e657 | 1451 | else |
d4e0b1c6 | 1452 | base_name = sourcename; |
3839e657 TT |
1453 | /* |
1454 | * Figure out the destination. First see if it exists and is | |
efc6f628 | 1455 | * a directory. |
3839e657 | 1456 | */ |
fc6d9d51 | 1457 | if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir))) |
d4e0b1c6 | 1458 | dest = base_name; |
3839e657 TT |
1459 | else { |
1460 | /* | |
1461 | * OK, it doesn't exist. See if it is | |
1462 | * '<dir>/basename' or 'basename' | |
1463 | */ | |
1464 | cp = strrchr(destname, '/'); | |
1465 | if (cp) { | |
1466 | *cp = 0; | |
1467 | dir = string_to_inode(destname); | |
1468 | if (!dir) | |
1469 | return; | |
1470 | dest = cp+1; | |
1471 | } else { | |
1472 | dir = cwd; | |
1473 | dest = destname; | |
1474 | } | |
1475 | } | |
abdf84f3 TT |
1476 | |
1477 | if (debugfs_read_inode(ino, &inode, sourcename)) | |
1478 | return; | |
efc6f628 TT |
1479 | |
1480 | retval = ext2fs_link(current_fs, dir, dest, ino, | |
abdf84f3 | 1481 | ext2_file_type(inode.i_mode)); |
3839e657 | 1482 | if (retval) |
9b9a780f | 1483 | com_err("make_link", retval, 0); |
3839e657 TT |
1484 | return; |
1485 | } | |
1486 | ||
1487 | ||
1488 | void do_link(int argc, char *argv[]) | |
1489 | { | |
e1018eea TT |
1490 | if (common_args_process(argc, argv, 3, 3, "link", |
1491 | "<source file> <dest_name>", CHECK_FS_RW)) | |
1492 | return; | |
1493 | ||
1494 | make_link(argv[1], argv[2]); | |
1495 | } | |
1496 | ||
048786d7 VAH |
1497 | static int mark_blocks_proc(ext2_filsys fs, blk64_t *blocknr, |
1498 | e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), | |
1499 | blk64_t ref_block EXT2FS_ATTR((unused)), | |
1500 | int ref_offset EXT2FS_ATTR((unused)), | |
54434927 | 1501 | void *private EXT2FS_ATTR((unused))) |
e1018eea | 1502 | { |
048786d7 | 1503 | blk64_t block; |
e1018eea TT |
1504 | |
1505 | block = *blocknr; | |
048786d7 | 1506 | ext2fs_block_alloc_stats2(fs, block, +1); |
e1018eea TT |
1507 | return 0; |
1508 | } | |
1509 | ||
1510 | void do_undel(int argc, char *argv[]) | |
1511 | { | |
1512 | ext2_ino_t ino; | |
1513 | struct ext2_inode inode; | |
e1018eea | 1514 | |
b026d539 TT |
1515 | if (common_args_process(argc, argv, 2, 3, "undelete", |
1516 | "<inode_num> [dest_name]", | |
e1018eea TT |
1517 | CHECK_FS_RW | CHECK_FS_BITMAPS)) |
1518 | return; | |
1519 | ||
1520 | ino = string_to_inode(argv[1]); | |
1521 | if (!ino) | |
1522 | return; | |
1523 | ||
1524 | if (debugfs_read_inode(ino, &inode, argv[1])) | |
1525 | return; | |
1526 | ||
6d879a99 | 1527 | if (ext2fs_test_inode_bitmap2(current_fs->inode_map, ino)) { |
e1018eea | 1528 | com_err(argv[1], 0, "Inode is not marked as deleted"); |
3839e657 TT |
1529 | return; |
1530 | } | |
e1018eea TT |
1531 | |
1532 | /* | |
1533 | * XXX this function doesn't handle changing the links count on the | |
efc6f628 | 1534 | * parent directory when undeleting a directory. |
e1018eea TT |
1535 | */ |
1536 | inode.i_links_count = LINUX_S_ISDIR(inode.i_mode) ? 2 : 1; | |
1537 | inode.i_dtime = 0; | |
1538 | ||
1539 | if (debugfs_write_inode(ino, &inode, argv[0])) | |
3839e657 TT |
1540 | return; |
1541 | ||
048786d7 VAH |
1542 | ext2fs_block_iterate3(current_fs, ino, BLOCK_FLAG_READ_ONLY, NULL, |
1543 | mark_blocks_proc, NULL); | |
e1018eea | 1544 | |
d7f64ae8 | 1545 | ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0); |
e1018eea | 1546 | |
b026d539 TT |
1547 | if (argc > 2) |
1548 | make_link(argv[1], argv[2]); | |
3839e657 TT |
1549 | } |
1550 | ||
50e1e10f | 1551 | static void unlink_file_by_name(char *filename) |
3839e657 | 1552 | { |
b044c2e0 TT |
1553 | int retval; |
1554 | ext2_ino_t dir; | |
d4e0b1c6 | 1555 | char *base_name; |
efc6f628 | 1556 | |
d4e0b1c6 TT |
1557 | base_name = strrchr(filename, '/'); |
1558 | if (base_name) { | |
1559 | *base_name++ = '\0'; | |
3839e657 TT |
1560 | dir = string_to_inode(filename); |
1561 | if (!dir) | |
1562 | return; | |
1563 | } else { | |
1564 | dir = cwd; | |
d4e0b1c6 | 1565 | base_name = filename; |
3839e657 | 1566 | } |
d4e0b1c6 | 1567 | retval = ext2fs_unlink(current_fs, dir, base_name, 0, 0); |
3839e657 | 1568 | if (retval) |
9b9a780f | 1569 | com_err("unlink_file_by_name", retval, 0); |
3839e657 TT |
1570 | return; |
1571 | } | |
1572 | ||
1573 | void do_unlink(int argc, char *argv[]) | |
1574 | { | |
e1018eea TT |
1575 | if (common_args_process(argc, argv, 2, 2, "link", |
1576 | "<pathname>", CHECK_FS_RW)) | |
3839e657 TT |
1577 | return; |
1578 | ||
1579 | unlink_file_by_name(argv[1]); | |
1580 | } | |
e88c5a33 | 1581 | #endif /* READ_ONLY */ |
3839e657 TT |
1582 | |
1583 | void do_find_free_block(int argc, char *argv[]) | |
1584 | { | |
048786d7 | 1585 | blk64_t free_blk, goal, first_free = 0; |
e1018eea | 1586 | int count; |
3839e657 TT |
1587 | errcode_t retval; |
1588 | char *tmp; | |
efc6f628 | 1589 | |
e1018eea TT |
1590 | if ((argc > 3) || (argc==2 && *argv[1] == '?')) { |
1591 | com_err(argv[0], 0, "Usage: find_free_block [count [goal]]"); | |
3839e657 TT |
1592 | return; |
1593 | } | |
1594 | if (check_fs_open(argv[0])) | |
1595 | return; | |
1596 | ||
1597 | if (argc > 1) { | |
e1018eea TT |
1598 | count = strtol(argv[1],&tmp,0); |
1599 | if (*tmp) { | |
1600 | com_err(argv[0], 0, "Bad count - %s", argv[1]); | |
1601 | return; | |
1602 | } | |
1603 | } else | |
1604 | count = 1; | |
1605 | ||
1606 | if (argc > 2) { | |
1607 | goal = strtol(argv[2], &tmp, 0); | |
3839e657 TT |
1608 | if (*tmp) { |
1609 | com_err(argv[0], 0, "Bad goal - %s", argv[1]); | |
1610 | return; | |
1611 | } | |
1612 | } | |
1613 | else | |
fc6d9d51 | 1614 | goal = current_fs->super->s_first_data_block; |
3839e657 | 1615 | |
e1018eea | 1616 | printf("Free blocks found: "); |
efc6f628 | 1617 | free_blk = goal - 1; |
e1018eea | 1618 | while (count-- > 0) { |
048786d7 VAH |
1619 | retval = ext2fs_new_block2(current_fs, free_blk + 1, 0, |
1620 | &free_blk); | |
5aae7c29 TT |
1621 | if (first_free) { |
1622 | if (first_free == free_blk) | |
1623 | break; | |
1624 | } else | |
1625 | first_free = free_blk; | |
e1018eea | 1626 | if (retval) { |
9b9a780f | 1627 | com_err("ext2fs_new_block", retval, 0); |
e1018eea TT |
1628 | return; |
1629 | } else | |
048786d7 | 1630 | printf("%llu ", free_blk); |
e1018eea TT |
1631 | } |
1632 | printf("\n"); | |
3839e657 TT |
1633 | } |
1634 | ||
1635 | void do_find_free_inode(int argc, char *argv[]) | |
1636 | { | |
b044c2e0 TT |
1637 | ext2_ino_t free_inode, dir; |
1638 | int mode; | |
1639 | int retval; | |
1640 | char *tmp; | |
efc6f628 | 1641 | |
50e1e10f TT |
1642 | if (argc > 3 || (argc>1 && *argv[1] == '?')) { |
1643 | com_err(argv[0], 0, "Usage: find_free_inode [dir] [mode]"); | |
3839e657 TT |
1644 | return; |
1645 | } | |
1646 | if (check_fs_open(argv[0])) | |
1647 | return; | |
1648 | ||
1649 | if (argc > 1) { | |
1650 | dir = strtol(argv[1], &tmp, 0); | |
1651 | if (*tmp) { | |
1652 | com_err(argv[0], 0, "Bad dir - %s", argv[1]); | |
1653 | return; | |
1654 | } | |
1655 | } | |
1656 | else | |
1657 | dir = root; | |
1658 | if (argc > 2) { | |
1659 | mode = strtol(argv[2], &tmp, 0); | |
1660 | if (*tmp) { | |
1661 | com_err(argv[0], 0, "Bad mode - %s", argv[2]); | |
1662 | return; | |
1663 | } | |
50e1e10f | 1664 | } else |
3839e657 TT |
1665 | mode = 010755; |
1666 | ||
fc6d9d51 | 1667 | retval = ext2fs_new_inode(current_fs, dir, mode, 0, &free_inode); |
3839e657 | 1668 | if (retval) |
9b9a780f | 1669 | com_err("ext2fs_new_inode", retval, 0); |
3839e657 | 1670 | else |
b044c2e0 | 1671 | printf("Free inode found: %u\n", free_inode); |
3839e657 TT |
1672 | } |
1673 | ||
e88c5a33 | 1674 | #ifndef READ_ONLY |
50e1e10f TT |
1675 | void do_write(int argc, char *argv[]) |
1676 | { | |
b044c2e0 | 1677 | errcode_t retval; |
50e1e10f | 1678 | |
e1018eea TT |
1679 | if (common_args_process(argc, argv, 3, 3, "write", |
1680 | "<native file> <new file>", CHECK_FS_RW)) | |
50e1e10f | 1681 | return; |
e1018eea | 1682 | |
a3111e80 DW |
1683 | retval = do_write_internal(current_fs, cwd, argv[1], argv[2], root); |
1684 | if (retval) | |
9b9a780f | 1685 | com_err(argv[0], retval, 0); |
50e1e10f TT |
1686 | } |
1687 | ||
1688 | void do_mknod(int argc, char *argv[]) | |
1689 | { | |
c4c9bc59 | 1690 | unsigned long major, minor; |
b044c2e0 | 1691 | errcode_t retval; |
c4c9bc59 | 1692 | int nr; |
9aa3aa8d | 1693 | struct stat st; |
50e1e10f TT |
1694 | |
1695 | if (check_fs_open(argv[0])) | |
1696 | return; | |
1697 | if (argc < 3 || argv[2][1]) { | |
e1018eea | 1698 | usage: |
50e1e10f TT |
1699 | com_err(argv[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]"); |
1700 | return; | |
1701 | } | |
9aa3aa8d | 1702 | |
c4c9bc59 | 1703 | minor = major = 0; |
50e1e10f TT |
1704 | switch (argv[2][0]) { |
1705 | case 'p': | |
9aa3aa8d | 1706 | st.st_mode = S_IFIFO; |
50e1e10f TT |
1707 | nr = 3; |
1708 | break; | |
1709 | case 'c': | |
9aa3aa8d | 1710 | st.st_mode = S_IFCHR; |
50e1e10f TT |
1711 | nr = 5; |
1712 | break; | |
1713 | case 'b': | |
9aa3aa8d | 1714 | st.st_mode = S_IFBLK; |
50e1e10f TT |
1715 | nr = 5; |
1716 | break; | |
1717 | default: | |
1718 | nr = 0; | |
1719 | } | |
9aa3aa8d | 1720 | |
50e1e10f TT |
1721 | if (nr == 5) { |
1722 | major = strtoul(argv[3], argv+3, 0); | |
1723 | minor = strtoul(argv[4], argv+4, 0); | |
2d10769e | 1724 | if (major > 65535 || minor > 65535 || argv[3][0] || argv[4][0]) |
50e1e10f TT |
1725 | nr = 0; |
1726 | } | |
9aa3aa8d | 1727 | |
e1018eea TT |
1728 | if (argc != nr) |
1729 | goto usage; | |
9aa3aa8d RY |
1730 | |
1731 | st.st_rdev = makedev(major, minor); | |
a3111e80 DW |
1732 | retval = do_mknod_internal(current_fs, cwd, argv[1], &st); |
1733 | if (retval) | |
9b9a780f | 1734 | com_err(argv[0], retval, 0); |
50e1e10f TT |
1735 | } |
1736 | ||
3839e657 TT |
1737 | void do_mkdir(int argc, char *argv[]) |
1738 | { | |
3839e657 TT |
1739 | errcode_t retval; |
1740 | ||
e1018eea TT |
1741 | if (common_args_process(argc, argv, 2, 2, "mkdir", |
1742 | "<filename>", CHECK_FS_RW)) | |
d3aea7dc TT |
1743 | return; |
1744 | ||
25f291c9 | 1745 | retval = do_mkdir_internal(current_fs, cwd, argv[1], root); |
a3111e80 | 1746 | if (retval) |
9aa3aa8d | 1747 | com_err(argv[0], retval, 0); |
3839e657 TT |
1748 | |
1749 | } | |
1750 | ||
048786d7 VAH |
1751 | static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr, |
1752 | e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), | |
1753 | blk64_t ref_block EXT2FS_ATTR((unused)), | |
1754 | int ref_offset EXT2FS_ATTR((unused)), | |
54434927 | 1755 | void *private EXT2FS_ATTR((unused))) |
3839e657 | 1756 | { |
048786d7 | 1757 | blk64_t block; |
34436891 TT |
1758 | |
1759 | block = *blocknr; | |
048786d7 | 1760 | ext2fs_block_alloc_stats2(fs, block, -1); |
3839e657 TT |
1761 | return 0; |
1762 | } | |
1763 | ||
b044c2e0 | 1764 | static void kill_file_by_inode(ext2_ino_t inode) |
3839e657 TT |
1765 | { |
1766 | struct ext2_inode inode_buf; | |
1767 | ||
e1018eea TT |
1768 | if (debugfs_read_inode(inode, &inode_buf, 0)) |
1769 | return; | |
4efae606 | 1770 | inode_buf.i_dtime = current_fs->now ? current_fs->now : time(0); |
e1018eea TT |
1771 | if (debugfs_write_inode(inode, &inode_buf, 0)) |
1772 | return; | |
716a3c35 ZL |
1773 | if (ext2fs_inode_has_valid_blocks2(current_fs, &inode_buf)) { |
1774 | ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, | |
1775 | NULL, release_blocks_proc, NULL); | |
1776 | } | |
521e3685 | 1777 | printf("\n"); |
d7f64ae8 TT |
1778 | ext2fs_inode_alloc_stats2(current_fs, inode, -1, |
1779 | LINUX_S_ISDIR(inode_buf.i_mode)); | |
3839e657 TT |
1780 | } |
1781 | ||
1782 | ||
1783 | void do_kill_file(int argc, char *argv[]) | |
1784 | { | |
b044c2e0 | 1785 | ext2_ino_t inode_num; |
3839e657 | 1786 | |
e1018eea | 1787 | if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW)) |
3839e657 TT |
1788 | return; |
1789 | ||
3839e657 TT |
1790 | kill_file_by_inode(inode_num); |
1791 | } | |
1792 | ||
1793 | void do_rm(int argc, char *argv[]) | |
1794 | { | |
1795 | int retval; | |
b044c2e0 | 1796 | ext2_ino_t inode_num; |
3839e657 TT |
1797 | struct ext2_inode inode; |
1798 | ||
e1018eea TT |
1799 | if (common_args_process(argc, argv, 2, 2, "rm", |
1800 | "<filename>", CHECK_FS_RW)) | |
d3aea7dc TT |
1801 | return; |
1802 | ||
fc6d9d51 | 1803 | retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num); |
3839e657 | 1804 | if (retval) { |
91d6d486 | 1805 | com_err(argv[0], retval, "while trying to resolve filename"); |
3839e657 TT |
1806 | return; |
1807 | } | |
1808 | ||
e1018eea | 1809 | if (debugfs_read_inode(inode_num, &inode, argv[0])) |
3839e657 | 1810 | return; |
3839e657 | 1811 | |
50e1e10f | 1812 | if (LINUX_S_ISDIR(inode.i_mode)) { |
3839e657 TT |
1813 | com_err(argv[0], 0, "file is a directory"); |
1814 | return; | |
1815 | } | |
1816 | ||
1817 | --inode.i_links_count; | |
e1018eea | 1818 | if (debugfs_write_inode(inode_num, &inode, argv[0])) |
3839e657 | 1819 | return; |
3839e657 TT |
1820 | |
1821 | unlink_file_by_name(argv[1]); | |
1822 | if (inode.i_links_count == 0) | |
1823 | kill_file_by_inode(inode_num); | |
1824 | } | |
1825 | ||
d7f64ae8 TT |
1826 | struct rd_struct { |
1827 | ext2_ino_t parent; | |
1828 | int empty; | |
1829 | }; | |
1830 | ||
54434927 TT |
1831 | static int rmdir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)), |
1832 | int entry EXT2FS_ATTR((unused)), | |
d7f64ae8 | 1833 | struct ext2_dir_entry *dirent, |
54434927 TT |
1834 | int offset EXT2FS_ATTR((unused)), |
1835 | int blocksize EXT2FS_ATTR((unused)), | |
1836 | char *buf EXT2FS_ATTR((unused)), | |
d7f64ae8 TT |
1837 | void *private) |
1838 | { | |
1839 | struct rd_struct *rds = (struct rd_struct *) private; | |
1840 | ||
1841 | if (dirent->inode == 0) | |
1842 | return 0; | |
70f4632b | 1843 | if ((ext2fs_dirent_name_len(dirent) == 1) && (dirent->name[0] == '.')) |
d7f64ae8 | 1844 | return 0; |
70f4632b | 1845 | if ((ext2fs_dirent_name_len(dirent) == 2) && (dirent->name[0] == '.') && |
d7f64ae8 TT |
1846 | (dirent->name[1] == '.')) { |
1847 | rds->parent = dirent->inode; | |
1848 | return 0; | |
1849 | } | |
1850 | rds->empty = 0; | |
1851 | return 0; | |
1852 | } | |
efc6f628 | 1853 | |
d7f64ae8 TT |
1854 | void do_rmdir(int argc, char *argv[]) |
1855 | { | |
1856 | int retval; | |
1857 | ext2_ino_t inode_num; | |
1858 | struct ext2_inode inode; | |
1859 | struct rd_struct rds; | |
1860 | ||
1861 | if (common_args_process(argc, argv, 2, 2, "rmdir", | |
1862 | "<filename>", CHECK_FS_RW)) | |
1863 | return; | |
1864 | ||
1865 | retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num); | |
1866 | if (retval) { | |
1867 | com_err(argv[0], retval, "while trying to resolve filename"); | |
1868 | return; | |
1869 | } | |
1870 | ||
1871 | if (debugfs_read_inode(inode_num, &inode, argv[0])) | |
1872 | return; | |
1873 | ||
1874 | if (!LINUX_S_ISDIR(inode.i_mode)) { | |
1875 | com_err(argv[0], 0, "file is not a directory"); | |
1876 | return; | |
1877 | } | |
1878 | ||
1879 | rds.parent = 0; | |
1880 | rds.empty = 1; | |
1881 | ||
1882 | retval = ext2fs_dir_iterate2(current_fs, inode_num, 0, | |
1883 | 0, rmdir_proc, &rds); | |
1884 | if (retval) { | |
1885 | com_err(argv[0], retval, "while iterating over directory"); | |
1886 | return; | |
1887 | } | |
1888 | if (rds.empty == 0) { | |
1889 | com_err(argv[0], 0, "directory not empty"); | |
1890 | return; | |
1891 | } | |
1892 | ||
1893 | inode.i_links_count = 0; | |
1894 | if (debugfs_write_inode(inode_num, &inode, argv[0])) | |
1895 | return; | |
1896 | ||
1897 | unlink_file_by_name(argv[1]); | |
1898 | kill_file_by_inode(inode_num); | |
1899 | ||
1900 | if (rds.parent) { | |
1901 | if (debugfs_read_inode(rds.parent, &inode, argv[0])) | |
1902 | return; | |
1903 | if (inode.i_links_count > 1) | |
1904 | inode.i_links_count--; | |
1905 | if (debugfs_write_inode(rds.parent, &inode, argv[0])) | |
1906 | return; | |
1907 | } | |
1908 | } | |
e88c5a33 | 1909 | #endif /* READ_ONLY */ |
d7f64ae8 | 1910 | |
efc6f628 | 1911 | void do_show_debugfs_params(int argc EXT2FS_ATTR((unused)), |
54434927 | 1912 | char *argv[] EXT2FS_ATTR((unused))) |
3839e657 | 1913 | { |
fc6d9d51 | 1914 | if (current_fs) |
1d520184 ZL |
1915 | printf("Open mode: read-%s\n", |
1916 | current_fs->flags & EXT2_FLAG_RW ? "write" : "only"); | |
1917 | printf("Filesystem in use: %s\n", | |
1918 | current_fs ? current_fs->device_name : "--none--"); | |
3839e657 TT |
1919 | } |
1920 | ||
e88c5a33 | 1921 | #ifndef READ_ONLY |
3839e657 TT |
1922 | void do_expand_dir(int argc, char *argv[]) |
1923 | { | |
b044c2e0 | 1924 | ext2_ino_t inode; |
3839e657 TT |
1925 | int retval; |
1926 | ||
e1018eea | 1927 | if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW)) |
3839e657 TT |
1928 | return; |
1929 | ||
fc6d9d51 | 1930 | retval = ext2fs_expand_dir(current_fs, inode); |
3839e657 | 1931 | if (retval) |
9b9a780f | 1932 | com_err("ext2fs_expand_dir", retval, 0); |
3839e657 TT |
1933 | return; |
1934 | } | |
1935 | ||
d3aea7dc TT |
1936 | void do_features(int argc, char *argv[]) |
1937 | { | |
1938 | int i; | |
efc6f628 | 1939 | |
d3aea7dc TT |
1940 | if (check_fs_open(argv[0])) |
1941 | return; | |
1942 | ||
1943 | if ((argc != 1) && check_fs_read_write(argv[0])) | |
1944 | return; | |
1945 | for (i=1; i < argc; i++) { | |
1946 | if (e2p_edit_feature(argv[i], | |
06968e7e | 1947 | ¤t_fs->super->s_feature_compat, 0)) |
d3aea7dc TT |
1948 | com_err(argv[0], 0, "Unknown feature: %s\n", |
1949 | argv[i]); | |
1950 | else | |
1951 | ext2fs_mark_super_dirty(current_fs); | |
1952 | } | |
5dd8f963 | 1953 | print_features(current_fs->super, stdout); |
d3aea7dc | 1954 | } |
e88c5a33 | 1955 | #endif /* READ_ONLY */ |
d3aea7dc | 1956 | |
b38cd283 TT |
1957 | void do_bmap(int argc, char *argv[]) |
1958 | { | |
1959 | ext2_ino_t ino; | |
9ed2c124 TT |
1960 | blk64_t blk, pblk = 0; |
1961 | int c, err, flags = 0, ret_flags = 0; | |
b38cd283 | 1962 | errcode_t errcode; |
efc6f628 | 1963 | |
9ed2c124 | 1964 | if (check_fs_open(argv[0])) |
b38cd283 TT |
1965 | return; |
1966 | ||
9ed2c124 TT |
1967 | reset_getopt(); |
1968 | while ((c = getopt (argc, argv, "a")) != EOF) { | |
1969 | switch (c) { | |
1970 | case 'a': | |
1971 | flags |= BMAP_ALLOC; | |
1972 | break; | |
1973 | default: | |
1974 | goto print_usage; | |
1975 | } | |
1976 | } | |
1977 | ||
1978 | if (argc <= optind+1) { | |
1979 | print_usage: | |
1980 | com_err(0, 0, | |
1981 | "Usage: bmap [-a] <file> logical_blk [physical_blk]"); | |
1982 | return; | |
1983 | } | |
1984 | ||
1985 | ino = string_to_inode(argv[optind++]); | |
becf36f6 TT |
1986 | if (!ino) |
1987 | return; | |
9ed2c124 | 1988 | err = strtoblk(argv[0], argv[optind++], "logical block", &blk); |
fe56188b DW |
1989 | if (err) |
1990 | return; | |
b38cd283 | 1991 | |
9ed2c124 TT |
1992 | if (argc > optind+1) |
1993 | goto print_usage; | |
1994 | ||
1995 | if (argc == optind+1) { | |
1996 | err = strtoblk(argv[0], argv[optind++], | |
1997 | "physical block", &pblk); | |
1998 | if (err) | |
1999 | return; | |
2000 | if (flags & BMAP_ALLOC) { | |
2001 | com_err(0, 0, "Can't set and allocate a block"); | |
2002 | return; | |
2003 | } | |
2004 | flags |= BMAP_SET; | |
2005 | } | |
2006 | ||
2007 | errcode = ext2fs_bmap2(current_fs, ino, 0, 0, flags, blk, | |
2008 | &ret_flags, &pblk); | |
b38cd283 | 2009 | if (errcode) { |
50295a3f | 2010 | com_err(argv[0], errcode, |
048786d7 | 2011 | "while mapping logical block %llu\n", blk); |
b38cd283 TT |
2012 | return; |
2013 | } | |
9ed2c124 TT |
2014 | printf("%llu", pblk); |
2015 | if (ret_flags & BMAP_RET_UNINIT) | |
2016 | fputs(" (uninit)", stdout); | |
2017 | fputc('\n', stdout); | |
b38cd283 TT |
2018 | } |
2019 | ||
becf36f6 TT |
2020 | void do_imap(int argc, char *argv[]) |
2021 | { | |
2022 | ext2_ino_t ino; | |
2023 | unsigned long group, block, block_nr, offset; | |
2024 | ||
2025 | if (common_args_process(argc, argv, 2, 2, argv[0], | |
2026 | "<file>", 0)) | |
2027 | return; | |
2028 | ino = string_to_inode(argv[1]); | |
2029 | if (!ino) | |
88494bb6 | 2030 | return; |
becf36f6 TT |
2031 | |
2032 | group = (ino - 1) / EXT2_INODES_PER_GROUP(current_fs->super); | |
2033 | offset = ((ino - 1) % EXT2_INODES_PER_GROUP(current_fs->super)) * | |
2034 | EXT2_INODE_SIZE(current_fs->super); | |
2035 | block = offset >> EXT2_BLOCK_SIZE_BITS(current_fs->super); | |
048786d7 | 2036 | if (!ext2fs_inode_table_loc(current_fs, (unsigned)group)) { |
54434927 | 2037 | com_err(argv[0], 0, "Inode table for group %lu is missing\n", |
becf36f6 TT |
2038 | group); |
2039 | return; | |
2040 | } | |
048786d7 | 2041 | block_nr = ext2fs_inode_table_loc(current_fs, (unsigned)group) + |
becf36f6 TT |
2042 | block; |
2043 | offset &= (EXT2_BLOCK_SIZE(current_fs->super) - 1); | |
2044 | ||
48e6e813 TT |
2045 | printf("Inode %d is part of block group %lu\n" |
2046 | "\tlocated at block %lu, offset 0x%04lx\n", ino, group, | |
becf36f6 TT |
2047 | block_nr, offset); |
2048 | ||
2049 | } | |
2050 | ||
e13ebfdd DW |
2051 | void do_idump(int argc, char *argv[]) |
2052 | { | |
2053 | ext2_ino_t ino; | |
0befec4e | 2054 | unsigned char *buf; |
e13ebfdd DW |
2055 | errcode_t err; |
2056 | int isize; | |
2057 | ||
2058 | if (common_args_process(argc, argv, 2, 2, argv[0], | |
2059 | "<file>", 0)) | |
2060 | return; | |
2061 | ino = string_to_inode(argv[1]); | |
2062 | if (!ino) | |
2063 | return; | |
2064 | ||
2065 | isize = EXT2_INODE_SIZE(current_fs->super); | |
2066 | err = ext2fs_get_mem(isize, &buf); | |
2067 | if (err) { | |
2068 | com_err(argv[0], err, "while allocating memory"); | |
2069 | return; | |
2070 | } | |
2071 | ||
2072 | err = ext2fs_read_inode_full(current_fs, ino, | |
2073 | (struct ext2_inode *)buf, isize); | |
2074 | if (err) { | |
2075 | com_err(argv[0], err, "while reading inode %d", ino); | |
2076 | goto err; | |
2077 | } | |
2078 | ||
2079 | do_byte_hexdump(stdout, buf, isize); | |
2080 | err: | |
2081 | ext2fs_free_mem(&buf); | |
2082 | } | |
2083 | ||
e88c5a33 | 2084 | #ifndef READ_ONLY |
4efae606 TT |
2085 | void do_set_current_time(int argc, char *argv[]) |
2086 | { | |
188960ea | 2087 | __s64 now; |
4efae606 TT |
2088 | |
2089 | if (common_args_process(argc, argv, 2, 2, argv[0], | |
2090 | "<time>", 0)) | |
2091 | return; | |
becf36f6 | 2092 | |
4efae606 | 2093 | now = string_to_time(argv[1]); |
188960ea | 2094 | if (now == -1) { |
4efae606 TT |
2095 | com_err(argv[0], 0, "Couldn't parse argument as a time: %s\n", |
2096 | argv[1]); | |
2097 | return; | |
2098 | ||
2099 | } else { | |
2100 | printf("Setting current time to %s\n", time_to_string(now)); | |
2101 | current_fs->now = now; | |
2102 | } | |
2103 | } | |
e88c5a33 | 2104 | #endif /* READ_ONLY */ |
b38cd283 | 2105 | |
03efde8a AD |
2106 | static int find_supp_feature(__u32 *supp, int feature_type, char *name) |
2107 | { | |
2108 | int compat, bit, ret; | |
2109 | unsigned int feature_mask; | |
2110 | ||
2111 | if (name) { | |
2112 | if (feature_type == E2P_FS_FEATURE) | |
2113 | ret = e2p_string2feature(name, &compat, &feature_mask); | |
2114 | else | |
2115 | ret = e2p_jrnl_string2feature(name, &compat, | |
2116 | &feature_mask); | |
2117 | if (ret) | |
2118 | return ret; | |
2119 | ||
2120 | if (!(supp[compat] & feature_mask)) | |
2121 | return 1; | |
2122 | } else { | |
2123 | for (compat = 0; compat < 3; compat++) { | |
2124 | for (bit = 0, feature_mask = 1; bit < 32; | |
2125 | bit++, feature_mask <<= 1) { | |
2126 | if (supp[compat] & feature_mask) { | |
2127 | if (feature_type == E2P_FS_FEATURE) | |
2128 | fprintf(stdout, " %s", | |
2129 | e2p_feature2string(compat, | |
2130 | feature_mask)); | |
2131 | else | |
2132 | fprintf(stdout, " %s", | |
2133 | e2p_jrnl_feature2string(compat, | |
2134 | feature_mask)); | |
2135 | } | |
2136 | } | |
2137 | } | |
2138 | fprintf(stdout, "\n"); | |
2139 | } | |
2140 | ||
2141 | return 0; | |
2142 | } | |
2143 | ||
2144 | void do_supported_features(int argc, char *argv[]) | |
2145 | { | |
42080a86 | 2146 | int ret; |
03efde8a AD |
2147 | __u32 supp[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP, |
2148 | EXT2_LIB_FEATURE_INCOMPAT_SUPP, | |
2149 | EXT2_LIB_FEATURE_RO_COMPAT_SUPP }; | |
2150 | __u32 jrnl_supp[3] = { JFS_KNOWN_COMPAT_FEATURES, | |
2151 | JFS_KNOWN_INCOMPAT_FEATURES, | |
2152 | JFS_KNOWN_ROCOMPAT_FEATURES }; | |
2153 | ||
2154 | if (argc > 1) { | |
2155 | ret = find_supp_feature(supp, E2P_FS_FEATURE, argv[1]); | |
2156 | if (ret) { | |
2157 | ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE, | |
2158 | argv[1]); | |
2159 | } | |
2160 | if (ret) | |
2161 | com_err(argv[0], 0, "Unknown feature: %s\n", argv[1]); | |
2162 | else | |
2163 | fprintf(stdout, "Supported feature: %s\n", argv[1]); | |
2164 | } else { | |
2165 | fprintf(stdout, "Supported features:"); | |
2166 | ret = find_supp_feature(supp, E2P_FS_FEATURE, NULL); | |
2167 | ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE, NULL); | |
2168 | } | |
2169 | } | |
2170 | ||
e88c5a33 | 2171 | #ifndef READ_ONLY |
86685923 TT |
2172 | void do_punch(int argc, char *argv[]) |
2173 | { | |
2174 | ext2_ino_t ino; | |
2175 | blk64_t start, end; | |
2176 | int err; | |
2177 | errcode_t errcode; | |
2178 | ||
2179 | if (common_args_process(argc, argv, 3, 4, argv[0], | |
2180 | "<file> start_blk [end_blk]", | |
2181 | CHECK_FS_RW | CHECK_FS_BITMAPS)) | |
2182 | return; | |
2183 | ||
2184 | ino = string_to_inode(argv[1]); | |
2185 | if (!ino) | |
2186 | return; | |
a25fffae | 2187 | err = strtoblk(argv[0], argv[2], "logical block", &start); |
fe56188b DW |
2188 | if (err) |
2189 | return; | |
2190 | if (argc == 4) { | |
a25fffae | 2191 | err = strtoblk(argv[0], argv[3], "logical block", &end); |
fe56188b DW |
2192 | if (err) |
2193 | return; | |
2194 | } else | |
86685923 TT |
2195 | end = ~0; |
2196 | ||
2197 | errcode = ext2fs_punch(current_fs, ino, 0, 0, start, end); | |
2198 | ||
2199 | if (errcode) { | |
2200 | com_err(argv[0], errcode, | |
2201 | "while truncating inode %u from %llu to %llu\n", ino, | |
2202 | (unsigned long long) start, (unsigned long long) end); | |
2203 | return; | |
2204 | } | |
2205 | } | |
2f8c0d02 DW |
2206 | |
2207 | void do_fallocate(int argc, char *argv[]) | |
2208 | { | |
2209 | ext2_ino_t ino; | |
2210 | blk64_t start, end; | |
2211 | int err; | |
2212 | errcode_t errcode; | |
2213 | ||
2214 | if (common_args_process(argc, argv, 3, 4, argv[0], | |
2215 | "<file> start_blk [end_blk]", | |
2216 | CHECK_FS_RW | CHECK_FS_BITMAPS)) | |
2217 | return; | |
2218 | ||
2219 | ino = string_to_inode(argv[1]); | |
2220 | if (!ino) | |
2221 | return; | |
2222 | err = strtoblk(argv[0], argv[2], "logical block", &start); | |
2223 | if (err) | |
2224 | return; | |
2225 | if (argc == 4) { | |
2226 | err = strtoblk(argv[0], argv[3], "logical block", &end); | |
2227 | if (err) | |
2228 | return; | |
2229 | } else | |
2230 | end = ~0; | |
2231 | ||
2232 | errcode = ext2fs_fallocate(current_fs, EXT2_FALLOCATE_INIT_BEYOND_EOF, | |
2233 | ino, NULL, ~0ULL, start, end - start + 1); | |
2234 | ||
2235 | if (errcode) { | |
2236 | com_err(argv[0], errcode, | |
2237 | "while fallocating inode %u from %llu to %llu\n", ino, | |
2238 | (unsigned long long) start, (unsigned long long) end); | |
2239 | return; | |
2240 | } | |
2241 | } | |
e88c5a33 | 2242 | #endif /* READ_ONLY */ |
86685923 | 2243 | |
4df6a37b DH |
2244 | void do_symlink(int argc, char *argv[]) |
2245 | { | |
4df6a37b DH |
2246 | errcode_t retval; |
2247 | ||
2248 | if (common_args_process(argc, argv, 3, 3, "symlink", | |
2249 | "<filename> <target>", CHECK_FS_RW)) | |
2250 | return; | |
2251 | ||
a3111e80 DW |
2252 | retval = do_symlink_internal(current_fs, cwd, argv[1], argv[2], root); |
2253 | if (retval) | |
9aa3aa8d | 2254 | com_err(argv[0], retval, 0); |
4df6a37b DH |
2255 | |
2256 | } | |
2257 | ||
25f291c9 | 2258 | #if CONFIG_MMP |
3cebf9c1 | 2259 | void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[]) |
0f5eba75 | 2260 | { |
0f5eba75 AD |
2261 | struct mmp_struct *mmp_s; |
2262 | time_t t; | |
2263 | errcode_t retval = 0; | |
2264 | ||
7105c183 ES |
2265 | if (check_fs_open(argv[0])) |
2266 | return; | |
2267 | ||
0f5eba75 AD |
2268 | if (current_fs->mmp_buf == NULL) { |
2269 | retval = ext2fs_get_mem(current_fs->blocksize, | |
2270 | ¤t_fs->mmp_buf); | |
2271 | if (retval) { | |
2272 | com_err(argv[0], retval, "allocating MMP buffer.\n"); | |
2273 | return; | |
2274 | } | |
2275 | } | |
2276 | ||
2277 | mmp_s = current_fs->mmp_buf; | |
2278 | ||
2279 | retval = ext2fs_mmp_read(current_fs, current_fs->super->s_mmp_block, | |
2280 | current_fs->mmp_buf); | |
2281 | if (retval) { | |
2282 | com_err(argv[0], retval, "reading MMP block.\n"); | |
2283 | return; | |
2284 | } | |
2285 | ||
2286 | t = mmp_s->mmp_time; | |
2287 | fprintf(stdout, "block_number: %llu\n", current_fs->super->s_mmp_block); | |
2288 | fprintf(stdout, "update_interval: %d\n", | |
2289 | current_fs->super->s_mmp_update_interval); | |
2290 | fprintf(stdout, "check_interval: %d\n", mmp_s->mmp_check_interval); | |
2291 | fprintf(stdout, "sequence: %08x\n", mmp_s->mmp_seq); | |
2292 | fprintf(stdout, "time: %lld -- %s", mmp_s->mmp_time, ctime(&t)); | |
2293 | fprintf(stdout, "node_name: %s\n", mmp_s->mmp_nodename); | |
2294 | fprintf(stdout, "device_name: %s\n", mmp_s->mmp_bdevname); | |
7105c183 | 2295 | fprintf(stdout, "magic: 0x%x\n", mmp_s->mmp_magic); |
a9620d8b | 2296 | fprintf(stdout, "checksum: 0x%08x\n", mmp_s->mmp_checksum); |
25f291c9 TT |
2297 | fprintf(stdout, "MMP is unsupported, please recompile with " |
2298 | "--enable-mmp\n"); | |
2299 | } | |
d6a4bcb5 | 2300 | #else |
25f291c9 TT |
2301 | void do_dump_mmp(int argc EXT2FS_ATTR((unused)), |
2302 | char *argv[] EXT2FS_ATTR((unused))) | |
2303 | { | |
d6a4bcb5 TB |
2304 | fprintf(stdout, "MMP is unsupported, please recompile with " |
2305 | "--enable-mmp\n"); | |
0f5eba75 | 2306 | } |
25f291c9 | 2307 | #endif |
0f5eba75 | 2308 | |
9e85208e | 2309 | static int source_file(const char *cmd_file, int ss_idx) |
fc6d9d51 TT |
2310 | { |
2311 | FILE *f; | |
355ffb2f | 2312 | char buf[BUFSIZ]; |
fc6d9d51 TT |
2313 | char *cp; |
2314 | int exit_status = 0; | |
2315 | int retval; | |
2316 | ||
2317 | if (strcmp(cmd_file, "-") == 0) | |
2318 | f = stdin; | |
2319 | else { | |
2320 | f = fopen(cmd_file, "r"); | |
2321 | if (!f) { | |
2322 | perror(cmd_file); | |
2323 | exit(1); | |
2324 | } | |
2325 | } | |
2a7bfe83 TT |
2326 | fflush(stdout); |
2327 | fflush(stderr); | |
fc6d9d51 TT |
2328 | setbuf(stdout, NULL); |
2329 | setbuf(stderr, NULL); | |
2330 | while (!feof(f)) { | |
2331 | if (fgets(buf, sizeof(buf), f) == NULL) | |
2332 | break; | |
2333 | cp = strchr(buf, '\n'); | |
2334 | if (cp) | |
2335 | *cp = 0; | |
2336 | cp = strchr(buf, '\r'); | |
2337 | if (cp) | |
2338 | *cp = 0; | |
2339 | printf("debugfs: %s\n", buf); | |
9e85208e | 2340 | retval = ss_execute_line(ss_idx, buf); |
fc6d9d51 | 2341 | if (retval) { |
9e85208e | 2342 | ss_perror(ss_idx, retval, buf); |
fc6d9d51 TT |
2343 | exit_status++; |
2344 | } | |
2345 | } | |
2d7ef236 PT |
2346 | if (f != stdin) |
2347 | fclose(f); | |
fc6d9d51 TT |
2348 | return exit_status; |
2349 | } | |
2350 | ||
a8859cad | 2351 | int main(int argc, char **argv) |
3839e657 | 2352 | { |
50e1e10f | 2353 | int retval; |
e88c5a33 TT |
2354 | const char *usage = |
2355 | "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] " | |
2356 | "[-R request] [-V] [" | |
2357 | #ifndef READ_ONLY | |
491cc33a | 2358 | "[-w] [-z undo_file] " |
e88c5a33 TT |
2359 | #endif |
2360 | "[-c] device]"; | |
f1304811 | 2361 | int c; |
03b9dca6 | 2362 | int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; |
fc6d9d51 TT |
2363 | char *request = 0; |
2364 | int exit_status = 0; | |
2365 | char *cmd_file = 0; | |
048786d7 VAH |
2366 | blk64_t superblock = 0; |
2367 | blk64_t blocksize = 0; | |
2e8d40d5 | 2368 | int catastrophic = 0; |
1ad54a94 | 2369 | char *data_filename = 0; |
e88c5a33 | 2370 | #ifdef READ_ONLY |
9bca9a39 | 2371 | const char *opt_string = "nicR:f:b:s:Vd:D"; |
e88c5a33 | 2372 | #else |
491cc33a DW |
2373 | const char *opt_string = "niwcR:f:b:s:Vd:Dz:"; |
2374 | char *undo_file = NULL; | |
e88c5a33 | 2375 | #endif |
efc6f628 | 2376 | |
49ce6cb5 | 2377 | if (debug_prog_name == 0) |
e88c5a33 TT |
2378 | #ifdef READ_ONLY |
2379 | debug_prog_name = "rdebugfs"; | |
2380 | #else | |
49ce6cb5 | 2381 | debug_prog_name = "debugfs"; |
e88c5a33 | 2382 | #endif |
a6d8302b | 2383 | add_error_table(&et_ext2_error_table); |
49ce6cb5 TT |
2384 | fprintf (stderr, "%s %s (%s)\n", debug_prog_name, |
2385 | E2FSPROGS_VERSION, E2FSPROGS_DATE); | |
3839e657 | 2386 | |
e88c5a33 | 2387 | while ((c = getopt (argc, argv, opt_string)) != EOF) { |
3839e657 | 2388 | switch (c) { |
fc6d9d51 TT |
2389 | case 'R': |
2390 | request = optarg; | |
2391 | break; | |
2392 | case 'f': | |
2393 | cmd_file = optarg; | |
2394 | break; | |
1ad54a94 TT |
2395 | case 'd': |
2396 | data_filename = optarg; | |
2397 | break; | |
59cf7e0d TT |
2398 | case 'i': |
2399 | open_flags |= EXT2_FLAG_IMAGE_FILE; | |
2400 | break; | |
9bca9a39 DW |
2401 | case 'n': |
2402 | open_flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; | |
2403 | break; | |
e88c5a33 | 2404 | #ifndef READ_ONLY |
3839e657 | 2405 | case 'w': |
59cf7e0d | 2406 | open_flags |= EXT2_FLAG_RW; |
3839e657 | 2407 | break; |
e88c5a33 | 2408 | #endif |
0fd68e02 TT |
2409 | case 'D': |
2410 | open_flags |= EXT2_FLAG_DIRECT_IO; | |
2411 | break; | |
2e8d40d5 | 2412 | case 'b': |
efc6f628 | 2413 | blocksize = parse_ulong(optarg, argv[0], |
e1018eea | 2414 | "block size", 0); |
2e8d40d5 TT |
2415 | break; |
2416 | case 's': | |
a25fffae EW |
2417 | retval = strtoblk(argv[0], optarg, |
2418 | "superblock block number", | |
2419 | &superblock); | |
32541fe4 | 2420 | if (retval) |
fe56188b | 2421 | return 1; |
2e8d40d5 TT |
2422 | break; |
2423 | case 'c': | |
2424 | catastrophic = 1; | |
2425 | break; | |
818180cd TT |
2426 | case 'V': |
2427 | /* Print version number and exit */ | |
2428 | fprintf(stderr, "\tUsing %s\n", | |
2429 | error_message(EXT2_ET_BASE)); | |
2430 | exit(0); | |
491cc33a DW |
2431 | case 'z': |
2432 | undo_file = optarg; | |
2433 | break; | |
3839e657 | 2434 | default: |
49ce6cb5 | 2435 | com_err(argv[0], 0, usage, debug_prog_name); |
b4ac9cc3 | 2436 | return 1; |
3839e657 TT |
2437 | } |
2438 | } | |
2439 | if (optind < argc) | |
2e8d40d5 | 2440 | open_filesystem(argv[optind], open_flags, |
1ad54a94 | 2441 | superblock, blocksize, catastrophic, |
491cc33a | 2442 | data_filename, undo_file); |
efc6f628 | 2443 | |
49ce6cb5 | 2444 | sci_idx = ss_create_invocation(debug_prog_name, "0.0", (char *) NULL, |
3839e657 TT |
2445 | &debug_cmds, &retval); |
2446 | if (retval) { | |
2447 | ss_perror(sci_idx, retval, "creating invocation"); | |
2448 | exit(1); | |
2449 | } | |
3ae497ea | 2450 | ss_get_readline(sci_idx); |
3839e657 TT |
2451 | |
2452 | (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval); | |
2453 | if (retval) { | |
2454 | ss_perror(sci_idx, retval, "adding standard requests"); | |
2455 | exit (1); | |
2456 | } | |
49ce6cb5 TT |
2457 | if (extra_cmds) |
2458 | ss_add_request_table (sci_idx, extra_cmds, 1, &retval); | |
2459 | if (retval) { | |
2460 | ss_perror(sci_idx, retval, "adding extra requests"); | |
2461 | exit (1); | |
2462 | } | |
fc6d9d51 TT |
2463 | if (request) { |
2464 | retval = 0; | |
2465 | retval = ss_execute_line(sci_idx, request); | |
2466 | if (retval) { | |
2467 | ss_perror(sci_idx, retval, request); | |
2468 | exit_status++; | |
2469 | } | |
2470 | } else if (cmd_file) { | |
2471 | exit_status = source_file(cmd_file, sci_idx); | |
2472 | } else { | |
2473 | ss_listen(sci_idx); | |
2474 | } | |
3839e657 | 2475 | |
6e9761c2 TT |
2476 | ss_delete_invocation(sci_idx); |
2477 | ||
fc6d9d51 | 2478 | if (current_fs) |
3839e657 | 2479 | close_filesystem(); |
efc6f628 | 2480 | |
a6d8302b | 2481 | remove_error_table(&et_ext2_error_table); |
e597304a | 2482 | return exit_status; |
3839e657 | 2483 | } |