Whamcloud - gitweb
Fix format statements to make e2fsprogs programs 32-bit clean
[tools/e2fsprogs.git] / debugfs / unused.c
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 <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 
21 extern int optind;
22 extern char *optarg;
23 #endif
24
25 #include "debugfs.h"
26
27 void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv)
28 {
29         unsigned long   blk;
30         unsigned char buf[32768];
31         unsigned int    i;
32         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 %lu contains non-zero data:\n\n",
49                        blk);
50                 for (i=0; i < current_fs->blocksize; i++)
51                         fputc(buf[i], stdout);
52         }
53 }