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