From a5fdcd5946971a2bbbecf26269c667aa6bf73966 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 21 May 2003 17:58:36 -0400 Subject: unused.c (do_dump_unused): Add new command which dumps the unused blocks. (Initial implementation; currently only dumps the output to stdout.) --- debugfs/unused.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 debugfs/unused.c (limited to 'debugfs/unused.c') 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 +#include +#include +#include +#include +#include +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_GETOPT_H +#include +#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); + } +} -- cgit v1.2.3