• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "config.h"
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <ctype.h>
13 #include <string.h>
14 #include <time.h>
15 #ifdef HAVE_ERRNO_H
16 #include <errno.h>
17 #endif
18 #include <sys/types.h>
19 #ifdef HAVE_GETOPT_H
20 #include <getopt.h>
21 #else
22 extern int optind;
23 extern char *optarg;
24 #endif
25 
26 #include "debugfs.h"
27 
do_dump_unused(int argc EXT2FS_ATTR ((unused)),char ** argv,int sci_idx EXT2FS_ATTR ((unused)),void * infop EXT2FS_ATTR ((unused)))28 void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv,
29 		    int sci_idx EXT2FS_ATTR((unused)),
30 		    void *infop EXT2FS_ATTR((unused)))
31 {
32 	blk64_t		blk;
33 	unsigned char	buf[EXT2_MAX_BLOCK_SIZE];
34 	unsigned int	i;
35 	errcode_t	retval;
36 
37 	if (common_args_process(argc, argv, 1, 1,
38 				"dump_unused", "", 0))
39 		return;
40 
41 	for (blk=current_fs->super->s_first_data_block;
42 	     blk < ext2fs_blocks_count(current_fs->super); blk++) {
43 		if (ext2fs_test_block_bitmap2(current_fs->block_map,blk))
44 			continue;
45 		retval = io_channel_read_blk64(current_fs->io, blk, 1, buf);
46 		if (retval) {
47 			com_err(argv[0], retval, "While reading block\n");
48 			return;
49 		}
50 		for (i=0; i < current_fs->blocksize; i++)
51 			if (buf[i])
52 				break;
53 		if (i >= current_fs->blocksize)
54 			continue;
55 		printf("\nUnused block %llu contains non-zero data:\n\n",
56 		       blk);
57 		for (i=0; i < current_fs->blocksize; i++)
58 			fputc(buf[i], stdout);
59 	}
60 }
61