Updated report.
[fsck.sofs09.git] / test_ininfo.c
bloba928d30983a2110b3041936e55e7766c73448a5a
1 #include "sofs09.h"
2 #include "fsck.h"
3 #include "fsck_helper.h"
5 /* This test can only be run after all other inode tests.
6 * This test is more like a set of tests, so, a lot of returns are spread all
7 * over the code.
8 */
9 testresult_t test_ininfo(void)
11 testresult_t ret;
12 int inodeidx;
13 SOInode inode;
14 ic_t icstat;
15 int typesum;
16 uint32_t realrefcount;
17 SOSuperBlock *sb;
18 int fret;
20 ret = nice;
21 fetch_superblock(&sb);
23 for (inodeidx = 0; inodeidx < sb->itotal; ++inodeidx) {
24 fret = soReadInode(&inode, inodeidx);
25 if (fret < 0) FABORT(fret, "test_ininfo");
27 /* check freeness */
28 ictable_get(inodeidx, &icstat);
29 switch(icstat) {
30 case idle:
31 if ((inode.mode && INODE_FREE) == 0) {
32 printf("Inode %d is free, but it's INODE_FREE bit is not "
33 "set.\n", inodeidx);
34 ret = corrupt;
36 break;
37 case busy:
38 if ((inode.mode && INODE_FREE) == INODE_FREE) {
39 printf("Inode %d is in use, but it's INODE_FREE bit is "
40 "set.\n", inodeidx);
41 ret = corrupt;
43 break;
44 default:
45 printf("BUM! test_ininfo assumes inodes are either free or "
46 "used.\n");
47 return corrupt;
50 /* check type */
51 typesum = (inode.mode && INODE_DIR)/INODE_DIR +
52 (inode.mode && INODE_FILE)/INODE_FILE +
53 (inode.mode && INODE_SYMLINK)/INODE_SYMLINK;
54 if (((inode.mode && INODE_FREE) == 0) && typesum == 0) {
55 printf("Inode %d is not free but has no type.\n", inodeidx);
56 ret = corrupt;
58 if (typesum > 1) {
59 printf("Inode %d has many types.\n", inodeidx);
60 ret = corrupt;
63 /* check refcount */
64 irtable_get(inodeidx, &realrefcount);
65 if (realrefcount != inode.refcount) {
66 printf("Refcount of inode %d is %d but should be %d.\n", inodeidx,
67 inode.refcount, realrefcount);
68 ret = corrupt;
72 return ret;