blob: 2b32d638147d5f4bdc3bf77ae8f46e4b2390bfcf [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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
12#ifndef __LINUX_JFFS2_H__
13#define __LINUX_JFFS2_H__
14
Arnd Bergmannccef7ab2009-02-26 00:51:41 +010015#include <linux/types.h>
Jeff Garzike18fa702006-09-24 11:13:19 -040016#include <linux/magic.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/* Values we may expect to find in the 'magic' field */
23#define JFFS2_OLD_MAGIC_BITMASK 0x1984
24#define JFFS2_MAGIC_BITMASK 0x1985
25#define KSAMTIB_CIGAM_2SFFJ 0x8519 /* For detecting wrong-endian fs */
26#define JFFS2_EMPTY_BITMASK 0xffff
27#define JFFS2_DIRTY_BITMASK 0x0000
28
Ferenc Havasie631ddb2005-09-07 09:35:26 +010029/* Summary node MAGIC marker */
30#define JFFS2_SUM_MAGIC 0x02851885
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/* We only allow a single char for length, and 0xFF is empty flash so
33 we don't want it confused with a real length. Hence max 254.
34*/
35#define JFFS2_MAX_NAME_LEN 254
36
37/* How small can we sensibly write nodes? */
38#define JFFS2_MIN_DATA_LEN 128
39
40#define JFFS2_COMPR_NONE 0x00
41#define JFFS2_COMPR_ZERO 0x01
42#define JFFS2_COMPR_RTIME 0x02
43#define JFFS2_COMPR_RUBINMIPS 0x03
44#define JFFS2_COMPR_COPY 0x04
45#define JFFS2_COMPR_DYNRUBIN 0x05
46#define JFFS2_COMPR_ZLIB 0x06
Richard Purdiec799aca2007-07-10 10:28:36 +010047#define JFFS2_COMPR_LZO 0x07
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* Compatibility flags. */
49#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
50#define JFFS2_NODE_ACCURATE 0x2000
51/* INCOMPAT: Fail to mount the filesystem */
52#define JFFS2_FEATURE_INCOMPAT 0xc000
53/* ROCOMPAT: Mount read-only */
54#define JFFS2_FEATURE_ROCOMPAT 0x8000
55/* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
56#define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
57/* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
58#define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
59
60#define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
61#define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
62#define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
63#define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
64
Ferenc Havasie631ddb2005-09-07 09:35:26 +010065#define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
66
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090067#define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8)
68#define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9)
69
70/* XATTR Related */
71#define JFFS2_XPREFIX_USER 1 /* for "user." */
72#define JFFS2_XPREFIX_SECURITY 2 /* for "security." */
73#define JFFS2_XPREFIX_ACL_ACCESS 3 /* for "system.posix_acl_access" */
74#define JFFS2_XPREFIX_ACL_DEFAULT 4 /* for "system.posix_acl_default" */
75#define JFFS2_XPREFIX_TRUSTED 5 /* for "trusted.*" */
76
77#define JFFS2_ACL_VERSION 0x0001
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079// Maybe later...
80//#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
81//#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
82
83
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000084#define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at
85 mount time, don't wait for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 happen later */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000087#define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 compression type */
89
90
91/* These can go once we've made sure we've caught all uses without
92 byteswapping */
93
94typedef struct {
Arnd Bergmannccef7ab2009-02-26 00:51:41 +010095 __u32 v32;
David Woodhouseba9627b2006-05-16 23:03:08 +010096} __attribute__((packed)) jint32_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98typedef struct {
Arnd Bergmannccef7ab2009-02-26 00:51:41 +010099 __u32 m;
David Woodhouseba9627b2006-05-16 23:03:08 +0100100} __attribute__((packed)) jmode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102typedef struct {
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100103 __u16 v16;
David Woodhouseba9627b2006-05-16 23:03:08 +0100104} __attribute__((packed)) jint16_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106struct jffs2_unknown_node
107{
108 /* All start like this */
109 jint16_t magic;
110 jint16_t nodetype;
111 jint32_t totlen; /* So we can skip over nodes we don't grok */
112 jint32_t hdr_crc;
David Woodhouse3e68fbb2006-05-15 00:49:43 +0100113};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115struct jffs2_raw_dirent
116{
117 jint16_t magic;
Artem B. Bityutskiyf302cd02005-07-24 16:29:59 +0100118 jint16_t nodetype; /* == JFFS2_NODETYPE_DIRENT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 jint32_t totlen;
120 jint32_t hdr_crc;
121 jint32_t pino;
122 jint32_t version;
123 jint32_t ino; /* == zero for unlink */
124 jint32_t mctime;
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100125 __u8 nsize;
126 __u8 type;
127 __u8 unused[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 jint32_t node_crc;
129 jint32_t name_crc;
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100130 __u8 name[0];
David Woodhouse3e68fbb2006-05-15 00:49:43 +0100131};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* The JFFS2 raw inode structure: Used for storage on physical media. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000134/* The uid, gid, atime, mtime and ctime members could be longer, but
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 are left like this for space efficiency. If and when people decide
136 they really need them extended, it's simple enough to add support for
137 a new type of raw node.
138*/
139struct jffs2_raw_inode
140{
141 jint16_t magic; /* A constant magic number. */
Artem B. Bityutskiyf302cd02005-07-24 16:29:59 +0100142 jint16_t nodetype; /* == JFFS2_NODETYPE_INODE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 jint32_t totlen; /* Total length of this node (inc data, etc.) */
144 jint32_t hdr_crc;
145 jint32_t ino; /* Inode number. */
146 jint32_t version; /* Version number. */
147 jmode_t mode; /* The file's type or mode. */
148 jint16_t uid; /* The file's owner. */
149 jint16_t gid; /* The file's group. */
150 jint32_t isize; /* Total resultant size of this inode (used for truncations) */
151 jint32_t atime; /* Last access time. */
152 jint32_t mtime; /* Last modification time. */
153 jint32_t ctime; /* Change time. */
154 jint32_t offset; /* Where to begin to write. */
155 jint32_t csize; /* (Compressed) data size */
156 jint32_t dsize; /* Size of the node's data. (after decompression) */
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100157 __u8 compr; /* Compression algorithm used */
158 __u8 usercompr; /* Compression algorithm requested by the user */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 jint16_t flags; /* See JFFS2_INO_FLAG_* */
160 jint32_t data_crc; /* CRC for the (compressed) data. */
161 jint32_t node_crc; /* CRC for the raw inode (excluding data) */
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100162 __u8 data[0];
David Woodhouse3e68fbb2006-05-15 00:49:43 +0100163};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900165struct jffs2_raw_xattr {
166 jint16_t magic;
167 jint16_t nodetype; /* = JFFS2_NODETYPE_XATTR */
168 jint32_t totlen;
169 jint32_t hdr_crc;
170 jint32_t xid; /* XATTR identifier number */
171 jint32_t version;
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100172 __u8 xprefix;
173 __u8 name_len;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900174 jint16_t value_len;
175 jint32_t data_crc;
176 jint32_t node_crc;
Arnd Bergmannccef7ab2009-02-26 00:51:41 +0100177 __u8 data[0];
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900178} __attribute__((packed));
179
180struct jffs2_raw_xref
181{
182 jint16_t magic;
183 jint16_t nodetype; /* = JFFS2_NODETYPE_XREF */
184 jint32_t totlen;
185 jint32_t hdr_crc;
186 jint32_t ino; /* inode number */
187 jint32_t xid; /* XATTR identifier number */
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900188 jint32_t xseqno; /* xref sequencial number */
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900189 jint32_t node_crc;
190} __attribute__((packed));
191
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100192struct jffs2_raw_summary
193{
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100194 jint16_t magic;
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100195 jint16_t nodetype; /* = JFFS2_NODETYPE_SUMMARY */
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100196 jint32_t totlen;
197 jint32_t hdr_crc;
198 jint32_t sum_num; /* number of sum entries*/
199 jint32_t cln_mkr; /* clean marker size, 0 = no cleanmarker */
200 jint32_t padded; /* sum of the size of padding nodes */
201 jint32_t sum_crc; /* summary information crc */
202 jint32_t node_crc; /* node crc */
203 jint32_t sum[0]; /* inode summary info */
David Woodhouse3e68fbb2006-05-15 00:49:43 +0100204};
Ferenc Havasie631ddb2005-09-07 09:35:26 +0100205
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000206union jffs2_node_union
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100207{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 struct jffs2_raw_inode i;
209 struct jffs2_raw_dirent d;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900210 struct jffs2_raw_xattr x;
211 struct jffs2_raw_xref r;
Ferenc Havasi2bc97642005-09-26 12:37:25 +0100212 struct jffs2_raw_summary s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 struct jffs2_unknown_node u;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
David Woodhouseaef9ab42006-05-19 00:28:49 +0100216/* Data payload for device nodes. */
217union jffs2_device_node {
218 jint16_t old;
219 jint32_t new;
220};
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#endif /* __LINUX_JFFS2_H__ */