blob: 06b6ca29194dd93cb0fcb3664fa674fb8711b213 [file] [log] [blame]
wdenk5a2543c2002-02-17 23:36:36 +00001#ifndef jffs2_private_h
2#define jffs2_private_h
3
4#include <jffs2/jffs2.h>
5
wdenk06d01db2003-03-14 20:47:52 +00006
wdenk5a2543c2002-02-17 23:36:36 +00007struct b_node {
8 u32 offset;
9 struct b_node *next;
Ilya Yanok142a80f2008-11-13 19:49:36 +030010 enum { CRC_UNKNOWN = 0, CRC_OK, CRC_BAD } datacrc;
wdenk5a2543c2002-02-17 23:36:36 +000011};
12
wdenk06d01db2003-03-14 20:47:52 +000013struct b_list {
14 struct b_node *listTail;
15 struct b_node *listHead;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020016#ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
wdenk06d01db2003-03-14 20:47:52 +000017 struct b_node *listLast;
18 int (*listCompare)(struct b_node *new, struct b_node *node);
19 u32 listLoops;
20#endif
21 u32 listCount;
22 struct mem_block *listMemBase;
23};
24
wdenk5a2543c2002-02-17 23:36:36 +000025struct b_lists {
wdenk06d01db2003-03-14 20:47:52 +000026 struct b_list dir;
27 struct b_list frag;
Ilya Yanok70741002008-11-13 19:49:34 +030028 void *readbuf;
wdenk5a2543c2002-02-17 23:36:36 +000029};
wdenk06d01db2003-03-14 20:47:52 +000030
wdenk5a2543c2002-02-17 23:36:36 +000031struct b_compr_info {
32 u32 num_frags;
33 u32 compr_sum;
34 u32 decompr_sum;
35};
36
37struct b_jffs2_info {
38 struct b_compr_info compr_info[JFFS2_NUM_COMPR];
39};
40
41static inline int
42hdr_crc(struct jffs2_unknown_node *node)
43{
wdenk06d01db2003-03-14 20:47:52 +000044#if 1
wdenk8bde7f72003-06-27 21:31:46 +000045 u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk06d01db2003-03-14 20:47:52 +000046#else
47 /* what's the semantics of this? why is this here? */
wdenk8bde7f72003-06-27 21:31:46 +000048 u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk5a2543c2002-02-17 23:36:36 +000049
wdenk8bde7f72003-06-27 21:31:46 +000050 crc ^= ~0;
wdenk06d01db2003-03-14 20:47:52 +000051#endif
wdenk8bde7f72003-06-27 21:31:46 +000052 if (node->hdr_crc != crc) {
53 return 0;
54 } else {
55 return 1;
56 }
wdenk5a2543c2002-02-17 23:36:36 +000057}
58
59static inline int
60dirent_crc(struct jffs2_raw_dirent *node)
61{
wdenk8bde7f72003-06-27 21:31:46 +000062 if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_dirent) - 8)) {
63 return 0;
64 } else {
65 return 1;
66 }
wdenk5a2543c2002-02-17 23:36:36 +000067}
68
69static inline int
70dirent_name_crc(struct jffs2_raw_dirent *node)
71{
wdenk8bde7f72003-06-27 21:31:46 +000072 if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) {
73 return 0;
74 } else {
75 return 1;
76 }
wdenk5a2543c2002-02-17 23:36:36 +000077}
78
79static inline int
80inode_crc(struct jffs2_raw_inode *node)
81{
wdenk8bde7f72003-06-27 21:31:46 +000082 if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_inode) - 8)) {
83 return 0;
84 } else {
85 return 1;
86 }
wdenk5a2543c2002-02-17 23:36:36 +000087}
88
Wolfgang Denk74f92e62006-03-12 16:05:05 +010089static inline int
90data_crc(struct jffs2_raw_inode *node)
91{
92 if (node->data_crc != crc32_no_comp(0, (unsigned char *)
Wolfgang Denk09e4b0c2006-03-17 11:42:53 +010093 ((int) &node->node_crc + sizeof (node->node_crc)),
94 node->csize)) {
Wolfgang Denk74f92e62006-03-12 16:05:05 +010095 return 0;
96 } else {
97 return 1;
98 }
99}
100
Mark Tomlinson10d3ac32015-07-01 16:38:29 +1200101#if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS)
102/* External merge sort. */
103int sort_list(struct b_list *list);
104#endif
wdenk5a2543c2002-02-17 23:36:36 +0000105#endif /* jffs2_private.h */