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.
18 #include <sys/types.h>
27 struct block_walk_struct {
28 struct block_info *barray;
29 e2_blkcnt_t blocks_left;
30 e2_blkcnt_t num_blocks;
34 static int icheck_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
36 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
37 blk64_t ref_block EXT2FS_ATTR((unused)),
38 int ref_offset EXT2FS_ATTR((unused)),
41 struct block_walk_struct *bw = (struct block_walk_struct *) private;
44 for (i=0; i < bw->num_blocks; i++) {
45 if (!bw->barray[i].ino && bw->barray[i].blk == *block_nr) {
46 bw->barray[i].ino = bw->inode;
56 void do_icheck(int argc, char **argv)
58 struct block_walk_struct bw;
59 struct block_info *binfo;
61 ext2_inode_scan scan = 0;
63 struct ext2_inode inode;
68 com_err(argv[0], 0, "Usage: icheck <block number> ...");
71 if (check_fs_open(argv[0]))
74 bw.barray = malloc(sizeof(struct block_info) * argc);
76 com_err("icheck", ENOMEM,
77 "while allocating inode info array");
80 memset(bw.barray, 0, sizeof(struct block_info) * argc);
82 block_buf = malloc(current_fs->blocksize * 3);
84 com_err("icheck", ENOMEM, "while allocating block buffer");
88 for (i=1; i < argc; i++) {
89 if (strtoblk(argv[0], argv[i], &bw.barray[i-1].blk))
93 bw.num_blocks = bw.blocks_left = argc-1;
95 retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
97 com_err("icheck", retval, "while opening inode scan");
102 retval = ext2fs_get_next_inode(scan, &ino, &inode);
103 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
105 com_err("icheck", retval, "while starting inode scan");
112 if (!inode.i_links_count)
117 blk = ext2fs_file_acl_block(current_fs, &inode);
119 icheck_proc(current_fs, &blk, 0,
121 if (bw.blocks_left == 0)
123 ext2fs_file_acl_block_set(current_fs, &inode, blk);
126 if (!ext2fs_inode_has_valid_blocks2(current_fs, &inode))
129 * To handle filesystems touched by 0.3c extfs; can be
135 retval = ext2fs_block_iterate3(current_fs, ino,
136 BLOCK_FLAG_READ_ONLY, block_buf,
139 com_err("icheck", retval,
140 "while calling ext2fs_block_iterate");
144 if (bw.blocks_left == 0)
149 retval = ext2fs_get_next_inode(scan, &ino, &inode);
150 } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
152 com_err("icheck", retval,
153 "while doing inode scan");
158 printf("Block\tInode number\n");
159 for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
160 if (binfo->ino == 0) {
161 printf("%llu\t<block not found>\n", binfo->blk);
164 printf("%llu\t%u\n", binfo->blk, binfo->ino);
171 ext2fs_close_inode_scan(scan);