[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/Makefile.in b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/Makefile.in
new file mode 100644
index 0000000..bf037e0
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/Makefile.in
@@ -0,0 +1,208 @@
+#
+# Standard e2fsprogs prologue....
+#
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+top_builddir = ..
+my_dir = debugfs
+INSTALL = @INSTALL@
+
+@MCONFIG@
+
+PROGS=		debugfs
+MANPAGES=	debugfs.8
+
+MK_CMDS=	_SS_DIR_OVERRIDE=../lib/ss ../lib/ss/mk_cmds
+
+DEBUG_OBJS= debug_cmds.o debugfs.o util.o ncheck.o icheck.o ls.o \
+	lsdel.o dump.o set_fields.o logdump.o htree.o unused.o e2freefrag.o \
+	filefrag.o extent_cmds.o extent_inode.o zap.o
+
+RO_DEBUG_OBJS= ro_debug_cmds.o ro_debugfs.o util.o ncheck.o icheck.o ls.o \
+	lsdel.o logdump.o htree.o e2freefrag.o filefrag.o extent_cmds.o \
+	extent_inode.o
+
+SRCS= debug_cmds.c $(srcdir)/debugfs.c $(srcdir)/util.c $(srcdir)/ls.c \
+	$(srcdir)/ncheck.c $(srcdir)/icheck.c $(srcdir)/lsdel.c \
+	$(srcdir)/dump.c $(srcdir)/set_fields.c ${srcdir}/logdump.c \
+	$(srcdir)/htree.c $(srcdir)/unused.c ${srcdir}/../misc/e2freefrag.c \
+	$(srcdir)/filefrag.c $(srcdir)/extent_inode.c $(srcdir)/zap.c
+
+LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
+	$(LIBUUID)
+DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(DEPLIBSS) $(DEPLIBCOM_ERR) \
+	$(DEPLIBBLKID) $(DEPLIBUUID)
+
+STATIC_LIBS= $(STATIC_LIBEXT2FS) $(STATIC_LIBSS) $(STATIC_LIBCOM_ERR) \
+	$(STATIC_LIBBLKID) $(STATIC_LIBUUID) $(STATIC_LIBE2P)
+STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBSS) \
+		$(DEPSTATIC_LIBCOM_ERR) $(DEPSTATIC_LIBUUID) \
+		$(DEPSTATIC_LIBE2P)
+
+.c.o:
+	$(E) "	CC $<"
+	$(Q) $(CC) -c $(ALL_CFLAGS) $< -o $@
+	$(Q) $(CHECK_CMD) $(ALL_CFLAGS) $<
+
+all:: $(PROGS) $(MANPAGES)
+
+debugfs: $(DEBUG_OBJS) $(DEPLIBS)
+	$(E) "	LD $@"
+	$(Q) $(CC) $(ALL_LDFLAGS) -o debugfs $(DEBUG_OBJS) $(LIBS)
+
+debugfs.static: $(DEBUG_OBJS) $(STATIC_DEPLIBS)
+	$(E) "	LD $@"
+	$(Q) $(CC) $(LDFLAGS_STATIC) -o debugfs.static $(DEBUG_OBJS) \
+		$(STATIC_LIBS) $(READLINE_LIB)
+
+rdebugfs: $(RO_DEBUG_OBJS) $(DEPLIBS)
+	$(E) "	LD $@"
+	$(Q) $(CC) $(ALL_LDFLAGS) -o rdebugfs $(RO_DEBUG_OBJS) $(LIBS)
+
+debug_cmds.c debug_cmds.h: debug_cmds.ct
+	$(E) "	MK_CMDS $@"
+	$(Q) $(MK_CMDS) $(srcdir)/debug_cmds.ct
+
+extent_cmds.c extent_cmds.h: extent_cmds.ct
+	$(E) "	MK_CMDS $@"
+	$(Q) $(MK_CMDS) $(srcdir)/extent_cmds.ct
+
+ro_debug_cmds.c ro_debug_cmds.h: ro_debug_cmds.ct
+	$(E) "	MK_CMDS $@"
+	$(Q) $(MK_CMDS) $(srcdir)/ro_debug_cmds.ct
+
+ro_debugfs.o: debugfs.c
+	$(E) "	CC $@"
+	$(Q) $(CC) -c $(ALL_CFLAGS) $< -DREAD_ONLY -o $@
+
+e2freefrag.o: $(srcdir)/../misc/e2freefrag.c
+	$(E) "	CC $@"
+	$(Q) $(CC) -c $(ALL_CFLAGS) -I$(srcdir) $< -DDEBUGFS -o $@
+
+debugfs.8: $(DEP_SUBSTITUTE) $(srcdir)/debugfs.8.in
+	$(E) "	SUBST $@"
+	$(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/debugfs.8.in debugfs.8
+
+installdirs:
+	$(E) "	MKINSTALLDIRS $(root_sbindir) $(man8dir)"
+	$(Q) $(MKINSTALLDIRS) $(DESTDIR)$(root_sbindir) \
+		$(DESTDIR)$(man8dir)
+
+install: $(PROGS) $(MANPAGES) installdirs
+	$(Q) for i in $(PROGS); do \
+		echo "	INSTALL $(root_sbindir)/$$i"; \
+		$(INSTALL_PROGRAM) $$i $(DESTDIR)$(root_sbindir)/$$i; \
+	done
+	$(Q) for i in $(MANPAGES); do \
+		for j in $(COMPRESS_EXT); do \
+			$(RM) -f $(DESTDIR)$(man8dir)/$$i.$$j; \
+		done; \
+		echo "	INSTALL_DATA $(man8dir)/$$i"; \
+		$(INSTALL_DATA) $$i $(DESTDIR)$(man8dir)/$$i; \
+	done
+
+install-strip: install
+	$(Q) for i in $(PROGS); do \
+		echo "	STRIP $(root_sbindir)/$$i"; \
+		$(STRIP) $(DESTDIR)$(root_sbindir)/$$i; \
+	done
+
+uninstall:
+	for i in $(PROGS); do \
+		$(RM) -f $(DESTDIR)$(root_sbindir)/$$i; \
+	done
+	for i in $(MANPAGES); do \
+		$(RM) -f $(DESTDIR)$(man8dir)/$$i; \
+	done
+
+clean:
+	$(RM) -f $(PROGS) debugfs.8 \#* *.s *.o *.a *~ debug_cmds.c \
+		extent_cmds.c ro_debug_cmds.c core rdebugfs debugfs.static
+
+mostlyclean: clean
+distclean: clean
+	$(RM) -f debug_cmds.c .depend Makefile $(srcdir)/TAGS \
+		$(srcdir)/Makefile.in.old
+
+# +++ Dependency line eater +++
+# 
+# Makefile dependencies follow.  This must be the last section in
+# the Makefile.in file
+#
+debug_cmds.o: debug_cmds.c $(top_srcdir)/lib/ss/ss.h \
+ $(top_builddir)/lib/ss/ss_err.h $(top_srcdir)/lib/et/com_err.h
+debugfs.o: $(srcdir)/debugfs.c $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ss/ss.h $(top_builddir)/lib/ss/ss_err.h \
+ $(srcdir)/debugfs.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/version.h $(srcdir)/jfs_user.h \
+ $(top_srcdir)/lib/ext2fs/kernel-jbd.h $(top_srcdir)/lib/ext2fs/jfs_compat.h \
+ $(top_srcdir)/lib/ext2fs/kernel-list.h
+util.o: $(srcdir)/util.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+ls.o: $(srcdir)/ls.c $(srcdir)/debugfs.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
+ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
+ $(top_srcdir)/lib/ext2fs/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+ncheck.o: $(srcdir)/ncheck.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+icheck.o: $(srcdir)/icheck.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+lsdel.o: $(srcdir)/lsdel.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+dump.o: $(srcdir)/dump.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
+set_fields.o: $(srcdir)/set_fields.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/e2p/e2p.h
+logdump.o: $(srcdir)/logdump.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(srcdir)/jfs_user.h $(top_srcdir)/lib/ext2fs/kernel-jbd.h \
+ $(top_srcdir)/lib/ext2fs/jfs_compat.h $(top_srcdir)/lib/ext2fs/kernel-list.h
+htree.o: $(srcdir)/htree.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h \
+ $(top_srcdir)/lib/e2p/e2p.h
+unused.o: $(srcdir)/unused.c $(srcdir)/debugfs.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
+ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext3_extents.h \
+ $(top_srcdir)/lib/et/com_err.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
+ $(top_builddir)/lib/ext2fs/ext2_err.h \
+ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/bitops.h
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debug_cmds.ct b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debug_cmds.ct
new file mode 100644
index 0000000..96ff00f
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debug_cmds.ct
@@ -0,0 +1,194 @@
+#
+# Copyright (C) 1993 Theodore Ts'o.  This file may be redistributed
+# under the terms of the GNU Public License.
+#
+command_table debug_cmds;
+
+request do_show_debugfs_params, "Show debugfs parameters",
+	show_debugfs_params, params;
+
+request do_open_filesys, "Open a filesystem",
+	open_filesys, open;
+
+request do_close_filesys, "Close the filesystem",
+	close_filesys, close;
+
+request do_freefrag, "Report free space fragmentation",
+	freefrag, e2freefrag;
+
+request do_features, "Set/print superblock features",
+	feature, features;
+
+request do_dirty_filesys, "Mark the filesystem as dirty",
+	dirty_filesys, dirty;
+
+request do_init_filesys, "Initialize a filesystem (DESTROYS DATA)",
+	init_filesys;
+
+request do_show_super_stats, "Show superblock statistics",
+	show_super_stats, stats;
+
+request do_ncheck, "Do inode->name translation",
+	ncheck;
+
+request do_icheck, "Do block->inode translation",
+	icheck;
+
+request do_chroot, "Change root directory",
+	change_root_directory, chroot;
+
+request do_change_working_dir, "Change working directory",
+	change_working_directory, cd;
+
+request do_list_dir, "List directory",
+	list_directory, ls;
+
+request do_stat, "Show inode information ",
+	show_inode_info, stat;
+
+request do_dump_extents, "Dump extents information ",
+	dump_extents, extents, ex;
+
+request do_blocks, "Dump blocks used by an inode ",
+	blocks;
+
+request do_filefrag, "Report fragmentation information for an inode",
+	filefrag;
+
+request do_link, "Create directory link",
+	link, ln;
+
+request do_unlink, "Delete a directory link",
+	unlink;
+
+request do_mkdir, "Create a directory",
+	mkdir;
+
+request do_rmdir, "Remove a directory",
+	rmdir;
+
+request do_rm, "Remove a file (unlink and kill_file, if appropriate)",
+	rm;
+
+request do_kill_file, "Deallocate an inode and its blocks",
+	kill_file;
+
+request do_clri, "Clear an inode's contents",
+	clri;
+
+request do_freei, "Clear an inode's in-use flag",
+	freei;
+
+request do_seti, "Set an inode's in-use flag",
+	seti;
+
+request do_testi, "Test an inode's in-use flag",
+	testi;
+
+request do_freeb, "Clear a block's in-use flag",
+	freeb;
+
+request do_setb, "Set a block's in-use flag",
+	setb;
+
+request do_testb, "Test a block's in-use flag",
+	testb;
+
+request do_modify_inode, "Modify an inode by structure",
+	modify_inode, mi;
+
+request do_find_free_block, "Find free block(s)",
+	find_free_block, ffb;
+
+request do_find_free_inode, "Find free inode(s)",
+	find_free_inode, ffi;
+
+request	do_print_working_directory, "Print current working directory",
+	print_working_directory, pwd; 
+
+request	do_expand_dir, "Expand directory",
+	expand_dir, expand;
+
+request do_mknod, "Create a special file",
+	mknod;
+
+request do_lsdel, "List deleted inodes",
+	list_deleted_inodes, lsdel;
+
+request do_undel, "Undelete file",
+	undelete, undel;
+
+request do_write, "Copy a file from your native filesystem",
+	write;
+
+request do_dump, "Dump an inode out to a file",
+	dump_inode, dump;
+
+request do_cat, "Dump an inode out to stdout",
+	cat;
+
+request do_lcd, "Change the current directory on your native filesystem",
+	lcd;
+
+request do_rdump, "Recursively dump a directory to the native filesystem",
+	rdump;
+
+request do_set_super, "Set superblock value",
+	set_super_value, ssv;
+
+request do_set_inode, "Set inode field",
+	set_inode_field, sif;
+
+request do_set_block_group_descriptor, "Set block group descriptor field",
+	set_block_group, set_bg;
+
+request do_logdump, "Dump the contents of the journal",
+	logdump;
+
+request do_htree_dump, "Dump a hash-indexed directory",
+	htree_dump, htree;
+
+request do_dx_hash, "Calculate the directory hash of a filename",
+	dx_hash, hash;
+
+request do_dirsearch, "Search a directory for a particular filename",
+	dirsearch;
+
+request do_bmap, "Calculate the logical->physical block mapping for an inode",
+	bmap;
+
+request do_punch, "Punch (or truncate) blocks from an inode by deallocating them",
+	punch, truncate;
+
+request do_symlink, "Create a symbolic link",
+	symlink;
+
+request do_imap, "Calculate the location of an inode",
+	imap;
+
+request	do_dump_unused, "Dump unused blocks",
+	dump_unused;
+
+request do_set_current_time, "Set current time to use when setting filesystem fields",
+	set_current_time;
+
+request do_supported_features, "Print features supported by this version of e2fsprogs",
+	supported_features;
+
+request do_dump_mmp, "Dump MMP information",
+	dump_mmp;
+
+request do_set_mmp_value, "Set MMP value",
+	set_mmp_value, smmp;
+
+request do_extent_open, "Open inode for extent manipulation",
+	extent_open, eo;
+
+request do_zap_block, "Zap block: fill with 0, pattern, flip bits etc.",
+	zap_block, zap;
+
+request do_block_dump, "Dump contents of a block",
+	block_dump, bd;
+
+end;
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.8.in b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.8.in
new file mode 100644
index 0000000..73254d3
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.8.in
@@ -0,0 +1,718 @@
+.\" -*- nroff -*-
+.\" Copyright 1993, 1994, 1995 by Theodore Ts'o.  All Rights Reserved.
+.\" This file may be copied under the terms of the GNU Public License.
+.\"
+.TH DEBUGFS 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
+.SH NAME
+debugfs \- ext2/ext3/ext4 file system debugger
+.SH SYNOPSIS
+.B debugfs
+[
+.B \-DVwci
+]
+[
+.B \-b
+blocksize
+]
+[
+.B \-s
+superblock
+]
+[
+.B \-f
+cmd_file
+]
+[
+.B \-R
+request
+]
+[
+.B \-d
+data_source_device
+]
+[
+device
+]
+.SH DESCRIPTION
+The
+.B debugfs
+program is an interactive file system debugger. It can be used to
+examine and change the state of an ext2, ext3, or ext4 file system.
+.br
+.I device
+is the special file corresponding to the device containing the
+file system (e.g /dev/hdXX).
+.SH OPTIONS
+.TP
+.I \-w
+Specifies that the file system should be opened in read-write mode.
+Without this option, the file system is opened in read-only mode.
+.TP
+.I \-c
+Specifies that the file system should be opened in catastrophic mode, in
+which the inode and group bitmaps are not read initially.  This can be
+useful for filesystems with significant corruption, but because of this,
+catastrophic mode forces the filesystem to be opened read-only.
+.TP
+.I \-i
+Specifies that
+.I device
+represents an ext2 image file created by the
+.B e2image
+program.  Since the ext2 image file only contains the superblock, block
+group descriptor, block and inode allocation bitmaps, and
+the inode table, many
+.B debugfs
+commands will not function properly.
+.B Warning:
+no safety checks are in place, and
+.B debugfs
+may fail in interesting ways if commands such as
+.IR ls ", " dump ", "
+etc. are tried without specifying the
+.I data_source_device
+using the
+.I \-d
+option.
+.B debugfs
+is a debugging tool.  It has rough edges!
+.TP
+.I -d data_source_device
+Used with the
+.I \-i
+option, specifies that
+.I data_source_device
+should be used when reading blocks not found in the ext2 image file.
+This includes data, directory, and indirect blocks.
+.TP
+.I -b blocksize
+Forces the use of the given block size for the file system, rather than
+detecting the correct block size as normal.
+.TP
+.I -s superblock
+Causes the file system superblock to be read from the given block
+number, instead of using the primary superblock (located at an offset of
+1024 bytes from the beginning of the filesystem).  If you specify the
+.I -s
+option, you must also provide the blocksize of the filesystem via the
+.I -b
+option.
+.TP
+.I -f cmd_file
+Causes
+.B debugfs
+to read in commands from
+.IR cmd_file ,
+and execute them.  When
+.B debugfs
+is finished executing those commands, it will exit.
+.TP
+.I -D
+Causes
+.B debugfs
+to open the device using Direct I/O, bypassing the buffer cache.  Note
+that some Linux devices, notably device mapper as of this writing, do
+not support Direct I/O.
+.TP
+.I -R request
+Causes
+.B debugfs
+to execute the single command
+.IR request ,
+and then exit.
+.TP
+.I -V
+print the version number of
+.B debugfs
+and exit.
+.SH SPECIFYING FILES
+Many
+.B debugfs
+commands take a
+.I filespec
+as an argument to specify an inode (as opposed to a pathname)
+in the filesystem which is currently opened by
+.BR debugfs .
+The
+.I filespec
+argument may be specified in two forms.  The first form is an inode
+number surrounded by angle brackets, e.g.,
+.IR <2> .
+The second form is a pathname; if the pathname is prefixed by a forward slash
+('/'), then it is interpreted relative to the root of the filesystem
+which is currently opened by
+.BR debugfs .
+If not, the pathname is
+interpreted relative to the current working directory as maintained by
+.BR debugfs .
+This may be modified by using the
+.B debugfs
+command
+.IR cd .
+.\"
+.\"
+.\"
+.SH COMMANDS
+This is a list of the commands which
+.B debugfs
+supports.
+.TP
+.BI blocks " filespace"
+Print the blocks used by the inode
+.I filespec
+to stdout.
+.TP
+.BI bmap " filespec logical_block"
+Print the physical block number corresponding to the logical block number
+.I logical_block
+in the inode
+.IR filespec .
+.TP
+.BI block_dump " [-f filespec] block_num"
+Dump the filesystem block given by
+.I block_num
+in hex and ASCII format to the console.  If the
+.I -f
+option is specified, the block number is relative to the start of the given
+.BR filespec .
+.TP
+.BI cat " filespec"
+Dump the contents of the inode
+.I filespec
+to stdout.
+.TP
+.BI cd " filespec"
+Change the current working directory to
+.IR filespec .
+.TP
+.BI chroot " filespec"
+Change the root directory to be the directory
+.IR filespec .
+.TP
+.BI close " [-a]"
+Close the currently open file system.  If the
+.I -a
+option is specified, write out any changes to the superblock and block
+group descriptors to all of the backup superblocks, not just to the
+master superblock.
+.TP
+.BI clri " filespec"
+Clear the contents of the inode
+.IR filespec .
+.TP
+.BI dirsearch " filespec filename"
+Search the directory
+.I filespec
+for
+.IR filename .
+.TP
+.B dirty
+Mark the filesystem as dirty, so that the superblocks will be written on exit.
+.TP
+.BI dump " [-p] filespec out_file"
+Dump the contents of the inode
+.I filespec
+to the output file
+.IR out_file .
+If the
+.I -p
+option is given set the owner, group and permissions information on
+.I out_file
+to match
+.IR filespec .
+.TP
+.B dump_mmp
+Display the multiple-mount protection (mmp) field values.
+.TP
+.BI dx_hash " [-h hash_alg] [-s hash_seed] filename"
+Calculate the directory hash of
+.IR filename .
+The hash algorithm specified with
+.I -h
+may be
+.BR legacy , " half_md4" ", or " tea .
+The hash seed specified with
+.I -s
+must be in UUID format.
+.TP
+.BI dump_extents " [-n] [-l] filespec"
+Dump the the extent tree of the inode
+.IR filespec .
+The
+.I -n
+flag will cause
+.B dump_extents
+to only display the interior nodes in the extent tree.   The
+.I -l
+flag will cause
+.B dump_extents
+to only display the leaf nodes in the extent tree.
+.IP
+(Please note that the length and range of blocks for the last extent in
+an interior node is an estimate by the extents library functions, and is
+not stored in filesystem data structures.   Hence, the values displayed
+may not necessarily by accurate and does not indicate a problem or
+corruption in the file system.)
+.TP
+.BI expand_dir " filespec"
+Expand the directory
+.IR filespec .
+.TP
+.BI feature " [fs_feature] [-fs_feature] ..."
+Set or clear various filesystem features in the superblock.  After setting
+or clearing any filesystem features that were requested, print the current
+state of the filesystem feature set.
+.TP
+.BI filefrag " [-dvr] filespec"
+Print the number of contiguous extents in
+.IR filespec .
+If
+.I filespec
+is a directory and the
+.I -d
+option is not specified,
+.I filefrag
+will print the number of contiguous extents for each file in
+the directory.  The
+.I -v
+option will cause
+.I filefrag
+print a tabular listing of the contiguous extents in the
+file.  The
+.I -r
+option will cause
+.I filefrag
+to do a recursive listing of the directory.
+.TP
+.BI find_free_block " [count [goal]]"
+Find the first
+.I count
+free blocks, starting from
+.I goal
+and allocate it.  Also available as
+.BR ffb .
+.TP
+.BI find_free_inode " [dir [mode]]"
+Find a free inode and allocate it.  If present,
+.I dir
+specifies the inode number of the directory
+which the inode is to be located.  The second
+optional argument
+.I mode
+specifies the permissions of the new inode.  (If the directory bit is set
+on the mode, the allocation routine will function differently.)  Also
+available as
+.BR ffi .
+.TP
+.BI freeb " block [count]"
+Mark the block number
+.I block
+as not allocated.
+If the optional argument
+.I count
+is present, then
+.I count
+blocks starting at block number
+.I block
+will be marked as not allocated.
+.TP
+.BI freefrag " [-c chunk_kb]"
+Report free space fragmentation on the currently open file system.
+If the
+.I \-c
+option is specified then the filefrag command will print how many free
+chunks of size
+.I chunk_kb
+can be found in the file system.  The chunk size must be a power of two
+and be larger than the file system block size.
+.TP
+.BI freei " filespec [num]"
+Free the inode specified by
+.IR filespec .
+If
+.I num
+is specified, also clear num-1 inodes after the specified inode.
+.TP
+.B help
+Print a list of commands understood by
+.BR debugfs .
+.TP
+.BI htree_dump " filespec"
+Dump the hash-indexed directory
+.IR filespec ,
+showing its tree structure.
+.TP
+.BI icheck " block ..."
+Print a listing of the inodes which use the one or more blocks specified
+on the command line.
+.TP
+.BI imap " filespec"
+Print the location of the inode data structure (in the inode table)
+of the inode
+.IR filespec .
+.TP
+.BI init_filesys " device blocksize"
+Create an ext2 file system on
+.I device
+with device size
+.IR blocksize .
+Note that this does not fully initialize all of the data structures;
+to do this, use the
+.BR mke2fs (8)
+program.  This is just a call to the low-level library, which sets up
+the superblock and block descriptors.
+.TP
+.BI kill_file " filespec"
+Deallocate the inode
+.I filespec
+and its blocks.  Note that this does not remove any directory
+entries (if any) to this inode.  See the
+.BR rm (1)
+command if you wish to unlink a file.
+.TP
+.BI lcd " directory"
+Change the current working directory of the
+.B debugfs
+process to
+.I directory
+on the native filesystem.
+.TP
+.BI ln " filespec dest_file"
+Create a link named
+.I dest_file
+which is a hard link to
+.IR filespec .
+Note this does not adjust the inode reference counts.
+.TP
+.BI logdump " [-acs] [-b block] [-i filespec] [-f journal_file] [output_file]"
+Dump the contents of the ext3 journal.  By default, dump the journal inode as
+specified in the superblock.  However, this can be overridden with the
+.I \-i
+option, which dumps the journal from the internal inode given by
+.IR filespec .
+A regular file containing journal data can be specified using the
+.I \-f
+option.  Finally, the
+.I \-s
+option utilizes the backup information in the superblock to locate the
+journal.
+.IP
+The
+.I \-a
+option causes the
+.B logdump
+program to print the contents of all of the descriptor blocks.
+The
+.I \-b
+option causes
+.B logdump
+to print all journal records that are refer to the specified block.
+The
+.I \-c
+option will print out the contents of all of the data blocks selected by
+the
+.I \-a
+and
+.I \-b
+options.
+.TP
+.BI ls " [-d] [-l] [-p] filespec"
+Print a listing of the files in the directory
+.IR filespec .
+The
+.I \-d
+flag will list deleted entries in the directory.
+The
+.I \-l
+flag will list files using a more verbose format.
+The
+.I \-p
+flag will list the files in a format which is more easily parsable by
+scripts, as well as making it more clear when there are spaces or other
+non-printing characters at the end of filenames.
+.TP
+.BI list_deleted_inodes " [limit]"
+List deleted inodes, optionally limited to those deleted within
+.I limit
+seconds ago.  Also available as
+.BR lsdel .
+.IP
+This command was useful for recovering from accidental file deletions
+for ext2 file systems.  Unfortunately, it is not useful for this purpose
+if the files were deleted using ext3 or ext4, since the inode's
+data blocks are no longer available after the inode is released.
+.TP
+.BI modify_inode " filespec"
+Modify the contents of the inode structure in the inode
+.IR filespec .
+Also available as
+.BR mi .
+.TP
+.BI mkdir " filespec"
+Make a directory.
+.TP
+.BI mknod " filespec [p|[[c|b] major minor]]"
+Create a special device file (a named pipe, character or block device).
+If a character or block device is to be made, the
+.I major
+and
+.I minor
+device numbers must be specified.
+.TP
+.BI ncheck " [-c] inode_num ..."
+Take the requested list of inode numbers, and print a listing of pathnames
+to those inodes.  The
+.I -c
+flag will enable checking the file type information in the directory
+entry to make sure it matches the inode's type.
+.TP
+.BI open " [-weficD] [-b blocksize] [-s superblock] device"
+Open a filesystem for editing.  The
+.I -f
+flag forces the filesystem to be opened even if there are some unknown
+or incompatible filesystem features which would normally
+prevent the filesystem from being opened.  The
+.I -e
+flag causes the filesystem to be opened in exclusive mode.  The
+.IR -b ", " -c ", " -i ", " -s ", " -w ", and " -D
+options behave the same as the command-line options to
+.BR debugfs .
+.TP
+.BI punch " filespec start_blk [end_blk]"
+Delete the blocks in the inode ranging from
+.I start_blk
+to
+.IR end_blk .
+If
+.I end_blk
+is omitted then this command will function as a truncate command; that
+is, all of the blocks starting at
+.I start_blk
+through to the end of the file will be deallocated.
+.TP
+.BI symlink " filespec target"
+Make a symbolic link.
+.TP
+.B pwd
+Print the current working directory.
+.TP
+.B quit
+Quit
+.B debugfs
+.TP
+.BI rdump " directory destination"
+Recursively dump
+.I directory
+and all its contents (including regular files, symbolic links, and other
+directories) into the named
+.I destination
+which should be an existing directory on the native filesystem.
+.TP
+.BI rm " pathname"
+Unlink
+.IR pathname .
+If this causes the inode pointed to by
+.I pathname
+to have no other references, deallocate the file.  This command functions
+as the unlink() system call.
+.I
+.TP
+.BI rmdir " filespec"
+Remove the directory
+.IR filespec .
+.TP
+.BI setb " block [count]"
+Mark the block number
+.I block
+as allocated.
+If the optional argument
+.I count
+is present, then
+.I count
+blocks starting at block number
+.I block
+will be marked as allocated.
+.TP
+.BI set_block_group " bgnum field value"
+Modify the block group descriptor specified by
+.I bgnum
+so that the block group descriptor field
+.I field
+has value
+.IR value .
+Also available as
+.BR set_bg .
+.TP
+.BI seti " filespec [num]"
+Mark inode
+.I filespec
+as in use in the inode bitmap.  If
+.I num
+is specified, also set num-1 inodes after the specified inode.
+.TP
+.BI set_inode_field " filespec field value"
+Modify the inode specified by
+.I filespec
+so that the inode field
+.I field
+has value
+.I value.
+The list of valid inode fields which can be set via this command
+can be displayed by using the command:
+.B set_inode_field -l
+Also available as
+.BR sif .
+.TP
+.BI set_mmp_value " field value"
+Modify the multiple-mount protection (MMP) data so that the MMP field
+.I field
+has value
+.I value.
+The list of valid MMP fields which can be set via this command
+can be displayed by using the command:
+.B set_mmp_value -l
+Also available as
+.BR smmp .
+.TP
+.BI set_super_value " field value"
+Set the superblock field
+.I field
+to
+.I value.
+The list of valid superblock fields which can be set via this command
+can be displayed by using the command:
+.B set_super_value -l
+Also available as
+.BR ssv .
+.TP
+.BI show_super_stats " [-h]"
+List the contents of the super block and the block group descriptors.  If the
+.I -h
+flag is given, only print out the superblock contents. Also available as
+.BR stats .
+.TP
+.BI stat " filespec"
+Display the contents of the inode structure of the inode
+.IR filespec .
+.TP
+.BI testb " block [count]"
+Test if the block number
+.I block
+is marked as allocated in the block bitmap.
+If the optional argument
+.I count
+is present, then
+.I count
+blocks starting at block number
+.I block
+will be tested.
+.TP
+.BI testi " filespec"
+Test if the inode
+.I filespec
+is marked as allocated in the inode bitmap.
+.TP
+.BI undel " <inode_number> [pathname]"
+Undelete the specified inode number (which must be surrounded by angle
+brackets) so that it and its blocks are marked in use, and optionally
+link the recovered inode to the specified pathname.  The
+.B e2fsck
+command should always be run after using the
+.B undel
+command to recover deleted files.
+.IP
+Note that if you are recovering a large number of deleted files, linking
+the inode to a directory may require the directory to be expanded, which
+could allocate a block that had been used by one of the
+yet-to-be-undeleted files.  So it is safer to undelete all of the
+inodes without specifying a destination pathname, and then in a separate
+pass, use the debugfs
+.B link
+command to link the inode to the destination pathname, or use
+.B e2fsck
+to check the filesystem and link all of the recovered inodes to the
+lost+found directory.
+.TP
+.BI unlink " pathname"
+Remove the link specified by
+.I pathname
+to an inode.  Note this does not adjust the inode reference counts.
+.TP
+.BI write " source_file out_file"
+Copy the contents of
+.I source_file
+into a newly-created file in the filesystem named
+.IR out_file .
+.TP
+.BI zap_block " [-f filespec] [-o offset] [-l length] [-p pattern] block_num"
+.TP
+Overwrite the block specified by
+.I block_num
+with zero (NUL) bytes, or if
+.I -p
+is given use the byte specified by
+.IR pattern .
+If
+.I -f
+is given then
+.I block_num
+is relative to the start of the file given by
+.IR filespec .
+The
+.I -o
+and
+.I -l
+options limit the range of bytes to zap to the specified
+.I offset
+and
+.I length
+relative to the start of the block.
+.TP
+.BI zap_block " [-f filespec] [-b bit] block_num"
+Bit-flip portions of the physical
+.IR block_num .
+If
+.I -f
+is given, then
+.I block_num
+is a logical block relative to the start of
+.IR filespec .
+.SH ENVIRONMENT VARIABLES
+.TP
+.B DEBUGFS_PAGER, PAGER
+The
+.B debugfs
+program always pipes the output of the some commands through a
+pager program.  These commands include:
+.IR show_super_stats " (" stats ),
+.IR list_directory " (" ls ),
+.IR show_inode_info " (" stat ),
+.IR list_deleted_inodes " (" lsdel ),
+and
+.IR htree_dump .
+The specific pager can explicitly specified by the
+.B DEBUGFS_PAGER
+environment variable, and if it is not set, by the
+.B PAGER
+environment variable.
+.IP
+Note that since a pager is always used, the
+.BR less (1)
+pager is not particularly appropriate, since it clears the screen before
+displaying the output of the command and clears the output the screen
+when the pager is exited.  Many users prefer to use the
+.BR less (1)
+pager for most purposes, which is why the
+.B DEBUGFS_PAGER
+environment variable is available to override the more general
+.B PAGER
+environment variable.
+.SH AUTHOR
+.B debugfs
+was written by Theodore Ts'o <tytso@mit.edu>.
+.SH SEE ALSO
+.BR dumpe2fs (8),
+.BR tune2fs (8),
+.BR e2fsck (8),
+.BR mke2fs (8),
+.BR ext4 (5)
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.c
new file mode 100644
index 0000000..cf7670b
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.c
@@ -0,0 +1,2521 @@
+/*
+ * debugfs.c --- a program which allows you to attach an ext2fs
+ * filesystem and play with it.
+ *
+ * Copyright (C) 1993 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ *
+ * Modifications by Robert Sanders <gt8134b@prism.gatech.edu>
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "debugfs.h"
+#include "uuid/uuid.h"
+#include "e2p/e2p.h"
+
+#include <ext2fs/ext2_ext_attr.h>
+
+#include "../version.h"
+#include "jfs_user.h"
+
+#ifndef BUFSIZ
+#define BUFSIZ 8192
+#endif
+
+/* 64KiB is the minimium blksize to best minimize system call overhead. */
+#ifndef IO_BUFSIZE
+#define IO_BUFSIZE 64*1024
+#endif
+
+/* Block size for `st_blocks' */
+#ifndef S_BLKSIZE
+#define S_BLKSIZE 512
+#endif
+
+ss_request_table *extra_cmds;
+const char *debug_prog_name;
+int sci_idx;
+
+ext2_filsys	current_fs = NULL;
+ext2_ino_t	root, cwd;
+
+static void open_filesystem(char *device, int open_flags, blk64_t superblock,
+			    blk64_t blocksize, int catastrophic,
+			    char *data_filename)
+{
+	int	retval;
+	io_channel data_io = 0;
+
+	if (superblock != 0 && blocksize == 0) {
+		com_err(device, 0, "if you specify the superblock, you must also specify the block size");
+		current_fs = NULL;
+		return;
+	}
+
+	if (data_filename) {
+		if ((open_flags & EXT2_FLAG_IMAGE_FILE) == 0) {
+			com_err(device, 0,
+				"The -d option is only valid when reading an e2image file");
+			current_fs = NULL;
+			return;
+		}
+		retval = unix_io_manager->open(data_filename, 0, &data_io);
+		if (retval) {
+			com_err(data_filename, 0, "while opening data source");
+			current_fs = NULL;
+			return;
+		}
+	}
+
+	if (catastrophic && (open_flags & EXT2_FLAG_RW)) {
+		com_err(device, 0,
+			"opening read-only because of catastrophic mode");
+		open_flags &= ~EXT2_FLAG_RW;
+	}
+	if (catastrophic)
+		open_flags |= EXT2_FLAG_SKIP_MMP;
+
+	retval = ext2fs_open(device, open_flags, superblock, blocksize,
+			     unix_io_manager, &current_fs);
+	if (retval) {
+		com_err(device, retval, "while opening filesystem");
+		current_fs = NULL;
+		return;
+	}
+	current_fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE;
+
+	if (catastrophic)
+		com_err(device, 0, "catastrophic mode - not reading inode or group bitmaps");
+	else {
+		retval = ext2fs_read_inode_bitmap(current_fs);
+		if (retval) {
+			com_err(device, retval, "while reading inode bitmap");
+			goto errout;
+		}
+		retval = ext2fs_read_block_bitmap(current_fs);
+		if (retval) {
+			com_err(device, retval, "while reading block bitmap");
+			goto errout;
+		}
+	}
+
+	if (data_io) {
+		retval = ext2fs_set_data_io(current_fs, data_io);
+		if (retval) {
+			com_err(device, retval,
+				"while setting data source");
+			goto errout;
+		}
+	}
+
+	root = cwd = EXT2_ROOT_INO;
+	return;
+
+errout:
+	retval = ext2fs_close(current_fs);
+	if (retval)
+		com_err(device, retval, "while trying to close filesystem");
+	current_fs = NULL;
+}
+
+void do_open_filesys(int argc, char **argv)
+{
+	int	c, err;
+	int	catastrophic = 0;
+	blk64_t	superblock = 0;
+	blk64_t	blocksize = 0;
+	int	open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS; 
+	char	*data_filename = 0;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "iwfecb:s:d:D")) != EOF) {
+		switch (c) {
+		case 'i':
+			open_flags |= EXT2_FLAG_IMAGE_FILE;
+			break;
+		case 'w':
+#ifdef READ_ONLY
+			goto print_usage;
+#else
+			open_flags |= EXT2_FLAG_RW;
+#endif /* READ_ONLY */
+			break;
+		case 'f':
+			open_flags |= EXT2_FLAG_FORCE;
+			break;
+		case 'e':
+			open_flags |= EXT2_FLAG_EXCLUSIVE;
+			break;
+		case 'c':
+			catastrophic = 1;
+			break;
+		case 'd':
+			data_filename = optarg;
+			break;
+		case 'D':
+			open_flags |= EXT2_FLAG_DIRECT_IO;
+			break;
+		case 'b':
+			blocksize = parse_ulong(optarg, argv[0],
+						"block size", &err);
+			if (err)
+				return;
+			break;
+		case 's':
+			err = strtoblk(argv[0], optarg, &superblock);
+			if (err)
+				return;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+	if (optind != argc-1) {
+		goto print_usage;
+	}
+	if (check_fs_not_open(argv[0]))
+		return;
+	open_filesystem(argv[optind], open_flags,
+			superblock, blocksize, catastrophic,
+			data_filename);
+	return;
+
+print_usage:
+	fprintf(stderr, "%s: Usage: open [-s superblock] [-b blocksize] "
+		"[-d image_filename] [-c] [-i] [-f] [-e] [-D] "
+#ifndef READ_ONLY
+		"[-w] "
+#endif
+		"<device>\n", argv[0]);
+}
+
+void do_lcd(int argc, char **argv)
+{
+	if (argc != 2) {
+		com_err(argv[0], 0, "Usage: %s %s", argv[0], "<native dir>");
+		return;
+	}
+
+	if (chdir(argv[1]) == -1) {
+		com_err(argv[0], errno,
+			"while trying to change native directory to %s",
+			argv[1]);
+		return;
+	}
+}
+
+static void close_filesystem(NOARGS)
+{
+	int	retval;
+
+	if (current_fs->flags & EXT2_FLAG_IB_DIRTY) {
+		retval = ext2fs_write_inode_bitmap(current_fs);
+		if (retval)
+			com_err("ext2fs_write_inode_bitmap", retval, 0);
+	}
+	if (current_fs->flags & EXT2_FLAG_BB_DIRTY) {
+		retval = ext2fs_write_block_bitmap(current_fs);
+		if (retval)
+			com_err("ext2fs_write_block_bitmap", retval, 0);
+	}
+	retval = ext2fs_close(current_fs);
+	if (retval)
+		com_err("ext2fs_close", retval, 0);
+	current_fs = NULL;
+	return;
+}
+
+void do_close_filesys(int argc, char **argv)
+{
+	int	c;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "a")) != EOF) {
+		switch (c) {
+		case 'a':
+			current_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+
+	if (argc > optind) {
+	print_usage:
+		com_err(0, 0, "Usage: close_filesys [-a]");
+		return;
+	}
+
+	close_filesystem();
+}
+
+#ifndef READ_ONLY
+void do_init_filesys(int argc, char **argv)
+{
+	struct ext2_super_block param;
+	errcode_t	retval;
+	int		err;
+	blk64_t		blocks;
+
+	if (common_args_process(argc, argv, 3, 3, "initialize",
+				"<device> <blocks>", CHECK_FS_NOTOPEN))
+		return;
+
+	memset(&param, 0, sizeof(struct ext2_super_block));
+	err = strtoblk(argv[0], argv[2], &blocks);
+	if (err)
+		return;
+	ext2fs_blocks_count_set(&param, blocks);
+	if (err)
+		return;
+	retval = ext2fs_initialize(argv[1], 0, &param,
+				   unix_io_manager, &current_fs);
+	if (retval) {
+		com_err(argv[1], retval, "while initializing filesystem");
+		current_fs = NULL;
+		return;
+	}
+	root = cwd = EXT2_ROOT_INO;
+	return;
+}
+
+static void print_features(struct ext2_super_block * s, FILE *f)
+{
+	int	i, j, printed=0;
+	__u32	*mask = &s->s_feature_compat, m;
+
+	fputs("Filesystem features:", f);
+	for (i=0; i <3; i++,mask++) {
+		for (j=0,m=1; j < 32; j++, m<<=1) {
+			if (*mask & m) {
+				fprintf(f, " %s", e2p_feature2string(i, m));
+				printed++;
+			}
+		}
+	}
+	if (printed == 0)
+		fputs("(none)", f);
+	fputs("\n", f);
+}
+#endif /* READ_ONLY */
+
+static void print_bg_opts(ext2_filsys fs, dgrp_t group, int mask,
+			  const char *str, int *first, FILE *f)
+{
+	if (ext2fs_bg_flags_test(fs, group, mask)) {
+		if (*first) {
+			fputs("           [", f);
+			*first = 0;
+		} else
+			fputs(", ", f);
+		fputs(str, f);
+	}
+}
+
+void do_show_super_stats(int argc, char *argv[])
+{
+	const char *units ="block";
+	dgrp_t	i;
+	FILE 	*out;
+	int	c, header_only = 0;
+	int	numdirs = 0, first, gdt_csum;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "h")) != EOF) {
+		switch (c) {
+		case 'h':
+			header_only++;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+	if (optind != argc) {
+		goto print_usage;
+	}
+	if (check_fs_open(argv[0]))
+		return;
+	out = open_pager();
+
+	if (EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super,
+				       EXT4_FEATURE_RO_COMPAT_BIGALLOC))
+		units = "cluster";
+
+	list_super2(current_fs->super, out);
+	for (i=0; i < current_fs->group_desc_count; i++)
+		numdirs += ext2fs_bg_used_dirs_count(current_fs, i);
+	fprintf(out, "Directories:              %d\n", numdirs);
+
+	if (header_only) {
+		close_pager(out);
+		return;
+	}
+
+	gdt_csum = EXT2_HAS_RO_COMPAT_FEATURE(current_fs->super,
+					      EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
+	for (i = 0; i < current_fs->group_desc_count; i++) {
+		fprintf(out, " Group %2d: block bitmap at %llu, "
+		        "inode bitmap at %llu, "
+		        "inode table at %llu\n"
+		        "           %u free %s%s, "
+		        "%u free %s, "
+		        "%u used %s%s",
+		        i, ext2fs_block_bitmap_loc(current_fs, i),
+		        ext2fs_inode_bitmap_loc(current_fs, i),
+			ext2fs_inode_table_loc(current_fs, i),
+		        ext2fs_bg_free_blocks_count(current_fs, i), units,
+		        ext2fs_bg_free_blocks_count(current_fs, i) != 1 ?
+			"s" : "",
+		        ext2fs_bg_free_inodes_count(current_fs, i),
+		        ext2fs_bg_free_inodes_count(current_fs, i) != 1 ?
+			"inodes" : "inode",
+		        ext2fs_bg_used_dirs_count(current_fs, i),
+		        ext2fs_bg_used_dirs_count(current_fs, i) != 1 ? "directories"
+ 				: "directory", gdt_csum ? ", " : "\n");
+		if (gdt_csum)
+			fprintf(out, "%u unused %s\n",
+				ext2fs_bg_itable_unused(current_fs, i),
+				ext2fs_bg_itable_unused(current_fs, i) != 1 ?
+				"inodes" : "inode");
+		first = 1;
+		print_bg_opts(current_fs, i, EXT2_BG_INODE_UNINIT, "Inode not init",
+			      &first, out);
+		print_bg_opts(current_fs, i, EXT2_BG_BLOCK_UNINIT, "Block not init",
+			      &first, out);
+		if (gdt_csum) {
+			fprintf(out, "%sChecksum 0x%04x",
+				first ? "           [":", ", ext2fs_bg_checksum(current_fs, i));
+			first = 0;
+		}
+		if (!first)
+			fputs("]\n", out);
+	}
+	close_pager(out);
+	return;
+print_usage:
+	fprintf(stderr, "%s: Usage: show_super [-h]\n", argv[0]);
+}
+
+#ifndef READ_ONLY
+void do_dirty_filesys(int argc EXT2FS_ATTR((unused)),
+		      char **argv EXT2FS_ATTR((unused)))
+{
+	if (check_fs_open(argv[0]))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+
+	if (argv[1] && !strcmp(argv[1], "-clean"))
+		current_fs->super->s_state |= EXT2_VALID_FS;
+	else
+		current_fs->super->s_state &= ~EXT2_VALID_FS;
+	ext2fs_mark_super_dirty(current_fs);
+}
+#endif /* READ_ONLY */
+
+struct list_blocks_struct {
+	FILE		*f;
+	e2_blkcnt_t	total;
+	blk64_t		first_block, last_block;
+	e2_blkcnt_t	first_bcnt, last_bcnt;
+	e2_blkcnt_t	first;
+};
+
+static void finish_range(struct list_blocks_struct *lb)
+{
+	if (lb->first_block == 0)
+		return;
+	if (lb->first)
+		lb->first = 0;
+	else
+		fprintf(lb->f, ", ");
+	if (lb->first_block == lb->last_block)
+		fprintf(lb->f, "(%lld):%llu",
+			(long long)lb->first_bcnt, lb->first_block);
+	else
+		fprintf(lb->f, "(%lld-%lld):%llu-%llu",
+			(long long)lb->first_bcnt, (long long)lb->last_bcnt,
+			lb->first_block, lb->last_block);
+	lb->first_block = 0;
+}
+
+static int list_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
+			    blk64_t *blocknr, e2_blkcnt_t blockcnt,
+			    blk64_t ref_block EXT2FS_ATTR((unused)),
+			    int ref_offset EXT2FS_ATTR((unused)),
+			    void *private)
+{
+	struct list_blocks_struct *lb = (struct list_blocks_struct *) private;
+
+	lb->total++;
+	if (blockcnt >= 0) {
+		/*
+		 * See if we can add on to the existing range (if it exists)
+		 */
+		if (lb->first_block &&
+		    (lb->last_block+1 == *blocknr) &&
+		    (lb->last_bcnt+1 == blockcnt)) {
+			lb->last_block = *blocknr;
+			lb->last_bcnt = blockcnt;
+			return 0;
+		}
+		/*
+		 * Start a new range.
+		 */
+		finish_range(lb);
+		lb->first_block = lb->last_block = *blocknr;
+		lb->first_bcnt = lb->last_bcnt = blockcnt;
+		return 0;
+	}
+	/*
+	 * Not a normal block.  Always force a new range.
+	 */
+	finish_range(lb);
+	if (lb->first)
+		lb->first = 0;
+	else
+		fprintf(lb->f, ", ");
+	if (blockcnt == -1)
+		fprintf(lb->f, "(IND):%llu", (unsigned long long) *blocknr);
+	else if (blockcnt == -2)
+		fprintf(lb->f, "(DIND):%llu", (unsigned long long) *blocknr);
+	else if (blockcnt == -3)
+		fprintf(lb->f, "(TIND):%llu", (unsigned long long) *blocknr);
+	return 0;
+}
+
+static void dump_xattr_string(FILE *out, const char *str, int len)
+{
+	int printable = 0;
+	int i;
+
+	/* check: is string "printable enough?" */
+	for (i = 0; i < len; i++)
+		if (isprint(str[i]))
+			printable++;
+
+	if (printable <= len*7/8)
+		printable = 0;
+
+	for (i = 0; i < len; i++)
+		if (printable)
+			fprintf(out, isprint(str[i]) ? "%c" : "\\%03o",
+				(unsigned char)str[i]);
+		else
+			fprintf(out, "%02x ", (unsigned char)str[i]);
+}
+
+static void internal_dump_inode_extra(FILE *out,
+				      const char *prefix EXT2FS_ATTR((unused)),
+				      ext2_ino_t inode_num EXT2FS_ATTR((unused)),
+				      struct ext2_inode_large *inode)
+{
+	struct ext2_ext_attr_entry *entry;
+	__u32 *magic;
+	char *start, *end;
+	unsigned int storage_size;
+
+	fprintf(out, "Size of extra inode fields: %u\n", inode->i_extra_isize);
+	if (inode->i_extra_isize > EXT2_INODE_SIZE(current_fs->super) -
+			EXT2_GOOD_OLD_INODE_SIZE) {
+		fprintf(stderr, "invalid inode->i_extra_isize (%u)\n",
+				inode->i_extra_isize);
+		return;
+	}
+	storage_size = EXT2_INODE_SIZE(current_fs->super) -
+			EXT2_GOOD_OLD_INODE_SIZE -
+			inode->i_extra_isize;
+	magic = (__u32 *)((char *)inode + EXT2_GOOD_OLD_INODE_SIZE +
+			inode->i_extra_isize);
+	if (*magic == EXT2_EXT_ATTR_MAGIC) {
+		fprintf(out, "Extended attributes stored in inode body: \n");
+		end = (char *) inode + EXT2_INODE_SIZE(current_fs->super);
+		start = (char *) magic + sizeof(__u32);
+		entry = (struct ext2_ext_attr_entry *) start;
+		while (!EXT2_EXT_IS_LAST_ENTRY(entry)) {
+			struct ext2_ext_attr_entry *next =
+				EXT2_EXT_ATTR_NEXT(entry);
+			if (entry->e_value_size > storage_size ||
+					(char *) next >= end) {
+				fprintf(out, "invalid EA entry in inode\n");
+				return;
+			}
+			fprintf(out, "  ");
+			dump_xattr_string(out, EXT2_EXT_ATTR_NAME(entry),
+					  entry->e_name_len);
+			fprintf(out, " = \"");
+			dump_xattr_string(out, start + entry->e_value_offs,
+						entry->e_value_size);
+			fprintf(out, "\" (%u)\n", entry->e_value_size);
+			entry = next;
+		}
+	}
+}
+
+static void dump_blocks(FILE *f, const char *prefix, ext2_ino_t inode)
+{
+	struct list_blocks_struct lb;
+
+	fprintf(f, "%sBLOCKS:\n%s", prefix, prefix);
+	lb.total = 0;
+	lb.first_block = 0;
+	lb.f = f;
+	lb.first = 1;
+	ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
+			      list_blocks_proc, (void *)&lb);
+	finish_range(&lb);
+	if (lb.total)
+		fprintf(f, "\n%sTOTAL: %lld\n", prefix, (long long)lb.total);
+	fprintf(f,"\n");
+}
+
+static int int_log10(unsigned long long arg)
+{
+	int     l = 0;
+
+	arg = arg / 10;
+	while (arg) {
+		l++;
+		arg = arg / 10;
+	}
+	return l;
+}
+
+#define DUMP_LEAF_EXTENTS	0x01
+#define DUMP_NODE_EXTENTS	0x02
+#define DUMP_EXTENT_TABLE	0x04
+
+static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
+			 int flags, int logical_width, int physical_width)
+{
+	ext2_extent_handle_t	handle;
+	struct ext2fs_extent	extent;
+	struct ext2_extent_info info;
+	int			op = EXT2_EXTENT_ROOT;
+	unsigned int		printed = 0;
+	errcode_t 		errcode;
+
+	errcode = ext2fs_extent_open(current_fs, ino, &handle);
+	if (errcode)
+		return;
+
+	if (flags & DUMP_EXTENT_TABLE)
+		fprintf(f, "Level Entries %*s %*s Length Flags\n",
+			(logical_width*2)+3, "Logical",
+			(physical_width*2)+3, "Physical");
+	else
+		fprintf(f, "%sEXTENTS:\n%s", prefix, prefix);
+
+	while (1) {
+		errcode = ext2fs_extent_get(handle, op, &extent);
+
+		if (errcode)
+			break;
+
+		op = EXT2_EXTENT_NEXT;
+
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
+			continue;
+
+		if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) {
+			if ((flags & DUMP_LEAF_EXTENTS) == 0)
+				continue;
+		} else {
+			if ((flags & DUMP_NODE_EXTENTS) == 0)
+				continue;
+		}
+
+		errcode = ext2fs_extent_get_info(handle, &info);
+		if (errcode)
+			continue;
+
+		if (!(extent.e_flags & EXT2_EXTENT_FLAGS_LEAF)) {
+			if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
+				continue;
+
+			if (flags & DUMP_EXTENT_TABLE) {
+				fprintf(f, "%2d/%2d %3d/%3d %*llu - %*llu "
+					"%*llu%*s %6u\n",
+					info.curr_level, info.max_depth,
+					info.curr_entry, info.num_entries,
+					logical_width,
+					extent.e_lblk,
+					logical_width,
+					extent.e_lblk + (extent.e_len - 1),
+					physical_width,
+					extent.e_pblk,
+					physical_width+3, "", extent.e_len);
+				continue;
+			}
+
+			fprintf(f, "%s(ETB%d):%lld",
+				printed ? ", " : "", info.curr_level,
+				extent.e_pblk);
+			printed = 1;
+			continue;
+		}
+
+		if (flags & DUMP_EXTENT_TABLE) {
+			fprintf(f, "%2d/%2d %3d/%3d %*llu - %*llu "
+				"%*llu - %*llu %6u %s\n",
+				info.curr_level, info.max_depth,
+				info.curr_entry, info.num_entries,
+				logical_width,
+				extent.e_lblk,
+				logical_width,
+				extent.e_lblk + (extent.e_len - 1),
+				physical_width,
+				extent.e_pblk,
+				physical_width,
+				extent.e_pblk + (extent.e_len - 1),
+				extent.e_len,
+				extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
+					"Uninit" : "");
+			continue;
+		}
+
+		if (extent.e_len == 0)
+			continue;
+		else if (extent.e_len == 1)
+			fprintf(f,
+				"%s(%lld%s):%lld",
+				printed ? ", " : "",
+				extent.e_lblk,
+				extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
+				"[u]" : "",
+				extent.e_pblk);
+		else
+			fprintf(f,
+				"%s(%lld-%lld%s):%lld-%lld",
+				printed ? ", " : "",
+				extent.e_lblk,
+				extent.e_lblk + (extent.e_len - 1),
+				extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT ?
+					"[u]" : "",
+				extent.e_pblk,
+				extent.e_pblk + (extent.e_len - 1));
+		printed = 1;
+	}
+	if (printed)
+		fprintf(f, "\n");
+}
+
+void internal_dump_inode(FILE *out, const char *prefix,
+			 ext2_ino_t inode_num, struct ext2_inode *inode,
+			 int do_dump_blocks)
+{
+	const char *i_type;
+	char frag, fsize;
+	int os = current_fs->super->s_creator_os;
+	struct ext2_inode_large *large_inode;
+	int is_large_inode = 0;
+
+	if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
+		is_large_inode = 1;
+	large_inode = (struct ext2_inode_large *) inode;
+
+	if (LINUX_S_ISDIR(inode->i_mode)) i_type = "directory";
+	else if (LINUX_S_ISREG(inode->i_mode)) i_type = "regular";
+	else if (LINUX_S_ISLNK(inode->i_mode)) i_type = "symlink";
+	else if (LINUX_S_ISBLK(inode->i_mode)) i_type = "block special";
+	else if (LINUX_S_ISCHR(inode->i_mode)) i_type = "character special";
+	else if (LINUX_S_ISFIFO(inode->i_mode)) i_type = "FIFO";
+	else if (LINUX_S_ISSOCK(inode->i_mode)) i_type = "socket";
+	else i_type = "bad type";
+	fprintf(out, "%sInode: %u   Type: %s    ", prefix, inode_num, i_type);
+	fprintf(out, "%sMode:  %04o   Flags: 0x%x\n",
+		prefix, inode->i_mode & 0777, inode->i_flags);
+	if (is_large_inode && large_inode->i_extra_isize >= 24) {
+		fprintf(out, "%sGeneration: %u    Version: 0x%08x:%08x\n",
+			prefix, inode->i_generation, large_inode->i_version_hi,
+			inode->osd1.linux1.l_i_version);
+	} else {
+		fprintf(out, "%sGeneration: %u    Version: 0x%08x\n", prefix,
+			inode->i_generation, inode->osd1.linux1.l_i_version);
+	}
+	fprintf(out, "%sUser: %5d   Group: %5d   Size: ",
+		prefix, inode_uid(*inode), inode_gid(*inode));
+	if (LINUX_S_ISREG(inode->i_mode))
+		fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
+	else
+		fprintf(out, "%d\n", inode->i_size);
+	if (os == EXT2_OS_HURD)
+		fprintf(out,
+			"%sFile ACL: %d    Directory ACL: %d Translator: %d\n",
+			prefix,
+			inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0,
+			inode->osd1.hurd1.h_i_translator);
+	else
+		fprintf(out, "%sFile ACL: %llu    Directory ACL: %d\n",
+			prefix,
+			inode->i_file_acl | ((long long)
+				(inode->osd2.linux2.l_i_file_acl_high) << 32),
+			LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0);
+	if (os == EXT2_OS_LINUX)
+		fprintf(out, "%sLinks: %d   Blockcount: %llu\n",
+			prefix, inode->i_links_count,
+			(((unsigned long long)
+			  inode->osd2.linux2.l_i_blocks_hi << 32)) +
+			inode->i_blocks);
+	else
+		fprintf(out, "%sLinks: %d   Blockcount: %u\n",
+			prefix, inode->i_links_count, inode->i_blocks);
+	switch (os) {
+	    case EXT2_OS_HURD:
+		frag = inode->osd2.hurd2.h_i_frag;
+		fsize = inode->osd2.hurd2.h_i_fsize;
+		break;
+	    default:
+		frag = fsize = 0;
+	}
+	fprintf(out, "%sFragment:  Address: %d    Number: %d    Size: %d\n",
+		prefix, inode->i_faddr, frag, fsize);
+	if (is_large_inode && large_inode->i_extra_isize >= 24) {
+		fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix,
+			inode->i_ctime, large_inode->i_ctime_extra,
+			time_to_string(inode->i_ctime));
+		fprintf(out, "%s atime: 0x%08x:%08x -- %s", prefix,
+			inode->i_atime, large_inode->i_atime_extra,
+			time_to_string(inode->i_atime));
+		fprintf(out, "%s mtime: 0x%08x:%08x -- %s", prefix,
+			inode->i_mtime, large_inode->i_mtime_extra,
+			time_to_string(inode->i_mtime));
+		fprintf(out, "%scrtime: 0x%08x:%08x -- %s", prefix,
+			large_inode->i_crtime, large_inode->i_crtime_extra,
+			time_to_string(large_inode->i_crtime));
+	} else {
+		fprintf(out, "%sctime: 0x%08x -- %s", prefix, inode->i_ctime,
+			time_to_string(inode->i_ctime));
+		fprintf(out, "%satime: 0x%08x -- %s", prefix, inode->i_atime,
+			time_to_string(inode->i_atime));
+		fprintf(out, "%smtime: 0x%08x -- %s", prefix, inode->i_mtime,
+			time_to_string(inode->i_mtime));
+	}
+	if (inode->i_dtime)
+	  fprintf(out, "%sdtime: 0x%08x -- %s", prefix, inode->i_dtime,
+		  time_to_string(inode->i_dtime));
+	if (EXT2_INODE_SIZE(current_fs->super) > EXT2_GOOD_OLD_INODE_SIZE)
+		internal_dump_inode_extra(out, prefix, inode_num,
+					  (struct ext2_inode_large *) inode);
+	if (LINUX_S_ISLNK(inode->i_mode) && ext2fs_inode_data_blocks(current_fs,inode) == 0)
+		fprintf(out, "%sFast_link_dest: %.*s\n", prefix,
+			(int) inode->i_size, (char *)inode->i_block);
+	else if (LINUX_S_ISBLK(inode->i_mode) || LINUX_S_ISCHR(inode->i_mode)) {
+		int major, minor;
+		const char *devnote;
+
+		if (inode->i_block[0]) {
+			major = (inode->i_block[0] >> 8) & 255;
+			minor = inode->i_block[0] & 255;
+			devnote = "";
+		} else {
+			major = (inode->i_block[1] & 0xfff00) >> 8;
+			minor = ((inode->i_block[1] & 0xff) |
+				 ((inode->i_block[1] >> 12) & 0xfff00));
+			devnote = "(New-style) ";
+		}
+		fprintf(out, "%sDevice major/minor number: %02d:%02d (hex %02x:%02x)\n",
+			devnote, major, minor, major, minor);
+	} else if (do_dump_blocks) {
+		if (inode->i_flags & EXT4_EXTENTS_FL)
+			dump_extents(out, prefix, inode_num,
+				     DUMP_LEAF_EXTENTS|DUMP_NODE_EXTENTS, 0, 0);
+		else
+			dump_blocks(out, prefix, inode_num);
+	}
+}
+
+static void dump_inode(ext2_ino_t inode_num, struct ext2_inode *inode)
+{
+	FILE	*out;
+
+	out = open_pager();
+	internal_dump_inode(out, "", inode_num, inode, 1);
+	close_pager(out);
+}
+
+void do_stat(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+	struct ext2_inode * inode_buf;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	inode_buf = (struct ext2_inode *)
+			malloc(EXT2_INODE_SIZE(current_fs->super));
+	if (!inode_buf) {
+		fprintf(stderr, "do_stat: can't allocate buffer\n");
+		return;
+	}
+
+	if (common_inode_args_process(argc, argv, &inode, 0)) {
+		free(inode_buf);
+		return;
+	}
+
+	if (debugfs_read_inode_full(inode, inode_buf, argv[0],
+					EXT2_INODE_SIZE(current_fs->super))) {
+		free(inode_buf);
+		return;
+	}
+
+	dump_inode(inode, inode_buf);
+	free(inode_buf);
+	return;
+}
+
+void do_dump_extents(int argc, char **argv)
+{
+	struct ext2_inode inode;
+	ext2_ino_t	ino;
+	FILE		*out;
+	int		c, flags = 0;
+	int		logical_width;
+	int		physical_width;
+
+	reset_getopt();
+	while ((c = getopt(argc, argv, "nl")) != EOF) {
+		switch (c) {
+		case 'n':
+			flags |= DUMP_NODE_EXTENTS;
+			break;
+		case 'l':
+			flags |= DUMP_LEAF_EXTENTS;
+			break;
+		}
+	}
+
+	if (argc != optind + 1) {
+		com_err(0, 0, "Usage: dump_extents [-n] [-l] file");
+		return;
+	}
+
+	if (flags == 0)
+		flags = DUMP_NODE_EXTENTS | DUMP_LEAF_EXTENTS;
+	flags |= DUMP_EXTENT_TABLE;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	ino = string_to_inode(argv[optind]);
+	if (ino == 0)
+		return;
+
+	if (debugfs_read_inode(ino, &inode, argv[0]))
+		return;
+
+	if ((inode.i_flags & EXT4_EXTENTS_FL) == 0) {
+		fprintf(stderr, "%s: does not uses extent block maps\n",
+			argv[optind]);
+		return;
+	}
+
+	logical_width = int_log10((EXT2_I_SIZE(&inode)+current_fs->blocksize-1)/
+				  current_fs->blocksize) + 1;
+	if (logical_width < 5)
+		logical_width = 5;
+	physical_width = int_log10(ext2fs_blocks_count(current_fs->super)) + 1;
+	if (physical_width < 5)
+		physical_width = 5;
+
+	out = open_pager();
+	dump_extents(out, "", ino, flags, logical_width, physical_width);
+	close_pager(out);
+	return;
+}
+
+static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
+			     blk64_t *blocknr,
+			     e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+			     blk64_t ref_block EXT2FS_ATTR((unused)),
+			     int ref_offset EXT2FS_ATTR((unused)),
+			     void *private EXT2FS_ATTR((unused)))
+{
+	printf("%llu ", *blocknr);
+	return 0;
+}
+
+void do_blocks(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (common_inode_args_process(argc, argv, &inode, 0)) {
+		return;
+	}
+
+	ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
+			      print_blocks_proc, NULL);
+	fputc('\n', stdout);
+	return;
+}
+
+void do_chroot(int argc, char *argv[])
+{
+	ext2_ino_t inode;
+	int retval;
+
+	if (common_inode_args_process(argc, argv, &inode, 0))
+		return;
+
+	retval = ext2fs_check_directory(current_fs, inode);
+	if (retval)  {
+		com_err(argv[1], retval, 0);
+		return;
+	}
+	root = inode;
+}
+
+#ifndef READ_ONLY
+void do_clri(int argc, char *argv[])
+{
+	ext2_ino_t inode;
+	struct ext2_inode inode_buf;
+
+	if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW))
+		return;
+
+	if (debugfs_read_inode(inode, &inode_buf, argv[0]))
+		return;
+	memset(&inode_buf, 0, sizeof(inode_buf));
+	if (debugfs_write_inode(inode, &inode_buf, argv[0]))
+		return;
+}
+
+void do_freei(int argc, char *argv[])
+{
+	unsigned int	len = 1;
+	int		err = 0;
+	ext2_ino_t	inode;
+
+	if (common_args_process(argc, argv, 2, 3, argv[0], "<file> [num]",
+				CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+
+	inode = string_to_inode(argv[1]);
+	if (!inode)
+		return;
+
+	if (argc == 3) {
+		len = parse_ulong(argv[2], argv[0], "length", &err);
+		if (err)
+			return;
+	}
+
+	if (len == 1 &&
+	    !ext2fs_test_inode_bitmap2(current_fs->inode_map,inode))
+		com_err(argv[0], 0, "Warning: inode already clear");
+	while (len-- > 0)
+		ext2fs_unmark_inode_bitmap2(current_fs->inode_map, inode++);
+	ext2fs_mark_ib_dirty(current_fs);
+}
+
+void do_seti(int argc, char *argv[])
+{
+	unsigned int	len = 1;
+	int		err = 0;
+	ext2_ino_t	inode;
+
+	if (common_args_process(argc, argv, 2, 3, argv[0], "<file> [num]",
+				CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+
+	inode = string_to_inode(argv[1]);
+	if (!inode)
+		return;
+
+	if (argc == 3) {
+		len = parse_ulong(argv[2], argv[0], "length", &err);
+		if (err)
+			return;
+	}
+
+	if ((len == 1) &&
+	    ext2fs_test_inode_bitmap2(current_fs->inode_map,inode))
+		com_err(argv[0], 0, "Warning: inode already set");
+	while (len-- > 0)
+		ext2fs_mark_inode_bitmap2(current_fs->inode_map, inode++);
+	ext2fs_mark_ib_dirty(current_fs);
+}
+#endif /* READ_ONLY */
+
+void do_testi(int argc, char *argv[])
+{
+	ext2_ino_t inode;
+
+	if (common_inode_args_process(argc, argv, &inode, CHECK_FS_BITMAPS))
+		return;
+
+	if (ext2fs_test_inode_bitmap2(current_fs->inode_map,inode))
+		printf("Inode %u is marked in use\n", inode);
+	else
+		printf("Inode %u is not in use\n", inode);
+}
+
+#ifndef READ_ONLY
+void do_freeb(int argc, char *argv[])
+{
+	blk64_t block;
+	blk64_t count = 1;
+
+	if (common_block_args_process(argc, argv, &block, &count))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+	while (count-- > 0) {
+		if (!ext2fs_test_block_bitmap2(current_fs->block_map,block))
+			com_err(argv[0], 0, "Warning: block %llu already clear",
+				block);
+		ext2fs_unmark_block_bitmap2(current_fs->block_map,block);
+		block++;
+	}
+	ext2fs_mark_bb_dirty(current_fs);
+}
+
+void do_setb(int argc, char *argv[])
+{
+	blk64_t block;
+	blk64_t count = 1;
+
+	if (common_block_args_process(argc, argv, &block, &count))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+	while (count-- > 0) {
+		if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
+			com_err(argv[0], 0, "Warning: block %llu already set",
+				block);
+		ext2fs_mark_block_bitmap2(current_fs->block_map,block);
+		block++;
+	}
+	ext2fs_mark_bb_dirty(current_fs);
+}
+#endif /* READ_ONLY */
+
+void do_testb(int argc, char *argv[])
+{
+	blk64_t block;
+	blk64_t count = 1;
+
+	if (common_block_args_process(argc, argv, &block, &count))
+		return;
+	while (count-- > 0) {
+		if (ext2fs_test_block_bitmap2(current_fs->block_map,block))
+			printf("Block %llu marked in use\n", block);
+		else
+			printf("Block %llu not in use\n", block);
+		block++;
+	}
+}
+
+#ifndef READ_ONLY
+static void modify_u8(char *com, const char *prompt,
+		      const char *format, __u8 *val)
+{
+	char buf[200];
+	unsigned long v;
+	char *tmp;
+
+	sprintf(buf, format, *val);
+	printf("%30s    [%s] ", prompt, buf);
+	if (!fgets(buf, sizeof(buf), stdin))
+		return;
+	if (buf[strlen (buf) - 1] == '\n')
+		buf[strlen (buf) - 1] = '\0';
+	if (!buf[0])
+		return;
+	v = strtoul(buf, &tmp, 0);
+	if (*tmp)
+		com_err(com, 0, "Bad value - %s", buf);
+	else
+		*val = v;
+}
+
+static void modify_u16(char *com, const char *prompt,
+		       const char *format, __u16 *val)
+{
+	char buf[200];
+	unsigned long v;
+	char *tmp;
+
+	sprintf(buf, format, *val);
+	printf("%30s    [%s] ", prompt, buf);
+	if (!fgets(buf, sizeof(buf), stdin))
+		return;
+	if (buf[strlen (buf) - 1] == '\n')
+		buf[strlen (buf) - 1] = '\0';
+	if (!buf[0])
+		return;
+	v = strtoul(buf, &tmp, 0);
+	if (*tmp)
+		com_err(com, 0, "Bad value - %s", buf);
+	else
+		*val = v;
+}
+
+static void modify_u32(char *com, const char *prompt,
+		       const char *format, __u32 *val)
+{
+	char buf[200];
+	unsigned long v;
+	char *tmp;
+
+	sprintf(buf, format, *val);
+	printf("%30s    [%s] ", prompt, buf);
+	if (!fgets(buf, sizeof(buf), stdin))
+		return;
+	if (buf[strlen (buf) - 1] == '\n')
+		buf[strlen (buf) - 1] = '\0';
+	if (!buf[0])
+		return;
+	v = strtoul(buf, &tmp, 0);
+	if (*tmp)
+		com_err(com, 0, "Bad value - %s", buf);
+	else
+		*val = v;
+}
+
+
+void do_modify_inode(int argc, char *argv[])
+{
+	struct ext2_inode inode;
+	ext2_ino_t	inode_num;
+	int 		i;
+	unsigned char	*frag, *fsize;
+	char		buf[80];
+	int 		os;
+	const char	*hex_format = "0x%x";
+	const char	*octal_format = "0%o";
+	const char	*decimal_format = "%d";
+	const char	*unsignedlong_format = "%lu";
+
+	if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW))
+		return;
+
+	os = current_fs->super->s_creator_os;
+
+	if (debugfs_read_inode(inode_num, &inode, argv[1]))
+		return;
+
+	modify_u16(argv[0], "Mode", octal_format, &inode.i_mode);
+	modify_u16(argv[0], "User ID", decimal_format, &inode.i_uid);
+	modify_u16(argv[0], "Group ID", decimal_format, &inode.i_gid);
+	modify_u32(argv[0], "Size", unsignedlong_format, &inode.i_size);
+	modify_u32(argv[0], "Creation time", decimal_format, &inode.i_ctime);
+	modify_u32(argv[0], "Modification time", decimal_format, &inode.i_mtime);
+	modify_u32(argv[0], "Access time", decimal_format, &inode.i_atime);
+	modify_u32(argv[0], "Deletion time", decimal_format, &inode.i_dtime);
+	modify_u16(argv[0], "Link count", decimal_format, &inode.i_links_count);
+	if (os == EXT2_OS_LINUX)
+		modify_u16(argv[0], "Block count high", unsignedlong_format,
+			   &inode.osd2.linux2.l_i_blocks_hi);
+	modify_u32(argv[0], "Block count", unsignedlong_format, &inode.i_blocks);
+	modify_u32(argv[0], "File flags", hex_format, &inode.i_flags);
+	modify_u32(argv[0], "Generation", hex_format, &inode.i_generation);
+#if 0
+	modify_u32(argv[0], "Reserved1", decimal_format, &inode.i_reserved1);
+#endif
+	modify_u32(argv[0], "File acl", decimal_format, &inode.i_file_acl);
+	if (LINUX_S_ISDIR(inode.i_mode))
+		modify_u32(argv[0], "Directory acl", decimal_format, &inode.i_dir_acl);
+	else
+		modify_u32(argv[0], "High 32bits of size", decimal_format, &inode.i_size_high);
+
+	if (os == EXT2_OS_HURD)
+		modify_u32(argv[0], "Translator Block",
+			    decimal_format, &inode.osd1.hurd1.h_i_translator);
+
+	modify_u32(argv[0], "Fragment address", decimal_format, &inode.i_faddr);
+	switch (os) {
+	    case EXT2_OS_HURD:
+		frag = &inode.osd2.hurd2.h_i_frag;
+		fsize = &inode.osd2.hurd2.h_i_fsize;
+		break;
+	    default:
+		frag = fsize = 0;
+	}
+	if (frag)
+		modify_u8(argv[0], "Fragment number", decimal_format, frag);
+	if (fsize)
+		modify_u8(argv[0], "Fragment size", decimal_format, fsize);
+
+	for (i=0;  i < EXT2_NDIR_BLOCKS; i++) {
+		sprintf(buf, "Direct Block #%d", i);
+		modify_u32(argv[0], buf, decimal_format, &inode.i_block[i]);
+	}
+	modify_u32(argv[0], "Indirect Block", decimal_format,
+		    &inode.i_block[EXT2_IND_BLOCK]);
+	modify_u32(argv[0], "Double Indirect Block", decimal_format,
+		    &inode.i_block[EXT2_DIND_BLOCK]);
+	modify_u32(argv[0], "Triple Indirect Block", decimal_format,
+		    &inode.i_block[EXT2_TIND_BLOCK]);
+	if (debugfs_write_inode(inode_num, &inode, argv[1]))
+		return;
+}
+#endif /* READ_ONLY */
+
+void do_change_working_dir(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+	int		retval;
+
+	if (common_inode_args_process(argc, argv, &inode, 0))
+		return;
+
+	retval = ext2fs_check_directory(current_fs, inode);
+	if (retval) {
+		com_err(argv[1], retval, 0);
+		return;
+	}
+	cwd = inode;
+	return;
+}
+
+void do_print_working_directory(int argc, char *argv[])
+{
+	int	retval;
+	char	*pathname = NULL;
+
+	if (common_args_process(argc, argv, 1, 1,
+				"print_working_directory", "", 0))
+		return;
+
+	retval = ext2fs_get_pathname(current_fs, cwd, 0, &pathname);
+	if (retval) {
+		com_err(argv[0], retval,
+			"while trying to get pathname of cwd");
+	}
+	printf("[pwd]   INODE: %6u  PATH: %s\n",
+	       cwd, pathname ? pathname : "NULL");
+        if (pathname) {
+		free(pathname);
+		pathname = NULL;
+        }
+	retval = ext2fs_get_pathname(current_fs, root, 0, &pathname);
+	if (retval) {
+		com_err(argv[0], retval,
+			"while trying to get pathname of root");
+	}
+	printf("[root]  INODE: %6u  PATH: %s\n",
+	       root, pathname ? pathname : "NULL");
+	if (pathname) {
+		free(pathname);
+		pathname = NULL;
+	}
+	return;
+}
+
+#ifndef READ_ONLY
+static void make_link(char *sourcename, char *destname)
+{
+	ext2_ino_t	ino;
+	struct ext2_inode inode;
+	int		retval;
+	ext2_ino_t	dir;
+	char		*dest, *cp, *base_name;
+
+	/*
+	 * Get the source inode
+	 */
+	ino = string_to_inode(sourcename);
+	if (!ino)
+		return;
+	base_name = strrchr(sourcename, '/');
+	if (base_name)
+		base_name++;
+	else
+		base_name = sourcename;
+	/*
+	 * Figure out the destination.  First see if it exists and is
+	 * a directory.
+	 */
+	if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir)))
+		dest = base_name;
+	else {
+		/*
+		 * OK, it doesn't exist.  See if it is
+		 * '<dir>/basename' or 'basename'
+		 */
+		cp = strrchr(destname, '/');
+		if (cp) {
+			*cp = 0;
+			dir = string_to_inode(destname);
+			if (!dir)
+				return;
+			dest = cp+1;
+		} else {
+			dir = cwd;
+			dest = destname;
+		}
+	}
+
+	if (debugfs_read_inode(ino, &inode, sourcename))
+		return;
+
+	retval = ext2fs_link(current_fs, dir, dest, ino,
+			     ext2_file_type(inode.i_mode));
+	if (retval)
+		com_err("make_link", retval, 0);
+	return;
+}
+
+
+void do_link(int argc, char *argv[])
+{
+	if (common_args_process(argc, argv, 3, 3, "link",
+				"<source file> <dest_name>", CHECK_FS_RW))
+		return;
+
+	make_link(argv[1], argv[2]);
+}
+
+static int mark_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
+			    e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+			    blk64_t ref_block EXT2FS_ATTR((unused)),
+			    int ref_offset EXT2FS_ATTR((unused)),
+			    void *private EXT2FS_ATTR((unused)))
+{
+	blk64_t	block;
+
+	block = *blocknr;
+	ext2fs_block_alloc_stats2(fs, block, +1);
+	return 0;
+}
+
+void do_undel(int argc, char *argv[])
+{
+	ext2_ino_t	ino;
+	struct ext2_inode inode;
+
+	if (common_args_process(argc, argv, 2, 3, "undelete",
+				"<inode_num> [dest_name]",
+				CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	ino = string_to_inode(argv[1]);
+	if (!ino)
+		return;
+
+	if (debugfs_read_inode(ino, &inode, argv[1]))
+		return;
+
+	if (ext2fs_test_inode_bitmap2(current_fs->inode_map, ino)) {
+		com_err(argv[1], 0, "Inode is not marked as deleted");
+		return;
+	}
+
+	/*
+	 * XXX this function doesn't handle changing the links count on the
+	 * parent directory when undeleting a directory.
+	 */
+	inode.i_links_count = LINUX_S_ISDIR(inode.i_mode) ? 2 : 1;
+	inode.i_dtime = 0;
+
+	if (debugfs_write_inode(ino, &inode, argv[0]))
+		return;
+
+	ext2fs_block_iterate3(current_fs, ino, BLOCK_FLAG_READ_ONLY, NULL,
+			      mark_blocks_proc, NULL);
+
+	ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0);
+
+	if (argc > 2)
+		make_link(argv[1], argv[2]);
+}
+
+static void unlink_file_by_name(char *filename)
+{
+	int		retval;
+	ext2_ino_t	dir;
+	char		*base_name;
+
+	base_name = strrchr(filename, '/');
+	if (base_name) {
+		*base_name++ = '\0';
+		dir = string_to_inode(filename);
+		if (!dir)
+			return;
+	} else {
+		dir = cwd;
+		base_name = filename;
+	}
+	retval = ext2fs_unlink(current_fs, dir, base_name, 0, 0);
+	if (retval)
+		com_err("unlink_file_by_name", retval, 0);
+	return;
+}
+
+void do_unlink(int argc, char *argv[])
+{
+	if (common_args_process(argc, argv, 2, 2, "link",
+				"<pathname>", CHECK_FS_RW))
+		return;
+
+	unlink_file_by_name(argv[1]);
+}
+#endif /* READ_ONLY */
+
+void do_find_free_block(int argc, char *argv[])
+{
+	blk64_t	free_blk, goal, first_free = 0;
+ 	int		count;
+	errcode_t	retval;
+	char		*tmp;
+
+	if ((argc > 3) || (argc==2 && *argv[1] == '?')) {
+		com_err(argv[0], 0, "Usage: find_free_block [count [goal]]");
+		return;
+	}
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (argc > 1) {
+		count = strtol(argv[1],&tmp,0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad count - %s", argv[1]);
+			return;
+		}
+ 	} else
+		count = 1;
+
+	if (argc > 2) {
+		goal = strtol(argv[2], &tmp, 0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad goal - %s", argv[1]);
+			return;
+		}
+	}
+	else
+		goal = current_fs->super->s_first_data_block;
+
+	printf("Free blocks found: ");
+	free_blk = goal - 1;
+	while (count-- > 0) {
+		retval = ext2fs_new_block2(current_fs, free_blk + 1, 0,
+					   &free_blk);
+		if (first_free) {
+			if (first_free == free_blk)
+				break;
+		} else
+			first_free = free_blk;
+		if (retval) {
+			com_err("ext2fs_new_block", retval, 0);
+			return;
+		} else
+			printf("%llu ", free_blk);
+	}
+ 	printf("\n");
+}
+
+void do_find_free_inode(int argc, char *argv[])
+{
+	ext2_ino_t	free_inode, dir;
+	int		mode;
+	int		retval;
+	char		*tmp;
+
+	if (argc > 3 || (argc>1 && *argv[1] == '?')) {
+		com_err(argv[0], 0, "Usage: find_free_inode [dir] [mode]");
+		return;
+	}
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (argc > 1) {
+		dir = strtol(argv[1], &tmp, 0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad dir - %s", argv[1]);
+			return;
+		}
+	}
+	else
+		dir = root;
+	if (argc > 2) {
+		mode = strtol(argv[2], &tmp, 0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad mode - %s", argv[2]);
+			return;
+		}
+	} else
+		mode = 010755;
+
+	retval = ext2fs_new_inode(current_fs, dir, mode, 0, &free_inode);
+	if (retval)
+		com_err("ext2fs_new_inode", retval, 0);
+	else
+		printf("Free inode found: %u\n", free_inode);
+}
+
+#ifndef READ_ONLY
+static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_holes)
+{
+	ext2_file_t	e2_file;
+	errcode_t	retval;
+	int		got;
+	unsigned int	written;
+	char		*buf;
+	char		*ptr;
+	char		*zero_buf;
+	int		cmp;
+
+	retval = ext2fs_file_open(current_fs, newfile,
+				  EXT2_FILE_WRITE, &e2_file);
+	if (retval)
+		return retval;
+
+	retval = ext2fs_get_mem(bufsize, &buf);
+	if (retval) {
+		com_err("copy_file", retval, "can't allocate buffer\n");
+		return retval;
+	}
+
+	/* This is used for checking whether the whole block is zero */
+	retval = ext2fs_get_memzero(bufsize, &zero_buf);
+	if (retval) {
+		com_err("copy_file", retval, "can't allocate buffer\n");
+		ext2fs_free_mem(&buf);
+		return retval;
+	}
+
+	while (1) {
+		got = read(fd, buf, bufsize);
+		if (got == 0)
+			break;
+		if (got < 0) {
+			retval = errno;
+			goto fail;
+		}
+		ptr = buf;
+
+		/* Sparse copy */
+		if (make_holes) {
+			/* Check whether all is zero */
+			cmp = memcmp(ptr, zero_buf, got);
+			if (cmp == 0) {
+				 /* The whole block is zero, make a hole */
+				retval = ext2fs_file_lseek(e2_file, got, EXT2_SEEK_CUR, NULL);
+				if (retval)
+					goto fail;
+				got = 0;
+			}
+		}
+
+		/* Normal copy */
+		while (got > 0) {
+			retval = ext2fs_file_write(e2_file, ptr,
+						   got, &written);
+			if (retval)
+				goto fail;
+
+			got -= written;
+			ptr += written;
+		}
+	}
+	ext2fs_free_mem(&buf);
+	ext2fs_free_mem(&zero_buf);
+	retval = ext2fs_file_close(e2_file);
+	return retval;
+
+fail:
+	ext2fs_free_mem(&buf);
+	ext2fs_free_mem(&zero_buf);
+	(void) ext2fs_file_close(e2_file);
+	return retval;
+}
+
+
+void do_write(int argc, char *argv[])
+{
+	int		fd;
+	struct stat	statbuf;
+	ext2_ino_t	newfile;
+	errcode_t	retval;
+	struct ext2_inode inode;
+	int		bufsize = IO_BUFSIZE;
+	int		make_holes = 0;
+
+	if (common_args_process(argc, argv, 3, 3, "write",
+				"<native file> <new file>", CHECK_FS_RW))
+		return;
+
+	fd = open(argv[1], O_RDONLY);
+	if (fd < 0) {
+		com_err(argv[1], errno, 0);
+		return;
+	}
+	if (fstat(fd, &statbuf) < 0) {
+		com_err(argv[1], errno, 0);
+		close(fd);
+		return;
+	}
+
+	retval = ext2fs_namei(current_fs, root, cwd, argv[2], &newfile);
+	if (retval == 0) {
+		com_err(argv[0], 0, "The file '%s' already exists\n", argv[2]);
+		close(fd);
+		return;
+	}
+
+	retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		close(fd);
+		return;
+	}
+	printf("Allocated inode: %u\n", newfile);
+	retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
+			     EXT2_FT_REG_FILE);
+	if (retval == EXT2_ET_DIR_NO_SPACE) {
+		retval = ext2fs_expand_dir(current_fs, cwd);
+		if (retval) {
+			com_err(argv[0], retval, "while expanding directory");
+			close(fd);
+			return;
+		}
+		retval = ext2fs_link(current_fs, cwd, argv[2], newfile,
+				     EXT2_FT_REG_FILE);
+	}
+	if (retval) {
+		com_err(argv[2], retval, 0);
+		close(fd);
+		return;
+	}
+        if (ext2fs_test_inode_bitmap2(current_fs->inode_map,newfile))
+		com_err(argv[0], 0, "Warning: inode already set");
+	ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
+	memset(&inode, 0, sizeof(inode));
+	inode.i_mode = (statbuf.st_mode & ~LINUX_S_IFMT) | LINUX_S_IFREG;
+	inode.i_atime = inode.i_ctime = inode.i_mtime =
+		current_fs->now ? current_fs->now : time(0);
+	inode.i_links_count = 1;
+	inode.i_size = statbuf.st_size;
+	if (current_fs->super->s_feature_incompat &
+	    EXT3_FEATURE_INCOMPAT_EXTENTS) {
+		int i;
+		struct ext3_extent_header *eh;
+
+		eh = (struct ext3_extent_header *) &inode.i_block[0];
+		eh->eh_depth = 0;
+		eh->eh_entries = 0;
+		eh->eh_magic = ext2fs_cpu_to_le16(EXT3_EXT_MAGIC);
+		i = (sizeof(inode.i_block) - sizeof(*eh)) /
+			sizeof(struct ext3_extent);
+		eh->eh_max = ext2fs_cpu_to_le16(i);
+		inode.i_flags |= EXT4_EXTENTS_FL;
+	}
+	if (debugfs_write_new_inode(newfile, &inode, argv[0])) {
+		close(fd);
+		return;
+	}
+	if (LINUX_S_ISREG(inode.i_mode)) {
+		if (statbuf.st_blocks < statbuf.st_size / S_BLKSIZE) {
+			make_holes = 1;
+			/*
+			 * Use I/O blocksize as buffer size when
+			 * copying sparse files.
+			 */
+			bufsize = statbuf.st_blksize;
+		}
+		retval = copy_file(fd, newfile, bufsize, make_holes);
+		if (retval)
+			com_err("copy_file", retval, 0);
+	}
+	close(fd);
+}
+
+void do_mknod(int argc, char *argv[])
+{
+	unsigned long	mode, major, minor;
+	ext2_ino_t	newfile;
+	errcode_t 	retval;
+	struct ext2_inode inode;
+	int		filetype, nr;
+
+	if (check_fs_open(argv[0]))
+		return;
+	if (argc < 3 || argv[2][1]) {
+	usage:
+		com_err(argv[0], 0, "Usage: mknod <name> [p| [c|b] <major> <minor>]");
+		return;
+	}
+	mode = minor = major = 0;
+	switch (argv[2][0]) {
+		case 'p':
+			mode = LINUX_S_IFIFO;
+			filetype = EXT2_FT_FIFO;
+			nr = 3;
+			break;
+		case 'c':
+			mode = LINUX_S_IFCHR;
+			filetype = EXT2_FT_CHRDEV;
+			nr = 5;
+			break;
+		case 'b':
+			mode = LINUX_S_IFBLK;
+			filetype = EXT2_FT_BLKDEV;
+			nr = 5;
+			break;
+		default:
+			filetype = 0;
+			nr = 0;
+	}
+	if (nr == 5) {
+		major = strtoul(argv[3], argv+3, 0);
+		minor = strtoul(argv[4], argv+4, 0);
+		if (major > 65535 || minor > 65535 || argv[3][0] || argv[4][0])
+			nr = 0;
+	}
+	if (argc != nr)
+		goto usage;
+	if (check_fs_read_write(argv[0]))
+		return;
+	retval = ext2fs_new_inode(current_fs, cwd, 010755, 0, &newfile);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+	printf("Allocated inode: %u\n", newfile);
+	retval = ext2fs_link(current_fs, cwd, argv[1], newfile, filetype);
+	if (retval == EXT2_ET_DIR_NO_SPACE) {
+		retval = ext2fs_expand_dir(current_fs, cwd);
+		if (retval) {
+			com_err(argv[0], retval, "while expanding directory");
+			return;
+		}
+		retval = ext2fs_link(current_fs, cwd, argv[1], newfile,
+				     filetype);
+	}
+	if (retval) {
+		com_err(argv[1], retval, 0);
+		return;
+	}
+        if (ext2fs_test_inode_bitmap2(current_fs->inode_map,newfile))
+		com_err(argv[0], 0, "Warning: inode already set");
+	ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
+	memset(&inode, 0, sizeof(inode));
+	inode.i_mode = mode;
+	inode.i_atime = inode.i_ctime = inode.i_mtime =
+		current_fs->now ? current_fs->now : time(0);
+	if ((major < 256) && (minor < 256)) {
+		inode.i_block[0] = major*256+minor;
+		inode.i_block[1] = 0;
+	} else {
+		inode.i_block[0] = 0;
+		inode.i_block[1] = (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
+	}
+	inode.i_links_count = 1;
+	if (debugfs_write_new_inode(newfile, &inode, argv[0]))
+		return;
+}
+
+void do_mkdir(int argc, char *argv[])
+{
+	char	*cp;
+	ext2_ino_t	parent;
+	char	*name;
+	errcode_t retval;
+
+	if (common_args_process(argc, argv, 2, 2, "mkdir",
+				"<filename>", CHECK_FS_RW))
+		return;
+
+	cp = strrchr(argv[1], '/');
+	if (cp) {
+		*cp = 0;
+		parent = string_to_inode(argv[1]);
+		if (!parent) {
+			com_err(argv[1], ENOENT, 0);
+			return;
+		}
+		name = cp+1;
+	} else {
+		parent = cwd;
+		name = argv[1];
+	}
+
+try_again:
+	retval = ext2fs_mkdir(current_fs, parent, 0, name);
+	if (retval == EXT2_ET_DIR_NO_SPACE) {
+		retval = ext2fs_expand_dir(current_fs, parent);
+		if (retval) {
+			com_err(argv[0], retval, "while expanding directory");
+			return;
+		}
+		goto try_again;
+	}
+	if (retval) {
+		com_err("ext2fs_mkdir", retval, 0);
+		return;
+	}
+
+}
+
+static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
+			       e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+			       blk64_t ref_block EXT2FS_ATTR((unused)),
+			       int ref_offset EXT2FS_ATTR((unused)),
+			       void *private EXT2FS_ATTR((unused)))
+{
+	blk64_t	block;
+
+	block = *blocknr;
+	ext2fs_block_alloc_stats2(fs, block, -1);
+	return 0;
+}
+
+static void kill_file_by_inode(ext2_ino_t inode)
+{
+	struct ext2_inode inode_buf;
+
+	if (debugfs_read_inode(inode, &inode_buf, 0))
+		return;
+	inode_buf.i_dtime = current_fs->now ? current_fs->now : time(0);
+	if (debugfs_write_inode(inode, &inode_buf, 0))
+		return;
+	if (!ext2fs_inode_has_valid_blocks2(current_fs, &inode_buf))
+		return;
+
+	ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
+			      release_blocks_proc, NULL);
+	printf("\n");
+	ext2fs_inode_alloc_stats2(current_fs, inode, -1,
+				  LINUX_S_ISDIR(inode_buf.i_mode));
+}
+
+
+void do_kill_file(int argc, char *argv[])
+{
+	ext2_ino_t inode_num;
+
+	if (common_inode_args_process(argc, argv, &inode_num, CHECK_FS_RW))
+		return;
+
+	kill_file_by_inode(inode_num);
+}
+
+void do_rm(int argc, char *argv[])
+{
+	int retval;
+	ext2_ino_t inode_num;
+	struct ext2_inode inode;
+
+	if (common_args_process(argc, argv, 2, 2, "rm",
+				"<filename>", CHECK_FS_RW))
+		return;
+
+	retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num);
+	if (retval) {
+		com_err(argv[0], retval, "while trying to resolve filename");
+		return;
+	}
+
+	if (debugfs_read_inode(inode_num, &inode, argv[0]))
+		return;
+
+	if (LINUX_S_ISDIR(inode.i_mode)) {
+		com_err(argv[0], 0, "file is a directory");
+		return;
+	}
+
+	--inode.i_links_count;
+	if (debugfs_write_inode(inode_num, &inode, argv[0]))
+		return;
+
+	unlink_file_by_name(argv[1]);
+	if (inode.i_links_count == 0)
+		kill_file_by_inode(inode_num);
+}
+
+struct rd_struct {
+	ext2_ino_t	parent;
+	int		empty;
+};
+
+static int rmdir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
+		      int	entry EXT2FS_ATTR((unused)),
+		      struct ext2_dir_entry *dirent,
+		      int	offset EXT2FS_ATTR((unused)),
+		      int	blocksize EXT2FS_ATTR((unused)),
+		      char	*buf EXT2FS_ATTR((unused)),
+		      void	*private)
+{
+	struct rd_struct *rds = (struct rd_struct *) private;
+
+	if (dirent->inode == 0)
+		return 0;
+	if (((dirent->name_len&0xFF) == 1) && (dirent->name[0] == '.'))
+		return 0;
+	if (((dirent->name_len&0xFF) == 2) && (dirent->name[0] == '.') &&
+	    (dirent->name[1] == '.')) {
+		rds->parent = dirent->inode;
+		return 0;
+	}
+	rds->empty = 0;
+	return 0;
+}
+
+void do_rmdir(int argc, char *argv[])
+{
+	int retval;
+	ext2_ino_t inode_num;
+	struct ext2_inode inode;
+	struct rd_struct rds;
+
+	if (common_args_process(argc, argv, 2, 2, "rmdir",
+				"<filename>", CHECK_FS_RW))
+		return;
+
+	retval = ext2fs_namei(current_fs, root, cwd, argv[1], &inode_num);
+	if (retval) {
+		com_err(argv[0], retval, "while trying to resolve filename");
+		return;
+	}
+
+	if (debugfs_read_inode(inode_num, &inode, argv[0]))
+		return;
+
+	if (!LINUX_S_ISDIR(inode.i_mode)) {
+		com_err(argv[0], 0, "file is not a directory");
+		return;
+	}
+
+	rds.parent = 0;
+	rds.empty = 1;
+
+	retval = ext2fs_dir_iterate2(current_fs, inode_num, 0,
+				    0, rmdir_proc, &rds);
+	if (retval) {
+		com_err(argv[0], retval, "while iterating over directory");
+		return;
+	}
+	if (rds.empty == 0) {
+		com_err(argv[0], 0, "directory not empty");
+		return;
+	}
+
+	inode.i_links_count = 0;
+	if (debugfs_write_inode(inode_num, &inode, argv[0]))
+		return;
+
+	unlink_file_by_name(argv[1]);
+	kill_file_by_inode(inode_num);
+
+	if (rds.parent) {
+		if (debugfs_read_inode(rds.parent, &inode, argv[0]))
+			return;
+		if (inode.i_links_count > 1)
+			inode.i_links_count--;
+		if (debugfs_write_inode(rds.parent, &inode, argv[0]))
+			return;
+	}
+}
+#endif /* READ_ONLY */
+
+void do_show_debugfs_params(int argc EXT2FS_ATTR((unused)),
+			    char *argv[] EXT2FS_ATTR((unused)))
+{
+	if (current_fs)
+		printf("Open mode: read-%s\n",
+		       current_fs->flags & EXT2_FLAG_RW ? "write" : "only");
+	printf("Filesystem in use: %s\n",
+	       current_fs ? current_fs->device_name : "--none--");
+}
+
+#ifndef READ_ONLY
+void do_expand_dir(int argc, char *argv[])
+{
+	ext2_ino_t inode;
+	int retval;
+
+	if (common_inode_args_process(argc, argv, &inode, CHECK_FS_RW))
+		return;
+
+	retval = ext2fs_expand_dir(current_fs, inode);
+	if (retval)
+		com_err("ext2fs_expand_dir", retval, 0);
+	return;
+}
+
+void do_features(int argc, char *argv[])
+{
+	int	i;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	if ((argc != 1) && check_fs_read_write(argv[0]))
+		return;
+	for (i=1; i < argc; i++) {
+		if (e2p_edit_feature(argv[i],
+				     &current_fs->super->s_feature_compat, 0))
+			com_err(argv[0], 0, "Unknown feature: %s\n",
+				argv[i]);
+		else
+			ext2fs_mark_super_dirty(current_fs);
+	}
+	print_features(current_fs->super, stdout);
+}
+#endif /* READ_ONLY */
+
+void do_bmap(int argc, char *argv[])
+{
+	ext2_ino_t	ino;
+	blk64_t		blk, pblk;
+	int		err;
+	errcode_t	errcode;
+
+	if (common_args_process(argc, argv, 3, 3, argv[0],
+				"<file> logical_blk", 0))
+		return;
+
+	ino = string_to_inode(argv[1]);
+	if (!ino)
+		return;
+	err = strtoblk(argv[0], argv[2], &blk);
+	if (err)
+		return;
+
+	errcode = ext2fs_bmap2(current_fs, ino, 0, 0, 0, blk, 0, &pblk);
+	if (errcode) {
+		com_err(argv[0], errcode,
+			"while mapping logical block %llu\n", blk);
+		return;
+	}
+	printf("%llu\n", pblk);
+}
+
+void do_imap(int argc, char *argv[])
+{
+	ext2_ino_t	ino;
+	unsigned long 	group, block, block_nr, offset;
+
+	if (common_args_process(argc, argv, 2, 2, argv[0],
+				"<file>", 0))
+		return;
+	ino = string_to_inode(argv[1]);
+	if (!ino)
+		return;
+
+	group = (ino - 1) / EXT2_INODES_PER_GROUP(current_fs->super);
+	offset = ((ino - 1) % EXT2_INODES_PER_GROUP(current_fs->super)) *
+		EXT2_INODE_SIZE(current_fs->super);
+	block = offset >> EXT2_BLOCK_SIZE_BITS(current_fs->super);
+	if (!ext2fs_inode_table_loc(current_fs, (unsigned)group)) {
+		com_err(argv[0], 0, "Inode table for group %lu is missing\n",
+			group);
+		return;
+	}
+	block_nr = ext2fs_inode_table_loc(current_fs, (unsigned)group) +
+		block;
+	offset &= (EXT2_BLOCK_SIZE(current_fs->super) - 1);
+
+	printf("Inode %d is part of block group %lu\n"
+	       "\tlocated at block %lu, offset 0x%04lx\n", ino, group,
+	       block_nr, offset);
+
+}
+
+#ifndef READ_ONLY
+void do_set_current_time(int argc, char *argv[])
+{
+	time_t now;
+
+	if (common_args_process(argc, argv, 2, 2, argv[0],
+				"<time>", 0))
+		return;
+
+	now = string_to_time(argv[1]);
+	if (now == ((time_t) -1)) {
+		com_err(argv[0], 0, "Couldn't parse argument as a time: %s\n",
+			argv[1]);
+		return;
+
+	} else {
+		printf("Setting current time to %s\n", time_to_string(now));
+		current_fs->now = now;
+	}
+}
+#endif /* READ_ONLY */
+
+static int find_supp_feature(__u32 *supp, int feature_type, char *name)
+{
+	int compat, bit, ret;
+	unsigned int feature_mask;
+
+	if (name) {
+		if (feature_type == E2P_FS_FEATURE)
+			ret = e2p_string2feature(name, &compat, &feature_mask);
+		else
+			ret = e2p_jrnl_string2feature(name, &compat,
+						      &feature_mask);
+		if (ret)
+			return ret;
+
+		if (!(supp[compat] & feature_mask))
+			return 1;
+	} else {
+	        for (compat = 0; compat < 3; compat++) {
+		        for (bit = 0, feature_mask = 1; bit < 32;
+			     bit++, feature_mask <<= 1) {
+			        if (supp[compat] & feature_mask) {
+					if (feature_type == E2P_FS_FEATURE)
+						fprintf(stdout, " %s",
+						e2p_feature2string(compat,
+						feature_mask));
+					else
+						fprintf(stdout, " %s",
+						e2p_jrnl_feature2string(compat,
+						feature_mask));
+				}
+	        	}
+		}
+	        fprintf(stdout, "\n");
+	}
+
+	return 0;
+}
+
+void do_supported_features(int argc, char *argv[])
+{
+        int	ret;
+	__u32	supp[3] = { EXT2_LIB_FEATURE_COMPAT_SUPP,
+			    EXT2_LIB_FEATURE_INCOMPAT_SUPP,
+			    EXT2_LIB_FEATURE_RO_COMPAT_SUPP };
+	__u32	jrnl_supp[3] = { JFS_KNOWN_COMPAT_FEATURES,
+				 JFS_KNOWN_INCOMPAT_FEATURES,
+				 JFS_KNOWN_ROCOMPAT_FEATURES };
+
+	if (argc > 1) {
+		ret = find_supp_feature(supp, E2P_FS_FEATURE, argv[1]);
+		if (ret) {
+			ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE,
+						argv[1]);
+		}
+		if (ret)
+			com_err(argv[0], 0, "Unknown feature: %s\n", argv[1]);
+		else
+			fprintf(stdout, "Supported feature: %s\n", argv[1]);
+	} else {
+		fprintf(stdout, "Supported features:");
+		ret = find_supp_feature(supp, E2P_FS_FEATURE, NULL);
+		ret = find_supp_feature(jrnl_supp, E2P_JOURNAL_FEATURE, NULL);
+	}
+}
+
+#ifndef READ_ONLY
+void do_punch(int argc, char *argv[])
+{
+	ext2_ino_t	ino;
+	blk64_t		start, end;
+	int		err;
+	errcode_t	errcode;
+
+	if (common_args_process(argc, argv, 3, 4, argv[0],
+				"<file> start_blk [end_blk]",
+				CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	ino = string_to_inode(argv[1]);
+	if (!ino)
+		return;
+	err = strtoblk(argv[0], argv[2], &start);
+	if (err)
+		return;
+	if (argc == 4) {
+		err = strtoblk(argv[0], argv[3], &end);
+		if (err)
+			return;
+	} else
+		end = ~0;
+
+	errcode = ext2fs_punch(current_fs, ino, 0, 0, start, end);
+
+	if (errcode) {
+		com_err(argv[0], errcode,
+			"while truncating inode %u from %llu to %llu\n", ino,
+			(unsigned long long) start, (unsigned long long) end);
+		return;
+	}
+}
+#endif /* READ_ONLY */
+
+void do_symlink(int argc, char *argv[])
+{
+	char		*cp;
+	ext2_ino_t	parent;
+	char		*name, *target;
+	errcode_t	retval;
+
+	if (common_args_process(argc, argv, 3, 3, "symlink",
+				"<filename> <target>", CHECK_FS_RW))
+		return;
+
+	cp = strrchr(argv[1], '/');
+	if (cp) {
+		*cp = 0;
+		parent = string_to_inode(argv[1]);
+		if (!parent) {
+			com_err(argv[1], ENOENT, 0);
+			return;
+		}
+		name = cp+1;
+	} else {
+		parent = cwd;
+		name = argv[1];
+	}
+	target = argv[2];
+
+try_again:
+	retval = ext2fs_symlink(current_fs, parent, 0, name, target);
+	if (retval == EXT2_ET_DIR_NO_SPACE) {
+		retval = ext2fs_expand_dir(current_fs, parent);
+		if (retval) {
+			com_err(argv[0], retval, "while expanding directory");
+			return;
+		}
+		goto try_again;
+	}
+	if (retval) {
+		com_err("ext2fs_symlink", retval, 0);
+		return;
+	}
+
+}
+
+void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
+{
+	struct ext2_super_block *sb;
+	struct mmp_struct *mmp_s;
+	time_t t;
+	errcode_t retval = 0;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	sb  = current_fs->super;
+
+	if (current_fs->mmp_buf == NULL) {
+		retval = ext2fs_get_mem(current_fs->blocksize,
+					&current_fs->mmp_buf);
+		if (retval) {
+			com_err(argv[0], retval, "allocating MMP buffer.\n");
+			return;
+		}
+	}
+
+	mmp_s = current_fs->mmp_buf;
+
+	retval = ext2fs_mmp_read(current_fs, current_fs->super->s_mmp_block,
+				 current_fs->mmp_buf);
+	if (retval) {
+		com_err(argv[0], retval, "reading MMP block.\n");
+		return;
+	}
+
+	t = mmp_s->mmp_time;
+	fprintf(stdout, "block_number: %llu\n", current_fs->super->s_mmp_block);
+	fprintf(stdout, "update_interval: %d\n",
+		current_fs->super->s_mmp_update_interval);
+	fprintf(stdout, "check_interval: %d\n", mmp_s->mmp_check_interval);
+	fprintf(stdout, "sequence: %08x\n", mmp_s->mmp_seq);
+	fprintf(stdout, "time: %lld -- %s", mmp_s->mmp_time, ctime(&t));
+	fprintf(stdout, "node_name: %s\n", mmp_s->mmp_nodename);
+	fprintf(stdout, "device_name: %s\n", mmp_s->mmp_bdevname);
+	fprintf(stdout, "magic: 0x%x\n", mmp_s->mmp_magic);
+}
+
+static int source_file(const char *cmd_file, int ss_idx)
+{
+	FILE		*f;
+	char		buf[BUFSIZ];
+	char		*cp;
+	int		exit_status = 0;
+	int		retval;
+
+	if (strcmp(cmd_file, "-") == 0)
+		f = stdin;
+	else {
+		f = fopen(cmd_file, "r");
+		if (!f) {
+			perror(cmd_file);
+			exit(1);
+		}
+	}
+	fflush(stdout);
+	fflush(stderr);
+	setbuf(stdout, NULL);
+	setbuf(stderr, NULL);
+	while (!feof(f)) {
+		if (fgets(buf, sizeof(buf), f) == NULL)
+			break;
+		cp = strchr(buf, '\n');
+		if (cp)
+			*cp = 0;
+		cp = strchr(buf, '\r');
+		if (cp)
+			*cp = 0;
+		printf("debugfs: %s\n", buf);
+		retval = ss_execute_line(ss_idx, buf);
+		if (retval) {
+			ss_perror(ss_idx, retval, buf);
+			exit_status++;
+		}
+	}
+	if (f != stdin)
+		fclose(f);
+	return exit_status;
+}
+
+int main(int argc, char **argv)
+{
+	int		retval;
+	const char	*usage = 
+		"Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] "
+		"[-R request] [-V] ["
+#ifndef READ_ONLY
+		"[-w] "
+#endif
+		"[-c] device]";
+	int		c;
+	int		open_flags = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
+	char		*request = 0;
+	int		exit_status = 0;
+	char		*cmd_file = 0;
+	blk64_t		superblock = 0;
+	blk64_t		blocksize = 0;
+	int		catastrophic = 0;
+	char		*data_filename = 0;
+#ifdef READ_ONLY
+	const char	*opt_string = "icR:f:b:s:Vd:D";
+#else
+	const char	*opt_string = "iwcR:f:b:s:Vd:D";
+#endif
+
+	if (debug_prog_name == 0)
+#ifdef READ_ONLY
+		debug_prog_name = "rdebugfs";
+#else
+		debug_prog_name = "debugfs";
+#endif
+	add_error_table(&et_ext2_error_table);
+	fprintf (stderr, "%s %s (%s)\n", debug_prog_name,
+		 E2FSPROGS_VERSION, E2FSPROGS_DATE);
+
+	while ((c = getopt (argc, argv, opt_string)) != EOF) {
+		switch (c) {
+		case 'R':
+			request = optarg;
+			break;
+		case 'f':
+			cmd_file = optarg;
+			break;
+		case 'd':
+			data_filename = optarg;
+			break;
+		case 'i':
+			open_flags |= EXT2_FLAG_IMAGE_FILE;
+			break;
+#ifndef READ_ONLY
+		case 'w':
+			open_flags |= EXT2_FLAG_RW;
+			break;
+#endif
+		case 'D':
+			open_flags |= EXT2_FLAG_DIRECT_IO;
+			break;
+		case 'b':
+			blocksize = parse_ulong(optarg, argv[0],
+						"block size", 0);
+			break;
+		case 's':
+			retval = strtoblk(argv[0], optarg, &superblock);
+			if (retval)
+				return 1;
+			break;
+		case 'c':
+			catastrophic = 1;
+			break;
+		case 'V':
+			/* Print version number and exit */
+			fprintf(stderr, "\tUsing %s\n",
+				error_message(EXT2_ET_BASE));
+			exit(0);
+		default:
+			com_err(argv[0], 0, usage, debug_prog_name);
+			return 1;
+		}
+	}
+	if (optind < argc)
+		open_filesystem(argv[optind], open_flags,
+				superblock, blocksize, catastrophic,
+				data_filename);
+
+	sci_idx = ss_create_invocation(debug_prog_name, "0.0", (char *) NULL,
+				       &debug_cmds, &retval);
+	if (retval) {
+		ss_perror(sci_idx, retval, "creating invocation");
+		exit(1);
+	}
+	ss_get_readline(sci_idx);
+
+	(void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval);
+	if (retval) {
+		ss_perror(sci_idx, retval, "adding standard requests");
+		exit (1);
+	}
+	if (extra_cmds)
+		ss_add_request_table (sci_idx, extra_cmds, 1, &retval);
+	if (retval) {
+		ss_perror(sci_idx, retval, "adding extra requests");
+		exit (1);
+	}
+	if (request) {
+		retval = 0;
+		retval = ss_execute_line(sci_idx, request);
+		if (retval) {
+			ss_perror(sci_idx, retval, request);
+			exit_status++;
+		}
+	} else if (cmd_file) {
+		exit_status = source_file(cmd_file, sci_idx);
+	} else {
+		ss_listen(sci_idx);
+	}
+
+	ss_delete_invocation(sci_idx);
+
+	if (current_fs)
+		close_filesystem();
+
+	remove_error_table(&et_ext2_error_table);
+	return exit_status;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.h
new file mode 100644
index 0000000..6b4f6ef
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/debugfs.h
@@ -0,0 +1,178 @@
+/*
+ * debugfs.h --- header file for the debugfs program
+ */
+
+#include "ss/ss.h"
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+
+#ifdef __STDC__
+#define NOARGS void
+#else
+#define NOARGS
+#define const
+#endif
+
+/*
+ * Flags used by the common argument processing functions
+ */
+#define CHECK_FS_RW		0x0001
+#define CHECK_FS_BITMAPS	0x0002
+#define CHECK_FS_NOTOPEN	0x0004
+
+extern ext2_filsys current_fs;
+extern ext2_ino_t	root, cwd;
+extern int sci_idx;
+extern ss_request_table debug_cmds, extent_cmds;
+
+extern void reset_getopt(void);
+extern FILE *open_pager(void);
+extern void close_pager(FILE *stream);
+extern int check_fs_open(char *name);
+extern int check_fs_not_open(char *name);
+extern int check_fs_read_write(char *name);
+extern int check_fs_bitmaps(char *name);
+extern ext2_ino_t string_to_inode(char *str);
+extern char *time_to_string(__u32);
+extern time_t string_to_time(const char *);
+extern unsigned long parse_ulong(const char *str, const char *cmd,
+				 const char *descr, int *err);
+extern unsigned long long parse_ulonglong(const char *str, const char *cmd,
+					  const char *descr, int *err);
+extern int strtoblk(const char *cmd, const char *str, blk64_t *ret);
+extern int common_args_process(int argc, char *argv[], int min_argc,
+			       int max_argc, const char *cmd,
+			       const char *usage, int flags);
+extern int common_inode_args_process(int argc, char *argv[],
+				     ext2_ino_t *inode, int flags);
+extern int common_block_args_process(int argc, char *argv[],
+				     blk64_t *block, blk64_t *count);
+extern int debugfs_read_inode(ext2_ino_t ino, struct ext2_inode * inode,
+			      const char *cmd);
+extern int debugfs_read_inode_full(ext2_ino_t ino, struct ext2_inode * inode,
+				   const char *cmd, int bufsize);
+extern int debugfs_write_inode(ext2_ino_t ino, struct ext2_inode * inode,
+			       const char *cmd);
+extern int debugfs_write_inode_full(ext2_ino_t ino, struct ext2_inode * inode,
+				    const char *cmd, int bufsize);
+extern int debugfs_write_new_inode(ext2_ino_t ino, struct ext2_inode * inode,
+				   const char *cmd);
+extern int ext2_file_type(unsigned int mode);
+
+/* ss command functions */
+
+/* dump.c */
+extern void do_dump(int argc, char **argv);
+extern void do_cat(int argc, char **argv);
+extern void do_rdump(int argc, char **argv);
+
+/* extent_inode.c */
+extern void do_extent_open(int argc, char **argv);
+extern void do_extent_close(int argc, char **argv);
+extern void do_current_node(int argc, char **argv);
+extern void do_root_node(int argc, char **argv);
+extern void do_last_leaf(int argc, char **argv);
+extern void do_first_sib(int argc, char **argv);
+extern void do_last_sib(int argc, char **argv);
+extern void do_next_sib(int argc, char **argv);
+extern void do_prev_sib(int argc, char **argv);
+extern void do_next_leaf(int argc, char **argv);
+extern void do_prev_leaf(int argc, char **argv);
+extern void do_next(int argc, char **argv);
+extern void do_prev(int argc, char **argv);
+extern void do_up(int argc, char **argv);
+extern void do_down(int argc, char **argv);
+extern void do_delete_node(int argc, char **argv);
+extern void do_replace_node(int argc, char **argv);
+extern void do_split_node(int argc, char **argv);
+extern void do_insert_node(int argc, char **argv);
+extern void do_set_bmap(int argc, char **argv);
+extern void do_print_all(int argc, char **argv);
+extern void do_fix_parents(int argc, char **argv);
+extern void do_info(int argc, char **argv);
+extern void do_goto_block(int argc, char **argv);
+
+/* htree.c */
+extern void do_htree_dump(int argc, char **argv);
+extern void do_dx_hash(int argc, char **argv);
+extern void do_dirsearch(int argc, char **argv);
+
+/* logdump.c */
+extern void do_logdump(int argc, char **argv);
+
+/* lsdel.c */
+extern void do_lsdel(int argc, char **argv);
+
+/* icheck.c */
+extern void do_icheck(int argc, char **argv);
+
+/* ncheck.c */
+extern void do_ncheck(int argc, char **argv);
+
+/* set_fields.c */
+extern void do_set_super(int argc, char **);
+extern void do_set_inode(int argc, char **);
+extern void do_set_block_group_descriptor(int argc, char **);
+
+/* unused.c */
+extern void do_dump_unused(int argc, char **argv);
+
+/* debugfs.c */
+extern void internal_dump_inode(FILE *, const char *, ext2_ino_t,
+				struct ext2_inode *, int);
+
+extern void do_dirty_filesys(int argc, char **argv);
+extern void do_open_filesys(int argc, char **argv);
+extern void do_close_filesys(int argc, char **argv);
+extern void do_lcd(int argc, char **argv);
+extern void do_init_filesys(int argc, char **argv);
+extern void do_show_super_stats(int argc, char **argv);
+extern void do_kill_file(int argc, char **argv);
+extern void do_rm(int argc, char **argv);
+extern void do_link(int argc, char **argv);
+extern void do_undel(int argc, char **argv);
+extern void do_unlink(int argc, char **argv);
+extern void do_find_free_block(int argc, char **argv);
+extern void do_find_free_inode(int argc, char **argv);
+extern void do_stat(int argc, char **argv);
+extern void do_dump_extents(int argc, char **argv);
+extern void do_blocks(int argc, char *argv[]);
+
+extern void do_chroot(int argc, char **argv);
+extern void do_clri(int argc, char **argv);
+extern void do_freei(int argc, char **argv);
+extern void do_seti(int argc, char **argv);
+extern void do_testi(int argc, char **argv);
+extern void do_freeb(int argc, char **argv);
+extern void do_setb(int argc, char **argv);
+extern void do_testb(int argc, char **argv);
+extern void do_modify_inode(int argc, char **argv);
+extern void do_list_dir(int argc, char **argv);
+extern void do_change_working_dir(int argc, char **argv);
+extern void do_print_working_directory(int argc, char **argv);
+extern void do_write(int argc, char **argv);
+extern void do_mknod(int argc, char **argv);
+extern void do_mkdir(int argc, char **argv);
+extern void do_rmdir(int argc, char **argv);
+extern void do_show_debugfs_params(int argc, char **argv);
+extern void do_expand_dir(int argc, char **argv);
+extern void do_features(int argc, char **argv);
+extern void do_bmap(int argc, char **argv);
+extern void do_imap(int argc, char **argv);
+extern void do_set_current_time(int argc, char **argv);
+extern void do_supported_features(int argc, char **argv);
+extern void do_punch(int argc, char **argv);
+extern void do_symlink(int argc, char **argv);
+
+extern void do_dump_mmp(int argc, char **argv);
+extern void do_set_mmp_value(int argc, char **argv);
+
+extern void do_freefrag(int argc, char **argv);
+extern void do_filefrag(int argc, char *argv[]);
+
+/* util.c */
+extern time_t string_to_time(const char *arg);
+
+/* zap.c */
+extern void do_zap_block(int argc, char **argv);
+extern void do_block_dump(int argc, char **argv);
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/dump.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/dump.c
new file mode 100644
index 0000000..51bc734
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/dump.c
@@ -0,0 +1,382 @@
+/*
+ * dump.c --- dump the contents of an inode out to a file
+ *
+ * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* for O_LARGEFILE */
+#endif
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <utime.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
+/*
+ * The mode_xlate function translates a linux mode into a native-OS mode_t.
+ */
+static struct {
+	__u16 lmask;
+	mode_t mask;
+} mode_table[] = {
+	{ LINUX_S_IRUSR, S_IRUSR },
+	{ LINUX_S_IWUSR, S_IWUSR },
+	{ LINUX_S_IXUSR, S_IXUSR },
+	{ LINUX_S_IRGRP, S_IRGRP },
+	{ LINUX_S_IWGRP, S_IWGRP },
+	{ LINUX_S_IXGRP, S_IXGRP },
+	{ LINUX_S_IROTH, S_IROTH },
+	{ LINUX_S_IWOTH, S_IWOTH },
+	{ LINUX_S_IXOTH, S_IXOTH },
+	{ 0, 0 }
+};
+
+static mode_t mode_xlate(__u16 lmode)
+{
+	mode_t	mode = 0;
+	int	i;
+
+	for (i=0; mode_table[i].lmask; i++) {
+		if (lmode & mode_table[i].lmask)
+			mode |= mode_table[i].mask;
+	}
+	return mode;
+}
+
+static void fix_perms(const char *cmd, const struct ext2_inode *inode,
+		      int fd, const char *name)
+{
+	struct utimbuf ut;
+	int i;
+
+	if (fd != -1)
+		i = fchmod(fd, mode_xlate(inode->i_mode));
+	else
+		i = chmod(name, mode_xlate(inode->i_mode));
+	if (i == -1)
+		com_err(cmd, errno, "while setting permissions of %s", name);
+
+#ifndef HAVE_FCHOWN
+	i = chown(name, inode->i_uid, inode->i_gid);
+#else
+	if (fd != -1)
+		i = fchown(fd, inode->i_uid, inode->i_gid);
+	else
+		i = chown(name, inode->i_uid, inode->i_gid);
+#endif
+	if (i == -1)
+		com_err(cmd, errno, "while changing ownership of %s", name);
+
+	if (fd != -1)
+		close(fd);
+
+	ut.actime = inode->i_atime;
+	ut.modtime = inode->i_mtime;
+	if (utime(name, &ut) == -1)
+		com_err(cmd, errno, "while setting times of %s", name);
+}
+
+static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
+		      int preserve, char *outname)
+{
+	errcode_t retval;
+	struct ext2_inode	inode;
+	char		*buf = 0;
+	ext2_file_t	e2_file;
+	int		nbytes;
+	unsigned int	got, blocksize = current_fs->blocksize;
+
+	if (debugfs_read_inode(ino, &inode, cmdname))
+		return;
+
+	retval = ext2fs_file_open(current_fs, ino, 0, &e2_file);
+	if (retval) {
+		com_err(cmdname, retval, "while opening ext2 file");
+		return;
+	}
+	retval = ext2fs_get_mem(blocksize, &buf);
+	if (retval) {
+		com_err(cmdname, retval, "while allocating memory");
+		return;
+	}
+	while (1) {
+		retval = ext2fs_file_read(e2_file, buf, blocksize, &got);
+		if (retval)
+			com_err(cmdname, retval, "while reading ext2 file");
+		if (got == 0)
+			break;
+		nbytes = write(fd, buf, got);
+		if ((unsigned) nbytes != got)
+			com_err(cmdname, errno, "while writing file");
+	}
+	if (buf)
+		ext2fs_free_mem(&buf);
+	retval = ext2fs_file_close(e2_file);
+	if (retval) {
+		com_err(cmdname, retval, "while closing ext2 file");
+		return;
+	}
+
+	if (preserve)
+		fix_perms("dump_file", &inode, fd, outname);
+
+	return;
+}
+
+void do_dump(int argc, char **argv)
+{
+	ext2_ino_t	inode;
+	int		fd;
+	int		c;
+	int		preserve = 0;
+	char		*in_fn, *out_fn;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "p")) != EOF) {
+		switch (c) {
+		case 'p':
+			preserve++;
+			break;
+		default:
+		print_usage:
+			com_err(argv[0], 0, "Usage: dump_inode [-p] "
+				"<file> <output_file>");
+			return;
+		}
+	}
+	if (optind != argc-2)
+		goto print_usage;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	in_fn = argv[optind];
+	out_fn = argv[optind+1];
+
+	inode = string_to_inode(in_fn);
+	if (!inode)
+		return;
+
+	fd = open(out_fn, O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE, 0666);
+	if (fd < 0) {
+		com_err(argv[0], errno, "while opening %s for dump_inode",
+			out_fn);
+		return;
+	}
+
+	dump_file(argv[0], inode, fd, preserve, out_fn);
+	if (close(fd) != 0) {
+		com_err(argv[0], errno, "while closing %s for dump_inode",
+			out_fn);
+		return;
+	}
+
+	return;
+}
+
+static void rdump_symlink(ext2_ino_t ino, struct ext2_inode *inode,
+			  const char *fullname)
+{
+	ext2_file_t e2_file;
+	char *buf;
+	errcode_t retval;
+
+	buf = malloc(inode->i_size + 1);
+	if (!buf) {
+		com_err("rdump", errno, "while allocating for symlink");
+		goto errout;
+	}
+
+	/* Apparently, this is the right way to detect and handle fast
+	 * symlinks; see do_stat() in debugfs.c. */
+	if (inode->i_blocks == 0)
+		strcpy(buf, (char *) inode->i_block);
+	else {
+		unsigned bytes = inode->i_size;
+		char *p = buf;
+		retval = ext2fs_file_open(current_fs, ino, 0, &e2_file);
+		if (retval) {
+			com_err("rdump", retval, "while opening symlink");
+			goto errout;
+		}
+		for (;;) {
+			unsigned int got;
+			retval = ext2fs_file_read(e2_file, p, bytes, &got);
+			if (retval) {
+				com_err("rdump", retval, "while reading symlink");
+				goto errout;
+			}
+			bytes -= got;
+			p += got;
+			if (got == 0 || bytes == 0)
+				break;
+		}
+		buf[inode->i_size] = 0;
+		retval = ext2fs_file_close(e2_file);
+		if (retval)
+			com_err("rdump", retval, "while closing symlink");
+	}
+
+	if (symlink(buf, fullname) == -1) {
+		com_err("rdump", errno, "while creating symlink %s -> %s", buf, fullname);
+		goto errout;
+	}
+
+errout:
+	free(buf);
+}
+
+static int rdump_dirent(struct ext2_dir_entry *, int, int, char *, void *);
+
+static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
+			const char *name, const char *dumproot)
+{
+	char *fullname;
+
+	/* There are more efficient ways to do this, but this method
+	 * requires only minimal debugging. */
+	fullname = malloc(strlen(dumproot) + strlen(name) + 2);
+	if (!fullname) {
+		com_err("rdump", errno, "while allocating memory");
+		return;
+	}
+	sprintf(fullname, "%s/%s", dumproot, name);
+
+	if (LINUX_S_ISLNK(inode->i_mode))
+		rdump_symlink(ino, inode, fullname);
+	else if (LINUX_S_ISREG(inode->i_mode)) {
+		int fd;
+		fd = open(fullname, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, S_IRWXU);
+		if (fd == -1) {
+			com_err("rdump", errno, "while dumping %s", fullname);
+			goto errout;
+		}
+		dump_file("rdump", ino, fd, 1, fullname);
+		if (close(fd) != 0) {
+			com_err("rdump", errno, "while dumping %s", fullname);
+			goto errout;
+		}
+	}
+	else if (LINUX_S_ISDIR(inode->i_mode) && strcmp(name, ".") && strcmp(name, "..")) {
+		errcode_t retval;
+
+		/* Create the directory with 0700 permissions, because we
+		 * expect to have to create entries it.  Then fix its perms
+		 * once we've done the traversal. */
+		if (mkdir(fullname, S_IRWXU) == -1) {
+			com_err("rdump", errno, "while making directory %s", fullname);
+			goto errout;
+		}
+
+		retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
+					    rdump_dirent, (void *) fullname);
+		if (retval)
+			com_err("rdump", retval, "while dumping %s", fullname);
+
+		fix_perms("rdump", inode, -1, fullname);
+	}
+	/* else do nothing (don't dump device files, sockets, fifos, etc.) */
+
+errout:
+	free(fullname);
+}
+
+static int rdump_dirent(struct ext2_dir_entry *dirent,
+			int offset EXT2FS_ATTR((unused)),
+			int blocksize EXT2FS_ATTR((unused)),
+			char *buf EXT2FS_ATTR((unused)), void *private)
+{
+	char name[EXT2_NAME_LEN + 1];
+	int thislen;
+	const char *dumproot = private;
+	struct ext2_inode inode;
+
+	thislen = dirent->name_len & 0xFF;
+	strncpy(name, dirent->name, thislen);
+	name[thislen] = 0;
+
+	if (debugfs_read_inode(dirent->inode, &inode, name))
+		return 0;
+
+	rdump_inode(dirent->inode, &inode, name, dumproot);
+
+	return 0;
+}
+
+void do_rdump(int argc, char **argv)
+{
+	ext2_ino_t ino;
+	struct ext2_inode inode;
+	struct stat st;
+	int i;
+	char *p;
+
+	if (common_args_process(argc, argv, 3, 3, "rdump",
+				"<directory> <native directory>", 0))
+		return;
+
+	ino = string_to_inode(argv[1]);
+	if (!ino)
+		return;
+
+	/* Ensure ARGV[2] is a directory. */
+	i = stat(argv[2], &st);
+	if (i == -1) {
+		com_err("rdump", errno, "while statting %s", argv[2]);
+		return;
+	}
+	if (!S_ISDIR(st.st_mode)) {
+		com_err("rdump", 0, "%s is not a directory", argv[2]);
+		return;
+	}
+
+	if (debugfs_read_inode(ino, &inode, argv[1]))
+		return;
+
+	p = strrchr(argv[1], '/');
+	if (p)
+		p++;
+	else
+		p = argv[1];
+
+	rdump_inode(ino, &inode, p, argv[2]);
+}
+
+void do_cat(int argc, char **argv)
+{
+	ext2_ino_t	inode;
+
+	if (common_inode_args_process(argc, argv, &inode, 0))
+		return;
+
+	fflush(stdout);
+	fflush(stderr);
+	dump_file(argv[0], inode, 1, 0, argv[2]);
+
+	return;
+}
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_cmds.ct b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_cmds.ct
new file mode 100644
index 0000000..e1c4395
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_cmds.ct
@@ -0,0 +1,77 @@
+#
+# Copyright (C) 1993 Theodore Ts'o.  This file may be redistributed
+# under the terms of the GNU Public License.
+#
+command_table extent_cmds;
+
+request do_current_node, "Current extent node",
+	current_node, current;
+
+request do_root_node, "Goto root extent",
+	root_node, root;
+
+request do_last_leaf, "Goto last leaf",
+	last_leaf;
+
+request do_first_sib, "Goto first sibling",
+	first_sibling, first_sib;
+
+request do_last_sib, "Goto last sibling",
+	last_sibling, last_sib;
+
+request do_next_sib, "Goto next sibling",
+	next_sibling, next_sib, ns;
+
+request do_prev_sib, "Goto previous sibling",
+	prev_sibling, prev_sib, ps;
+
+request do_next_leaf, "Goto next leaf",
+	next_leaf, nl;
+
+request do_prev_leaf, "Goto previous leaf",
+	prev_leaf, pl;
+
+request do_next, "Goto next node",
+	next, n;
+
+request do_prev, "Goto previous node",
+	previous, prev, p;
+
+request do_up, "Up node",
+	up_node, up, u;
+
+request do_down, "Down node",
+	down_node, down, d;
+
+request do_delete_node, "Delete node",
+	delete_node, delete;
+
+request do_insert_node, "Insert node",
+	insert_node, insert;
+
+request do_split_node, "Split node",
+	split_node, split;
+
+request do_fix_parents, "Fix parents",
+	fix_parents, fixp;
+
+request do_set_bmap, "Set block mapping",
+	set_bmap;
+
+request do_replace_node, "Insert node",
+	replace_node, replace;
+
+request do_print_all, "Iterate over all nodes and print them",
+	print_all, all;
+
+request do_goto_block, "Goto extent containing specified block",
+	goto_block, goto;
+
+request do_info, "Print extent info",
+	info;
+
+request do_extent_close, "Close extent handle",
+	extent_close, ec;
+
+end;
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_inode.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_inode.c
new file mode 100644
index 0000000..b3c55f9
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/extent_inode.c
@@ -0,0 +1,538 @@
+/*
+ * extent_inode.c --- direct extent tree manipulation
+ *
+ * Copyright (C) 2012 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+static ext2_ino_t	current_ino;
+static ext2_extent_handle_t current_handle;
+
+static void dbg_print_extent(char *desc, struct ext2fs_extent *extent)
+{
+	if (desc)
+		printf("%s: ", desc);
+	printf("extent: lblk %llu--%llu, len %u, pblk %llu, flags: ",
+	       extent->e_lblk, extent->e_lblk + extent->e_len - 1,
+	       extent->e_len, extent->e_pblk);
+	if (extent->e_flags & EXT2_EXTENT_FLAGS_LEAF)
+		fputs("LEAF ", stdout);
+	if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT)
+		fputs("UNINIT ", stdout);
+	if (extent->e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
+		fputs("2ND_VISIT ", stdout);
+	if (!extent->e_flags)
+		fputs("(none)", stdout);
+	fputc('\n', stdout);
+
+}
+
+static int common_extent_args_process(int argc, char *argv[], int min_argc,
+				      int max_argc, const char *cmd,
+				      const char *usage, int flags)
+{
+	if (common_args_process(argc, argv, min_argc, max_argc, cmd,
+				usage, flags))
+		return 1;
+
+	if (!current_handle) {
+		com_err(cmd, 0, "Extent handle not open");
+		return 1;
+	}
+	return 0;
+}
+
+static char *orig_prompt, *extent_prompt;
+
+void do_extent_open(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+	int		ret;
+	errcode_t	retval;
+	char		*cp;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (argc == 1) {
+		if (current_ino)
+			printf("Current inode is %d\n", current_ino);
+		else
+			printf("No current inode\n");
+		return;
+	}
+
+	if (common_inode_args_process(argc, argv, &inode, 0))
+		return;
+
+	current_ino = 0;
+
+	retval = ext2fs_extent_open(current_fs, inode, &current_handle);
+	if (retval) {
+		com_err(argv[1], retval, "while opening extent handle");
+		return;
+	}
+
+	current_ino = inode;
+
+	orig_prompt = ss_get_prompt(sci_idx);
+	extent_prompt = malloc(strlen(orig_prompt) + 32);
+	strcpy(extent_prompt, orig_prompt);
+	cp = strchr(extent_prompt, ':');
+	if (cp)
+		*cp = 0;
+	sprintf(extent_prompt + strlen(extent_prompt), " (extent ino %d): ",
+		current_ino);
+	ss_add_request_table(sci_idx, &extent_cmds, 1, &ret);
+	ss_set_prompt(sci_idx, extent_prompt);
+	return;
+}
+
+void do_extent_close(int argc, char *argv[])
+{
+	int ret;
+
+	if (common_args_process(argc, argv, 1, 1,
+				"extent_close", "", 0))
+		return;
+
+	if (!current_handle) {
+		com_err(argv[0], 0, "Extent handle not open");
+		return;
+	}
+
+	ext2fs_extent_free(current_handle);
+	current_handle = NULL;
+	current_ino = 0;
+	ss_delete_request_table(sci_idx, &extent_cmds, &ret);
+	ss_set_prompt(sci_idx, orig_prompt);
+	free(extent_prompt);
+	extent_prompt = NULL;
+}
+
+static void generic_goto_node(const char *my_name, int argc,
+			      char **argv, int op)
+{
+	struct ext2fs_extent	extent;
+	errcode_t		retval;
+
+	if (my_name && common_args_process(argc, argv, 1, 1,
+					   my_name, "", 0))
+		return;
+
+	if (!current_handle) {
+		com_err(argv[0], 0, "Extent handle not open");
+		return;
+	}
+
+	retval = ext2fs_extent_get(current_handle, op, &extent);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+	dbg_print_extent(0, &extent);
+}
+
+void do_current_node(int argc, char *argv[])
+{
+	generic_goto_node("current_node", argc, argv, EXT2_EXTENT_CURRENT);
+}
+
+void do_root_node(int argc, char *argv[])
+{
+	generic_goto_node("root_node", argc, argv, EXT2_EXTENT_ROOT);
+}
+
+void do_last_leaf(int argc, char *argv[])
+{
+	generic_goto_node("last_leaf", argc, argv, EXT2_EXTENT_LAST_LEAF);
+}
+
+void do_first_sib(int argc, char *argv[])
+{
+	generic_goto_node("first_sib", argc, argv, EXT2_EXTENT_FIRST_SIB);
+}
+
+void do_last_sib(int argc, char *argv[])
+{
+	generic_goto_node("next_sib", argc, argv, EXT2_EXTENT_LAST_SIB);
+}
+
+void do_next_sib(int argc, char *argv[])
+{
+	generic_goto_node("next_sib", argc, argv, EXT2_EXTENT_NEXT_SIB);
+}
+
+void do_prev_sib(int argc, char *argv[])
+{
+	generic_goto_node("prev_sib", argc, argv, EXT2_EXTENT_PREV_SIB);
+}
+
+void do_next_leaf(int argc, char *argv[])
+{
+	generic_goto_node("next_leaf", argc, argv, EXT2_EXTENT_NEXT_LEAF);
+}
+
+void do_prev_leaf(int argc, char *argv[])
+{
+	generic_goto_node("prev_leaf", argc, argv, EXT2_EXTENT_PREV_LEAF);
+}
+
+void do_next(int argc, char *argv[])
+{
+	generic_goto_node("next", argc, argv, EXT2_EXTENT_NEXT);
+}
+
+void do_prev(int argc, char *argv[])
+{
+	generic_goto_node("prev", argc, argv, EXT2_EXTENT_PREV);
+}
+
+void do_up(int argc, char *argv[])
+{
+	generic_goto_node("up", argc, argv, EXT2_EXTENT_UP);
+}
+
+void do_down(int argc, char *argv[])
+{
+	generic_goto_node("down", argc, argv, EXT2_EXTENT_DOWN);
+}
+
+void do_delete_node(int argc, char *argv[])
+{
+	struct ext2fs_extent extent;
+	errcode_t	retval;
+
+	if (common_extent_args_process(argc, argv, 1, 1, "delete_node",
+				       "", CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	retval = ext2fs_extent_delete(current_handle, 0);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+
+	retval = ext2fs_extent_get(current_handle, EXT2_EXTENT_CURRENT,
+				   &extent);
+	if (retval)
+		return;
+	dbg_print_extent(0, &extent);
+}
+
+void do_replace_node(int argc, char *argv[])
+{
+	const char	*usage = "[--uninit] <lblk> <len> <pblk>";
+	errcode_t	retval;
+	struct ext2fs_extent extent;
+	int err;
+
+	if (common_extent_args_process(argc, argv, 3, 5, "replace_node",
+				       usage, CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	extent.e_flags = 0;
+
+	if (!strcmp(argv[1], "--uninit")) {
+		argc--;
+		argv++;
+		extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT;
+	}
+
+	if (argc != 4) {
+		fprintf(stderr, "Usage: %s %s\n", argv[0], usage);
+		return;
+	}
+
+	err = strtoblk(argv[0], argv[1], &extent.e_lblk);
+	if (err)
+		return;
+
+	extent.e_len = parse_ulong(argv[2], argv[0], "logical block", &err);
+	if (err)
+		return;
+
+	err = strtoblk(argv[0], argv[3], &extent.e_pblk);
+	if (err)
+		return;
+
+	retval = ext2fs_extent_replace(current_handle, 0, &extent);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+	generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT);
+}
+
+void do_split_node(int argc, char *argv[])
+{
+	errcode_t	retval;
+
+	if (common_extent_args_process(argc, argv, 1, 1, "split_node",
+				       "", CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	retval = ext2fs_extent_node_split(current_handle);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+	generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT);
+}
+
+void do_insert_node(int argc, char *argv[])
+{
+	const char	*usage = "[--after] [--uninit] <lblk> <len> <pblk>";
+	errcode_t	retval;
+	struct ext2fs_extent extent;
+	char *cmd;
+	int err;
+	int flags = 0;
+
+	if (common_extent_args_process(argc, argv, 3, 6, "insert_node",
+				       usage, CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	cmd = argv[0];
+
+	extent.e_flags = 0;
+
+	while (argc > 2) {
+		if (!strcmp(argv[1], "--after")) {
+			argc--;
+			argv++;
+			flags |= EXT2_EXTENT_INSERT_AFTER;
+			continue;
+		}
+		if (!strcmp(argv[1], "--uninit")) {
+			argc--;
+			argv++;
+			extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT;
+			continue;
+		}
+		break;
+	}
+
+	if (argc != 4) {
+		fprintf(stderr, "usage: %s %s\n", cmd, usage);
+		return;
+	}
+
+	err = strtoblk(cmd, argv[1], &extent.e_lblk);
+	if (err)
+		return;
+
+	extent.e_len = parse_ulong(argv[2], cmd,
+				    "length", &err);
+	if (err)
+		return;
+
+	err = strtoblk(cmd, argv[3], &extent.e_pblk);
+	if (err)
+		return;
+
+	retval = ext2fs_extent_insert(current_handle, flags, &extent);
+	if (retval) {
+		com_err(cmd, retval, 0);
+		return;
+	}
+	generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT);
+}
+
+void do_set_bmap(int argc, char **argv)
+{
+	const char	*usage = "[--uninit] <lblk> <pblk>";
+	struct ext2fs_extent extent;
+	errcode_t	retval;
+	blk64_t		logical;
+	blk64_t		physical;
+	char		*cmd = argv[0];
+	int		flags = 0;
+	int		err;
+
+	if (common_extent_args_process(argc, argv, 3, 5, "set_bmap",
+				       usage, CHECK_FS_RW | CHECK_FS_BITMAPS))
+		return;
+
+	if (argc > 2 && !strcmp(argv[1], "--uninit")) {
+		argc--;
+		argv++;
+		flags |= EXT2_EXTENT_SET_BMAP_UNINIT;
+	}
+
+	if (argc != 3) {
+		fprintf(stderr, "Usage: %s %s\n", cmd, usage);
+		return;
+	}
+
+	err = strtoblk(cmd, argv[1], &logical);
+	if (err)
+		return;
+
+	err = strtoblk(cmd, argv[2], &physical);
+	if (err)
+		return;
+
+	retval = ext2fs_extent_set_bmap(current_handle, logical,
+					physical, flags);
+	if (retval) {
+		com_err(cmd, retval, 0);
+		return;
+	}
+
+	retval = ext2fs_extent_get(current_handle, EXT2_EXTENT_CURRENT,
+				   &extent);
+	if (retval)
+		return;
+	dbg_print_extent(0, &extent);
+}
+
+void do_print_all(int argc, char **argv)
+{
+	const char	*usage = "[--leaf-only|--reverse|--reverse-leaf]";
+	struct ext2fs_extent	extent;
+	errcode_t		retval;
+	errcode_t		end_err = EXT2_ET_EXTENT_NO_NEXT;
+	int			op = EXT2_EXTENT_NEXT;
+	int			first_op = EXT2_EXTENT_ROOT;
+
+
+	if (common_extent_args_process(argc, argv, 1, 2, "print_all",
+				       usage, 0))
+		return;
+
+	if (argc == 2) {
+		if (!strcmp(argv[1], "--leaf-only"))
+			op = EXT2_EXTENT_NEXT_LEAF;
+		else if (!strcmp(argv[1], "--reverse")) {
+			op = EXT2_EXTENT_PREV;
+			first_op = EXT2_EXTENT_LAST_LEAF;
+			end_err = EXT2_ET_EXTENT_NO_PREV;
+		} else if (!strcmp(argv[1], "--reverse-leaf")) {
+			op = EXT2_EXTENT_PREV_LEAF;
+			first_op = EXT2_EXTENT_LAST_LEAF;
+			end_err = EXT2_ET_EXTENT_NO_PREV;
+		} else {
+			fprintf(stderr, "Usage: %s %s\n", argv[0], usage);
+			return;
+		}
+	}
+
+	retval = ext2fs_extent_get(current_handle, first_op, &extent);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+	dbg_print_extent(0, &extent);
+
+	while (1) {
+		retval = ext2fs_extent_get(current_handle, op, &extent);
+		if (retval == end_err)
+			break;
+
+		if (retval) {
+			com_err(argv[0], retval, 0);
+			return;
+		}
+		dbg_print_extent(0, &extent);
+	}
+}
+
+void do_fix_parents(int argc, char **argv)
+{
+	errcode_t		retval;
+
+	if (common_extent_args_process(argc, argv, 1, 1, "fix_parents", "",
+				       CHECK_FS_RW))
+		return;
+
+	retval = ext2fs_extent_fix_parents(current_handle);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+}
+
+void do_info(int argc, char **argv)
+{
+	struct ext2fs_extent	extent;
+	struct ext2_extent_info	info;
+	errcode_t		retval;
+
+	if (common_extent_args_process(argc, argv, 1, 1, "info", "", 0))
+		return;
+
+	retval = ext2fs_extent_get_info(current_handle, &info);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+
+	retval = ext2fs_extent_get(current_handle,
+				   EXT2_EXTENT_CURRENT, &extent);
+	if (retval) {
+		com_err(argv[0], retval, 0);
+		return;
+	}
+
+	dbg_print_extent(0, &extent);
+
+	printf("Current handle location: %d/%d (max: %d, bytes %d), level %d/%d\n",
+	       info.curr_entry, info.num_entries, info.max_entries,
+	       info.bytes_avail, info.curr_level, info.max_depth);
+	printf("\tmax lblk: %llu, max pblk: %llu\n", info.max_lblk,
+	       info.max_pblk);
+	printf("\tmax_len: %u, max_uninit_len: %u\n", info.max_len,
+	       info.max_uninit_len);
+}
+
+void do_goto_block(int argc, char **argv)
+{
+	errcode_t		retval;
+	blk64_t			blk;
+	int			level = 0, err;
+
+	if (common_extent_args_process(argc, argv, 2, 3, "goto_block",
+				       "block [level]", 0))
+		return;
+
+	if (strtoblk(argv[0], argv[1], &blk))
+		return;
+
+	if (argc == 3) {
+		level = parse_ulong(argv[2], argv[0], "level", &err);
+		if (err)
+			return;
+	}
+
+	retval = ext2fs_extent_goto2(current_handle, level, (blk64_t) blk);
+
+	if (retval) {
+		com_err(argv[0], retval,
+			"while trying to go to block %llu, level %d",
+			(unsigned long long) blk, level);
+		return;
+	}
+
+	generic_goto_node(NULL, argc, argv, EXT2_EXTENT_CURRENT);
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/filefrag.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/filefrag.c
new file mode 100644
index 0000000..0adea40
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/filefrag.c
@@ -0,0 +1,324 @@
+/*
+ * filefrag.c --- display the fragmentation information for a file
+ *
+ * Copyright (C) 2011 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <utime.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+#define VERBOSE_OPT	0x0001
+#define DIR_OPT		0x0002
+#define RECURSIVE_OPT	0x0004
+
+struct dir_list {
+	char		*name;
+	ext2_ino_t	ino;
+	struct dir_list	*next;
+};
+
+struct filefrag_struct {
+	FILE		*f;
+	const char	*name;
+	const char	*dir_name;
+	int		options;
+	int		logical_width;
+	int		physical_width;
+	int		ext;
+	int		cont_ext;
+	e2_blkcnt_t	num;
+	e2_blkcnt_t	logical_start;
+	blk64_t		physical_start;
+	blk64_t		expected;
+	struct dir_list *dir_list, *dir_last;
+};
+
+static int int_log10(unsigned long long arg)
+{
+	int     l = 0;
+
+	arg = arg / 10;
+	while (arg) {
+		l++;
+		arg = arg / 10;
+	}
+	return l;
+}
+
+static void print_header(struct filefrag_struct *fs)
+{
+	if (fs->options & VERBOSE_OPT) {
+		fprintf(fs->f, "%4s %*s %*s %*s %*s\n", "ext",
+			fs->logical_width, "logical", fs->physical_width,
+			"physical", fs->physical_width, "expected",
+			fs->logical_width, "length");
+	}
+}
+
+static void report_filefrag(struct filefrag_struct *fs)
+{
+	if (fs->num == 0)
+		return;
+	if (fs->options & VERBOSE_OPT) {
+		if (fs->expected)
+			fprintf(fs->f, "%4d %*lu %*llu %*llu %*lu\n", fs->ext,
+				fs->logical_width,
+				(unsigned long) fs->logical_start,
+				fs->physical_width, fs->physical_start,
+				fs->physical_width, fs->expected,
+				fs->logical_width, (unsigned long) fs->num);
+		else
+			fprintf(fs->f, "%4d %*lu %*llu %*s %*lu\n", fs->ext,
+				fs->logical_width,
+				(unsigned long) fs->logical_start,
+				fs->physical_width, fs->physical_start,
+				fs->physical_width, "",
+				fs->logical_width, (unsigned long) fs->num);
+	}
+	fs->ext++;
+}
+
+static int filefrag_blocks_proc(ext2_filsys ext4_fs EXT2FS_ATTR((unused)),
+				blk64_t *blocknr, e2_blkcnt_t blockcnt,
+				blk64_t ref_block EXT2FS_ATTR((unused)),
+				int ref_offset EXT2FS_ATTR((unused)),
+				void *private)
+{
+	struct filefrag_struct *fs = private;
+
+	if (blockcnt < 0 || *blocknr == 0)
+		return 0;
+
+	if ((fs->num == 0) || (blockcnt != fs->logical_start + fs->num) ||
+	    (*blocknr != fs->physical_start + fs->num)) {
+		report_filefrag(fs);
+		if (blockcnt == fs->logical_start + fs->num)
+			fs->expected = fs->physical_start + fs->num;
+		else
+			fs->expected = 0;
+		fs->logical_start = blockcnt;
+		fs->physical_start = *blocknr;
+		fs->num = 1;
+		fs->cont_ext++;
+	} else
+		fs->num++;
+	return 0;
+}
+
+static void filefrag(ext2_ino_t ino, struct ext2_inode *inode,
+		     struct filefrag_struct *fs)
+{
+	errcode_t	retval;
+	int		blocksize = current_fs->blocksize;
+
+	fs->logical_width = int_log10((EXT2_I_SIZE(inode) + blocksize - 1) /
+				      blocksize) + 1;
+	if (fs->logical_width < 7)
+		fs->logical_width = 7;
+	fs->ext = 0;
+	fs->cont_ext = 0;
+	fs->logical_start = 0;
+	fs->physical_start = 0;
+	fs->num = 0;
+
+	if (fs->options & VERBOSE_OPT) {
+		blk64_t num_blocks = ext2fs_inode_i_blocks(current_fs, inode);
+
+		if (!(current_fs->super->s_feature_ro_compat &
+		     EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
+		    !(inode->i_flags & EXT4_HUGE_FILE_FL))
+			num_blocks /= current_fs->blocksize / 512;
+
+		fprintf(fs->f, "\n%s has %llu block(s), i_size is %llu\n",
+			fs->name, num_blocks, EXT2_I_SIZE(inode));
+	}
+	print_header(fs);
+	retval = ext2fs_block_iterate3(current_fs, ino,
+				       BLOCK_FLAG_READ_ONLY, NULL,
+				       filefrag_blocks_proc, fs);
+	if (retval)
+		com_err("ext2fs_block_iterate3", retval, 0);
+
+	report_filefrag(fs);
+	fprintf(fs->f, "%s: %d contiguous extents%s\n", fs->name, fs->ext,
+		LINUX_S_ISDIR(inode->i_mode) ? " (dir)" : "");
+}
+
+static int filefrag_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
+			     int	entry,
+			     struct ext2_dir_entry *dirent,
+			     int	offset EXT2FS_ATTR((unused)),
+			     int	blocksize EXT2FS_ATTR((unused)),
+			     char	*buf EXT2FS_ATTR((unused)),
+			     void	*private)
+{
+	struct filefrag_struct *fs = private;
+	struct ext2_inode	inode;
+	ext2_ino_t		ino;
+	char			name[EXT2_NAME_LEN + 1];
+	char			*cp;
+	int			thislen;
+
+	if (entry == DIRENT_DELETED_FILE)
+		return 0;
+
+	thislen = dirent->name_len & 0xFF;
+	strncpy(name, dirent->name, thislen);
+	name[thislen] = '\0';
+	ino = dirent->inode;
+
+	if (!strcmp(name, ".") || !strcmp(name, ".."))
+		return 0;
+
+	cp = malloc(strlen(fs->dir_name) + strlen(name) + 2);
+	if (!cp) {
+		fprintf(stderr, "Couldn't allocate memory for %s/%s\n",
+			fs->dir_name, name);
+		return 0;
+	}
+
+	sprintf(cp, "%s/%s", fs->dir_name, name);
+	fs->name = cp;
+
+	if (debugfs_read_inode(ino, &inode, fs->name))
+		goto errout;
+
+	filefrag(ino, &inode, fs);
+
+	if ((fs->options & RECURSIVE_OPT) && LINUX_S_ISDIR(inode.i_mode)) {
+		struct dir_list *p;
+
+		p = malloc(sizeof(struct dir_list));
+		if (!p) {
+			fprintf(stderr, "Couldn't allocate dir_list for %s\n",
+				fs->name);
+			goto errout;
+		}
+		memset(p, 0, sizeof(struct dir_list));
+		p->name = cp;
+		p->ino = ino;
+		if (fs->dir_last)
+			fs->dir_last->next = p;
+		else
+			fs->dir_list = p;
+		fs->dir_last = p;
+		return 0;
+	}
+errout:
+	free(cp);
+	fs->name = 0;
+	return 0;
+}
+
+
+static void dir_iterate(ext2_ino_t ino, struct filefrag_struct *fs)
+{
+	errcode_t	retval;
+	struct dir_list	*p = NULL;
+
+	fs->dir_name = fs->name;
+
+	while (1) {
+		retval = ext2fs_dir_iterate2(current_fs, ino, 0,
+					     0, filefrag_dir_proc, fs);
+		if (retval)
+			com_err("ext2fs_dir_iterate2", retval, 0);
+		if (p) {
+			free(p->name);
+			fs->dir_list = p->next;
+			if (!fs->dir_list)
+				fs->dir_last = 0;
+			free(p);
+		}
+		p = fs->dir_list;
+		if (!p)
+			break;
+		ino = p->ino;
+		fs->dir_name = p->name;
+	}
+}
+
+void do_filefrag(int argc, char *argv[])
+{
+	struct filefrag_struct fs;
+	struct ext2_inode inode;
+	ext2_ino_t	ino;
+	int		c;
+
+	memset(&fs, 0, sizeof(fs));
+	if (check_fs_open(argv[0]))
+		return;
+
+	reset_getopt();
+	while ((c = getopt(argc, argv, "dvr")) != EOF) {
+		switch (c) {
+		case 'd':
+			fs.options |= DIR_OPT;
+			break;
+		case 'v':
+			fs.options |= VERBOSE_OPT;
+			break;
+		case 'r':
+			fs.options |= RECURSIVE_OPT;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+
+	if (argc > optind+1) {
+	print_usage:
+		com_err(0, 0, "Usage: filefrag [-dvr] file");
+		return;
+	}
+
+	if (argc == optind) {
+		ino = cwd;
+		fs.name = ".";
+	} else {
+		ino = string_to_inode(argv[optind]);
+		fs.name = argv[optind];
+	}
+	if (!ino)
+		return;
+
+	if (debugfs_read_inode(ino, &inode, argv[0]))
+		return;
+
+	fs.f = open_pager();
+	fs.physical_width = int_log10(ext2fs_blocks_count(current_fs->super));
+	fs.physical_width++;
+	if (fs.physical_width < 8)
+		fs.physical_width = 8;
+
+	if (!LINUX_S_ISDIR(inode.i_mode) || (fs.options & DIR_OPT))
+		filefrag(ino, &inode, &fs);
+	else
+		dir_iterate(ino, &fs);
+
+	fprintf(fs.f, "\n");
+	close_pager(fs.f);
+
+	return;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/htree.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/htree.c
new file mode 100644
index 0000000..24f8250
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/htree.c
@@ -0,0 +1,409 @@
+/*
+ * htree.c --- hash tree routines
+ *
+ * Copyright (C) 2002 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+#include "uuid/uuid.h"
+#include "e2p/e2p.h"
+
+static FILE *pager;
+
+static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
+				 struct ext2_inode *inode,
+				 struct ext2_dx_root_info * rootnode,
+				 blk64_t blk, char *buf)
+{
+	errcode_t	errcode;
+	struct ext2_dir_entry *dirent;
+	int		thislen, col = 0;
+	unsigned int	offset = 0;
+	char		name[EXT2_NAME_LEN + 1];
+	char		tmp[EXT2_NAME_LEN + 64];
+	blk64_t		pblk;
+	ext2_dirhash_t 	hash, minor_hash;
+	unsigned int	rec_len;
+	int		hash_alg;
+
+	errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
+	if (errcode) {
+		com_err("htree_dump_leaf_node", errcode,
+			"while mapping logical block %llu\n", blk);
+		return;
+	}
+
+	fprintf(pager, "Reading directory block %llu, phys %llu\n", blk, pblk);
+	errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
+	if (errcode) {
+		com_err("htree_dump_leaf_node", errcode,
+			"while reading block %llu (%llu)\n",
+			blk, pblk);
+		return;
+	}
+	hash_alg = rootnode->hash_version;
+	if ((hash_alg <= EXT2_HASH_TEA) &&
+	    (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
+		hash_alg += 3;
+
+	while (offset < fs->blocksize) {
+		dirent = (struct ext2_dir_entry *) (buf + offset);
+		errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
+		if (errcode) {
+			com_err("htree_dump_leaf_inode", errcode,
+				"while getting rec_len for block %lu",
+				(unsigned long) blk);
+			return;
+		}
+		if (((offset + rec_len) > fs->blocksize) ||
+		    (rec_len < 8) ||
+		    ((rec_len % 4) != 0) ||
+		    ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) {
+			fprintf(pager, "Corrupted directory block (%llu)!\n",
+				blk);
+			break;
+		}
+		thislen = dirent->name_len & 0xFF;
+		strncpy(name, dirent->name, thislen);
+		name[thislen] = '\0';
+		errcode = ext2fs_dirhash(hash_alg, name,
+					 thislen, fs->super->s_hash_seed,
+					 &hash, &minor_hash);
+		if (errcode)
+			com_err("htree_dump_leaf_node", errcode,
+				"while calculating hash");
+		snprintf(tmp, EXT2_NAME_LEN + 64, "%u 0x%08x-%08x (%d) %s   ",
+			dirent->inode, hash, minor_hash, rec_len, name);
+		thislen = strlen(tmp);
+		if (col + thislen > 80) {
+			fprintf(pager, "\n");
+			col = 0;
+		}
+		fprintf(pager, "%s", tmp);
+		col += thislen;
+		offset += rec_len;
+	}
+	fprintf(pager, "\n");
+}
+
+
+static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
+				 struct ext2_inode *inode,
+				 struct ext2_dx_root_info * rootnode,
+				 blk64_t blk, char *buf, int level);
+
+
+static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
+				struct ext2_inode *inode,
+				struct ext2_dx_root_info * rootnode,
+				struct ext2_dx_entry *ent,
+				char *buf, int level)
+{
+	struct ext2_dx_countlimit	limit;
+	struct ext2_dx_entry		e;
+	int				hash, i;
+
+
+	limit = *((struct ext2_dx_countlimit *) ent);
+	limit.count = ext2fs_le16_to_cpu(limit.count);
+	limit.limit = ext2fs_le16_to_cpu(limit.limit);
+
+	fprintf(pager, "Number of entries (count): %d\n", limit.count);
+	fprintf(pager, "Number of entries (limit): %d\n", limit.limit);
+
+	for (i=0; i < limit.count; i++) {
+		hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
+		fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
+			hash, (hash & 1) ? " (**)" : "",
+			ext2fs_le32_to_cpu(ent[i].block));
+		}
+
+	fprintf(pager, "\n");
+
+	for (i=0; i < limit.count; i++) {
+		e.hash = ext2fs_le32_to_cpu(ent[i].hash);
+		e.block = ext2fs_le32_to_cpu(ent[i].block);
+		fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
+		       i ? e.hash : 0, e.block);
+		if (level)
+			htree_dump_int_block(fs, ino, inode, rootnode,
+					     e.block, buf, level-1);
+		else
+			htree_dump_leaf_node(fs, ino, inode, rootnode,
+					     e.block, buf);
+	}
+
+	fprintf(pager, "---------------------\n");
+}
+
+static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
+				 struct ext2_inode *inode,
+				 struct ext2_dx_root_info * rootnode,
+				 blk64_t blk, char *buf, int level)
+{
+	char		*cbuf;
+	errcode_t	errcode;
+	blk64_t		pblk;
+
+	cbuf = malloc(fs->blocksize);
+	if (!cbuf) {
+		fprintf(pager, "Couldn't allocate child block.\n");
+		return;
+	}
+
+	errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
+	if (errcode) {
+		com_err("htree_dump_int_block", errcode,
+			"while mapping logical block %llu\n", blk);
+		goto errout;
+	}
+
+	errcode = io_channel_read_blk64(current_fs->io, pblk, 1, buf);
+	if (errcode) {
+		com_err("htree_dump_int_block", errcode,
+			"while 	reading block %llu\n", blk);
+		goto errout;
+	}
+
+	htree_dump_int_node(fs, ino, inode, rootnode,
+			    (struct ext2_dx_entry *) (buf+8),
+			    cbuf, level);
+errout:
+	free(cbuf);
+}
+
+
+
+void do_htree_dump(int argc, char *argv[])
+{
+	ext2_ino_t	ino;
+	struct ext2_inode inode;
+	blk64_t		blk;
+	char		*buf = NULL;
+	struct 		ext2_dx_root_info  *rootnode;
+	struct 		ext2_dx_entry *ent;
+	errcode_t	errcode;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	pager = open_pager();
+
+	if (common_inode_args_process(argc, argv, &ino, 0))
+		goto errout;
+
+	if (debugfs_read_inode(ino, &inode, argv[1]))
+		goto errout;
+
+	if (!LINUX_S_ISDIR(inode.i_mode)) {
+		com_err(argv[0], 0, "Not a directory");
+		goto errout;
+	}
+
+	if ((inode.i_flags & EXT2_BTREE_FL) == 0) {
+		com_err(argv[0], 0, "Not a hash-indexed directory");
+		goto errout;
+	}
+
+	buf = malloc(2*current_fs->blocksize);
+	if (!buf) {
+		com_err(argv[0], 0, "Couldn't allocate htree buffer");
+		goto errout;
+	}
+
+	errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk);
+	if (errcode) {
+		com_err("do_htree_block", errcode,
+			"while mapping logical block 0\n");
+		goto errout;
+	}
+
+	errcode = io_channel_read_blk64(current_fs->io, blk,
+					1, buf);
+	if (errcode) {
+		com_err(argv[0], errcode, "Error reading root node");
+		goto errout;
+	}
+
+	rootnode = (struct ext2_dx_root_info *) (buf + 24);
+
+	fprintf(pager, "Root node dump:\n");
+	fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero);
+	fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version);
+	fprintf(pager, "\t Info length: %d\n", rootnode->info_length);
+	fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels);
+	fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags);
+
+	ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length);
+
+	htree_dump_int_node(current_fs, ino, &inode, rootnode, ent,
+			    buf + current_fs->blocksize,
+			    rootnode->indirect_levels);
+
+errout:
+	free(buf);
+	close_pager(pager);
+}
+
+/*
+ * This function prints the hash of a given file.
+ */
+void do_dx_hash(int argc, char *argv[])
+{
+	ext2_dirhash_t hash, minor_hash;
+	errcode_t	err;
+	int		c;
+	int		hash_version = 0;
+	__u32		hash_seed[4];
+
+	hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "h:s:")) != EOF) {
+		switch (c) {
+		case 'h':
+			hash_version = e2p_string2hash(optarg);
+			if (hash_version < 0)
+				hash_version = atoi(optarg);
+			break;
+		case 's':
+			if (uuid_parse(optarg, (unsigned char *) hash_seed)) {
+				fprintf(stderr, "Invalid UUID format: %s\n",
+					optarg);
+				return;
+			}
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+	if (optind != argc-1) {
+	print_usage:
+		com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] "
+			"[-s hash_seed] filename");
+		return;
+	}
+	err = ext2fs_dirhash(hash_version, argv[optind], strlen(argv[optind]),
+			     hash_seed, &hash, &minor_hash);
+	if (err) {
+		com_err(argv[0], err, "while caclulating hash");
+		return;
+	}
+	printf("Hash of %s is 0x%0x (minor 0x%0x)\n", argv[optind],
+	       hash, minor_hash);
+}
+
+/*
+ * Search for particular directory entry (useful for debugging very
+ * large hash tree directories that have lost some blocks from the
+ * btree index).
+ */
+struct process_block_struct {
+	char	*search_name;
+	char	*buf;
+	int	len;
+};
+
+static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
+			    e2_blkcnt_t blockcnt, blk64_t ref_blk,
+			    int ref_offset, void *priv_data);
+
+void do_dirsearch(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+	struct process_block_struct pb;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (argc != 3) {
+		com_err(0, 0, "Usage: dirsearch dir filename");
+		return;
+	}
+
+	inode = string_to_inode(argv[1]);
+	if (!inode)
+		return;
+
+	pb.buf = malloc(current_fs->blocksize);
+	if (!pb.buf) {
+		com_err("dirsearch", 0, "Couldn't allocate buffer");
+		return;
+	}
+	pb.search_name = argv[2];
+	pb.len = strlen(pb.search_name);
+
+	ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0,
+			      search_dir_block, &pb);
+
+	free(pb.buf);
+}
+
+
+static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
+			    e2_blkcnt_t blockcnt,
+			    blk64_t ref_blk EXT2FS_ATTR((unused)),
+			    int ref_offset EXT2FS_ATTR((unused)),
+			    void *priv_data)
+{
+	struct process_block_struct *p;
+	struct ext2_dir_entry *dirent;
+	errcode_t	       	errcode;
+	unsigned int		offset = 0;
+	unsigned int		rec_len;
+
+	if (blockcnt < 0)
+		return 0;
+
+	p = (struct process_block_struct *) priv_data;
+
+	errcode = io_channel_read_blk64(current_fs->io, *blocknr, 1, p->buf);
+	if (errcode) {
+		com_err("search_dir_block", errcode,
+			"while reading block %lu", (unsigned long) *blocknr);
+		return BLOCK_ABORT;
+	}
+
+	while (offset < fs->blocksize) {
+		dirent = (struct ext2_dir_entry *) (p->buf + offset);
+		errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
+		if (errcode) {
+			com_err("htree_dump_leaf_inode", errcode,
+				"while getting rec_len for block %lu",
+				(unsigned long) *blocknr);
+			return BLOCK_ABORT;
+		}
+		if (dirent->inode &&
+		    p->len == (dirent->name_len & 0xFF) &&
+		    strncmp(p->search_name, dirent->name,
+			    p->len) == 0) {
+			printf("Entry found at logical block %lld, "
+			       "phys %llu, offset %u\n", (long long)blockcnt,
+			       *blocknr, offset);
+			printf("offset %u\n", offset);
+			return BLOCK_ABORT;
+		}
+		offset += rec_len;
+	}
+	return 0;
+}
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/icheck.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/icheck.c
new file mode 100644
index 0000000..48f432a
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/icheck.c
@@ -0,0 +1,173 @@
+/*
+ * icheck.c --- given a list of blocks, generate a list of inodes
+ *
+ * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+
+#include "debugfs.h"
+
+struct block_info {
+	blk64_t		blk;
+	ext2_ino_t	ino;
+};
+
+struct block_walk_struct {
+	struct block_info	*barray;
+	e2_blkcnt_t		blocks_left;
+	e2_blkcnt_t		num_blocks;
+	ext2_ino_t		inode;
+};
+
+static int icheck_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
+		       blk64_t	*block_nr,
+		       e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+		       blk64_t ref_block EXT2FS_ATTR((unused)),
+		       int ref_offset EXT2FS_ATTR((unused)),
+		       void *private)
+{
+	struct block_walk_struct *bw = (struct block_walk_struct *) private;
+	e2_blkcnt_t	i;
+
+	for (i=0; i < bw->num_blocks; i++) {
+		if (!bw->barray[i].ino && bw->barray[i].blk == *block_nr) {
+			bw->barray[i].ino = bw->inode;
+			bw->blocks_left--;
+		}
+	}
+	if (!bw->blocks_left)
+		return BLOCK_ABORT;
+
+	return 0;
+}
+
+void do_icheck(int argc, char **argv)
+{
+	struct block_walk_struct bw;
+	struct block_info	*binfo;
+	int			i;
+	ext2_inode_scan		scan = 0;
+	ext2_ino_t		ino;
+	struct ext2_inode	inode;
+	errcode_t		retval;
+	char			*block_buf;
+
+	if (argc < 2) {
+		com_err(argv[0], 0, "Usage: icheck <block number> ...");
+		return;
+	}
+	if (check_fs_open(argv[0]))
+		return;
+
+	bw.barray = malloc(sizeof(struct block_info) * argc);
+	if (!bw.barray) {
+		com_err("icheck", ENOMEM,
+			"while allocating inode info array");
+		return;
+	}
+	memset(bw.barray, 0, sizeof(struct block_info) * argc);
+
+	block_buf = malloc(current_fs->blocksize * 3);
+	if (!block_buf) {
+		com_err("icheck", ENOMEM, "while allocating block buffer");
+		goto error_out;
+	}
+
+	for (i=1; i < argc; i++) {
+		if (strtoblk(argv[0], argv[i], &bw.barray[i-1].blk))
+			goto error_out;
+	}
+
+	bw.num_blocks = bw.blocks_left = argc-1;
+
+	retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
+	if (retval) {
+		com_err("icheck", retval, "while opening inode scan");
+		goto error_out;
+	}
+
+	do {
+		retval = ext2fs_get_next_inode(scan, &ino, &inode);
+	} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+	if (retval) {
+		com_err("icheck", retval, "while starting inode scan");
+		goto error_out;
+	}
+
+	while (ino) {
+		blk64_t blk;
+
+		if (!inode.i_links_count)
+			goto next;
+
+		bw.inode = ino;
+
+		blk = ext2fs_file_acl_block(current_fs, &inode);
+		if (blk) {
+			icheck_proc(current_fs, &blk, 0,
+				    0, 0, &bw);
+			if (bw.blocks_left == 0)
+				break;
+			ext2fs_file_acl_block_set(current_fs, &inode, blk);
+		}
+
+		if (!ext2fs_inode_has_valid_blocks2(current_fs, &inode))
+			goto next;
+		/*
+		 * To handle filesystems touched by 0.3c extfs; can be
+		 * removed later.
+		 */
+		if (inode.i_dtime)
+			goto next;
+
+		retval = ext2fs_block_iterate3(current_fs, ino,
+					       BLOCK_FLAG_READ_ONLY, block_buf,
+					       icheck_proc, &bw);
+		if (retval) {
+			com_err("icheck", retval,
+				"while calling ext2fs_block_iterate");
+			goto next;
+		}
+
+		if (bw.blocks_left == 0)
+			break;
+
+	next:
+		do {
+			retval = ext2fs_get_next_inode(scan, &ino, &inode);
+		} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+		if (retval) {
+			com_err("icheck", retval,
+				"while doing inode scan");
+			goto error_out;
+		}
+	}
+
+	printf("Block\tInode number\n");
+	for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
+		if (binfo->ino == 0) {
+			printf("%llu\t<block not found>\n", binfo->blk);
+			continue;
+		}
+		printf("%llu\t%u\n", binfo->blk, binfo->ino);
+	}
+
+error_out:
+	free(bw.barray);
+	free(block_buf);
+	if (scan)
+		ext2fs_close_inode_scan(scan);
+	return;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/jfs_user.h b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/jfs_user.h
new file mode 100644
index 0000000..3070cd5
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/jfs_user.h
@@ -0,0 +1,8 @@
+#ifndef _JFS_USER_H
+#define _JFS_USER_H
+
+typedef unsigned short kdev_t;
+
+#include <ext2fs/kernel-jbd.h>
+
+#endif /* _JFS_USER_H */
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/logdump.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/logdump.c
new file mode 100644
index 0000000..66a5428
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/logdump.c
@@ -0,0 +1,698 @@
+/*
+ * logdump.c --- dump the contents of the journal out to a file
+ *
+ * Authro: Stephen C. Tweedie, 2001  <sct@redhat.com>
+ * Copyright (C) 2001 Red Hat, Inc.
+ * Based on portions  Copyright (C) 1994 Theodore Ts'o.
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <utime.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+#include "blkid/blkid.h"
+#include "jfs_user.h"
+#include <uuid/uuid.h>
+
+enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
+
+#define ANY_BLOCK ((blk64_t) -1)
+
+static int		dump_all, dump_contents, dump_descriptors;
+static blk64_t		block_to_dump, bitmap_to_dump, inode_block_to_dump;
+static unsigned int	group_to_dump, inode_offset_to_dump;
+static ext2_ino_t	inode_to_dump;
+
+struct journal_source
+{
+	enum journal_location where;
+	int fd;
+	ext2_file_t file;
+};
+
+static void dump_journal(char *, FILE *, struct journal_source *);
+
+static void dump_descriptor_block(FILE *, struct journal_source *,
+				  char *, journal_superblock_t *,
+				  unsigned int *, int, tid_t);
+
+static void dump_revoke_block(FILE *, char *, journal_superblock_t *,
+				  unsigned int, int, tid_t);
+
+static void dump_metadata_block(FILE *, struct journal_source *,
+				journal_superblock_t*,
+				unsigned int, unsigned int, unsigned int,
+				int, tid_t);
+
+static void do_hexdump (FILE *, char *, int);
+
+#define WRAP(jsb, blocknr)					\
+	if (blocknr >= be32_to_cpu((jsb)->s_maxlen))		\
+		blocknr -= (be32_to_cpu((jsb)->s_maxlen) -	\
+			    be32_to_cpu((jsb)->s_first));
+
+void do_logdump(int argc, char **argv)
+{
+	int		c;
+	int		retval;
+	char		*out_fn;
+	FILE		*out_file;
+
+	char		*inode_spec = NULL;
+	char		*journal_fn = NULL;
+	int		journal_fd = 0;
+	int		use_sb = 0;
+	ext2_ino_t	journal_inum;
+	struct ext2_inode journal_inode;
+	ext2_file_t 	journal_file;
+	char		*tmp;
+	struct journal_source journal_source;
+	struct ext2_super_block *es = NULL;
+
+	journal_source.where = JOURNAL_IS_INTERNAL;
+	journal_source.fd = 0;
+	journal_source.file = 0;
+	dump_all = 0;
+	dump_contents = 0;
+	dump_descriptors = 1;
+	block_to_dump = ANY_BLOCK;
+	bitmap_to_dump = -1;
+	inode_block_to_dump = ANY_BLOCK;
+	inode_to_dump = -1;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "ab:ci:f:s")) != EOF) {
+		switch (c) {
+		case 'a':
+			dump_all++;
+			break;
+		case 'b':
+			block_to_dump = strtoul(optarg, &tmp, 0);
+			if (*tmp) {
+				com_err(argv[0], 0,
+					"Bad block number - %s", optarg);
+				return;
+			}
+			dump_descriptors = 0;
+			break;
+		case 'c':
+			dump_contents++;
+			break;
+		case 'f':
+			journal_fn = optarg;
+			break;
+		case 'i':
+			inode_spec = optarg;
+			dump_descriptors = 0;
+			break;
+		case 's':
+			use_sb++;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+	if (optind != argc && optind != argc-1) {
+		goto print_usage;
+	}
+
+	if (current_fs)
+		es = current_fs->super;
+
+	if (inode_spec) {
+		int inode_group, group_offset, inodes_per_block;
+
+		if (check_fs_open(argv[0]))
+			return;
+
+		inode_to_dump = string_to_inode(inode_spec);
+		if (!inode_to_dump)
+			return;
+
+		inode_group = ((inode_to_dump - 1)
+			       / es->s_inodes_per_group);
+		group_offset = ((inode_to_dump - 1)
+				% es->s_inodes_per_group);
+		inodes_per_block = (current_fs->blocksize
+				    / sizeof(struct ext2_inode));
+
+		inode_block_to_dump =
+			ext2fs_inode_table_loc(current_fs, inode_group) +
+			(group_offset / inodes_per_block);
+		inode_offset_to_dump = ((group_offset % inodes_per_block)
+					* sizeof(struct ext2_inode));
+		printf("Inode %u is at group %u, block %llu, offset %u\n",
+		       inode_to_dump, inode_group,
+		       inode_block_to_dump, inode_offset_to_dump);
+	}
+
+	if (optind == argc) {
+		out_file = stdout;
+	} else {
+		out_fn = argv[optind];
+		out_file = fopen(out_fn, "w");
+		if (!out_file) {
+			com_err(argv[0], errno, "while opening %s for logdump",
+				out_fn);
+			goto errout;
+		}
+	}
+
+	if (block_to_dump != ANY_BLOCK && current_fs != NULL) {
+		group_to_dump = ((block_to_dump -
+				  es->s_first_data_block)
+				 / es->s_blocks_per_group);
+		bitmap_to_dump = ext2fs_block_bitmap_loc(current_fs, group_to_dump);
+	}
+
+	if (!journal_fn && check_fs_open(argv[0]))
+		goto errout;
+
+	if (journal_fn) {
+		/* Set up to read journal from a regular file somewhere */
+		journal_fd = open(journal_fn, O_RDONLY, 0);
+		if (journal_fd < 0) {
+			com_err(argv[0], errno, "while opening %s for logdump",
+				journal_fn);
+			goto errout;
+		}
+
+		journal_source.where = JOURNAL_IS_EXTERNAL;
+		journal_source.fd = journal_fd;
+	} else if ((journal_inum = es->s_journal_inum)) {
+		if (use_sb) {
+			if (es->s_jnl_backup_type != EXT3_JNL_BACKUP_BLOCKS) {
+				com_err(argv[0], 0,
+					"no journal backup in super block\n");
+				goto errout;
+			}
+			memset(&journal_inode, 0, sizeof(struct ext2_inode));
+			memcpy(&journal_inode.i_block[0], es->s_jnl_blocks,
+			       EXT2_N_BLOCKS*4);
+			journal_inode.i_size_high = es->s_jnl_blocks[15];
+			journal_inode.i_size = es->s_jnl_blocks[16];
+			journal_inode.i_links_count = 1;
+			journal_inode.i_mode = LINUX_S_IFREG | 0600;
+		} else {
+			if (debugfs_read_inode(journal_inum, &journal_inode,
+					       argv[0]))
+				goto errout;
+		}
+
+		retval = ext2fs_file_open2(current_fs, journal_inum,
+					   &journal_inode, 0, &journal_file);
+		if (retval) {
+			com_err(argv[0], retval, "while opening ext2 file");
+			goto errout;
+		}
+		journal_source.where = JOURNAL_IS_INTERNAL;
+		journal_source.file = journal_file;
+	} else {
+		char uuid[37];
+
+		uuid_unparse(es->s_journal_uuid, uuid);
+		journal_fn = blkid_get_devname(NULL, "UUID", uuid);
+		if (!journal_fn)
+				journal_fn = blkid_devno_to_devname(es->s_journal_dev);
+		if (!journal_fn) {
+			com_err(argv[0], 0, "filesystem has no journal");
+			goto errout;
+		}
+		journal_fd = open(journal_fn, O_RDONLY, 0);
+		if (journal_fd < 0) {
+			com_err(argv[0], errno, "while opening %s for logdump",
+				journal_fn);
+			free(journal_fn);
+			goto errout;
+		}
+		fprintf(out_file, "Using external journal found at %s\n",
+			journal_fn);
+		free(journal_fn);
+		journal_source.where = JOURNAL_IS_EXTERNAL;
+		journal_source.fd = journal_fd;
+	}
+
+	dump_journal(argv[0], out_file, &journal_source);
+
+	if (journal_source.where == JOURNAL_IS_INTERNAL)
+		ext2fs_file_close(journal_file);
+	else
+		close(journal_fd);
+
+errout:
+	if (out_file && (out_file != stdout))
+		fclose(out_file);
+
+	return;
+
+print_usage:
+	fprintf(stderr, "%s: Usage: logdump [-acs] [-b<block>] [-i<filespec>]\n\t"
+		"[-f<journal_file>] [output_file]\n", argv[0]);
+}
+
+
+static int read_journal_block(const char *cmd, struct journal_source *source,
+			      off_t offset, char *buf, int size,
+			      unsigned int *got)
+{
+	int retval;
+
+	if (source->where == JOURNAL_IS_EXTERNAL) {
+		if (lseek(source->fd, offset, SEEK_SET) < 0) {
+			retval = errno;
+			com_err(cmd, retval, "while seeking in reading journal");
+			return retval;
+		}
+		retval = read(source->fd, buf, size);
+		if (retval >= 0) {
+			*got = retval;
+			retval = 0;
+		} else
+			retval = errno;
+	} else {
+		retval = ext2fs_file_lseek(source->file, offset,
+					   EXT2_SEEK_SET, NULL);
+		if (retval) {
+			com_err(cmd, retval, "while seeking in reading journal");
+			return retval;
+		}
+
+		retval = ext2fs_file_read(source->file, buf, size, got);
+	}
+
+	if (retval)
+		com_err(cmd, retval, "while reading journal");
+	else if (*got != (unsigned int) size) {
+		com_err(cmd, 0, "short read (read %d, expected %d) "
+			"while reading journal", *got, size);
+		retval = -1;
+	}
+
+	return retval;
+}
+
+static const char *type_to_name(int btype)
+{
+	switch (btype) {
+	case JFS_DESCRIPTOR_BLOCK:
+		return "descriptor block";
+	case JFS_COMMIT_BLOCK:
+		return "commit block";
+	case JFS_SUPERBLOCK_V1:
+		return "V1 superblock";
+	case JFS_SUPERBLOCK_V2:
+		return "V2 superblock";
+	case JFS_REVOKE_BLOCK:
+		return "revoke table";
+	}
+	return "unrecognised type";
+}
+
+
+static void dump_journal(char *cmdname, FILE *out_file,
+			 struct journal_source *source)
+{
+	struct ext2_super_block *sb;
+	char			jsb_buffer[1024];
+	char			buf[8192];
+	journal_superblock_t	*jsb;
+	unsigned int		blocksize = 1024;
+	unsigned int		got;
+	int			retval;
+	__u32			magic, sequence, blocktype;
+	journal_header_t	*header;
+
+	tid_t			transaction;
+	unsigned int		blocknr = 0;
+
+	/* First, check to see if there's an ext2 superblock header */
+	retval = read_journal_block(cmdname, source, 0,
+				    buf, 2048, &got);
+	if (retval)
+		return;
+
+	jsb = (journal_superblock_t *) buf;
+	sb = (struct ext2_super_block *) (buf+1024);
+#ifdef WORDS_BIGENDIAN
+	if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
+		ext2fs_swap_super(sb);
+#endif
+
+	if ((be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) &&
+	    (sb->s_magic == EXT2_SUPER_MAGIC) &&
+	    (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
+		blocksize = EXT2_BLOCK_SIZE(sb);
+		blocknr = (blocksize == 1024) ? 2 : 1;
+		uuid_unparse(sb->s_uuid, jsb_buffer);
+		fprintf(out_file, "Ext2 superblock header found.\n");
+		if (dump_all) {
+			fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
+			fprintf(out_file, "\tblocksize=%d\n", blocksize);
+			fprintf(out_file, "\tjournal data size %lu\n",
+				(unsigned long) ext2fs_blocks_count(sb));
+		}
+	}
+
+	/* Next, read the journal superblock */
+
+	retval = read_journal_block(cmdname, source, blocknr*blocksize,
+				    jsb_buffer, 1024, &got);
+	if (retval)
+		return;
+
+	jsb = (journal_superblock_t *) jsb_buffer;
+	if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) {
+		fprintf(out_file,
+			"Journal superblock magic number invalid!\n");
+		return;
+	}
+	blocksize = be32_to_cpu(jsb->s_blocksize);
+	transaction = be32_to_cpu(jsb->s_sequence);
+	blocknr = be32_to_cpu(jsb->s_start);
+
+	fprintf(out_file, "Journal starts at block %u, transaction %u\n",
+		blocknr, transaction);
+
+	if (!blocknr)
+		/* Empty journal, nothing to do. */
+		return;
+
+	while (1) {
+		retval = read_journal_block(cmdname, source,
+					    blocknr*blocksize, buf,
+					    blocksize, &got);
+		if (retval || got != blocksize)
+			return;
+
+		header = (journal_header_t *) buf;
+
+		magic = be32_to_cpu(header->h_magic);
+		sequence = be32_to_cpu(header->h_sequence);
+		blocktype = be32_to_cpu(header->h_blocktype);
+
+		if (magic != JFS_MAGIC_NUMBER) {
+			fprintf (out_file, "No magic number at block %u: "
+				 "end of journal.\n", blocknr);
+			return;
+		}
+
+		if (sequence != transaction) {
+			fprintf (out_file, "Found sequence %u (not %u) at "
+				 "block %u: end of journal.\n",
+				 sequence, transaction, blocknr);
+			return;
+		}
+
+		if (dump_descriptors) {
+			fprintf (out_file, "Found expected sequence %u, "
+				 "type %u (%s) at block %u\n",
+				 sequence, blocktype,
+				 type_to_name(blocktype), blocknr);
+		}
+
+		switch (blocktype) {
+		case JFS_DESCRIPTOR_BLOCK:
+			dump_descriptor_block(out_file, source, buf, jsb,
+					      &blocknr, blocksize,
+					      transaction);
+			continue;
+
+		case JFS_COMMIT_BLOCK:
+			transaction++;
+			blocknr++;
+			WRAP(jsb, blocknr);
+			continue;
+
+		case JFS_REVOKE_BLOCK:
+			dump_revoke_block(out_file, buf, jsb,
+					  blocknr, blocksize,
+					  transaction);
+			blocknr++;
+			WRAP(jsb, blocknr);
+			continue;
+
+		default:
+			fprintf (out_file, "Unexpected block type %u at "
+				 "block %u.\n", blocktype, blocknr);
+			return;
+		}
+	}
+}
+
+
+static void dump_descriptor_block(FILE *out_file,
+				  struct journal_source *source,
+				  char *buf,
+				  journal_superblock_t *jsb,
+				  unsigned int *blockp, int blocksize,
+				  tid_t transaction)
+{
+	int			offset, tag_size = JBD_TAG_SIZE32;
+	char			*tagp;
+	journal_block_tag_t	*tag;
+	unsigned int		blocknr;
+	__u32			tag_block;
+	__u32			tag_flags;
+
+	if (be32_to_cpu(jsb->s_feature_incompat) & JFS_FEATURE_INCOMPAT_64BIT)
+		tag_size = JBD_TAG_SIZE64;
+
+	offset = sizeof(journal_header_t);
+	blocknr = *blockp;
+
+	if (dump_all)
+		fprintf(out_file, "Dumping descriptor block, sequence %u, at "
+			"block %u:\n", transaction, blocknr);
+
+	++blocknr;
+	WRAP(jsb, blocknr);
+
+	do {
+		/* Work out the location of the current tag, and skip to
+		 * the next one... */
+		tagp = &buf[offset];
+		tag = (journal_block_tag_t *) tagp;
+		offset += tag_size;
+
+		/* ... and if we have gone too far, then we've reached the
+		   end of this block. */
+		if (offset > blocksize)
+			break;
+
+		tag_block = be32_to_cpu(tag->t_blocknr);
+		tag_flags = be32_to_cpu(tag->t_flags);
+
+		if (!(tag_flags & JFS_FLAG_SAME_UUID))
+			offset += 16;
+
+		dump_metadata_block(out_file, source, jsb,
+				    blocknr, tag_block, tag_flags, blocksize,
+				    transaction);
+
+		++blocknr;
+		WRAP(jsb, blocknr);
+
+	} while (!(tag_flags & JFS_FLAG_LAST_TAG));
+
+	*blockp = blocknr;
+}
+
+
+static void dump_revoke_block(FILE *out_file, char *buf,
+			      journal_superblock_t *jsb EXT2FS_ATTR((unused)),
+			      unsigned int blocknr,
+			      int blocksize EXT2FS_ATTR((unused)),
+			      tid_t transaction)
+{
+	int			offset, max;
+	journal_revoke_header_t *header;
+	unsigned int		*entry, rblock;
+
+	if (dump_all)
+		fprintf(out_file, "Dumping revoke block, sequence %u, at "
+			"block %u:\n", transaction, blocknr);
+
+	header = (journal_revoke_header_t *) buf;
+	offset = sizeof(journal_revoke_header_t);
+	max = be32_to_cpu(header->r_count);
+
+	while (offset < max) {
+		entry = (unsigned int *) (buf + offset);
+		rblock = be32_to_cpu(*entry);
+		if (dump_all || rblock == block_to_dump) {
+			fprintf(out_file, "  Revoke FS block %u", rblock);
+			if (dump_all)
+				fprintf(out_file, "\n");
+			else
+				fprintf(out_file," at block %u, sequence %u\n",
+					blocknr, transaction);
+		}
+		offset += 4;
+	}
+}
+
+
+static void show_extent(FILE *out_file, int start_extent, int end_extent,
+			__u32 first_block)
+{
+	if (start_extent >= 0 && first_block != 0)
+		fprintf(out_file, "(%d+%u): %u ",
+			start_extent, end_extent-start_extent, first_block);
+}
+
+static void show_indirect(FILE *out_file, const char *name, __u32 where)
+{
+	if (where)
+		fprintf(out_file, "(%s): %u ", name, where);
+}
+
+
+static void dump_metadata_block(FILE *out_file, struct journal_source *source,
+				journal_superblock_t *jsb EXT2FS_ATTR((unused)),
+				unsigned int log_blocknr,
+				unsigned int fs_blocknr,
+				unsigned int log_tag_flags,
+				int blocksize,
+				tid_t transaction)
+{
+	unsigned int 	got;
+	int		retval;
+	char 		buf[8192];
+
+	if (!(dump_all
+	      || (fs_blocknr == block_to_dump)
+	      || (fs_blocknr == inode_block_to_dump)
+	      || (fs_blocknr == bitmap_to_dump)))
+		return;
+
+	fprintf(out_file, "  FS block %u logged at ", fs_blocknr);
+	if (!dump_all)
+		fprintf(out_file, "sequence %u, ", transaction);
+	fprintf(out_file, "journal block %u (flags 0x%x)\n", log_blocknr,
+		log_tag_flags);
+
+	/* There are two major special cases to parse:
+	 *
+	 * If this block is a block
+	 * bitmap block, we need to give it special treatment so that we
+	 * can log any allocates and deallocates which affect the
+	 * block_to_dump query block.
+	 *
+	 * If the block is an inode block for the inode being searched
+	 * for, then we need to dump the contents of that inode
+	 * structure symbolically.
+	 */
+
+	if (!(dump_contents && dump_all)
+	    && fs_blocknr != block_to_dump
+	    && fs_blocknr != bitmap_to_dump
+	    && fs_blocknr != inode_block_to_dump)
+		return;
+
+	retval = read_journal_block("logdump", source,
+				    blocksize * log_blocknr,
+				    buf, blocksize, &got);
+	if (retval)
+		return;
+
+	if (fs_blocknr == bitmap_to_dump) {
+		struct ext2_super_block *super;
+		int offset;
+
+		super = current_fs->super;
+		offset = ((block_to_dump - super->s_first_data_block) %
+			  super->s_blocks_per_group);
+
+		fprintf(out_file, "    (block bitmap for block %llu: "
+			"block is %s)\n",
+			block_to_dump,
+			ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");
+	}
+
+	if (fs_blocknr == inode_block_to_dump) {
+		struct ext2_inode *inode;
+		int first, prev, this, start_extent, i;
+
+		fprintf(out_file, "    (inode block for inode %u):\n",
+			inode_to_dump);
+
+		inode = (struct ext2_inode *) (buf + inode_offset_to_dump);
+		internal_dump_inode(out_file, "    ", inode_to_dump, inode, 0);
+
+		/* Dump out the direct/indirect blocks here:
+		 * internal_dump_inode can only dump them from the main
+		 * on-disk inode, not from the journaled copy of the
+		 * inode. */
+
+		fprintf (out_file, "    Blocks:  ");
+		first = prev = start_extent = -1;
+
+		for (i=0; i<EXT2_NDIR_BLOCKS; i++) {
+			this = inode->i_block[i];
+			if (start_extent >= 0  && this == prev+1) {
+				prev = this;
+				continue;
+			} else {
+				show_extent(out_file, start_extent, i, first);
+				start_extent = i;
+				first = prev = this;
+			}
+		}
+		show_extent(out_file, start_extent, i, first);
+		show_indirect(out_file, "IND", inode->i_block[i++]);
+		show_indirect(out_file, "DIND", inode->i_block[i++]);
+		show_indirect(out_file, "TIND", inode->i_block[i++]);
+
+		fprintf(out_file, "\n");
+	}
+
+	if (dump_contents)
+		do_hexdump(out_file, buf, blocksize);
+
+}
+
+static void do_hexdump (FILE *out_file, char *buf, int blocksize)
+{
+	int i,j;
+	int *intp;
+	char *charp;
+	unsigned char c;
+
+	intp = (int *) buf;
+	charp = (char *) buf;
+
+	for (i=0; i<blocksize; i+=16) {
+		fprintf(out_file, "    %04x:  ", i);
+		for (j=0; j<16; j+=4)
+			fprintf(out_file, "%08x ", *intp++);
+		for (j=0; j<16; j++) {
+			c = *charp++;
+			if (c < ' ' || c >= 127)
+				c = '.';
+			fprintf(out_file, "%c", c);
+		}
+		fprintf(out_file, "\n");
+	}
+}
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ls.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ls.c
new file mode 100644
index 0000000..b4036de
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ls.c
@@ -0,0 +1,183 @@
+/*
+ * ls.c --- list directories
+ *
+ * Copyright (C) 1997 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+/*
+ * list directory
+ */
+
+#define LONG_OPT	0x0001
+#define DELETED_OPT	0x0002
+#define PARSE_OPT	0x0004
+
+struct list_dir_struct {
+	FILE	*f;
+	int	col;
+	int	options;
+};
+
+static const char *monstr[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+				"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+
+static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
+			 int	entry,
+			 struct ext2_dir_entry *dirent,
+			 int	offset EXT2FS_ATTR((unused)),
+			 int	blocksize EXT2FS_ATTR((unused)),
+			 char	*buf EXT2FS_ATTR((unused)),
+			 void	*private)
+{
+	struct ext2_inode	inode;
+	ext2_ino_t		ino;
+	struct tm		*tm_p;
+	time_t			modtime;
+	char			name[EXT2_NAME_LEN + 1];
+	char			tmp[EXT2_NAME_LEN + 16];
+	char			datestr[80];
+	char			lbr, rbr;
+	int			thislen;
+	struct list_dir_struct *ls = (struct list_dir_struct *) private;
+
+	thislen = dirent->name_len & 0xFF;
+	strncpy(name, dirent->name, thislen);
+	name[thislen] = '\0';
+	ino = dirent->inode;
+
+	if (entry == DIRENT_DELETED_FILE) {
+		lbr = '<';
+		rbr = '>';
+		ino = 0;
+	} else {
+		lbr = rbr = ' ';
+	}
+	if (ls->options & PARSE_OPT) {
+		if (ino) {
+			if (debugfs_read_inode(ino, &inode, name))
+				return 0;
+		} else
+			memset(&inode, 0, sizeof(struct ext2_inode));
+		fprintf(ls->f,"/%u/%06o/%d/%d/%s/",ino,inode.i_mode,inode.i_uid, inode.i_gid,name);
+		if (LINUX_S_ISDIR(inode.i_mode))
+			fprintf(ls->f, "/");
+		else
+			fprintf(ls->f, "%lld/", EXT2_I_SIZE(&inode));
+		fprintf(ls->f, "\n");
+	} else if (ls->options & LONG_OPT) {
+		if (ino) {
+			if (debugfs_read_inode(ino, &inode, name))
+				return 0;
+			modtime = inode.i_mtime;
+			tm_p = localtime(&modtime);
+			sprintf(datestr, "%2d-%s-%4d %02d:%02d",
+				tm_p->tm_mday, monstr[tm_p->tm_mon],
+				1900 + tm_p->tm_year, tm_p->tm_hour,
+				tm_p->tm_min);
+		} else {
+			strcpy(datestr, "                 ");
+			memset(&inode, 0, sizeof(struct ext2_inode));
+		}
+		fprintf(ls->f, "%c%6u%c %6o (%d)  %5d  %5d   ", lbr, ino, rbr,
+			inode.i_mode, dirent->name_len >> 8,
+			inode_uid(inode), inode_gid(inode));
+		if (LINUX_S_ISDIR(inode.i_mode))
+			fprintf(ls->f, "%5d", inode.i_size);
+		else
+			fprintf(ls->f, "%5llu", EXT2_I_SIZE(&inode));
+		fprintf (ls->f, " %s %s\n", datestr, name);
+	} else {
+		sprintf(tmp, "%c%u%c (%d) %s   ", lbr, dirent->inode, rbr,
+			dirent->rec_len, name);
+		thislen = strlen(tmp);
+
+		if (ls->col + thislen > 80) {
+			fprintf(ls->f, "\n");
+			ls->col = 0;
+		}
+		fprintf(ls->f, "%s", tmp);
+		ls->col += thislen;
+	}
+	return 0;
+}
+
+void do_list_dir(int argc, char *argv[])
+{
+	ext2_ino_t	inode;
+	int		retval;
+	int		c;
+	int		flags;
+	struct list_dir_struct ls;
+
+	ls.options = 0;
+	if (check_fs_open(argv[0]))
+		return;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "dlp")) != EOF) {
+		switch (c) {
+		case 'l':
+			ls.options |= LONG_OPT;
+			break;
+		case 'd':
+			ls.options |= DELETED_OPT;
+			break;
+		case 'p':
+			ls.options |= PARSE_OPT;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+
+	if (argc > optind+1) {
+	print_usage:
+		com_err(0, 0, "Usage: ls [-l] [-d] [-p] file");
+		return;
+	}
+
+	if (argc == optind)
+		inode = cwd;
+	else
+		inode = string_to_inode(argv[optind]);
+	if (!inode)
+		return;
+
+	ls.f = open_pager();
+	ls.col = 0;
+	flags = DIRENT_FLAG_INCLUDE_EMPTY;
+	if (ls.options & DELETED_OPT)
+		flags |= DIRENT_FLAG_INCLUDE_REMOVED;
+
+	retval = ext2fs_dir_iterate2(current_fs, inode, flags,
+				    0, list_dir_proc, &ls);
+	fprintf(ls.f, "\n");
+	close_pager(ls.f);
+	if (retval)
+		com_err(argv[1], retval, 0);
+
+	return;
+}
+
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/lsdel.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/lsdel.c
new file mode 100644
index 0000000..e5b2d20
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/lsdel.c
@@ -0,0 +1,212 @@
+/*
+ * lsdel.c --- routines to try to help a user recover a deleted file.
+ *
+ * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ * Theodore Ts'o.  This file may be redistributed under the terms of
+ * the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "debugfs.h"
+
+struct deleted_info {
+	ext2_ino_t	ino;
+	unsigned short	mode;
+	__u32		uid;
+	__u64		size;
+	time_t		dtime;
+	e2_blkcnt_t	num_blocks;
+	e2_blkcnt_t	free_blocks;
+};
+
+struct lsdel_struct {
+	ext2_ino_t		inode;
+	e2_blkcnt_t		num_blocks;
+	e2_blkcnt_t		free_blocks;
+	e2_blkcnt_t		bad_blocks;
+};
+
+static int deleted_info_compare(const void *a, const void *b)
+{
+	const struct deleted_info *arg1, *arg2;
+
+	arg1 = (const struct deleted_info *) a;
+	arg2 = (const struct deleted_info *) b;
+
+	return arg1->dtime - arg2->dtime;
+}
+
+static int lsdel_proc(ext2_filsys fs,
+		      blk64_t	*block_nr,
+		      e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+		      blk64_t ref_block EXT2FS_ATTR((unused)),
+		      int ref_offset EXT2FS_ATTR((unused)),
+		      void *private)
+{
+	struct lsdel_struct *lsd = (struct lsdel_struct *) private;
+
+	lsd->num_blocks++;
+
+	if (*block_nr < fs->super->s_first_data_block ||
+	    *block_nr >= ext2fs_blocks_count(fs->super)) {
+		lsd->bad_blocks++;
+		return BLOCK_ABORT;
+	}
+
+	if (!ext2fs_test_block_bitmap2(fs->block_map,*block_nr))
+		lsd->free_blocks++;
+
+	return 0;
+}
+
+void do_lsdel(int argc, char **argv)
+{
+	struct lsdel_struct 	lsd;
+	struct deleted_info	*delarray;
+	int			num_delarray, max_delarray;
+	ext2_inode_scan		scan = 0;
+	ext2_ino_t		ino;
+	struct ext2_inode	inode;
+	errcode_t		retval;
+	char			*block_buf;
+	int			i;
+ 	long			secs = 0;
+ 	char			*tmp;
+	time_t			now;
+	FILE			*out;
+
+	if (common_args_process(argc, argv, 1, 2, "list_deleted_inodes",
+				"[secs]", 0))
+		return;
+
+	if (argc > 1) {
+		secs = strtol(argv[1],&tmp,0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad time - %s",argv[1]);
+			return;
+		}
+	}
+
+	now = current_fs->now ? current_fs->now : time(0);
+	max_delarray = 100;
+	num_delarray = 0;
+	delarray = malloc(max_delarray * sizeof(struct deleted_info));
+	if (!delarray) {
+		com_err("ls_deleted_inodes", ENOMEM,
+			"while allocating deleted information storage");
+		exit(1);
+	}
+
+	block_buf = malloc(current_fs->blocksize * 3);
+	if (!block_buf) {
+		com_err("ls_deleted_inodes", ENOMEM, "while allocating block buffer");
+		goto error_out;
+	}
+
+	retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
+	if (retval) {
+		com_err("ls_deleted_inodes", retval,
+			"while opening inode scan");
+		goto error_out;
+	}
+
+	do {
+		retval = ext2fs_get_next_inode(scan, &ino, &inode);
+	} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+	if (retval) {
+		com_err("ls_deleted_inodes", retval,
+			"while starting inode scan");
+		goto error_out;
+	}
+
+	while (ino) {
+		if ((inode.i_dtime == 0) ||
+		    (secs && ((unsigned) abs(now - secs) > inode.i_dtime)))
+			goto next;
+
+		lsd.inode = ino;
+		lsd.num_blocks = 0;
+		lsd.free_blocks = 0;
+		lsd.bad_blocks = 0;
+
+		retval = ext2fs_block_iterate3(current_fs, ino,
+					       BLOCK_FLAG_READ_ONLY, block_buf,
+					       lsdel_proc, &lsd);
+		if (retval) {
+			com_err("ls_deleted_inodes", retval,
+				"while calling ext2fs_block_iterate2");
+			goto next;
+		}
+		if (lsd.free_blocks && !lsd.bad_blocks) {
+			if (num_delarray >= max_delarray) {
+				max_delarray += 50;
+				delarray = realloc(delarray,
+			   max_delarray * sizeof(struct deleted_info));
+				if (!delarray) {
+					com_err("ls_deleted_inodes",
+						ENOMEM,
+						"while reallocating array");
+					exit(1);
+				}
+			}
+
+			delarray[num_delarray].ino = ino;
+			delarray[num_delarray].mode = inode.i_mode;
+			delarray[num_delarray].uid = inode_uid(inode);
+			delarray[num_delarray].size = EXT2_I_SIZE(&inode);
+			delarray[num_delarray].dtime = inode.i_dtime;
+			delarray[num_delarray].num_blocks = lsd.num_blocks;
+			delarray[num_delarray].free_blocks = lsd.free_blocks;
+			num_delarray++;
+		}
+
+	next:
+		do {
+			retval = ext2fs_get_next_inode(scan, &ino, &inode);
+		} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+		if (retval) {
+			com_err("ls_deleted_inodes", retval,
+				"while doing inode scan");
+			goto error_out;
+		}
+	}
+
+	out = open_pager();
+
+	fprintf(out, " Inode  Owner  Mode    Size      Blocks   Time deleted\n");
+
+	qsort(delarray, num_delarray, sizeof(struct deleted_info),
+	      deleted_info_compare);
+
+	for (i = 0; i < num_delarray; i++) {
+		fprintf(out, "%6u %6d %6o %6llu %6lld/%6lld %s",
+			delarray[i].ino,
+			delarray[i].uid, delarray[i].mode, delarray[i].size,
+			delarray[i].free_blocks, delarray[i].num_blocks,
+			time_to_string(delarray[i].dtime));
+	}
+	fprintf(out, "%d deleted inodes found.\n", num_delarray);
+	close_pager(out);
+
+error_out:
+	free(block_buf);
+	free(delarray);
+	if (scan)
+		ext2fs_close_inode_scan(scan);
+	return;
+}
+
+
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ncheck.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ncheck.c
new file mode 100644
index 0000000..58f3a50
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ncheck.c
@@ -0,0 +1,206 @@
+/*
+ * ncheck.c --- given a list of inodes, generate a list of names
+ *
+ * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+struct inode_walk_struct {
+	ext2_ino_t		dir;
+	ext2_ino_t		*iarray;
+	int			inodes_left;
+	int			num_inodes;
+	int			position;
+	char			*parent;
+	unsigned int		get_pathname_failed:1;
+	unsigned int		check_dirent:1;
+};
+
+static int ncheck_proc(struct ext2_dir_entry *dirent,
+		       int	offset EXT2FS_ATTR((unused)),
+		       int	blocksize EXT2FS_ATTR((unused)),
+		       char	*buf EXT2FS_ATTR((unused)),
+		       void	*private)
+{
+	struct inode_walk_struct *iw = (struct inode_walk_struct *) private;
+	struct ext2_inode inode;
+	errcode_t	retval;
+	int		filetype = dirent->name_len >> 8;
+	int		i;
+
+	iw->position++;
+	if (iw->position <= 2)
+		return 0;
+	for (i=0; i < iw->num_inodes; i++) {
+		if (iw->iarray[i] == dirent->inode) {
+			if (!iw->parent && !iw->get_pathname_failed) {
+				retval = ext2fs_get_pathname(current_fs,
+							     iw->dir,
+							     0, &iw->parent);
+				if (retval) {
+					com_err("ncheck", retval,
+		"while calling ext2fs_get_pathname for inode #%u", iw->dir);
+					iw->get_pathname_failed = 1;
+				}
+			}
+			if (iw->parent)
+				printf("%u\t%s/%.*s", iw->iarray[i],
+				       iw->parent,
+				       (dirent->name_len & 0xFF), dirent->name);
+			else
+				printf("%u\t<%u>/%.*s", iw->iarray[i],
+				       iw->dir,
+				       (dirent->name_len & 0xFF), dirent->name);
+			if (iw->check_dirent && filetype) {
+				if (!debugfs_read_inode(dirent->inode, &inode,
+							"ncheck") &&
+				    filetype != ext2_file_type(inode.i_mode)) {
+					printf("  <--- BAD FILETYPE");
+				}
+			}
+			putc('\n', stdout);
+		}
+	}
+	if (!iw->inodes_left)
+		return DIRENT_ABORT;
+
+	return 0;
+}
+
+void do_ncheck(int argc, char **argv)
+{
+	struct inode_walk_struct iw;
+	int			c, i;
+	ext2_inode_scan		scan = 0;
+	ext2_ino_t		ino;
+	struct ext2_inode	inode;
+	errcode_t		retval;
+	char			*tmp;
+
+	iw.check_dirent = 0;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "c")) != EOF) {
+		switch (c) {
+		case 'c':
+			iw.check_dirent = 1;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if (argc < 1) {
+	print_usage:
+		com_err(argv[0], 0, "Usage: ncheck [-c] <inode number> ...");
+		return;
+	}
+	if (check_fs_open(argv[0]))
+		return;
+
+	iw.iarray = malloc(sizeof(ext2_ino_t) * argc);
+	if (!iw.iarray) {
+		com_err("ncheck", ENOMEM,
+			"while allocating inode number array");
+		return;
+	}
+	memset(iw.iarray, 0, sizeof(ext2_ino_t) * argc);
+
+	for (i=0; i < argc; i++) {
+		iw.iarray[i] = strtol(argv[i], &tmp, 0);
+		if (*tmp) {
+			com_err(argv[0], 0, "Bad inode - %s", argv[i]);
+			goto error_out;
+		}
+	}
+
+	iw.num_inodes = iw.inodes_left = argc;
+
+	retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
+	if (retval) {
+		com_err("ncheck", retval, "while opening inode scan");
+		goto error_out;
+	}
+
+	do {
+		retval = ext2fs_get_next_inode(scan, &ino, &inode);
+	} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+	if (retval) {
+		com_err("ncheck", retval, "while starting inode scan");
+		goto error_out;
+	}
+
+	printf("Inode\tPathname\n");
+	while (ino) {
+		if (!inode.i_links_count)
+			goto next;
+		/*
+		 * To handle filesystems touched by 0.3c extfs; can be
+		 * removed later.
+		 */
+		if (inode.i_dtime)
+			goto next;
+		/* Ignore anything that isn't a directory */
+		if (!LINUX_S_ISDIR(inode.i_mode))
+			goto next;
+
+		iw.position = 0;
+		iw.parent = 0;
+		iw.dir = ino;
+		iw.get_pathname_failed = 0;
+
+		retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
+					    ncheck_proc, &iw);
+		ext2fs_free_mem(&iw.parent);
+		if (retval) {
+			com_err("ncheck", retval,
+				"while calling ext2_dir_iterate");
+			goto next;
+		}
+
+		if (iw.inodes_left == 0)
+			break;
+
+	next:
+		do {
+			retval = ext2fs_get_next_inode(scan, &ino, &inode);
+		} while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
+
+		if (retval) {
+			com_err("ncheck", retval,
+				"while doing inode scan");
+			goto error_out;
+		}
+	}
+
+error_out:
+	free(iw.iarray);
+	if (scan)
+		ext2fs_close_inode_scan(scan);
+	return;
+}
+
+
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ro_debug_cmds.ct b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ro_debug_cmds.ct
new file mode 100644
index 0000000..8226d1a
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/ro_debug_cmds.ct
@@ -0,0 +1,94 @@
+#
+# Restricted set of debugfs commands
+#
+# Copyright (C) 1993 Theodore Ts'o.  This file may be redistributed
+# under the terms of the GNU Public License.
+#
+command_table debug_cmds;
+
+request do_show_debugfs_params, "Show debugfs parameters",
+	show_debugfs_params, params;
+
+request do_open_filesys, "Open a filesystem",
+	open_filesys, open;
+
+request do_close_filesys, "Close the filesystem",
+	close_filesys, close;
+
+request do_freefrag, "Report free space fragmentation",
+	freefrag, e2freefrag;
+
+request do_show_super_stats, "Show superblock statistics",
+	show_super_stats, stats;
+
+request do_ncheck, "Do inode->name translation",
+	ncheck;
+
+request do_icheck, "Do block->inode translation",
+	icheck;
+
+request do_chroot, "Change root directory",
+	change_root_directory, chroot;
+
+request do_change_working_dir, "Change working directory",
+	change_working_directory, cd;
+
+request do_list_dir, "List directory",
+	list_directory, ls;
+
+request do_stat, "Show inode information ",
+	show_inode_info, stat;
+
+request do_dump_extents, "Dump extents information ",
+	dump_extents, extents, ex;
+
+request do_blocks, "Dump blocks used by an inode ",
+	blocks;
+
+request do_filefrag, "Report fragmentation information for an inode",
+	filefrag;
+
+request do_testi, "Test an inode's in-use flag",
+	testi;
+
+request do_find_free_block, "Find free block(s)",
+	find_free_block, ffb;
+
+request do_find_free_inode, "Find free inode(s)",
+	find_free_inode, ffi;
+
+request	do_print_working_directory, "Print current working directory",
+	print_working_directory, pwd; 
+
+request do_lsdel, "List deleted inodes",
+	list_deleted_inodes, lsdel;
+
+request do_logdump, "Dump the contents of the journal",
+	logdump;
+
+request do_htree_dump, "Dump a hash-indexed directory",
+	htree_dump, htree;
+
+request do_dx_hash, "Calculate the directory hash of a filename",
+	dx_hash, hash;
+
+request do_dirsearch, "Search a directory for a particular filename",
+	dirsearch;
+
+request do_bmap, "Calculate the logical->physical block mapping for an inode",
+	bmap;
+
+request do_imap, "Calculate the location of an inode",
+	imap;
+
+request do_supported_features, "Print features supported by this version of e2fsprogs",
+	supported_features;
+
+request do_dump_mmp, "Dump MMP information",
+	dump_mmp;
+
+request do_extent_open, "Open inode for extent manipulation",
+	extent_open, eo;
+
+end;
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/set_fields.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/set_fields.c
new file mode 100644
index 0000000..9c3b000
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/set_fields.c
@@ -0,0 +1,827 @@
+/*
+ * set_fields.c --- set a superblock value
+ *
+ * Copyright (C) 2000, 2001, 2002, 2003, 2004 by Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#define _XOPEN_SOURCE 600 /* for inclusion of strptime() and strtoull */
+
+#ifdef HAVE_STRTOULL
+#define STRTOULL strtoull
+#else
+#define STRTOULL strtoul
+#endif
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#if HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#include <fcntl.h>
+#include <utime.h>
+
+#include "debugfs.h"
+#include "uuid/uuid.h"
+#include "e2p/e2p.h"
+
+static struct ext2_super_block set_sb;
+static struct ext2_inode_large set_inode;
+static struct ext2_group_desc set_gd;
+static struct ext4_group_desc set_gd4;
+static struct mmp_struct set_mmp;
+static dgrp_t set_bg;
+static ext2_ino_t set_ino;
+static int array_idx;
+
+#define FLAG_ARRAY	0x0001
+
+struct field_set_info {
+	const char	*name;
+	void	*ptr;
+	void	*ptr2;
+	unsigned int	size;
+	errcode_t (*func)(struct field_set_info *info, char *field, char *arg);
+	int flags;
+	int max_idx;
+};
+
+static errcode_t parse_uint(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_int(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_string(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_uuid(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_hashalg(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_time(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_bmap(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_gd_csum(struct field_set_info *info, char *field, char *arg);
+static errcode_t parse_mmp_clear(struct field_set_info *info, char *field,
+				 char *arg);
+
+static struct field_set_info super_fields[] = {
+	{ "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
+	{ "blocks_count", &set_sb.s_blocks_count, &set_sb.s_blocks_count_hi,
+		4, parse_uint },
+	{ "r_blocks_count", &set_sb.s_r_blocks_count,
+		&set_sb.s_r_blocks_count_hi, 4, parse_uint },
+	{ "free_blocks_count", &set_sb.s_free_blocks_count,
+		&set_sb.s_free_blocks_hi, 4, parse_uint },
+	{ "free_inodes_count", &set_sb.s_free_inodes_count, NULL, 4, parse_uint },
+	{ "first_data_block", &set_sb.s_first_data_block, NULL, 4, parse_uint },
+	{ "log_block_size", &set_sb.s_log_block_size, NULL, 4, parse_uint },
+	{ "log_cluster_size", &set_sb.s_log_cluster_size, NULL, 4, parse_int },
+	{ "blocks_per_group", &set_sb.s_blocks_per_group, NULL, 4, parse_uint },
+	{ "clusters_per_group", &set_sb.s_clusters_per_group, NULL, 4, parse_uint },
+	{ "inodes_per_group", &set_sb.s_inodes_per_group, NULL, 4, parse_uint },
+	{ "mtime", &set_sb.s_mtime, NULL, 4, parse_time },
+	{ "wtime", &set_sb.s_wtime, NULL, 4, parse_time },
+	{ "mnt_count", &set_sb.s_mnt_count, NULL, 2, parse_uint },
+	{ "max_mnt_count", &set_sb.s_max_mnt_count, NULL, 2, parse_int },
+	/* s_magic */
+	{ "state", &set_sb.s_state, NULL, 2, parse_uint },
+	{ "errors", &set_sb.s_errors, NULL, 2, parse_uint },
+	{ "minor_rev_level", &set_sb.s_minor_rev_level, NULL, 2, parse_uint },
+	{ "lastcheck", &set_sb.s_lastcheck, NULL, 4, parse_time },
+	{ "checkinterval", &set_sb.s_checkinterval, NULL, 4, parse_uint },
+	{ "creator_os", &set_sb.s_creator_os, NULL, 4, parse_uint },
+	{ "rev_level", &set_sb.s_rev_level, NULL, 4, parse_uint },
+	{ "def_resuid", &set_sb.s_def_resuid, NULL, 2, parse_uint },
+	{ "def_resgid", &set_sb.s_def_resgid, NULL, 2, parse_uint },
+	{ "first_ino", &set_sb.s_first_ino, NULL, 4, parse_uint },
+	{ "inode_size", &set_sb.s_inode_size, NULL, 2, parse_uint },
+	{ "block_group_nr", &set_sb.s_block_group_nr, NULL, 2, parse_uint },
+	{ "feature_compat", &set_sb.s_feature_compat, NULL, 4, parse_uint },
+	{ "feature_incompat", &set_sb.s_feature_incompat, NULL, 4, parse_uint },
+	{ "feature_ro_compat", &set_sb.s_feature_ro_compat, NULL, 4, parse_uint },
+	{ "uuid", &set_sb.s_uuid, NULL, 16, parse_uuid },
+	{ "volume_name",  &set_sb.s_volume_name, NULL, 16, parse_string },
+	{ "last_mounted",  &set_sb.s_last_mounted, NULL, 64, parse_string },
+	{ "lastcheck",  &set_sb.s_lastcheck, NULL, 4, parse_uint },
+	{ "algorithm_usage_bitmap", &set_sb.s_algorithm_usage_bitmap, NULL,
+		  4, parse_uint },
+	{ "prealloc_blocks", &set_sb.s_prealloc_blocks, NULL, 1, parse_uint },
+	{ "prealloc_dir_blocks", &set_sb.s_prealloc_dir_blocks, NULL, 1,
+		  parse_uint },
+	{ "reserved_gdt_blocks", &set_sb.s_reserved_gdt_blocks, NULL, 2,
+		  parse_uint },
+	{ "journal_uuid", &set_sb.s_journal_uuid, NULL, 16, parse_uuid },
+	{ "journal_inum", &set_sb.s_journal_inum, NULL, 4, parse_uint },
+	{ "journal_dev", &set_sb.s_journal_dev, NULL, 4, parse_uint },
+	{ "last_orphan", &set_sb.s_last_orphan, NULL, 4, parse_uint },
+	{ "hash_seed", &set_sb.s_hash_seed, NULL, 16, parse_uuid },
+	{ "def_hash_version", &set_sb.s_def_hash_version, NULL, 1, parse_hashalg },
+	{ "jnl_backup_type", &set_sb.s_jnl_backup_type, NULL, 1, parse_uint },
+	{ "desc_size", &set_sb.s_desc_size, NULL, 2, parse_uint },
+	{ "default_mount_opts", &set_sb.s_default_mount_opts, NULL, 4, parse_uint },
+	{ "first_meta_bg", &set_sb.s_first_meta_bg, NULL, 4, parse_uint },
+	{ "mkfs_time", &set_sb.s_mkfs_time, NULL, 4, parse_time },
+	{ "jnl_blocks", &set_sb.s_jnl_blocks[0], NULL, 4, parse_uint, FLAG_ARRAY,
+	  17 },
+	{ "min_extra_isize", &set_sb.s_min_extra_isize, NULL, 2, parse_uint },
+	{ "want_extra_isize", &set_sb.s_want_extra_isize, NULL, 2, parse_uint },
+	{ "flags", &set_sb.s_flags, NULL, 4, parse_uint },
+	{ "raid_stride", &set_sb.s_raid_stride, NULL, 2, parse_uint },
+	{ "min_extra_isize", &set_sb.s_min_extra_isize, NULL, 4, parse_uint },
+	{ "mmp_interval", &set_sb.s_mmp_update_interval, NULL, 2, parse_uint },
+	{ "mmp_block", &set_sb.s_mmp_block, NULL, 8, parse_uint },
+	{ "raid_stripe_width", &set_sb.s_raid_stripe_width, NULL, 4, parse_uint },
+	{ "log_groups_per_flex", &set_sb.s_log_groups_per_flex, NULL, 1, parse_uint },
+	{ "kbytes_written", &set_sb.s_kbytes_written, NULL, 8, parse_uint },
+	{ "snapshot_inum", &set_sb.s_snapshot_inum, NULL, 4, parse_uint },
+	{ "snapshot_id", &set_sb.s_snapshot_id, NULL, 4, parse_uint },
+	{ "snapshot_r_blocks_count", &set_sb.s_snapshot_r_blocks_count,
+	  NULL, 8, parse_uint },
+	{ "snapshot_list", &set_sb.s_snapshot_list, NULL, 4, parse_uint },
+	{ "mount_opts",  &set_sb.s_mount_opts, NULL, 64, parse_string },
+	{ "usr_quota_inum", &set_sb.s_usr_quota_inum, NULL, 4, parse_uint },
+	{ "grp_quota_inum", &set_sb.s_grp_quota_inum, NULL, 4, parse_uint },
+	{ "overhead_blocks", &set_sb.s_overhead_blocks, NULL, 4, parse_uint },
+	{ "checksum", &set_sb.s_checksum, NULL, 4, parse_uint },
+	{ 0, 0, 0, 0 }
+};
+
+static struct field_set_info inode_fields[] = {
+	{ "inodes_count", &set_sb.s_inodes_count, NULL, 4, parse_uint },
+	{ "mode", &set_inode.i_mode, NULL, 2, parse_uint },
+	{ "uid", &set_inode.i_uid, &set_inode.osd2.linux2.l_i_uid_high,
+		2, parse_uint },
+	{ "size", &set_inode.i_size, &set_inode.i_size_high, 4, parse_uint },
+	{ "atime", &set_inode.i_atime, NULL, 4, parse_time },
+	{ "ctime", &set_inode.i_ctime, NULL, 4, parse_time },
+	{ "mtime", &set_inode.i_mtime, NULL, 4, parse_time },
+	{ "dtime", &set_inode.i_dtime, NULL, 4, parse_time },
+	{ "gid", &set_inode.i_gid, &set_inode.osd2.linux2.l_i_gid_high,
+		2, parse_uint },
+	{ "links_count", &set_inode.i_links_count, NULL, 2, parse_uint },
+	/* Special case: i_blocks is 4 bytes, i_blocks_high is 2 bytes */
+	{ "blocks", &set_inode.i_blocks, &set_inode.osd2.linux2.l_i_blocks_hi,
+		6, parse_uint },
+	{ "flags", &set_inode.i_flags, NULL, 4, parse_uint },
+	{ "version", &set_inode.osd1.linux1.l_i_version,
+		&set_inode.i_version_hi, 4, parse_uint },
+	{ "translator", &set_inode.osd1.hurd1.h_i_translator, NULL, 4, parse_uint },
+	{ "block", &set_inode.i_block[0], NULL, 4, parse_uint, FLAG_ARRAY,
+	  EXT2_NDIR_BLOCKS },
+	{ "block[IND]", &set_inode.i_block[EXT2_IND_BLOCK], NULL, 4, parse_uint },
+	{ "block[DIND]", &set_inode.i_block[EXT2_DIND_BLOCK], NULL, 4, parse_uint },
+	{ "block[TIND]", &set_inode.i_block[EXT2_TIND_BLOCK], NULL, 4, parse_uint },
+	{ "generation", &set_inode.i_generation, NULL, 4, parse_uint },
+	/* Special case: i_file_acl_high is 2 bytes */
+	{ "file_acl", &set_inode.i_file_acl, 
+		&set_inode.osd2.linux2.l_i_file_acl_high, 6, parse_uint },
+	{ "dir_acl", &set_inode.i_dir_acl, NULL, 4, parse_uint },
+	{ "faddr", &set_inode.i_faddr, NULL, 4, parse_uint },
+	{ "frag", &set_inode.osd2.hurd2.h_i_frag, NULL, 1, parse_uint },
+	{ "fsize", &set_inode.osd2.hurd2.h_i_fsize, NULL, 1, parse_uint },
+	{ "checksum", &set_inode.osd2.linux2.l_i_checksum_lo, 
+		&set_inode.i_checksum_hi, 2, parse_uint },
+	{ "author", &set_inode.osd2.hurd2.h_i_author, NULL,
+		4, parse_uint },
+	{ "extra_isize", &set_inode.i_extra_isize, NULL,
+		2, parse_uint },
+	{ "ctime_extra", &set_inode.i_ctime_extra, NULL,
+		4, parse_uint },
+	{ "mtime_extra", &set_inode.i_mtime_extra, NULL,
+		4, parse_uint },
+	{ "atime_extra", &set_inode.i_atime_extra, NULL,
+		4, parse_uint },
+	{ "crtime", &set_inode.i_crtime, NULL, 4, parse_uint },
+	{ "crtime_extra", &set_inode.i_crtime_extra, NULL,
+		4, parse_uint },
+	{ "bmap", NULL, NULL, 4, parse_bmap, FLAG_ARRAY },
+	{ 0, 0, 0, 0 }
+};
+
+static struct field_set_info ext2_bg_fields[] = {
+	{ "block_bitmap", &set_gd.bg_block_bitmap, NULL, 4, parse_uint },
+	{ "inode_bitmap", &set_gd.bg_inode_bitmap, NULL, 4, parse_uint },
+	{ "inode_table", &set_gd.bg_inode_table, NULL, 4, parse_uint },
+	{ "free_blocks_count", &set_gd.bg_free_blocks_count, NULL, 2, parse_uint },
+	{ "free_inodes_count", &set_gd.bg_free_inodes_count, NULL, 2, parse_uint },
+	{ "used_dirs_count", &set_gd.bg_used_dirs_count, NULL, 2, parse_uint },
+	{ "flags", &set_gd.bg_flags, NULL, 2, parse_uint },
+	{ "itable_unused", &set_gd.bg_itable_unused, NULL, 2, parse_uint },
+	{ "checksum", &set_gd.bg_checksum, NULL, 2, parse_gd_csum },
+	{ 0, 0, 0, 0 }
+};
+
+static struct field_set_info ext4_bg_fields[] = {
+	{ "block_bitmap", &set_gd4.bg_block_bitmap,
+		&set_gd4.bg_block_bitmap_hi, 4, parse_uint },
+	{ "inode_bitmap", &set_gd4.bg_inode_bitmap,
+		&set_gd4.bg_inode_bitmap_hi, 4, parse_uint },
+	{ "inode_table", &set_gd4.bg_inode_table,
+		&set_gd4.bg_inode_table_hi, 4, parse_uint },
+	{ "free_blocks_count", &set_gd4.bg_free_blocks_count,
+		&set_gd4.bg_free_blocks_count_hi, 2, parse_uint },
+	{ "free_inodes_count", &set_gd4.bg_free_inodes_count,
+		&set_gd4.bg_free_inodes_count_hi, 2, parse_uint },
+	{ "used_dirs_count", &set_gd4.bg_used_dirs_count,
+		&set_gd4.bg_used_dirs_count_hi, 2, parse_uint },
+	{ "flags", &set_gd4.bg_flags, NULL, 2, parse_uint },
+	{ "exclude_bitmap", &set_gd4.bg_exclude_bitmap_lo,
+		&set_gd4.bg_exclude_bitmap_hi, 4, parse_uint },
+	{ "block_bitmap_csum", &set_gd4.bg_block_bitmap_csum_lo,
+		&set_gd4.bg_block_bitmap_csum_hi, 2, parse_uint },
+	{ "inode_bitmap_csum", &set_gd4.bg_inode_bitmap_csum_lo,
+		&set_gd4.bg_inode_bitmap_csum_hi, 2, parse_uint },
+	{ "itable_unused", &set_gd4.bg_itable_unused,
+		&set_gd4.bg_itable_unused_hi, 2, parse_uint },
+	{ "checksum", &set_gd4.bg_checksum, NULL, 2, parse_gd_csum },
+	{ 0, 0, 0, 0 }
+};
+
+static struct field_set_info mmp_fields[] = {
+	{ "clear", &set_mmp.mmp_magic, NULL, sizeof(set_mmp), parse_mmp_clear },
+	{ "magic", &set_mmp.mmp_magic, NULL, 4, parse_uint },
+	{ "seq", &set_mmp.mmp_seq, NULL, 4, parse_uint },
+	{ "time", &set_mmp.mmp_time, NULL, 8, parse_uint },
+	{ "nodename", &set_mmp.mmp_nodename, NULL, sizeof(set_mmp.mmp_nodename),
+		parse_string },
+	{ "bdevname", &set_mmp.mmp_bdevname, NULL, sizeof(set_mmp.mmp_bdevname),
+		parse_string },
+	{ "check_interval", &set_mmp.mmp_check_interval, NULL, 2, parse_uint },
+};
+
+static int check_suffix(const char *field)
+{
+	int len = strlen(field);
+
+	if (len <= 3)
+		return 0;
+	field += len-3;
+	if (!strcmp(field, "_lo"))
+		return 1;
+	if (!strcmp(field, "_hi"))
+		return 2;
+	return 0;
+}
+
+static struct field_set_info *find_field(struct field_set_info *fields,
+					 char *field)
+{
+	struct field_set_info *ss;
+	const char	*prefix;
+	char		*arg, *delim, *idx, *tmp;
+	int		suffix, prefix_len;
+
+	if (fields == super_fields)
+		prefix = "s_";
+	else if (fields == inode_fields)
+		prefix = "i_";
+	else
+		prefix = "bg_";
+	prefix_len = strlen(prefix);
+	if (strncmp(field, prefix, prefix_len) == 0)
+		field += prefix_len;
+
+	arg = malloc(strlen(field)+1);
+	if (!arg)
+		return NULL;
+	strcpy(arg, field);
+
+	idx = strchr(arg, '[');
+	if (idx) {
+		*idx++ = 0;
+		delim = idx + strlen(idx) - 1;
+		if (!*idx || *delim != ']')
+			idx = 0;
+		else
+			*delim = 0;
+	}
+	/*
+	 * Can we parse the number?
+	 */
+	if (idx) {
+		array_idx = strtol(idx, &tmp, 0);
+		if (*tmp)
+			idx = 0;
+	}
+
+	/*
+	 * If there is a valid _hi or a _lo suffix, strip it off
+	 */
+	suffix = check_suffix(arg);
+	if (suffix > 0)
+		arg[strlen(arg)-3] = 0;
+
+	for (ss = fields ; ss->name ; ss++) {
+		if (suffix && ss->ptr2 == 0)
+			continue;
+		if (ss->flags & FLAG_ARRAY) {
+			if (!idx || (strcmp(ss->name, arg) != 0))
+				continue;
+			if (ss->max_idx > 0 && array_idx >= ss->max_idx)
+				continue;
+		} else {
+			if (strcmp(ss->name, arg) != 0)
+				continue;
+		}
+		free(arg);
+		return ss;
+	}
+	free(arg);
+	return NULL;
+}
+
+/*
+ * Note: info->size == 6 is special; this means a base size 4 bytes,
+ * and secondiory (high) size of 2 bytes.  This is needed for the
+ * special case of i_blocks_high and i_file_acl_high.
+ */
+static errcode_t parse_uint(struct field_set_info *info, char *field,
+			    char *arg)
+{
+	unsigned long long n, num, mask, limit;
+	int suffix = check_suffix(field);
+	char *tmp;
+	void *field1 = info->ptr, *field2 = info->ptr2;
+	int size = (info->size == 6) ? 4 : info->size;
+	union {
+		__u64	*ptr64;
+		__u32	*ptr32;
+		__u16	*ptr16;
+		__u8	*ptr8;
+	} u;
+
+	if (suffix == 1)
+		field2 = 0;
+	if (suffix == 2) {
+		field1 = field2;
+		field2 = 0;
+	}
+
+	u.ptr8 = (__u8 *) field1;
+	if (info->flags & FLAG_ARRAY)
+		u.ptr8 += array_idx * info->size;
+
+	errno = 0;
+	num = STRTOULL(arg, &tmp, 0);
+	if (*tmp || errno) {
+		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
+			arg, info->name);
+		return EINVAL;
+	}
+	mask = ~0ULL >> ((8 - size) * 8);
+	limit = ~0ULL >> ((8 - info->size) * 8);
+	if (field2 && info->size != 6)
+		limit = ~0ULL >> ((8 - info->size*2) * 8);
+
+	if (num > limit) {
+		fprintf(stderr, "Value '%s' exceeds field %s maximum %llu.\n",
+			arg, info->name, limit);
+		return EINVAL;
+	}
+	n = num & mask;
+	switch (size) {
+	case 8:
+		/* Should never get here */
+		fprintf(stderr, "64-bit field %s has a second 64-bit field\n"
+			"defined; BUG?!?\n", info->name);
+		*u.ptr64 = 0;
+		break;
+	case 4:
+		*u.ptr32 = n;
+		break;
+	case 2:
+		*u.ptr16 = n;
+		break;
+	case 1:
+		*u.ptr8 = n;
+		break;
+	}
+	if (!field2)
+		return 0;
+	n = num >> (size*8);
+	u.ptr8 = (__u8 *) field2;
+	if (info->size == 6)
+		size = 2;
+	switch (size) {
+	case 8:
+		*u.ptr64 = n;
+		break;
+	case 4:
+		*u.ptr32 = n;
+		break;
+	case 2:
+		*u.ptr16 = n;
+		break;
+	case 1:
+		*u.ptr8 = n;
+		break;
+	}
+	return 0;
+}
+
+static errcode_t parse_int(struct field_set_info *info,
+			   char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	long	num;
+	char *tmp;
+	__s32	*ptr32;
+	__s16	*ptr16;
+	__s8	*ptr8;
+
+	num = strtol(arg, &tmp, 0);
+	if (*tmp) {
+		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
+			arg, info->name);
+		return EINVAL;
+	}
+	switch (info->size) {
+	case 4:
+		ptr32 = (__s32 *) info->ptr;
+		*ptr32 = num;
+		break;
+	case 2:
+		ptr16 = (__s16 *) info->ptr;
+		*ptr16 = num;
+		break;
+	case 1:
+		ptr8 = (__s8 *) info->ptr;
+		*ptr8 = num;
+		break;
+	}
+	return 0;
+}
+
+static errcode_t parse_string(struct field_set_info *info,
+			      char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	char	*cp = (char *) info->ptr;
+
+	if (strlen(arg) >= info->size) {
+		fprintf(stderr, "Error maximum size for %s is %d.\n",
+			info->name, info->size);
+		return EINVAL;
+	}
+	strcpy(cp, arg);
+	return 0;
+}
+
+static errcode_t parse_time(struct field_set_info *info,
+			    char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	time_t		t;
+	__u32		*ptr32;
+
+	ptr32 = (__u32 *) info->ptr;
+
+	t = string_to_time(arg);
+
+	if (t == ((time_t) -1)) {
+		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
+			arg, info->name);
+		return EINVAL;
+	}
+	*ptr32 = t;
+	return 0;
+}
+
+static errcode_t parse_uuid(struct field_set_info *info,
+			    char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	unsigned char *	p = (unsigned char *) info->ptr;
+
+	if ((strcasecmp(arg, "null") == 0) ||
+	    (strcasecmp(arg, "clear") == 0)) {
+		uuid_clear(p);
+	} else if (strcasecmp(arg, "time") == 0) {
+		uuid_generate_time(p);
+	} else if (strcasecmp(arg, "random") == 0) {
+		uuid_generate(p);
+	} else if (uuid_parse(arg, p)) {
+		fprintf(stderr, "Invalid UUID format: %s\n", arg);
+		return EINVAL;
+	}
+	return 0;
+}
+
+static errcode_t parse_hashalg(struct field_set_info *info,
+			       char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	int	hashv;
+	unsigned char	*p = (unsigned char *) info->ptr;
+
+	hashv = e2p_string2hash(arg);
+	if (hashv < 0) {
+		fprintf(stderr, "Invalid hash algorithm: %s\n", arg);
+		return EINVAL;
+	}
+	*p = hashv;
+	return 0;
+}
+
+static errcode_t parse_bmap(struct field_set_info *info,
+			    char *field EXT2FS_ATTR((unused)), char *arg)
+{
+	blk64_t		blk;
+	errcode_t	retval;
+	char		*tmp;
+
+	blk = strtoull(arg, &tmp, 0);
+	if (*tmp) {
+		fprintf(stderr, "Couldn't parse '%s' for field %s.\n",
+			arg, info->name);
+		return EINVAL;
+	}
+
+	retval = ext2fs_bmap2(current_fs, set_ino,
+			     (struct ext2_inode *) &set_inode,
+			     NULL, BMAP_SET, array_idx, NULL, &blk);
+	if (retval) {
+		com_err("set_inode", retval, "while setting block map");
+	}
+	return retval;
+}
+
+static errcode_t parse_gd_csum(struct field_set_info *info, char *field,
+			       char *arg)
+{
+
+	if (strcmp(arg, "calc") == 0) {
+		ext2fs_group_desc_csum_set(current_fs, set_bg);
+		memcpy(&set_gd, ext2fs_group_desc(current_fs,
+					current_fs->group_desc,
+					set_bg),
+			sizeof(set_gd));
+		printf("Checksum set to 0x%04x\n",
+		       ext2fs_bg_checksum(current_fs, set_bg));
+		return 0;
+	}
+
+	return parse_uint(info, field, arg);
+}
+
+static void print_possible_fields(struct field_set_info *fields)
+{
+	struct field_set_info *ss;
+	const char	*type, *cmd;
+	FILE *f;
+	char name[40], idx[40];
+
+	if (fields == super_fields) {
+		type = "Superblock";
+		cmd = "set_super_value";
+	} else if (fields == inode_fields) {
+		type = "Inode";
+		cmd = "set_inode";
+	} else if (fields == mmp_fields) {
+		type = "MMP";
+		cmd = "set_mmp_value";
+	} else {
+		type = "Block group descriptor";
+		cmd = "set_block_group";
+	}
+	f = open_pager();
+
+	fprintf(f, "%s fields supported by the %s command:\n", type, cmd);
+
+	for (ss = fields ; ss->name ; ss++) {
+		type = "unknown";
+		if (ss->func == parse_string)
+			type = "string";
+		else if (ss->func == parse_int)
+			type = "integer";
+		else if (ss->func == parse_uint)
+			type = "unsigned integer";
+		else if (ss->func == parse_uuid)
+			type = "UUID";
+		else if (ss->func == parse_hashalg)
+			type = "hash algorithm";
+		else if (ss->func == parse_time)
+			type = "date/time";
+		else if (ss->func == parse_bmap)
+			type = "set physical->logical block map";
+		else if (ss->func == parse_gd_csum)
+			type = "unsigned integer OR \"calc\"";
+		strcpy(name, ss->name);
+		if (ss->flags & FLAG_ARRAY) {
+			if (ss->max_idx > 0)
+				sprintf(idx, "[%d]", ss->max_idx);
+			else
+				strcpy(idx, "[]");
+			strcat(name, idx);
+		}
+		if (ss->ptr2)
+			strcat(name, "[_hi|_lo]");
+		fprintf(f, "\t%-25s\t%s\n", name, type);
+	}
+	close_pager(f);
+}
+
+
+void do_set_super(int argc, char *argv[])
+{
+	const char *usage = "<field> <value>\n"
+		"\t\"set_super_value -l\" will list the names of "
+		"superblock fields\n\twhich can be set.";
+	static struct field_set_info *ss;
+
+	if ((argc == 2) && !strcmp(argv[1], "-l")) {
+		print_possible_fields(super_fields);
+		return;
+	}
+
+	if (common_args_process(argc, argv, 3, 3, "set_super_value",
+				usage, CHECK_FS_RW))
+		return;
+
+	if ((ss = find_field(super_fields, argv[1])) == 0) {
+		com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
+		return;
+	}
+	set_sb = *current_fs->super;
+	if (ss->func(ss, argv[1], argv[2]) == 0) {
+		*current_fs->super = set_sb;
+		ext2fs_mark_super_dirty(current_fs);
+	}
+}
+
+void do_set_inode(int argc, char *argv[])
+{
+	const char *usage = "<inode> <field> <value>\n"
+		"\t\"set_inode_field -l\" will list the names of "
+		"the fields in an ext2 inode\n\twhich can be set.";
+	static struct field_set_info *ss;
+
+	if ((argc == 2) && !strcmp(argv[1], "-l")) {
+		print_possible_fields(inode_fields);
+		return;
+	}
+
+	if (common_args_process(argc, argv, 4, 4, "set_inode",
+				usage, CHECK_FS_RW))
+		return;
+
+	if ((ss = find_field(inode_fields, argv[2])) == 0) {
+		com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
+		return;
+	}
+
+	set_ino = string_to_inode(argv[1]);
+	if (!set_ino)
+		return;
+
+	if (debugfs_read_inode_full(set_ino,
+			(struct ext2_inode *) &set_inode, argv[1],
+				    sizeof(set_inode)))
+		return;
+
+	if (ss->func(ss, argv[2], argv[3]) == 0) {
+		if (debugfs_write_inode_full(set_ino, 
+			     (struct ext2_inode *) &set_inode,
+			     argv[1], sizeof(set_inode)))
+			return;
+	}
+}
+
+void do_set_block_group_descriptor(int argc, char *argv[])
+{
+	const char *usage = "<bg number> <field> <value>\n"
+		"\t\"set_block_group_descriptor -l\" will list the names of "
+		"the fields in a block group descriptor\n\twhich can be set.";
+	struct field_set_info	*table;
+	struct field_set_info	*ss;
+	char			*end;
+	void			*edit, *target;
+	int			size;
+
+	/*
+	 * Determine whether we are editing an ext2 or ext4 block group
+	 * descriptor.  Descriptors larger than ext4_group_desc cannot
+	 * have their fields edited yet, because they do not have any
+	 * names assigned.  When that happens, this function needs to
+	 * be updated for the new descriptor struct and fields.
+	 */
+	if (current_fs &&
+	    EXT2_DESC_SIZE(current_fs->super) >= EXT2_MIN_DESC_SIZE_64BIT) {
+		table = ext4_bg_fields;
+		edit = &set_gd4;
+		size = sizeof(set_gd4);
+	} else {
+		table = ext2_bg_fields;
+		edit = &set_gd;
+		size = sizeof(set_gd);
+	}
+
+	if ((argc == 2) && !strcmp(argv[1], "-l")) {
+		print_possible_fields(table);
+		return;
+	}
+
+	if (common_args_process(argc, argv, 4, 4, "set_block_group_descriptor",
+				usage, CHECK_FS_RW))
+		return;
+
+	set_bg = strtoul(argv[1], &end, 0);
+	if (*end) {
+		com_err(argv[0], 0, "invalid block group number: %s", argv[1]);
+		return;
+	}
+
+	if (set_bg >= current_fs->group_desc_count) {
+		com_err(argv[0], 0, "block group number too big: %d", set_bg);
+		return;
+	}
+
+	if ((ss = find_field(table, argv[2])) == 0) {
+		com_err(argv[0], 0, "invalid field specifier: %s", argv[2]);
+		return;
+	}
+
+	target = ext2fs_group_desc(current_fs, current_fs->group_desc, set_bg);
+	memcpy(edit, target, size);
+	if (ss->func(ss, argv[2], argv[3]) == 0) {
+		memcpy(target, edit, size);
+		ext2fs_mark_super_dirty(current_fs);
+	}
+}
+
+static errcode_t parse_mmp_clear(struct field_set_info *info,
+				 char *field EXT2FS_ATTR((unused)),
+				 char *arg EXT2FS_ATTR((unused)))
+{
+	errcode_t retval;
+
+	retval = ext2fs_mmp_clear(current_fs);
+	if (retval != 0)
+		com_err("set_mmp_value", retval, "while clearing MMP block\n");
+	else
+		memcpy(info->ptr, current_fs->mmp_buf, info->size);
+
+	return 1; /* we don't need the MMP block written again */
+}
+
+void do_set_mmp_value(int argc, char *argv[])
+{
+	const char *usage = "<field> <value>\n"
+		"\t\"set_mmp_value -l\" will list the names of "
+		"MMP fields\n\twhich can be set.";
+	static struct field_set_info *smmp;
+	struct mmp_struct *mmp_s;
+	errcode_t retval;
+
+	if (argc == 2 && strcmp(argv[1], "-l") == 0) {
+		print_possible_fields(mmp_fields);
+		return;
+	}
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	if (current_fs->super->s_mmp_block == 0) {
+		com_err(argv[0], 0, "no MMP block allocated\n");
+		return;
+	}
+
+	if (common_args_process(argc, argv, 2, 3, "set_mmp_value",
+				usage, CHECK_FS_RW))
+		return;
+
+	mmp_s = current_fs->mmp_buf;
+	if (mmp_s == NULL) {
+		retval = ext2fs_get_mem(current_fs->blocksize, &mmp_s);
+		if (retval) {
+			com_err(argv[0], retval, "allocating MMP buffer\n");
+			return;
+		}
+		retval = ext2fs_mmp_read(current_fs,
+					 current_fs->super->s_mmp_block, mmp_s);
+		if (retval) {
+			com_err(argv[0], retval, "reading MMP block %llu.\n",
+				(long long)current_fs->super->s_mmp_block);
+			ext2fs_free_mem(&mmp_s);
+			return;
+		}
+		current_fs->mmp_buf = mmp_s;
+	}
+
+	smmp = find_field(mmp_fields, argv[1]);
+	if (smmp == 0) {
+		com_err(argv[0], 0, "invalid field specifier: %s", argv[1]);
+		return;
+	}
+
+	set_mmp = *mmp_s;
+	if (smmp->func(smmp, argv[1], argv[2]) == 0) {
+		ext2fs_mmp_write(current_fs, current_fs->super->s_mmp_block,
+				 &set_mmp);
+		*mmp_s = set_mmp;
+	}
+}
+
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/unused.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/unused.c
new file mode 100644
index 0000000..4cb1191
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/unused.c
@@ -0,0 +1,58 @@
+/*
+ * unused.c --- quick and dirty unused space dumper
+ *
+ * Copyright (C) 1997 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv)
+{
+	blk64_t		blk;
+	unsigned char	buf[EXT2_MAX_BLOCK_SIZE];
+	unsigned int	i;
+	errcode_t	retval;
+
+	if (common_args_process(argc, argv, 1, 1,
+				"dump_unused", "", 0))
+		return;
+
+	for (blk=current_fs->super->s_first_data_block;
+	     blk < ext2fs_blocks_count(current_fs->super); blk++) {
+		if (ext2fs_test_block_bitmap2(current_fs->block_map,blk))
+			continue;
+		retval = io_channel_read_blk64(current_fs->io, blk, 1, buf);
+		if (retval) {
+			com_err(argv[0], retval, "While reading block\n");
+			return;
+		}
+		for (i=0; i < current_fs->blocksize; i++)
+			if (buf[i])
+				break;
+		if (i >= current_fs->blocksize)
+			continue;
+		printf("\nUnused block %llu contains non-zero data:\n\n",
+		       blk);
+		for (i=0; i < current_fs->blocksize; i++)
+			fputc(buf[i], stdout);
+	}
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/util.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/util.c
new file mode 100644
index 0000000..aafbc56
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/util.c
@@ -0,0 +1,482 @@
+/*
+ * util.c --- utilities for the debugfs program
+ *
+ * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be
+ * redistributed under the terms of the GNU Public License.
+ *
+ */
+
+#define _XOPEN_SOURCE 600 /* needed for strptime */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#include <signal.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+#ifdef HAVE_OPTRESET
+extern int optreset;		/* defined by BSD, but not others */
+#endif
+
+#include "ss/ss.h"
+#include "debugfs.h"
+
+/*
+ * This function resets the libc getopt() function, which keeps
+ * internal state.  Bad design!  Stupid libc API designers!  No
+ * biscuit!
+ *
+ * BSD-derived getopt() functions require that optind be reset to 1 in
+ * order to reset getopt() state.  This used to be generally accepted
+ * way of resetting getopt().  However, glibc's getopt()
+ * has additional getopt() state beyond optind, and requires that
+ * optind be set zero to reset its state.  So the unfortunate state of
+ * affairs is that BSD-derived versions of getopt() misbehave if
+ * optind is set to 0 in order to reset getopt(), and glibc's getopt()
+ * will core dump if optind is set 1 in order to reset getopt().
+ *
+ * More modern versions of BSD require that optreset be set to 1 in
+ * order to reset getopt().   Sigh.  Standards, anyone?
+ *
+ * We hide the hair here.
+ */
+void reset_getopt(void)
+{
+#if defined(__GLIBC__) || defined(__linux__)
+	optind = 0;
+#else
+	optind = 1;
+#endif
+#ifdef HAVE_OPTRESET
+	optreset = 1;		/* Makes BSD getopt happy */
+#endif
+}
+
+static const char *pager_search_list[] = { "pager", "more", "less", 0 };
+static const char *pager_dir_list[] = { "/usr/bin", "/bin", 0 };
+
+static const char *find_pager(char *buf)
+{
+	const char **i, **j;
+
+	for (i = pager_search_list; *i; i++) {
+		for (j = pager_dir_list; *j; j++) {
+			sprintf(buf, "%s/%s", *j, *i);
+			if (access(buf, X_OK) == 0)
+				return(buf);
+		}
+	}
+	return 0;
+}
+
+FILE *open_pager(void)
+{
+	FILE *outfile = 0;
+	const char *pager = ss_safe_getenv("DEBUGFS_PAGER");
+	char buf[80];
+
+	signal(SIGPIPE, SIG_IGN);
+	if (!isatty(1))
+		return stdout;
+	if (!pager)
+		pager = ss_safe_getenv("PAGER");
+	if (!pager)
+		pager = find_pager(buf);
+	if (!pager ||
+	    (strcmp(pager, "__none__") == 0) ||
+	    ((outfile = popen(pager, "w")) == 0))
+		return stdout;
+	return outfile;
+}
+
+void close_pager(FILE *stream)
+{
+	if (stream && stream != stdout) pclose(stream);
+}
+
+/*
+ * This routine is used whenever a command needs to turn a string into
+ * an inode.
+ */
+ext2_ino_t string_to_inode(char *str)
+{
+	ext2_ino_t	ino;
+	int		len = strlen(str);
+	char		*end;
+	int		retval;
+
+	/*
+	 * If the string is of the form <ino>, then treat it as an
+	 * inode number.
+	 */
+	if ((len > 2) && (str[0] == '<') && (str[len-1] == '>')) {
+		ino = strtoul(str+1, &end, 0);
+		if (*end=='>')
+			return ino;
+	}
+
+	retval = ext2fs_namei(current_fs, root, cwd, str, &ino);
+	if (retval) {
+		com_err(str, retval, 0);
+		return 0;
+	}
+	return ino;
+}
+
+/*
+ * This routine returns 1 if the filesystem is not open, and prints an
+ * error message to that effect.
+ */
+int check_fs_open(char *name)
+{
+	if (!current_fs) {
+		com_err(name, 0, "Filesystem not open");
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * This routine returns 1 if a filesystem is open, and prints an
+ * error message to that effect.
+ */
+int check_fs_not_open(char *name)
+{
+	if (current_fs) {
+		com_err(name, 0,
+			"Filesystem %s is still open.  Close it first.\n",
+			current_fs->device_name);
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * This routine returns 1 if a filesystem is not opened read/write,
+ * and prints an error message to that effect.
+ */
+int check_fs_read_write(char *name)
+{
+	if (!(current_fs->flags & EXT2_FLAG_RW)) {
+		com_err(name, 0, "Filesystem opened read/only");
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * This routine returns 1 if a filesystem is doesn't have its inode
+ * and block bitmaps loaded, and prints an error message to that
+ * effect.
+ */
+int check_fs_bitmaps(char *name)
+{
+	if (!current_fs->block_map || !current_fs->inode_map) {
+		com_err(name, 0, "Filesystem bitmaps not loaded");
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * This function takes a __u32 time value and converts it to a string,
+ * using ctime
+ */
+char *time_to_string(__u32 cl)
+{
+	static int	do_gmt = -1;
+	time_t		t = (time_t) cl;
+	const char	*tz;
+
+	if (do_gmt == -1) {
+		/* The diet libc doesn't respect the TZ environemnt variable */
+		tz = ss_safe_getenv("TZ");
+		if (!tz)
+			tz = "";
+		do_gmt = !strcmp(tz, "GMT");
+	}
+
+	return asctime((do_gmt) ? gmtime(&t) : localtime(&t));
+}
+
+/*
+ * Parse a string as a time.  Return ((time_t)-1) if the string
+ * doesn't appear to be a sane time.
+ */
+time_t string_to_time(const char *arg)
+{
+	struct	tm	ts;
+	time_t		ret;
+	char *tmp;
+
+	if (strcmp(arg, "now") == 0) {
+		return time(0);
+	}
+	if (arg[0] == '@') {
+		/* interpret it as an integer */
+		ret = strtoul(arg+1, &tmp, 0);
+		if (*tmp)
+			return ((time_t) -1);
+		return ret;
+	}
+	memset(&ts, 0, sizeof(ts));
+#ifdef HAVE_STRPTIME
+	strptime(arg, "%Y%m%d%H%M%S", &ts);
+#else
+	sscanf(arg, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
+	       &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
+	ts.tm_year -= 1900;
+	ts.tm_mon -= 1;
+	if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
+	    ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
+	    ts.tm_min > 59 || ts.tm_sec > 61)
+		ts.tm_mday = 0;
+#endif
+	ts.tm_isdst = -1;
+	ret = mktime(&ts);
+	if (ts.tm_mday == 0 || ret == ((time_t) -1)) {
+		/* Try it as an integer... */
+		ret = strtoul(arg, &tmp, 0);
+		if (*tmp)
+			return ((time_t) -1);
+	}
+	return ret;
+}
+
+/*
+ * This function will convert a string to an unsigned long, printing
+ * an error message if it fails, and returning success or failure in err.
+ */
+unsigned long parse_ulong(const char *str, const char *cmd,
+			  const char *descr, int *err)
+{
+	char		*tmp;
+	unsigned long	ret;
+
+	ret = strtoul(str, &tmp, 0);
+	if (*tmp == 0) {
+		if (err)
+			*err = 0;
+		return ret;
+	}
+	com_err(cmd, 0, "Bad %s - %s", descr, str);
+	if (err)
+		*err = 1;
+	else
+		exit(1);
+	return 0;
+}
+
+/*
+ * This function will convert a string to an unsigned long long, printing
+ * an error message if it fails, and returning success or failure in err.
+ */
+unsigned long long parse_ulonglong(const char *str, const char *cmd,
+				   const char *descr, int *err)
+{
+	char			*tmp;
+	unsigned long long	ret;
+
+	ret = strtoull(str, &tmp, 0);
+	if (*tmp == 0) {
+		if (err)
+			*err = 0;
+		return ret;
+	}
+	com_err(cmd, 0, "Bad %s - %s", descr, str);
+	if (err)
+		*err = 1;
+	else
+		exit(1);
+	return 0;
+}
+
+/*
+ * This function will convert a string to a block number.  It returns
+ * 0 on success, 1 on failure.
+ */
+int strtoblk(const char *cmd, const char *str, blk64_t *ret)
+{
+	blk64_t	blk;
+	int	err;
+
+	blk = parse_ulonglong(str, cmd, "block number", &err);
+	*ret = blk;
+	if (err)
+		com_err(cmd, 0, "Invalid block number: %s", str);
+	return err;
+}
+
+/*
+ * This is a common helper function used by the command processing
+ * routines
+ */
+int common_args_process(int argc, char *argv[], int min_argc, int max_argc,
+			const char *cmd, const char *usage, int flags)
+{
+	if (argc < min_argc || argc > max_argc) {
+		com_err(argv[0], 0, "Usage: %s %s", cmd, usage);
+		return 1;
+	}
+	if (flags & CHECK_FS_NOTOPEN) {
+		if (check_fs_not_open(argv[0]))
+			return 1;
+	} else {
+		if (check_fs_open(argv[0]))
+			return 1;
+	}
+	if ((flags & CHECK_FS_RW) && check_fs_read_write(argv[0]))
+		return 1;
+	if ((flags & CHECK_FS_BITMAPS) && check_fs_bitmaps(argv[0]))
+		return 1;
+	return 0;
+}
+
+/*
+ * This is a helper function used by do_stat, do_freei, do_seti, and
+ * do_testi, etc.  Basically, any command which takes a single
+ * argument which is a file/inode number specifier.
+ */
+int common_inode_args_process(int argc, char *argv[],
+			      ext2_ino_t *inode, int flags)
+{
+	if (common_args_process(argc, argv, 2, 2, argv[0], "<file>", flags))
+		return 1;
+
+	*inode = string_to_inode(argv[1]);
+	if (!*inode)
+		return 1;
+	return 0;
+}
+
+/*
+ * This is a helper function used by do_freeb, do_setb, and do_testb
+ */
+int common_block_args_process(int argc, char *argv[],
+			      blk64_t *block, blk64_t *count)
+{
+	int	err;
+
+	if (common_args_process(argc, argv, 2, 3, argv[0],
+				"<block> [count]", CHECK_FS_BITMAPS))
+		return 1;
+
+	if (strtoblk(argv[0], argv[1], block))
+		return 1;
+	if (*block == 0) {
+		com_err(argv[0], 0, "Invalid block number 0");
+		err = 1;
+	}
+
+	if (argc > 2) {
+		err = strtoblk(argv[0], argv[2], count);
+		if (err)
+			return 1;
+	}
+	return 0;
+}
+
+int debugfs_read_inode_full(ext2_ino_t ino, struct ext2_inode * inode,
+			const char *cmd, int bufsize)
+{
+	int retval;
+
+	retval = ext2fs_read_inode_full(current_fs, ino, inode, bufsize);
+	if (retval) {
+		com_err(cmd, retval, "while reading inode %u", ino);
+		return 1;
+	}
+	return 0;
+}
+
+int debugfs_read_inode(ext2_ino_t ino, struct ext2_inode * inode,
+			const char *cmd)
+{
+	int retval;
+
+	retval = ext2fs_read_inode(current_fs, ino, inode);
+	if (retval) {
+		com_err(cmd, retval, "while reading inode %u", ino);
+		return 1;
+	}
+	return 0;
+}
+
+int debugfs_write_inode_full(ext2_ino_t ino,
+			     struct ext2_inode *inode,
+			     const char *cmd,
+			     int bufsize)
+{
+	int retval;
+
+	retval = ext2fs_write_inode_full(current_fs, ino,
+					 inode, bufsize);
+	if (retval) {
+		com_err(cmd, retval, "while writing inode %u", ino);
+		return 1;
+	}
+	return 0;
+}
+
+int debugfs_write_inode(ext2_ino_t ino, struct ext2_inode * inode,
+			const char *cmd)
+{
+	int retval;
+
+	retval = ext2fs_write_inode(current_fs, ino, inode);
+	if (retval) {
+		com_err(cmd, retval, "while writing inode %u", ino);
+		return 1;
+	}
+	return 0;
+}
+
+int debugfs_write_new_inode(ext2_ino_t ino, struct ext2_inode * inode,
+			    const char *cmd)
+{
+	int retval;
+
+	retval = ext2fs_write_new_inode(current_fs, ino, inode);
+	if (retval) {
+		com_err(cmd, retval, "while creating inode %u", ino);
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * Given a mode, return the ext2 file type
+ */
+int ext2_file_type(unsigned int mode)
+{
+	if (LINUX_S_ISREG(mode))
+		return EXT2_FT_REG_FILE;
+
+	if (LINUX_S_ISDIR(mode))
+		return EXT2_FT_DIR;
+
+	if (LINUX_S_ISCHR(mode))
+		return EXT2_FT_CHRDEV;
+
+	if (LINUX_S_ISBLK(mode))
+		return EXT2_FT_BLKDEV;
+
+	if (LINUX_S_ISLNK(mode))
+		return EXT2_FT_SYMLINK;
+
+	if (LINUX_S_ISFIFO(mode))
+		return EXT2_FT_FIFO;
+
+	if (LINUX_S_ISSOCK(mode))
+		return EXT2_FT_SOCK;
+
+	return 0;
+}
diff --git a/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/zap.c b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/zap.c
new file mode 100644
index 0000000..8109209
--- /dev/null
+++ b/ap/app/e2fsprogs/e2fsprogs-1.42.9/debugfs/zap.c
@@ -0,0 +1,260 @@
+/*
+ * zap.c --- zap block
+ *
+ * Copyright (C) 2012 Theodore Ts'o.  This file may be redistributed
+ * under the terms of the GNU Public License.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <sys/types.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int optind;
+extern char *optarg;
+#endif
+
+#include "debugfs.h"
+
+void do_zap_block(int argc, char *argv[])
+{
+	unsigned long	pattern = 0;
+	unsigned char	*buf;
+	ext2_ino_t	inode;
+	errcode_t	errcode;
+	blk64_t		block;
+	char		*file = NULL;
+	int		c, err;
+	int		offset = -1;
+	int		length = -1;
+	int		bit = -1;
+
+	if (check_fs_open(argv[0]))
+		return;
+	if (check_fs_read_write(argv[0]))
+		return;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "b:f:l:o:p:")) != EOF) {
+		switch (c) {
+		case 'f':
+			file = optarg;
+			break;
+		case 'b':
+			bit = parse_ulong(optarg, argv[0],
+					  "bit", &err);
+			if (err)
+				return;
+			if (bit >= (int) current_fs->blocksize * 8) {
+				com_err(argv[0], 0, "The bit to flip "
+					"must be within a %d block\n",
+					current_fs->blocksize);
+				return;
+			}
+			break;
+		case 'p':
+			pattern = parse_ulong(optarg, argv[0],
+					      "pattern", &err);
+			if (err)
+				return;
+			if (pattern >= 256) {
+				com_err(argv[0], 0, "The fill pattern must "
+					"be an 8-bit value\n");
+				return;
+			}
+			break;
+		case 'o':
+			offset = parse_ulong(optarg, argv[0],
+					     "offset", &err);
+			if (err)
+				return;
+			if (offset >= (int) current_fs->blocksize) {
+				com_err(argv[0], 0, "The offset must be "
+					"within a %d block\n",
+					current_fs->blocksize);
+				return;
+			}
+			break;
+
+			break;
+		case 'l':
+			length = parse_ulong(optarg, argv[0],
+					     "length", &err);
+			if (err)
+				return;
+			break;
+		default:
+			goto print_usage;
+		}
+	}
+
+	if (bit > 0 && offset > 0) {
+		com_err(argv[0], 0, "The -o and -b options can not be mixed.");
+		return;
+	}
+
+	if (offset < 0)
+		offset = 0;
+	if (length < 0)
+		length = current_fs->blocksize - offset;
+	if ((offset + length) > (int) current_fs->blocksize) {
+		com_err(argv[0], 0, "The specified length is too bug\n");
+		return;
+	}
+
+	if (argc != optind+1) {
+	print_usage:
+		com_err(0, 0, "Usage:\tzap_block [-f file] [-o offset] "
+			"[-l length] [-p pattern] block_num");
+		com_err(0, 0, "\tzap_block [-f file] [-b bit] "
+			"block_num");
+		return;
+	}
+
+	block = parse_ulonglong(argv[optind], argv[0], "block", &err);
+	if (err)
+		return;
+
+	if (file) {
+		inode = string_to_inode(file);
+		if (!inode)
+			return;
+		errcode = ext2fs_bmap2(current_fs, inode, 0, 0, 0,
+				       block, 0, &block);
+		if (errcode) {
+			com_err(argv[0], errcode,
+				"while mapping logical block %llu\n", block);
+			return;
+		}
+	}
+
+	buf = malloc(current_fs->blocksize);
+	if (!buf) {
+		com_err(argv[0], 0, "Couldn't allocate block buffer");
+		return;
+	}
+
+	errcode = io_channel_read_blk64(current_fs->io, block, 1, buf);
+	if (errcode) {
+		com_err(argv[0], errcode,
+			"while reading block %llu\n", block);
+		goto errout;
+	}
+
+	if (bit >= 0)
+		buf[bit >> 3] ^= 1 << (bit & 7);
+	else
+		memset(buf+offset, pattern, length);
+
+	errcode = io_channel_write_blk64(current_fs->io, block, 1, buf);
+	if (errcode) {
+		com_err(argv[0], errcode,
+			"while write block %llu\n", block);
+		goto errout;
+	}
+
+errout:
+	free(buf);
+	return;
+}
+
+void do_block_dump(int argc, char *argv[])
+{
+	unsigned char	*buf;
+	ext2_ino_t	inode;
+	errcode_t	errcode;
+	blk64_t		block;
+	char		*file = NULL;
+	unsigned int	i, j;
+	int		c, err;
+	int		suppress = -1;
+
+	if (check_fs_open(argv[0]))
+		return;
+
+	reset_getopt();
+	while ((c = getopt (argc, argv, "f:")) != EOF) {
+		switch (c) {
+		case 'f':
+			file = optarg;
+			break;
+
+		default:
+			goto print_usage;
+		}
+	}
+
+	if (argc != optind + 1) {
+	print_usage:
+		com_err(0, 0, "Usage: block_dump [-f inode] block_num");
+		return;
+	}
+
+	block = parse_ulonglong(argv[optind], argv[0], "block", &err);
+	if (err)
+		return;
+
+	if (file) {
+		inode = string_to_inode(file);
+		if (!inode)
+			return;
+		errcode = ext2fs_bmap2(current_fs, inode, 0, 0, 0,
+				       block, 0, &block);
+		if (errcode) {
+			com_err(argv[0], errcode,
+				"while mapping logical block %llu\n", block);
+			return;
+		}
+	}
+
+	buf = malloc(current_fs->blocksize);
+	if (!buf) {
+		com_err(argv[0], 0, "Couldn't allocate block buffer");
+		return;
+	}
+
+	errcode = io_channel_read_blk64(current_fs->io, block, 1, buf);
+	if (errcode) {
+		com_err(argv[0], errcode,
+			"while reading block %llu\n", block);
+		goto errout;
+	}
+
+	for (i=0; i < current_fs->blocksize; i += 16) {
+		if (suppress < 0) {
+			if (i && memcmp(buf + i, buf + i - 16, 16) == 0) {
+				suppress = i;
+				printf("*\n");
+				continue;
+			}
+		} else {
+			if (memcmp(buf + i, buf + suppress, 16) == 0)
+				continue;
+			suppress = -1;
+		}
+		printf("%04o  ", i);
+		for (j = 0; j < 16; j++) {
+			printf("%02x", buf[i+j]);
+			if ((j % 2) == 1)
+				putchar(' ');
+		}
+		putchar(' ');
+		for (j = 0; j < 16; j++)
+			printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+		putchar('\n');
+	}
+	putchar('\n');
+
+errout:
+	free(buf);
+	return;
+}