Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * JFFS2 -- Journalling Flash File System, Version 2. |
| 3 | * |
| 4 | * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>, |
| 5 | * Zoltan Sogor <weth@inf.u-szeged.hu>, |
| 6 | * Patrik Kluba <pajko@halom.u-szeged.hu>, |
| 7 | * University of Szeged, Hungary |
| 8 | * |
| 9 | * For licensing information, see the file 'LICENCE' in this directory. |
| 10 | * |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 11 | * $Id: summary.h,v 1.2 2005/09/26 11:37:21 havasi Exp $ |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 12 | * |
| 13 | */ |
| 14 | |
| 15 | #ifndef JFFS2_SUMMARY_H |
| 16 | #define JFFS2_SUMMARY_H |
| 17 | |
| 18 | #include <linux/uio.h> |
| 19 | #include <linux/jffs2.h> |
| 20 | |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 21 | #define BLK_STATE_ALLFF 0 |
| 22 | #define BLK_STATE_CLEAN 1 |
| 23 | #define BLK_STATE_PARTDIRTY 2 |
| 24 | #define BLK_STATE_CLEANMARKER 3 |
| 25 | #define BLK_STATE_ALLDIRTY 4 |
| 26 | #define BLK_STATE_BADBLOCK 5 |
| 27 | |
| 28 | #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff |
| 29 | #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash)) |
| 30 | #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x)) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 31 | #define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash)) |
| 32 | #define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash)) |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 33 | |
| 34 | /* Summary structures used on flash */ |
| 35 | |
| 36 | struct jffs2_sum_unknown_flash |
| 37 | { |
| 38 | jint16_t nodetype; /* node type */ |
| 39 | }; |
| 40 | |
| 41 | struct jffs2_sum_inode_flash |
| 42 | { |
| 43 | jint16_t nodetype; /* node type */ |
| 44 | jint32_t inode; /* inode number */ |
| 45 | jint32_t version; /* inode version */ |
| 46 | jint32_t offset; /* offset on jeb */ |
| 47 | jint32_t totlen; /* record length */ |
| 48 | } __attribute__((packed)); |
| 49 | |
| 50 | struct jffs2_sum_dirent_flash |
| 51 | { |
| 52 | jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ |
| 53 | jint32_t totlen; /* record length */ |
| 54 | jint32_t offset; /* offset on jeb */ |
| 55 | jint32_t pino; /* parent inode */ |
| 56 | jint32_t version; /* dirent version */ |
| 57 | jint32_t ino; /* == zero for unlink */ |
| 58 | uint8_t nsize; /* dirent name size */ |
| 59 | uint8_t type; /* dirent type */ |
| 60 | uint8_t name[0]; /* dirent name */ |
| 61 | } __attribute__((packed)); |
| 62 | |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 63 | struct jffs2_sum_xattr_flash |
| 64 | { |
| 65 | jint16_t nodetype; /* == JFFS2_NODETYPE_XATR */ |
| 66 | jint32_t xid; /* xattr identifier */ |
| 67 | jint32_t version; /* version number */ |
| 68 | jint32_t offset; /* offset on jeb */ |
| 69 | jint32_t totlen; /* node length */ |
| 70 | } __attribute__((packed)); |
| 71 | |
| 72 | struct jffs2_sum_xref_flash |
| 73 | { |
| 74 | jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */ |
| 75 | jint32_t offset; /* offset on jeb */ |
| 76 | } __attribute__((packed)); |
| 77 | |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 78 | union jffs2_sum_flash |
| 79 | { |
| 80 | struct jffs2_sum_unknown_flash u; |
| 81 | struct jffs2_sum_inode_flash i; |
| 82 | struct jffs2_sum_dirent_flash d; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 83 | struct jffs2_sum_xattr_flash x; |
| 84 | struct jffs2_sum_xref_flash r; |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /* Summary structures used in the memory */ |
| 88 | |
| 89 | struct jffs2_sum_unknown_mem |
| 90 | { |
| 91 | union jffs2_sum_mem *next; |
| 92 | jint16_t nodetype; /* node type */ |
| 93 | }; |
| 94 | |
| 95 | struct jffs2_sum_inode_mem |
| 96 | { |
| 97 | union jffs2_sum_mem *next; |
| 98 | jint16_t nodetype; /* node type */ |
| 99 | jint32_t inode; /* inode number */ |
| 100 | jint32_t version; /* inode version */ |
| 101 | jint32_t offset; /* offset on jeb */ |
| 102 | jint32_t totlen; /* record length */ |
| 103 | } __attribute__((packed)); |
| 104 | |
| 105 | struct jffs2_sum_dirent_mem |
| 106 | { |
| 107 | union jffs2_sum_mem *next; |
| 108 | jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ |
| 109 | jint32_t totlen; /* record length */ |
| 110 | jint32_t offset; /* ofset on jeb */ |
| 111 | jint32_t pino; /* parent inode */ |
| 112 | jint32_t version; /* dirent version */ |
| 113 | jint32_t ino; /* == zero for unlink */ |
| 114 | uint8_t nsize; /* dirent name size */ |
| 115 | uint8_t type; /* dirent type */ |
| 116 | uint8_t name[0]; /* dirent name */ |
| 117 | } __attribute__((packed)); |
| 118 | |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 119 | struct jffs2_sum_xattr_mem |
| 120 | { |
| 121 | union jffs2_sum_mem *next; |
| 122 | jint16_t nodetype; |
| 123 | jint32_t xid; |
| 124 | jint32_t version; |
| 125 | jint32_t offset; |
| 126 | jint32_t totlen; |
| 127 | } __attribute__((packed)); |
| 128 | |
| 129 | struct jffs2_sum_xref_mem |
| 130 | { |
| 131 | union jffs2_sum_mem *next; |
| 132 | jint16_t nodetype; |
| 133 | jint32_t offset; |
| 134 | } __attribute__((packed)); |
| 135 | |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 136 | union jffs2_sum_mem |
| 137 | { |
| 138 | struct jffs2_sum_unknown_mem u; |
| 139 | struct jffs2_sum_inode_mem i; |
| 140 | struct jffs2_sum_dirent_mem d; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 141 | struct jffs2_sum_xattr_mem x; |
| 142 | struct jffs2_sum_xref_mem r; |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /* Summary related information stored in superblock */ |
| 146 | |
| 147 | struct jffs2_summary |
| 148 | { |
| 149 | uint32_t sum_size; /* collected summary information for nextblock */ |
| 150 | uint32_t sum_num; |
| 151 | uint32_t sum_padded; |
| 152 | union jffs2_sum_mem *sum_list_head; |
| 153 | union jffs2_sum_mem *sum_list_tail; |
| 154 | |
| 155 | jint32_t *sum_buf; /* buffer for writing out summary */ |
| 156 | }; |
| 157 | |
| 158 | /* Summary marker is stored at the end of every sumarized erase block */ |
| 159 | |
| 160 | struct jffs2_sum_marker |
| 161 | { |
| 162 | jint32_t offset; /* offset of the summary node in the jeb */ |
| 163 | jint32_t magic; /* == JFFS2_SUM_MAGIC */ |
| 164 | }; |
| 165 | |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 166 | #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker)) |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 167 | |
| 168 | #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */ |
| 169 | |
| 170 | #define jffs2_sum_active() (1) |
| 171 | int jffs2_sum_init(struct jffs2_sb_info *c); |
| 172 | void jffs2_sum_exit(struct jffs2_sb_info *c); |
| 173 | void jffs2_sum_disable_collecting(struct jffs2_summary *s); |
| 174 | int jffs2_sum_is_disabled(struct jffs2_summary *s); |
| 175 | void jffs2_sum_reset_collected(struct jffs2_summary *s); |
| 176 | void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s); |
| 177 | int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs, |
| 178 | unsigned long count, uint32_t to); |
| 179 | int jffs2_sum_write_sumnode(struct jffs2_sb_info *c); |
| 180 | int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size); |
| 181 | int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs); |
| 182 | int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs); |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 183 | int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs); |
| 184 | int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs); |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 185 | int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, |
David Woodhouse | 9641b78 | 2006-05-20 16:13:34 +0100 | [diff] [blame] | 186 | struct jffs2_raw_summary *summary, uint32_t sumlen, |
| 187 | uint32_t *pseudo_random); |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 188 | |
| 189 | #else /* SUMMARY DISABLED */ |
| 190 | |
| 191 | #define jffs2_sum_active() (0) |
| 192 | #define jffs2_sum_init(a) (0) |
| 193 | #define jffs2_sum_exit(a) |
| 194 | #define jffs2_sum_disable_collecting(a) |
| 195 | #define jffs2_sum_is_disabled(a) (0) |
| 196 | #define jffs2_sum_reset_collected(a) |
| 197 | #define jffs2_sum_add_kvec(a,b,c,d) (0) |
| 198 | #define jffs2_sum_move_collected(a,b) |
| 199 | #define jffs2_sum_write_sumnode(a) (0) |
| 200 | #define jffs2_sum_add_padding_mem(a,b) |
| 201 | #define jffs2_sum_add_inode_mem(a,b,c) |
| 202 | #define jffs2_sum_add_dirent_mem(a,b,c) |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 203 | #define jffs2_sum_add_xattr_mem(a,b,c) |
| 204 | #define jffs2_sum_add_xref_mem(a,b,c) |
David Woodhouse | 06c6764 | 2006-05-22 11:27:14 +0100 | [diff] [blame] | 205 | #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0) |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 206 | |
| 207 | #endif /* CONFIG_JFFS2_SUMMARY */ |
| 208 | |
| 209 | #endif /* JFFS2_SUMMARY_H */ |