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 21extern int optind; 22extern char *optarg; 23#endif 24 25#include "debugfs.h" 26 27void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv) 28{ 29 blk64_t blk; 30 unsigned char buf[EXT2_MAX_BLOCK_SIZE]; 31 unsigned int i; 32 errcode_t retval; 33 34 if (common_args_process(argc, argv, 1, 1, 35 "dump_unused", "", 0)) 36 return; 37 38 for (blk=current_fs->super->s_first_data_block; 39 blk < ext2fs_blocks_count(current_fs->super); blk++) { 40 if (ext2fs_test_block_bitmap2(current_fs->block_map,blk)) 41 continue; 42 retval = io_channel_read_blk64(current_fs->io, blk, 1, buf); 43 if (retval) { 44 com_err(argv[0], retval, "While reading block\n"); 45 return; 46 } 47 for (i=0; i < current_fs->blocksize; i++) 48 if (buf[i]) 49 break; 50 if (i >= current_fs->blocksize) 51 continue; 52 printf("\nUnused block %llu contains non-zero data:\n\n", 53 blk); 54 for (i=0; i < current_fs->blocksize; i++) 55 fputc(buf[i], stdout); 56 } 57} 58