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>
27 #include <sys/types.h>
30 #include "et/com_err.h"
33 #include "uuid/uuid.h"
36 #include <ext2fs/ext2_ext_attr.h>
38 #include "../version.h"
41 extern ss_request_table debug_cmds;
42 ss_request_table *extra_cmds;
43 const char *debug_prog_name;
45 ext2_filsys current_fs = NULL;
48 static void open_filesystem(char *device, int open_flags, blk_t superblock,
49 blk_t blocksize, int catastrophic,
53 io_channel data_io = 0;
55 if (superblock != 0 && blocksize == 0) {
56 com_err(device, 0, "if you specify the superblock, you must also specify the block size");
62 if ((open_flags & EXT2_FLAG_IMAGE_FILE) == 0) {
64 "The -d option is only valid when reading an e2image file");
68 retval = unix_io_manager->open(data_filename, 0, &data_io);
70 com_err(data_filename, 0, "while opening data source");
76 if (catastrophic && (open_flags & EXT2_FLAG_RW)) {
78 "opening read-only because of catastrophic mode");
79 open_flags &= ~EXT2_FLAG_RW;
82 retval = ext2fs_open(device, open_flags, superblock, blocksize,
83 unix_io_manager, ¤t_fs);
85 com_err(device, retval, "while opening filesystem");
91 com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps");
93 retval = ext2fs_read_inode_bitmap(current_fs);
95 com_err(device, retval, "while reading inode bitmap");
98 retval = ext2fs_read_block_bitmap(current_fs);
100 com_err(device, retval, "while reading block bitmap");
106 retval = ext2fs_set_data_io(current_fs, data_io);
108 com_err(device, retval,
109 "while setting data source");
114 root = cwd = EXT2_ROOT_INO;
118 retval = ext2fs_close(current_fs);
120 com_err(device, retval, "while trying to close filesystem");
124 void do_open_filesys(int argc, char **argv)
127 int catastrophic = 0;
128 blk_t superblock = 0;
130 int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES;
131 char *data_filename = 0;
134 while ((c = getopt (argc, argv, "iwfecb:s:d:")) != EOF) {
137 open_flags |= EXT2_FLAG_IMAGE_FILE;
140 open_flags |= EXT2_FLAG_RW;
143 open_flags |= EXT2_FLAG_FORCE;
146 open_flags |= EXT2_FLAG_EXCLUSIVE;
152 data_filename = optarg;
155 blocksize = parse_ulong(optarg, argv[0],
161 superblock = parse_ulong(optarg, argv[0],
162 "superblock number", &err);
170 if (optind != argc-1) {
173 if (check_fs_not_open(argv[0]))
175 open_filesystem(argv[optind], open_flags,
176 superblock, blocksize, catastrophic,
181 fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] "
182 "[-c] [-w] <device>\n", argv[0]);
185 void do_lcd(int argc, char **argv)
188 com_err(argv[0], 0, "Usage: %s %s", argv[0], "<native dir>");
192 if (chdir(argv[1]) == -1) {
193 com_err(argv[0], errno,
194 "while trying to change native directory to %s",
200 static void close_filesystem(NOARGS)
204 if (current_fs->flags & EXT2_FLAG_IB_DIRTY) {
205 retval = ext2fs_write_inode_bitmap(current_fs);
207 com_err("ext2fs_write_inode_bitmap", retval, 0);
209 if (current_fs->flags & EXT2_FLAG_BB_DIRTY) {
210 retval = ext2fs_write_block_bitmap(current_fs);
212 com_err("ext2fs_write_block_bitmap", retval, 0);
214 retval = ext2fs_close(current_fs);
216 com_err("ext2fs_close", retval, 0);
221 void do_close_filesys(int argc, char **argv)
223 if (common_args_process(argc, argv, 1, 1, "close_filesys", "", 0))
228 void do_init_filesys(int argc, char **argv)
230 struct ext2_super_block param;
234 if (common_args_process(argc, argv, 3, 3, "initialize",
235 "<device> <blocksize>", CHECK_FS_NOTOPEN))
238 memset(¶m, 0, sizeof(struct ext2_super_block));
239 param.s_blocks_count = parse_ulong(argv[2], argv[0],
240 "blocks count", &err);
243 retval = ext2fs_initialize(argv[1], 0, ¶m,
244 unix_io_manager, ¤t_fs);
246 com_err(argv[1], retval, "while initializing filesystem");
250 root = cwd = EXT2_ROOT_INO;
254 static void print_features(struct ext2_super_block * s, FILE *f)
257 __u32 *mask = &s->s_feature_compat, m;
259 fputs("Filesystem features:", f);
260 for (i=0; i <3; i++,mask++) {
261 for (j=0,m=1; j < 32; j++, m<<=1) {
263 fprintf(f, " %s", e2p_feature2string(i, m));
273 static void print_bg_opts(struct ext2_group_desc *gdp, int mask,
274 const char *str, int *first, FILE *f)
276 if (gdp->bg_flags & mask) {
286 void do_show_super_stats(int argc, char *argv[])
290 struct ext2_group_desc *gdp;
291 int c, header_only = 0;
292 int numdirs = 0, first, gdt_csum;
294 gdt_csum = EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super,
295 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
298 while ((c = getopt (argc, argv, "h")) != EOF) {
307 if (optind != argc) {
310 if (check_fs_open(argv[0]))
314 list_super2(current_fs->super, out);
315 for (i=0; i < current_fs->group_desc_count; i++)
316 numdirs += current_fs->group_desc[i].bg_used_dirs_count;
317 fprintf(out, "Directories: %d\n", numdirs);
324 gdp = ¤t_fs->group_desc[0];
325 for (i = 0; i < current_fs->group_desc_count; i++, gdp++) {
326 fprintf(out, " Group %2d: block bitmap at %u, "
327 "inode bitmap at %u, "
328 "inode table at %u\n"
332 i, gdp->bg_block_bitmap,
333 gdp->bg_inode_bitmap, gdp->bg_inode_table,
334 gdp->bg_free_blocks_count,
335 gdp->bg_free_blocks_count != 1 ? "blocks" : "block",
336 gdp->bg_free_inodes_count,
337 gdp->bg_free_inodes_count != 1 ? "inodes" : "inode",
338 gdp->bg_used_dirs_count,
339 gdp->bg_used_dirs_count != 1 ? "directories"
340 : "directory", gdt_csum ? ", " : "\n");
342 fprintf(out, "%d unused %s\n",
343 gdp->bg_itable_unused,
344 gdp->bg_itable_unused != 1 ? "inodes":"inode");
346 print_bg_opts(gdp, EXT2_BG_INODE_UNINIT, "Inode not init",
348 print_bg_opts(gdp, EXT2_BG_BLOCK_UNINIT, "Block not init",
351 fprintf(out, "%sChecksum 0x%04x",
352 first ? " [":", ", gdp->bg_checksum);
361 fprintf(stderr, "%s: Usage: show_super [-h]\n", argv[0]);
364 void do_dirty_filesys(int argc EXT2FS_ATTR((unused)),
365 char **argv EXT2FS_ATTR((unused)))
367 if (check_fs_open(argv[0]))
369 if (check_fs_read_write(argv[0]))
372 if (argv[1] && !strcmp(argv[1], "-clean"))
373 current_fs->super->s_state |= EXT2_VALID_FS;
375 current_fs->super->s_state &= ~EXT2_VALID_FS;
376 ext2fs_mark_super_dirty(current_fs);
379 struct list_blocks_struct {
382 blk_t first_block, last_block;
383 e2_blkcnt_t first_bcnt, last_bcnt;
387 static void finish_range(struct list_blocks_struct *lb)
389 if (lb->first_block == 0)
394 fprintf(lb->f, ", ");
395 if (lb->first_block == lb->last_block)
396 fprintf(lb->f, "(%lld):%u",
397 (long long)lb->first_bcnt, lb->first_block);
399 fprintf(lb->f, "(%lld-%lld):%u-%u",
400 (long long)lb->first_bcnt, (long long)lb->last_bcnt,
401 lb->first_block, lb->last_block);
405 static int list_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
406 blk_t *blocknr, e2_blkcnt_t blockcnt,
407 blk_t ref_block EXT2FS_ATTR((unused)),
408 int ref_offset EXT2FS_ATTR((unused)),
411 struct list_blocks_struct *lb = (struct list_blocks_struct *) private;
416 * See if we can add on to the existing range (if it exists)
418 if (lb->first_block &&
419 (lb->last_block+1 == *blocknr) &&
420 (lb->last_bcnt+1 == blockcnt)) {
421 lb->last_block = *blocknr;
422 lb->last_bcnt = blockcnt;
429 lb->first_block = lb->last_block = *blocknr;
430 lb->first_bcnt = lb->last_bcnt = blockcnt;
434 * Not a normal block. Always force a new range.
440 fprintf(lb->f, ", ");
442 fprintf(lb->f, "(IND):%u", *blocknr);
443 else if (blockcnt == -2)
444 fprintf(lb->f, "(DIND):%u", *blocknr);
445 else if (blockcnt == -3)
446 fprintf(lb->f, "(TIND):%u", *blocknr);
450 static void dump_xattr_string(FILE *out, const char *str, int len)
455 /* check: is string "printable enough?" */
456 for (i = 0; i < len; i++)
460 if (printable <= len*7/8)
463 for (i = 0; i < len; i++)
465 fprintf(out, isprint(str[i]) ? "%c" : "\\%03o",
466 (unsigned char)str[i]);
468 fprintf(out, "%02x ", (unsigned char)str[i]);
471 static void internal_dump_inode_extra(FILE *out,
472 const char *prefix EXT2FS_ATTR((unused)),
473 ext2_ino_t inode_num EXT2FS_ATTR((unused)),
474 struct ext2_inode_large *inode)
476 struct ext2_ext_attr_entry *entry;
479 unsigned int storage_size;
481 fprintf(out, "Size of extra inode fields: %u\n", inode->i_extra_isize);
482 if (inode->i_extra_isize > EXT2_INODE_SIZE(current_fs->super) -
483 EXT2_GOOD_OLD_INODE_SIZE) {
484 fprintf(stderr, "invalid inode->i_extra_isize (%u)\n",
485 inode->i_extra_isize);
488 storage_size = EXT2_INODE_SIZE(current_fs->super) -
489 EXT2_GOOD_OLD_INODE_SIZE -
490 inode->i_extra_isize;
491 magic = (__u32 *)((char *)inode + EXT2_GOOD_OLD_INODE_SIZE +
492 inode->i_extra_isize);
493 if (*magic == EXT2_EXT_ATTR_MAGIC) {
494 fprintf(out, "Extended attributes stored in inode body: \n");
495 end = (char *) inode + EXT2_INODE_SIZE(current_fs->super);
496 start = (char *) magic + sizeof(__u32);
497 entry = (struct ext2_ext_attr_entry *) start;
498 while (!EXT2_EXT_IS_LAST_ENTRY(entry)) {
499 struct ext2_ext_attr_entry *next =
500 EXT2_EXT_ATTR_NEXT(entry);
501 if (entry->e_value_size > storage_size ||
502 (char *) next >= end) {
503 fprintf(out, "invalid EA entry in inode\n");
507 dump_xattr_string(out, EXT2_EXT_ATTR_NAME(entry),
509 fprintf(out, " = \"");
510 dump_xattr_string(out, start + entry->e_value_offs,
511 entry->e_value_size);
512 fprintf(out, "\" (%u)\n", entry->e_value_size);
518 static void dump_blocks(FILE *f, const char *prefix, ext2_ino_t inode)
520 struct list_blocks_struct lb;
522 fprintf(f, "%sBLOCKS:\n%s", prefix, prefix);
527 ext2fs_block_iterate2(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
528 list_blocks_proc, (void *)&lb);
531 fprintf(f, "\n%sTOTAL: %lld\n", prefix, (long long)lb.total);
536 void internal_dump_inode(FILE *out, const char *prefix,
537 ext2_ino_t inode_num, struct ext2_inode *inode,
542 int os = current_fs->super->s_creator_os;
543 struct ext2_inode_large *large_inode;
544 int is_large_inode = 0;
546 if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
548 large_inode = (struct ext2_inode_large *) inode;
550 if (LINUX_S_ISDIR(inode->i_mode)) i_type = "directory";
551 else if (LINUX_S_ISREG(inode->i_mode)) i_type = "regular";
552 else if (LINUX_S_ISLNK(inode->i_mode)) i_type = "symlink";
553 else if (LINUX_S_ISBLK(inode->i_mode)) i_type = "block special";
554 else if (LINUX_S_ISCHR(inode->i_mode)) i_type = "character special";
555 else if (LINUX_S_ISFIFO(inode->i_mode)) i_type = "FIFO";
556 else if (LINUX_S_ISSOCK(inode->i_mode)) i_type = "socket";
557 else i_type = "bad type";
558 fprintf(out, "%sInode: %u Type: %s ", prefix, inode_num, i_type);
559 fprintf(out, "%sMode: %04o Flags: 0x%x\n",
560 prefix, inode->i_mode & 0777, inode->i_flags);
561 if (is_large_inode && large_inode->i_extra_isize >= 24) {
562 fprintf(out, "%sGeneration: %u Version: 0x%08x:%08x\n",
563 prefix, inode->i_generation, large_inode->i_version_hi,
564 inode->osd1.linux1.l_i_version);
566 fprintf(out, "%sGeneration: %u Version: 0x%08x\n", prefix,
567 inode->i_generation, inode->osd1.linux1.l_i_version);
569 fprintf(out, "%sUser: %5d Group: %5d Size: ",
570 prefix, inode_uid(*inode), inode_gid(*inode));
571 if (LINUX_S_ISREG(inode->i_mode)) {
572 unsigned long long i_size = (inode->i_size |
573 ((unsigned long long)inode->i_size_high << 32));
575 fprintf(out, "%llu\n", i_size);
577 fprintf(out, "%d\n", inode->i_size);
578 if (os == EXT2_OS_HURD)
580 "%sFile ACL: %d Directory ACL: %d Translator: %d\n",
582 inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0,
583 inode->osd1.hurd1.h_i_translator);
585 fprintf(out, "%sFile ACL: %d Directory ACL: %d\n",
587 inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0);
588 if (os == EXT2_OS_LINUX)
589 fprintf(out, "%sLinks: %d Blockcount: %llu\n",
590 prefix, inode->i_links_count,
591 (((unsigned long long)
592 inode->osd2.linux2.l_i_blocks_hi << 32)) +
595 fprintf(out, "%sLinks: %d Blockcount: %u\n",
596 prefix, inode->i_links_count, inode->i_blocks);
599 frag = inode->osd2.hurd2.h_i_frag;
600 fsize = inode->osd2.hurd2.h_i_fsize;
605 fprintf(out, "%sFragment: Address: %d Number: %d Size: %d\n",
606 prefix, inode->i_faddr, frag, fsize);
607 if (is_large_inode && large_inode->i_extra_isize >= 24) {
608 fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix,
609 inode->i_ctime, large_inode->i_ctime_extra,
610 time_to_string(inode->i_ctime));
611 fprintf(out, "%s atime: 0x%08x:%08x -- %s", prefix,
612 inode->i_atime, large_inode->i_atime_extra,
613 time_to_string(inode->i_atime));
614 fprintf(out, "%s mtime: 0x%08x:%08x -- %s", prefix,
615 inode->i_mtime, large_inode->i_mtime_extra,
616 time_to_string(inode->i_mtime));
617 fprintf(out, "%scrtime: 0x%08x:%08x -- %s", prefix,
618 large_inode->i_crtime, large_inode->i_crtime_extra,
619 time_to_string(large_inode->i_crtime));
621 fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime,
622 time_to_string(inode->i_ctime));
623 fprintf(out, "%satime: 0x%08x -- %s", prefix, inode->i_atime,
624 time_to_string(inode->i_atime));
625 fprintf(out, "%smtime: 0x%08x -- %s", prefix, inode->i_mtime,
626 time_to_string(inode->i_mtime));
629 fprintf(out, "%sdtime: 0x%08x -- %s", prefix, inode->i_dtime,
630 time_to_string(inode->i_dtime));
631 if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
632 internal_dump_inode_extra(out, prefix, inode_num,
633 (struct ext2_inode_large *) inode);
634 if (LINUX_S_ISLNK(inode->i_mode) && ext2fs_inode_data_blocks(current_fs,inode) == 0)
635 fprintf(out, "%sFast_link_dest: %.*s\n", prefix,
636 (int) inode->i_size, (char *)inode->i_block);
637 else if (LINUX_S_ISBLK(inode->i_mode) || LINUX_S_ISCHR(inode->i_mode)) {
641 if (inode->i_block[0]) {
642 major = (inode->i_block[0] >> 8) & 255;
643 minor = inode->i_block[0] & 255;
646 major = (inode->i_block[1] & 0xfff00) >> 8;
647 minor = ((inode->i_block[1] & 0xff) |
648 ((inode->i_block[1] >> 12) & 0xfff00));
649 devnote = "(New-style) ";
651 fprintf(out, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n",
652 devnote, major, minor, major, minor);
654 else if (do_dump_blocks)
655 dump_blocks(out, prefix, inode_num);
658 static void dump_inode(ext2_ino_t inode_num, struct ext2_inode *inode)
663 internal_dump_inode(out, "", inode_num, inode, 1);
667 void do_stat(int argc, char *argv[])
670 struct ext2_inode * inode_buf;
672 if (check_fs_open(argv[0]))
675 inode_buf = (struct ext2_inode *)
676 malloc(EXT2_INODE_SIZE(current_fs->super));
678 fprintf(stderr, "do_stat: can't allocate buffer\n");
682 if (common_inode_args_process(argc, argv, &inode, 0)) {
687 if (debugfs_read_inode_full(inode, inode_buf, argv[0],
688 EXT2_INODE_SIZE(current_fs->super))) {
693 dump_inode(inode, inode_buf);
698 void do_chroot(int argc, char *argv[])
703 if (common_inode_args_process(argc, argv, &inode, 0))
706 retval = ext2fs_check_directory(current_fs, inode);
708 com_err(argv[1], retval, 0);
714 void do_clri(int argc, char *argv[])
717 struct ext2_inode inode_buf;
719 if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW))
722 if (debugfs_read_inode(inode, &inode_buf, argv[0]))
724 memset(&inode_buf, 0, sizeof(inode_buf));
725 if (debugfs_write_inode(inode, &inode_buf, argv[0]))
729 void do_freei(int argc, char *argv[])
733 if (common_inode_args_process(argc, argv, &inode,
734 CHECK_FS_RW | CHECK_FS_BITMAPS))
737 if (!ext2fs_test_inode_bitmap(current_fs->inode_map,inode))
738 com_err(argv[0], 0, "Warning: inode already clear");
739 ext2fs_unmark_inode_bitmap(current_fs->inode_map,inode);
740 ext2fs_mark_ib_dirty(current_fs);
743 void do_seti(int argc, char *argv[])
747 if (common_inode_args_process(argc, argv, &inode,
748 CHECK_FS_RW | CHECK_FS_BITMAPS))
751 if (ext2fs_test_inode_bitmap(current_fs->inode_map,inode))
752 com_err(argv[0], 0, "Warning: inode already set");
753 ext2fs_mark_inode_bitmap(current_fs->inode_map,inode);
754 ext2fs_mark_ib_dirty(current_fs);
757 void do_testi(int argc, char *argv[])
761 if (common_inode_args_process(argc, argv, &inode, CHECK_FS_BITMAPS))
764 if (ext2fs_test_inode_bitmap(current_fs->inode_map,inode))
765 printf("Inode %u is marked in use\n", inode);
767 printf("Inode %u is not in use\n", inode);
770 void do_freeb(int argc, char *argv[])
775 if (common_block_args_process(argc, argv, &block, &count))
777 if (check_fs_read_write(argv[0]))
779 while (count-- > 0) {
780 if (!ext2fs_test_block_bitmap(current_fs->block_map,block))
781 com_err(argv[0], 0, "Warning: block %u already clear",
783 ext2fs_unmark_block_bitmap(current_fs->block_map,block);
786 ext2fs_mark_bb_dirty(current_fs);
789 void do_setb(int argc, char *argv[])
794 if (common_block_args_process(argc, argv, &block, &count))
796 if (check_fs_read_write(argv[0]))
798 while (count-- > 0) {
799 if (ext2fs_test_block_bitmap(current_fs->block_map,block))
800 com_err(argv[0], 0, "Warning: block %u already set",
802 ext2fs_mark_block_bitmap(current_fs->block_map,block);
805 ext2fs_mark_bb_dirty(current_fs);
808 void do_testb(int argc, char *argv[])
813 if (common_block_args_process(argc, argv, &block, &count))
815 while (count-- > 0) {
816 if (ext2fs_test_block_bitmap(current_fs->block_map,block))
817 printf("Block %u marked in use\n", block);
819 printf("Block %u not in use\n", block);
824 static void modify_u8(char *com, const char *prompt,
825 const char *format, __u8 *val)
831 sprintf(buf, format, *val);
832 printf("%30s [%s] ", prompt, buf);
833 if (!fgets(buf, sizeof(buf), stdin))
835 if (buf[strlen (buf) - 1] == '\n')
836 buf[strlen (buf) - 1] = '\0';
839 v = strtoul(buf, &tmp, 0);
841 com_err(com, 0, "Bad value - %s", buf);
846 static void modify_u16(char *com, const char *prompt,
847 const char *format, __u16 *val)
853 sprintf(buf, format, *val);
854 printf("%30s [%s] ", prompt, buf);
855 if (!fgets(buf, sizeof(buf), stdin))
857 if (buf[strlen (buf) - 1] == '\n')
858 buf[strlen (buf) - 1] = '\0';
861 v = strtoul(buf, &tmp, 0);
863 com_err(com, 0, "Bad value - %s", buf);
868 static void modify_u32(char *com, const char *prompt,
869 const char *format, __u32 *val)
875 sprintf(buf, format, *val);
876 printf("%30s [%s] ", prompt, buf);
877 if (!fgets(buf, sizeof(buf), stdin))
879 if (buf[strlen (buf) - 1] == '\n')
880 buf[strlen (buf) - 1] = '\0';
883 v = strtoul(buf, &tmp, 0);
885 com_err(com, 0, "Bad value - %s", buf);
891 void do_modify_inode(int argc, char *argv[])
893 struct ext2_inode inode;
894 ext2_ino_t inode_num;
896 unsigned char *frag, *fsize;
899 const char *hex_format = "0x%x";
900 const char *octal_format = "0%o";
901 const char *decimal_format = "%d";
902 const char *unsignedlong_format = "%lu";
904 if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW))
907 os = current_fs->super->s_creator_os;
909 if (debugfs_read_inode(inode_num, &inode, argv[1]))
912 modify_u16(argv[0], "Mode", octal_format, &inode.i_mode);
913 modify_u16(argv[0], "User ID", decimal_format, &inode.i_uid);
914 modify_u16(argv[0], "Group ID", decimal_format, &inode.i_gid);
915 modify_u32(argv[0], "Size", unsignedlong_format, &inode.i_size);
916 modify_u32(argv[0], "Creation time", decimal_format, &inode.i_ctime);
917 modify_u32(argv[0], "Modification time", decimal_format, &inode.i_mtime);
918 modify_u32(argv[0], "Access time", decimal_format, &inode.i_atime);
919 modify_u32(argv[0], "Deletion time", decimal_format, &inode.i_dtime);
920 modify_u16(argv[0], "Link count", decimal_format, &inode.i_links_count);
921 if (os == EXT2_OS_LINUX)
922 modify_u16(argv[0], "Block count high", unsignedlong_format,
923 &inode.osd2.linux2.l_i_blocks_hi);
924 modify_u32(argv[0], "Block count", unsignedlong_format, &inode.i_blocks);
925 modify_u32(argv[0], "File flags", hex_format, &inode.i_flags);
926 modify_u32(argv[0], "Generation", hex_format, &inode.i_generation);
928 modify_u32(argv[0], "Reserved1", decimal_format, &inode.i_reserved1);
930 modify_u32(argv[0], "File acl", decimal_format, &inode.i_file_acl);
931 if (LINUX_S_ISDIR(inode.i_mode))
932 modify_u32(argv[0], "Directory acl", decimal_format, &inode.i_dir_acl);
934 modify_u32(argv[0], "High 32bits of size", decimal_format, &inode.i_size_high);
936 if (os == EXT2_OS_HURD)
937 modify_u32(argv[0], "Translator Block",
938 decimal_format, &inode.osd1.hurd1.h_i_translator);
940 modify_u32(argv[0], "Fragment address", decimal_format, &inode.i_faddr);
943 frag = &inode.osd2.hurd2.h_i_frag;
944 fsize = &inode.osd2.hurd2.h_i_fsize;
950 modify_u8(argv[0], "Fragment number", decimal_format, frag);
952 modify_u8(argv[0], "Fragment size", decimal_format, fsize);
954 for (i=0; i < EXT2_NDIR_BLOCKS; i++) {
955 sprintf(buf, "Direct Block #%d", i);
956 modify_u32(argv[0], buf, decimal_format, &inode.i_block[i]);
958 modify_u32(argv[0], "Indirect Block", decimal_format,
959 &inode.i_block[EXT2_IND_BLOCK]);
960 modify_u32(argv[0], "Double Indirect Block", decimal_format,
961 &inode.i_block[EXT2_DIND_BLOCK]);
962 modify_u32(argv[0], "Triple Indirect Block", decimal_format,
963 &inode.i_block[EXT2_TIND_BLOCK]);
964 if (debugfs_write_inode(inode_num, &inode, argv[1]))
968 void do_change_working_dir(int argc, char *argv[])
973 if (common_inode_args_process(argc, argv, &inode, 0))
976 retval = ext2fs_check_directory(current_fs, inode);
978 com_err(argv[1], retval, 0);
985 void do_print_working_directory(int argc, char *argv[])
988 char *pathname = NULL;
990 if (common_args_process(argc, argv, 1, 1,
991 "print_working_directory", "", 0))
994 retval = ext2fs_get_pathname(current_fs, cwd, 0, &pathname);
996 com_err(argv[0], retval,
997 "while trying to get pathname of cwd");
999 printf("[pwd] INODE: %6u PATH: %s\n",
1000 cwd, pathname ? pathname : "NULL");
1005 retval = ext2fs_get_pathname(current_fs, root, 0, &pathname);
1007 com_err(argv[0], retval,
1008 "while trying to get pathname of root");
1010 printf("[root] INODE: %6u PATH: %s\n",
1011 root, pathname ? pathname : "NULL");
1020 * Given a mode, return the ext2 file type
1022 static int ext2_file_type(unsigned int mode)
1024 if (LINUX_S_ISREG(mode))
1025 return EXT2_FT_REG_FILE;
1027 if (LINUX_S_ISDIR(mode))
1030 if (LINUX_S_ISCHR(mode))
1031 return EXT2_FT_CHRDEV;
1033 if (LINUX_S_ISBLK(mode))
1034 return EXT2_FT_BLKDEV;
1036 if (LINUX_S_ISLNK(mode))
1037 return EXT2_FT_SYMLINK;
1039 if (LINUX_S_ISFIFO(mode))
1040 return EXT2_FT_FIFO;
1042 if (LINUX_S_ISSOCK(mode))
1043 return EXT2_FT_SOCK;
1048 static void make_link(char *sourcename, char *destname)
1051 struct ext2_inode inode;
1054 char *dest, *cp, *base_name;
1057 * Get the source inode
1059 ino = string_to_inode(sourcename);
1062 base_name = strrchr(sourcename, '/');
1066 base_name = sourcename;
1068 * Figure out the destination. First see if it exists and is
1071 if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir)))
1075 * OK, it doesn't exist. See if it is
1076 * '<dir>/basename' or 'basename'
1078 cp = strrchr(destname, '/');
1081 dir = string_to_inode(destname);
1091 if (debugfs_read_inode(ino, &inode, sourcename))
1094 retval = ext2fs_link(current_fs, dir, dest, ino,
1095 ext2_file_type(inode.i_mode));
1097 com_err("make_link", retval, 0);
1102 void do_link(int argc, char *argv[])
1104 if (common_args_process(argc, argv, 3, 3, "link",
1105 "<source file> <dest_name>", CHECK_FS_RW))
1108 make_link(argv[1], argv[2]);
1111 static int mark_blocks_proc(ext2_filsys fs, blk_t *blocknr,
1112 int blockcnt EXT2FS_ATTR((unused)),
1113 void *private EXT2FS_ATTR((unused)))
1118 ext2fs_block_alloc_stats(fs, block, +1);
1122 void do_undel(int argc, char *argv[])
1125 struct ext2_inode inode;
1127 if (common_args_process(argc, argv, 2, 3, "undelete",
1128 "<inode_num> [dest_name]",
1129 CHECK_FS_RW | CHECK_FS_BITMAPS))
1132 ino = string_to_inode(argv[1]);
1136 if (debugfs_read_inode(ino, &inode, argv[1]))
1139 if (ext2fs_test_inode_bitmap(current_fs->inode_map, ino)) {
1140 com_err(argv[1], 0, "Inode is not marked as deleted");
1145 * XXX this function doesn't handle changing the links count on the
1146 * parent directory when undeleting a directory.
1148 inode.i_links_count = LINUX_S_ISDIR(inode.i_mode) ? 2 : 1;
1151 if (debugfs_write_inode(ino, &inode, argv[0]))
1154 ext2fs_block_iterate(current_fs, ino, BLOCK_FLAG_READ_ONLY, NULL,
1155 mark_blocks_proc, NULL);
1157 ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0);
1160 make_link(argv[1], argv[2]);
1163 static void unlink_file_by_name(char *filename)
1169 base_name = strrchr(filename, '/');
1171 *base_name++ = '\0';
1172 dir = string_to_inode(filename);
1177 base_name = filename;
1179 retval = ext2fs_unlink(current_fs, dir, base_name, 0, 0);
1181 com_err("unlink_file_by_name", retval, 0);
1185 void do_unlink(int argc, char *argv[])
1187 if (common_args_process(argc, argv, 2, 2, "link",
1188 "<pathname>", CHECK_FS_RW))
1191 unlink_file_by_name(argv[1]);
1194 void do_find_free_block(int argc, char *argv[])
1196 blk_t free_blk, goal, first_free = 0;
1201 if ((argc > 3) || (argc==2 && *argv[1] == '?')) {
1202 com_err(argv[0], 0, "Usage: find_free_block [count [goal]]");
1205 if (check_fs_open(argv[0]))
1209 count = strtol(argv[1],&tmp,0);
1211 com_err(argv[0], 0, "Bad count - %s", argv[1]);
1218 goal = strtol(argv[2], &tmp, 0);
1220 com_err(argv[0], 0, "Bad goal - %s", argv[1]);
1225 goal = current_fs->super->s_first_data_block;
1227 printf("Free blocks found: ");
1228 free_blk = goal - 1;
1229 while (count-- > 0) {
1230 retval = ext2fs_new_block(current_fs, free_blk + 1, 0,
1233 if (first_free == free_blk)
1236 first_free = free_blk;
1238 com_err("ext2fs_new_block", retval, 0);
1241 printf("%u ", free_blk);
1246 void do_find_free_inode(int argc, char *argv[])
1248 ext2_ino_t free_inode, dir;
1253 if (argc > 3 || (argc>1 && *argv[1] == '?')) {
1254 com_err(argv[0], 0, "Usage: find_free_inode [dir] [mode]");
1257 if (check_fs_open(argv[0]))
1261 dir = strtol(argv[1], &tmp, 0);
1263 com_err(argv[0], 0, "Bad dir - %s", argv[1]);
1270 mode = strtol(argv[2], &tmp, 0);
1272 com_err(argv[0], 0, "Bad mode - %s", argv[2]);
1278 retval = ext2fs_new_inode(current_fs, dir, mode, 0, &free_inode);
1280 com_err("ext2fs_new_inode", retval, 0);
1282 printf("Free inode found: %u\n", free_inode);
1285 static errcode_t copy_file(int fd, ext2_ino_t newfile)
1287 ext2_file_t e2_file;
1290 unsigned int written;
1294 retval = ext2fs_file_open(current_fs, newfile,
1295 EXT2_FILE_WRITE, &e2_file);
1300 got = read(fd, buf, sizeof(buf));
1309 retval = ext2fs_file_write(e2_file, ptr,
1318 retval = ext2fs_file_close(e2_file);
1322 (void) ext2fs_file_close(e2_file);
1327 void do_write(int argc, char *argv[])
1330 struct stat statbuf;
1333 struct ext2_inode inode;
1335 if (common_args_process(argc, argv, 3, 3, "write",
1336 "<native file> <new file>", CHECK_FS_RW))
1339 fd = open(argv[1], O_RDONLY);
1341 com_err(argv[1], errno, 0);
1344 if (fstat(fd, &statbuf) < 0) {
1345 com_err(argv[1], errno, 0);
1350 retval = ext2fs_namei(current_fs, root, cwd, argv[2], &newfile);
1352 com_err(argv[0], 0, "The file '%s' already exists\n", argv[2]);
1357 retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
1359 com_err(argv[0], retval, 0);
1363 printf("Allocated inode: %u\n", newfile);
1364 retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
1366 if (retval == EXT2_ET_DIR_NO_SPACE) {
1367 retval = ext2fs_expand_dir(current_fs, cwd);
1369 com_err(argv[0], retval, "while expanding directory");
1373 retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
1377 com_err(argv[2], retval, 0);
1381 if (ext2fs_test_inode_bitmap(current_fs->inode_map,newfile))
1382 com_err(argv[0], 0, "Warning: inode already set");
1383 ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
1384 memset(&inode, 0, sizeof(inode));
1385 inode.i_mode = (statbuf.st_mode & ~LINUX_S_IFMT) | LINUX_S_IFREG;
1386 inode.i_atime = inode.i_ctime = inode.i_mtime =
1387 current_fs->now ? current_fs->now : time(0);
1388 inode.i_links_count = 1;
1389 inode.i_size = statbuf.st_size;
1390 if (current_fs->super->s_feature_incompat &
1391 EXT3_FEATURE_INCOMPAT_EXTENTS)
1392 inode.i_flags |= EXT4_EXTENTS_FL;
1393 if (debugfs_write_new_inode(newfile, &inode, argv[0])) {
1397 if (LINUX_S_ISREG(inode.i_mode)) {
1398 retval = copy_file(fd, newfile);
1400 com_err("copy_file", retval, 0);
1405 void do_mknod(int argc, char *argv[])
1407 unsigned long mode, major, minor;
1410 struct ext2_inode inode;
1413 if (check_fs_open(argv[0]))
1415 if (argc < 3 || argv[2][1]) {
1417 com_err(argv[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
1420 mode = minor = major = 0;
1421 switch (argv[2][0]) {
1423 mode = LINUX_S_IFIFO;
1424 filetype = EXT2_FT_FIFO;
1428 mode = LINUX_S_IFCHR;
1429 filetype = EXT2_FT_CHRDEV;
1433 mode = LINUX_S_IFBLK;
1434 filetype = EXT2_FT_BLKDEV;
1442 major = strtoul(argv[3], argv+3, 0);
1443 minor = strtoul(argv[4], argv+4, 0);
1444 if (major > 65535 || minor > 65535 || argv[3][0] || argv[4][0])
1449 if (check_fs_read_write(argv[0]))
1451 retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
1453 com_err(argv[0], retval, 0);
1456 printf("Allocated inode: %u\n", newfile);
1457 retval = ext2fs_link(current_fs, cwd, argv[1], newfile, filetype);
1458 if (retval == EXT2_ET_DIR_NO_SPACE) {
1459 retval = ext2fs_expand_dir(current_fs, cwd);
1461 com_err(argv[0], retval, "while expanding directory");
1464 retval = ext2fs_link(current_fs, cwd, argv[1], newfile,
1468 com_err(argv[1], retval, 0);
1471 if (ext2fs_test_inode_bitmap(current_fs->inode_map,newfile))
1472 com_err(argv[0], 0, "Warning: inode already set");
1473 ext2fs_mark_inode_bitmap(current_fs->inode_map, newfile);
1474 ext2fs_mark_ib_dirty(current_fs);
1475 memset(&inode, 0, sizeof(inode));
1476 inode.i_mode = mode;
1477 inode.i_atime = inode.i_ctime = inode.i_mtime =
1478 current_fs->now ? current_fs->now : time(0);
1479 if ((major < 256) && (minor < 256)) {
1480 inode.i_block[0] = major*256+minor;
1481 inode.i_block[1] = 0;
1483 inode.i_block[0] = 0;
1484 inode.i_block[1] = (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
1486 inode.i_links_count = 1;
1487 if (debugfs_write_new_inode(newfile, &inode, argv[0]))
1491 void do_mkdir(int argc, char *argv[])
1498 if (common_args_process(argc, argv, 2, 2, "mkdir",
1499 "<filename>", CHECK_FS_RW))
1502 cp = strrchr(argv[1], '/');
1505 parent = string_to_inode(argv[1]);
1507 com_err(argv[1], ENOENT, 0);
1517 retval = ext2fs_mkdir(current_fs, parent, 0, name);
1518 if (retval == EXT2_ET_DIR_NO_SPACE) {
1519 retval = ext2fs_expand_dir(current_fs, parent);
1521 com_err(argv[0], retval, "while expanding directory");
1527 com_err("ext2fs_mkdir", retval, 0);
1533 static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
1534 int blockcnt EXT2FS_ATTR((unused)),
1535 void *private EXT2FS_ATTR((unused)))
1540 ext2fs_block_alloc_stats(fs, block, -1);
1544 static void kill_file_by_inode(ext2_ino_t inode)
1546 struct ext2_inode inode_buf;
1548 if (debugfs_read_inode(inode, &inode_buf, 0))
1550 inode_buf.i_dtime = current_fs->now ? current_fs->now : time(0);
1551 if (debugfs_write_inode(inode, &inode_buf, 0))
1553 if (!ext2fs_inode_has_valid_blocks(&inode_buf))
1556 ext2fs_block_iterate(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
1557 release_blocks_proc, NULL);
1559 ext2fs_inode_alloc_stats2(current_fs, inode, -1,
1560 LINUX_S_ISDIR(inode_buf.i_mode));
1564 void do_kill_file(int argc, char *argv[])
1566 ext2_ino_t inode_num;
1568 if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW))
1571 kill_file_by_inode(inode_num);
1574 void do_rm(int argc, char *argv[])
1577 ext2_ino_t inode_num;
1578 struct ext2_inode inode;
1580 if (common_args_process(argc, argv, 2, 2, "rm",
1581 "<filename>", CHECK_FS_RW))
1584 retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num);
1586 com_err(argv[0], retval, "while trying to resolve filename");
1590 if (debugfs_read_inode(inode_num, &inode, argv[0]))
1593 if (LINUX_S_ISDIR(inode.i_mode)) {
1594 com_err(argv[0], 0, "file is a directory");
1598 --inode.i_links_count;
1599 if (debugfs_write_inode(inode_num, &inode, argv[0]))
1602 unlink_file_by_name(argv[1]);
1603 if (inode.i_links_count == 0)
1604 kill_file_by_inode(inode_num);
1612 static int rmdir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
1613 int entry EXT2FS_ATTR((unused)),
1614 struct ext2_dir_entry *dirent,
1615 int offset EXT2FS_ATTR((unused)),
1616 int blocksize EXT2FS_ATTR((unused)),
1617 char *buf EXT2FS_ATTR((unused)),
1620 struct rd_struct *rds = (struct rd_struct *) private;
1622 if (dirent->inode == 0)
1624 if (((dirent->name_len&0xFF) == 1) && (dirent->name[0] == '.'))
1626 if (((dirent->name_len&0xFF) == 2) && (dirent->name[0] == '.') &&
1627 (dirent->name[1] == '.')) {
1628 rds->parent = dirent->inode;
1635 void do_rmdir(int argc, char *argv[])
1638 ext2_ino_t inode_num;
1639 struct ext2_inode inode;
1640 struct rd_struct rds;
1642 if (common_args_process(argc, argv, 2, 2, "rmdir",
1643 "<filename>", CHECK_FS_RW))
1646 retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num);
1648 com_err(argv[0], retval, "while trying to resolve filename");
1652 if (debugfs_read_inode(inode_num, &inode, argv[0]))
1655 if (!LINUX_S_ISDIR(inode.i_mode)) {
1656 com_err(argv[0], 0, "file is not a directory");
1663 retval = ext2fs_dir_iterate2(current_fs, inode_num, 0,
1664 0, rmdir_proc, &rds);
1666 com_err(argv[0], retval, "while iterating over directory");
1669 if (rds.empty == 0) {
1670 com_err(argv[0], 0, "directory not empty");
1674 inode.i_links_count = 0;
1675 if (debugfs_write_inode(inode_num, &inode, argv[0]))
1678 unlink_file_by_name(argv[1]);
1679 kill_file_by_inode(inode_num);
1682 if (debugfs_read_inode(rds.parent, &inode, argv[0]))
1684 if (inode.i_links_count > 1)
1685 inode.i_links_count--;
1686 if (debugfs_write_inode(rds.parent, &inode, argv[0]))
1691 void do_show_debugfs_params(int argc EXT2FS_ATTR((unused)),
1692 char *argv[] EXT2FS_ATTR((unused)))
1697 fprintf(out, "Open mode: read-%s\n",
1698 current_fs->flags & EXT2_FLAG_RW ? "write" : "only");
1699 fprintf(out, "Filesystem in use: %s\n",
1700 current_fs ? current_fs->device_name : "--none--");
1703 void do_expand_dir(int argc, char *argv[])
1708 if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW))
1711 retval = ext2fs_expand_dir(current_fs, inode);
1713 com_err("ext2fs_expand_dir", retval, 0);
1717 void do_features(int argc, char *argv[])
1721 if (check_fs_open(argv[0]))
1724 if ((argc != 1) && check_fs_read_write(argv[0]))
1726 for (i=1; i < argc; i++) {
1727 if (e2p_edit_feature(argv[i],
1728 ¤t_fs->super->s_feature_compat, 0))
1729 com_err(argv[0], 0, "Unknown feature: %s\n",
1732 ext2fs_mark_super_dirty(current_fs);
1734 print_features(current_fs->super, stdout);
1737 void do_bmap(int argc, char *argv[])
1744 if (common_args_process(argc, argv, 3, 3, argv[0],
1745 "<file> logical_blk", 0))
1748 ino = string_to_inode(argv[1]);
1751 blk = parse_ulong(argv[2], argv[0], "logical_block", &err);
1753 errcode = ext2fs_bmap(current_fs, ino, 0, 0, 0, blk, &pblk);
1755 com_err("argv[0]", errcode,
1756 "while mapping logical block %u\n", blk);
1759 printf("%u\n", pblk);
1762 void do_imap(int argc, char *argv[])
1765 unsigned long group, block, block_nr, offset;
1767 if (common_args_process(argc, argv, 2, 2, argv[0],
1770 ino = string_to_inode(argv[1]);
1774 group = (ino - 1) / EXT2_INODES_PER_GROUP(current_fs->super);
1775 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(current_fs->super)) *
1776 EXT2_INODE_SIZE(current_fs->super);
1777 block = offset >> EXT2_BLOCK_SIZE_BITS(current_fs->super);
1778 if (!current_fs->group_desc[(unsigned)group].bg_inode_table) {
1779 com_err(argv[0], 0, "Inode table for group %lu is missing\n",
1783 block_nr = current_fs->group_desc[(unsigned)group].bg_inode_table +
1785 offset &= (EXT2_BLOCK_SIZE(current_fs->super) - 1);
1787 printf("Inode %d is part of block group %lu\n"
1788 "\tlocated at block %lu, offset 0x%04lx\n", ino, group,
1793 void do_set_current_time(int argc, char *argv[])
1797 if (common_args_process(argc, argv, 2, 2, argv[0],
1801 now = string_to_time(argv[1]);
1802 if (now == ((time_t) -1)) {
1803 com_err(argv[0], 0, "Couldn't parse argument as a time: %s\n",
1808 printf("Setting current time to %s\n", time_to_string(now));
1809 current_fs->now = now;
1813 static int find_supp_feature(__u32 *supp, int feature_type, char *name)
1815 int compat, bit, ret;
1816 unsigned int feature_mask;
1819 if (feature_type == E2P_FS_FEATURE)
1820 ret = e2p_string2feature(name, &compat, &feature_mask);
1822 ret = e2p_jrnl_string2feature(name, &compat,
1827 if (!(supp[compat] & feature_mask))
1830 for (compat = 0; compat < 3; compat++) {
1831 for (bit = 0, feature_mask = 1; bit < 32;
1832 bit++, feature_mask <<= 1) {
1833 if (supp[compat] & feature_mask) {
1834 if (feature_type == E2P_FS_FEATURE)
1835 fprintf(stdout, " %s",
1836 e2p_feature2string(compat,
1839 fprintf(stdout, " %s",
1840 e2p_jrnl_feature2string(compat,
1845 fprintf(stdout, "\n");
1851 void do_supported_features(int argc, char *argv[])
1854 __u32 supp[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP,
1855 EXT2_LIB_FEATURE_INCOMPAT_SUPP,
1856 EXT2_LIB_FEATURE_RO_COMPAT_SUPP };
1857 __u32 jrnl_supp[3] = { JFS_KNOWN_COMPAT_FEATURES,
1858 JFS_KNOWN_INCOMPAT_FEATURES,
1859 JFS_KNOWN_ROCOMPAT_FEATURES };
1862 ret = find_supp_feature(supp, E2P_FS_FEATURE, argv[1]);
1864 ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE,
1868 com_err(argv[0], 0, "Unknown feature: %s\n", argv[1]);
1870 fprintf(stdout, "Supported feature: %s\n", argv[1]);
1872 fprintf(stdout, "Supported features:");
1873 ret = find_supp_feature(supp, E2P_FS_FEATURE, NULL);
1874 ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE, NULL);
1878 static int source_file(const char *cmd_file, int sci_idx)
1883 int exit_status = 0;
1886 if (strcmp(cmd_file, "-") == 0)
1889 f = fopen(cmd_file, "r");
1897 setbuf(stdout, NULL);
1898 setbuf(stderr, NULL);
1900 if (fgets(buf, sizeof(buf), f) == NULL)
1902 cp = strchr(buf, '\n');
1905 cp = strchr(buf, '\r');
1908 printf("debugfs: %s\n", buf);
1909 retval = ss_execute_line(sci_idx, buf);
1911 ss_perror(sci_idx, retval, buf);
1918 int main(int argc, char **argv)
1922 const char *usage = "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] [-R request] [-V] [[-w] [-c] device]";
1924 int open_flags = EXT2_FLAG_SOFTSUPP_FEATURES;
1926 int exit_status = 0;
1928 blk_t superblock = 0;
1929 blk_t blocksize = 0;
1930 int catastrophic = 0;
1931 char *data_filename = 0;
1933 if (debug_prog_name == 0)
1934 debug_prog_name = "debugfs";
1936 add_error_table(&et_ext2_error_table);
1937 fprintf (stderr, "%s %s (%s)\n", debug_prog_name,
1938 E2FSPROGS_VERSION, E2FSPROGS_DATE);
1940 while ((c = getopt (argc, argv, "iwcR:f:b:s:Vd:")) != EOF) {
1949 data_filename = optarg;
1952 open_flags |= EXT2_FLAG_IMAGE_FILE;
1955 open_flags |= EXT2_FLAG_RW;
1958 blocksize = parse_ulong(optarg, argv[0],
1962 superblock = parse_ulong(optarg, argv[0],
1963 "superblock number", 0);
1969 /* Print version number and exit */
1970 fprintf(stderr, "\tUsing %s\n",
1971 error_message(EXT2_ET_BASE));
1974 com_err(argv[0], 0, usage, debug_prog_name);
1979 open_filesystem(argv[optind], open_flags,
1980 superblock, blocksize, catastrophic,
1983 sci_idx = ss_create_invocation(debug_prog_name, "0.0", (char *) NULL,
1984 &debug_cmds, &retval);
1986 ss_perror(sci_idx, retval, "creating invocation");
1989 ss_get_readline(sci_idx);
1991 (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval);
1993 ss_perror(sci_idx, retval, "adding standard requests");
1997 ss_add_request_table (sci_idx, extra_cmds, 1, &retval);
1999 ss_perror(sci_idx, retval, "adding extra requests");
2004 retval = ss_execute_line(sci_idx, request);
2006 ss_perror(sci_idx, retval, request);
2009 } else if (cmd_file) {
2010 exit_status = source_file(cmd_file, sci_idx);
2018 remove_error_table(&et_ext2_error_table);