blob: d0a51621a80e6e527a423aedb55c63f474a3cbd5 [file] [log] [blame]
Theodore Ts'oa5fdcd52003-05-21 17:58:36 -04001/*
2 * unused.c --- quick and dirty unused space dumper
3 *
4 * Copyright (C) 1997 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
6 */
7
8#include <stdio.h>
9#include <unistd.h>
10#include <stdlib.h>
11#include <ctype.h>
12#include <string.h>
13#include <time.h>
14#ifdef HAVE_ERRNO_H
15#include <errno.h>
16#endif
17#include <sys/types.h>
18#ifdef HAVE_GETOPT_H
19#include <getopt.h>
20#else
21extern int optind;
22extern char *optarg;
23#endif
24
25#include "debugfs.h"
26
Theodore Ts'o54434922003-12-07 01:28:50 -050027void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv)
Theodore Ts'oa5fdcd52003-05-21 17:58:36 -040028{
29 unsigned long blk;
30 unsigned char buf[32768];
Theodore Ts'o54434922003-12-07 01:28:50 -050031 unsigned int i;
Theodore Ts'oa5fdcd52003-05-21 17:58:36 -040032 errcode_t retval;
33
34 for (blk=current_fs->super->s_first_data_block;
35 blk < current_fs->super->s_blocks_count; blk++) {
36 if (ext2fs_test_block_bitmap(current_fs->block_map,blk))
37 continue;
38 retval = io_channel_read_blk(current_fs->io, blk, 1, buf);
39 if (retval) {
40 com_err(argv[0], retval, "While reading block\n");
41 return;
42 }
43 for (i=0; i < current_fs->blocksize; i++)
44 if (buf[i])
45 break;
46 if (i >= current_fs->blocksize)
47 continue;
48 printf("\nUnused block %ld contains non-zero data:\n\n",
49 blk);
50 for (i=0; i < current_fs->blocksize; i++)
51 fputc(buf[i], stdout);
52 }
53}