aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2003-05-21 17:58:36 -0400
committerTheodore Ts'o <tytso@mit.edu>2003-05-21 17:58:36 -0400
commita5fdcd5946971a2bbbecf26269c667aa6bf73966 (patch)
treef7f22646e2b99ca2196464b6ed44ef78f171aa32
parentd339f2684d54a4d7c3dbc527c9b8700543f9e27a (diff)
downloade2fsprogs-a5fdcd5946971a2bbbecf26269c667aa6bf73966.tar.gz
unused.c (do_dump_unused): Add new command which dumps the
unused blocks. (Initial implementation; currently only dumps the output to stdout.)
-rw-r--r--debugfs/ChangeLog6
-rw-r--r--debugfs/Makefile.in4
-rw-r--r--debugfs/debug_cmds.ct3
-rw-r--r--debugfs/unused.c53
4 files changed, 64 insertions, 2 deletions
diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog
index 7e153530..33eb3953 100644
--- a/debugfs/ChangeLog
+++ b/debugfs/ChangeLog
@@ -1,3 +1,9 @@
+2003-05-21 Theodore Ts'o <tytso@mit.edu>
+
+ * unused.c (do_dump_unused): Add new command which dumps the
+ unused blocks. (Initial implementation; currently only
+ dumps the output to stdout.)
+
2003-05-13 root <tytso@mit.edu>
* util.c (reset_getopt), debugfs.c (do_open_filesys,
diff --git a/debugfs/Makefile.in b/debugfs/Makefile.in
index 3fc7fb0d..cfc24e99 100644
--- a/debugfs/Makefile.in
+++ b/debugfs/Makefile.in
@@ -18,12 +18,12 @@ 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 setsuper.o logdump.o htree.o
+ lsdel.o dump.o setsuper.o logdump.o htree.o unused.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)/setsuper.c ${srcdir}/logdump.c \
- $(srcdir)/htree.c
+ $(srcdir)/htree.c $(srcdir)/unused.c
LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBSS) $(LIBCOM_ERR) $(LIBBLKID) \
$(LIBUUID) $(DLOPEN_LIB)
diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct
index 21cab096..cea56852 100644
--- a/debugfs/debug_cmds.ct
+++ b/debugfs/debug_cmds.ct
@@ -142,5 +142,8 @@ request do_bmap, "Calculate the logical->physical block mapping for an inode",
request do_imap, "Calculate the location of an inode",
imap;
+request do_dump_unused, "Dump unused blocks",
+ dump_unused;
+
end;
diff --git a/debugfs/unused.c b/debugfs/unused.c
new file mode 100644
index 00000000..c055db7d
--- /dev/null
+++ b/debugfs/unused.c
@@ -0,0 +1,53 @@
+/*
+ * 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 <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, char **argv)
+{
+ unsigned long blk;
+ unsigned char buf[32768];
+ int i;
+ errcode_t retval;
+
+ for (blk=current_fs->super->s_first_data_block;
+ blk < current_fs->super->s_blocks_count; blk++) {
+ if (ext2fs_test_block_bitmap(current_fs->block_map,blk))
+ continue;
+ retval = io_channel_read_blk(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 %ld contains non-zero data:\n\n",
+ blk);
+ for (i=0; i < current_fs->blocksize; i++)
+ fputc(buf[i], stdout);
+ }
+}