]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - debugfs/unused.c
ext2fs: convert unicode normalization from NFKD -> NFD
[thirdparty/e2fsprogs.git] / debugfs / unused.c
CommitLineData
a5fdcd59
TT
1/*
2 * unused.c --- quick and dirty unused space dumper
efc6f628 3 *
a5fdcd59
TT
4 * Copyright (C) 1997 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
6 */
7
d1154eb4 8#include "config.h"
a5fdcd59
TT
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>
efc6f628 21#else
a5fdcd59
TT
22extern int optind;
23extern char *optarg;
24#endif
25
26#include "debugfs.h"
27
2fcbcb1b
TT
28void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv,
29 int sci_idx EXT2FS_ATTR((unused)),
30 void *infop EXT2FS_ATTR((unused)))
a5fdcd59 31{
048786d7
VAH
32 blk64_t blk;
33 unsigned char buf[EXT2_MAX_BLOCK_SIZE];
54434927 34 unsigned int i;
a5fdcd59
TT
35 errcode_t retval;
36
97fa31b9
MK
37 if (common_args_process(argc, argv, 1, 1,
38 "dump_unused", "", 0))
39 return;
40
a5fdcd59 41 for (blk=current_fs->super->s_first_data_block;
4efbac6f 42 blk < ext2fs_blocks_count(current_fs->super); blk++) {
6d879a99 43 if (ext2fs_test_block_bitmap2(current_fs->block_map,blk))
a5fdcd59 44 continue;
24a117ab 45 retval = io_channel_read_blk64(current_fs->io, blk, 1, buf);
a5fdcd59
TT
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;
048786d7 55 printf("\nUnused block %llu contains non-zero data:\n\n",
a5fdcd59
TT
56 blk);
57 for (i=0; i < current_fs->blocksize; i++)
58 fputc(buf[i], stdout);
59 }
60}