cleanup mtd, implement jffs2write - one step closer to config preserving system upgrades
[openwrt/svn-archive/archive.git] / package / mtd / src / jffs2.h
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in the
9 * jffs2 directory.
10 *
11 * $Id: jffs2.h,v 1.38 2005/09/26 11:37:23 havasi Exp $
12 *
13 */
14
15 #ifndef __LINUX_JFFS2_H__
16 #define __LINUX_JFFS2_H__
17
18 #define JFFS2_SUPER_MAGIC 0x72b6
19
20 /* You must include something which defines the C99 uintXX_t types.
21 We don't do it from here because this file is used in too many
22 different environments. */
23
24 /* Values we may expect to find in the 'magic' field */
25 #define JFFS2_OLD_MAGIC_BITMASK 0x1984
26 #define JFFS2_MAGIC_BITMASK 0x1985
27 #define KSAMTIB_CIGAM_2SFFJ 0x8519 /* For detecting wrong-endian fs */
28 #define JFFS2_EMPTY_BITMASK 0xffff
29 #define JFFS2_DIRTY_BITMASK 0x0000
30
31 /* Summary node MAGIC marker */
32 #define JFFS2_SUM_MAGIC 0x02851885
33
34 /* We only allow a single char for length, and 0xFF is empty flash so
35 we don't want it confused with a real length. Hence max 254.
36 */
37 #define JFFS2_MAX_NAME_LEN 254
38
39 /* How small can we sensibly write nodes? */
40 #define JFFS2_MIN_DATA_LEN 128
41
42 #define JFFS2_COMPR_NONE 0x00
43 #define JFFS2_COMPR_ZERO 0x01
44 #define JFFS2_COMPR_RTIME 0x02
45 #define JFFS2_COMPR_RUBINMIPS 0x03
46 #define JFFS2_COMPR_COPY 0x04
47 #define JFFS2_COMPR_DYNRUBIN 0x05
48 #define JFFS2_COMPR_ZLIB 0x06
49 /* Compatibility flags. */
50 #define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
51 #define JFFS2_NODE_ACCURATE 0x2000
52 /* INCOMPAT: Fail to mount the filesystem */
53 #define JFFS2_FEATURE_INCOMPAT 0xc000
54 /* ROCOMPAT: Mount read-only */
55 #define JFFS2_FEATURE_ROCOMPAT 0x8000
56 /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
57 #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
58 /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
59 #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
60
61 #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
62 #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
63 #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
64 #define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
65
66 #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
67
68 #define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8)
69 #define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9)
70
71 /* XATTR Related */
72 #define JFFS2_XPREFIX_USER 1 /* for "user." */
73 #define JFFS2_XPREFIX_SECURITY 2 /* for "security." */
74 #define JFFS2_XPREFIX_ACL_ACCESS 3 /* for "system.posix_acl_access" */
75 #define JFFS2_XPREFIX_ACL_DEFAULT 4 /* for "system.posix_acl_default" */
76 #define JFFS2_XPREFIX_TRUSTED 5 /* for "trusted.*" */
77
78 #define JFFS2_ACL_VERSION 0x0001
79
80 // Maybe later...
81 //#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
82 //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
83
84
85 #define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at
86 mount time, don't wait for it to
87 happen later */
88 #define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific
89 compression type */
90
91
92 /* These can go once we've made sure we've caught all uses without
93 byteswapping */
94
95 typedef uint32_t jint32_t;
96
97 typedef uint32_t jmode_t;
98
99 typedef uint16_t jint16_t;
100
101 struct jffs2_unknown_node
102 {
103 /* All start like this */
104 jint16_t magic;
105 jint16_t nodetype;
106 jint32_t totlen; /* So we can skip over nodes we don't grok */
107 jint32_t hdr_crc;
108 };
109
110 struct jffs2_raw_dirent
111 {
112 jint16_t magic;
113 jint16_t nodetype; /* == JFFS2_NODETYPE_DIRENT */
114 jint32_t totlen;
115 jint32_t hdr_crc;
116 jint32_t pino;
117 jint32_t version;
118 jint32_t ino; /* == zero for unlink */
119 jint32_t mctime;
120 uint8_t nsize;
121 uint8_t type;
122 uint8_t unused[2];
123 jint32_t node_crc;
124 jint32_t name_crc;
125 uint8_t name[0];
126 };
127
128 /* The JFFS2 raw inode structure: Used for storage on physical media. */
129 /* The uid, gid, atime, mtime and ctime members could be longer, but
130 are left like this for space efficiency. If and when people decide
131 they really need them extended, it's simple enough to add support for
132 a new type of raw node.
133 */
134 struct jffs2_raw_inode
135 {
136 jint16_t magic; /* A constant magic number. */
137 jint16_t nodetype; /* == JFFS2_NODETYPE_INODE */
138 jint32_t totlen; /* Total length of this node (inc data, etc.) */
139 jint32_t hdr_crc;
140 jint32_t ino; /* Inode number. */
141 jint32_t version; /* Version number. */
142 jmode_t mode; /* The file's type or mode. */
143 jint16_t uid; /* The file's owner. */
144 jint16_t gid; /* The file's group. */
145 jint32_t isize; /* Total resultant size of this inode (used for truncations) */
146 jint32_t atime; /* Last access time. */
147 jint32_t mtime; /* Last modification time. */
148 jint32_t ctime; /* Change time. */
149 jint32_t offset; /* Where to begin to write. */
150 jint32_t csize; /* (Compressed) data size */
151 jint32_t dsize; /* Size of the node's data. (after decompression) */
152 uint8_t compr; /* Compression algorithm used */
153 uint8_t usercompr; /* Compression algorithm requested by the user */
154 jint16_t flags; /* See JFFS2_INO_FLAG_* */
155 jint32_t data_crc; /* CRC for the (compressed) data. */
156 jint32_t node_crc; /* CRC for the raw inode (excluding data) */
157 uint8_t data[0];
158 };
159
160 struct jffs2_raw_xattr {
161 jint16_t magic;
162 jint16_t nodetype; /* = JFFS2_NODETYPE_XATTR */
163 jint32_t totlen;
164 jint32_t hdr_crc;
165 jint32_t xid; /* XATTR identifier number */
166 jint32_t version;
167 uint8_t xprefix;
168 uint8_t name_len;
169 jint16_t value_len;
170 jint32_t data_crc;
171 jint32_t node_crc;
172 uint8_t data[0];
173 } __attribute__((packed));
174
175 struct jffs2_raw_xref
176 {
177 jint16_t magic;
178 jint16_t nodetype; /* = JFFS2_NODETYPE_XREF */
179 jint32_t totlen;
180 jint32_t hdr_crc;
181 jint32_t ino; /* inode number */
182 jint32_t xid; /* XATTR identifier number */
183 jint32_t xseqno; /* xref sequencial number */
184 jint32_t node_crc;
185 } __attribute__((packed));
186
187 struct jffs2_raw_summary
188 {
189 jint16_t magic;
190 jint16_t nodetype; /* = JFFS2_NODETYPE_SUMMARY */
191 jint32_t totlen;
192 jint32_t hdr_crc;
193 jint32_t sum_num; /* number of sum entries*/
194 jint32_t cln_mkr; /* clean marker size, 0 = no cleanmarker */
195 jint32_t padded; /* sum of the size of padding nodes */
196 jint32_t sum_crc; /* summary information crc */
197 jint32_t node_crc; /* node crc */
198 jint32_t sum[0]; /* inode summary info */
199 };
200
201 union jffs2_node_union
202 {
203 struct jffs2_raw_inode i;
204 struct jffs2_raw_dirent d;
205 struct jffs2_raw_xattr x;
206 struct jffs2_raw_xref r;
207 struct jffs2_raw_summary s;
208 struct jffs2_unknown_node u;
209 };
210
211 /* Data payload for device nodes. */
212 union jffs2_device_node {
213 jint16_t old;
214 jint32_t new;
215 };
216
217 #endif /* __LINUX_JFFS2_H__ */