1 /*
2  * JFFS2 -- Journalling Flash File System, Version 2.
3  *
4  * Copyright (C) 2001 Red Hat, Inc.
5  *
6  * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
7  *
8  * The original JFFS, from which the design for JFFS2 was derived,
9  * was designed and implemented by Axis Communications AB.
10  *
11  * The contents of this file are subject to the Red Hat eCos Public
12  * License Version 1.1 (the "Licence"); you may not use this file
13  * except in compliance with the Licence.  You may obtain a copy of
14  * the Licence at http://www.redhat.com/
15  *
16  * Software distributed under the Licence is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
18  * See the Licence for the specific language governing rights and
19  * limitations under the Licence.
20  *
21  * The Original Code is JFFS2 - Journalling Flash File System, version 2
22  *
23  * Alternatively, the contents of this file may be used under the
24  * terms of the GNU General Public License version 2 (the "GPL"), in
25  * which case the provisions of the GPL are applicable instead of the
26  * above.  If you wish to allow the use of your version of this file
27  * only under the terms of the GPL and not to allow others to use your
28  * version of this file under the RHEPL, indicate your decision by
29  * deleting the provisions above and replace them with the notice and
30  * other provisions required by the GPL.  If you do not delete the
31  * provisions above, a recipient may use your version of this file
32  * under either the RHEPL or the GPL.
33  *
34  * $Id: jffs2.h,v 1.19 2001/10/09 13:20:23 dwmw2 Exp $
35  *
36  */
37 
38 #ifndef __LINUX_JFFS2_H__
39 #define __LINUX_JFFS2_H__
40 
41 #include <asm/types.h>
42 #define JFFS2_SUPER_MAGIC 0x72b6
43 
44 /* Values we may expect to find in the 'magic' field */
45 #define JFFS2_OLD_MAGIC_BITMASK 0x1984
46 #define JFFS2_MAGIC_BITMASK 0x1985
47 #define KSAMTIB_CIGAM_2SFFJ 0x5981 /* For detecting wrong-endian fs */
48 #define JFFS2_EMPTY_BITMASK 0xffff
49 #define JFFS2_DIRTY_BITMASK 0x0000
50 
51 /* We only allow a single char for length, and 0xFF is empty flash so
52    we don't want it confused with a real length. Hence max 254.
53 */
54 #define JFFS2_MAX_NAME_LEN 254
55 
56 /* How small can we sensibly write nodes? */
57 #define JFFS2_MIN_DATA_LEN 128
58 
59 #define JFFS2_COMPR_NONE	0x00
60 #define JFFS2_COMPR_ZERO	0x01
61 #define JFFS2_COMPR_RTIME	0x02
62 #define JFFS2_COMPR_RUBINMIPS	0x03
63 #define JFFS2_COMPR_COPY	0x04
64 #define JFFS2_COMPR_DYNRUBIN	0x05
65 #define JFFS2_COMPR_ZLIB	0x06
66 /* Compatibility flags. */
67 #define JFFS2_COMPAT_MASK 0xc000      /* What do to if an unknown nodetype is found */
68 #define JFFS2_NODE_ACCURATE 0x2000
69 /* INCOMPAT: Fail to mount the filesystem */
70 #define JFFS2_FEATURE_INCOMPAT 0xc000
71 /* ROCOMPAT: Mount read-only */
72 #define JFFS2_FEATURE_ROCOMPAT 0x8000
73 /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
74 #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
75 /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
76 #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
77 
78 #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
79 #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
80 #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
81 
82 // Maybe later...
83 //#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
84 //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
85 
86 /* Same as the non_ECC versions, but with extra space for real
87  * ECC instead of just the checksum. For use on NAND flash
88  */
89 //#define JFFS2_NODETYPE_DIRENT_ECC (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 5)
90 //#define JFFS2_NODETYPE_INODE_ECC (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 6)
91 
92 #define JFFS2_INO_FLAG_PREREAD	  1	/* Do read_inode() for this one at
93 					   mount time, don't wait for it to
94 					   happen later */
95 #define JFFS2_INO_FLAG_USERCOMPR  2	/* User has requested a specific
96 					   compression type */
97 
98 
99 struct jffs2_unknown_node
100 {
101 	/* All start like this */
102 	__u16 magic;
103 	__u16 nodetype;
104 	__u32 totlen; /* So we can skip over nodes we don't grok */
105 	__u32 hdr_crc;
106 } __attribute__((packed));
107 
108 struct jffs2_raw_dirent
109 {
110 	__u16 magic;
111 	__u16 nodetype;	/* == JFFS_NODETYPE_DIRENT */
112 	__u32 totlen;
113 	__u32 hdr_crc;
114 	__u32 pino;
115 	__u32 version;
116 	__u32 ino; /* == zero for unlink */
117 	__u32 mctime;
118 	__u8 nsize;
119 	__u8 type;
120 	__u8 unused[2];
121 	__u32 node_crc;
122 	__u32 name_crc;
123 	__u8 name[0];
124 } __attribute__((packed));
125 
126 /* The JFFS2 raw inode structure: Used for storage on physical media.  */
127 /* The uid, gid, atime, mtime and ctime members could be longer, but
128    are left like this for space efficiency. If and when people decide
129    they really need them extended, it's simple enough to add support for
130    a new type of raw node.
131 */
132 struct jffs2_raw_inode
133 {
134 	__u16 magic;      /* A constant magic number.  */
135 	__u16 nodetype;   /* == JFFS_NODETYPE_INODE */
136 	__u32 totlen;     /* Total length of this node (inc data, etc.) */
137 	__u32 hdr_crc;
138 	__u32 ino;        /* Inode number.  */
139 	__u32 version;    /* Version number.  */
140 	__u32 mode;       /* The file's type or mode.  */
141 	__u16 uid;        /* The file's owner.  */
142 	__u16 gid;        /* The file's group.  */
143 	__u32 isize;      /* Total resultant size of this inode (used for truncations)  */
144 	__u32 atime;      /* Last access time.  */
145 	__u32 mtime;      /* Last modification time.  */
146 	__u32 ctime;      /* Change time.  */
147 	__u32 offset;     /* Where to begin to write.  */
148 	__u32 csize;      /* (Compressed) data size */
149 	__u32 dsize;	  /* Size of the node's data. (after decompression) */
150 	__u8 compr;       /* Compression algorithm used */
151 	__u8 usercompr;	  /* Compression algorithm requested by the user */
152 	__u16 flags;	  /* See JFFS2_INO_FLAG_* */
153 	__u32 data_crc;   /* CRC for the (compressed) data.  */
154 	__u32 node_crc;   /* CRC for the raw inode (excluding data)  */
155 //	__u8 data[dsize];
156 } __attribute__((packed));
157 
158 union jffs2_node_union {
159 	struct jffs2_raw_inode i;
160 	struct jffs2_raw_dirent d;
161 	struct jffs2_unknown_node u;
162 };
163 
164 #endif /* __LINUX_JFFS2_H__ */
165