blob: 65d19a76f97cc86afc0d90dad4b1479974adab33 [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
wdenk6b58f332003-03-14 20:47:52 +00006
wdenk5a2543c2002-02-17 23:36:36 +00007struct b_node {
8 u32 offset;
9 struct b_node *next;
Ilya Yanokc0c07732008-11-13 19:49:36 +030010 enum { CRC_UNKNOWN = 0, CRC_OK, CRC_BAD } datacrc;
Petr Borsodi80c25b12020-05-07 12:25:56 +020011 u32 version;
12 union {
13 u32 ino; /* for inodes */
14 u32 pino; /* for dirents */
15 };
wdenk5a2543c2002-02-17 23:36:36 +000016};
17
wdenk6b58f332003-03-14 20:47:52 +000018struct b_list {
19 struct b_node *listTail;
20 struct b_node *listHead;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020021#ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
wdenk6b58f332003-03-14 20:47:52 +000022 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
wdenk5a2543c2002-02-17 23:36:36 +000030struct b_lists {
wdenk6b58f332003-03-14 20:47:52 +000031 struct b_list dir;
32 struct b_list frag;
Ilya Yanoke7fd6712008-11-13 19:49:34 +030033 void *readbuf;
wdenk5a2543c2002-02-17 23:36:36 +000034};
wdenk6b58f332003-03-14 20:47:52 +000035
wdenk5a2543c2002-02-17 23:36:36 +000036struct b_compr_info {
37 u32 num_frags;
38 u32 compr_sum;
39 u32 decompr_sum;
40};
41
42struct b_jffs2_info {
43 struct b_compr_info compr_info[JFFS2_NUM_COMPR];
44};
45
46static inline int
47hdr_crc(struct jffs2_unknown_node *node)
48{
wdenk6b58f332003-03-14 20:47:52 +000049#if 1
wdenk57b2d802003-06-27 21:31:46 +000050 u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk6b58f332003-03-14 20:47:52 +000051#else
52 /* what's the semantics of this? why is this here? */
wdenk57b2d802003-06-27 21:31:46 +000053 u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk5a2543c2002-02-17 23:36:36 +000054
wdenk57b2d802003-06-27 21:31:46 +000055 crc ^= ~0;
wdenk6b58f332003-03-14 20:47:52 +000056#endif
wdenk57b2d802003-06-27 21:31:46 +000057 if (node->hdr_crc != crc) {
58 return 0;
59 } else {
60 return 1;
61 }
wdenk5a2543c2002-02-17 23:36:36 +000062}
63
64static inline int
65dirent_crc(struct jffs2_raw_dirent *node)
66{
wdenk57b2d802003-06-27 21:31:46 +000067 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 }
wdenk5a2543c2002-02-17 23:36:36 +000072}
73
74static inline int
75dirent_name_crc(struct jffs2_raw_dirent *node)
76{
wdenk57b2d802003-06-27 21:31:46 +000077 if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) {
78 return 0;
79 } else {
80 return 1;
81 }
wdenk5a2543c2002-02-17 23:36:36 +000082}
83
84static inline int
85inode_crc(struct jffs2_raw_inode *node)
86{
wdenk57b2d802003-06-27 21:31:46 +000087 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 }
wdenk5a2543c2002-02-17 23:36:36 +000092}
93
Wolfgang Denkdd7e8662006-03-12 16:05:05 +010094static inline int
95data_crc(struct jffs2_raw_inode *node)
96{
97 if (node->data_crc != crc32_no_comp(0, (unsigned char *)
Wolfgang Denk315b46a2006-03-17 11:42:53 +010098 ((int) &node->node_crc + sizeof (node->node_crc)),
99 node->csize)) {
Wolfgang Denkdd7e8662006-03-12 16:05:05 +0100100 return 0;
101 } else {
102 return 1;
103 }
104}
105
Mark Tomlinsonefdc2a62015-07-01 16:38:29 +1200106#if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS)
107/* External merge sort. */
108int sort_list(struct b_list *list);
109#endif
wdenk5a2543c2002-02-17 23:36:36 +0000110#endif /* jffs2_private.h */