Theodore Ts'o | a5fdcd5 | 2003-05-21 17:58:36 -0400 | [diff] [blame] | 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 | |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 27 | void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv) |
Theodore Ts'o | a5fdcd5 | 2003-05-21 17:58:36 -0400 | [diff] [blame] | 28 | { |
| 29 | unsigned long blk; |
| 30 | unsigned char buf[32768]; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 31 | unsigned int i; |
Theodore Ts'o | a5fdcd5 | 2003-05-21 17:58:36 -0400 | [diff] [blame] | 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 %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 | } |