Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * JFFS2 -- Journalling Flash File System, Version 2.
0003  *
0004  * Copyright © 2004  Ferenc Havasi <havasi@inf.u-szeged.hu>,
0005  *           Zoltan Sogor <weth@inf.u-szeged.hu>,
0006  *           Patrik Kluba <pajko@halom.u-szeged.hu>,
0007  *           University of Szeged, Hungary
0008  *
0009  * For licensing information, see the file 'LICENCE' in this directory.
0010  *
0011  */
0012 
0013 #ifndef JFFS2_SUMMARY_H
0014 #define JFFS2_SUMMARY_H
0015 
0016 /* Limit summary size to 64KiB so that we can kmalloc it. If the summary
0017    is larger than that, we have to just ditch it and avoid using summary
0018    for the eraseblock in question... and it probably doesn't hurt us much
0019    anyway. */
0020 #define MAX_SUMMARY_SIZE 65536
0021 
0022 #include <linux/uio.h>
0023 #include <linux/jffs2.h>
0024 
0025 #define BLK_STATE_ALLFF     0
0026 #define BLK_STATE_CLEAN     1
0027 #define BLK_STATE_PARTDIRTY 2
0028 #define BLK_STATE_CLEANMARKER   3
0029 #define BLK_STATE_ALLDIRTY  4
0030 #define BLK_STATE_BADBLOCK  5
0031 
0032 #define JFFS2_SUMMARY_NOSUM_SIZE 0xffffffff
0033 #define JFFS2_SUMMARY_INODE_SIZE (sizeof(struct jffs2_sum_inode_flash))
0034 #define JFFS2_SUMMARY_DIRENT_SIZE(x) (sizeof(struct jffs2_sum_dirent_flash) + (x))
0035 #define JFFS2_SUMMARY_XATTR_SIZE (sizeof(struct jffs2_sum_xattr_flash))
0036 #define JFFS2_SUMMARY_XREF_SIZE (sizeof(struct jffs2_sum_xref_flash))
0037 
0038 /* Summary structures used on flash */
0039 
0040 struct jffs2_sum_unknown_flash
0041 {
0042     jint16_t nodetype;  /* node type */
0043 };
0044 
0045 struct jffs2_sum_inode_flash
0046 {
0047     jint16_t nodetype;  /* node type */
0048     jint32_t inode;     /* inode number */
0049     jint32_t version;   /* inode version */
0050     jint32_t offset;    /* offset on jeb */
0051     jint32_t totlen;    /* record length */
0052 } __attribute__((packed));
0053 
0054 struct jffs2_sum_dirent_flash
0055 {
0056     jint16_t nodetype;  /* == JFFS_NODETYPE_DIRENT */
0057     jint32_t totlen;    /* record length */
0058     jint32_t offset;    /* offset on jeb */
0059     jint32_t pino;      /* parent inode */
0060     jint32_t version;   /* dirent version */
0061     jint32_t ino;       /* == zero for unlink */
0062     uint8_t nsize;      /* dirent name size */
0063     uint8_t type;       /* dirent type */
0064     uint8_t name[]; /* dirent name */
0065 } __attribute__((packed));
0066 
0067 struct jffs2_sum_xattr_flash
0068 {
0069     jint16_t nodetype;  /* == JFFS2_NODETYPE_XATR */
0070     jint32_t xid;       /* xattr identifier */
0071     jint32_t version;   /* version number */
0072     jint32_t offset;    /* offset on jeb */
0073     jint32_t totlen;    /* node length */
0074 } __attribute__((packed));
0075 
0076 struct jffs2_sum_xref_flash
0077 {
0078     jint16_t nodetype;  /* == JFFS2_NODETYPE_XREF */
0079     jint32_t offset;    /* offset on jeb */
0080 } __attribute__((packed));
0081 
0082 union jffs2_sum_flash
0083 {
0084     struct jffs2_sum_unknown_flash u;
0085     struct jffs2_sum_inode_flash i;
0086     struct jffs2_sum_dirent_flash d;
0087     struct jffs2_sum_xattr_flash x;
0088     struct jffs2_sum_xref_flash r;
0089 };
0090 
0091 /* Summary structures used in the memory */
0092 
0093 struct jffs2_sum_unknown_mem
0094 {
0095     union jffs2_sum_mem *next;
0096     jint16_t nodetype;  /* node type */
0097 };
0098 
0099 struct jffs2_sum_inode_mem
0100 {
0101     union jffs2_sum_mem *next;
0102     jint16_t nodetype;  /* node type */
0103     jint32_t inode;     /* inode number */
0104     jint32_t version;   /* inode version */
0105     jint32_t offset;    /* offset on jeb */
0106     jint32_t totlen;    /* record length */
0107 } __attribute__((packed));
0108 
0109 struct jffs2_sum_dirent_mem
0110 {
0111     union jffs2_sum_mem *next;
0112     jint16_t nodetype;  /* == JFFS_NODETYPE_DIRENT */
0113     jint32_t totlen;    /* record length */
0114     jint32_t offset;    /* ofset on jeb */
0115     jint32_t pino;      /* parent inode */
0116     jint32_t version;   /* dirent version */
0117     jint32_t ino;       /* == zero for unlink */
0118     uint8_t nsize;      /* dirent name size */
0119     uint8_t type;       /* dirent type */
0120     uint8_t name[]; /* dirent name */
0121 } __attribute__((packed));
0122 
0123 struct jffs2_sum_xattr_mem
0124 {
0125     union jffs2_sum_mem *next;
0126     jint16_t nodetype;
0127     jint32_t xid;
0128     jint32_t version;
0129     jint32_t offset;
0130     jint32_t totlen;
0131 } __attribute__((packed));
0132 
0133 struct jffs2_sum_xref_mem
0134 {
0135     union jffs2_sum_mem *next;
0136     jint16_t nodetype;
0137     jint32_t offset;
0138 } __attribute__((packed));
0139 
0140 union jffs2_sum_mem
0141 {
0142     struct jffs2_sum_unknown_mem u;
0143     struct jffs2_sum_inode_mem i;
0144     struct jffs2_sum_dirent_mem d;
0145     struct jffs2_sum_xattr_mem x;
0146     struct jffs2_sum_xref_mem r;
0147 };
0148 
0149 /* Summary related information stored in superblock */
0150 
0151 struct jffs2_summary
0152 {
0153     uint32_t sum_size;      /* collected summary information for nextblock */
0154     uint32_t sum_num;
0155     uint32_t sum_padded;
0156     union jffs2_sum_mem *sum_list_head;
0157     union jffs2_sum_mem *sum_list_tail;
0158 
0159     jint32_t *sum_buf;  /* buffer for writing out summary */
0160 };
0161 
0162 /* Summary marker is stored at the end of every sumarized erase block */
0163 
0164 struct jffs2_sum_marker
0165 {
0166     jint32_t offset;    /* offset of the summary node in the jeb */
0167     jint32_t magic;     /* == JFFS2_SUM_MAGIC */
0168 };
0169 
0170 #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
0171 
0172 #ifdef CONFIG_JFFS2_SUMMARY /* SUMMARY SUPPORT ENABLED */
0173 
0174 #define jffs2_sum_active() (1)
0175 int jffs2_sum_init(struct jffs2_sb_info *c);
0176 void jffs2_sum_exit(struct jffs2_sb_info *c);
0177 void jffs2_sum_disable_collecting(struct jffs2_summary *s);
0178 int jffs2_sum_is_disabled(struct jffs2_summary *s);
0179 void jffs2_sum_reset_collected(struct jffs2_summary *s);
0180 void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
0181 int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
0182             unsigned long count,  uint32_t to);
0183 int jffs2_sum_write_sumnode(struct jffs2_sb_info *c);
0184 int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size);
0185 int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri, uint32_t ofs);
0186 int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd, uint32_t ofs);
0187 int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs);
0188 int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs);
0189 int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
0190                struct jffs2_raw_summary *summary, uint32_t sumlen,
0191                uint32_t *pseudo_random);
0192 
0193 #else               /* SUMMARY DISABLED */
0194 
0195 #define jffs2_sum_active() (0)
0196 #define jffs2_sum_init(a) (0)
0197 #define jffs2_sum_exit(a) do { } while (0)
0198 #define jffs2_sum_disable_collecting(a)
0199 #define jffs2_sum_is_disabled(a) (0)
0200 #define jffs2_sum_reset_collected(a) do { } while (0)
0201 #define jffs2_sum_add_kvec(a,b,c,d) (0)
0202 #define jffs2_sum_move_collected(a,b) do { } while (0)
0203 #define jffs2_sum_write_sumnode(a) (0)
0204 #define jffs2_sum_add_padding_mem(a,b) do { } while (0)
0205 #define jffs2_sum_add_inode_mem(a,b,c) do { } while (0)
0206 #define jffs2_sum_add_dirent_mem(a,b,c) do { } while (0)
0207 #define jffs2_sum_add_xattr_mem(a,b,c) do { } while (0)
0208 #define jffs2_sum_add_xref_mem(a,b,c) do { } while (0)
0209 #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
0210 
0211 #endif /* CONFIG_JFFS2_SUMMARY */
0212 
0213 #endif /* JFFS2_SUMMARY_H */