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
;
67 static int debugfs_setup_tdb(const char *device_name
, char *undo_file
,
70 errcode_t retval
= ENOMEM
;
71 const char *tdb_dir
= NULL
;
72 char *tdb_file
= NULL
;
73 char *dev_name
, *tmp_name
;
75 /* (re)open a specific undo file */
76 if (undo_file
&& undo_file
[0] != 0) {
77 retval
= set_undo_io_backing_manager(*io_ptr
);
80 *io_ptr
= undo_io_manager
;
81 retval
= set_undo_io_backup_file(undo_file
);
84 printf("Overwriting existing filesystem; this can be undone "
85 "using the command:\n"
87 undo_file
, device_name
);
92 * Configuration via a conf file would be
95 tdb_dir
= ss_safe_getenv("E2FSPROGS_UNDO_DIR");
97 tdb_dir
= "/var/lib/e2fsprogs";
99 if (!strcmp(tdb_dir
, "none") || (tdb_dir
[0] == 0) ||
100 access(tdb_dir
, W_OK
))
103 tmp_name
= strdup(device_name
);
106 dev_name
= basename(tmp_name
);
107 tdb_file
= malloc(strlen(tdb_dir
) + 9 + strlen(dev_name
) + 7 + 1);
112 sprintf(tdb_file
, "%s/debugfs-%s.e2undo", tdb_dir
, dev_name
);
115 if ((unlink(tdb_file
) < 0) && (errno
!= ENOENT
)) {
117 com_err("debugfs", retval
,
118 "while trying to delete %s", tdb_file
);
122 retval
= set_undo_io_backing_manager(*io_ptr
);
125 *io_ptr
= undo_io_manager
;
126 retval
= set_undo_io_backup_file(tdb_file
);
129 printf("Overwriting existing filesystem; this can be undone "
130 "using the command:\n"
131 " e2undo %s %s\n\n", tdb_file
, device_name
);
138 com_err("debugfs", retval
, "while trying to setup undo file\n");
142 static void open_filesystem(char *device
, int open_flags
, blk64_t superblock
,
143 blk64_t blocksize
, int catastrophic
,
144 char *data_filename
, char *undo_file
)
147 io_channel data_io
= 0;
148 io_manager io_ptr
= unix_io_manager
;
150 if (superblock
!= 0 && blocksize
== 0) {
151 com_err(device
, 0, "if you specify the superblock, you must also specify the block size");
157 if ((open_flags
& EXT2_FLAG_IMAGE_FILE
) == 0) {
159 "The -d option is only valid when reading an e2image file");
163 retval
= unix_io_manager
->open(data_filename
, 0, &data_io
);
165 com_err(data_filename
, 0, "while opening data source");
172 open_flags
|= EXT2_FLAG_SKIP_MMP
| EXT2_FLAG_IGNORE_SB_ERRORS
;
175 retval
= debugfs_setup_tdb(device
, undo_file
, &io_ptr
);
181 retval
= ext2fs_open(device
, open_flags
, superblock
, blocksize
,
182 io_ptr
, ¤t_fs
);
183 if (retval
&& (retval
== EXT2_ET_SB_CSUM_INVALID
) &&
184 !(open_flags
& EXT2_FLAG_IGNORE_CSUM_ERRORS
)) {
185 open_flags
|= EXT2_FLAG_IGNORE_CSUM_ERRORS
;
186 printf("Checksum errors in superblock! Retrying...\n");
190 com_err(debug_prog_name
, retval
,
191 "while trying to open %s", device
);
192 if (retval
== EXT2_ET_BAD_MAGIC
)
193 check_plausibility(device
, CHECK_FS_EXIST
, NULL
);
197 current_fs
->default_bitmap_type
= EXT2FS_BMAP64_RBTREE
;
200 retval
= ext2fs_read_bitmaps(current_fs
);
202 com_err(device
, retval
,
203 "while reading allocation bitmaps");
209 retval
= ext2fs_set_data_io(current_fs
, data_io
);
211 com_err(device
, retval
,
212 "while setting data source");
217 root
= cwd
= EXT2_ROOT_INO
;
221 retval
= ext2fs_close_free(¤t_fs
);
223 com_err(device
, retval
, "while trying to close filesystem");
226 void do_open_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
227 void *infop
EXT2FS_ATTR((unused
)))
230 int catastrophic
= 0;
231 blk64_t superblock
= 0;
232 blk64_t blocksize
= 0;
233 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
| EXT2_FLAG_64BITS
|
235 char *data_filename
= 0;
236 char *undo_file
= NULL
;
239 while ((c
= getopt(argc
, argv
, "iwfecb:s:d:Dz:")) != EOF
) {
242 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
248 open_flags
|= EXT2_FLAG_RW
;
249 #endif /* READ_ONLY */
252 open_flags
|= EXT2_FLAG_FORCE
;
255 open_flags
|= EXT2_FLAG_EXCLUSIVE
;
261 data_filename
= optarg
;
264 open_flags
|= EXT2_FLAG_DIRECT_IO
;
267 blocksize
= parse_ulong(optarg
, argv
[0],
273 err
= strtoblk(argv
[0], optarg
,
274 "superblock block number", &superblock
);
289 if (optind
!= argc
-1) {
292 if (check_fs_not_open(argv
[0]))
294 open_filesystem(argv
[optind
], open_flags
,
295 superblock
, blocksize
, catastrophic
,
296 data_filename
, undo_file
);
300 fprintf(stderr
, "%s: Usage: open [-s superblock] [-b blocksize] "
302 "[-d image_filename] [-z undo_file] [-c] [-i] [-f] [-e] [-D] "
304 "[-d image_filename] [-c] [-i] [-f] [-e] [-D] [-w] "
306 "<device>\n", argv
[0]);
309 void do_lcd(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
310 void *infop
EXT2FS_ATTR((unused
)))
313 com_err(argv
[0], 0, "Usage: %s %s", argv
[0], "<native dir>");
317 if (chdir(argv
[1]) == -1) {
318 com_err(argv
[0], errno
,
319 "while trying to change native directory to %s",
325 static void close_filesystem(NOARGS
)
329 if (current_fs
->flags
& EXT2_FLAG_IB_DIRTY
) {
330 retval
= ext2fs_write_inode_bitmap(current_fs
);
332 com_err("ext2fs_write_inode_bitmap", retval
, 0);
334 if (current_fs
->flags
& EXT2_FLAG_BB_DIRTY
) {
335 retval
= ext2fs_write_block_bitmap(current_fs
);
337 com_err("ext2fs_write_block_bitmap", retval
, 0);
340 quota_release_context(¤t_qctx
);
341 retval
= ext2fs_close_free(¤t_fs
);
343 com_err("ext2fs_close", retval
, 0);
347 void do_close_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
348 void *infop
EXT2FS_ATTR((unused
)))
352 if (check_fs_open(argv
[0]))
356 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
359 current_fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
368 com_err(0, 0, "Usage: close_filesys [-a]");
376 void do_init_filesys(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
377 void *infop
EXT2FS_ATTR((unused
)))
379 struct ext2_super_block param
;
384 if (common_args_process(argc
, argv
, 3, 3, "initialize",
385 "<device> <blocks>", CHECK_FS_NOTOPEN
))
388 memset(¶m
, 0, sizeof(struct ext2_super_block
));
389 err
= strtoblk(argv
[0], argv
[2], "blocks count", &blocks
);
392 ext2fs_blocks_count_set(¶m
, blocks
);
393 retval
= ext2fs_initialize(argv
[1], 0, ¶m
,
394 unix_io_manager
, ¤t_fs
);
396 com_err(argv
[1], retval
, "while initializing filesystem");
400 root
= cwd
= EXT2_ROOT_INO
;
404 static void print_features(struct ext2_super_block
* s
, FILE *f
)
407 __u32
*mask
= &s
->s_feature_compat
, m
;
409 fputs("Filesystem features:", f
);
410 for (i
=0; i
<3; i
++,mask
++) {
411 for (j
=0,m
=1; j
< 32; j
++, m
<<=1) {
413 fprintf(f
, " %s", e2p_feature2string(i
, m
));
422 #endif /* READ_ONLY */
424 static void print_bg_opts(ext2_filsys fs
, dgrp_t group
, int mask
,
425 const char *str
, int *first
, FILE *f
)
427 if (ext2fs_bg_flags_test(fs
, group
, mask
)) {
437 void do_show_super_stats(int argc
, ss_argv_t argv
,
438 int sci_idx
EXT2FS_ATTR((unused
)),
439 void *infop
EXT2FS_ATTR((unused
)))
441 const char *units
="block";
444 int c
, header_only
= 0;
445 int numdirs
= 0, first
, gdt_csum
;
448 while ((c
= getopt (argc
, argv
, "h")) != EOF
) {
457 if (optind
!= argc
) {
460 if (check_fs_open(argv
[0]))
464 if (ext2fs_has_feature_bigalloc(current_fs
->super
))
467 list_super2(current_fs
->super
, out
);
468 if (ext2fs_has_feature_metadata_csum(current_fs
->super
) &&
469 !ext2fs_superblock_csum_verify(current_fs
,
470 current_fs
->super
)) {
471 __u32 orig_csum
= current_fs
->super
->s_checksum
;
473 ext2fs_superblock_csum_set(current_fs
,
475 fprintf(out
, "Expected Checksum: 0x%08x\n",
476 current_fs
->super
->s_checksum
);
477 current_fs
->super
->s_checksum
= orig_csum
;
479 for (i
=0; i
< current_fs
->group_desc_count
; i
++)
480 numdirs
+= ext2fs_bg_used_dirs_count(current_fs
, i
);
481 fprintf(out
, "Directories: %u\n", numdirs
);
488 gdt_csum
= ext2fs_has_group_desc_csum(current_fs
);
489 for (i
= 0; i
< current_fs
->group_desc_count
; i
++) {
490 fprintf(out
, " Group %2d: block bitmap at %llu, "
491 "inode bitmap at %llu, "
492 "inode table at %llu\n"
496 (unsigned long long) ext2fs_block_bitmap_loc(current_fs
, i
),
497 (unsigned long long) ext2fs_inode_bitmap_loc(current_fs
, i
),
498 (unsigned long long) ext2fs_inode_table_loc(current_fs
, i
),
499 ext2fs_bg_free_blocks_count(current_fs
, i
),
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 ss_argv_t 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
,
571 (unsigned long long) lb
->first_block
);
573 fprintf(lb
->f
, "(%lld-%lld):%llu-%llu",
574 (long long)lb
->first_bcnt
, (long long)lb
->last_bcnt
,
575 (unsigned long long) lb
->first_block
,
576 (unsigned long long) lb
->last_block
);
580 static int list_blocks_proc(ext2_filsys fs
EXT2FS_ATTR((unused
)),
581 blk64_t
*blocknr
, e2_blkcnt_t blockcnt
,
582 blk64_t ref_block
EXT2FS_ATTR((unused
)),
583 int ref_offset
EXT2FS_ATTR((unused
)),
586 struct list_blocks_struct
*lb
= (struct list_blocks_struct
*) private;
591 * See if we can add on to the existing range (if it exists)
593 if (lb
->first_block
&&
594 (lb
->last_block
+1 == *blocknr
) &&
595 (lb
->last_bcnt
+1 == blockcnt
)) {
596 lb
->last_block
= *blocknr
;
597 lb
->last_bcnt
= blockcnt
;
604 lb
->first_block
= lb
->last_block
= *blocknr
;
605 lb
->first_bcnt
= lb
->last_bcnt
= blockcnt
;
609 * Not a normal block. Always force a new range.
615 fprintf(lb
->f
, ", ");
617 fprintf(lb
->f
, "(IND):%llu", (unsigned long long) *blocknr
);
618 else if (blockcnt
== -2)
619 fprintf(lb
->f
, "(DIND):%llu", (unsigned long long) *blocknr
);
620 else if (blockcnt
== -3)
621 fprintf(lb
->f
, "(TIND):%llu", (unsigned long long) *blocknr
);
625 static void internal_dump_inode_extra(FILE *out
,
626 const char *prefix
EXT2FS_ATTR((unused
)),
627 ext2_ino_t inode_num
EXT2FS_ATTR((unused
)),
628 struct ext2_inode_large
*inode
)
630 fprintf(out
, "Size of extra inode fields: %u\n", inode
->i_extra_isize
);
631 if (inode
->i_extra_isize
> EXT2_INODE_SIZE(current_fs
->super
) -
632 EXT2_GOOD_OLD_INODE_SIZE
) {
633 fprintf(stderr
, "invalid inode->i_extra_isize (%u)\n",
634 inode
->i_extra_isize
);
639 static void dump_blocks(FILE *f
, const char *prefix
, ext2_ino_t inode
)
641 struct list_blocks_struct lb
;
643 fprintf(f
, "%sBLOCKS:\n%s", prefix
, prefix
);
648 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
, NULL
,
649 list_blocks_proc
, (void *)&lb
);
652 fprintf(f
, "\n%sTOTAL: %lld\n", prefix
, (long long)lb
.total
);
656 static int int_log10(unsigned long long arg
)
668 #define DUMP_LEAF_EXTENTS 0x01
669 #define DUMP_NODE_EXTENTS 0x02
670 #define DUMP_EXTENT_TABLE 0x04
672 static void dump_extents(FILE *f
, const char *prefix
, ext2_ino_t ino
,
673 int flags
, int logical_width
, int physical_width
)
675 ext2_extent_handle_t handle
;
676 struct ext2fs_extent extent
;
677 struct ext2_extent_info info
;
678 int op
= EXT2_EXTENT_ROOT
;
679 unsigned int printed
= 0;
682 errcode
= ext2fs_extent_open(current_fs
, ino
, &handle
);
686 if (flags
& DUMP_EXTENT_TABLE
)
687 fprintf(f
, "Level Entries %*s %*s Length Flags\n",
688 (logical_width
*2)+3, "Logical",
689 (physical_width
*2)+3, "Physical");
691 fprintf(f
, "%sEXTENTS:\n%s", prefix
, prefix
);
694 errcode
= ext2fs_extent_get(handle
, op
, &extent
);
699 op
= EXT2_EXTENT_NEXT
;
701 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
704 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
) {
705 if ((flags
& DUMP_LEAF_EXTENTS
) == 0)
708 if ((flags
& DUMP_NODE_EXTENTS
) == 0)
712 errcode
= ext2fs_extent_get_info(handle
, &info
);
716 if (!(extent
.e_flags
& EXT2_EXTENT_FLAGS_LEAF
)) {
717 if (extent
.e_flags
& EXT2_EXTENT_FLAGS_SECOND_VISIT
)
720 if (flags
& DUMP_EXTENT_TABLE
) {
721 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
723 info
.curr_level
, info
.max_depth
,
724 info
.curr_entry
, info
.num_entries
,
726 (unsigned long long) extent
.e_lblk
,
728 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
730 (unsigned long long) extent
.e_pblk
,
731 physical_width
+3, "", extent
.e_len
);
735 fprintf(f
, "%s(ETB%d):%llu",
736 printed
? ", " : "", info
.curr_level
,
737 (unsigned long long) extent
.e_pblk
);
742 if (flags
& DUMP_EXTENT_TABLE
) {
743 fprintf(f
, "%2d/%2d %3d/%3d %*llu - %*llu "
744 "%*llu - %*llu %6u %s\n",
745 info
.curr_level
, info
.max_depth
,
746 info
.curr_entry
, info
.num_entries
,
748 (unsigned long long) extent
.e_lblk
,
750 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
752 (unsigned long long) extent
.e_pblk
,
754 (unsigned long long) extent
.e_pblk
+ (extent
.e_len
- 1),
756 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
761 if (extent
.e_len
== 0)
763 else if (extent
.e_len
== 1)
767 (unsigned long long) extent
.e_lblk
,
768 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
770 (unsigned long long) extent
.e_pblk
);
773 "%s(%lld-%lld%s):%lld-%lld",
775 (unsigned long long) extent
.e_lblk
,
776 (unsigned long long) extent
.e_lblk
+ (extent
.e_len
- 1),
777 extent
.e_flags
& EXT2_EXTENT_FLAGS_UNINIT
?
779 (unsigned long long) extent
.e_pblk
,
780 (unsigned long long) extent
.e_pblk
+ (extent
.e_len
- 1));
785 ext2fs_extent_free(handle
);
788 static void dump_inline_data(FILE *out
, const char *prefix
, ext2_ino_t inode_num
)
793 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
795 fprintf(out
, "%sSize of inline data: %zu\n", prefix
, size
);
798 static void dump_inline_symlink(FILE *out
, ext2_ino_t inode_num
,
799 struct ext2_inode
*inode
, const char *prefix
)
805 retval
= ext2fs_inline_data_size(current_fs
, inode_num
, &size
);
809 retval
= ext2fs_get_memzero(size
+ 1, &buf
);
813 retval
= ext2fs_inline_data_get(current_fs
, inode_num
,
818 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
822 ext2fs_free_mem(&buf
);
824 com_err(__func__
, retval
, "while dumping link destination");
827 void internal_dump_inode(FILE *out
, const char *prefix
,
828 ext2_ino_t inode_num
, struct ext2_inode
*inode
,
833 int os
= current_fs
->super
->s_creator_os
;
834 struct ext2_inode_large
*large_inode
;
837 large_inode
= (struct ext2_inode_large
*) inode
;
838 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
839 inode_size
= ext2fs_inode_actual_size(large_inode
);
841 inode_size
= EXT2_GOOD_OLD_INODE_SIZE
;
843 if (LINUX_S_ISDIR(inode
->i_mode
)) i_type
= "directory";
844 else if (LINUX_S_ISREG(inode
->i_mode
)) i_type
= "regular";
845 else if (LINUX_S_ISLNK(inode
->i_mode
)) i_type
= "symlink";
846 else if (LINUX_S_ISBLK(inode
->i_mode
)) i_type
= "block special";
847 else if (LINUX_S_ISCHR(inode
->i_mode
)) i_type
= "character special";
848 else if (LINUX_S_ISFIFO(inode
->i_mode
)) i_type
= "FIFO";
849 else if (LINUX_S_ISSOCK(inode
->i_mode
)) i_type
= "socket";
850 else i_type
= "bad type";
851 fprintf(out
, "%sInode: %u Type: %s ", prefix
, inode_num
, i_type
);
852 fprintf(out
, "%sMode: 0%03o Flags: 0x%x\n",
853 prefix
, inode
->i_mode
& 07777, inode
->i_flags
);
854 if (ext2fs_inode_includes(inode_size
, i_version_hi
)) {
855 fprintf(out
, "%sGeneration: %u Version: 0x%08x:%08x\n",
856 prefix
, inode
->i_generation
, large_inode
->i_version_hi
,
857 inode
->osd1
.linux1
.l_i_version
);
859 fprintf(out
, "%sGeneration: %u Version: 0x%08x\n", prefix
,
860 inode
->i_generation
, inode
->osd1
.linux1
.l_i_version
);
862 fprintf(out
, "%sUser: %5d Group: %5d",
863 prefix
, inode_uid(*inode
), inode_gid(*inode
));
864 if (ext2fs_inode_includes(inode_size
, i_projid
))
865 fprintf(out
, " Project: %5d", large_inode
->i_projid
);
866 fputs(" Size: ", out
);
867 if (LINUX_S_ISREG(inode
->i_mode
) || LINUX_S_ISDIR(inode
->i_mode
))
868 fprintf(out
, "%llu\n", (unsigned long long) EXT2_I_SIZE(inode
));
870 fprintf(out
, "%u\n", inode
->i_size
);
871 if (os
== EXT2_OS_HURD
)
873 "%sFile ACL: %u Translator: %u\n",
876 inode
->osd1
.hurd1
.h_i_translator
);
878 fprintf(out
, "%sFile ACL: %llu\n",
880 inode
->i_file_acl
| ((long long)
881 (inode
->osd2
.linux2
.l_i_file_acl_high
) << 32));
882 if (os
!= EXT2_OS_HURD
)
883 fprintf(out
, "%sLinks: %u Blockcount: %llu\n",
884 prefix
, inode
->i_links_count
,
885 (((unsigned long long)
886 inode
->osd2
.linux2
.l_i_blocks_hi
<< 32)) +
889 fprintf(out
, "%sLinks: %u Blockcount: %u\n",
890 prefix
, inode
->i_links_count
, inode
->i_blocks
);
893 frag
= inode
->osd2
.hurd2
.h_i_frag
;
894 fsize
= inode
->osd2
.hurd2
.h_i_fsize
;
899 fprintf(out
, "%sFragment: Address: %u Number: %u Size: %u\n",
900 prefix
, inode
->i_faddr
, frag
, fsize
);
901 if (ext2fs_inode_includes(inode_size
, i_ctime_extra
))
902 fprintf(out
, "%s ctime: 0x%08x:%08x -- %s", prefix
,
903 inode
->i_ctime
, large_inode
->i_ctime_extra
,
904 time_to_string(ext2fs_inode_xtime_get(large_inode
,
907 fprintf(out
, "%sctime: 0x%08x -- %s", prefix
, inode
->i_ctime
,
908 time_to_string((__s32
) inode
->i_ctime
));
909 if (ext2fs_inode_includes(inode_size
, i_atime_extra
))
910 fprintf(out
, "%s atime: 0x%08x:%08x -- %s", prefix
,
911 inode
->i_atime
, large_inode
->i_atime_extra
,
912 time_to_string(ext2fs_inode_xtime_get(large_inode
,
915 fprintf(out
, "%satime: 0x%08x -- %s", prefix
, inode
->i_atime
,
916 time_to_string((__s32
) inode
->i_atime
));
917 if (ext2fs_inode_includes(inode_size
, i_mtime_extra
))
918 fprintf(out
, "%s mtime: 0x%08x:%08x -- %s", prefix
,
919 inode
->i_mtime
, large_inode
->i_mtime_extra
,
920 time_to_string(ext2fs_inode_xtime_get(large_inode
,
923 fprintf(out
, "%smtime: 0x%08x -- %s", prefix
, inode
->i_mtime
,
924 time_to_string((__s32
) inode
->i_mtime
));
925 if (ext2fs_inode_includes(inode_size
, i_crtime_extra
))
926 fprintf(out
, "%scrtime: 0x%08x:%08x -- %s", prefix
,
927 large_inode
->i_crtime
, large_inode
->i_crtime_extra
,
928 time_to_string(ext2fs_inode_xtime_get(large_inode
,
930 if (inode
->i_dtime
) {
931 if (ext2fs_inode_includes(inode_size
, i_ctime_extra
)) {
934 /* dtime doesn't have its own i_dtime_extra field, so
935 * approximate this with i_ctime_extra instead. */
936 tm
= __decode_extra_sec(inode
->i_dtime
,
937 large_inode
->i_ctime_extra
);
938 fprintf(out
, "%s dtime: 0x%08x:(%08x) -- %s", prefix
,
939 inode
->i_dtime
, large_inode
->i_ctime_extra
,
942 fprintf(out
, "%sdtime: 0x%08x -- %s", prefix
,
944 time_to_string((__s32
) inode
->i_dtime
));
947 if (EXT2_INODE_SIZE(current_fs
->super
) > EXT2_GOOD_OLD_INODE_SIZE
)
948 internal_dump_inode_extra(out
, prefix
, inode_num
,
949 (struct ext2_inode_large
*) inode
);
950 dump_inode_attributes(out
, inode_num
);
951 if (ext2fs_has_feature_metadata_csum(current_fs
->super
)) {
952 __u32 crc
= inode
->i_checksum_lo
;
953 if (ext2fs_inode_includes(inode_size
, i_checksum_hi
))
954 crc
|= ((__u32
)large_inode
->i_checksum_hi
) << 16;
955 fprintf(out
, "Inode checksum: 0x%08x\n", crc
);
958 if (LINUX_S_ISLNK(inode
->i_mode
) && ext2fs_is_fast_symlink(inode
))
959 fprintf(out
, "%sFast link dest: \"%.*s\"\n", prefix
,
960 (int)EXT2_I_SIZE(inode
), (char *)inode
->i_block
);
961 else if (LINUX_S_ISLNK(inode
->i_mode
) &&
962 (inode
->i_flags
& EXT4_INLINE_DATA_FL
))
963 dump_inline_symlink(out
, inode_num
, inode
, prefix
);
964 else if (LINUX_S_ISBLK(inode
->i_mode
) || LINUX_S_ISCHR(inode
->i_mode
)) {
968 if (inode
->i_block
[0]) {
969 major
= (inode
->i_block
[0] >> 8) & 255;
970 minor
= inode
->i_block
[0] & 255;
973 major
= (inode
->i_block
[1] & 0xfff00) >> 8;
974 minor
= ((inode
->i_block
[1] & 0xff) |
975 ((inode
->i_block
[1] >> 12) & 0xfff00));
976 devnote
= "(New-style) ";
978 fprintf(out
, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n",
979 devnote
, major
, minor
, major
, minor
);
980 } else if (do_dump_blocks
) {
981 if (inode
->i_flags
& EXT4_EXTENTS_FL
)
982 dump_extents(out
, prefix
, inode_num
,
983 DUMP_LEAF_EXTENTS
|DUMP_NODE_EXTENTS
, 0, 0);
984 else if (inode
->i_flags
& EXT4_INLINE_DATA_FL
)
985 dump_inline_data(out
, prefix
, inode_num
);
987 dump_blocks(out
, prefix
, inode_num
);
991 static void dump_inode(ext2_ino_t inode_num
, struct ext2_inode
*inode
)
996 internal_dump_inode(out
, "", inode_num
, inode
, 1);
1000 void do_stat(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1001 void *infop
EXT2FS_ATTR((unused
)))
1004 struct ext2_inode
* inode_buf
;
1006 if (check_fs_open(argv
[0]))
1009 inode_buf
= (struct ext2_inode
*)
1010 malloc(EXT2_INODE_SIZE(current_fs
->super
));
1012 fprintf(stderr
, "do_stat: can't allocate buffer\n");
1016 if (common_inode_args_process(argc
, argv
, &inode
, 0)) {
1021 if (debugfs_read_inode2(inode
, inode_buf
, argv
[0],
1022 EXT2_INODE_SIZE(current_fs
->super
), 0)) {
1027 dump_inode(inode
, inode_buf
);
1032 void do_dump_extents(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1033 void *infop
EXT2FS_ATTR((unused
)))
1035 struct ext2_inode inode
;
1043 while ((c
= getopt(argc
, argv
, "nl")) != EOF
) {
1046 flags
|= DUMP_NODE_EXTENTS
;
1049 flags
|= DUMP_LEAF_EXTENTS
;
1054 if (argc
!= optind
+ 1) {
1055 com_err(0, 0, "Usage: dump_extents [-n] [-l] file");
1060 flags
= DUMP_NODE_EXTENTS
| DUMP_LEAF_EXTENTS
;
1061 flags
|= DUMP_EXTENT_TABLE
;
1063 if (check_fs_open(argv
[0]))
1066 ino
= string_to_inode(argv
[optind
]);
1070 if (debugfs_read_inode(ino
, &inode
, argv
[0]))
1073 if ((inode
.i_flags
& EXT4_EXTENTS_FL
) == 0) {
1074 fprintf(stderr
, "%s: does not uses extent block maps\n",
1079 logical_width
= int_log10((EXT2_I_SIZE(&inode
)+current_fs
->blocksize
-1)/
1080 current_fs
->blocksize
) + 1;
1081 if (logical_width
< 5)
1083 physical_width
= int_log10(ext2fs_blocks_count(current_fs
->super
)) + 1;
1084 if (physical_width
< 5)
1088 dump_extents(out
, "", ino
, flags
, logical_width
, physical_width
);
1093 static int print_blocks_proc(ext2_filsys fs
EXT2FS_ATTR((unused
)),
1095 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1096 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1097 int ref_offset
EXT2FS_ATTR((unused
)),
1098 void *private EXT2FS_ATTR((unused
)))
1100 printf("%llu ", (unsigned long long) *blocknr
);
1104 void do_blocks(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1105 void *infop
EXT2FS_ATTR((unused
)))
1109 if (check_fs_open(argv
[0]))
1112 if (common_inode_args_process(argc
, argv
, &inode
, 0)) {
1116 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
, NULL
,
1117 print_blocks_proc
, NULL
);
1118 fputc('\n', stdout
);
1122 void do_chroot(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1123 void *infop
EXT2FS_ATTR((unused
)))
1128 if (common_inode_args_process(argc
, argv
, &inode
, 0))
1131 retval
= ext2fs_check_directory(current_fs
, inode
);
1133 com_err(argv
[1], retval
, 0);
1140 void do_clri(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1141 void *infop
EXT2FS_ATTR((unused
)))
1144 struct ext2_inode inode_buf
;
1146 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_RW
))
1149 if (debugfs_read_inode(inode
, &inode_buf
, argv
[0]))
1151 memset(&inode_buf
, 0, sizeof(inode_buf
));
1152 if (debugfs_write_inode(inode
, &inode_buf
, argv
[0]))
1156 void do_freei(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1157 void *infop
EXT2FS_ATTR((unused
)))
1159 unsigned int len
= 1;
1163 if (common_args_process(argc
, argv
, 2, 3, argv
[0], "<file> [num]",
1164 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1166 if (check_fs_read_write(argv
[0]))
1169 inode
= string_to_inode(argv
[1]);
1174 len
= parse_ulong(argv
[2], argv
[0], "length", &err
);
1180 !ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1181 com_err(argv
[0], 0, "Warning: inode already clear");
1183 ext2fs_unmark_inode_bitmap2(current_fs
->inode_map
, inode
++);
1184 ext2fs_mark_ib_dirty(current_fs
);
1187 void do_seti(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1188 void *infop
EXT2FS_ATTR((unused
)))
1190 unsigned int len
= 1;
1194 if (common_args_process(argc
, argv
, 2, 3, argv
[0], "<file> [num]",
1195 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1197 if (check_fs_read_write(argv
[0]))
1200 inode
= string_to_inode(argv
[1]);
1205 len
= parse_ulong(argv
[2], argv
[0], "length", &err
);
1211 ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1212 com_err(argv
[0], 0, "Warning: inode already set");
1214 ext2fs_mark_inode_bitmap2(current_fs
->inode_map
, inode
++);
1215 ext2fs_mark_ib_dirty(current_fs
);
1217 #endif /* READ_ONLY */
1219 void do_testi(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1220 void *infop
EXT2FS_ATTR((unused
)))
1224 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_BITMAPS
))
1227 if (ext2fs_test_inode_bitmap2(current_fs
->inode_map
,inode
))
1228 printf("Inode %u is marked in use\n", inode
);
1230 printf("Inode %u is not in use\n", inode
);
1234 void do_freeb(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1235 void *infop
EXT2FS_ATTR((unused
)))
1240 if (common_block_args_process(argc
, argv
, &block
, &count
))
1242 if (check_fs_read_write(argv
[0]))
1244 while (count
-- > 0) {
1245 if (!ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1246 com_err(argv
[0], 0, "Warning: block %llu already clear",
1247 (unsigned long long) block
);
1248 ext2fs_unmark_block_bitmap2(current_fs
->block_map
,block
);
1251 ext2fs_mark_bb_dirty(current_fs
);
1254 void do_setb(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1255 void *infop
EXT2FS_ATTR((unused
)))
1260 if (common_block_args_process(argc
, argv
, &block
, &count
))
1262 if (check_fs_read_write(argv
[0]))
1264 while (count
-- > 0) {
1265 if (ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1266 com_err(argv
[0], 0, "Warning: block %llu already set",
1267 (unsigned long long) block
);
1268 ext2fs_mark_block_bitmap2(current_fs
->block_map
,block
);
1271 ext2fs_mark_bb_dirty(current_fs
);
1273 #endif /* READ_ONLY */
1275 void do_testb(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1276 void *infop
EXT2FS_ATTR((unused
)))
1281 if (common_block_args_process(argc
, argv
, &block
, &count
))
1283 while (count
-- > 0) {
1284 if (ext2fs_test_block_bitmap2(current_fs
->block_map
,block
))
1285 printf("Block %llu marked in use\n",
1286 (unsigned long long) block
);
1288 printf("Block %llu not in use\n",
1289 (unsigned long long) block
);
1295 static void modify_u8(char *com
, const char *prompt
,
1296 const char *format
, __u8
*val
)
1302 sprintf(buf
, format
, *val
);
1303 printf("%30s [%s] ", prompt
, buf
);
1304 if (!fgets(buf
, sizeof(buf
), stdin
))
1306 if (buf
[strlen (buf
) - 1] == '\n')
1307 buf
[strlen (buf
) - 1] = '\0';
1310 v
= strtoul(buf
, &tmp
, 0);
1312 com_err(com
, 0, "Bad value - %s", buf
);
1317 static void modify_u16(char *com
, const char *prompt
,
1318 const char *format
, __u16
*val
)
1324 sprintf(buf
, format
, *val
);
1325 printf("%30s [%s] ", prompt
, buf
);
1326 if (!fgets(buf
, sizeof(buf
), stdin
))
1328 if (buf
[strlen (buf
) - 1] == '\n')
1329 buf
[strlen (buf
) - 1] = '\0';
1332 v
= strtoul(buf
, &tmp
, 0);
1334 com_err(com
, 0, "Bad value - %s", buf
);
1339 static void modify_u32(char *com
, const char *prompt
,
1340 const char *format
, __u32
*val
)
1346 sprintf(buf
, format
, *val
);
1347 printf("%30s [%s] ", prompt
, buf
);
1348 if (!fgets(buf
, sizeof(buf
), stdin
))
1350 if (buf
[strlen (buf
) - 1] == '\n')
1351 buf
[strlen (buf
) - 1] = '\0';
1354 v
= strtoul(buf
, &tmp
, 0);
1356 com_err(com
, 0, "Bad value - %s", buf
);
1362 void do_modify_inode(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1363 void *infop
EXT2FS_ATTR((unused
)))
1365 struct ext2_inode inode
;
1366 ext2_ino_t inode_num
;
1368 unsigned char *frag
, *fsize
;
1371 const char *hex_format
= "0x%x";
1372 const char *octal_format
= "0%o";
1373 const char *decimal_format
= "%d";
1374 const char *unsignedlong_format
= "%lu";
1376 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1379 os
= current_fs
->super
->s_creator_os
;
1381 if (debugfs_read_inode(inode_num
, &inode
, argv
[1]))
1384 modify_u16(argv
[0], "Mode", octal_format
, &inode
.i_mode
);
1385 modify_u16(argv
[0], "User ID", decimal_format
, &inode
.i_uid
);
1386 modify_u16(argv
[0], "Group ID", decimal_format
, &inode
.i_gid
);
1387 modify_u32(argv
[0], "Size", unsignedlong_format
, &inode
.i_size
);
1388 modify_u32(argv
[0], "Creation time", decimal_format
, &inode
.i_ctime
);
1389 modify_u32(argv
[0], "Modification time", decimal_format
, &inode
.i_mtime
);
1390 modify_u32(argv
[0], "Access time", decimal_format
, &inode
.i_atime
);
1391 modify_u32(argv
[0], "Deletion time", decimal_format
, &inode
.i_dtime
);
1392 modify_u16(argv
[0], "Link count", decimal_format
, &inode
.i_links_count
);
1393 if (os
== EXT2_OS_LINUX
)
1394 modify_u16(argv
[0], "Block count high", unsignedlong_format
,
1395 &inode
.osd2
.linux2
.l_i_blocks_hi
);
1396 modify_u32(argv
[0], "Block count", unsignedlong_format
, &inode
.i_blocks
);
1397 modify_u32(argv
[0], "File flags", hex_format
, &inode
.i_flags
);
1398 modify_u32(argv
[0], "Generation", hex_format
, &inode
.i_generation
);
1400 modify_u32(argv
[0], "Reserved1", decimal_format
, &inode
.i_reserved1
);
1402 modify_u32(argv
[0], "File acl", decimal_format
, &inode
.i_file_acl
);
1404 modify_u32(argv
[0], "High 32bits of size", decimal_format
,
1405 &inode
.i_size_high
);
1407 if (os
== EXT2_OS_HURD
)
1408 modify_u32(argv
[0], "Translator Block",
1409 decimal_format
, &inode
.osd1
.hurd1
.h_i_translator
);
1411 modify_u32(argv
[0], "Fragment address", decimal_format
, &inode
.i_faddr
);
1414 frag
= &inode
.osd2
.hurd2
.h_i_frag
;
1415 fsize
= &inode
.osd2
.hurd2
.h_i_fsize
;
1421 modify_u8(argv
[0], "Fragment number", decimal_format
, frag
);
1423 modify_u8(argv
[0], "Fragment size", decimal_format
, fsize
);
1425 for (i
=0; i
< EXT2_NDIR_BLOCKS
; i
++) {
1426 sprintf(buf
, "Direct Block #%u", i
);
1427 modify_u32(argv
[0], buf
, decimal_format
, &inode
.i_block
[i
]);
1429 modify_u32(argv
[0], "Indirect Block", decimal_format
,
1430 &inode
.i_block
[EXT2_IND_BLOCK
]);
1431 modify_u32(argv
[0], "Double Indirect Block", decimal_format
,
1432 &inode
.i_block
[EXT2_DIND_BLOCK
]);
1433 modify_u32(argv
[0], "Triple Indirect Block", decimal_format
,
1434 &inode
.i_block
[EXT2_TIND_BLOCK
]);
1435 if (debugfs_write_inode(inode_num
, &inode
, argv
[1]))
1438 #endif /* READ_ONLY */
1440 void do_change_working_dir(int argc
, ss_argv_t argv
,
1441 int sci_idx
EXT2FS_ATTR((unused
)),
1442 void *infop
EXT2FS_ATTR((unused
)))
1447 if (common_inode_args_process(argc
, argv
, &inode
, 0))
1450 retval
= ext2fs_check_directory(current_fs
, inode
);
1452 com_err(argv
[1], retval
, 0);
1459 void do_print_working_directory(int argc
, ss_argv_t argv
,
1460 int sci_idx
EXT2FS_ATTR((unused
)),
1461 void *infop
EXT2FS_ATTR((unused
)))
1464 char *pathname
= NULL
;
1466 if (common_args_process(argc
, argv
, 1, 1,
1467 "print_working_directory", "", 0))
1470 retval
= ext2fs_get_pathname(current_fs
, cwd
, 0, &pathname
);
1472 com_err(argv
[0], retval
,
1473 "while trying to get pathname of cwd");
1475 printf("[pwd] INODE: %6u PATH: %s\n",
1476 cwd
, pathname
? pathname
: "NULL");
1481 retval
= ext2fs_get_pathname(current_fs
, root
, 0, &pathname
);
1483 com_err(argv
[0], retval
,
1484 "while trying to get pathname of root");
1486 printf("[root] INODE: %6u PATH: %s\n",
1487 root
, pathname
? pathname
: "NULL");
1496 static void make_link(char *sourcename
, char *destname
)
1499 struct ext2_inode inode
;
1502 char *dest
, *cp
, *base_name
;
1505 * Get the source inode
1507 ino
= string_to_inode(sourcename
);
1510 base_name
= strrchr(sourcename
, '/');
1514 base_name
= sourcename
;
1516 * Figure out the destination. First see if it exists and is
1519 if (! (retval
=ext2fs_namei(current_fs
, root
, cwd
, destname
, &dir
)))
1523 * OK, it doesn't exist. See if it is
1524 * '<dir>/basename' or 'basename'
1526 cp
= strrchr(destname
, '/');
1529 dir
= string_to_inode(destname
);
1539 if (debugfs_read_inode(ino
, &inode
, sourcename
))
1542 retval
= ext2fs_link(current_fs
, dir
, dest
, ino
,
1543 ext2_file_type(inode
.i_mode
));
1545 com_err("make_link", retval
, 0);
1550 void do_link(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1551 void *infop
EXT2FS_ATTR((unused
)))
1553 if (common_args_process(argc
, argv
, 3, 3, "link",
1554 "<source file> <dest_name>", CHECK_FS_RW
))
1557 make_link(argv
[1], argv
[2]);
1560 static int mark_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1561 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1562 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1563 int ref_offset
EXT2FS_ATTR((unused
)),
1564 void *private EXT2FS_ATTR((unused
)))
1569 ext2fs_block_alloc_stats2(fs
, block
, +1);
1573 void do_undel(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1574 void *infop
EXT2FS_ATTR((unused
)))
1577 struct ext2_inode inode
;
1579 if (common_args_process(argc
, argv
, 2, 3, "undelete",
1580 "<inode_num> [dest_name]",
1581 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
1584 ino
= string_to_inode(argv
[1]);
1588 if (debugfs_read_inode(ino
, &inode
, argv
[1]))
1591 if (ext2fs_test_inode_bitmap2(current_fs
->inode_map
, ino
)) {
1592 com_err(argv
[1], 0, "Inode is not marked as deleted");
1597 * XXX this function doesn't handle changing the links count on the
1598 * parent directory when undeleting a directory.
1600 inode
.i_links_count
= LINUX_S_ISDIR(inode
.i_mode
) ? 2 : 1;
1603 if (debugfs_write_inode(ino
, &inode
, argv
[0]))
1606 ext2fs_block_iterate3(current_fs
, ino
, BLOCK_FLAG_READ_ONLY
, NULL
,
1607 mark_blocks_proc
, NULL
);
1609 ext2fs_inode_alloc_stats2(current_fs
, ino
, +1, 0);
1612 make_link(argv
[1], argv
[2]);
1615 static void unlink_file_by_name(char *filename
)
1621 base_name
= strrchr(filename
, '/');
1623 *base_name
++ = '\0';
1624 dir
= string_to_inode(filename
);
1629 base_name
= filename
;
1631 retval
= ext2fs_unlink(current_fs
, dir
, base_name
, 0, 0);
1633 com_err("unlink_file_by_name", retval
, 0);
1637 void do_unlink(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1638 void *infop
EXT2FS_ATTR((unused
)))
1640 if (common_args_process(argc
, argv
, 2, 2, "link",
1641 "<pathname>", CHECK_FS_RW
))
1644 unlink_file_by_name(argv
[1]);
1647 void do_copy_inode(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1648 void *infop
EXT2FS_ATTR((unused
)))
1650 ext2_ino_t src_ino
, dest_ino
;
1651 unsigned char buf
[4096];
1653 if (common_args_process(argc
, argv
, 3, 3, "copy_inode",
1654 "<source file> <dest_name>", CHECK_FS_RW
))
1657 src_ino
= string_to_inode(argv
[1]);
1661 dest_ino
= string_to_inode(argv
[2]);
1665 if (debugfs_read_inode2(src_ino
, (struct ext2_inode
*) buf
,
1666 argv
[0], sizeof(buf
), 0))
1669 if (debugfs_write_inode2(dest_ino
, (struct ext2_inode
*) buf
,
1670 argv
[0], sizeof(buf
), 0))
1674 #endif /* READ_ONLY */
1676 void do_find_free_block(int argc
, ss_argv_t argv
,
1677 int sci_idx
EXT2FS_ATTR((unused
)),
1678 void *infop
EXT2FS_ATTR((unused
)))
1680 blk64_t free_blk
, goal
, first_free
= 0;
1685 if ((argc
> 3) || (argc
==2 && *argv
[1] == '?')) {
1686 com_err(argv
[0], 0, "Usage: find_free_block [count [goal]]");
1689 if (check_fs_open(argv
[0]))
1693 count
= strtol(argv
[1],&tmp
,0);
1695 com_err(argv
[0], 0, "Bad count - %s", argv
[1]);
1702 goal
= strtol(argv
[2], &tmp
, 0);
1704 com_err(argv
[0], 0, "Bad goal - %s", argv
[1]);
1709 goal
= current_fs
->super
->s_first_data_block
;
1711 printf("Free blocks found: ");
1712 free_blk
= goal
- 1;
1713 while (count
-- > 0) {
1714 retval
= ext2fs_new_block2(current_fs
, free_blk
+ 1, 0,
1717 if (first_free
== free_blk
)
1720 first_free
= free_blk
;
1722 com_err("ext2fs_new_block", retval
, 0);
1725 printf("%llu ", (unsigned long long) free_blk
);
1730 void do_find_free_inode(int argc
, ss_argv_t argv
,
1731 int sci_idx
EXT2FS_ATTR((unused
)),
1732 void *infop
EXT2FS_ATTR((unused
)))
1734 ext2_ino_t free_inode
, dir
;
1739 if (argc
> 3 || (argc
>1 && *argv
[1] == '?')) {
1740 com_err(argv
[0], 0, "Usage: find_free_inode [dir [mode]]");
1743 if (check_fs_open(argv
[0]))
1747 dir
= strtol(argv
[1], &tmp
, 0);
1749 com_err(argv
[0], 0, "Bad dir - %s", argv
[1]);
1756 mode
= strtol(argv
[2], &tmp
, 0);
1758 com_err(argv
[0], 0, "Bad mode - %s", argv
[2]);
1764 retval
= ext2fs_new_inode(current_fs
, dir
, mode
, 0, &free_inode
);
1766 com_err("ext2fs_new_inode", retval
, 0);
1768 printf("Free inode found: %u\n", free_inode
);
1772 void do_write(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1773 void *infop
EXT2FS_ATTR((unused
)))
1777 if (common_args_process(argc
, argv
, 3, 3, "write",
1778 "<native file> <new file>", CHECK_FS_RW
))
1781 retval
= do_write_internal(current_fs
, cwd
, argv
[1], argv
[2], root
);
1783 com_err(argv
[0], retval
, 0);
1786 void do_mknod(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1787 void *infop
EXT2FS_ATTR((unused
)))
1789 unsigned long major
, minor
;
1794 if (check_fs_open(argv
[0]))
1796 if (argc
< 3 || argv
[2][1]) {
1798 com_err(argv
[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
1803 switch (argv
[2][0]) {
1805 st
.st_mode
= S_IFIFO
;
1809 st
.st_mode
= S_IFCHR
;
1813 st
.st_mode
= S_IFBLK
;
1821 char *end1
= NULL
, *end2
= NULL
;
1823 major
= strtoul(argv
[3], &end1
, 0);
1824 minor
= strtoul(argv
[4], &end2
, 0);
1825 if (major
> 65535 || minor
> 65535 ||
1826 (end1
&& *end1
) || (end2
&& *end2
))
1833 st
.st_rdev
= makedev(major
, minor
);
1834 retval
= do_mknod_internal(current_fs
, cwd
, argv
[1],
1835 st
.st_mode
, st
.st_rdev
);
1837 com_err(argv
[0], retval
, 0);
1840 void do_mkdir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1841 void *infop
EXT2FS_ATTR((unused
)))
1845 if (common_args_process(argc
, argv
, 2, 2, "mkdir",
1846 "<filename>", CHECK_FS_RW
))
1849 retval
= do_mkdir_internal(current_fs
, cwd
, argv
[1], root
);
1851 com_err(argv
[0], retval
, 0);
1855 static int release_blocks_proc(ext2_filsys fs
, blk64_t
*blocknr
,
1856 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1857 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1858 int ref_offset
EXT2FS_ATTR((unused
)),
1861 blk64_t block
= *blocknr
;
1862 blk64_t
*last_cluster
= (blk64_t
*)private;
1863 blk64_t cluster
= EXT2FS_B2C(fs
, block
);
1865 if (cluster
== *last_cluster
)
1868 *last_cluster
= cluster
;
1870 ext2fs_block_alloc_stats2(fs
, block
, -1);
1874 static void kill_file_by_inode(ext2_ino_t inode
)
1876 struct ext2_inode inode_buf
;
1878 if (debugfs_read_inode(inode
, &inode_buf
, 0))
1880 ext2fs_set_dtime(current_fs
, &inode_buf
);
1881 if (debugfs_write_inode(inode
, &inode_buf
, 0))
1883 if (ext2fs_inode_has_valid_blocks2(current_fs
, &inode_buf
)) {
1884 blk64_t last_cluster
= 0;
1885 ext2fs_block_iterate3(current_fs
, inode
, BLOCK_FLAG_READ_ONLY
,
1886 NULL
, release_blocks_proc
, &last_cluster
);
1889 ext2fs_inode_alloc_stats2(current_fs
, inode
, -1,
1890 LINUX_S_ISDIR(inode_buf
.i_mode
));
1894 void do_kill_file(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1895 void *infop
EXT2FS_ATTR((unused
)))
1897 ext2_ino_t inode_num
;
1899 if (common_inode_args_process(argc
, argv
, &inode_num
, CHECK_FS_RW
))
1902 kill_file_by_inode(inode_num
);
1905 void do_rm(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1906 void *infop
EXT2FS_ATTR((unused
)))
1909 ext2_ino_t inode_num
;
1910 struct ext2_inode inode
;
1912 if (common_args_process(argc
, argv
, 2, 2, "rm",
1913 "<filename>", CHECK_FS_RW
))
1916 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1918 com_err(argv
[0], retval
, "while trying to resolve filename");
1922 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1925 if (LINUX_S_ISDIR(inode
.i_mode
)) {
1926 com_err(argv
[0], 0, "file is a directory");
1930 --inode
.i_links_count
;
1931 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
1934 unlink_file_by_name(argv
[1]);
1935 if (inode
.i_links_count
== 0)
1936 kill_file_by_inode(inode_num
);
1944 static int rmdir_proc(ext2_ino_t dir
EXT2FS_ATTR((unused
)),
1945 int entry
EXT2FS_ATTR((unused
)),
1946 struct ext2_dir_entry
*dirent
,
1947 int offset
EXT2FS_ATTR((unused
)),
1948 int blocksize
EXT2FS_ATTR((unused
)),
1949 char *buf
EXT2FS_ATTR((unused
)),
1952 struct rd_struct
*rds
= (struct rd_struct
*) private;
1954 if (dirent
->inode
== 0)
1956 if ((ext2fs_dirent_name_len(dirent
) == 1) && (dirent
->name
[0] == '.'))
1958 if ((ext2fs_dirent_name_len(dirent
) == 2) && (dirent
->name
[0] == '.') &&
1959 (dirent
->name
[1] == '.')) {
1960 rds
->parent
= dirent
->inode
;
1967 void do_rmdir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
1968 void *infop
EXT2FS_ATTR((unused
)))
1971 ext2_ino_t inode_num
;
1972 struct ext2_inode inode
;
1973 struct rd_struct rds
;
1975 if (common_args_process(argc
, argv
, 2, 2, "rmdir",
1976 "<filename>", CHECK_FS_RW
))
1979 retval
= ext2fs_namei(current_fs
, root
, cwd
, argv
[1], &inode_num
);
1981 com_err(argv
[0], retval
, "while trying to resolve filename");
1985 if (debugfs_read_inode(inode_num
, &inode
, argv
[0]))
1988 if (!LINUX_S_ISDIR(inode
.i_mode
)) {
1989 com_err(argv
[0], 0, "file is not a directory");
1996 retval
= ext2fs_dir_iterate2(current_fs
, inode_num
, 0,
1997 0, rmdir_proc
, &rds
);
1999 com_err(argv
[0], retval
, "while iterating over directory");
2002 if (rds
.empty
== 0) {
2003 com_err(argv
[0], 0, "directory not empty");
2007 inode
.i_links_count
= 0;
2008 if (debugfs_write_inode(inode_num
, &inode
, argv
[0]))
2011 unlink_file_by_name(argv
[1]);
2012 kill_file_by_inode(inode_num
);
2015 if (debugfs_read_inode(rds
.parent
, &inode
, argv
[0]))
2017 if (inode
.i_links_count
> 1)
2018 inode
.i_links_count
--;
2019 if (debugfs_write_inode(rds
.parent
, &inode
, argv
[0]))
2023 #endif /* READ_ONLY */
2025 void do_show_debugfs_params(int argc
EXT2FS_ATTR((unused
)),
2026 ss_argv_t argv
EXT2FS_ATTR((unused
)),
2027 int sci_idx
EXT2FS_ATTR((unused
)),
2028 void *infop
EXT2FS_ATTR((unused
)))
2031 printf("Open mode: read-%s\n",
2032 current_fs
->flags
& EXT2_FLAG_RW
? "write" : "only");
2033 printf("Filesystem in use: %s\n",
2034 current_fs
? current_fs
->device_name
: "--none--");
2038 void do_expand_dir(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2039 void *infop
EXT2FS_ATTR((unused
)))
2044 if (common_inode_args_process(argc
, argv
, &inode
, CHECK_FS_RW
))
2047 retval
= ext2fs_expand_dir(current_fs
, inode
);
2049 com_err("ext2fs_expand_dir", retval
, 0);
2053 void do_features(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2054 void *infop
EXT2FS_ATTR((unused
)))
2058 if (check_fs_open(argv
[0]))
2061 if ((argc
!= 1) && check_fs_read_write(argv
[0]))
2063 for (i
=1; i
< argc
; i
++) {
2064 if (e2p_edit_feature(argv
[i
],
2065 ¤t_fs
->super
->s_feature_compat
, 0))
2066 com_err(argv
[0], 0, "Unknown feature: %s\n",
2069 ext2fs_mark_super_dirty(current_fs
);
2071 print_features(current_fs
->super
, stdout
);
2073 #endif /* READ_ONLY */
2075 void do_bmap(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2076 void *infop
EXT2FS_ATTR((unused
)))
2079 blk64_t blk
, pblk
= 0;
2080 int c
, err
, flags
= 0, ret_flags
= 0;
2083 if (check_fs_open(argv
[0]))
2087 while ((c
= getopt (argc
, argv
, "a")) != EOF
) {
2090 flags
|= BMAP_ALLOC
;
2097 if (argc
<= optind
+1) {
2100 "Usage: bmap [-a] <file> logical_blk [physical_blk]");
2104 ino
= string_to_inode(argv
[optind
++]);
2107 err
= strtoblk(argv
[0], argv
[optind
++], "logical block", &blk
);
2111 if (argc
> optind
+1)
2114 if (argc
== optind
+1) {
2115 err
= strtoblk(argv
[0], argv
[optind
++],
2116 "physical block", &pblk
);
2119 if (flags
& BMAP_ALLOC
) {
2120 com_err(0, 0, "Can't set and allocate a block");
2126 errcode
= ext2fs_bmap2(current_fs
, ino
, 0, 0, flags
, blk
,
2129 com_err(argv
[0], errcode
,
2130 "while mapping logical block %llu\n",
2131 (unsigned long long) blk
);
2134 printf("%llu", (unsigned long long) pblk
);
2135 if (ret_flags
& BMAP_RET_UNINIT
)
2136 fputs(" (uninit)", stdout
);
2137 fputc('\n', stdout
);
2140 void do_imap(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2141 void *infop
EXT2FS_ATTR((unused
)))
2144 unsigned long group
, block
, block_nr
, offset
;
2146 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2149 ino
= string_to_inode(argv
[1]);
2153 group
= (ino
- 1) / EXT2_INODES_PER_GROUP(current_fs
->super
);
2154 offset
= ((ino
- 1) % EXT2_INODES_PER_GROUP(current_fs
->super
)) *
2155 EXT2_INODE_SIZE(current_fs
->super
);
2156 block
= offset
>> EXT2_BLOCK_SIZE_BITS(current_fs
->super
);
2157 if (!ext2fs_inode_table_loc(current_fs
, (unsigned)group
)) {
2158 com_err(argv
[0], 0, "Inode table for group %lu is missing\n",
2162 block_nr
= ext2fs_inode_table_loc(current_fs
, (unsigned)group
) +
2164 offset
&= (EXT2_BLOCK_SIZE(current_fs
->super
) - 1);
2166 printf("Inode %u is part of block group %lu\n"
2167 "\tlocated at block %lu, offset 0x%04lx\n", ino
, group
,
2172 void do_idump(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2173 void *infop
EXT2FS_ATTR((unused
)))
2175 struct ext2_inode_large
*inode
;
2179 unsigned int isize
, size
, offset
= 0;
2183 while ((c
= getopt (argc
, argv
, "bex")) != EOF
) {
2184 if (mode
|| c
== '?') {
2186 "Usage: inode_dump [-b]|[-e] <file>");
2191 if (optind
!= argc
-1)
2194 if (check_fs_open(argv
[0]))
2197 ino
= string_to_inode(argv
[optind
]);
2201 isize
= EXT2_INODE_SIZE(current_fs
->super
);
2202 err
= ext2fs_get_mem(isize
, &buf
);
2204 com_err(argv
[0], err
, "while allocating memory");
2208 err
= ext2fs_read_inode_full(current_fs
, ino
,
2209 (struct ext2_inode
*)buf
, isize
);
2211 com_err(argv
[0], err
, "while reading inode %u", ino
);
2215 inode
= (struct ext2_inode_large
*) buf
;
2219 offset
= ((char *) (&inode
->i_block
)) - ((char *) buf
);
2220 size
= sizeof(inode
->i_block
);
2224 if (size
<= EXT2_GOOD_OLD_INODE_SIZE
) {
2225 com_err(argv
[0], 0, "No extra space in inode");
2228 offset
= EXT2_GOOD_OLD_INODE_SIZE
+ inode
->i_extra_isize
;
2235 raw_inode_xattr_dump(stdout
, buf
+ offset
, size
);
2237 do_byte_hexdump(stdout
, buf
+ offset
, size
);
2239 ext2fs_free_mem(&buf
);
2243 void do_set_current_time(int argc
, ss_argv_t argv
,
2244 int sci_idx
EXT2FS_ATTR((unused
)),
2245 void *infop
EXT2FS_ATTR((unused
)))
2249 if (common_args_process(argc
, argv
, 2, 2, argv
[0],
2253 now
= string_to_time(argv
[1]);
2255 com_err(argv
[0], 0, "Couldn't parse argument as a time: %s\n",
2260 printf("Setting current time to %s\n", time_to_string(now
));
2261 current_fs
->now
= now
;
2264 #endif /* READ_ONLY */
2266 static int find_supp_feature(__u32
*supp
, int feature_type
, char *name
)
2268 int compat
, bit
, ret
;
2269 unsigned int feature_mask
;
2272 if (feature_type
== E2P_FS_FEATURE
)
2273 ret
= e2p_string2feature(name
, &compat
, &feature_mask
);
2275 ret
= e2p_jrnl_string2feature(name
, &compat
,
2280 if (!(supp
[compat
] & feature_mask
))
2283 for (compat
= 0; compat
< 3; compat
++) {
2284 for (bit
= 0, feature_mask
= 1; bit
< 32;
2285 bit
++, feature_mask
<<= 1) {
2286 if (supp
[compat
] & feature_mask
) {
2287 if (feature_type
== E2P_FS_FEATURE
)
2288 fprintf(stdout
, " %s",
2289 e2p_feature2string(compat
,
2292 fprintf(stdout
, " %s",
2293 e2p_jrnl_feature2string(compat
,
2298 fprintf(stdout
, "\n");
2304 void do_supported_features(int argc
, ss_argv_t argv
,
2305 int sci_idx
EXT2FS_ATTR((unused
)),
2306 void *infop
EXT2FS_ATTR((unused
)))
2309 __u32 supp
[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP
,
2310 EXT2_LIB_FEATURE_INCOMPAT_SUPP
,
2311 EXT2_LIB_FEATURE_RO_COMPAT_SUPP
};
2312 __u32 jrnl_supp
[3] = { JBD2_KNOWN_COMPAT_FEATURES
,
2313 JBD2_KNOWN_INCOMPAT_FEATURES
,
2314 JBD2_KNOWN_ROCOMPAT_FEATURES
};
2317 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, argv
[1]);
2319 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
,
2323 com_err(argv
[0], 0, "Unknown feature: %s\n", argv
[1]);
2325 fprintf(stdout
, "Supported feature: %s\n", argv
[1]);
2327 fprintf(stdout
, "Supported features:");
2328 ret
= find_supp_feature(supp
, E2P_FS_FEATURE
, NULL
);
2329 ret
= find_supp_feature(jrnl_supp
, E2P_JOURNAL_FEATURE
, NULL
);
2334 void do_punch(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2335 void *infop
EXT2FS_ATTR((unused
)))
2342 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2343 "<file> start_blk [end_blk]",
2344 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2347 ino
= string_to_inode(argv
[1]);
2350 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2354 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2360 errcode
= ext2fs_punch(current_fs
, ino
, 0, 0, start
, end
);
2363 com_err(argv
[0], errcode
,
2364 "while truncating inode %u from %llu to %llu\n", ino
,
2365 (unsigned long long) start
, (unsigned long long) end
);
2370 void do_fallocate(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2371 void *infop
EXT2FS_ATTR((unused
)))
2378 if (common_args_process(argc
, argv
, 3, 4, argv
[0],
2379 "<file> start_blk [end_blk]",
2380 CHECK_FS_RW
| CHECK_FS_BITMAPS
))
2383 ino
= string_to_inode(argv
[1]);
2386 err
= strtoblk(argv
[0], argv
[2], "logical block", &start
);
2390 err
= strtoblk(argv
[0], argv
[3], "logical block", &end
);
2396 errcode
= ext2fs_fallocate(current_fs
, EXT2_FALLOCATE_INIT_BEYOND_EOF
,
2397 ino
, NULL
, ~0ULL, start
, end
- start
+ 1);
2400 com_err(argv
[0], errcode
,
2401 "while fallocating inode %u from %llu to %llu\n", ino
,
2402 (unsigned long long) start
, (unsigned long long) end
);
2407 void do_symlink(int argc
, ss_argv_t argv
, int sci_idx
EXT2FS_ATTR((unused
)),
2408 void *infop
EXT2FS_ATTR((unused
)))
2412 if (common_args_process(argc
, argv
, 3, 3, "symlink",
2413 "<filename> <target>", CHECK_FS_RW
))
2416 retval
= do_symlink_internal(current_fs
, cwd
, argv
[1], argv
[2], root
);
2418 com_err(argv
[0], retval
, 0);
2421 #endif /* READ_ONLY */
2424 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)), ss_argv_t argv
,
2425 int sci_idx
EXT2FS_ATTR((unused
)),
2426 void *infop
EXT2FS_ATTR((unused
)))
2428 struct mmp_struct
*mmp_s
;
2429 unsigned long long mmp_block
;
2431 errcode_t retval
= 0;
2433 if (check_fs_open(argv
[0]))
2438 mmp_block
= strtoull(argv
[1], &end
, 0);
2439 if (end
== argv
[0] || mmp_block
== 0) {
2440 fprintf(stderr
, "%s: invalid MMP block '%s' given\n",
2445 mmp_block
= current_fs
->super
->s_mmp_block
;
2448 if (mmp_block
== 0) {
2449 fprintf(stderr
, "%s: MMP: not active on this filesystem.\n",
2454 if (current_fs
->mmp_buf
== NULL
) {
2455 retval
= ext2fs_get_mem(current_fs
->blocksize
,
2456 ¤t_fs
->mmp_buf
);
2458 com_err(argv
[0], retval
, "allocating MMP buffer.\n");
2463 mmp_s
= current_fs
->mmp_buf
;
2465 retval
= ext2fs_mmp_read(current_fs
, mmp_block
, current_fs
->mmp_buf
);
2467 com_err(argv
[0], retval
, "reading MMP block %llu.\n",
2468 (unsigned long long) mmp_block
);
2472 t
= mmp_s
->mmp_time
;
2473 fprintf(stdout
, "block_number: %llu\n",
2474 (unsigned long long) current_fs
->super
->s_mmp_block
);
2475 fprintf(stdout
, "update_interval: %d\n",
2476 current_fs
->super
->s_mmp_update_interval
);
2477 fprintf(stdout
, "check_interval: %d\n", mmp_s
->mmp_check_interval
);
2478 fprintf(stdout
, "sequence: %08x\n", mmp_s
->mmp_seq
);
2479 fprintf(stdout
, "time: %llu -- %s",
2480 (unsigned long long) mmp_s
->mmp_time
, ctime(&t
));
2481 fprintf(stdout
, "node_name: %.*s\n",
2482 EXT2_LEN_STR(mmp_s
->mmp_nodename
));
2483 fprintf(stdout
, "device_name: %.*s\n",
2484 EXT2_LEN_STR(mmp_s
->mmp_bdevname
));
2485 fprintf(stdout
, "magic: 0x%x\n", mmp_s
->mmp_magic
);
2486 fprintf(stdout
, "checksum: 0x%08x\n", mmp_s
->mmp_checksum
);
2489 void do_dump_mmp(int argc
EXT2FS_ATTR((unused
)),
2490 ss_argv_t argv
EXT2FS_ATTR((unused
)),
2491 int sci_idx
EXT2FS_ATTR((unused
)),
2492 void *infop
EXT2FS_ATTR((unused
)))
2494 fprintf(stdout
, "MMP is unsupported, please recompile with "
2499 static int source_file(const char *cmd_file
, int ss_idx
)
2504 int exit_status
= 0;
2507 if (strcmp(cmd_file
, "-") == 0)
2510 f
= fopen(cmd_file
, "r");
2518 setbuf(stdout
, NULL
);
2519 setbuf(stderr
, NULL
);
2521 if (fgets(buf
, sizeof(buf
), f
) == NULL
)
2523 if (buf
[0] == '#') {
2527 cp
= strchr(buf
, '\n');
2530 cp
= strchr(buf
, '\r');
2533 printf("debugfs: %s\n", buf
);
2534 retval
= ss_execute_line(ss_idx
, buf
);
2536 ss_perror(ss_idx
, retval
, buf
);
2545 int main(int argc
, char **argv
)
2549 "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] "
2550 "[-R request] [-d data_source_device] [-i] [-n] [-D] [-V] ["
2552 "[-w] [-z undo_file] "
2556 int open_flags
= EXT2_FLAG_SOFTSUPP_FEATURES
|
2557 EXT2_FLAG_64BITS
| EXT2_FLAG_THREADS
;
2559 int exit_status
= 0;
2561 blk64_t superblock
= 0;
2562 blk64_t blocksize
= 0;
2563 int catastrophic
= 0;
2564 char *data_filename
= 0;
2566 const char *opt_string
= "nicR:f:b:s:Vd:D";
2568 const char *opt_string
= "niwcR:f:b:s:Vd:Dz:";
2570 char *undo_file
= NULL
;
2571 #ifdef CONFIG_JBD_DEBUG
2575 setlocale(LC_CTYPE
, "");
2577 if (debug_prog_name
== 0)
2579 debug_prog_name
= "rdebugfs";
2581 debug_prog_name
= "debugfs";
2583 add_error_table(&et_ext2_error_table
);
2584 fprintf (stderr
, "%s %s (%s)\n", debug_prog_name
,
2585 E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
2587 #ifdef CONFIG_JBD_DEBUG
2588 jbd_debug
= ss_safe_getenv("DEBUGFS_JBD_DEBUG");
2590 int res
= sscanf(jbd_debug
, "%d", &journal_enable_debug
);
2594 "DEBUGFS_JBD_DEBUG \"%s\" not an integer\n\n",
2600 while ((c
= getopt (argc
, argv
, opt_string
)) != EOF
) {
2609 data_filename
= optarg
;
2612 open_flags
|= EXT2_FLAG_IMAGE_FILE
;
2615 open_flags
|= EXT2_FLAG_IGNORE_CSUM_ERRORS
;
2619 open_flags
|= EXT2_FLAG_RW
;
2623 open_flags
|= EXT2_FLAG_DIRECT_IO
;
2626 blocksize
= parse_ulong(optarg
, argv
[0],
2630 retval
= strtoblk(argv
[0], optarg
,
2631 "superblock block number",
2640 /* Print version number and exit */
2641 fprintf(stderr
, "\tUsing %s\n",
2642 error_message(EXT2_ET_BASE
));
2650 com_err(argv
[0], 0, usage
, debug_prog_name
);
2655 open_filesystem(argv
[optind
], open_flags
,
2656 superblock
, blocksize
, catastrophic
,
2657 data_filename
, undo_file
);
2659 ss_sci_idx
= ss_create_invocation(debug_prog_name
, "0.0", (char *) NULL
,
2660 &debug_cmds
, &retval
);
2662 ss_perror(ss_sci_idx
, retval
, "creating invocation");
2665 ss_get_readline(ss_sci_idx
);
2667 (void) ss_add_request_table(ss_sci_idx
, &ss_std_requests
, 1, &retval
);
2669 ss_perror(ss_sci_idx
, retval
, "adding standard requests");
2673 ss_add_request_table(ss_sci_idx
, extra_cmds
, 1, &retval
);
2675 ss_perror(ss_sci_idx
, retval
, "adding extra requests");
2680 retval
= ss_execute_line(ss_sci_idx
, request
);
2682 ss_perror(ss_sci_idx
, retval
, request
);
2685 } else if (cmd_file
) {
2686 exit_status
= source_file(cmd_file
, ss_sci_idx
);
2688 ss_listen(ss_sci_idx
);
2691 ss_delete_invocation(ss_sci_idx
);
2696 remove_error_table(&et_ext2_error_table
);