wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 1 | #ifndef jffs2_private_h |
| 2 | #define jffs2_private_h |
| 3 | |
| 4 | #include <jffs2/jffs2.h> |
| 5 | |
| 6 | struct b_node { |
| 7 | u32 offset; |
| 8 | struct b_node *next; |
Ilya Yanok | c0c0773 | 2008-11-13 19:49:36 +0300 | [diff] [blame] | 9 | enum { CRC_UNKNOWN = 0, CRC_OK, CRC_BAD } datacrc; |
Petr Borsodi | 80c25b1 | 2020-05-07 12:25:56 +0200 | [diff] [blame] | 10 | u32 version; |
| 11 | union { |
| 12 | u32 ino; /* for inodes */ |
| 13 | u32 pino; /* for dirents */ |
| 14 | }; |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 15 | }; |
| 16 | |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 17 | struct b_list { |
| 18 | struct b_node *listTail; |
| 19 | struct b_node *listHead; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 21 | 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 | |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 29 | struct b_lists { |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 30 | struct b_list dir; |
| 31 | struct b_list frag; |
Ilya Yanok | e7fd671 | 2008-11-13 19:49:34 +0300 | [diff] [blame] | 32 | void *readbuf; |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 33 | }; |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 34 | |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 35 | struct b_compr_info { |
| 36 | u32 num_frags; |
| 37 | u32 compr_sum; |
| 38 | u32 decompr_sum; |
| 39 | }; |
| 40 | |
| 41 | struct b_jffs2_info { |
| 42 | struct b_compr_info compr_info[JFFS2_NUM_COMPR]; |
| 43 | }; |
| 44 | |
| 45 | static inline int |
| 46 | hdr_crc(struct jffs2_unknown_node *node) |
| 47 | { |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 48 | #if 1 |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4); |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 50 | #else |
| 51 | /* what's the semantics of this? why is this here? */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 52 | u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4); |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 53 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | crc ^= ~0; |
wdenk | 6b58f33 | 2003-03-14 20:47:52 +0000 | [diff] [blame] | 55 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | if (node->hdr_crc != crc) { |
| 57 | return 0; |
| 58 | } else { |
| 59 | return 1; |
| 60 | } |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static inline int |
| 64 | dirent_crc(struct jffs2_raw_dirent *node) |
| 65 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 66 | 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 | } |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static inline int |
| 74 | dirent_name_crc(struct jffs2_raw_dirent *node) |
| 75 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) { |
| 77 | return 0; |
| 78 | } else { |
| 79 | return 1; |
| 80 | } |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static inline int |
| 84 | inode_crc(struct jffs2_raw_inode *node) |
| 85 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | 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 | } |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Wolfgang Denk | dd7e866 | 2006-03-12 16:05:05 +0100 | [diff] [blame] | 93 | static inline int |
| 94 | data_crc(struct jffs2_raw_inode *node) |
| 95 | { |
| 96 | if (node->data_crc != crc32_no_comp(0, (unsigned char *) |
Wolfgang Denk | 315b46a | 2006-03-17 11:42:53 +0100 | [diff] [blame] | 97 | ((int) &node->node_crc + sizeof (node->node_crc)), |
| 98 | node->csize)) { |
Wolfgang Denk | dd7e866 | 2006-03-12 16:05:05 +0100 | [diff] [blame] | 99 | return 0; |
| 100 | } else { |
| 101 | return 1; |
| 102 | } |
| 103 | } |
| 104 | |
Mark Tomlinson | efdc2a6 | 2015-07-01 16:38:29 +1200 | [diff] [blame] | 105 | #if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS) |
| 106 | /* External merge sort. */ |
| 107 | int sort_list(struct b_list *list); |
| 108 | #endif |
wdenk | 5a2543c | 2002-02-17 23:36:36 +0000 | [diff] [blame] | 109 | #endif /* jffs2_private.h */ |