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>
30 #ifdef HAVE_SYS_SYSMACROS_H
31 #include <sys/sysmacros.h>
35 #include "uuid/uuid.h"
38 #include <ext2fs/ext2_ext_attr.h>
40 #include "../version.h"
42 #include "support/plausible.h"
48 #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jbd-debug */
49 int journal_enable_debug
= -1;
53 * There must be only one definition if we're hooking in extra commands or
54 * changing default prompt. Use -DSKIP_GLOBDEF for that.
57 ss_request_table
*extra_cmds
;
58 const char *debug_prog_name
;
62 ext2_filsys current_fs
;
63 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 retval
= ext2fs_read_bitmaps(current_fs
);
201 com_err(device
, retval
,
202 "while reading allocation bitmaps");
208 retval
= ext2fs_set_data_io(current_fs
, data_io
);
210 com_err(device
, retval
,
211 "while setting data source");
216 root
= cwd
= EXT2_ROOT_INO
;
220 retval
= ext2fs_close_free(¤t_fs
);
222 com_err(device
, retval
, "while trying to close filesystem");
225 void do_open_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
226 void *infop
EXT2FS_ATTR((unused
)))
229 int catastrophic
= 0;
230 blk64_t superblock
= 0;
231 blk64_t blocksize
= 0;
232 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
| EXT2_FLAG_64BITS
|
234 char *data_filename
= 0;
235 char *undo_file
= NULL
;
238 while ((c
= getopt(argc
, argv
, "iwfecb:s:d:Dz:")) != EOF
) {
241 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
247 open_flags
|= EXT2_FLAG_RW
;
248 #endif /* READ_ONLY */
251 open_flags
|= EXT2_FLAG_FORCE
;
254 open_flags
|= EXT2_FLAG_EXCLUSIVE
;
260 data_filename
= optarg
;
263 open_flags
|= EXT2_FLAG_DIRECT_IO
;
266 blocksize
= parse_ulong(optarg
, argv
[0],
272 err
= strtoblk(argv
[0], optarg
,
273 "superblock block number", &superblock
);
288 if (optind
!= argc
-1) {
291 if (check_fs_not_open(argv
[0]))
293 open_filesystem(argv
[optind
], open_flags
,
294 superblock
, blocksize
, catastrophic
,
295 data_filename
, undo_file
);
299 fprintf(stderr
, "%s: Usage: open [-s superblock] [-b blocksize] "
301 "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
303 "[-d image_filename] [-c] [-i] [-f] [-e] [-D] [-w] "
305 "<device>\n", argv
[0]);
308 void do_lcd(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
309 void *infop
EXT2FS_ATTR((unused
)))
312 com_err(argv
[0], 0, "Usage: %s %s", argv
[0], "<native dir>");
316 if (chdir(argv
[1]) == -1) {
317 com_err(argv
[0], errno
,
318 "while trying to change native directory to %s",
324 static void close_filesystem(NOARGS
)
328 if (current_fs
->flags
& EXT2_FLAG_IB_DIRTY
) {
329 retval
= ext2fs_write_inode_bitmap(current_fs
);
331 com_err("ext2fs_write_inode_bitmap", retval
, 0);
333 if (current_fs
->flags
& EXT2_FLAG_BB_DIRTY
) {
334 retval
= ext2fs_write_block_bitmap(current_fs
);
336 com_err("ext2fs_write_block_bitmap", retval
, 0);
339 quota_release_context(¤t_qctx
);
340 retval
= ext2fs_close_free(¤t_fs
);
342 com_err("ext2fs_close", retval
, 0);
346 void do_close_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
347 void *infop
EXT2FS_ATTR((unused
)))
351 if (check_fs_open(argv
[0]))
355 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
358 current_fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
367 com_err(0, 0, "Usage: close_filesys [-a]");
375 void do_init_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
376 void *infop
EXT2FS_ATTR((unused
)))
378 struct ext2_super_block param
;
383 if (common_args_process(argc
, argv
, 3, 3, "initialize",
384 "<device> <blocks>", CHECK_FS_NOTOPEN
))
387 memset(¶m
, 0, sizeof(struct ext2_super_block
));
388 err
= strtoblk(argv
[0], argv
[2], "blocks count", &blocks
);
391 ext2fs_blocks_count_set(¶m
, blocks
);
392 retval
= ext2fs_initialize(argv
[1], 0, ¶m
,
393 unix_io_manager
, ¤t_fs
);
395 com_err(argv
[1], retval
, "while initializing filesystem");
399 root
= cwd
= EXT2_ROOT_INO
;
403 static void print_features(struct ext2_super_block
* s
, FILE *f
)
406 __u32
*mask
= &s
->s_feature_compat
, m
;
408 fputs("Filesystem features:", f
);
409 for (i
=0; i
<3; i
++,mask
++) {
410 for (j
=0,m
=1; j
< 32; j
++, m
<<=1) {
412 fprintf(f
, " %s", e2p_feature2string(i
, m
));
421 #endif /* READ_ONLY */
423 static void print_bg_opts(ext2_filsys fs
, dgrp_t group
, int mask
,
424 const char *str
, int *first
, FILE *f
)
426 if (ext2fs_bg_flags_test(fs
, group
, mask
)) {
436 void do_show_super_stats(int argc
, ss_argv_t argv
,
437 int sci_idx
EXT2FS_ATTR((unused
)),
438 void *infop
EXT2FS_ATTR((unused
)))
440 const char *units
="block";
443 int c
, header_only
= 0;
444 int numdirs
= 0, first
, gdt_csum
;
447 while ((c
= getopt (argc
, argv
, "h")) != EOF
) {
456 if (optind
!= argc
) {
459 if (check_fs_open(argv
[0]))
463 if (ext2fs_has_feature_bigalloc(current_fs
->super
))
466 list_super2(current_fs
->super
, out
);
467 if (ext2fs_has_feature_metadata_csum(current_fs
->super
) &&
468 !ext2fs_superblock_csum_verify(current_fs
,
469 current_fs
->super
)) {
470 __u32 orig_csum
= current_fs
->super
->s_checksum
;
472 ext2fs_superblock_csum_set(current_fs
,
474 fprintf(out
, "Expected Checksum: 0x%08x\n",
475 current_fs
->super
->s_checksum
);
476 current_fs
->super
->s_checksum
= orig_csum
;
478 for (i
=0; i
< current_fs
->group_desc_count
; i
++)
479 numdirs
+= ext2fs_bg_used_dirs_count(current_fs
, i
);
480 fprintf(out
, "Directories: %u\n", numdirs
);
487 gdt_csum
= ext2fs_has_group_desc_csum(current_fs
);
488 for (i
= 0; i
< current_fs
->group_desc_count
; i
++) {
489 fprintf(out
, " Group %2d: block bitmap at %llu, "
490 "inode bitmap at %llu, "
491 "inode table at %llu\n"
495 (unsigned long long) ext2fs_block_bitmap_loc(current_fs
, i
),
496 (unsigned long long) ext2fs_inode_bitmap_loc(current_fs
, i
),
497 (unsigned long long) ext2fs_inode_table_loc(current_fs
, i
),
498 ext2fs_bg_free_blocks_count(current_fs
, i
),
500 ext2fs_bg_free_blocks_count(current_fs
, i
) != 1 ?
502 ext2fs_bg_free_inodes_count(current_fs
, i
),
503 ext2fs_bg_free_inodes_count(current_fs
, i
) != 1 ?
505 ext2fs_bg_used_dirs_count(current_fs
, i
),
506 ext2fs_bg_used_dirs_count(current_fs
, i
) != 1 ? "directories"
507 : "directory", gdt_csum
? ", " : "\n");
509 fprintf(out
, "%u unused %s\n",
510 ext2fs_bg_itable_unused(current_fs
, i
),
511 ext2fs_bg_itable_unused(current_fs
, i
) != 1 ?
514 print_bg_opts(current_fs
, i
, EXT2_BG_INODE_UNINIT
, "Inode not init",
516 print_bg_opts(current_fs
, i
, EXT2_BG_BLOCK_UNINIT
, "Block not init",
519 fprintf(out
, "%sChecksum 0x%04x",
520 first
? " [":", ", ext2fs_bg_checksum(current_fs
, i
));
529 fprintf(stderr
, "%s: Usage: show_super_stats [-h]\n", argv
[0]);
533 void do_dirty_filesys(int argc
EXT2FS_ATTR((unused
)),
534 ss_argv_t argv
EXT2FS_ATTR((unused
)),
535 int sci_idx
EXT2FS_ATTR((unused
)),
536 void *infop
EXT2FS_ATTR((unused
)))
538 if (check_fs_open(argv
[0]))
540 if (check_fs_read_write(argv
[0]))
543 if (argv
[1] && !strcmp(argv
[1], "-clean"))
544 current_fs
->super
->s_state
|= EXT2_VALID_FS
;
546 current_fs
->super
->s_state
&= ~EXT2_VALID_FS
;
547 ext2fs_mark_super_dirty(current_fs
);
549 #endif /* READ_ONLY */
551 struct list_blocks_struct
{
554 blk64_t first_block
, last_block
;
555 e2_blkcnt_t first_bcnt
, last_bcnt
;
559 static void finish_range(struct list_blocks_struct
*lb
)
561 if (lb
->first_block
== 0)
566 fprintf(lb
->f
, ", ");
567 if (lb
->first_block
== lb
->last_block
)
568 fprintf(lb
->f
, "(%lld):%llu",
569 (long long)lb
->first_bcnt
,
570 (unsigned long long) lb
->first_block
);
572 fprintf(lb
->f
, "(%lld-%lld):%llu-%llu",
573 (long long)lb
->first_bcnt
, (long long)lb
->last_bcnt
,
574 (unsigned long long) lb
->first_block
,
575 (unsigned long long) lb
->last_block
);
579 static int list_blocks_proc(ext2_filsys fs
EXT2FS_ATTR((unused
)),
580 blk64_t
*blocknr
, e2_blkcnt_t blockcnt
,
581 blk64_t ref_block
EXT2FS_ATTR((unused
)),
582 int ref_offset
EXT2FS_ATTR((unused
)),
585 struct list_blocks_struct
*lb
= (struct list_blocks_struct
*) private;
590 * See if we can add on to the existing range (if it exists)
592 if (lb
->first_block
&&
593 (lb
->last_block
+1 == *blocknr
) &&
594 (lb
->last_bcnt
+1 == blockcnt
)) {
595 lb
->last_block
= *blocknr
;
596 lb
->last_bcnt
= blockcnt
;
603 lb
->first_block
= lb
->last_block
= *blocknr
;
604 lb
->first_bcnt
= lb
->last_bcnt
= blockcnt
;
608 * Not a normal block. Always force a new range.
614 fprintf(lb
->f
, ", ");
616 fprintf(lb
->f
, "(IND):%llu", (unsigned long long) *blocknr
);
617 else if (blockcnt
== -2)
618 fprintf(lb
->f
, "(DIND):%llu", (unsigned long long) *blocknr
);
619 else if (blockcnt
== -3)
620 fprintf(lb
->f
, "(TIND):%llu", (unsigned long long) *blocknr
);
624 static void internal_dump_inode_extra(FILE *out
,
625 const char *prefix
EXT2FS_ATTR((unused
)),
626 ext2_ino_t inode_num
EXT2FS_ATTR((unused
)),
627 struct ext2_inode_large
*inode
)
629 fprintf(out
, "Size of extra inode fields: %u\n", inode
->i_extra_isize
);
630 if (inode
->i_extra_isize
> EXT2_INODE_SIZE(current_fs
->super
) -
631 EXT2_GOOD_OLD_INODE_SIZE
) {
632 fprintf(stderr
, "invalid inode->i_extra_isize (%u)\n",
633 inode
->i_extra_isize
);
638 static void dump_blocks(FILE *f
, const char *prefix
, ext2_ino_t inode
)
640 struct list_blocks_struct lb
;
642 fprintf(f
, "%sBLOCKS:\n%s", prefix
, prefix
);
647 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
, NULL
,
648 list_blocks_proc
, (void *)&lb
);
651 fprintf(f
, "\n%sTOTAL: %lld\n", prefix
, (long long)lb
.total
);
655 #define DUMP_LEAF_EXTENTS 0x01
656 #define DUMP_NODE_EXTENTS 0x02
657 #define DUMP_EXTENT_TABLE 0x04
659 static void dump_extents(FILE *f
, const char *prefix
, ext2_ino_t ino
,
660 int flags
, int logical_width
, int physical_width
)
662 ext2_extent_handle_t handle
;
663 struct ext2fs_extent extent
;
664 struct ext2_extent_info info
;
665 int op
= EXT2_EXTENT_ROOT
;
666 unsigned int printed
= 0;
669 errcode
= ext2fs_extent_open(current_fs
, ino
, &handle
);
673 if (flags
& DUMP_EXTENT_TABLE
)
674 fprintf(f
, "Level Entries %*s %*s Length Flags\n",
675 (logical_width
*2)+3, "Logical",
676 (physical_width
*2)+3, "Physical");
678 fprintf(f
, "%sEXTENTS:\n%s", prefix
, prefix
);
681 errcode
= ext2fs_extent_get(handle
, op
, &extent
);
686 op
= EXT2_EXTENT_NEXT
;
688 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
691 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
) {
692 if ((flags
& DUMP_LEAF_EXTENTS
) == 0)
695 if ((flags
& DUMP_NODE_EXTENTS
) == 0)
699 errcode
= ext2fs_extent_get_info(handle
, &info
);
703 if (!(extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
)) {
704 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
707 if (flags
& DUMP_EXTENT_TABLE
) {
708 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
710 info
.curr_level
, info
.max_depth
,
711 info
.curr_entry
, info
.num_entries
,
713 (unsigned long long) extent
.e_lblk
,
715 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
717 (unsigned long long) extent
.e_pblk
,
718 physical_width
+3, "", extent
.e_len
);
722 fprintf(f
, "%s(ETB%d):%llu",
723 printed
? ", " : "", info
.curr_level
,
724 (unsigned long long) extent
.e_pblk
);
729 if (flags
& DUMP_EXTENT_TABLE
) {
730 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
731 "%*llu - %*llu %6u %s\n",
732 info
.curr_level
, info
.max_depth
,
733 info
.curr_entry
, info
.num_entries
,
735 (unsigned long long) extent
.e_lblk
,
737 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
739 (unsigned long long) extent
.e_pblk
,
741 (unsigned long long) extent
.e_pblk
+ (extent
.e_len
- 1),
743 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
748 if (extent
.e_len
== 0)
750 else if (extent
.e_len
== 1)
754 (unsigned long long) extent
.e_lblk
,
755 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
757 (unsigned long long) extent
.e_pblk
);
760 "%s(%lld-%lld%s):%lld-%lld",
762 (unsigned long long) extent
.e_lblk
,
763 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
764 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
766 (unsigned long long) extent
.e_pblk
,
767 (unsigned long long) extent
.e_pblk
+ (extent
.e_len
- 1));
772 ext2fs_extent_free(handle
);
775 static void dump_inline_data(FILE *out
, const char *prefix
, ext2_ino_t inode_num
)
780 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
782 fprintf(out
, "%sSize of inline data: %zu\n", prefix
, size
);
785 static void dump_inline_symlink(FILE *out
, ext2_ino_t inode_num
,
786 struct ext2_inode
*inode
, const char *prefix
)
792 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
796 retval
= ext2fs_get_memzero(size
+ 1, &buf
);
800 retval
= ext2fs_inline_data_get(current_fs
, inode_num
,
805 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
809 ext2fs_free_mem(&buf
);
811 com_err(__func__
, retval
, "while dumping link destination");
814 void internal_dump_inode(FILE *out
, const char *prefix
,
815 ext2_ino_t inode_num
, struct ext2_inode
*inode
,
820 int os
= current_fs
->super
->s_creator_os
;
821 struct ext2_inode_large
*large_inode
;
824 large_inode
= (struct ext2_inode_large
*) inode
;
825 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
826 inode_size
= ext2fs_inode_actual_size(large_inode
);
828 inode_size
= EXT2_GOOD_OLD_INODE_SIZE
;
830 if (LINUX_S_ISDIR(inode
->i_mode
)) i_type
= "directory";
831 else if (LINUX_S_ISREG(inode
->i_mode
)) i_type
= "regular";
832 else if (LINUX_S_ISLNK(inode
->i_mode
)) i_type
= "symlink";
833 else if (LINUX_S_ISBLK(inode
->i_mode
)) i_type
= "block special";
834 else if (LINUX_S_ISCHR(inode
->i_mode
)) i_type
= "character special";
835 else if (LINUX_S_ISFIFO(inode
->i_mode
)) i_type
= "FIFO";
836 else if (LINUX_S_ISSOCK(inode
->i_mode
)) i_type
= "socket";
837 else i_type
= "bad type";
838 fprintf(out
, "%sInode: %u Type: %s ", prefix
, inode_num
, i_type
);
839 fprintf(out
, "%sMode: 0%03o Flags: 0x%x\n",
840 prefix
, inode
->i_mode
& 07777, inode
->i_flags
);
841 if (ext2fs_inode_includes(inode_size
, i_version_hi
)) {
842 fprintf(out
, "%sGeneration: %u Version: 0x%08x:%08x\n",
843 prefix
, inode
->i_generation
, large_inode
->i_version_hi
,
844 inode
->osd1
.linux1
.l_i_version
);
846 fprintf(out
, "%sGeneration: %u Version: 0x%08x\n", prefix
,
847 inode
->i_generation
, inode
->osd1
.linux1
.l_i_version
);
849 fprintf(out
, "%sUser: %5d Group: %5d",
850 prefix
, inode_uid(*inode
), inode_gid(*inode
));
851 if (ext2fs_inode_includes(inode_size
, i_projid
))
852 fprintf(out
, " Project: %5d", large_inode
->i_projid
);
853 fputs(" Size: ", out
);
854 if (LINUX_S_ISREG(inode
->i_mode
) || LINUX_S_ISDIR(inode
->i_mode
))
855 fprintf(out
, "%llu\n", (unsigned long long) EXT2_I_SIZE(inode
));
857 fprintf(out
, "%u\n", inode
->i_size
);
858 if (os
== EXT2_OS_HURD
)
860 "%sFile ACL: %u Translator: %u\n",
863 inode
->osd1
.hurd1
.h_i_translator
);
865 fprintf(out
, "%sFile ACL: %llu\n",
867 inode
->i_file_acl
| ((long long)
868 (inode
->osd2
.linux2
.l_i_file_acl_high
) << 32));
869 if (os
!= EXT2_OS_HURD
)
870 fprintf(out
, "%sLinks: %u Blockcount: %llu\n",
871 prefix
, inode
->i_links_count
,
872 (((unsigned long long)
873 inode
->osd2
.linux2
.l_i_blocks_hi
<< 32)) +
876 fprintf(out
, "%sLinks: %u Blockcount: %u\n",
877 prefix
, inode
->i_links_count
, inode
->i_blocks
);
880 frag
= inode
->osd2
.hurd2
.h_i_frag
;
881 fsize
= inode
->osd2
.hurd2
.h_i_fsize
;
886 fprintf(out
, "%sFragment: Address: %u Number: %u Size: %u\n",
887 prefix
, inode
->i_faddr
, frag
, fsize
);
888 if (ext2fs_inode_includes(inode_size
, i_ctime_extra
))
889 fprintf(out
, "%s ctime: 0x%08x:%08x -- %s", prefix
,
890 inode
->i_ctime
, large_inode
->i_ctime_extra
,
891 time_to_string(ext2fs_inode_xtime_get(large_inode
,
894 fprintf(out
, "%sctime: 0x%08x -- %s", prefix
, inode
->i_ctime
,
895 time_to_string((__s32
) inode
->i_ctime
));
896 if (ext2fs_inode_includes(inode_size
, i_atime_extra
))
897 fprintf(out
, "%s atime: 0x%08x:%08x -- %s", prefix
,
898 inode
->i_atime
, large_inode
->i_atime_extra
,
899 time_to_string(ext2fs_inode_xtime_get(large_inode
,
902 fprintf(out
, "%satime: 0x%08x -- %s", prefix
, inode
->i_atime
,
903 time_to_string((__s32
) inode
->i_atime
));
904 if (ext2fs_inode_includes(inode_size
, i_mtime_extra
))
905 fprintf(out
, "%s mtime: 0x%08x:%08x -- %s", prefix
,
906 inode
->i_mtime
, large_inode
->i_mtime_extra
,
907 time_to_string(ext2fs_inode_xtime_get(large_inode
,
910 fprintf(out
, "%smtime: 0x%08x -- %s", prefix
, inode
->i_mtime
,
911 time_to_string((__s32
) inode
->i_mtime
));
912 if (ext2fs_inode_includes(inode_size
, i_crtime_extra
))
913 fprintf(out
, "%scrtime: 0x%08x:%08x -- %s", prefix
,
914 large_inode
->i_crtime
, large_inode
->i_crtime_extra
,
915 time_to_string(ext2fs_inode_xtime_get(large_inode
,
917 if (inode
->i_dtime
) {
918 if (ext2fs_inode_includes(inode_size
, i_ctime_extra
)) {
921 /* dtime doesn't have its own i_dtime_extra field, so
922 * approximate this with i_ctime_extra instead. */
923 tm
= __decode_extra_sec(inode
->i_dtime
,
924 large_inode
->i_ctime_extra
);
925 fprintf(out
, "%s dtime: 0x%08x:(%08x) -- %s", prefix
,
926 inode
->i_dtime
, large_inode
->i_ctime_extra
,
929 fprintf(out
, "%sdtime: 0x%08x -- %s", prefix
,
931 time_to_string((__s32
) inode
->i_dtime
));
934 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
935 internal_dump_inode_extra(out
, prefix
, inode_num
,
936 (struct ext2_inode_large
*) inode
);
937 dump_inode_attributes(out
, inode_num
);
938 if (ext2fs_has_feature_metadata_csum(current_fs
->super
)) {
939 __u32 crc
= inode
->i_checksum_lo
;
940 if (ext2fs_inode_includes(inode_size
, i_checksum_hi
))
941 crc
|= ((__u32
)large_inode
->i_checksum_hi
) << 16;
942 fprintf(out
, "Inode checksum: 0x%08x\n", crc
);
945 if (LINUX_S_ISLNK(inode
->i_mode
) && ext2fs_is_fast_symlink(inode
))
946 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
947 (int)EXT2_I_SIZE(inode
), (char *)inode
->i_block
);
948 else if (LINUX_S_ISLNK(inode
->i_mode
) &&
949 (inode
->i_flags
& EXT4_INLINE_DATA_FL
))
950 dump_inline_symlink(out
, inode_num
, inode
, prefix
);
951 else if (LINUX_S_ISBLK(inode
->i_mode
) || LINUX_S_ISCHR(inode
->i_mode
)) {
955 if (inode
->i_block
[0]) {
956 major
= (inode
->i_block
[0] >> 8) & 255;
957 minor
= inode
->i_block
[0] & 255;
960 major
= (inode
->i_block
[1] & 0xfff00) >> 8;
961 minor
= ((inode
->i_block
[1] & 0xff) |
962 ((inode
->i_block
[1] >> 12) & 0xfff00));
963 devnote
= "(New-style) ";
965 fprintf(out
, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n",
966 devnote
, major
, minor
, major
, minor
);
967 } else if (do_dump_blocks
) {
968 if (inode
->i_flags
& EXT4_EXTENTS_FL
)
969 dump_extents(out
, prefix
, inode_num
,
970 DUMP_LEAF_EXTENTS
|DUMP_NODE_EXTENTS
, 0, 0);
971 else if (inode
->i_flags
& EXT4_INLINE_DATA_FL
)
972 dump_inline_data(out
, prefix
, inode_num
);
974 dump_blocks(out
, prefix
, inode_num
);
978 static void dump_inode(ext2_ino_t inode_num
, struct ext2_inode
*inode
)
983 internal_dump_inode(out
, "", inode_num
, inode
, 1);
987 void do_stat(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
988 void *infop
EXT2FS_ATTR((unused
)))
991 struct ext2_inode
* inode_buf
;
993 if (check_fs_open(argv
[0]))
996 inode_buf
= (struct ext2_inode
*)
997 malloc(EXT2_INODE_SIZE(current_fs
->super
));
999 fprintf(stderr
, "do_stat: can't allocate buffer\n");
1003 if (common_inode_args_process(argc
, argv
, &inode
, 0)) {
1008 if (debugfs_read_inode2(inode
, inode_buf
, argv
[0],
1009 EXT2_INODE_SIZE(current_fs
->super
), 0)) {
1014 dump_inode(inode
, inode_buf
);
1019 void do_dump_extents(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1020 void *infop
EXT2FS_ATTR((unused
)))
1022 struct ext2_inode inode
;
1030 while ((c
= getopt(argc
, argv
, "nl")) != EOF
) {
1033 flags
|= DUMP_NODE_EXTENTS
;
1036 flags
|= DUMP_LEAF_EXTENTS
;
1041 if (argc
!= optind
+ 1) {
1042 com_err(0, 0, "Usage: dump_extents [-n] [-l] file");
1047 flags
= DUMP_NODE_EXTENTS
| DUMP_LEAF_EXTENTS
;
1048 flags
|= DUMP_EXTENT_TABLE
;
1050 if (check_fs_open(argv
[0]))
1053 ino
= string_to_inode(argv
[optind
]);
1057 if (debugfs_read_inode(ino
, &inode
, argv
[0]))
1060 if ((inode
.i_flags
& EXT4_EXTENTS_FL
) == 0) {
1061 fprintf(stderr
, "%s: does not uses extent block maps\n",
1066 logical_width
= ext2fs_log10_u32((EXT2_I_SIZE(&inode
) +
1067 current_fs
->blocksize
- 1) /
1068 current_fs
->blocksize
) + 1;
1069 if (logical_width
< 5)
1071 physical_width
= ext2fs_log10_u64(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 ", (unsigned long long) *blocknr
);
1092 void do_blocks(int argc
, ss_argv_t 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
, ss_argv_t 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
, ss_argv_t 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
, ss_argv_t 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
, ss_argv_t 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
, ss_argv_t 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
, ss_argv_t 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",
1235 (unsigned long long) block
);
1236 ext2fs_unmark_block_bitmap2(current_fs
->block_map
,block
);
1239 ext2fs_mark_bb_dirty(current_fs
);
1242 void do_setb(int argc
, ss_argv_t 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",
1255 (unsigned long long) block
);
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
, ss_argv_t 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",
1274 (unsigned long long) block
);
1276 printf("Block %llu not in use\n",
1277 (unsigned long long) block
);
1283 static void modify_u8(char *com
, const char *prompt
,
1284 const char *format
, __u8
*val
)
1290 sprintf(buf
, format
, *val
);
1291 printf("%30s [%s] ", prompt
, buf
);
1292 if (!fgets(buf
, sizeof(buf
), stdin
))
1294 if (buf
[strlen (buf
) - 1] == '\n')
1295 buf
[strlen (buf
) - 1] = '\0';
1298 v
= strtoul(buf
, &tmp
, 0);
1300 com_err(com
, 0, "Bad value - %s", buf
);
1305 static void modify_u16(char *com
, const char *prompt
,
1306 const char *format
, __u16
*val
)
1312 sprintf(buf
, format
, *val
);
1313 printf("%30s [%s] ", prompt
, buf
);
1314 if (!fgets(buf
, sizeof(buf
), stdin
))
1316 if (buf
[strlen (buf
) - 1] == '\n')
1317 buf
[strlen (buf
) - 1] = '\0';
1320 v
= strtoul(buf
, &tmp
, 0);
1322 com_err(com
, 0, "Bad value - %s", buf
);
1327 static void modify_u32(char *com
, const char *prompt
,
1328 const char *format
, __u32
*val
)
1334 sprintf(buf
, format
, *val
);
1335 printf("%30s [%s] ", prompt
, buf
);
1336 if (!fgets(buf
, sizeof(buf
), stdin
))
1338 if (buf
[strlen (buf
) - 1] == '\n')
1339 buf
[strlen (buf
) - 1] = '\0';
1342 v
= strtoul(buf
, &tmp
, 0);
1344 com_err(com
, 0, "Bad value - %s", buf
);
1350 void do_modify_inode(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1351 void *infop
EXT2FS_ATTR((unused
)))
1353 struct ext2_inode inode
;
1354 ext2_ino_t inode_num
;
1356 unsigned char *frag
, *fsize
;
1359 const char *hex_format
= "0x%x";
1360 const char *octal_format
= "0%o";
1361 const char *decimal_format
= "%d";
1362 const char *unsignedlong_format
= "%lu";
1364 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1367 os
= current_fs
->super
->s_creator_os
;
1369 if (debugfs_read_inode(inode_num
, &inode
, argv
[1]))
1372 modify_u16(argv
[0], "Mode", octal_format
, &inode
.i_mode
);
1373 modify_u16(argv
[0], "User ID", decimal_format
, &inode
.i_uid
);
1374 modify_u16(argv
[0], "Group ID", decimal_format
, &inode
.i_gid
);
1375 modify_u32(argv
[0], "Size", unsignedlong_format
, &inode
.i_size
);
1376 modify_u32(argv
[0], "Creation time", decimal_format
, &inode
.i_ctime
);
1377 modify_u32(argv
[0], "Modification time", decimal_format
, &inode
.i_mtime
);
1378 modify_u32(argv
[0], "Access time", decimal_format
, &inode
.i_atime
);
1379 modify_u32(argv
[0], "Deletion time", decimal_format
, &inode
.i_dtime
);
1380 modify_u16(argv
[0], "Link count", decimal_format
, &inode
.i_links_count
);
1381 if (os
== EXT2_OS_LINUX
)
1382 modify_u16(argv
[0], "Block count high", unsignedlong_format
,
1383 &inode
.osd2
.linux2
.l_i_blocks_hi
);
1384 modify_u32(argv
[0], "Block count", unsignedlong_format
, &inode
.i_blocks
);
1385 modify_u32(argv
[0], "File flags", hex_format
, &inode
.i_flags
);
1386 modify_u32(argv
[0], "Generation", hex_format
, &inode
.i_generation
);
1388 modify_u32(argv
[0], "Reserved1", decimal_format
, &inode
.i_reserved1
);
1390 modify_u32(argv
[0], "File acl", decimal_format
, &inode
.i_file_acl
);
1392 modify_u32(argv
[0], "High 32bits of size", decimal_format
,
1393 &inode
.i_size_high
);
1395 if (os
== EXT2_OS_HURD
)
1396 modify_u32(argv
[0], "Translator Block",
1397 decimal_format
, &inode
.osd1
.hurd1
.h_i_translator
);
1399 modify_u32(argv
[0], "Fragment address", decimal_format
, &inode
.i_faddr
);
1402 frag
= &inode
.osd2
.hurd2
.h_i_frag
;
1403 fsize
= &inode
.osd2
.hurd2
.h_i_fsize
;
1409 modify_u8(argv
[0], "Fragment number", decimal_format
, frag
);
1411 modify_u8(argv
[0], "Fragment size", decimal_format
, fsize
);
1413 for (i
=0; i
< EXT2_NDIR_BLOCKS
; i
++) {
1414 sprintf(buf
, "Direct Block #%u", i
);
1415 modify_u32(argv
[0], buf
, decimal_format
, &inode
.i_block
[i
]);
1417 modify_u32(argv
[0], "Indirect Block", decimal_format
,
1418 &inode
.i_block
[EXT2_IND_BLOCK
]);
1419 modify_u32(argv
[0], "Double Indirect Block", decimal_format
,
1420 &inode
.i_block
[EXT2_DIND_BLOCK
]);
1421 modify_u32(argv
[0], "Triple Indirect Block", decimal_format
,
1422 &inode
.i_block
[EXT2_TIND_BLOCK
]);
1423 if (debugfs_write_inode(inode_num
, &inode
, argv
[1]))
1426 #endif /* READ_ONLY */
1428 void do_change_working_dir(int argc
, ss_argv_t argv
,
1429 int sci_idx
EXT2FS_ATTR((unused
)),
1430 void *infop
EXT2FS_ATTR((unused
)))
1435 if (common_inode_args_process(argc
, argv
, &inode
, 0))
1438 retval
= ext2fs_check_directory(current_fs
, inode
);
1440 com_err(argv
[1], retval
, 0);
1447 void do_print_working_directory(int argc
, ss_argv_t argv
,
1448 int sci_idx
EXT2FS_ATTR((unused
)),
1449 void *infop
EXT2FS_ATTR((unused
)))
1452 char *pathname
= NULL
;
1454 if (common_args_process(argc
, argv
, 1, 1,
1455 "print_working_directory", "", 0))
1458 retval
= ext2fs_get_pathname(current_fs
, cwd
, 0, &pathname
);
1460 com_err(argv
[0], retval
,
1461 "while trying to get pathname of cwd");
1463 printf("[pwd] INODE: %6u PATH: %s\n",
1464 cwd
, pathname
? pathname
: "NULL");
1469 retval
= ext2fs_get_pathname(current_fs
, root
, 0, &pathname
);
1471 com_err(argv
[0], retval
,
1472 "while trying to get pathname of root");
1474 printf("[root] INODE: %6u PATH: %s\n",
1475 root
, pathname
? pathname
: "NULL");
1484 static void make_link(char *sourcename
, char *destname
)
1487 struct ext2_inode inode
;
1490 char *dest
, *cp
, *base_name
;
1493 * Get the source inode
1495 ino
= string_to_inode(sourcename
);
1498 base_name
= strrchr(sourcename
, '/');
1502 base_name
= sourcename
;
1504 * Figure out the destination. First see if it exists and is
1507 if (! (retval
=ext2fs_namei(current_fs
, root
, cwd
, destname
, &dir
)))
1511 * OK, it doesn't exist. See if it is
1512 * '<dir>/basename' or 'basename'
1514 cp
= strrchr(destname
, '/');
1517 dir
= string_to_inode(destname
);
1527 if (debugfs_read_inode(ino
, &inode
, sourcename
))
1530 retval
= ext2fs_link(current_fs
, dir
, dest
, ino
,
1531 ext2_file_type(inode
.i_mode
));
1533 com_err("make_link", retval
, 0);
1538 void do_link(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1539 void *infop
EXT2FS_ATTR((unused
)))
1541 if (common_args_process(argc
, argv
, 3, 3, "link",
1542 "<source file> <dest_name>", CHECK_FS_RW
))
1545 make_link(argv
[1], argv
[2]);
1548 static int mark_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1549 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1550 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1551 int ref_offset
EXT2FS_ATTR((unused
)),
1552 void *private EXT2FS_ATTR((unused
)))
1557 ext2fs_block_alloc_stats2(fs
, block
, +1);
1561 void do_undel(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1562 void *infop
EXT2FS_ATTR((unused
)))
1565 struct ext2_inode inode
;
1567 if (common_args_process(argc
, argv
, 2, 3, "undelete",
1568 "<inode_num> [dest_name]",
1569 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1572 ino
= string_to_inode(argv
[1]);
1576 if (debugfs_read_inode(ino
, &inode
, argv
[1]))
1579 if (ext2fs_test_inode_bitmap2(current_fs
->inode_map
, ino
)) {
1580 com_err(argv
[1], 0, "Inode is not marked as deleted");
1585 * XXX this function doesn't handle changing the links count on the
1586 * parent directory when undeleting a directory.
1588 inode
.i_links_count
= LINUX_S_ISDIR(inode
.i_mode
) ? 2 : 1;
1591 if (debugfs_write_inode(ino
, &inode
, argv
[0]))
1594 ext2fs_block_iterate3(current_fs
, ino
, BLOCK_FLAG_READ_ONLY
, NULL
,
1595 mark_blocks_proc
, NULL
);
1597 ext2fs_inode_alloc_stats2(current_fs
, ino
, +1, 0);
1600 make_link(argv
[1], argv
[2]);
1603 static void unlink_file_by_name(char *filename
)
1609 base_name
= strrchr(filename
, '/');
1611 *base_name
++ = '\0';
1612 dir
= string_to_inode(filename
);
1617 base_name
= filename
;
1619 retval
= ext2fs_unlink(current_fs
, dir
, base_name
, 0, 0);
1621 com_err("unlink_file_by_name", retval
, 0);
1625 void do_unlink(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1626 void *infop
EXT2FS_ATTR((unused
)))
1628 if (common_args_process(argc
, argv
, 2, 2, "link",
1629 "<pathname>", CHECK_FS_RW
))
1632 unlink_file_by_name(argv
[1]);
1635 void do_copy_inode(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1636 void *infop
EXT2FS_ATTR((unused
)))
1638 ext2_ino_t src_ino
, dest_ino
;
1639 unsigned char buf
[4096];
1641 if (common_args_process(argc
, argv
, 3, 3, "copy_inode",
1642 "<source file> <dest_name>", CHECK_FS_RW
))
1645 src_ino
= string_to_inode(argv
[1]);
1649 dest_ino
= string_to_inode(argv
[2]);
1653 if (debugfs_read_inode2(src_ino
, (struct ext2_inode
*) buf
,
1654 argv
[0], sizeof(buf
), 0))
1657 if (debugfs_write_inode2(dest_ino
, (struct ext2_inode
*) buf
,
1658 argv
[0], sizeof(buf
), 0))
1662 #endif /* READ_ONLY */
1664 void do_find_free_block(int argc
, ss_argv_t argv
,
1665 int sci_idx
EXT2FS_ATTR((unused
)),
1666 void *infop
EXT2FS_ATTR((unused
)))
1668 blk64_t free_blk
, goal
, first_free
= 0;
1673 if ((argc
> 3) || (argc
==2 && *argv
[1] == '?')) {
1674 com_err(argv
[0], 0, "Usage: find_free_block [count [goal]]");
1677 if (check_fs_open(argv
[0]))
1681 count
= strtol(argv
[1],&tmp
,0);
1683 com_err(argv
[0], 0, "Bad count - %s", argv
[1]);
1690 goal
= strtol(argv
[2], &tmp
, 0);
1692 com_err(argv
[0], 0, "Bad goal - %s", argv
[1]);
1697 goal
= current_fs
->super
->s_first_data_block
;
1699 printf("Free blocks found: ");
1700 free_blk
= goal
- 1;
1701 while (count
-- > 0) {
1702 retval
= ext2fs_new_block2(current_fs
, free_blk
+ 1, 0,
1705 if (first_free
== free_blk
)
1708 first_free
= free_blk
;
1710 com_err("ext2fs_new_block", retval
, 0);
1713 printf("%llu ", (unsigned long long) free_blk
);
1718 void do_find_free_inode(int argc
, ss_argv_t argv
,
1719 int sci_idx
EXT2FS_ATTR((unused
)),
1720 void *infop
EXT2FS_ATTR((unused
)))
1722 ext2_ino_t free_inode
, dir
;
1727 if (argc
> 3 || (argc
>1 && *argv
[1] == '?')) {
1728 com_err(argv
[0], 0, "Usage: find_free_inode [dir [mode]]");
1731 if (check_fs_open(argv
[0]))
1735 dir
= strtol(argv
[1], &tmp
, 0);
1737 com_err(argv
[0], 0, "Bad dir - %s", argv
[1]);
1744 mode
= strtol(argv
[2], &tmp
, 0);
1746 com_err(argv
[0], 0, "Bad mode - %s", argv
[2]);
1752 retval
= ext2fs_new_inode(current_fs
, dir
, mode
, 0, &free_inode
);
1754 com_err("ext2fs_new_inode", retval
, 0);
1756 printf("Free inode found: %u\n", free_inode
);
1760 void do_write(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1761 void *infop
EXT2FS_ATTR((unused
)))
1765 if (common_args_process(argc
, argv
, 3, 3, "write",
1766 "<native file> <new file>", CHECK_FS_RW
))
1769 retval
= do_write_internal(current_fs
, cwd
, argv
[1], argv
[2], 0, root
);
1771 com_err(argv
[0], retval
, 0);
1774 void do_mknod(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1775 void *infop
EXT2FS_ATTR((unused
)))
1777 unsigned long major
, minor
;
1782 if (check_fs_open(argv
[0]))
1784 if (argc
< 3 || argv
[2][1]) {
1786 com_err(argv
[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
1791 switch (argv
[2][0]) {
1793 st
.st_mode
= S_IFIFO
;
1797 st
.st_mode
= S_IFCHR
;
1801 st
.st_mode
= S_IFBLK
;
1809 char *end1
= NULL
, *end2
= NULL
;
1811 major
= strtoul(argv
[3], &end1
, 0);
1812 minor
= strtoul(argv
[4], &end2
, 0);
1813 if (major
> 65535 || minor
> 65535 ||
1814 (end1
&& *end1
) || (end2
&& *end2
))
1821 st
.st_rdev
= makedev(major
, minor
);
1822 retval
= do_mknod_internal(current_fs
, cwd
, argv
[1],
1823 st
.st_mode
, st
.st_rdev
);
1825 com_err(argv
[0], retval
, 0);
1828 void do_mkdir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1829 void *infop
EXT2FS_ATTR((unused
)))
1833 if (common_args_process(argc
, argv
, 2, 2, "mkdir",
1834 "<filename>", CHECK_FS_RW
))
1837 retval
= do_mkdir_internal(current_fs
, cwd
, argv
[1], 0, root
);
1839 com_err(argv
[0], retval
, 0);
1843 static int release_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1844 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1845 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1846 int ref_offset
EXT2FS_ATTR((unused
)),
1849 blk64_t block
= *blocknr
;
1850 blk64_t
*last_cluster
= (blk64_t
*)private;
1851 blk64_t cluster
= EXT2FS_B2C(fs
, block
);
1853 if (cluster
== *last_cluster
)
1856 *last_cluster
= cluster
;
1858 ext2fs_block_alloc_stats2(fs
, block
, -1);
1862 static void kill_file_by_inode(ext2_ino_t inode
)
1864 struct ext2_inode inode_buf
;
1866 if (debugfs_read_inode(inode
, &inode_buf
, 0))
1868 ext2fs_set_dtime(current_fs
, &inode_buf
);
1869 if (debugfs_write_inode(inode
, &inode_buf
, 0))
1871 if (ext2fs_inode_has_valid_blocks2(current_fs
, &inode_buf
)) {
1872 blk64_t last_cluster
= 0;
1873 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
,
1874 NULL
, release_blocks_proc
, &last_cluster
);
1877 ext2fs_inode_alloc_stats2(current_fs
, inode
, -1,
1878 LINUX_S_ISDIR(inode_buf
.i_mode
));
1882 void do_kill_file(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1883 void *infop
EXT2FS_ATTR((unused
)))
1885 ext2_ino_t inode_num
;
1887 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1890 kill_file_by_inode(inode_num
);
1893 void do_rm(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1894 void *infop
EXT2FS_ATTR((unused
)))
1897 ext2_ino_t inode_num
;
1898 struct ext2_inode inode
;
1900 if (common_args_process(argc
, argv
, 2, 2, "rm",
1901 "<filename>", CHECK_FS_RW
))
1904 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1906 com_err(argv
[0], retval
, "while trying to resolve filename");
1910 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1913 if (LINUX_S_ISDIR(inode
.i_mode
)) {
1914 com_err(argv
[0], 0, "file is a directory");
1918 --inode
.i_links_count
;
1919 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
1922 unlink_file_by_name(argv
[1]);
1923 if (inode
.i_links_count
== 0)
1924 kill_file_by_inode(inode_num
);
1932 static int rmdir_proc(ext2_ino_t dir
EXT2FS_ATTR((unused
)),
1933 int entry
EXT2FS_ATTR((unused
)),
1934 struct ext2_dir_entry
*dirent
,
1935 int offset
EXT2FS_ATTR((unused
)),
1936 int blocksize
EXT2FS_ATTR((unused
)),
1937 char *buf
EXT2FS_ATTR((unused
)),
1940 struct rd_struct
*rds
= (struct rd_struct
*) private;
1942 if (dirent
->inode
== 0)
1944 if ((ext2fs_dirent_name_len(dirent
) == 1) && (dirent
->name
[0] == '.'))
1946 if ((ext2fs_dirent_name_len(dirent
) == 2) && (dirent
->name
[0] == '.') &&
1947 (dirent
->name
[1] == '.')) {
1948 rds
->parent
= dirent
->inode
;
1955 void do_rmdir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1956 void *infop
EXT2FS_ATTR((unused
)))
1959 ext2_ino_t inode_num
;
1960 struct ext2_inode inode
;
1961 struct rd_struct rds
;
1963 if (common_args_process(argc
, argv
, 2, 2, "rmdir",
1964 "<filename>", CHECK_FS_RW
))
1967 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1969 com_err(argv
[0], retval
, "while trying to resolve filename");
1973 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1976 if (!LINUX_S_ISDIR(inode
.i_mode
)) {
1977 com_err(argv
[0], 0, "file is not a directory");
1984 retval
= ext2fs_dir_iterate2(current_fs
, inode_num
, 0,
1985 0, rmdir_proc
, &rds
);
1987 com_err(argv
[0], retval
, "while iterating over directory");
1990 if (rds
.empty
== 0) {
1991 com_err(argv
[0], 0, "directory not empty");
1995 inode
.i_links_count
= 0;
1996 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
1999 unlink_file_by_name(argv
[1]);
2000 kill_file_by_inode(inode_num
);
2003 if (debugfs_read_inode(rds
.parent
, &inode
, argv
[0]))
2005 if (inode
.i_links_count
> 1)
2006 inode
.i_links_count
--;
2007 if (debugfs_write_inode(rds
.parent
, &inode
, argv
[0]))
2011 #endif /* READ_ONLY */
2013 void do_show_debugfs_params(int argc
EXT2FS_ATTR((unused
)),
2014 ss_argv_t argv
EXT2FS_ATTR((unused
)),
2015 int sci_idx
EXT2FS_ATTR((unused
)),
2016 void *infop
EXT2FS_ATTR((unused
)))
2019 printf("Open mode: read-%s\n",
2020 current_fs
->flags
& EXT2_FLAG_RW
? "write" : "only");
2021 printf("Filesystem in use: %s\n",
2022 current_fs
? current_fs
->device_name
: "--none--");
2026 void do_expand_dir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2027 void *infop
EXT2FS_ATTR((unused
)))
2032 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_RW
))
2035 retval
= ext2fs_expand_dir(current_fs
, inode
);
2037 com_err("ext2fs_expand_dir", retval
, 0);
2041 void do_features(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2042 void *infop
EXT2FS_ATTR((unused
)))
2046 if (check_fs_open(argv
[0]))
2049 if ((argc
!= 1) && check_fs_read_write(argv
[0]))
2051 for (i
=1; i
< argc
; i
++) {
2052 if (e2p_edit_feature(argv
[i
],
2053 ¤t_fs
->super
->s_feature_compat
, 0))
2054 com_err(argv
[0], 0, "Unknown feature: %s\n",
2057 ext2fs_mark_super_dirty(current_fs
);
2059 print_features(current_fs
->super
, stdout
);
2061 #endif /* READ_ONLY */
2063 void do_bmap(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2064 void *infop
EXT2FS_ATTR((unused
)))
2067 blk64_t blk
, pblk
= 0;
2068 int c
, err
, flags
= 0, ret_flags
= 0;
2071 if (check_fs_open(argv
[0]))
2075 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
2078 flags
|= BMAP_ALLOC
;
2085 if (argc
<= optind
+1) {
2088 "Usage: bmap [-a] <file> logical_blk [physical_blk]");
2092 ino
= string_to_inode(argv
[optind
++]);
2095 err
= strtoblk(argv
[0], argv
[optind
++], "logical block", &blk
);
2099 if (argc
> optind
+1)
2102 if (argc
== optind
+1) {
2103 err
= strtoblk(argv
[0], argv
[optind
++],
2104 "physical block", &pblk
);
2107 if (flags
& BMAP_ALLOC
) {
2108 com_err(0, 0, "Can't set and allocate a block");
2114 errcode
= ext2fs_bmap2(current_fs
, ino
, 0, 0, flags
, blk
,
2117 com_err(argv
[0], errcode
,
2118 "while mapping logical block %llu\n",
2119 (unsigned long long) blk
);
2122 printf("%llu", (unsigned long long) pblk
);
2123 if (ret_flags
& BMAP_RET_UNINIT
)
2124 fputs(" (uninit)", stdout
);
2125 fputc('\n', stdout
);
2128 void do_imap(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2129 void *infop
EXT2FS_ATTR((unused
)))
2132 unsigned long group
, block
, block_nr
, offset
;
2134 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2137 ino
= string_to_inode(argv
[1]);
2141 group
= (ino
- 1) / EXT2_INODES_PER_GROUP(current_fs
->super
);
2142 offset
= ((ino
- 1) % EXT2_INODES_PER_GROUP(current_fs
->super
)) *
2143 EXT2_INODE_SIZE(current_fs
->super
);
2144 block
= offset
>> EXT2_BLOCK_SIZE_BITS(current_fs
->super
);
2145 if (!ext2fs_inode_table_loc(current_fs
, (unsigned)group
)) {
2146 com_err(argv
[0], 0, "Inode table for group %lu is missing\n",
2150 block_nr
= ext2fs_inode_table_loc(current_fs
, (unsigned)group
) +
2152 offset
&= (EXT2_BLOCK_SIZE(current_fs
->super
) - 1);
2154 printf("Inode %u is part of block group %lu\n"
2155 "\tlocated at block %lu, offset 0x%04lx\n", ino
, group
,
2160 void do_idump(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2161 void *infop
EXT2FS_ATTR((unused
)))
2163 struct ext2_inode_large
*inode
;
2167 unsigned int isize
, size
, offset
= 0;
2171 while ((c
= getopt (argc
, argv
, "bex")) != EOF
) {
2172 if (mode
|| c
== '?') {
2174 "Usage: inode_dump [-b]|[-e] <file>");
2179 if (optind
!= argc
-1)
2182 if (check_fs_open(argv
[0]))
2185 ino
= string_to_inode(argv
[optind
]);
2189 isize
= EXT2_INODE_SIZE(current_fs
->super
);
2190 err
= ext2fs_get_mem(isize
, &buf
);
2192 com_err(argv
[0], err
, "while allocating memory");
2196 err
= ext2fs_read_inode_full(current_fs
, ino
,
2197 (struct ext2_inode
*)buf
, isize
);
2199 com_err(argv
[0], err
, "while reading inode %u", ino
);
2203 inode
= (struct ext2_inode_large
*) buf
;
2207 offset
= ((char *) (&inode
->i_block
)) - ((char *) buf
);
2208 size
= sizeof(inode
->i_block
);
2212 if (size
<= EXT2_GOOD_OLD_INODE_SIZE
) {
2213 com_err(argv
[0], 0, "No extra space in inode");
2216 offset
= EXT2_GOOD_OLD_INODE_SIZE
+ inode
->i_extra_isize
;
2223 raw_inode_xattr_dump(stdout
, buf
+ offset
, size
);
2225 do_byte_hexdump(stdout
, buf
+ offset
, size
);
2227 ext2fs_free_mem(&buf
);
2231 void do_set_current_time(int argc
, ss_argv_t argv
,
2232 int sci_idx
EXT2FS_ATTR((unused
)),
2233 void *infop
EXT2FS_ATTR((unused
)))
2237 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2241 now
= string_to_time(argv
[1]);
2243 com_err(argv
[0], 0, "Couldn't parse argument as a time: %s\n",
2248 printf("Setting current time to %s\n", time_to_string(now
));
2249 current_fs
->now
= now
;
2252 #endif /* READ_ONLY */
2254 static int find_supp_feature(__u32
*supp
, int feature_type
, char *name
)
2256 int compat
, bit
, ret
;
2257 unsigned int feature_mask
;
2260 if (feature_type
== E2P_FS_FEATURE
)
2261 ret
= e2p_string2feature(name
, &compat
, &feature_mask
);
2263 ret
= e2p_jrnl_string2feature(name
, &compat
,
2268 if (!(supp
[compat
] & feature_mask
))
2271 for (compat
= 0; compat
< 3; compat
++) {
2272 for (bit
= 0, feature_mask
= 1; bit
< 32;
2273 bit
++, feature_mask
<<= 1) {
2274 if (supp
[compat
] & feature_mask
) {
2275 if (feature_type
== E2P_FS_FEATURE
)
2276 fprintf(stdout
, " %s",
2277 e2p_feature2string(compat
,
2280 fprintf(stdout
, " %s",
2281 e2p_jrnl_feature2string(compat
,
2286 fprintf(stdout
, "\n");
2292 void do_supported_features(int argc
, ss_argv_t argv
,
2293 int sci_idx
EXT2FS_ATTR((unused
)),
2294 void *infop
EXT2FS_ATTR((unused
)))
2297 __u32 supp
[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP
,
2298 EXT2_LIB_FEATURE_INCOMPAT_SUPP
,
2299 EXT2_LIB_FEATURE_RO_COMPAT_SUPP
};
2300 __u32 jrnl_supp
[3] = { JBD2_KNOWN_COMPAT_FEATURES
,
2301 JBD2_KNOWN_INCOMPAT_FEATURES
,
2302 JBD2_KNOWN_ROCOMPAT_FEATURES
};
2305 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, argv
[1]);
2307 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
,
2311 com_err(argv
[0], 0, "Unknown feature: %s\n", argv
[1]);
2313 fprintf(stdout
, "Supported feature: %s\n", argv
[1]);
2315 fprintf(stdout
, "Supported features:");
2316 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, NULL
);
2317 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
, NULL
);
2322 void do_punch(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2323 void *infop
EXT2FS_ATTR((unused
)))
2330 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2331 "<file> start_blk [end_blk]",
2332 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2335 ino
= string_to_inode(argv
[1]);
2338 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2342 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2348 errcode
= ext2fs_punch(current_fs
, ino
, 0, 0, start
, end
);
2351 com_err(argv
[0], errcode
,
2352 "while truncating inode %u from %llu to %llu\n", ino
,
2353 (unsigned long long) start
, (unsigned long long) end
);
2358 void do_fallocate(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2359 void *infop
EXT2FS_ATTR((unused
)))
2366 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2367 "<file> start_blk [end_blk]",
2368 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2371 ino
= string_to_inode(argv
[1]);
2374 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2378 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2384 errcode
= ext2fs_fallocate(current_fs
, EXT2_FALLOCATE_INIT_BEYOND_EOF
,
2385 ino
, NULL
, ~0ULL, start
, end
- start
+ 1);
2388 com_err(argv
[0], errcode
,
2389 "while fallocating inode %u from %llu to %llu\n", ino
,
2390 (unsigned long long) start
, (unsigned long long) end
);
2395 void do_symlink(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2396 void *infop
EXT2FS_ATTR((unused
)))
2400 if (common_args_process(argc
, argv
, 3, 3, "symlink",
2401 "<filename> <target>", CHECK_FS_RW
))
2404 retval
= do_symlink_internal(current_fs
, cwd
, argv
[1], argv
[2], root
);
2406 com_err(argv
[0], retval
, 0);
2409 #endif /* READ_ONLY */
2412 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)), ss_argv_t argv
,
2413 int sci_idx
EXT2FS_ATTR((unused
)),
2414 void *infop
EXT2FS_ATTR((unused
)))
2416 struct mmp_struct
*mmp_s
;
2417 unsigned long long mmp_block
;
2419 errcode_t retval
= 0;
2421 if (check_fs_open(argv
[0]))
2426 mmp_block
= strtoull(argv
[1], &end
, 0);
2427 if (end
== argv
[0] || mmp_block
== 0) {
2428 fprintf(stderr
, "%s: invalid MMP block '%s' given\n",
2433 mmp_block
= current_fs
->super
->s_mmp_block
;
2436 if (mmp_block
== 0) {
2437 fprintf(stderr
, "%s: MMP: not active on this filesystem.\n",
2442 if (current_fs
->mmp_buf
== NULL
) {
2443 retval
= ext2fs_get_mem(current_fs
->blocksize
,
2444 ¤t_fs
->mmp_buf
);
2446 com_err(argv
[0], retval
, "allocating MMP buffer.\n");
2451 mmp_s
= current_fs
->mmp_buf
;
2453 retval
= ext2fs_mmp_read(current_fs
, mmp_block
, current_fs
->mmp_buf
);
2455 com_err(argv
[0], retval
, "reading MMP block %llu.\n",
2456 (unsigned long long) mmp_block
);
2460 t
= mmp_s
->mmp_time
;
2461 fprintf(stdout
, "block_number: %llu\n",
2462 (unsigned long long) current_fs
->super
->s_mmp_block
);
2463 fprintf(stdout
, "update_interval: %d\n",
2464 current_fs
->super
->s_mmp_update_interval
);
2465 fprintf(stdout
, "check_interval: %d\n", mmp_s
->mmp_check_interval
);
2466 fprintf(stdout
, "sequence: %08x\n", mmp_s
->mmp_seq
);
2467 fprintf(stdout
, "time: %llu -- %s",
2468 (unsigned long long) mmp_s
->mmp_time
, ctime(&t
));
2469 fprintf(stdout
, "node_name: %.*s\n",
2470 EXT2_LEN_STR(mmp_s
->mmp_nodename
));
2471 fprintf(stdout
, "device_name: %.*s\n",
2472 EXT2_LEN_STR(mmp_s
->mmp_bdevname
));
2473 fprintf(stdout
, "magic: 0x%x\n", mmp_s
->mmp_magic
);
2474 fprintf(stdout
, "checksum: 0x%08x\n", mmp_s
->mmp_checksum
);
2477 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)),
2478 ss_argv_t argv
EXT2FS_ATTR((unused
)),
2479 int sci_idx
EXT2FS_ATTR((unused
)),
2480 void *infop
EXT2FS_ATTR((unused
)))
2482 fprintf(stdout
, "MMP is unsupported, please recompile with "
2487 static int source_file(const char *cmd_file
, int ss_idx
)
2492 int exit_status
= 0;
2495 if (strcmp(cmd_file
, "-") == 0)
2498 f
= fopen(cmd_file
, "r");
2506 setbuf(stdout
, NULL
);
2507 setbuf(stderr
, NULL
);
2509 if (fgets(buf
, sizeof(buf
), f
) == NULL
)
2511 if (buf
[0] == '#') {
2515 cp
= strchr(buf
, '\n');
2518 cp
= strchr(buf
, '\r');
2521 printf("debugfs: %s\n", buf
);
2522 retval
= ss_execute_line(ss_idx
, buf
);
2524 ss_perror(ss_idx
, retval
, buf
);
2533 int main(int argc
, char **argv
)
2537 "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] "
2538 "[-R request] [-d data_source_device] [-i] [-n] [-D] [-V] ["
2540 "[-w] [-z undo_file] "
2544 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
|
2545 EXT2_FLAG_64BITS
| EXT2_FLAG_THREADS
;
2547 int exit_status
= 0;
2549 blk64_t superblock
= 0;
2550 blk64_t blocksize
= 0;
2551 int catastrophic
= 0;
2552 char *data_filename
= 0;
2554 const char *opt_string
= "nicR:f:b:s:Vd:D";
2556 const char *opt_string
= "niwcR:f:b:s:Vd:Dz:";
2558 char *undo_file
= NULL
;
2559 #ifdef CONFIG_JBD_DEBUG
2563 setlocale(LC_CTYPE
, "");
2565 if (debug_prog_name
== 0)
2567 debug_prog_name
= "rdebugfs";
2569 debug_prog_name
= "debugfs";
2571 add_error_table(&et_ext2_error_table
);
2572 fprintf (stderr
, "%s %s (%s)\n", debug_prog_name
,
2573 E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
2575 #ifdef CONFIG_JBD_DEBUG
2576 jbd_debug
= ss_safe_getenv("DEBUGFS_JBD_DEBUG");
2578 int res
= sscanf(jbd_debug
, "%d", &journal_enable_debug
);
2582 "DEBUGFS_JBD_DEBUG \"%s\" not an integer\n\n",
2588 while ((c
= getopt (argc
, argv
, opt_string
)) != EOF
) {
2597 data_filename
= optarg
;
2600 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
2603 open_flags
|= EXT2_FLAG_IGNORE_CSUM_ERRORS
;
2607 open_flags
|= EXT2_FLAG_RW
;
2611 open_flags
|= EXT2_FLAG_DIRECT_IO
;
2614 blocksize
= parse_ulong(optarg
, argv
[0],
2618 retval
= strtoblk(argv
[0], optarg
,
2619 "superblock block number",
2628 /* Print version number and exit */
2629 fprintf(stderr
, "\tUsing %s\n",
2630 error_message(EXT2_ET_BASE
));
2638 com_err(argv
[0], 0, usage
, debug_prog_name
);
2643 open_filesystem(argv
[optind
], open_flags
,
2644 superblock
, blocksize
, catastrophic
,
2645 data_filename
, undo_file
);
2647 ss_sci_idx
= ss_create_invocation(debug_prog_name
, "0.0", (char *) NULL
,
2648 &debug_cmds
, &retval
);
2650 ss_perror(ss_sci_idx
, retval
, "creating invocation");
2653 ss_get_readline(ss_sci_idx
);
2655 (void) ss_add_request_table(ss_sci_idx
, &ss_std_requests
, 1, &retval
);
2657 ss_perror(ss_sci_idx
, retval
, "adding standard requests");
2661 ss_add_request_table(ss_sci_idx
, extra_cmds
, 1, &retval
);
2663 ss_perror(ss_sci_idx
, retval
, "adding extra requests");
2668 retval
= ss_execute_line(ss_sci_idx
, request
);
2670 ss_perror(ss_sci_idx
, retval
, request
);
2673 } else if (cmd_file
) {
2674 exit_status
= source_file(cmd_file
, ss_sci_idx
);
2676 ss_listen(ss_sci_idx
);
2679 ss_delete_invocation(ss_sci_idx
);
2684 remove_error_table(&et_ext2_error_table
);