| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 8 | * For licensing information, see the file 'LICENCE' in the | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * jffs2 directory. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ | 
|  | 11 |  | 
|  | 12 | #ifndef __LINUX_JFFS2_H__ | 
|  | 13 | #define __LINUX_JFFS2_H__ | 
|  | 14 |  | 
| Jeff Garzik | e18fa70 | 2006-09-24 11:13:19 -0400 | [diff] [blame] | 15 | #include <linux/magic.h> | 
|  | 16 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* You must include something which defines the C99 uintXX_t types. | 
|  | 18 | We don't do it from here because this file is used in too many | 
|  | 19 | different environments. */ | 
|  | 20 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* Values we may expect to find in the 'magic' field */ | 
|  | 22 | #define JFFS2_OLD_MAGIC_BITMASK 0x1984 | 
|  | 23 | #define JFFS2_MAGIC_BITMASK 0x1985 | 
|  | 24 | #define KSAMTIB_CIGAM_2SFFJ 0x8519 /* For detecting wrong-endian fs */ | 
|  | 25 | #define JFFS2_EMPTY_BITMASK 0xffff | 
|  | 26 | #define JFFS2_DIRTY_BITMASK 0x0000 | 
|  | 27 |  | 
| Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 28 | /* Summary node MAGIC marker */ | 
|  | 29 | #define JFFS2_SUM_MAGIC	0x02851885 | 
|  | 30 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Richard Purdie | c799aca | 2007-07-10 10:28:36 +0100 | [diff] [blame] | 46 | #define JFFS2_COMPR_LZO		0x07 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* Compatibility flags. */ | 
|  | 48 | #define JFFS2_COMPAT_MASK 0xc000      /* What do to if an unknown nodetype is found */ | 
|  | 49 | #define JFFS2_NODE_ACCURATE 0x2000 | 
|  | 50 | /* INCOMPAT: Fail to mount the filesystem */ | 
|  | 51 | #define JFFS2_FEATURE_INCOMPAT 0xc000 | 
|  | 52 | /* ROCOMPAT: Mount read-only */ | 
|  | 53 | #define JFFS2_FEATURE_ROCOMPAT 0x8000 | 
|  | 54 | /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */ | 
|  | 55 | #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000 | 
|  | 56 | /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */ | 
|  | 57 | #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000 | 
|  | 58 |  | 
|  | 59 | #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1) | 
|  | 60 | #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2) | 
|  | 61 | #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) | 
|  | 62 | #define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4) | 
|  | 63 |  | 
| Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 64 | #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6) | 
|  | 65 |  | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 66 | #define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8) | 
|  | 67 | #define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9) | 
|  | 68 |  | 
|  | 69 | /* XATTR Related */ | 
|  | 70 | #define JFFS2_XPREFIX_USER		1	/* for "user." */ | 
|  | 71 | #define JFFS2_XPREFIX_SECURITY		2	/* for "security." */ | 
|  | 72 | #define JFFS2_XPREFIX_ACL_ACCESS	3	/* for "system.posix_acl_access" */ | 
|  | 73 | #define JFFS2_XPREFIX_ACL_DEFAULT	4	/* for "system.posix_acl_default" */ | 
|  | 74 | #define JFFS2_XPREFIX_TRUSTED		5	/* for "trusted.*" */ | 
|  | 75 |  | 
|  | 76 | #define JFFS2_ACL_VERSION		0x0001 | 
|  | 77 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | // Maybe later... | 
|  | 79 | //#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) | 
|  | 80 | //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4) | 
|  | 81 |  | 
|  | 82 |  | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 83 | #define JFFS2_INO_FLAG_PREREAD	  1	/* Do read_inode() for this one at | 
|  | 84 | mount time, don't wait for it to | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | happen later */ | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 86 | #define JFFS2_INO_FLAG_USERCOMPR  2	/* User has requested a specific | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | compression type */ | 
|  | 88 |  | 
|  | 89 |  | 
|  | 90 | /* These can go once we've made sure we've caught all uses without | 
|  | 91 | byteswapping */ | 
|  | 92 |  | 
|  | 93 | typedef struct { | 
|  | 94 | uint32_t v32; | 
| David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 95 | } __attribute__((packed)) jint32_t; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
|  | 97 | typedef struct { | 
|  | 98 | uint32_t m; | 
| David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 99 | } __attribute__((packed)) jmode_t; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
|  | 101 | typedef struct { | 
|  | 102 | uint16_t v16; | 
| David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 103 | } __attribute__((packed)) jint16_t; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
|  | 105 | struct jffs2_unknown_node | 
|  | 106 | { | 
|  | 107 | /* All start like this */ | 
|  | 108 | jint16_t magic; | 
|  | 109 | jint16_t nodetype; | 
|  | 110 | jint32_t totlen; /* So we can skip over nodes we don't grok */ | 
|  | 111 | jint32_t hdr_crc; | 
| David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 112 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
|  | 114 | struct jffs2_raw_dirent | 
|  | 115 | { | 
|  | 116 | jint16_t magic; | 
| Artem B. Bityutskiy | f302cd0 | 2005-07-24 16:29:59 +0100 | [diff] [blame] | 117 | jint16_t nodetype;	/* == JFFS2_NODETYPE_DIRENT */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | jint32_t totlen; | 
|  | 119 | jint32_t hdr_crc; | 
|  | 120 | jint32_t pino; | 
|  | 121 | jint32_t version; | 
|  | 122 | jint32_t ino; /* == zero for unlink */ | 
|  | 123 | jint32_t mctime; | 
|  | 124 | uint8_t nsize; | 
|  | 125 | uint8_t type; | 
|  | 126 | uint8_t unused[2]; | 
|  | 127 | jint32_t node_crc; | 
|  | 128 | jint32_t name_crc; | 
|  | 129 | uint8_t name[0]; | 
| David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 130 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 |  | 
|  | 132 | /* The JFFS2 raw inode structure: Used for storage on physical media.  */ | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 133 | /* The uid, gid, atime, mtime and ctime members could be longer, but | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | are left like this for space efficiency. If and when people decide | 
|  | 135 | they really need them extended, it's simple enough to add support for | 
|  | 136 | a new type of raw node. | 
|  | 137 | */ | 
|  | 138 | struct jffs2_raw_inode | 
|  | 139 | { | 
|  | 140 | jint16_t magic;      /* A constant magic number.  */ | 
| Artem B. Bityutskiy | f302cd0 | 2005-07-24 16:29:59 +0100 | [diff] [blame] | 141 | jint16_t nodetype;   /* == JFFS2_NODETYPE_INODE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | jint32_t totlen;     /* Total length of this node (inc data, etc.) */ | 
|  | 143 | jint32_t hdr_crc; | 
|  | 144 | jint32_t ino;        /* Inode number.  */ | 
|  | 145 | jint32_t version;    /* Version number.  */ | 
|  | 146 | jmode_t mode;       /* The file's type or mode.  */ | 
|  | 147 | jint16_t uid;        /* The file's owner.  */ | 
|  | 148 | jint16_t gid;        /* The file's group.  */ | 
|  | 149 | jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */ | 
|  | 150 | jint32_t atime;      /* Last access time.  */ | 
|  | 151 | jint32_t mtime;      /* Last modification time.  */ | 
|  | 152 | jint32_t ctime;      /* Change time.  */ | 
|  | 153 | jint32_t offset;     /* Where to begin to write.  */ | 
|  | 154 | jint32_t csize;      /* (Compressed) data size */ | 
|  | 155 | jint32_t dsize;	     /* Size of the node's data. (after decompression) */ | 
|  | 156 | uint8_t compr;       /* Compression algorithm used */ | 
|  | 157 | uint8_t usercompr;   /* Compression algorithm requested by the user */ | 
|  | 158 | jint16_t flags;	     /* See JFFS2_INO_FLAG_* */ | 
|  | 159 | jint32_t data_crc;   /* CRC for the (compressed) data.  */ | 
|  | 160 | jint32_t node_crc;   /* CRC for the raw inode (excluding data)  */ | 
|  | 161 | uint8_t data[0]; | 
| David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 162 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 |  | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 164 | struct jffs2_raw_xattr { | 
|  | 165 | jint16_t magic; | 
|  | 166 | jint16_t nodetype;	/* = JFFS2_NODETYPE_XATTR */ | 
|  | 167 | jint32_t totlen; | 
|  | 168 | jint32_t hdr_crc; | 
|  | 169 | jint32_t xid;		/* XATTR identifier number */ | 
|  | 170 | jint32_t version; | 
|  | 171 | uint8_t xprefix; | 
|  | 172 | uint8_t name_len; | 
|  | 173 | jint16_t value_len; | 
|  | 174 | jint32_t data_crc; | 
|  | 175 | jint32_t node_crc; | 
|  | 176 | uint8_t data[0]; | 
|  | 177 | } __attribute__((packed)); | 
|  | 178 |  | 
|  | 179 | struct jffs2_raw_xref | 
|  | 180 | { | 
|  | 181 | jint16_t magic; | 
|  | 182 | jint16_t nodetype;	/* = JFFS2_NODETYPE_XREF */ | 
|  | 183 | jint32_t totlen; | 
|  | 184 | jint32_t hdr_crc; | 
|  | 185 | jint32_t ino;		/* inode number */ | 
|  | 186 | jint32_t xid;		/* XATTR identifier number */ | 
| KaiGai Kohei | c9f700f | 2006-06-11 10:35:15 +0900 | [diff] [blame] | 187 | jint32_t xseqno;	/* xref sequencial number */ | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 188 | jint32_t node_crc; | 
|  | 189 | } __attribute__((packed)); | 
|  | 190 |  | 
| Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 191 | struct jffs2_raw_summary | 
|  | 192 | { | 
| Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 193 | jint16_t magic; | 
| Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 194 | jint16_t nodetype; 	/* = JFFS2_NODETYPE_SUMMARY */ | 
| Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 195 | jint32_t totlen; | 
|  | 196 | jint32_t hdr_crc; | 
|  | 197 | jint32_t sum_num;	/* number of sum entries*/ | 
|  | 198 | jint32_t cln_mkr;	/* clean marker size, 0 = no cleanmarker */ | 
|  | 199 | jint32_t padded;	/* sum of the size of padding nodes */ | 
|  | 200 | jint32_t sum_crc;	/* summary information crc */ | 
|  | 201 | jint32_t node_crc; 	/* node crc */ | 
|  | 202 | jint32_t sum[0]; 	/* inode summary info */ | 
| David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 203 | }; | 
| Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 204 |  | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 205 | union jffs2_node_union | 
| Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 206 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | struct jffs2_raw_inode i; | 
|  | 208 | struct jffs2_raw_dirent d; | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 209 | struct jffs2_raw_xattr x; | 
|  | 210 | struct jffs2_raw_xref r; | 
| Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 211 | struct jffs2_raw_summary s; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | struct jffs2_unknown_node u; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | }; | 
|  | 214 |  | 
| David Woodhouse | aef9ab4 | 2006-05-19 00:28:49 +0100 | [diff] [blame] | 215 | /* Data payload for device nodes. */ | 
|  | 216 | union jffs2_device_node { | 
|  | 217 | jint16_t old; | 
|  | 218 | jint32_t new; | 
|  | 219 | }; | 
|  | 220 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | #endif /* __LINUX_JFFS2_H__ */ |