2 * icheck.c --- given a list of blocks, generate a list of inodes
4 * Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
17 #include <sys/types.h>
26 struct block_walk_struct {
27 struct block_info *barray;
33 static int icheck_proc(ext2_filsys fs,
38 struct block_walk_struct *bw = (struct block_walk_struct *) private;
41 for (i=0; i < bw->num_blocks; i++) {
42 if (bw->barray[i].blk == *block_nr) {
43 bw->barray[i].ino = bw->inode;
53 void do_icheck(int argc, char **argv)
55 struct block_walk_struct bw;
56 struct block_info *binfo;
58 ext2_inode_scan scan = 0;
60 struct ext2_inode inode;
66 com_err(argv[0], 0, "Usage: icheck <block number> ...");
69 if (check_fs_open(argv[0]))
72 bw.barray = malloc(sizeof(struct block_info) * argc);
74 com_err("icheck", ENOMEM,
75 "while allocating inode info array");
78 memset(bw.barray, 0, sizeof(struct block_info) * argc);
80 block_buf = malloc(fs->blocksize * 3);
82 com_err("icheck", ENOMEM, "while allocating block buffer");
86 for (i=1; i < argc; i++) {
87 bw.barray[i-1].blk = strtol(argv[i], &tmp, 0);
89 com_err(argv[0], 0, "Bad block - %s", argv[i]);
94 bw.num_blocks = bw.blocks_left = argc-1;
96 retval = ext2fs_open_inode_scan(fs, 0, &scan);
98 com_err("icheck", retval, "while opening inode scan");
102 retval = ext2fs_get_next_inode(scan, &ino, &inode);
104 com_err("icheck", retval, "while starting inode scan");
109 if (!inode.i_links_count)
112 * To handle filesystems touched by 0.3c extfs; can be
120 retval = ext2fs_block_iterate(fs, ino, 0, block_buf,
123 com_err("icheck", retval,
124 "while calling ext2_block_iterate");
128 if (bw.blocks_left == 0)
132 retval = ext2fs_get_next_inode(scan, &ino, &inode);
134 com_err("icheck", retval,
135 "while doing inode scan");
140 printf("Block\tInode number\n");
141 for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
142 if (binfo->ino == 0) {
143 printf("%ld\t<block not found>\n", binfo->blk);
146 printf("%ld\t%ld\n", binfo->blk, binfo->ino);
153 ext2fs_close_inode_scan(scan);