xref: /linux/include/uapi/linux/jffs2.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * JFFS2 -- Journalling Flash File System, Version 2.
3607ca46eSDavid Howells  *
4607ca46eSDavid Howells  * Copyright © 2001-2007 Red Hat, Inc.
5607ca46eSDavid Howells  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
6607ca46eSDavid Howells  *
7607ca46eSDavid Howells  * Created by David Woodhouse <dwmw2@infradead.org>
8607ca46eSDavid Howells  *
9607ca46eSDavid Howells  * For licensing information, see the file 'LICENCE' in the
10607ca46eSDavid Howells  * jffs2 directory.
11607ca46eSDavid Howells  */
12607ca46eSDavid Howells 
13607ca46eSDavid Howells #ifndef __LINUX_JFFS2_H__
14607ca46eSDavid Howells #define __LINUX_JFFS2_H__
15607ca46eSDavid Howells 
16607ca46eSDavid Howells #include <linux/types.h>
17607ca46eSDavid Howells #include <linux/magic.h>
18607ca46eSDavid Howells 
19607ca46eSDavid Howells /* You must include something which defines the C99 uintXX_t types.
20607ca46eSDavid Howells    We don't do it from here because this file is used in too many
21607ca46eSDavid Howells    different environments. */
22607ca46eSDavid Howells 
23607ca46eSDavid Howells /* Values we may expect to find in the 'magic' field */
24607ca46eSDavid Howells #define JFFS2_OLD_MAGIC_BITMASK 0x1984
25607ca46eSDavid Howells #define JFFS2_MAGIC_BITMASK 0x1985
26607ca46eSDavid Howells #define KSAMTIB_CIGAM_2SFFJ 0x8519 /* For detecting wrong-endian fs */
27607ca46eSDavid Howells #define JFFS2_EMPTY_BITMASK 0xffff
28607ca46eSDavid Howells #define JFFS2_DIRTY_BITMASK 0x0000
29607ca46eSDavid Howells 
30607ca46eSDavid Howells /* Summary node MAGIC marker */
31607ca46eSDavid Howells #define JFFS2_SUM_MAGIC	0x02851885
32607ca46eSDavid Howells 
33607ca46eSDavid Howells /* We only allow a single char for length, and 0xFF is empty flash so
34607ca46eSDavid Howells    we don't want it confused with a real length. Hence max 254.
35607ca46eSDavid Howells */
36607ca46eSDavid Howells #define JFFS2_MAX_NAME_LEN 254
37607ca46eSDavid Howells 
38607ca46eSDavid Howells /* How small can we sensibly write nodes? */
39607ca46eSDavid Howells #define JFFS2_MIN_DATA_LEN 128
40607ca46eSDavid Howells 
41607ca46eSDavid Howells #define JFFS2_COMPR_NONE	0x00
42607ca46eSDavid Howells #define JFFS2_COMPR_ZERO	0x01
43607ca46eSDavid Howells #define JFFS2_COMPR_RTIME	0x02
44607ca46eSDavid Howells #define JFFS2_COMPR_RUBINMIPS	0x03
45607ca46eSDavid Howells #define JFFS2_COMPR_COPY	0x04
46607ca46eSDavid Howells #define JFFS2_COMPR_DYNRUBIN	0x05
47607ca46eSDavid Howells #define JFFS2_COMPR_ZLIB	0x06
48607ca46eSDavid Howells #define JFFS2_COMPR_LZO		0x07
49607ca46eSDavid Howells /* Compatibility flags. */
50607ca46eSDavid Howells #define JFFS2_COMPAT_MASK 0xc000      /* What do to if an unknown nodetype is found */
51607ca46eSDavid Howells #define JFFS2_NODE_ACCURATE 0x2000
52607ca46eSDavid Howells /* INCOMPAT: Fail to mount the filesystem */
53607ca46eSDavid Howells #define JFFS2_FEATURE_INCOMPAT 0xc000
54607ca46eSDavid Howells /* ROCOMPAT: Mount read-only */
55607ca46eSDavid Howells #define JFFS2_FEATURE_ROCOMPAT 0x8000
56607ca46eSDavid Howells /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
57607ca46eSDavid Howells #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
58607ca46eSDavid Howells /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
59607ca46eSDavid Howells #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
60607ca46eSDavid Howells 
61607ca46eSDavid Howells #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
62607ca46eSDavid Howells #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
63607ca46eSDavid Howells #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
64607ca46eSDavid Howells #define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
65607ca46eSDavid Howells 
66607ca46eSDavid Howells #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
67607ca46eSDavid Howells 
68607ca46eSDavid Howells #define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8)
69607ca46eSDavid Howells #define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9)
70607ca46eSDavid Howells 
71607ca46eSDavid Howells /* XATTR Related */
72607ca46eSDavid Howells #define JFFS2_XPREFIX_USER		1	/* for "user." */
73607ca46eSDavid Howells #define JFFS2_XPREFIX_SECURITY		2	/* for "security." */
74607ca46eSDavid Howells #define JFFS2_XPREFIX_ACL_ACCESS	3	/* for "system.posix_acl_access" */
75607ca46eSDavid Howells #define JFFS2_XPREFIX_ACL_DEFAULT	4	/* for "system.posix_acl_default" */
76607ca46eSDavid Howells #define JFFS2_XPREFIX_TRUSTED		5	/* for "trusted.*" */
77607ca46eSDavid Howells 
78607ca46eSDavid Howells #define JFFS2_ACL_VERSION		0x0001
79607ca46eSDavid Howells 
80607ca46eSDavid Howells #define JFFS2_INO_FLAG_PREREAD	  1	/* Do read_inode() for this one at
81607ca46eSDavid Howells 					   mount time, don't wait for it to
82607ca46eSDavid Howells 					   happen later */
83607ca46eSDavid Howells #define JFFS2_INO_FLAG_USERCOMPR  2	/* User has requested a specific
84607ca46eSDavid Howells 					   compression type */
85607ca46eSDavid Howells 
86607ca46eSDavid Howells 
87607ca46eSDavid Howells /* These can go once we've made sure we've caught all uses without
88607ca46eSDavid Howells    byteswapping */
89607ca46eSDavid Howells 
90607ca46eSDavid Howells typedef struct {
91607ca46eSDavid Howells 	__u32 v32;
92607ca46eSDavid Howells } __attribute__((packed)) jint32_t;
93607ca46eSDavid Howells 
94607ca46eSDavid Howells typedef struct {
95607ca46eSDavid Howells 	__u32 m;
96607ca46eSDavid Howells } __attribute__((packed)) jmode_t;
97607ca46eSDavid Howells 
98607ca46eSDavid Howells typedef struct {
99607ca46eSDavid Howells 	__u16 v16;
100607ca46eSDavid Howells } __attribute__((packed)) jint16_t;
101607ca46eSDavid Howells 
102607ca46eSDavid Howells struct jffs2_unknown_node
103607ca46eSDavid Howells {
104607ca46eSDavid Howells 	/* All start like this */
105607ca46eSDavid Howells 	jint16_t magic;
106607ca46eSDavid Howells 	jint16_t nodetype;
107607ca46eSDavid Howells 	jint32_t totlen; /* So we can skip over nodes we don't grok */
108607ca46eSDavid Howells 	jint32_t hdr_crc;
109607ca46eSDavid Howells };
110607ca46eSDavid Howells 
111607ca46eSDavid Howells struct jffs2_raw_dirent
112607ca46eSDavid Howells {
113607ca46eSDavid Howells 	jint16_t magic;
114607ca46eSDavid Howells 	jint16_t nodetype;	/* == JFFS2_NODETYPE_DIRENT */
115607ca46eSDavid Howells 	jint32_t totlen;
116607ca46eSDavid Howells 	jint32_t hdr_crc;
117607ca46eSDavid Howells 	jint32_t pino;
118607ca46eSDavid Howells 	jint32_t version;
119607ca46eSDavid Howells 	jint32_t ino; /* == zero for unlink */
120607ca46eSDavid Howells 	jint32_t mctime;
121607ca46eSDavid Howells 	__u8 nsize;
122607ca46eSDavid Howells 	__u8 type;
123607ca46eSDavid Howells 	__u8 unused[2];
124607ca46eSDavid Howells 	jint32_t node_crc;
125607ca46eSDavid Howells 	jint32_t name_crc;
126*94dfc73eSGustavo A. R. Silva 	__u8 name[];
127607ca46eSDavid Howells };
128607ca46eSDavid Howells 
129607ca46eSDavid Howells /* The JFFS2 raw inode structure: Used for storage on physical media.  */
130607ca46eSDavid Howells /* The uid, gid, atime, mtime and ctime members could be longer, but
131607ca46eSDavid Howells    are left like this for space efficiency. If and when people decide
132607ca46eSDavid Howells    they really need them extended, it's simple enough to add support for
133607ca46eSDavid Howells    a new type of raw node.
134607ca46eSDavid Howells */
135607ca46eSDavid Howells struct jffs2_raw_inode
136607ca46eSDavid Howells {
137607ca46eSDavid Howells 	jint16_t magic;      /* A constant magic number.  */
138607ca46eSDavid Howells 	jint16_t nodetype;   /* == JFFS2_NODETYPE_INODE */
139607ca46eSDavid Howells 	jint32_t totlen;     /* Total length of this node (inc data, etc.) */
140607ca46eSDavid Howells 	jint32_t hdr_crc;
141607ca46eSDavid Howells 	jint32_t ino;        /* Inode number.  */
142607ca46eSDavid Howells 	jint32_t version;    /* Version number.  */
143607ca46eSDavid Howells 	jmode_t mode;       /* The file's type or mode.  */
144607ca46eSDavid Howells 	jint16_t uid;        /* The file's owner.  */
145607ca46eSDavid Howells 	jint16_t gid;        /* The file's group.  */
146607ca46eSDavid Howells 	jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
147607ca46eSDavid Howells 	jint32_t atime;      /* Last access time.  */
148607ca46eSDavid Howells 	jint32_t mtime;      /* Last modification time.  */
149607ca46eSDavid Howells 	jint32_t ctime;      /* Change time.  */
150607ca46eSDavid Howells 	jint32_t offset;     /* Where to begin to write.  */
151607ca46eSDavid Howells 	jint32_t csize;      /* (Compressed) data size */
152607ca46eSDavid Howells 	jint32_t dsize;	     /* Size of the node's data. (after decompression) */
153607ca46eSDavid Howells 	__u8 compr;       /* Compression algorithm used */
154607ca46eSDavid Howells 	__u8 usercompr;   /* Compression algorithm requested by the user */
155607ca46eSDavid Howells 	jint16_t flags;	     /* See JFFS2_INO_FLAG_* */
156607ca46eSDavid Howells 	jint32_t data_crc;   /* CRC for the (compressed) data.  */
157607ca46eSDavid Howells 	jint32_t node_crc;   /* CRC for the raw inode (excluding data)  */
158*94dfc73eSGustavo A. R. Silva 	__u8 data[];
159607ca46eSDavid Howells };
160607ca46eSDavid Howells 
161607ca46eSDavid Howells struct jffs2_raw_xattr {
162607ca46eSDavid Howells 	jint16_t magic;
163607ca46eSDavid Howells 	jint16_t nodetype;	/* = JFFS2_NODETYPE_XATTR */
164607ca46eSDavid Howells 	jint32_t totlen;
165607ca46eSDavid Howells 	jint32_t hdr_crc;
166607ca46eSDavid Howells 	jint32_t xid;		/* XATTR identifier number */
167607ca46eSDavid Howells 	jint32_t version;
168607ca46eSDavid Howells 	__u8 xprefix;
169607ca46eSDavid Howells 	__u8 name_len;
170607ca46eSDavid Howells 	jint16_t value_len;
171607ca46eSDavid Howells 	jint32_t data_crc;
172607ca46eSDavid Howells 	jint32_t node_crc;
173*94dfc73eSGustavo A. R. Silva 	__u8 data[];
174607ca46eSDavid Howells } __attribute__((packed));
175607ca46eSDavid Howells 
176607ca46eSDavid Howells struct jffs2_raw_xref
177607ca46eSDavid Howells {
178607ca46eSDavid Howells 	jint16_t magic;
179607ca46eSDavid Howells 	jint16_t nodetype;	/* = JFFS2_NODETYPE_XREF */
180607ca46eSDavid Howells 	jint32_t totlen;
181607ca46eSDavid Howells 	jint32_t hdr_crc;
182607ca46eSDavid Howells 	jint32_t ino;		/* inode number */
183607ca46eSDavid Howells 	jint32_t xid;		/* XATTR identifier number */
184607ca46eSDavid Howells 	jint32_t xseqno;	/* xref sequential number */
185607ca46eSDavid Howells 	jint32_t node_crc;
186607ca46eSDavid Howells } __attribute__((packed));
187607ca46eSDavid Howells 
188607ca46eSDavid Howells struct jffs2_raw_summary
189607ca46eSDavid Howells {
190607ca46eSDavid Howells 	jint16_t magic;
191607ca46eSDavid Howells 	jint16_t nodetype; 	/* = JFFS2_NODETYPE_SUMMARY */
192607ca46eSDavid Howells 	jint32_t totlen;
193607ca46eSDavid Howells 	jint32_t hdr_crc;
194607ca46eSDavid Howells 	jint32_t sum_num;	/* number of sum entries*/
195607ca46eSDavid Howells 	jint32_t cln_mkr;	/* clean marker size, 0 = no cleanmarker */
196607ca46eSDavid Howells 	jint32_t padded;	/* sum of the size of padding nodes */
197607ca46eSDavid Howells 	jint32_t sum_crc;	/* summary information crc */
198607ca46eSDavid Howells 	jint32_t node_crc; 	/* node crc */
199*94dfc73eSGustavo A. R. Silva 	jint32_t sum[]; 	/* inode summary info */
200607ca46eSDavid Howells };
201607ca46eSDavid Howells 
202607ca46eSDavid Howells union jffs2_node_union
203607ca46eSDavid Howells {
204607ca46eSDavid Howells 	struct jffs2_raw_inode i;
205607ca46eSDavid Howells 	struct jffs2_raw_dirent d;
206607ca46eSDavid Howells 	struct jffs2_raw_xattr x;
207607ca46eSDavid Howells 	struct jffs2_raw_xref r;
208607ca46eSDavid Howells 	struct jffs2_raw_summary s;
209607ca46eSDavid Howells 	struct jffs2_unknown_node u;
210607ca46eSDavid Howells };
211607ca46eSDavid Howells 
212607ca46eSDavid Howells /* Data payload for device nodes. */
213607ca46eSDavid Howells union jffs2_device_node {
214607ca46eSDavid Howells 	jint16_t old_id;
215607ca46eSDavid Howells 	jint32_t new_id;
216607ca46eSDavid Howells };
217607ca46eSDavid Howells 
218607ca46eSDavid Howells #endif /* __LINUX_JFFS2_H__ */
219