blob: cf792bb3c72655beafc28d29c72f25f14bf96a4b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Thomas Gleixner182ec4e2005-11-07 11:16:07 +00008 * For licensing information, see the file 'LICENCE' in the
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * jffs2 directory.
10 *
Ferenc Havasi2bc97642005-09-26 12:37:25 +010011 * $Id: jffs2.h,v 1.38 2005/09/26 11:37:23 havasi Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 0x8519 /* For detecting wrong-endian fs */
28#define JFFS2_EMPTY_BITMASK 0xffff
29#define JFFS2_DIRTY_BITMASK 0x0000
30
Ferenc Havasie631ddb2005-09-07 09:35:26 +010031/* Summary node MAGIC marker */
32#define JFFS2_SUM_MAGIC 0x02851885
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070049/* 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
Ferenc Havasie631ddb2005-09-07 09:35:26 +010066#define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068// Maybe later...
69//#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
70//#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
71
72
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000073#define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at
74 mount time, don't wait for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 happen later */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000076#define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 compression type */
78
79
80/* These can go once we've made sure we've caught all uses without
81 byteswapping */
82
83typedef struct {
84 uint32_t v32;
85} __attribute__((packed)) jint32_t;
86
87typedef struct {
88 uint32_t m;
89} __attribute__((packed)) jmode_t;
90
91typedef struct {
92 uint16_t v16;
93} __attribute__((packed)) jint16_t;
94
95struct jffs2_unknown_node
96{
97 /* All start like this */
98 jint16_t magic;
99 jint16_t nodetype;
100 jint32_t totlen; /* So we can skip over nodes we don't grok */
101 jint32_t hdr_crc;
102} __attribute__((packed));
103
104struct jffs2_raw_dirent
105{
106 jint16_t magic;
Artem B. Bityutskiyf302cd02005-07-24 16:29:59 +0100107 jint16_t nodetype; /* == JFFS2_NODETYPE_DIRENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 jint32_t totlen;
109 jint32_t hdr_crc;
110 jint32_t pino;
111 jint32_t version;
112 jint32_t ino; /* == zero for unlink */
113 jint32_t mctime;
114 uint8_t nsize;
115 uint8_t type;
116 uint8_t unused[2];
117 jint32_t node_crc;
118 jint32_t name_crc;
119 uint8_t name[0];
120} __attribute__((packed));
121
122/* The JFFS2 raw inode structure: Used for storage on physical media. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000123/* The uid, gid, atime, mtime and ctime members could be longer, but
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 are left like this for space efficiency. If and when people decide
125 they really need them extended, it's simple enough to add support for
126 a new type of raw node.
127*/
128struct jffs2_raw_inode
129{
130 jint16_t magic; /* A constant magic number. */
Artem B. Bityutskiyf302cd02005-07-24 16:29:59 +0100131 jint16_t nodetype; /* == JFFS2_NODETYPE_INODE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 jint32_t totlen; /* Total length of this node (inc data, etc.) */
133 jint32_t hdr_crc;
134 jint32_t ino; /* Inode number. */
135 jint32_t version; /* Version number. */
136 jmode_t mode; /* The file's type or mode. */
137 jint16_t uid; /* The file's owner. */
138 jint16_t gid; /* The file's group. */
139 jint32_t isize; /* Total resultant size of this inode (used for truncations) */
140 jint32_t atime; /* Last access time. */
141 jint32_t mtime; /* Last modification time. */
142 jint32_t ctime; /* Change time. */
143 jint32_t offset; /* Where to begin to write. */
144 jint32_t csize; /* (Compressed) data size */
145 jint32_t dsize; /* Size of the node's data. (after decompression) */
146 uint8_t compr; /* Compression algorithm used */
147 uint8_t usercompr; /* Compression algorithm requested by the user */
148 jint16_t flags; /* See JFFS2_INO_FLAG_* */
149 jint32_t data_crc; /* CRC for the (compressed) data. */
150 jint32_t node_crc; /* CRC for the raw inode (excluding data) */
151 uint8_t data[0];
152} __attribute__((packed));
153
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100154struct jffs2_raw_summary
155{
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100156 jint16_t magic;
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100157 jint16_t nodetype; /* = JFFS2_NODETYPE_SUMMARY */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100158 jint32_t totlen;
159 jint32_t hdr_crc;
160 jint32_t sum_num; /* number of sum entries*/
161 jint32_t cln_mkr; /* clean marker size, 0 = no cleanmarker */
162 jint32_t padded; /* sum of the size of padding nodes */
163 jint32_t sum_crc; /* summary information crc */
164 jint32_t node_crc; /* node crc */
165 jint32_t sum[0]; /* inode summary info */
166} __attribute__((packed));
167
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000168union jffs2_node_union
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100169{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct jffs2_raw_inode i;
171 struct jffs2_raw_dirent d;
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100172 struct jffs2_raw_summary s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 struct jffs2_unknown_node u;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
176#endif /* __LINUX_JFFS2_H__ */