18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * JFFS2 -- Journalling Flash File System, Version 2. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>, 58c2ecf20Sopenharmony_ci * Zoltan Sogor <weth@inf.u-szeged.hu>, 68c2ecf20Sopenharmony_ci * Patrik Kluba <pajko@halom.u-szeged.hu>, 78c2ecf20Sopenharmony_ci * University of Szeged, Hungary 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * For licensing information, see the file 'LICENCE' in this directory. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef JFFS2_SUMMARY_H 148c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_H 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Limit summary size to 64KiB so that we can kmalloc it. If the summary 178c2ecf20Sopenharmony_ci is larger than that, we have to just ditch it and avoid using summary 188c2ecf20Sopenharmony_ci for the eraseblock in question... and it probably doesn't hurt us much 198c2ecf20Sopenharmony_ci anyway. */ 208c2ecf20Sopenharmony_ci#define MAX_SUMMARY_SIZE 65536 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <linux/uio.h> 238c2ecf20Sopenharmony_ci#include <linux/jffs2.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define BLK_STATE_ALLFF 0 268c2ecf20Sopenharmony_ci#define BLK_STATE_CLEAN 1 278c2ecf20Sopenharmony_ci#define BLK_STATE_PARTDIRTY 2 288c2ecf20Sopenharmony_ci#define BLK_STATE_CLEANMARKER 3 298c2ecf20Sopenharmony_ci#define BLK_STATE_ALLDIRTY 4 308c2ecf20Sopenharmony_ci#define BLK_STATE_BADBLOCK 5 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff 338c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash)) 348c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x)) 358c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash)) 368c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash)) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Summary structures used on flash */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct jffs2_sum_unknown_flash 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci jint16_t nodetype; /* node type */ 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct jffs2_sum_inode_flash 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci jint16_t nodetype; /* node type */ 488c2ecf20Sopenharmony_ci jint32_t inode; /* inode number */ 498c2ecf20Sopenharmony_ci jint32_t version; /* inode version */ 508c2ecf20Sopenharmony_ci jint32_t offset; /* offset on jeb */ 518c2ecf20Sopenharmony_ci jint32_t totlen; /* record length */ 528c2ecf20Sopenharmony_ci} __attribute__((packed)); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct jffs2_sum_dirent_flash 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ 578c2ecf20Sopenharmony_ci jint32_t totlen; /* record length */ 588c2ecf20Sopenharmony_ci jint32_t offset; /* offset on jeb */ 598c2ecf20Sopenharmony_ci jint32_t pino; /* parent inode */ 608c2ecf20Sopenharmony_ci jint32_t version; /* dirent version */ 618c2ecf20Sopenharmony_ci jint32_t ino; /* == zero for unlink */ 628c2ecf20Sopenharmony_ci uint8_t nsize; /* dirent name size */ 638c2ecf20Sopenharmony_ci uint8_t type; /* dirent type */ 648c2ecf20Sopenharmony_ci uint8_t name[]; /* dirent name */ 658c2ecf20Sopenharmony_ci} __attribute__((packed)); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistruct jffs2_sum_xattr_flash 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci jint16_t nodetype; /* == JFFS2_NODETYPE_XATR */ 708c2ecf20Sopenharmony_ci jint32_t xid; /* xattr identifier */ 718c2ecf20Sopenharmony_ci jint32_t version; /* version number */ 728c2ecf20Sopenharmony_ci jint32_t offset; /* offset on jeb */ 738c2ecf20Sopenharmony_ci jint32_t totlen; /* node length */ 748c2ecf20Sopenharmony_ci} __attribute__((packed)); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistruct jffs2_sum_xref_flash 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci jint16_t nodetype; /* == JFFS2_NODETYPE_XREF */ 798c2ecf20Sopenharmony_ci jint32_t offset; /* offset on jeb */ 808c2ecf20Sopenharmony_ci} __attribute__((packed)); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ciunion jffs2_sum_flash 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci struct jffs2_sum_unknown_flash u; 858c2ecf20Sopenharmony_ci struct jffs2_sum_inode_flash i; 868c2ecf20Sopenharmony_ci struct jffs2_sum_dirent_flash d; 878c2ecf20Sopenharmony_ci struct jffs2_sum_xattr_flash x; 888c2ecf20Sopenharmony_ci struct jffs2_sum_xref_flash r; 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* Summary structures used in the memory */ 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct jffs2_sum_unknown_mem 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci union jffs2_sum_mem *next; 968c2ecf20Sopenharmony_ci jint16_t nodetype; /* node type */ 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct jffs2_sum_inode_mem 1008c2ecf20Sopenharmony_ci{ 1018c2ecf20Sopenharmony_ci union jffs2_sum_mem *next; 1028c2ecf20Sopenharmony_ci jint16_t nodetype; /* node type */ 1038c2ecf20Sopenharmony_ci jint32_t inode; /* inode number */ 1048c2ecf20Sopenharmony_ci jint32_t version; /* inode version */ 1058c2ecf20Sopenharmony_ci jint32_t offset; /* offset on jeb */ 1068c2ecf20Sopenharmony_ci jint32_t totlen; /* record length */ 1078c2ecf20Sopenharmony_ci} __attribute__((packed)); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistruct jffs2_sum_dirent_mem 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci union jffs2_sum_mem *next; 1128c2ecf20Sopenharmony_ci jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */ 1138c2ecf20Sopenharmony_ci jint32_t totlen; /* record length */ 1148c2ecf20Sopenharmony_ci jint32_t offset; /* ofset on jeb */ 1158c2ecf20Sopenharmony_ci jint32_t pino; /* parent inode */ 1168c2ecf20Sopenharmony_ci jint32_t version; /* dirent version */ 1178c2ecf20Sopenharmony_ci jint32_t ino; /* == zero for unlink */ 1188c2ecf20Sopenharmony_ci uint8_t nsize; /* dirent name size */ 1198c2ecf20Sopenharmony_ci uint8_t type; /* dirent type */ 1208c2ecf20Sopenharmony_ci uint8_t name[]; /* dirent name */ 1218c2ecf20Sopenharmony_ci} __attribute__((packed)); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct jffs2_sum_xattr_mem 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci union jffs2_sum_mem *next; 1268c2ecf20Sopenharmony_ci jint16_t nodetype; 1278c2ecf20Sopenharmony_ci jint32_t xid; 1288c2ecf20Sopenharmony_ci jint32_t version; 1298c2ecf20Sopenharmony_ci jint32_t offset; 1308c2ecf20Sopenharmony_ci jint32_t totlen; 1318c2ecf20Sopenharmony_ci} __attribute__((packed)); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistruct jffs2_sum_xref_mem 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci union jffs2_sum_mem *next; 1368c2ecf20Sopenharmony_ci jint16_t nodetype; 1378c2ecf20Sopenharmony_ci jint32_t offset; 1388c2ecf20Sopenharmony_ci} __attribute__((packed)); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciunion jffs2_sum_mem 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci struct jffs2_sum_unknown_mem u; 1438c2ecf20Sopenharmony_ci struct jffs2_sum_inode_mem i; 1448c2ecf20Sopenharmony_ci struct jffs2_sum_dirent_mem d; 1458c2ecf20Sopenharmony_ci struct jffs2_sum_xattr_mem x; 1468c2ecf20Sopenharmony_ci struct jffs2_sum_xref_mem r; 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Summary related information stored in superblock */ 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistruct jffs2_summary 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci uint32_t sum_size; /* collected summary information for nextblock */ 1548c2ecf20Sopenharmony_ci uint32_t sum_num; 1558c2ecf20Sopenharmony_ci uint32_t sum_padded; 1568c2ecf20Sopenharmony_ci union jffs2_sum_mem *sum_list_head; 1578c2ecf20Sopenharmony_ci union jffs2_sum_mem *sum_list_tail; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci jint32_t *sum_buf; /* buffer for writing out summary */ 1608c2ecf20Sopenharmony_ci}; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci/* Summary marker is stored at the end of every sumarized erase block */ 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_cistruct jffs2_sum_marker 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci jint32_t offset; /* offset of the summary node in the jeb */ 1678c2ecf20Sopenharmony_ci jint32_t magic; /* == JFFS2_SUM_MAGIC */ 1688c2ecf20Sopenharmony_ci}; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker)) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */ 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#define jffs2_sum_active() (1) 1758c2ecf20Sopenharmony_ciint jffs2_sum_init(struct jffs2_sb_info *c); 1768c2ecf20Sopenharmony_civoid jffs2_sum_exit(struct jffs2_sb_info *c); 1778c2ecf20Sopenharmony_civoid jffs2_sum_disable_collecting(struct jffs2_summary *s); 1788c2ecf20Sopenharmony_ciint jffs2_sum_is_disabled(struct jffs2_summary *s); 1798c2ecf20Sopenharmony_civoid jffs2_sum_reset_collected(struct jffs2_summary *s); 1808c2ecf20Sopenharmony_civoid jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s); 1818c2ecf20Sopenharmony_ciint jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs, 1828c2ecf20Sopenharmony_ci unsigned long count, uint32_t to); 1838c2ecf20Sopenharmony_ciint jffs2_sum_write_sumnode(struct jffs2_sb_info *c); 1848c2ecf20Sopenharmony_ciint jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size); 1858c2ecf20Sopenharmony_ciint jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs); 1868c2ecf20Sopenharmony_ciint jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs); 1878c2ecf20Sopenharmony_ciint jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs); 1888c2ecf20Sopenharmony_ciint jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs); 1898c2ecf20Sopenharmony_ciint jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 1908c2ecf20Sopenharmony_ci struct jffs2_raw_summary *summary, uint32_t sumlen, 1918c2ecf20Sopenharmony_ci uint32_t *pseudo_random); 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#else /* SUMMARY DISABLED */ 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#define jffs2_sum_active() (0) 1968c2ecf20Sopenharmony_ci#define jffs2_sum_init(a) (0) 1978c2ecf20Sopenharmony_ci#define jffs2_sum_exit(a) 1988c2ecf20Sopenharmony_ci#define jffs2_sum_disable_collecting(a) 1998c2ecf20Sopenharmony_ci#define jffs2_sum_is_disabled(a) (0) 2008c2ecf20Sopenharmony_ci#define jffs2_sum_reset_collected(a) 2018c2ecf20Sopenharmony_ci#define jffs2_sum_add_kvec(a,b,c,d) (0) 2028c2ecf20Sopenharmony_ci#define jffs2_sum_move_collected(a,b) 2038c2ecf20Sopenharmony_ci#define jffs2_sum_write_sumnode(a) (0) 2048c2ecf20Sopenharmony_ci#define jffs2_sum_add_padding_mem(a,b) 2058c2ecf20Sopenharmony_ci#define jffs2_sum_add_inode_mem(a,b,c) 2068c2ecf20Sopenharmony_ci#define jffs2_sum_add_dirent_mem(a,b,c) 2078c2ecf20Sopenharmony_ci#define jffs2_sum_add_xattr_mem(a,b,c) 2088c2ecf20Sopenharmony_ci#define jffs2_sum_add_xref_mem(a,b,c) 2098c2ecf20Sopenharmony_ci#define jffs2_sum_scan_sumnode(a,b,c,d,e) (0) 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#endif /* CONFIG_JFFS2_SUMMARY */ 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci#endif /* JFFS2_SUMMARY_H */ 214