wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 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.2 2002/01/17 00:53:20 nyet Exp $ |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | #ifndef __LINUX_JFFS2_H__ |
| 39 | #define __LINUX_JFFS2_H__ |
| 40 | |
| 41 | #include <asm/types.h> |
| 42 | #include <jffs2/load_kernel.h> |
| 43 | |
| 44 | #define JFFS2_SUPER_MAGIC 0x72b6 |
| 45 | |
| 46 | /* Values we may expect to find in the 'magic' field */ |
| 47 | #define JFFS2_OLD_MAGIC_BITMASK 0x1984 |
| 48 | #define JFFS2_MAGIC_BITMASK 0x1985 |
| 49 | #define KSAMTIB_CIGAM_2SFFJ 0x5981 /* For detecting wrong-endian fs */ |
| 50 | #define JFFS2_EMPTY_BITMASK 0xffff |
| 51 | #define JFFS2_DIRTY_BITMASK 0x0000 |
| 52 | |
Ilya Yanok | 9b70762 | 2008-11-13 19:49:35 +0300 | [diff] [blame] | 53 | /* Summary node MAGIC marker */ |
| 54 | #define JFFS2_SUM_MAGIC 0x02851885 |
| 55 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 56 | /* We only allow a single char for length, and 0xFF is empty flash so |
| 57 | we don't want it confused with a real length. Hence max 254. |
| 58 | */ |
| 59 | #define JFFS2_MAX_NAME_LEN 254 |
| 60 | |
| 61 | /* How small can we sensibly write nodes? */ |
| 62 | #define JFFS2_MIN_DATA_LEN 128 |
| 63 | |
| 64 | #define JFFS2_COMPR_NONE 0x00 |
| 65 | #define JFFS2_COMPR_ZERO 0x01 |
| 66 | #define JFFS2_COMPR_RTIME 0x02 |
| 67 | #define JFFS2_COMPR_RUBINMIPS 0x03 |
| 68 | #define JFFS2_COMPR_COPY 0x04 |
| 69 | #define JFFS2_COMPR_DYNRUBIN 0x05 |
| 70 | #define JFFS2_COMPR_ZLIB 0x06 |
wdenk | 412babe | 2005-05-05 09:51:44 +0000 | [diff] [blame] | 71 | #if defined(CONFIG_JFFS2_LZO_LZARI) |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 72 | #define JFFS2_COMPR_LZO 0x07 |
| 73 | #define JFFS2_COMPR_LZARI 0x08 |
| 74 | #define JFFS2_NUM_COMPR 9 |
wdenk | 412babe | 2005-05-05 09:51:44 +0000 | [diff] [blame] | 75 | #else |
| 76 | #define JFFS2_NUM_COMPR 7 |
| 77 | #endif |
wdenk | 9dd41a7 | 2005-05-12 22:48:09 +0000 | [diff] [blame] | 78 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 79 | /* Compatibility flags. */ |
| 80 | #define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */ |
| 81 | #define JFFS2_NODE_ACCURATE 0x2000 |
| 82 | /* INCOMPAT: Fail to mount the filesystem */ |
| 83 | #define JFFS2_FEATURE_INCOMPAT 0xc000 |
| 84 | /* ROCOMPAT: Mount read-only */ |
| 85 | #define JFFS2_FEATURE_ROCOMPAT 0x8000 |
| 86 | /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */ |
| 87 | #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000 |
| 88 | /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */ |
| 89 | #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000 |
| 90 | |
| 91 | #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1) |
| 92 | #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2) |
| 93 | #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 94 | #define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4) |
Ilya Yanok | 9b70762 | 2008-11-13 19:49:35 +0300 | [diff] [blame] | 95 | #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 96 | |
| 97 | /* Maybe later... */ |
| 98 | /*#define JFFS2_NODETYPE_CHECKPOINT (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3) */ |
| 99 | /*#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4) */ |
| 100 | |
| 101 | /* Same as the non_ECC versions, but with extra space for real |
| 102 | * ECC instead of just the checksum. For use on NAND flash |
| 103 | */ |
| 104 | /*#define JFFS2_NODETYPE_DIRENT_ECC (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 5) */ |
| 105 | /*#define JFFS2_NODETYPE_INODE_ECC (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 6) */ |
| 106 | |
| 107 | #define JFFS2_INO_FLAG_PREREAD 1 /* Do read_inode() for this one at |
| 108 | mount time, don't wait for it to |
| 109 | happen later */ |
| 110 | #define JFFS2_INO_FLAG_USERCOMPR 2 /* User has requested a specific |
| 111 | compression type */ |
| 112 | |
| 113 | |
| 114 | struct jffs2_unknown_node |
| 115 | { |
| 116 | /* All start like this */ |
| 117 | __u16 magic; |
| 118 | __u16 nodetype; |
| 119 | __u32 totlen; /* So we can skip over nodes we don't grok */ |
| 120 | __u32 hdr_crc; |
| 121 | } __attribute__((packed)); |
| 122 | |
| 123 | struct jffs2_raw_dirent |
| 124 | { |
| 125 | __u16 magic; |
| 126 | __u16 nodetype; /* == JFFS_NODETYPE_DIRENT */ |
| 127 | __u32 totlen; |
| 128 | __u32 hdr_crc; |
| 129 | __u32 pino; |
| 130 | __u32 version; |
| 131 | __u32 ino; /* == zero for unlink */ |
| 132 | __u32 mctime; |
| 133 | __u8 nsize; |
| 134 | __u8 type; |
| 135 | __u8 unused[2]; |
| 136 | __u32 node_crc; |
| 137 | __u32 name_crc; |
| 138 | __u8 name[0]; |
| 139 | } __attribute__((packed)); |
| 140 | |
| 141 | /* The JFFS2 raw inode structure: Used for storage on physical media. */ |
| 142 | /* The uid, gid, atime, mtime and ctime members could be longer, but |
| 143 | are left like this for space efficiency. If and when people decide |
| 144 | they really need them extended, it's simple enough to add support for |
| 145 | a new type of raw node. |
| 146 | */ |
| 147 | struct jffs2_raw_inode |
| 148 | { |
| 149 | __u16 magic; /* A constant magic number. */ |
| 150 | __u16 nodetype; /* == JFFS_NODETYPE_INODE */ |
| 151 | __u32 totlen; /* Total length of this node (inc data, etc.) */ |
| 152 | __u32 hdr_crc; |
| 153 | __u32 ino; /* Inode number. */ |
| 154 | __u32 version; /* Version number. */ |
| 155 | __u32 mode; /* The file's type or mode. */ |
| 156 | __u16 uid; /* The file's owner. */ |
| 157 | __u16 gid; /* The file's group. */ |
| 158 | __u32 isize; /* Total resultant size of this inode (used for truncations) */ |
| 159 | __u32 atime; /* Last access time. */ |
| 160 | __u32 mtime; /* Last modification time. */ |
| 161 | __u32 ctime; /* Change time. */ |
| 162 | __u32 offset; /* Where to begin to write. */ |
| 163 | __u32 csize; /* (Compressed) data size */ |
| 164 | __u32 dsize; /* Size of the node's data. (after decompression) */ |
| 165 | __u8 compr; /* Compression algorithm used */ |
| 166 | __u8 usercompr; /* Compression algorithm requested by the user */ |
| 167 | __u16 flags; /* See JFFS2_INO_FLAG_* */ |
| 168 | __u32 data_crc; /* CRC for the (compressed) data. */ |
| 169 | __u32 node_crc; /* CRC for the raw inode (excluding data) */ |
| 170 | /* __u8 data[dsize]; */ |
| 171 | } __attribute__((packed)); |
| 172 | |
Ilya Yanok | 9b70762 | 2008-11-13 19:49:35 +0300 | [diff] [blame] | 173 | struct jffs2_raw_summary |
| 174 | { |
| 175 | __u16 magic; |
| 176 | __u16 nodetype; /* = JFFS2_NODETYPE_SUMMARY */ |
| 177 | __u32 totlen; |
| 178 | __u32 hdr_crc; |
| 179 | __u32 sum_num; /* number of sum entries*/ |
| 180 | __u32 cln_mkr; /* clean marker size, 0 = no cleanmarker */ |
| 181 | __u32 padded; /* sum of the size of padding nodes */ |
| 182 | __u32 sum_crc; /* summary information crc */ |
| 183 | __u32 node_crc; /* node crc */ |
| 184 | __u32 sum[0]; /* inode summary info */ |
| 185 | }; |
| 186 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 187 | union jffs2_node_union { |
| 188 | struct jffs2_raw_inode i; |
| 189 | struct jffs2_raw_dirent d; |
Ilya Yanok | 9b70762 | 2008-11-13 19:49:35 +0300 | [diff] [blame] | 190 | struct jffs2_raw_summary s; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 191 | struct jffs2_unknown_node u; |
| 192 | } __attribute__((packed)); |
| 193 | |
| 194 | enum |
| 195 | { |
| 196 | DT_UNKNOWN = 0, |
| 197 | # define DT_UNKNOWN DT_UNKNOWN |
| 198 | DT_FIFO = 1, |
| 199 | # define DT_FIFO DT_FIFO |
| 200 | DT_CHR = 2, |
| 201 | # define DT_CHR DT_CHR |
| 202 | DT_DIR = 4, |
| 203 | # define DT_DIR DT_DIR |
| 204 | DT_BLK = 6, |
| 205 | # define DT_BLK DT_BLK |
| 206 | DT_REG = 8, |
| 207 | # define DT_REG DT_REG |
| 208 | DT_LNK = 10, |
| 209 | # define DT_LNK DT_LNK |
| 210 | DT_SOCK = 12, |
| 211 | # define DT_SOCK DT_SOCK |
| 212 | DT_WHT = 14 |
| 213 | # define DT_WHT DT_WHT |
| 214 | }; |
| 215 | |
| 216 | |
| 217 | u32 jffs2_1pass_ls(struct part_info *part,const char *fname); |
| 218 | u32 jffs2_1pass_load(char *dest, struct part_info *part,const char *fname); |
| 219 | u32 jffs2_1pass_info(struct part_info *part); |
| 220 | |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 221 | void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, |
| 222 | u32 srclen, u32 destlen); |
| 223 | void rubin_do_decompress(unsigned char *bits, unsigned char *in, |
| 224 | unsigned char *page_out, __u32 destlen); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 225 | void dynrubin_decompress(unsigned char *data_in, unsigned char *cpage_out, |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 226 | unsigned long sourcelen, unsigned long dstlen); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 227 | long zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 228 | __u32 srclen, __u32 destlen); |
wdenk | 412babe | 2005-05-05 09:51:44 +0000 | [diff] [blame] | 229 | #if defined(CONFIG_JFFS2_LZO_LZARI) |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 230 | int lzo_decompress(unsigned char *data_in, unsigned char *cpage_out, |
| 231 | u32 srclen, u32 destlen); |
wdenk | 412babe | 2005-05-05 09:51:44 +0000 | [diff] [blame] | 232 | int lzari_decompress(unsigned char *data_in, unsigned char *cpage_out, |
| 233 | u32 srclen, u32 destlen); |
wdenk | 07cc099 | 2005-05-05 00:04:14 +0000 | [diff] [blame] | 234 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 235 | |
wdenk | 180d3f7 | 2004-01-04 16:28:35 +0000 | [diff] [blame] | 236 | char *mkmodestr(unsigned long mode, char *str); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 237 | #endif /* __LINUX_JFFS2_H__ */ |