test_insued refactored
[fsck.sofs09.git] / test_ininfo.c
blob9b3efe0cae8f671251c30394be3a59248f91169a
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 testresult_t test_ininfo(void)
8 testresult_t ret;
9 int inodeidx;
10 SOInode inode;
11 ic_t icstat;
12 int typesum;
13 uint32_t realrefcount;
14 SOSuperBlock *sb;
15 int fret;
17 ret = nice;
18 fetch_superblock(&sb);
20 for (inodeidx = 0; inodeidx < sb->itotal; ++inodeidx) {
21 fret = soReadInode(&inode, inodeidx);
22 if (fret < 0) FABORT(fret, "test_ininfo");
24 /* check freeness */
25 ictable_get(inodeidx, &icstat);
26 switch(icstat) {
27 case idle:
28 if ((inode.mode && INODE_FREE) == 0) {
29 printf("Inode %d is free, but it's INODE_FREE bit is not "
30 "set.\n", inodeidx);
31 ret = corrupt;
33 break;
34 case busy:
35 if ((inode.mode && INODE_FREE) == INODE_FREE) {
36 printf("Inode %d is in use, but it's INODE_FREE bit is "
37 "set.\n", inodeidx);
38 ret = corrupt;
40 break;
41 default:
42 printf("BUM! test_ininfo assumes inodes are either free or "
43 "used.\n");
44 return corrupt;
47 /* check type */
48 typesum = (inode.mode && INODE_DIR)/INODE_DIR +
49 (inode.mode && INODE_FILE)/INODE_FILE +
50 (inode.mode && INODE_SYMLINK)/INODE_SYMLINK;
51 if (((inode.mode && INODE_FREE) == 0) && typesum == 0) {
52 printf("Inode %d is not free but has no type.\n", inodeidx);
53 ret = corrupt;
55 if (typesum > 1) {
56 printf("Inode %d has many types.\n", inodeidx);
57 ret = corrupt;
60 /* check refcount */
61 irtable_get(inodeidx, &realrefcount);
62 if (realrefcount != inode.refcount) {
63 printf("Refcount of inode %d is %d but should be %d.\n", inodeidx,
64 inode.refcount, realrefcount);
65 ret = corrupt;
69 return ret;