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