1 #ifndef jffs2_private_h
2 #define jffs2_private_h
3 
4 #include <jffs2/jffs2.h>
5 
6 
7 struct b_node {
8 	u32 offset;
9 	struct b_node *next;
10 	enum { CRC_UNKNOWN = 0, CRC_OK, CRC_BAD } datacrc;
11 	u32 version;
12 	union {
13 		u32 ino; /* for inodes */
14 		u32 pino; /* for dirents */
15 	};
16 };
17 
18 struct b_list {
19 	struct b_node *listTail;
20 	struct b_node *listHead;
21 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
22 	struct b_node *listLast;
23 	int (*listCompare)(struct b_node *new, struct b_node *node);
24 	u32 listLoops;
25 #endif
26 	u32 listCount;
27 	struct mem_block *listMemBase;
28 };
29 
30 struct b_lists {
31 	struct b_list dir;
32 	struct b_list frag;
33 	void *readbuf;
34 };
35 
36 struct b_compr_info {
37 	u32 num_frags;
38 	u32 compr_sum;
39 	u32 decompr_sum;
40 };
41 
42 struct b_jffs2_info {
43 	struct b_compr_info compr_info[JFFS2_NUM_COMPR];
44 };
45 
46 static inline int
hdr_crc(struct jffs2_unknown_node * node)47 hdr_crc(struct jffs2_unknown_node *node)
48 {
49 #if 1
50 	u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
51 #else
52 	/* what's the semantics of this? why is this here? */
53 	u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
54 
55 	crc ^= ~0;
56 #endif
57 	if (node->hdr_crc != crc) {
58 		return 0;
59 	} else {
60 		return 1;
61 	}
62 }
63 
64 static inline int
dirent_crc(struct jffs2_raw_dirent * node)65 dirent_crc(struct jffs2_raw_dirent *node)
66 {
67 	if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_dirent) - 8)) {
68 		return 0;
69 	} else {
70 		return 1;
71 	}
72 }
73 
74 static inline int
dirent_name_crc(struct jffs2_raw_dirent * node)75 dirent_name_crc(struct jffs2_raw_dirent *node)
76 {
77 	if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) {
78 		return 0;
79 	} else {
80 		return 1;
81 	}
82 }
83 
84 static inline int
inode_crc(struct jffs2_raw_inode * node)85 inode_crc(struct jffs2_raw_inode *node)
86 {
87 	if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_inode) - 8)) {
88 		return 0;
89 	} else {
90 		return 1;
91 	}
92 }
93 
94 static inline int
data_crc(struct jffs2_raw_inode * node)95 data_crc(struct jffs2_raw_inode *node)
96 {
97 	if (node->data_crc != crc32_no_comp(0, (unsigned char *)
98 					    ((int) &node->node_crc + sizeof (node->node_crc)),
99 					     node->csize)) {
100 		return 0;
101 	} else {
102 		return 1;
103 	}
104 }
105 
106 #if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS)
107 /* External merge sort. */
108 int sort_list(struct b_list *list);
109 #endif
110 #endif /* jffs2_private.h */
111