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(current_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(current_fs
, 0, &scan
);
98 com_err("icheck", retval
, "while opening inode scan");
103 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
104 } while (retval
== EXT2_ET_BAD_BLOCK_IN_INODE_TABLE
);
106 com_err("icheck", retval
, "while starting inode scan");
111 if (!inode
.i_links_count
)
113 if (!ext2fs_inode_has_valid_blocks(&inode
))
116 * To handle filesystems touched by 0.3c extfs; can be
124 retval
= ext2fs_block_iterate(current_fs
, ino
, 0, block_buf
,
127 com_err("icheck", retval
,
128 "while calling ext2_block_iterate");
132 if (bw
.blocks_left
== 0)
137 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
138 } while (retval
== EXT2_ET_BAD_BLOCK_IN_INODE_TABLE
);
140 com_err("icheck", retval
,
141 "while doing inode scan");
146 printf("Block\tInode number\n");
147 for (i
=0, binfo
= bw
.barray
; i
< bw
.num_blocks
; i
++, binfo
++) {
148 if (binfo
->ino
== 0) {
149 printf("%u\t<block not found>\n", binfo
->blk
);
152 printf("%u\t%ld\n", binfo
->blk
, binfo
->ino
);
159 ext2fs_close_inode_scan(scan
);