Implemented changes proposed by the teacher.
[fsck.sofs09.git] / test_infree.c
bloba11ef63d85d3e45a804286dc475ca084348c63dc
1 #include <stdio.h>
2 #include "fsck.h"
3 #include "fsck_helper.h"
4 #include "sofs09.h"
6 testresult_t test_infree (void)
8 testresult_t ret;
9 uint32_t fret;
10 SOSuperBlock *sb;
11 uint32_t ifree;
12 SOInode inode;
13 uint32_t inodeidx, previnodeidx;
14 ic_t icstat;
16 ret = nice;
18 fetch_superblock(&sb);
20 ifree = 0;
21 inodeidx = sb->ihead;
22 previnodeidx = NULL_INODE;
23 while (inodeidx != NULL_INODE) {
24 if (inodeidx < sb->itotal) {
25 ictable_get(inodeidx, &icstat);
26 switch (icstat) {
27 case bah:
28 fret = soReadInode(&inode, inodeidx);
29 if (fret < 0) FABORT(fret, "test_infree");
30 ifree++;
31 ictable_set(inodeidx, idle);
32 break;
33 case busy:
34 printf("Inode number %u is marked as used and is in free"
35 "inode list.\n", inodeidx);
36 ret = corrupt;
37 break;
38 case idle:
39 printf("Free inode list closes over itself.\n");
40 return corrupt;
41 break;
42 default:
43 printf("BUM! ictable has something strange in it.\n");
44 return corrupt;
45 break;
47 } else {
48 printf("Free inode list has a member pointing to %u, which is "
49 "outside the list.\n", inodeidx);
50 return corrupt;
53 /* check previous */
54 if (inode.prev != previnodeidx) {
55 printf("Prev of inode %u in free inode list is %u, should be %u.\n"
56 inodeidx, inode.prev, previnodeidx);
57 ret = corrupt;
60 previnodeidx = inodeidx;
61 inodeidx = inode.next;
64 /* check itail */
65 if (previnodeidx != sb->itail) {
66 printf("Itail is %u, should be %u.\n", sb->itail, previnodeidx);
67 ret = corrupt;
69 if (ifree != sb->ifree) {
70 printf("ifree is %u, should be %u.\n", sb->ifree, ifree);
71 ret = corrupt;
74 return ret;