yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 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 | #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS |
| 12 | struct b_node *prev; |
| 13 | struct b_node *hash_next; |
| 14 | #endif |
| 15 | }; |
| 16 | |
| 17 | struct b_list { |
| 18 | struct b_node *listTail; |
| 19 | struct b_node *listHead; |
| 20 | #if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS) || defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS_DIR) |
| 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 | |
| 29 | struct b_lists { |
| 30 | struct b_list dir; |
| 31 | struct b_list frag; |
| 32 | void *readbuf; |
| 33 | }; |
| 34 | |
| 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 | { |
| 48 | #if 1 |
| 49 | u32 crc = crc32_no_comp(0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4); |
| 50 | #else |
| 51 | /* what's the semantics of this? why is this here? */ |
| 52 | u32 crc = crc32_no_comp(~0, (unsigned char *)node, sizeof(struct jffs2_unknown_node) - 4); |
| 53 | |
| 54 | crc ^= ~0; |
| 55 | #endif |
| 56 | if (node->hdr_crc != crc) { |
| 57 | return 0; |
| 58 | } else { |
| 59 | return 1; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | static inline int |
| 64 | dirent_crc(struct jffs2_raw_dirent *node) |
| 65 | { |
| 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 | } |
| 71 | } |
| 72 | |
| 73 | static inline int |
| 74 | dirent_name_crc(struct jffs2_raw_dirent *node) |
| 75 | { |
| 76 | if (node->name_crc != crc32_no_comp(0, (unsigned char *)&(node->name), node->nsize)) { |
| 77 | return 0; |
| 78 | } else { |
| 79 | return 1; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static inline int |
| 84 | inode_crc(struct jffs2_raw_inode *node) |
| 85 | { |
| 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 | } |
| 91 | } |
| 92 | |
| 93 | static inline int |
| 94 | data_crc(struct jffs2_raw_inode *node) |
| 95 | { |
| 96 | if (node->data_crc != crc32_no_comp(0, (unsigned char *) |
| 97 | ((int) &node->node_crc + sizeof (node->node_crc)), |
| 98 | node->csize)) { |
| 99 | return 0; |
| 100 | } else { |
| 101 | return 1; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | #if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS) || defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS_DIR) |
| 106 | /* External merge sort. */ |
| 107 | int sort_list(struct b_list *list); |
| 108 | #endif |
| 109 | #endif /* jffs2_private.h */ |