17 * - check hash table index
18 * - clear extents from free bitmap and make sure free bitmap is null
19 * - sanity check block size, sys block size, mirrors, etc
20 * - check that extent count is valid
21 * - check that terminator matches
22 * - make sure file sizes match up
25 int check_crc(u8
*blk
)
28 size_t hdr_size
= sizeof(struct omfs_header
);
29 struct omfs_inode
*oi
;
31 oi
= (struct omfs_inode
*) blk
;
33 crc
= crc_ccitt_msb(0, blk
+ hdr_size
,
34 swap_be32(oi
->head
.body_size
));
36 return (crc
== swap_be16(oi
->head
.crc
));
39 int check_header(u8
*blk
)
43 struct omfs_inode
*oi
;
45 oi
= (struct omfs_inode
*) blk
;
48 for (i
= 1; i
< OMFS_XOR_COUNT
; i
++)
51 return (xor == oi
->head
.check_xor
);
54 int check_sanity(check_context_t
*ctx
)
56 omfs_inode_t
*inode
= ctx
->current_inode
;
57 if (inode
->head
.body_size
> ctx
->omfs_info
->super
->sys_blocksize
)
59 // check device size here too.
63 int check_inode(check_context_t
*ctx
)
66 omfs_inode_t
*inode
= ctx
->current_inode
;
67 if (!check_sanity(ctx
))
69 fix_problem(E_INSANE
, ctx
);
72 if (!check_header(inode
->data
))
74 fix_problem(E_HEADER_XOR
, ctx
);
76 if (!check_crc(inode
->data
))
78 fix_problem(E_HEADER_CRC
, ctx
);
80 if (inode
->head
.self
!= ctx
->block
)
82 fix_problem(E_SELF_PTR
, ctx
);
85 if (inode
->parent
!= ctx
->parent
)
87 fix_problem(E_PARENT_PTR
, ctx
);
90 if (omfs_compute_hash(ctx
->omfs_info
, inode
->name
) != ctx
->hash
)
92 fix_problem(E_HASH_WRONG
, ctx
);
95 if (ctx
->bitmap
&& !test_bit(ctx
->bitmap
, inode
->head
.self
))
97 fix_problem(E_BIT_CLEAR
, ctx
);
100 clear_bit(ctx
->bitmap
, inode
->head
.self
);
101 if (inode
->type
== OMFS_FILE
)
103 // TODO check its extents here
109 int check_fs(FILE *fp
)
120 if (omfs_read_super(fp
, &super
))
122 fix_problem(E_READ_SUPER
, 0);
125 if (omfs_read_root_block(fp
, &super
, &root
))
127 fix_problem(E_READ_ROOT
, 0);
131 dirscan_entry_t
*entry
;
132 ctx
.omfs_info
= &info
;
133 ctx
.bitmap
= omfs_get_bitmap(&info
);
135 dirscan_t
*scan
= dirscan_begin(&info
);
138 fix_problem(E_SCAN
, 0);
142 while ((entry
= dirscan_next(scan
)))
144 char *name
= escape(entry
->inode
->name
);
145 printf("inode: %*c%s %llx %d %llx %llx\n",
146 entry
->level
*2, ' ', name
,
147 entry
->inode
->head
.self
, entry
->hindex
,
148 entry
->parent
, entry
->block
);
151 ctx
.current_inode
= entry
->inode
;
152 ctx
.block
= entry
->block
;
153 ctx
.parent
= entry
->parent
;
154 ctx
.hash
= entry
->hindex
;
157 dirscan_release_entry(entry
);
161 // TODO check all set bits for real inodes. If they are there,
162 // move them to root directory with a found-<name>