2 * debugfs.c --- a program which allows you to attach an ext2fs
3 * filesystem and play with it.
5 * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
6 * under the terms of the GNU Public License.
8 * Modifications by Robert Sanders <gt8134b@prism.gatech.edu>
29 #ifdef HAVE_SYS_SYSMACROS_H
30 #include <sys/sysmacros.h>
34 #include "uuid/uuid.h"
37 #include <ext2fs/ext2_ext_attr.h>
39 #include "../version.h"
41 #include "support/plausible.h"
47 #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jbd-debug */
48 int journal_enable_debug
= -1;
52 * There must be only one definition if we're hooking in extra commands or
53 * chaging default prompt. Use -DSKIP_GLOBDEF for that.
56 ss_request_table
*extra_cmds
;
57 const char *debug_prog_name
;
61 ext2_filsys current_fs
;
62 quota_ctx_t current_qctx
;
66 static int debugfs_setup_tdb(const char *device_name
, char *undo_file
,
69 errcode_t retval
= ENOMEM
;
70 const char *tdb_dir
= NULL
;
71 char *tdb_file
= NULL
;
72 char *dev_name
, *tmp_name
;
74 /* (re)open a specific undo file */
75 if (undo_file
&& undo_file
[0] != 0) {
76 retval
= set_undo_io_backing_manager(*io_ptr
);
79 *io_ptr
= undo_io_manager
;
80 retval
= set_undo_io_backup_file(undo_file
);
83 printf("Overwriting existing filesystem; this can be undone "
84 "using the command:\n"
86 undo_file
, device_name
);
91 * Configuration via a conf file would be
94 tdb_dir
= ss_safe_getenv("E2FSPROGS_UNDO_DIR");
96 tdb_dir
= "/var/lib/e2fsprogs";
98 if (!strcmp(tdb_dir
, "none") || (tdb_dir
[0] == 0) ||
99 access(tdb_dir
, W_OK
))
102 tmp_name
= strdup(device_name
);
105 dev_name
= basename(tmp_name
);
106 tdb_file
= malloc(strlen(tdb_dir
) + 9 + strlen(dev_name
) + 7 + 1);
111 sprintf(tdb_file
, "%s/debugfs-%s.e2undo", tdb_dir
, dev_name
);
114 if ((unlink(tdb_file
) < 0) && (errno
!= ENOENT
)) {
116 com_err("debugfs", retval
,
117 "while trying to delete %s", tdb_file
);
121 retval
= set_undo_io_backing_manager(*io_ptr
);
124 *io_ptr
= undo_io_manager
;
125 retval
= set_undo_io_backup_file(tdb_file
);
128 printf("Overwriting existing filesystem; this can be undone "
129 "using the command:\n"
130 " e2undo %s %s\n\n", tdb_file
, device_name
);
137 com_err("debugfs", retval
, "while trying to setup undo file\n");
141 static void open_filesystem(char *device
, int open_flags
, blk64_t superblock
,
142 blk64_t blocksize
, int catastrophic
,
143 char *data_filename
, char *undo_file
)
146 io_channel data_io
= 0;
147 io_manager io_ptr
= unix_io_manager
;
149 if (superblock
!= 0 && blocksize
== 0) {
150 com_err(device
, 0, "if you specify the superblock, you must also specify the block size");
156 if ((open_flags
& EXT2_FLAG_IMAGE_FILE
) == 0) {
158 "The -d option is only valid when reading an e2image file");
162 retval
= unix_io_manager
->open(data_filename
, 0, &data_io
);
164 com_err(data_filename
, 0, "while opening data source");
171 open_flags
|= EXT2_FLAG_SKIP_MMP
| EXT2_FLAG_IGNORE_SB_ERRORS
;
174 retval
= debugfs_setup_tdb(device
, undo_file
, &io_ptr
);
180 retval
= ext2fs_open(device
, open_flags
, superblock
, blocksize
,
181 io_ptr
, ¤t_fs
);
182 if (retval
&& (retval
== EXT2_ET_SB_CSUM_INVALID
) &&
183 !(open_flags
& EXT2_FLAG_IGNORE_CSUM_ERRORS
)) {
184 open_flags
|= EXT2_FLAG_IGNORE_CSUM_ERRORS
;
185 printf("Checksum errors in superblock! Retrying...\n");
189 com_err(debug_prog_name
, retval
,
190 "while trying to open %s", device
);
191 if (retval
== EXT2_ET_BAD_MAGIC
)
192 check_plausibility(device
, CHECK_FS_EXIST
, NULL
);
196 current_fs
->default_bitmap_type
= EXT2FS_BMAP64_RBTREE
;
199 com_err(device
, 0, "catastrophic mode - not reading inode or group bitmaps");
201 retval
= ext2fs_read_bitmaps(current_fs
);
203 com_err(device
, retval
,
204 "while reading allocation bitmaps");
210 retval
= ext2fs_set_data_io(current_fs
, data_io
);
212 com_err(device
, retval
,
213 "while setting data source");
218 root
= cwd
= EXT2_ROOT_INO
;
222 retval
= ext2fs_close_free(¤t_fs
);
224 com_err(device
, retval
, "while trying to close filesystem");
227 void do_open_filesys(int argc
, char **argv
, int sci_idx
EXT2FS_ATTR((unused
)),
228 void *infop
EXT2FS_ATTR((unused
)))
231 int catastrophic
= 0;
232 blk64_t superblock
= 0;
233 blk64_t blocksize
= 0;
234 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
| EXT2_FLAG_64BITS
|
236 char *data_filename
= 0;
237 char *undo_file
= NULL
;
240 while ((c
= getopt(argc
, argv
, "iwfecb:s:d:Dz:")) != EOF
) {
243 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
249 open_flags
|= EXT2_FLAG_RW
;
250 #endif /* READ_ONLY */
253 open_flags
|= EXT2_FLAG_FORCE
;
256 open_flags
|= EXT2_FLAG_EXCLUSIVE
;
262 data_filename
= optarg
;
265 open_flags
|= EXT2_FLAG_DIRECT_IO
;
268 blocksize
= parse_ulong(optarg
, argv
[0],
274 err
= strtoblk(argv
[0], optarg
,
275 "superblock block number", &superblock
);
290 if (optind
!= argc
-1) {
293 if (check_fs_not_open(argv
[0]))
295 open_filesystem(argv
[optind
], open_flags
,
296 superblock
, blocksize
, catastrophic
,
297 data_filename
, undo_file
);
301 fprintf(stderr
, "%s: Usage: open [-s superblock] [-b blocksize] "
303 "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
305 "[-d image_filename] [-c] [-i] [-f] [-e] [-D] [-w] "
307 "<device>\n", argv
[0]);
310 void do_lcd(int argc
, char **argv
, int sci_idx
EXT2FS_ATTR((unused
)),
311 void *infop
EXT2FS_ATTR((unused
)))
314 com_err(argv
[0], 0, "Usage: %s %s", argv
[0], "<native dir>");
318 if (chdir(argv
[1]) == -1) {
319 com_err(argv
[0], errno
,
320 "while trying to change native directory to %s",
326 static void close_filesystem(NOARGS
)
330 if (current_fs
->flags
& EXT2_FLAG_IB_DIRTY
) {
331 retval
= ext2fs_write_inode_bitmap(current_fs
);
333 com_err("ext2fs_write_inode_bitmap", retval
, 0);
335 if (current_fs
->flags
& EXT2_FLAG_BB_DIRTY
) {
336 retval
= ext2fs_write_block_bitmap(current_fs
);
338 com_err("ext2fs_write_block_bitmap", retval
, 0);
341 quota_release_context(¤t_qctx
);
342 retval
= ext2fs_close_free(¤t_fs
);
344 com_err("ext2fs_close", retval
, 0);
348 void do_close_filesys(int argc
, char **argv
, int sci_idx
EXT2FS_ATTR((unused
)),
349 void *infop
EXT2FS_ATTR((unused
)))
353 if (check_fs_open(argv
[0]))
357 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
360 current_fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
369 com_err(0, 0, "Usage: close_filesys [-a]");
377 void do_init_filesys(int argc
, char **argv
, int sci_idx
EXT2FS_ATTR((unused
)),
378 void *infop
EXT2FS_ATTR((unused
)))
380 struct ext2_super_block param
;
385 if (common_args_process(argc
, argv
, 3, 3, "initialize",
386 "<device> <blocks>", CHECK_FS_NOTOPEN
))
389 memset(¶m
, 0, sizeof(struct ext2_super_block
));
390 err
= strtoblk(argv
[0], argv
[2], "blocks count", &blocks
);
393 ext2fs_blocks_count_set(¶m
, blocks
);
394 retval
= ext2fs_initialize(argv
[1], 0, ¶m
,
395 unix_io_manager
, ¤t_fs
);
397 com_err(argv
[1], retval
, "while initializing filesystem");
401 root
= cwd
= EXT2_ROOT_INO
;
405 static void print_features(struct ext2_super_block
* s
, FILE *f
)
408 __u32
*mask
= &s
->s_feature_compat
, m
;
410 fputs("Filesystem features:", f
);
411 for (i
=0; i
<3; i
++,mask
++) {
412 for (j
=0,m
=1; j
< 32; j
++, m
<<=1) {
414 fprintf(f
, " %s", e2p_feature2string(i
, m
));
423 #endif /* READ_ONLY */
425 static void print_bg_opts(ext2_filsys fs
, dgrp_t group
, int mask
,
426 const char *str
, int *first
, FILE *f
)
428 if (ext2fs_bg_flags_test(fs
, group
, mask
)) {
438 void do_show_super_stats(int argc
, char *argv
[],
439 int sci_idx
EXT2FS_ATTR((unused
)),
440 void *infop
EXT2FS_ATTR((unused
)))
442 const char *units
="block";
445 int c
, header_only
= 0;
446 int numdirs
= 0, first
, gdt_csum
;
449 while ((c
= getopt (argc
, argv
, "h")) != EOF
) {
458 if (optind
!= argc
) {
461 if (check_fs_open(argv
[0]))
465 if (ext2fs_has_feature_bigalloc(current_fs
->super
))
468 list_super2(current_fs
->super
, out
);
469 if (ext2fs_has_feature_metadata_csum(current_fs
->super
) &&
470 !ext2fs_superblock_csum_verify(current_fs
,
471 current_fs
->super
)) {
472 __u32 orig_csum
= current_fs
->super
->s_checksum
;
474 ext2fs_superblock_csum_set(current_fs
,
476 fprintf(out
, "Expected Checksum: 0x%08x\n",
477 current_fs
->super
->s_checksum
);
478 current_fs
->super
->s_checksum
= orig_csum
;
480 for (i
=0; i
< current_fs
->group_desc_count
; i
++)
481 numdirs
+= ext2fs_bg_used_dirs_count(current_fs
, i
);
482 fprintf(out
, "Directories: %u\n", numdirs
);
489 gdt_csum
= ext2fs_has_group_desc_csum(current_fs
);
490 for (i
= 0; i
< current_fs
->group_desc_count
; i
++) {
491 fprintf(out
, " Group %2d: block bitmap at %llu, "
492 "inode bitmap at %llu, "
493 "inode table at %llu\n"
497 i
, ext2fs_block_bitmap_loc(current_fs
, i
),
498 ext2fs_inode_bitmap_loc(current_fs
, i
),
499 ext2fs_inode_table_loc(current_fs
, i
),
500 ext2fs_bg_free_blocks_count(current_fs
, i
), units
,
501 ext2fs_bg_free_blocks_count(current_fs
, i
) != 1 ?
503 ext2fs_bg_free_inodes_count(current_fs
, i
),
504 ext2fs_bg_free_inodes_count(current_fs
, i
) != 1 ?
506 ext2fs_bg_used_dirs_count(current_fs
, i
),
507 ext2fs_bg_used_dirs_count(current_fs
, i
) != 1 ? "directories"
508 : "directory", gdt_csum
? ", " : "\n");
510 fprintf(out
, "%u unused %s\n",
511 ext2fs_bg_itable_unused(current_fs
, i
),
512 ext2fs_bg_itable_unused(current_fs
, i
) != 1 ?
515 print_bg_opts(current_fs
, i
, EXT2_BG_INODE_UNINIT
, "Inode not init",
517 print_bg_opts(current_fs
, i
, EXT2_BG_BLOCK_UNINIT
, "Block not init",
520 fprintf(out
, "%sChecksum 0x%04x",
521 first
? " [":", ", ext2fs_bg_checksum(current_fs
, i
));
530 fprintf(stderr
, "%s: Usage: show_super_stats [-h]\n", argv
[0]);
534 void do_dirty_filesys(int argc
EXT2FS_ATTR((unused
)),
535 char **argv
EXT2FS_ATTR((unused
)),
536 int sci_idx
EXT2FS_ATTR((unused
)),
537 void *infop
EXT2FS_ATTR((unused
)))
539 if (check_fs_open(argv
[0]))
541 if (check_fs_read_write(argv
[0]))
544 if (argv
[1] && !strcmp(argv
[1], "-clean"))
545 current_fs
->super
->s_state
|= EXT2_VALID_FS
;
547 current_fs
->super
->s_state
&= ~EXT2_VALID_FS
;
548 ext2fs_mark_super_dirty(current_fs
);
550 #endif /* READ_ONLY */
552 struct list_blocks_struct
{
555 blk64_t first_block
, last_block
;
556 e2_blkcnt_t first_bcnt
, last_bcnt
;
560 static void finish_range(struct list_blocks_struct
*lb
)
562 if (lb
->first_block
== 0)
567 fprintf(lb
->f
, ", ");
568 if (lb
->first_block
== lb
->last_block
)
569 fprintf(lb
->f
, "(%lld):%llu",
570 (long long)lb
->first_bcnt
, lb
->first_block
);
572 fprintf(lb
->f
, "(%lld-%lld):%llu-%llu",
573 (long long)lb
->first_bcnt
, (long long)lb
->last_bcnt
,
574 lb
->first_block
, lb
->last_block
);
578 static int list_blocks_proc(ext2_filsys fs
EXT2FS_ATTR((unused
)),
579 blk64_t
*blocknr
, e2_blkcnt_t blockcnt
,
580 blk64_t ref_block
EXT2FS_ATTR((unused
)),
581 int ref_offset
EXT2FS_ATTR((unused
)),
584 struct list_blocks_struct
*lb
= (struct list_blocks_struct
*) private;
589 * See if we can add on to the existing range (if it exists)
591 if (lb
->first_block
&&
592 (lb
->last_block
+1 == *blocknr
) &&
593 (lb
->last_bcnt
+1 == blockcnt
)) {
594 lb
->last_block
= *blocknr
;
595 lb
->last_bcnt
= blockcnt
;
602 lb
->first_block
= lb
->last_block
= *blocknr
;
603 lb
->first_bcnt
= lb
->last_bcnt
= blockcnt
;
607 * Not a normal block. Always force a new range.
613 fprintf(lb
->f
, ", ");
615 fprintf(lb
->f
, "(IND):%llu", (unsigned long long) *blocknr
);
616 else if (blockcnt
== -2)
617 fprintf(lb
->f
, "(DIND):%llu", (unsigned long long) *blocknr
);
618 else if (blockcnt
== -3)
619 fprintf(lb
->f
, "(TIND):%llu", (unsigned long long) *blocknr
);
623 static void internal_dump_inode_extra(FILE *out
,
624 const char *prefix
EXT2FS_ATTR((unused
)),
625 ext2_ino_t inode_num
EXT2FS_ATTR((unused
)),
626 struct ext2_inode_large
*inode
)
628 fprintf(out
, "Size of extra inode fields: %u\n", inode
->i_extra_isize
);
629 if (inode
->i_extra_isize
> EXT2_INODE_SIZE(current_fs
->super
) -
630 EXT2_GOOD_OLD_INODE_SIZE
) {
631 fprintf(stderr
, "invalid inode->i_extra_isize (%u)\n",
632 inode
->i_extra_isize
);
637 static void dump_blocks(FILE *f
, const char *prefix
, ext2_ino_t inode
)
639 struct list_blocks_struct lb
;
641 fprintf(f
, "%sBLOCKS:\n%s", prefix
, prefix
);
646 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
, NULL
,
647 list_blocks_proc
, (void *)&lb
);
650 fprintf(f
, "\n%sTOTAL: %lld\n", prefix
, (long long)lb
.total
);
654 static int int_log10(unsigned long long arg
)
666 #define DUMP_LEAF_EXTENTS 0x01
667 #define DUMP_NODE_EXTENTS 0x02
668 #define DUMP_EXTENT_TABLE 0x04
670 static void dump_extents(FILE *f
, const char *prefix
, ext2_ino_t ino
,
671 int flags
, int logical_width
, int physical_width
)
673 ext2_extent_handle_t handle
;
674 struct ext2fs_extent extent
;
675 struct ext2_extent_info info
;
676 int op
= EXT2_EXTENT_ROOT
;
677 unsigned int printed
= 0;
680 errcode
= ext2fs_extent_open(current_fs
, ino
, &handle
);
684 if (flags
& DUMP_EXTENT_TABLE
)
685 fprintf(f
, "Level Entries %*s %*s Length Flags\n",
686 (logical_width
*2)+3, "Logical",
687 (physical_width
*2)+3, "Physical");
689 fprintf(f
, "%sEXTENTS:\n%s", prefix
, prefix
);
692 errcode
= ext2fs_extent_get(handle
, op
, &extent
);
697 op
= EXT2_EXTENT_NEXT
;
699 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
702 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
) {
703 if ((flags
& DUMP_LEAF_EXTENTS
) == 0)
706 if ((flags
& DUMP_NODE_EXTENTS
) == 0)
710 errcode
= ext2fs_extent_get_info(handle
, &info
);
714 if (!(extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
)) {
715 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
718 if (flags
& DUMP_EXTENT_TABLE
) {
719 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
721 info
.curr_level
, info
.max_depth
,
722 info
.curr_entry
, info
.num_entries
,
726 extent
.e_lblk
+ (extent
.e_len
- 1),
729 physical_width
+3, "", extent
.e_len
);
733 fprintf(f
, "%s(ETB%d):%llu",
734 printed
? ", " : "", info
.curr_level
,
740 if (flags
& DUMP_EXTENT_TABLE
) {
741 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
742 "%*llu - %*llu %6u %s\n",
743 info
.curr_level
, info
.max_depth
,
744 info
.curr_entry
, info
.num_entries
,
748 extent
.e_lblk
+ (extent
.e_len
- 1),
752 extent
.e_pblk
+ (extent
.e_len
- 1),
754 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
759 if (extent
.e_len
== 0)
761 else if (extent
.e_len
== 1)
766 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
771 "%s(%lld-%lld%s):%lld-%lld",
774 extent
.e_lblk
+ (extent
.e_len
- 1),
775 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
778 extent
.e_pblk
+ (extent
.e_len
- 1));
783 ext2fs_extent_free(handle
);
786 static void dump_inline_data(FILE *out
, const char *prefix
, ext2_ino_t inode_num
)
791 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
793 fprintf(out
, "%sSize of inline data: %zu\n", prefix
, size
);
796 static void dump_inline_symlink(FILE *out
, ext2_ino_t inode_num
,
797 struct ext2_inode
*inode
, const char *prefix
)
803 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
807 retval
= ext2fs_get_memzero(size
+ 1, &buf
);
811 retval
= ext2fs_inline_data_get(current_fs
, inode_num
,
816 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
820 ext2fs_free_mem(&buf
);
822 com_err(__func__
, retval
, "while dumping link destination");
825 void internal_dump_inode(FILE *out
, const char *prefix
,
826 ext2_ino_t inode_num
, struct ext2_inode
*inode
,
831 int os
= current_fs
->super
->s_creator_os
;
832 struct ext2_inode_large
*large_inode
;
833 int is_large_inode
= 0;
835 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
837 large_inode
= (struct ext2_inode_large
*) inode
;
839 if (LINUX_S_ISDIR(inode
->i_mode
)) i_type
= "directory";
840 else if (LINUX_S_ISREG(inode
->i_mode
)) i_type
= "regular";
841 else if (LINUX_S_ISLNK(inode
->i_mode
)) i_type
= "symlink";
842 else if (LINUX_S_ISBLK(inode
->i_mode
)) i_type
= "block special";
843 else if (LINUX_S_ISCHR(inode
->i_mode
)) i_type
= "character special";
844 else if (LINUX_S_ISFIFO(inode
->i_mode
)) i_type
= "FIFO";
845 else if (LINUX_S_ISSOCK(inode
->i_mode
)) i_type
= "socket";
846 else i_type
= "bad type";
847 fprintf(out
, "%sInode: %u Type: %s ", prefix
, inode_num
, i_type
);
848 fprintf(out
, "%sMode: 0%03o Flags: 0x%x\n",
849 prefix
, inode
->i_mode
& 07777, inode
->i_flags
);
850 if (is_large_inode
&& large_inode
->i_extra_isize
>= 24) {
851 fprintf(out
, "%sGeneration: %u Version: 0x%08x:%08x\n",
852 prefix
, inode
->i_generation
, large_inode
->i_version_hi
,
853 inode
->osd1
.linux1
.l_i_version
);
855 fprintf(out
, "%sGeneration: %u Version: 0x%08x\n", prefix
,
856 inode
->i_generation
, inode
->osd1
.linux1
.l_i_version
);
858 fprintf(out
, "%sUser: %5d Group: %5d",
859 prefix
, inode_uid(*inode
), inode_gid(*inode
));
860 if (is_large_inode
&& large_inode
->i_extra_isize
>= 32)
861 fprintf(out
, " Project: %5d", large_inode
->i_projid
);
862 fputs(" Size: ", out
);
863 if (LINUX_S_ISREG(inode
->i_mode
) || LINUX_S_ISDIR(inode
->i_mode
))
864 fprintf(out
, "%llu\n", EXT2_I_SIZE(inode
));
866 fprintf(out
, "%u\n", inode
->i_size
);
867 if (os
== EXT2_OS_HURD
)
869 "%sFile ACL: %u Translator: %u\n",
872 inode
->osd1
.hurd1
.h_i_translator
);
874 fprintf(out
, "%sFile ACL: %llu\n",
876 inode
->i_file_acl
| ((long long)
877 (inode
->osd2
.linux2
.l_i_file_acl_high
) << 32));
878 if (os
!= EXT2_OS_HURD
)
879 fprintf(out
, "%sLinks: %u Blockcount: %llu\n",
880 prefix
, inode
->i_links_count
,
881 (((unsigned long long)
882 inode
->osd2
.linux2
.l_i_blocks_hi
<< 32)) +
885 fprintf(out
, "%sLinks: %u Blockcount: %u\n",
886 prefix
, inode
->i_links_count
, inode
->i_blocks
);
889 frag
= inode
->osd2
.hurd2
.h_i_frag
;
890 fsize
= inode
->osd2
.hurd2
.h_i_fsize
;
895 fprintf(out
, "%sFragment: Address: %u Number: %u Size: %u\n",
896 prefix
, inode
->i_faddr
, frag
, fsize
);
897 if (is_large_inode
&& large_inode
->i_extra_isize
>= 24) {
898 fprintf(out
, "%s ctime: 0x%08x:%08x -- %s", prefix
,
899 inode
->i_ctime
, large_inode
->i_ctime_extra
,
900 inode_time_to_string(inode
->i_ctime
,
901 large_inode
->i_ctime_extra
));
902 fprintf(out
, "%s atime: 0x%08x:%08x -- %s", prefix
,
903 inode
->i_atime
, large_inode
->i_atime_extra
,
904 inode_time_to_string(inode
->i_atime
,
905 large_inode
->i_atime_extra
));
906 fprintf(out
, "%s mtime: 0x%08x:%08x -- %s", prefix
,
907 inode
->i_mtime
, large_inode
->i_mtime_extra
,
908 inode_time_to_string(inode
->i_mtime
,
909 large_inode
->i_mtime_extra
));
910 fprintf(out
, "%scrtime: 0x%08x:%08x -- %s", prefix
,
911 large_inode
->i_crtime
, large_inode
->i_crtime_extra
,
912 inode_time_to_string(large_inode
->i_crtime
,
913 large_inode
->i_crtime_extra
));
915 fprintf(out
, "%s dtime: 0x%08x:(%08x) -- %s", prefix
,
916 large_inode
->i_dtime
, large_inode
->i_ctime_extra
,
917 inode_time_to_string(inode
->i_dtime
,
918 large_inode
->i_ctime_extra
));
920 fprintf(out
, "%sctime: 0x%08x -- %s", prefix
, inode
->i_ctime
,
921 time_to_string((__s32
) inode
->i_ctime
));
922 fprintf(out
, "%satime: 0x%08x -- %s", prefix
, inode
->i_atime
,
923 time_to_string((__s32
) inode
->i_atime
));
924 fprintf(out
, "%smtime: 0x%08x -- %s", prefix
, inode
->i_mtime
,
925 time_to_string((__s32
) inode
->i_mtime
));
927 fprintf(out
, "%sdtime: 0x%08x -- %s", prefix
,
929 time_to_string((__s32
) inode
->i_dtime
));
931 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
932 internal_dump_inode_extra(out
, prefix
, inode_num
,
933 (struct ext2_inode_large
*) inode
);
934 dump_inode_attributes(out
, inode_num
);
935 if (ext2fs_has_feature_metadata_csum(current_fs
->super
)) {
936 __u32 crc
= inode
->i_checksum_lo
;
937 if (is_large_inode
&&
938 large_inode
->i_extra_isize
>=
939 (offsetof(struct ext2_inode_large
,
941 EXT2_GOOD_OLD_INODE_SIZE
))
942 crc
|= ((__u32
)large_inode
->i_checksum_hi
) << 16;
943 fprintf(out
, "Inode checksum: 0x%08x\n", crc
);
946 if (LINUX_S_ISLNK(inode
->i_mode
) && ext2fs_is_fast_symlink(inode
))
947 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
948 (int)EXT2_I_SIZE(inode
), (char *)inode
->i_block
);
949 else if (LINUX_S_ISLNK(inode
->i_mode
) &&
950 (inode
->i_flags
& EXT4_INLINE_DATA_FL
))
951 dump_inline_symlink(out
, inode_num
, inode
, prefix
);
952 else if (LINUX_S_ISBLK(inode
->i_mode
) || LINUX_S_ISCHR(inode
->i_mode
)) {
956 if (inode
->i_block
[0]) {
957 major
= (inode
->i_block
[0] >> 8) & 255;
958 minor
= inode
->i_block
[0] & 255;
961 major
= (inode
->i_block
[1] & 0xfff00) >> 8;
962 minor
= ((inode
->i_block
[1] & 0xff) |
963 ((inode
->i_block
[1] >> 12) & 0xfff00));
964 devnote
= "(New-style) ";
966 fprintf(out
, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n",
967 devnote
, major
, minor
, major
, minor
);
968 } else if (do_dump_blocks
) {
969 if (inode
->i_flags
& EXT4_EXTENTS_FL
)
970 dump_extents(out
, prefix
, inode_num
,
971 DUMP_LEAF_EXTENTS
|DUMP_NODE_EXTENTS
, 0, 0);
972 else if (inode
->i_flags
& EXT4_INLINE_DATA_FL
)
973 dump_inline_data(out
, prefix
, inode_num
);
975 dump_blocks(out
, prefix
, inode_num
);
979 static void dump_inode(ext2_ino_t inode_num
, struct ext2_inode
*inode
)
984 internal_dump_inode(out
, "", inode_num
, inode
, 1);
988 void do_stat(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
989 void *infop
EXT2FS_ATTR((unused
)))
992 struct ext2_inode
* inode_buf
;
994 if (check_fs_open(argv
[0]))
997 inode_buf
= (struct ext2_inode
*)
998 malloc(EXT2_INODE_SIZE(current_fs
->super
));
1000 fprintf(stderr
, "do_stat: can't allocate buffer\n");
1004 if (common_inode_args_process(argc
, argv
, &inode
, 0)) {
1009 if (debugfs_read_inode2(inode
, inode_buf
, argv
[0],
1010 EXT2_INODE_SIZE(current_fs
->super
), 0)) {
1015 dump_inode(inode
, inode_buf
);
1020 void do_dump_extents(int argc
, char **argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1021 void *infop
EXT2FS_ATTR((unused
)))
1023 struct ext2_inode inode
;
1031 while ((c
= getopt(argc
, argv
, "nl")) != EOF
) {
1034 flags
|= DUMP_NODE_EXTENTS
;
1037 flags
|= DUMP_LEAF_EXTENTS
;
1042 if (argc
!= optind
+ 1) {
1043 com_err(0, 0, "Usage: dump_extents [-n] [-l] file");
1048 flags
= DUMP_NODE_EXTENTS
| DUMP_LEAF_EXTENTS
;
1049 flags
|= DUMP_EXTENT_TABLE
;
1051 if (check_fs_open(argv
[0]))
1054 ino
= string_to_inode(argv
[optind
]);
1058 if (debugfs_read_inode(ino
, &inode
, argv
[0]))
1061 if ((inode
.i_flags
& EXT4_EXTENTS_FL
) == 0) {
1062 fprintf(stderr
, "%s: does not uses extent block maps\n",
1067 logical_width
= int_log10((EXT2_I_SIZE(&inode
)+current_fs
->blocksize
-1)/
1068 current_fs
->blocksize
) + 1;
1069 if (logical_width
< 5)
1071 physical_width
= int_log10(ext2fs_blocks_count(current_fs
->super
)) + 1;
1072 if (physical_width
< 5)
1076 dump_extents(out
, "", ino
, flags
, logical_width
, physical_width
);
1081 static int print_blocks_proc(ext2_filsys fs
EXT2FS_ATTR((unused
)),
1083 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1084 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1085 int ref_offset
EXT2FS_ATTR((unused
)),
1086 void *private EXT2FS_ATTR((unused
)))
1088 printf("%llu ", *blocknr
);
1092 void do_blocks(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1093 void *infop
EXT2FS_ATTR((unused
)))
1097 if (check_fs_open(argv
[0]))
1100 if (common_inode_args_process(argc
, argv
, &inode
, 0)) {
1104 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
, NULL
,
1105 print_blocks_proc
, NULL
);
1106 fputc('\n', stdout
);
1110 void do_chroot(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1111 void *infop
EXT2FS_ATTR((unused
)))
1116 if (common_inode_args_process(argc
, argv
, &inode
, 0))
1119 retval
= ext2fs_check_directory(current_fs
, inode
);
1121 com_err(argv
[1], retval
, 0);
1128 void do_clri(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1129 void *infop
EXT2FS_ATTR((unused
)))
1132 struct ext2_inode inode_buf
;
1134 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_RW
))
1137 if (debugfs_read_inode(inode
, &inode_buf
, argv
[0]))
1139 memset(&inode_buf
, 0, sizeof(inode_buf
));
1140 if (debugfs_write_inode(inode
, &inode_buf
, argv
[0]))
1144 void do_freei(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1145 void *infop
EXT2FS_ATTR((unused
)))
1147 unsigned int len
= 1;
1151 if (common_args_process(argc
, argv
, 2, 3, argv
[0], "<file> [num]",
1152 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1154 if (check_fs_read_write(argv
[0]))
1157 inode
= string_to_inode(argv
[1]);
1162 len
= parse_ulong(argv
[2], argv
[0], "length", &err
);
1168 !ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1169 com_err(argv
[0], 0, "Warning: inode already clear");
1171 ext2fs_unmark_inode_bitmap2(current_fs
->inode_map
, inode
++);
1172 ext2fs_mark_ib_dirty(current_fs
);
1175 void do_seti(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1176 void *infop
EXT2FS_ATTR((unused
)))
1178 unsigned int len
= 1;
1182 if (common_args_process(argc
, argv
, 2, 3, argv
[0], "<file> [num]",
1183 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1185 if (check_fs_read_write(argv
[0]))
1188 inode
= string_to_inode(argv
[1]);
1193 len
= parse_ulong(argv
[2], argv
[0], "length", &err
);
1199 ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1200 com_err(argv
[0], 0, "Warning: inode already set");
1202 ext2fs_mark_inode_bitmap2(current_fs
->inode_map
, inode
++);
1203 ext2fs_mark_ib_dirty(current_fs
);
1205 #endif /* READ_ONLY */
1207 void do_testi(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1208 void *infop
EXT2FS_ATTR((unused
)))
1212 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_BITMAPS
))
1215 if (ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1216 printf("Inode %u is marked in use\n", inode
);
1218 printf("Inode %u is not in use\n", inode
);
1222 void do_freeb(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1223 void *infop
EXT2FS_ATTR((unused
)))
1228 if (common_block_args_process(argc
, argv
, &block
, &count
))
1230 if (check_fs_read_write(argv
[0]))
1232 while (count
-- > 0) {
1233 if (!ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1234 com_err(argv
[0], 0, "Warning: block %llu already clear",
1236 ext2fs_unmark_block_bitmap2(current_fs
->block_map
,block
);
1239 ext2fs_mark_bb_dirty(current_fs
);
1242 void do_setb(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1243 void *infop
EXT2FS_ATTR((unused
)))
1248 if (common_block_args_process(argc
, argv
, &block
, &count
))
1250 if (check_fs_read_write(argv
[0]))
1252 while (count
-- > 0) {
1253 if (ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1254 com_err(argv
[0], 0, "Warning: block %llu already set",
1256 ext2fs_mark_block_bitmap2(current_fs
->block_map
,block
);
1259 ext2fs_mark_bb_dirty(current_fs
);
1261 #endif /* READ_ONLY */
1263 void do_testb(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1264 void *infop
EXT2FS_ATTR((unused
)))
1269 if (common_block_args_process(argc
, argv
, &block
, &count
))
1271 while (count
-- > 0) {
1272 if (ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1273 printf("Block %llu marked in use\n", block
);
1275 printf("Block %llu not in use\n", block
);
1281 static void modify_u8(char *com
, const char *prompt
,
1282 const char *format
, __u8
*val
)
1288 sprintf(buf
, format
, *val
);
1289 printf("%30s [%s] ", prompt
, buf
);
1290 if (!fgets(buf
, sizeof(buf
), stdin
))
1292 if (buf
[strlen (buf
) - 1] == '\n')
1293 buf
[strlen (buf
) - 1] = '\0';
1296 v
= strtoul(buf
, &tmp
, 0);
1298 com_err(com
, 0, "Bad value - %s", buf
);
1303 static void modify_u16(char *com
, const char *prompt
,
1304 const char *format
, __u16
*val
)
1310 sprintf(buf
, format
, *val
);
1311 printf("%30s [%s] ", prompt
, buf
);
1312 if (!fgets(buf
, sizeof(buf
), stdin
))
1314 if (buf
[strlen (buf
) - 1] == '\n')
1315 buf
[strlen (buf
) - 1] = '\0';
1318 v
= strtoul(buf
, &tmp
, 0);
1320 com_err(com
, 0, "Bad value - %s", buf
);
1325 static void modify_u32(char *com
, const char *prompt
,
1326 const char *format
, __u32
*val
)
1332 sprintf(buf
, format
, *val
);
1333 printf("%30s [%s] ", prompt
, buf
);
1334 if (!fgets(buf
, sizeof(buf
), stdin
))
1336 if (buf
[strlen (buf
) - 1] == '\n')
1337 buf
[strlen (buf
) - 1] = '\0';
1340 v
= strtoul(buf
, &tmp
, 0);
1342 com_err(com
, 0, "Bad value - %s", buf
);
1348 void do_modify_inode(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1349 void *infop
EXT2FS_ATTR((unused
)))
1351 struct ext2_inode inode
;
1352 ext2_ino_t inode_num
;
1354 unsigned char *frag
, *fsize
;
1357 const char *hex_format
= "0x%x";
1358 const char *octal_format
= "0%o";
1359 const char *decimal_format
= "%d";
1360 const char *unsignedlong_format
= "%lu";
1362 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1365 os
= current_fs
->super
->s_creator_os
;
1367 if (debugfs_read_inode(inode_num
, &inode
, argv
[1]))
1370 modify_u16(argv
[0], "Mode", octal_format
, &inode
.i_mode
);
1371 modify_u16(argv
[0], "User ID", decimal_format
, &inode
.i_uid
);
1372 modify_u16(argv
[0], "Group ID", decimal_format
, &inode
.i_gid
);
1373 modify_u32(argv
[0], "Size", unsignedlong_format
, &inode
.i_size
);
1374 modify_u32(argv
[0], "Creation time", decimal_format
, &inode
.i_ctime
);
1375 modify_u32(argv
[0], "Modification time", decimal_format
, &inode
.i_mtime
);
1376 modify_u32(argv
[0], "Access time", decimal_format
, &inode
.i_atime
);
1377 modify_u32(argv
[0], "Deletion time", decimal_format
, &inode
.i_dtime
);
1378 modify_u16(argv
[0], "Link count", decimal_format
, &inode
.i_links_count
);
1379 if (os
== EXT2_OS_LINUX
)
1380 modify_u16(argv
[0], "Block count high", unsignedlong_format
,
1381 &inode
.osd2
.linux2
.l_i_blocks_hi
);
1382 modify_u32(argv
[0], "Block count", unsignedlong_format
, &inode
.i_blocks
);
1383 modify_u32(argv
[0], "File flags", hex_format
, &inode
.i_flags
);
1384 modify_u32(argv
[0], "Generation", hex_format
, &inode
.i_generation
);
1386 modify_u32(argv
[0], "Reserved1", decimal_format
, &inode
.i_reserved1
);
1388 modify_u32(argv
[0], "File acl", decimal_format
, &inode
.i_file_acl
);
1390 modify_u32(argv
[0], "High 32bits of size", decimal_format
,
1391 &inode
.i_size_high
);
1393 if (os
== EXT2_OS_HURD
)
1394 modify_u32(argv
[0], "Translator Block",
1395 decimal_format
, &inode
.osd1
.hurd1
.h_i_translator
);
1397 modify_u32(argv
[0], "Fragment address", decimal_format
, &inode
.i_faddr
);
1400 frag
= &inode
.osd2
.hurd2
.h_i_frag
;
1401 fsize
= &inode
.osd2
.hurd2
.h_i_fsize
;
1407 modify_u8(argv
[0], "Fragment number", decimal_format
, frag
);
1409 modify_u8(argv
[0], "Fragment size", decimal_format
, fsize
);
1411 for (i
=0; i
< EXT2_NDIR_BLOCKS
; i
++) {
1412 sprintf(buf
, "Direct Block #%u", i
);
1413 modify_u32(argv
[0], buf
, decimal_format
, &inode
.i_block
[i
]);
1415 modify_u32(argv
[0], "Indirect Block", decimal_format
,
1416 &inode
.i_block
[EXT2_IND_BLOCK
]);
1417 modify_u32(argv
[0], "Double Indirect Block", decimal_format
,
1418 &inode
.i_block
[EXT2_DIND_BLOCK
]);
1419 modify_u32(argv
[0], "Triple Indirect Block", decimal_format
,
1420 &inode
.i_block
[EXT2_TIND_BLOCK
]);
1421 if (debugfs_write_inode(inode_num
, &inode
, argv
[1]))
1424 #endif /* READ_ONLY */
1426 void do_change_working_dir(int argc
, char *argv
[],
1427 int sci_idx
EXT2FS_ATTR((unused
)),
1428 void *infop
EXT2FS_ATTR((unused
)))
1433 if (common_inode_args_process(argc
, argv
, &inode
, 0))
1436 retval
= ext2fs_check_directory(current_fs
, inode
);
1438 com_err(argv
[1], retval
, 0);
1445 void do_print_working_directory(int argc
, char *argv
[],
1446 int sci_idx
EXT2FS_ATTR((unused
)),
1447 void *infop
EXT2FS_ATTR((unused
)))
1450 char *pathname
= NULL
;
1452 if (common_args_process(argc
, argv
, 1, 1,
1453 "print_working_directory", "", 0))
1456 retval
= ext2fs_get_pathname(current_fs
, cwd
, 0, &pathname
);
1458 com_err(argv
[0], retval
,
1459 "while trying to get pathname of cwd");
1461 printf("[pwd] INODE: %6u PATH: %s\n",
1462 cwd
, pathname
? pathname
: "NULL");
1467 retval
= ext2fs_get_pathname(current_fs
, root
, 0, &pathname
);
1469 com_err(argv
[0], retval
,
1470 "while trying to get pathname of root");
1472 printf("[root] INODE: %6u PATH: %s\n",
1473 root
, pathname
? pathname
: "NULL");
1482 static void make_link(char *sourcename
, char *destname
)
1485 struct ext2_inode inode
;
1488 char *dest
, *cp
, *base_name
;
1491 * Get the source inode
1493 ino
= string_to_inode(sourcename
);
1496 base_name
= strrchr(sourcename
, '/');
1500 base_name
= sourcename
;
1502 * Figure out the destination. First see if it exists and is
1505 if (! (retval
=ext2fs_namei(current_fs
, root
, cwd
, destname
, &dir
)))
1509 * OK, it doesn't exist. See if it is
1510 * '<dir>/basename' or 'basename'
1512 cp
= strrchr(destname
, '/');
1515 dir
= string_to_inode(destname
);
1525 if (debugfs_read_inode(ino
, &inode
, sourcename
))
1528 retval
= ext2fs_link(current_fs
, dir
, dest
, ino
,
1529 ext2_file_type(inode
.i_mode
));
1531 com_err("make_link", retval
, 0);
1536 void do_link(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1537 void *infop
EXT2FS_ATTR((unused
)))
1539 if (common_args_process(argc
, argv
, 3, 3, "link",
1540 "<source file> <dest_name>", CHECK_FS_RW
))
1543 make_link(argv
[1], argv
[2]);
1546 static int mark_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1547 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1548 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1549 int ref_offset
EXT2FS_ATTR((unused
)),
1550 void *private EXT2FS_ATTR((unused
)))
1555 ext2fs_block_alloc_stats2(fs
, block
, +1);
1559 void do_undel(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1560 void *infop
EXT2FS_ATTR((unused
)))
1563 struct ext2_inode inode
;
1565 if (common_args_process(argc
, argv
, 2, 3, "undelete",
1566 "<inode_num> [dest_name]",
1567 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1570 ino
= string_to_inode(argv
[1]);
1574 if (debugfs_read_inode(ino
, &inode
, argv
[1]))
1577 if (ext2fs_test_inode_bitmap2(current_fs
->inode_map
, ino
)) {
1578 com_err(argv
[1], 0, "Inode is not marked as deleted");
1583 * XXX this function doesn't handle changing the links count on the
1584 * parent directory when undeleting a directory.
1586 inode
.i_links_count
= LINUX_S_ISDIR(inode
.i_mode
) ? 2 : 1;
1589 if (debugfs_write_inode(ino
, &inode
, argv
[0]))
1592 ext2fs_block_iterate3(current_fs
, ino
, BLOCK_FLAG_READ_ONLY
, NULL
,
1593 mark_blocks_proc
, NULL
);
1595 ext2fs_inode_alloc_stats2(current_fs
, ino
, +1, 0);
1598 make_link(argv
[1], argv
[2]);
1601 static void unlink_file_by_name(char *filename
)
1607 base_name
= strrchr(filename
, '/');
1609 *base_name
++ = '\0';
1610 dir
= string_to_inode(filename
);
1615 base_name
= filename
;
1617 retval
= ext2fs_unlink(current_fs
, dir
, base_name
, 0, 0);
1619 com_err("unlink_file_by_name", retval
, 0);
1623 void do_unlink(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1624 void *infop
EXT2FS_ATTR((unused
)))
1626 if (common_args_process(argc
, argv
, 2, 2, "link",
1627 "<pathname>", CHECK_FS_RW
))
1630 unlink_file_by_name(argv
[1]);
1633 void do_copy_inode(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1634 void *infop
EXT2FS_ATTR((unused
)))
1636 ext2_ino_t src_ino
, dest_ino
;
1637 unsigned char buf
[4096];
1639 if (common_args_process(argc
, argv
, 3, 3, "copy_inode",
1640 "<source file> <dest_name>", CHECK_FS_RW
))
1643 src_ino
= string_to_inode(argv
[1]);
1647 dest_ino
= string_to_inode(argv
[2]);
1651 if (debugfs_read_inode2(src_ino
, (struct ext2_inode
*) buf
,
1652 argv
[0], sizeof(buf
), 0))
1655 if (debugfs_write_inode2(dest_ino
, (struct ext2_inode
*) buf
,
1656 argv
[0], sizeof(buf
), 0))
1660 #endif /* READ_ONLY */
1662 void do_find_free_block(int argc
, char *argv
[],
1663 int sci_idx
EXT2FS_ATTR((unused
)),
1664 void *infop
EXT2FS_ATTR((unused
)))
1666 blk64_t free_blk
, goal
, first_free
= 0;
1671 if ((argc
> 3) || (argc
==2 && *argv
[1] == '?')) {
1672 com_err(argv
[0], 0, "Usage: find_free_block [count [goal]]");
1675 if (check_fs_open(argv
[0]))
1679 count
= strtol(argv
[1],&tmp
,0);
1681 com_err(argv
[0], 0, "Bad count - %s", argv
[1]);
1688 goal
= strtol(argv
[2], &tmp
, 0);
1690 com_err(argv
[0], 0, "Bad goal - %s", argv
[1]);
1695 goal
= current_fs
->super
->s_first_data_block
;
1697 printf("Free blocks found: ");
1698 free_blk
= goal
- 1;
1699 while (count
-- > 0) {
1700 retval
= ext2fs_new_block2(current_fs
, free_blk
+ 1, 0,
1703 if (first_free
== free_blk
)
1706 first_free
= free_blk
;
1708 com_err("ext2fs_new_block", retval
, 0);
1711 printf("%llu ", free_blk
);
1716 void do_find_free_inode(int argc
, char *argv
[],
1717 int sci_idx
EXT2FS_ATTR((unused
)),
1718 void *infop
EXT2FS_ATTR((unused
)))
1720 ext2_ino_t free_inode
, dir
;
1725 if (argc
> 3 || (argc
>1 && *argv
[1] == '?')) {
1726 com_err(argv
[0], 0, "Usage: find_free_inode [dir [mode]]");
1729 if (check_fs_open(argv
[0]))
1733 dir
= strtol(argv
[1], &tmp
, 0);
1735 com_err(argv
[0], 0, "Bad dir - %s", argv
[1]);
1742 mode
= strtol(argv
[2], &tmp
, 0);
1744 com_err(argv
[0], 0, "Bad mode - %s", argv
[2]);
1750 retval
= ext2fs_new_inode(current_fs
, dir
, mode
, 0, &free_inode
);
1752 com_err("ext2fs_new_inode", retval
, 0);
1754 printf("Free inode found: %u\n", free_inode
);
1758 void do_write(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1759 void *infop
EXT2FS_ATTR((unused
)))
1763 if (common_args_process(argc
, argv
, 3, 3, "write",
1764 "<native file> <new file>", CHECK_FS_RW
))
1767 retval
= do_write_internal(current_fs
, cwd
, argv
[1], argv
[2], root
);
1769 com_err(argv
[0], retval
, 0);
1772 void do_mknod(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1773 void *infop
EXT2FS_ATTR((unused
)))
1775 unsigned long major
, minor
;
1780 if (check_fs_open(argv
[0]))
1782 if (argc
< 3 || argv
[2][1]) {
1784 com_err(argv
[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
1789 switch (argv
[2][0]) {
1791 st
.st_mode
= S_IFIFO
;
1795 st
.st_mode
= S_IFCHR
;
1799 st
.st_mode
= S_IFBLK
;
1807 major
= strtoul(argv
[3], argv
+3, 0);
1808 minor
= strtoul(argv
[4], argv
+4, 0);
1809 if (major
> 65535 || minor
> 65535 || argv
[3][0] || argv
[4][0])
1816 st
.st_rdev
= makedev(major
, minor
);
1817 retval
= do_mknod_internal(current_fs
, cwd
, argv
[1],
1818 st
.st_mode
, st
.st_rdev
);
1820 com_err(argv
[0], retval
, 0);
1823 void do_mkdir(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1824 void *infop
EXT2FS_ATTR((unused
)))
1828 if (common_args_process(argc
, argv
, 2, 2, "mkdir",
1829 "<filename>", CHECK_FS_RW
))
1832 retval
= do_mkdir_internal(current_fs
, cwd
, argv
[1], root
);
1834 com_err(argv
[0], retval
, 0);
1838 static int release_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1839 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1840 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1841 int ref_offset
EXT2FS_ATTR((unused
)),
1844 blk64_t block
= *blocknr
;
1845 blk64_t
*last_cluster
= (blk64_t
*)private;
1846 blk64_t cluster
= EXT2FS_B2C(fs
, block
);
1848 if (cluster
== *last_cluster
)
1851 *last_cluster
= cluster
;
1853 ext2fs_block_alloc_stats2(fs
, block
, -1);
1857 static void kill_file_by_inode(ext2_ino_t inode
)
1859 struct ext2_inode inode_buf
;
1861 if (debugfs_read_inode(inode
, &inode_buf
, 0))
1863 inode_buf
.i_dtime
= current_fs
->now
? current_fs
->now
: time(0);
1864 if (debugfs_write_inode(inode
, &inode_buf
, 0))
1866 if (ext2fs_inode_has_valid_blocks2(current_fs
, &inode_buf
)) {
1867 blk64_t last_cluster
= 0;
1868 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
,
1869 NULL
, release_blocks_proc
, &last_cluster
);
1872 ext2fs_inode_alloc_stats2(current_fs
, inode
, -1,
1873 LINUX_S_ISDIR(inode_buf
.i_mode
));
1877 void do_kill_file(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1878 void *infop
EXT2FS_ATTR((unused
)))
1880 ext2_ino_t inode_num
;
1882 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1885 kill_file_by_inode(inode_num
);
1888 void do_rm(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1889 void *infop
EXT2FS_ATTR((unused
)))
1892 ext2_ino_t inode_num
;
1893 struct ext2_inode inode
;
1895 if (common_args_process(argc
, argv
, 2, 2, "rm",
1896 "<filename>", CHECK_FS_RW
))
1899 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1901 com_err(argv
[0], retval
, "while trying to resolve filename");
1905 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1908 if (LINUX_S_ISDIR(inode
.i_mode
)) {
1909 com_err(argv
[0], 0, "file is a directory");
1913 --inode
.i_links_count
;
1914 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
1917 unlink_file_by_name(argv
[1]);
1918 if (inode
.i_links_count
== 0)
1919 kill_file_by_inode(inode_num
);
1927 static int rmdir_proc(ext2_ino_t dir
EXT2FS_ATTR((unused
)),
1928 int entry
EXT2FS_ATTR((unused
)),
1929 struct ext2_dir_entry
*dirent
,
1930 int offset
EXT2FS_ATTR((unused
)),
1931 int blocksize
EXT2FS_ATTR((unused
)),
1932 char *buf
EXT2FS_ATTR((unused
)),
1935 struct rd_struct
*rds
= (struct rd_struct
*) private;
1937 if (dirent
->inode
== 0)
1939 if ((ext2fs_dirent_name_len(dirent
) == 1) && (dirent
->name
[0] == '.'))
1941 if ((ext2fs_dirent_name_len(dirent
) == 2) && (dirent
->name
[0] == '.') &&
1942 (dirent
->name
[1] == '.')) {
1943 rds
->parent
= dirent
->inode
;
1950 void do_rmdir(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
1951 void *infop
EXT2FS_ATTR((unused
)))
1954 ext2_ino_t inode_num
;
1955 struct ext2_inode inode
;
1956 struct rd_struct rds
;
1958 if (common_args_process(argc
, argv
, 2, 2, "rmdir",
1959 "<filename>", CHECK_FS_RW
))
1962 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1964 com_err(argv
[0], retval
, "while trying to resolve filename");
1968 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1971 if (!LINUX_S_ISDIR(inode
.i_mode
)) {
1972 com_err(argv
[0], 0, "file is not a directory");
1979 retval
= ext2fs_dir_iterate2(current_fs
, inode_num
, 0,
1980 0, rmdir_proc
, &rds
);
1982 com_err(argv
[0], retval
, "while iterating over directory");
1985 if (rds
.empty
== 0) {
1986 com_err(argv
[0], 0, "directory not empty");
1990 inode
.i_links_count
= 0;
1991 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
1994 unlink_file_by_name(argv
[1]);
1995 kill_file_by_inode(inode_num
);
1998 if (debugfs_read_inode(rds
.parent
, &inode
, argv
[0]))
2000 if (inode
.i_links_count
> 1)
2001 inode
.i_links_count
--;
2002 if (debugfs_write_inode(rds
.parent
, &inode
, argv
[0]))
2006 #endif /* READ_ONLY */
2008 void do_show_debugfs_params(int argc
EXT2FS_ATTR((unused
)),
2009 char *argv
[] EXT2FS_ATTR((unused
)),
2010 int sci_idx
EXT2FS_ATTR((unused
)),
2011 void *infop
EXT2FS_ATTR((unused
)))
2014 printf("Open mode: read-%s\n",
2015 current_fs
->flags
& EXT2_FLAG_RW
? "write" : "only");
2016 printf("Filesystem in use: %s\n",
2017 current_fs
? current_fs
->device_name
: "--none--");
2021 void do_expand_dir(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2022 void *infop
EXT2FS_ATTR((unused
)))
2027 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_RW
))
2030 retval
= ext2fs_expand_dir(current_fs
, inode
);
2032 com_err("ext2fs_expand_dir", retval
, 0);
2036 void do_features(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2037 void *infop
EXT2FS_ATTR((unused
)))
2041 if (check_fs_open(argv
[0]))
2044 if ((argc
!= 1) && check_fs_read_write(argv
[0]))
2046 for (i
=1; i
< argc
; i
++) {
2047 if (e2p_edit_feature(argv
[i
],
2048 ¤t_fs
->super
->s_feature_compat
, 0))
2049 com_err(argv
[0], 0, "Unknown feature: %s\n",
2052 ext2fs_mark_super_dirty(current_fs
);
2054 print_features(current_fs
->super
, stdout
);
2056 #endif /* READ_ONLY */
2058 void do_bmap(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2059 void *infop
EXT2FS_ATTR((unused
)))
2062 blk64_t blk
, pblk
= 0;
2063 int c
, err
, flags
= 0, ret_flags
= 0;
2066 if (check_fs_open(argv
[0]))
2070 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
2073 flags
|= BMAP_ALLOC
;
2080 if (argc
<= optind
+1) {
2083 "Usage: bmap [-a] <file> logical_blk [physical_blk]");
2087 ino
= string_to_inode(argv
[optind
++]);
2090 err
= strtoblk(argv
[0], argv
[optind
++], "logical block", &blk
);
2094 if (argc
> optind
+1)
2097 if (argc
== optind
+1) {
2098 err
= strtoblk(argv
[0], argv
[optind
++],
2099 "physical block", &pblk
);
2102 if (flags
& BMAP_ALLOC
) {
2103 com_err(0, 0, "Can't set and allocate a block");
2109 errcode
= ext2fs_bmap2(current_fs
, ino
, 0, 0, flags
, blk
,
2112 com_err(argv
[0], errcode
,
2113 "while mapping logical block %llu\n", blk
);
2116 printf("%llu", pblk
);
2117 if (ret_flags
& BMAP_RET_UNINIT
)
2118 fputs(" (uninit)", stdout
);
2119 fputc('\n', stdout
);
2122 void do_imap(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2123 void *infop
EXT2FS_ATTR((unused
)))
2126 unsigned long group
, block
, block_nr
, offset
;
2128 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2131 ino
= string_to_inode(argv
[1]);
2135 group
= (ino
- 1) / EXT2_INODES_PER_GROUP(current_fs
->super
);
2136 offset
= ((ino
- 1) % EXT2_INODES_PER_GROUP(current_fs
->super
)) *
2137 EXT2_INODE_SIZE(current_fs
->super
);
2138 block
= offset
>> EXT2_BLOCK_SIZE_BITS(current_fs
->super
);
2139 if (!ext2fs_inode_table_loc(current_fs
, (unsigned)group
)) {
2140 com_err(argv
[0], 0, "Inode table for group %lu is missing\n",
2144 block_nr
= ext2fs_inode_table_loc(current_fs
, (unsigned)group
) +
2146 offset
&= (EXT2_BLOCK_SIZE(current_fs
->super
) - 1);
2148 printf("Inode %u is part of block group %lu\n"
2149 "\tlocated at block %lu, offset 0x%04lx\n", ino
, group
,
2154 void do_idump(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2155 void *infop
EXT2FS_ATTR((unused
)))
2157 struct ext2_inode_large
*inode
;
2161 unsigned int isize
, size
, offset
= 0;
2165 while ((c
= getopt (argc
, argv
, "bex")) != EOF
) {
2166 if (mode
|| c
== '?') {
2168 "Usage: inode_dump [-b]|[-e] <file>");
2173 if (optind
!= argc
-1)
2176 if (check_fs_open(argv
[0]))
2179 ino
= string_to_inode(argv
[optind
]);
2183 isize
= EXT2_INODE_SIZE(current_fs
->super
);
2184 err
= ext2fs_get_mem(isize
, &buf
);
2186 com_err(argv
[0], err
, "while allocating memory");
2190 err
= ext2fs_read_inode_full(current_fs
, ino
,
2191 (struct ext2_inode
*)buf
, isize
);
2193 com_err(argv
[0], err
, "while reading inode %u", ino
);
2197 inode
= (struct ext2_inode_large
*) buf
;
2201 offset
= ((char *) (&inode
->i_block
)) - ((char *) buf
);
2202 size
= sizeof(inode
->i_block
);
2206 if (size
<= EXT2_GOOD_OLD_INODE_SIZE
) {
2207 com_err(argv
[0], 0, "No extra space in inode");
2210 offset
= EXT2_GOOD_OLD_INODE_SIZE
+ inode
->i_extra_isize
;
2217 raw_inode_xattr_dump(stdout
, buf
+ offset
, size
);
2219 do_byte_hexdump(stdout
, buf
+ offset
, size
);
2221 ext2fs_free_mem(&buf
);
2225 void do_set_current_time(int argc
, char *argv
[],
2226 int sci_idx
EXT2FS_ATTR((unused
)),
2227 void *infop
EXT2FS_ATTR((unused
)))
2231 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2235 now
= string_to_time(argv
[1]);
2237 com_err(argv
[0], 0, "Couldn't parse argument as a time: %s\n",
2242 printf("Setting current time to %s\n", time_to_string(now
));
2243 current_fs
->now
= now
;
2246 #endif /* READ_ONLY */
2248 static int find_supp_feature(__u32
*supp
, int feature_type
, char *name
)
2250 int compat
, bit
, ret
;
2251 unsigned int feature_mask
;
2254 if (feature_type
== E2P_FS_FEATURE
)
2255 ret
= e2p_string2feature(name
, &compat
, &feature_mask
);
2257 ret
= e2p_jrnl_string2feature(name
, &compat
,
2262 if (!(supp
[compat
] & feature_mask
))
2265 for (compat
= 0; compat
< 3; compat
++) {
2266 for (bit
= 0, feature_mask
= 1; bit
< 32;
2267 bit
++, feature_mask
<<= 1) {
2268 if (supp
[compat
] & feature_mask
) {
2269 if (feature_type
== E2P_FS_FEATURE
)
2270 fprintf(stdout
, " %s",
2271 e2p_feature2string(compat
,
2274 fprintf(stdout
, " %s",
2275 e2p_jrnl_feature2string(compat
,
2280 fprintf(stdout
, "\n");
2286 void do_supported_features(int argc
, char *argv
[],
2287 int sci_idx
EXT2FS_ATTR((unused
)),
2288 void *infop
EXT2FS_ATTR((unused
)))
2291 __u32 supp
[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP
,
2292 EXT2_LIB_FEATURE_INCOMPAT_SUPP
,
2293 EXT2_LIB_FEATURE_RO_COMPAT_SUPP
};
2294 __u32 jrnl_supp
[3] = { JBD2_KNOWN_COMPAT_FEATURES
,
2295 JBD2_KNOWN_INCOMPAT_FEATURES
,
2296 JBD2_KNOWN_ROCOMPAT_FEATURES
};
2299 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, argv
[1]);
2301 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
,
2305 com_err(argv
[0], 0, "Unknown feature: %s\n", argv
[1]);
2307 fprintf(stdout
, "Supported feature: %s\n", argv
[1]);
2309 fprintf(stdout
, "Supported features:");
2310 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, NULL
);
2311 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
, NULL
);
2316 void do_punch(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2317 void *infop
EXT2FS_ATTR((unused
)))
2324 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2325 "<file> start_blk [end_blk]",
2326 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2329 ino
= string_to_inode(argv
[1]);
2332 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2336 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2342 errcode
= ext2fs_punch(current_fs
, ino
, 0, 0, start
, end
);
2345 com_err(argv
[0], errcode
,
2346 "while truncating inode %u from %llu to %llu\n", ino
,
2347 (unsigned long long) start
, (unsigned long long) end
);
2352 void do_fallocate(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2353 void *infop
EXT2FS_ATTR((unused
)))
2360 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2361 "<file> start_blk [end_blk]",
2362 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2365 ino
= string_to_inode(argv
[1]);
2368 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2372 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2378 errcode
= ext2fs_fallocate(current_fs
, EXT2_FALLOCATE_INIT_BEYOND_EOF
,
2379 ino
, NULL
, ~0ULL, start
, end
- start
+ 1);
2382 com_err(argv
[0], errcode
,
2383 "while fallocating inode %u from %llu to %llu\n", ino
,
2384 (unsigned long long) start
, (unsigned long long) end
);
2389 void do_symlink(int argc
, char *argv
[], int sci_idx
EXT2FS_ATTR((unused
)),
2390 void *infop
EXT2FS_ATTR((unused
)))
2394 if (common_args_process(argc
, argv
, 3, 3, "symlink",
2395 "<filename> <target>", CHECK_FS_RW
))
2398 retval
= do_symlink_internal(current_fs
, cwd
, argv
[1], argv
[2], root
);
2400 com_err(argv
[0], retval
, 0);
2403 #endif /* READ_ONLY */
2406 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)), char *argv
[],
2407 int sci_idx
EXT2FS_ATTR((unused
)),
2408 void *infop
EXT2FS_ATTR((unused
)))
2410 struct mmp_struct
*mmp_s
;
2411 unsigned long long mmp_block
;
2413 errcode_t retval
= 0;
2415 if (check_fs_open(argv
[0]))
2420 mmp_block
= strtoull(argv
[1], &end
, 0);
2421 if (end
== argv
[0] || mmp_block
== 0) {
2422 fprintf(stderr
, "%s: invalid MMP block '%s' given\n",
2427 mmp_block
= current_fs
->super
->s_mmp_block
;
2430 if (mmp_block
== 0) {
2431 fprintf(stderr
, "%s: MMP: not active on this filesystem.\n",
2436 if (current_fs
->mmp_buf
== NULL
) {
2437 retval
= ext2fs_get_mem(current_fs
->blocksize
,
2438 ¤t_fs
->mmp_buf
);
2440 com_err(argv
[0], retval
, "allocating MMP buffer.\n");
2445 mmp_s
= current_fs
->mmp_buf
;
2447 retval
= ext2fs_mmp_read(current_fs
, mmp_block
, current_fs
->mmp_buf
);
2449 com_err(argv
[0], retval
, "reading MMP block %llu.\n",
2454 t
= mmp_s
->mmp_time
;
2455 fprintf(stdout
, "block_number: %llu\n", current_fs
->super
->s_mmp_block
);
2456 fprintf(stdout
, "update_interval: %d\n",
2457 current_fs
->super
->s_mmp_update_interval
);
2458 fprintf(stdout
, "check_interval: %d\n", mmp_s
->mmp_check_interval
);
2459 fprintf(stdout
, "sequence: %08x\n", mmp_s
->mmp_seq
);
2460 fprintf(stdout
, "time: %lld -- %s", mmp_s
->mmp_time
, ctime(&t
));
2461 fprintf(stdout
, "node_name: %.*s\n",
2462 EXT2_LEN_STR(mmp_s
->mmp_nodename
));
2463 fprintf(stdout
, "device_name: %.*s\n",
2464 EXT2_LEN_STR(mmp_s
->mmp_bdevname
));
2465 fprintf(stdout
, "magic: 0x%x\n", mmp_s
->mmp_magic
);
2466 fprintf(stdout
, "checksum: 0x%08x\n", mmp_s
->mmp_checksum
);
2469 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)),
2470 char *argv
[] EXT2FS_ATTR((unused
)),
2471 int sci_idx
EXT2FS_ATTR((unused
)),
2472 void *infop
EXT2FS_ATTR((unused
)))
2474 fprintf(stdout
, "MMP is unsupported, please recompile with "
2479 static int source_file(const char *cmd_file
, int ss_idx
)
2484 int exit_status
= 0;
2487 if (strcmp(cmd_file
, "-") == 0)
2490 f
= fopen(cmd_file
, "r");
2498 setbuf(stdout
, NULL
);
2499 setbuf(stderr
, NULL
);
2501 if (fgets(buf
, sizeof(buf
), f
) == NULL
)
2503 if (buf
[0] == '#') {
2507 cp
= strchr(buf
, '\n');
2510 cp
= strchr(buf
, '\r');
2513 printf("debugfs: %s\n", buf
);
2514 retval
= ss_execute_line(ss_idx
, buf
);
2516 ss_perror(ss_idx
, retval
, buf
);
2525 int main(int argc
, char **argv
)
2529 "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] "
2530 "[-R request] [-d data_source_device] [-i] [-n] [-D] [-V] ["
2532 "[-w] [-z undo_file] "
2536 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
|
2537 EXT2_FLAG_64BITS
| EXT2_FLAG_THREADS
;
2539 int exit_status
= 0;
2541 blk64_t superblock
= 0;
2542 blk64_t blocksize
= 0;
2543 int catastrophic
= 0;
2544 char *data_filename
= 0;
2546 const char *opt_string
= "nicR:f:b:s:Vd:D";
2548 const char *opt_string
= "niwcR:f:b:s:Vd:Dz:";
2550 char *undo_file
= NULL
;
2551 #ifdef CONFIG_JBD_DEBUG
2555 if (debug_prog_name
== 0)
2557 debug_prog_name
= "rdebugfs";
2559 debug_prog_name
= "debugfs";
2561 add_error_table(&et_ext2_error_table
);
2562 fprintf (stderr
, "%s %s (%s)\n", debug_prog_name
,
2563 E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
2565 #ifdef CONFIG_JBD_DEBUG
2566 jbd_debug
= ss_safe_getenv("DEBUGFS_JBD_DEBUG");
2568 int res
= sscanf(jbd_debug
, "%d", &journal_enable_debug
);
2572 "DEBUGFS_JBD_DEBUG \"%s\" not an integer\n\n",
2578 while ((c
= getopt (argc
, argv
, opt_string
)) != EOF
) {
2587 data_filename
= optarg
;
2590 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
2593 open_flags
|= EXT2_FLAG_IGNORE_CSUM_ERRORS
;
2597 open_flags
|= EXT2_FLAG_RW
;
2601 open_flags
|= EXT2_FLAG_DIRECT_IO
;
2604 blocksize
= parse_ulong(optarg
, argv
[0],
2608 retval
= strtoblk(argv
[0], optarg
,
2609 "superblock block number",
2618 /* Print version number and exit */
2619 fprintf(stderr
, "\tUsing %s\n",
2620 error_message(EXT2_ET_BASE
));
2628 com_err(argv
[0], 0, usage
, debug_prog_name
);
2633 open_filesystem(argv
[optind
], open_flags
,
2634 superblock
, blocksize
, catastrophic
,
2635 data_filename
, undo_file
);
2637 ss_sci_idx
= ss_create_invocation(debug_prog_name
, "0.0", (char *) NULL
,
2638 &debug_cmds
, &retval
);
2640 ss_perror(ss_sci_idx
, retval
, "creating invocation");
2643 ss_get_readline(ss_sci_idx
);
2645 (void) ss_add_request_table(ss_sci_idx
, &ss_std_requests
, 1, &retval
);
2647 ss_perror(ss_sci_idx
, retval
, "adding standard requests");
2651 ss_add_request_table(ss_sci_idx
, extra_cmds
, 1, &retval
);
2653 ss_perror(ss_sci_idx
, retval
, "adding extra requests");
2658 retval
= ss_execute_line(ss_sci_idx
, request
);
2660 ss_perror(ss_sci_idx
, retval
, request
);
2663 } else if (cmd_file
) {
2664 exit_status
= source_file(cmd_file
, ss_sci_idx
);
2666 ss_listen(ss_sci_idx
);
2669 ss_delete_invocation(ss_sci_idx
);
2674 remove_error_table(&et_ext2_error_table
);