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. |
| 10 | * |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 11 | * $Id: jffs2.h,v 1.38 2005/09/26 11:37:23 havasi Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 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 Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 31 | /* Summary node MAGIC marker */ |
| 32 | #define JFFS2_SUM_MAGIC 0x02851885 |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | /* 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 Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 66 | #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6) |
| 67 | |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 68 | #define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8) |
| 69 | #define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9) |
| 70 | |
| 71 | /* XATTR Related */ |
| 72 | #define JFFS2_XPREFIX_USER 1 /* for "user." */ |
| 73 | #define JFFS2_XPREFIX_SECURITY 2 /* for "security." */ |
| 74 | #define JFFS2_XPREFIX_ACL_ACCESS 3 /* for "system.posix_acl_access" */ |
| 75 | #define JFFS2_XPREFIX_ACL_DEFAULT 4 /* for "system.posix_acl_default" */ |
| 76 | #define JFFS2_XPREFIX_TRUSTED 5 /* for "trusted.*" */ |
| 77 | |
| 78 | #define JFFS2_ACL_VERSION 0x0001 |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | // Maybe later... |
| 81 | //#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) |
| 82 | //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4) |
| 83 | |
| 84 | |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 85 | #define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at |
| 86 | mount time, don't wait for it to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | happen later */ |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 88 | #define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | compression type */ |
| 90 | |
| 91 | |
| 92 | /* These can go once we've made sure we've caught all uses without |
| 93 | byteswapping */ |
| 94 | |
| 95 | typedef struct { |
| 96 | uint32_t v32; |
David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 97 | } __attribute__((packed)) jint32_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | typedef struct { |
| 100 | uint32_t m; |
David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 101 | } __attribute__((packed)) jmode_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | typedef struct { |
| 104 | uint16_t v16; |
David Woodhouse | ba9627b | 2006-05-16 23:03:08 +0100 | [diff] [blame] | 105 | } __attribute__((packed)) jint16_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | struct jffs2_unknown_node |
| 108 | { |
| 109 | /* All start like this */ |
| 110 | jint16_t magic; |
| 111 | jint16_t nodetype; |
| 112 | jint32_t totlen; /* So we can skip over nodes we don't grok */ |
| 113 | jint32_t hdr_crc; |
David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | struct jffs2_raw_dirent |
| 117 | { |
| 118 | jint16_t magic; |
Artem B. Bityutskiy | f302cd0 | 2005-07-24 16:29:59 +0100 | [diff] [blame] | 119 | jint16_t nodetype; /* == JFFS2_NODETYPE_DIRENT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | jint32_t totlen; |
| 121 | jint32_t hdr_crc; |
| 122 | jint32_t pino; |
| 123 | jint32_t version; |
| 124 | jint32_t ino; /* == zero for unlink */ |
| 125 | jint32_t mctime; |
| 126 | uint8_t nsize; |
| 127 | uint8_t type; |
| 128 | uint8_t unused[2]; |
| 129 | jint32_t node_crc; |
| 130 | jint32_t name_crc; |
| 131 | uint8_t name[0]; |
David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 132 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* The JFFS2 raw inode structure: Used for storage on physical media. */ |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 135 | /* The uid, gid, atime, mtime and ctime members could be longer, but |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | are left like this for space efficiency. If and when people decide |
| 137 | they really need them extended, it's simple enough to add support for |
| 138 | a new type of raw node. |
| 139 | */ |
| 140 | struct jffs2_raw_inode |
| 141 | { |
| 142 | jint16_t magic; /* A constant magic number. */ |
Artem B. Bityutskiy | f302cd0 | 2005-07-24 16:29:59 +0100 | [diff] [blame] | 143 | jint16_t nodetype; /* == JFFS2_NODETYPE_INODE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | jint32_t totlen; /* Total length of this node (inc data, etc.) */ |
| 145 | jint32_t hdr_crc; |
| 146 | jint32_t ino; /* Inode number. */ |
| 147 | jint32_t version; /* Version number. */ |
| 148 | jmode_t mode; /* The file's type or mode. */ |
| 149 | jint16_t uid; /* The file's owner. */ |
| 150 | jint16_t gid; /* The file's group. */ |
| 151 | jint32_t isize; /* Total resultant size of this inode (used for truncations) */ |
| 152 | jint32_t atime; /* Last access time. */ |
| 153 | jint32_t mtime; /* Last modification time. */ |
| 154 | jint32_t ctime; /* Change time. */ |
| 155 | jint32_t offset; /* Where to begin to write. */ |
| 156 | jint32_t csize; /* (Compressed) data size */ |
| 157 | jint32_t dsize; /* Size of the node's data. (after decompression) */ |
| 158 | uint8_t compr; /* Compression algorithm used */ |
| 159 | uint8_t usercompr; /* Compression algorithm requested by the user */ |
| 160 | jint16_t flags; /* See JFFS2_INO_FLAG_* */ |
| 161 | jint32_t data_crc; /* CRC for the (compressed) data. */ |
| 162 | jint32_t node_crc; /* CRC for the raw inode (excluding data) */ |
| 163 | uint8_t data[0]; |
David Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 164 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 166 | struct jffs2_raw_xattr { |
| 167 | jint16_t magic; |
| 168 | jint16_t nodetype; /* = JFFS2_NODETYPE_XATTR */ |
| 169 | jint32_t totlen; |
| 170 | jint32_t hdr_crc; |
| 171 | jint32_t xid; /* XATTR identifier number */ |
| 172 | jint32_t version; |
| 173 | uint8_t xprefix; |
| 174 | uint8_t name_len; |
| 175 | jint16_t value_len; |
| 176 | jint32_t data_crc; |
| 177 | jint32_t node_crc; |
| 178 | uint8_t data[0]; |
| 179 | } __attribute__((packed)); |
| 180 | |
| 181 | struct jffs2_raw_xref |
| 182 | { |
| 183 | jint16_t magic; |
| 184 | jint16_t nodetype; /* = JFFS2_NODETYPE_XREF */ |
| 185 | jint32_t totlen; |
| 186 | jint32_t hdr_crc; |
| 187 | jint32_t ino; /* inode number */ |
| 188 | jint32_t xid; /* XATTR identifier number */ |
| 189 | jint32_t node_crc; |
| 190 | } __attribute__((packed)); |
| 191 | |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 192 | struct jffs2_raw_summary |
| 193 | { |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 194 | jint16_t magic; |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 195 | jint16_t nodetype; /* = JFFS2_NODETYPE_SUMMARY */ |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 196 | 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 Woodhouse | 3e68fbb | 2006-05-15 00:49:43 +0100 | [diff] [blame] | 204 | }; |
Ferenc Havasi | e631ddb | 2005-09-07 09:35:26 +0100 | [diff] [blame] | 205 | |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 206 | union jffs2_node_union |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 207 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | struct jffs2_raw_inode i; |
| 209 | struct jffs2_raw_dirent d; |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 210 | struct jffs2_raw_xattr x; |
| 211 | struct jffs2_raw_xref r; |
Ferenc Havasi | 2bc9764 | 2005-09-26 12:37:25 +0100 | [diff] [blame] | 212 | struct jffs2_raw_summary s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | struct jffs2_unknown_node u; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
David Woodhouse | aef9ab4 | 2006-05-19 00:28:49 +0100 | [diff] [blame] | 216 | /* Data payload for device nodes. */ |
| 217 | union jffs2_device_node { |
| 218 | jint16_t old; |
| 219 | jint32_t new; |
| 220 | }; |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | #endif /* __LINUX_JFFS2_H__ */ |