Head cache cnt and idx were being checked the wrong way.
[fsck.sofs09.git] / test_inused.c
blob329899af7ce4b1559e6ebdb3a9b0225c9d96abe6
1 #include <stdio.h>
3 #include "fsck.h"
4 #include "fsck_helper.h"
5 #include "sofs09.h"
7 /* this function needs to be remade. IT IS NASTY */
8 static bool parse_directory(uint32_t inodeidx)
10 bool ret;
11 uint32_t fret;
12 uint32_t cn, den;
13 SOInode inode, newinode;
14 SODirEntry dec[DPC]; /* direntry cluster */
15 ic_t icstat;
16 SOSuperBlock *sb;
18 fetch_superblock(&sb);
19 printf("Parsing directory number %d.\n", inodeidx);
21 ret = true;
23 fret = soReadInode(&inode, inodeidx);
24 if (fret < 0) FABORT(fret, "parse_directory");
26 ictable_get(inodeidx, &icstat);
27 switch (icstat) {
28 case bah:
29 ictable_set(inodeidx, busy);
30 break;
31 case idle:
32 printf ("Inode %d is marked as free but is in use.\n", inodeidx);
33 break;
34 case busy:
35 /* already parsed this inode */
36 break;
37 default:
38 printf("BUM! ictable has something strange in it.\n");
39 return false;
40 break;
43 for (cn = 0; (cn*CLUSTER_SIZE < inode.size) && (ret != false)
44 && (icstat == bah); ++cn) {
45 /* read a new cluster */
46 fret = soReadFileCluster(inodeidx, cn, dec);
47 if (fret < 0) FABORT(fret, "parse_directory");
48 for (den = 0; (den < DPC) && ((cn*CLUSTER_SIZE + den*sizeof(SODirEntry))
49 < inode.size) && (ret != false); ++den) {
50 /* process direntry */
51 if (dec[den].name[0] != '\0') {
52 if (dec[den].inode >= sb->itotal) {
53 printf("Direntry number %d of inode %d is pointing to %d, "
54 "which lies outside inode table.\n", den+(cn*DPC),
55 inodeidx, dec[den].inode);
56 ret = false;
57 } else {
58 irtable_inc(dec[den].inode);
59 fret = soReadInode(&newinode, dec[den].inode);
60 if (fret < 0) FABORT(fret, "parse_directory");
61 if ((newinode.mode & INODE_DIR) == INODE_DIR) {
62 ret = parse_directory(dec[den].inode);
63 } else {
64 ictable_get(dec[den].inode, &icstat);
65 switch (icstat) {
66 case bah:
67 ictable_set(dec[den].inode, busy);
68 break;
69 case idle:
70 printf
71 ("Inode %d is marked as free but is in "
72 "use.\n", dec[den].inode);
73 break;
74 case
75 busy:
76 /* already parsed this inode * */
77 break;
78 default:
79 printf("BUM! ictable has something strange in "
80 "it.\n");
81 return false;
82 break;
90 return ret;
93 testresult_t test_inused(void)
95 testresult_t ret;
97 ret = nice;
99 /* begin in root directory */
100 if (parse_directory(0) == false) {
101 ret = corrupt;
104 return ret;