blob: 9284ab5c2c1dd8ab9fa1a23bcb1f6f0fe1f63b07 [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
6struct b_node {
7 u32 offset;
8 struct b_node *next;
Ilya Yanokc0c07732008-11-13 19:49:36 +03009 enum { CRC_UNKNOWN = 0, CRC_OK, CRC_BAD } datacrc;
Petr Borsodi80c25b12020-05-07 12:25:56 +020010 u32 version;
11 union {
12 u32 ino; /* for inodes */
13 u32 pino; /* for dirents */
14 };
wdenk5a2543c2002-02-17 23:36:36 +000015};
16
wdenk6b58f332003-03-14 20:47:52 +000017struct b_list {
18 struct b_node *listTail;
19 struct b_node *listHead;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020020#ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
wdenk6b58f332003-03-14 20:47:52 +000021 struct b_node *listLast;
22 int (*listCompare)(struct b_node *new, struct b_node *node);
23 u32 listLoops;
24#endif
25 u32 listCount;
26 struct mem_block *listMemBase;
27};
28
wdenk5a2543c2002-02-17 23:36:36 +000029struct b_lists {
wdenk6b58f332003-03-14 20:47:52 +000030 struct b_list dir;
31 struct b_list frag;
Ilya Yanoke7fd6712008-11-13 19:49:34 +030032 void *readbuf;
wdenk5a2543c2002-02-17 23:36:36 +000033};
wdenk6b58f332003-03-14 20:47:52 +000034
wdenk5a2543c2002-02-17 23:36:36 +000035struct b_compr_info {
36 u32 num_frags;
37 u32 compr_sum;
38 u32 decompr_sum;
39};
40
41struct b_jffs2_info {
42 struct b_compr_info compr_info[JFFS2_NUM_COMPR];
43};
44
45static inline int
46hdr_crc(struct jffs2_unknown_node *node)
47{
wdenk6b58f332003-03-14 20:47:52 +000048#if 1
wdenk57b2d802003-06-27 21:31:46 +000049 u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk6b58f332003-03-14 20:47:52 +000050#else
51 /* what's the semantics of this? why is this here? */
wdenk57b2d802003-06-27 21:31:46 +000052 u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4);
wdenk5a2543c2002-02-17 23:36:36 +000053
wdenk57b2d802003-06-27 21:31:46 +000054 crc ^= ~0;
wdenk6b58f332003-03-14 20:47:52 +000055#endif
wdenk57b2d802003-06-27 21:31:46 +000056 if (node->hdr_crc != crc) {
57 return 0;
58 } else {
59 return 1;
60 }
wdenk5a2543c2002-02-17 23:36:36 +000061}
62
63static inline int
64dirent_crc(struct jffs2_raw_dirent *node)
65{
wdenk57b2d802003-06-27 21:31:46 +000066 if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_dirent) - 8)) {
67 return 0;
68 } else {
69 return 1;
70 }
wdenk5a2543c2002-02-17 23:36:36 +000071}
72
73static inline int
74dirent_name_crc(struct jffs2_raw_dirent *node)
75{
wdenk57b2d802003-06-27 21:31:46 +000076 if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) {
77 return 0;
78 } else {
79 return 1;
80 }
wdenk5a2543c2002-02-17 23:36:36 +000081}
82
83static inline int
84inode_crc(struct jffs2_raw_inode *node)
85{
wdenk57b2d802003-06-27 21:31:46 +000086 if (node->node_crc != crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_raw_inode) - 8)) {
87 return 0;
88 } else {
89 return 1;
90 }
wdenk5a2543c2002-02-17 23:36:36 +000091}
92
Wolfgang Denkdd7e8662006-03-12 16:05:05 +010093static inline int
94data_crc(struct jffs2_raw_inode *node)
95{
96 if (node->data_crc != crc32_no_comp(0, (unsigned char *)
Wolfgang Denk315b46a2006-03-17 11:42:53 +010097 ((int) &node->node_crc + sizeof (node->node_crc)),
98 node->csize)) {
Wolfgang Denkdd7e8662006-03-12 16:05:05 +010099 return 0;
100 } else {
101 return 1;
102 }
103}
104
Mark Tomlinsonefdc2a62015-07-01 16:38:29 +1200105#if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS)
106/* External merge sort. */
107int sort_list(struct b_list *list);
108#endif
wdenk5a2543c2002-02-17 23:36:36 +0000109#endif /* jffs2_private.h */