1 |
27 |
unneback |
/*
|
2 |
|
|
* JFFS2 -- Journalling Flash File System, Version 2.
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 2001, 2002 Red Hat, Inc.
|
5 |
|
|
*
|
6 |
|
|
* Created by David Woodhouse <dwmw2@cambridge.redhat.com>
|
7 |
|
|
*
|
8 |
|
|
* For licensing information, see the file 'LICENCE' in the
|
9 |
|
|
* jffs2 directory.
|
10 |
|
|
*
|
11 |
|
|
* $Id: jffs2.h,v 1.1.1.1 2004-02-14 13:29:21 phoenix Exp $
|
12 |
|
|
*
|
13 |
|
|
*/
|
14 |
|
|
|
15 |
|
|
#ifndef __LINUX_JFFS2_H__
|
16 |
|
|
#define __LINUX_JFFS2_H__
|
17 |
|
|
|
18 |
|
|
/* You must include something which defines the C99 uintXX_t types.
|
19 |
|
|
We don't do it from here because this file is used in too many
|
20 |
|
|
different environments. */
|
21 |
|
|
|
22 |
|
|
#define JFFS2_SUPER_MAGIC 0x72b6
|
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 0x5981 /* For detecting wrong-endian fs */
|
28 |
|
|
#define JFFS2_EMPTY_BITMASK 0xffff
|
29 |
|
|
#define JFFS2_DIRTY_BITMASK 0x0000
|
30 |
|
|
|
31 |
|
|
/* We only allow a single char for length, and 0xFF is empty flash so
|
32 |
|
|
we don't want it confused with a real length. Hence max 254.
|
33 |
|
|
*/
|
34 |
|
|
#define JFFS2_MAX_NAME_LEN 254
|
35 |
|
|
|
36 |
|
|
/* How small can we sensibly write nodes? */
|
37 |
|
|
#define JFFS2_MIN_DATA_LEN 128
|
38 |
|
|
|
39 |
|
|
#define JFFS2_COMPR_NONE 0x00
|
40 |
|
|
#define JFFS2_COMPR_ZERO 0x01
|
41 |
|
|
#define JFFS2_COMPR_RTIME 0x02
|
42 |
|
|
#define JFFS2_COMPR_RUBINMIPS 0x03
|
43 |
|
|
#define JFFS2_COMPR_COPY 0x04
|
44 |
|
|
#define JFFS2_COMPR_DYNRUBIN 0x05
|
45 |
|
|
#define JFFS2_COMPR_ZLIB 0x06
|
46 |
|
|
/* Compatibility flags. */
|
47 |
|
|
#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
|
48 |
|
|
#define JFFS2_NODE_ACCURATE 0x2000
|
49 |
|
|
/* INCOMPAT: Fail to mount the filesystem */
|
50 |
|
|
#define JFFS2_FEATURE_INCOMPAT 0xc000
|
51 |
|
|
/* ROCOMPAT: Mount read-only */
|
52 |
|
|
#define JFFS2_FEATURE_ROCOMPAT 0x8000
|
53 |
|
|
/* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
|
54 |
|
|
#define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
|
55 |
|
|
/* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
|
56 |
|
|
#define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
|
57 |
|
|
|
58 |
|
|
#define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
|
59 |
|
|
#define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
|
60 |
|
|
#define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
|
61 |
|
|
#define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
|
62 |
|
|
|
63 |
|
|
// Maybe later...
|
64 |
|
|
//#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
|
65 |
|
|
//#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
#define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at
|
69 |
|
|
mount time, don't wait for it to
|
70 |
|
|
happen later */
|
71 |
|
|
#define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific
|
72 |
|
|
compression type */
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/* These can go once we've made sure we've caught all uses without
|
76 |
|
|
byteswapping */
|
77 |
|
|
|
78 |
|
|
typedef struct {
|
79 |
|
|
uint32_t v32;
|
80 |
|
|
} __attribute__((packed)) jint32_t;
|
81 |
|
|
|
82 |
|
|
typedef struct {
|
83 |
|
|
uint32_t m;
|
84 |
|
|
} __attribute__((packed)) jmode_t;
|
85 |
|
|
|
86 |
|
|
typedef struct {
|
87 |
|
|
uint16_t v16;
|
88 |
|
|
} __attribute__((packed)) jint16_t;
|
89 |
|
|
|
90 |
|
|
#define JFFS2_NATIVE_ENDIAN
|
91 |
|
|
|
92 |
|
|
/* Note we handle mode bits conversion from JFFS2 (i.e. Linux) to/from
|
93 |
|
|
whatever OS we're actually running on here too. */
|
94 |
|
|
|
95 |
|
|
#if defined(JFFS2_NATIVE_ENDIAN)
|
96 |
|
|
#define cpu_to_je16(x) ((jint16_t){x})
|
97 |
|
|
#define cpu_to_je32(x) ((jint32_t){x})
|
98 |
|
|
#define cpu_to_jemode(x) ((jmode_t){os_to_jffs2_mode(x)})
|
99 |
|
|
|
100 |
|
|
#define je16_to_cpu(x) ((x).v16)
|
101 |
|
|
#define je32_to_cpu(x) ((x).v32)
|
102 |
|
|
#define jemode_to_cpu(x) (jffs2_to_os_mode((x).m))
|
103 |
|
|
#elif defined(JFFS2_BIG_ENDIAN)
|
104 |
|
|
#define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})
|
105 |
|
|
#define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})
|
106 |
|
|
#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))})
|
107 |
|
|
|
108 |
|
|
#define je16_to_cpu(x) (be16_to_cpu(x.v16))
|
109 |
|
|
#define je32_to_cpu(x) (be32_to_cpu(x.v32))
|
110 |
|
|
#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m)))
|
111 |
|
|
#elif defined(JFFS2_LITTLE_ENDIAN)
|
112 |
|
|
#define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})
|
113 |
|
|
#define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})
|
114 |
|
|
#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))})
|
115 |
|
|
|
116 |
|
|
#define je16_to_cpu(x) (le16_to_cpu(x.v16))
|
117 |
|
|
#define je32_to_cpu(x) (le32_to_cpu(x.v32))
|
118 |
|
|
#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))
|
119 |
|
|
#else
|
120 |
|
|
#error wibble
|
121 |
|
|
#endif
|
122 |
|
|
|
123 |
|
|
struct jffs2_unknown_node
|
124 |
|
|
{
|
125 |
|
|
/* All start like this */
|
126 |
|
|
jint16_t magic;
|
127 |
|
|
jint16_t nodetype;
|
128 |
|
|
jint32_t totlen; /* So we can skip over nodes we don't grok */
|
129 |
|
|
jint32_t hdr_crc;
|
130 |
|
|
} __attribute__((packed));
|
131 |
|
|
|
132 |
|
|
struct jffs2_raw_dirent
|
133 |
|
|
{
|
134 |
|
|
jint16_t magic;
|
135 |
|
|
jint16_t nodetype; /* == JFFS_NODETYPE_DIRENT */
|
136 |
|
|
jint32_t totlen;
|
137 |
|
|
jint32_t hdr_crc;
|
138 |
|
|
jint32_t pino;
|
139 |
|
|
jint32_t version;
|
140 |
|
|
jint32_t ino; /* == zero for unlink */
|
141 |
|
|
jint32_t mctime;
|
142 |
|
|
uint8_t nsize;
|
143 |
|
|
uint8_t type;
|
144 |
|
|
uint8_t unused[2];
|
145 |
|
|
jint32_t node_crc;
|
146 |
|
|
jint32_t name_crc;
|
147 |
|
|
uint8_t name[0];
|
148 |
|
|
} __attribute__((packed));
|
149 |
|
|
|
150 |
|
|
/* The JFFS2 raw inode structure: Used for storage on physical media. */
|
151 |
|
|
/* The uid, gid, atime, mtime and ctime members could be longer, but
|
152 |
|
|
are left like this for space efficiency. If and when people decide
|
153 |
|
|
they really need them extended, it's simple enough to add support for
|
154 |
|
|
a new type of raw node.
|
155 |
|
|
*/
|
156 |
|
|
struct jffs2_raw_inode
|
157 |
|
|
{
|
158 |
|
|
jint16_t magic; /* A constant magic number. */
|
159 |
|
|
jint16_t nodetype; /* == JFFS_NODETYPE_INODE */
|
160 |
|
|
jint32_t totlen; /* Total length of this node (inc data, etc.) */
|
161 |
|
|
jint32_t hdr_crc;
|
162 |
|
|
jint32_t ino; /* Inode number. */
|
163 |
|
|
jint32_t version; /* Version number. */
|
164 |
|
|
jmode_t mode; /* The file's type or mode. */
|
165 |
|
|
jint16_t uid; /* The file's owner. */
|
166 |
|
|
jint16_t gid; /* The file's group. */
|
167 |
|
|
jint32_t isize; /* Total resultant size of this inode (used for truncations) */
|
168 |
|
|
jint32_t atime; /* Last access time. */
|
169 |
|
|
jint32_t mtime; /* Last modification time. */
|
170 |
|
|
jint32_t ctime; /* Change time. */
|
171 |
|
|
jint32_t offset; /* Where to begin to write. */
|
172 |
|
|
jint32_t csize; /* (Compressed) data size */
|
173 |
|
|
jint32_t dsize; /* Size of the node's data. (after decompression) */
|
174 |
|
|
uint8_t compr; /* Compression algorithm used */
|
175 |
|
|
uint8_t usercompr; /* Compression algorithm requested by the user */
|
176 |
|
|
jint16_t flags; /* See JFFS2_INO_FLAG_* */
|
177 |
|
|
jint32_t data_crc; /* CRC for the (compressed) data. */
|
178 |
|
|
jint32_t node_crc; /* CRC for the raw inode (excluding data) */
|
179 |
|
|
uint8_t data[0];
|
180 |
|
|
} __attribute__((packed));
|
181 |
|
|
|
182 |
|
|
union jffs2_node_union {
|
183 |
|
|
struct jffs2_raw_inode i;
|
184 |
|
|
struct jffs2_raw_dirent d;
|
185 |
|
|
struct jffs2_unknown_node u;
|
186 |
|
|
};
|
187 |
|
|
|
188 |
|
|
#endif /* __LINUX_JFFS2_H__ */
|