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.
15 #include <sys/types.h>
25 struct block_walk_struct {
26 struct block_info *barray;
32 int icheck_proc(ext2_filsys fs,
37 struct block_walk_struct *bw = (struct block_walk_struct *) private;
40 for (i=0; i < bw->num_blocks; i++) {
41 if (bw->barray[i].blk == *block_nr) {
42 bw->barray[i].ino = bw->inode;
52 void do_icheck(int argc, char **argv)
54 struct block_walk_struct bw;
55 struct block_info *binfo;
57 ext2_inode_scan scan = 0;
59 struct ext2_inode inode;
65 com_err(argv[0], 0, "Usage: icheck <block number> ...");
68 if (check_fs_open(argv[0]))
71 bw.barray = malloc(sizeof(struct block_info) * argc);
73 com_err("icheck", ENOMEM,
74 "while allocating inode info array");
77 memset(bw.barray, 0, sizeof(struct block_info) * argc);
79 block_buf = malloc(fs->blocksize * 3);
81 com_err("icheck", ENOMEM, "while allocating block buffer");
85 for (i=1; i < argc; i++) {
86 bw.barray[i-1].blk = strtol(argv[i], &tmp, 0);
88 com_err(argv[0], 0, "Bad block - %s", argv[i]);
93 bw.num_blocks = bw.blocks_left = argc-1;
95 retval = ext2fs_open_inode_scan(fs, 0, &scan);
97 com_err("icheck", retval, "while opening inode scan");
101 retval = ext2fs_get_next_inode(scan, &ino, &inode);
103 com_err("icheck", retval, "while starting inode scan");
108 if (!inode.i_links_count)
111 * To handle filesystems touched by 0.3c extfs; can be
119 retval = ext2fs_block_iterate(fs, ino, 0, block_buf,
122 com_err("icheck", retval,
123 "while calling ext2_block_iterate");
127 if (bw.blocks_left == 0)
131 retval = ext2fs_get_next_inode(scan, &ino, &inode);
133 com_err("icheck", retval,
134 "while doing inode scan");
139 printf("Block\tInode number\n");
140 for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
141 if (binfo->ino == 0) {
142 printf("%ld\t<block not found>\n", binfo->blk);
145 printf("%ld\t%ld\n", binfo->blk, binfo->ino);
152 ext2fs_close_inode_scan(scan);