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;
28 e2_blkcnt_t blocks_left;
29 e2_blkcnt_t num_blocks;
33 static int icheck_proc(ext2_filsys fs,
40 struct block_walk_struct *bw = (struct block_walk_struct *) private;
43 for (i=0; i < bw->num_blocks; i++) {
44 if (bw->barray[i].blk == *block_nr) {
45 bw->barray[i].ino = bw->inode;
55 void do_icheck(int argc, char **argv)
57 struct block_walk_struct bw;
58 struct block_info *binfo;
60 ext2_inode_scan scan = 0;
62 struct ext2_inode inode;
67 com_err(argv[0], 0, "Usage: icheck <block number> ...");
70 if (check_fs_open(argv[0]))
73 bw.barray = malloc(sizeof(struct block_info) * argc);
75 com_err("icheck", ENOMEM,
76 "while allocating inode info array");
79 memset(bw.barray, 0, sizeof(struct block_info) * argc);
81 block_buf = malloc(current_fs->blocksize * 3);
83 com_err("icheck", ENOMEM, "while allocating block buffer");
87 for (i=1; i < argc; i++) {
88 if (strtoblk(argv[0], argv[i], &bw.barray[i-1].blk))
92 bw.num_blocks = bw.blocks_left = argc-1;
94 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
96 com_err("icheck", retval, "while opening inode scan");
101 retval = ext2fs_get_next_inode(scan, &ino, &inode);
102 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
104 com_err("icheck", retval, "while starting inode scan");
109 if (!inode.i_links_count)
111 if (!ext2fs_inode_has_valid_blocks(&inode))
114 * To handle filesystems touched by 0.3c extfs; can be
122 retval = ext2fs_block_iterate2(current_fs, ino, 0, block_buf,
125 com_err("icheck", retval,
126 "while calling ext2fs_block_iterate");
130 if (bw.blocks_left == 0)
135 retval = ext2fs_get_next_inode(scan, &ino, &inode);
136 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
138 com_err("icheck", retval,
139 "while doing inode scan");
144 printf("Block\tInode number\n");
145 for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
146 if (binfo->ino == 0) {
147 printf("%u\t<block not found>\n", binfo->blk);
150 printf("%u\t%u\n", binfo->blk, binfo->ino);
157 ext2fs_close_inode_scan(scan);