Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * JFFS2 -- Journalling Flash File System, Version 2.
0003  *
0004  * Copyright © 2001-2007 Red Hat, Inc.
0005  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
0006  *
0007  * Created by David Woodhouse <dwmw2@infradead.org>
0008  *
0009  * For licensing information, see the file 'LICENCE' in the
0010  * jffs2 directory.
0011  */
0012 
0013 #ifndef __LINUX_JFFS2_H__
0014 #define __LINUX_JFFS2_H__
0015 
0016 #include <linux/types.h>
0017 #include <linux/magic.h>
0018 
0019 /* You must include something which defines the C99 uintXX_t types. 
0020    We don't do it from here because this file is used in too many
0021    different environments. */
0022 
0023 /* Values we may expect to find in the 'magic' field */
0024 #define JFFS2_OLD_MAGIC_BITMASK 0x1984
0025 #define JFFS2_MAGIC_BITMASK 0x1985
0026 #define KSAMTIB_CIGAM_2SFFJ 0x8519 /* For detecting wrong-endian fs */
0027 #define JFFS2_EMPTY_BITMASK 0xffff
0028 #define JFFS2_DIRTY_BITMASK 0x0000
0029 
0030 /* Summary node MAGIC marker */
0031 #define JFFS2_SUM_MAGIC 0x02851885
0032 
0033 /* We only allow a single char for length, and 0xFF is empty flash so
0034    we don't want it confused with a real length. Hence max 254.
0035 */
0036 #define JFFS2_MAX_NAME_LEN 254
0037 
0038 /* How small can we sensibly write nodes? */
0039 #define JFFS2_MIN_DATA_LEN 128
0040 
0041 #define JFFS2_COMPR_NONE    0x00
0042 #define JFFS2_COMPR_ZERO    0x01
0043 #define JFFS2_COMPR_RTIME   0x02
0044 #define JFFS2_COMPR_RUBINMIPS   0x03
0045 #define JFFS2_COMPR_COPY    0x04
0046 #define JFFS2_COMPR_DYNRUBIN    0x05
0047 #define JFFS2_COMPR_ZLIB    0x06
0048 #define JFFS2_COMPR_LZO     0x07
0049 /* Compatibility flags. */
0050 #define JFFS2_COMPAT_MASK 0xc000      /* What do to if an unknown nodetype is found */
0051 #define JFFS2_NODE_ACCURATE 0x2000
0052 /* INCOMPAT: Fail to mount the filesystem */
0053 #define JFFS2_FEATURE_INCOMPAT 0xc000
0054 /* ROCOMPAT: Mount read-only */
0055 #define JFFS2_FEATURE_ROCOMPAT 0x8000
0056 /* RWCOMPAT_COPY: Mount read/write, and copy the node when it's GC'd */
0057 #define JFFS2_FEATURE_RWCOMPAT_COPY 0x4000
0058 /* RWCOMPAT_DELETE: Mount read/write, and delete the node when it's GC'd */
0059 #define JFFS2_FEATURE_RWCOMPAT_DELETE 0x0000
0060 
0061 #define JFFS2_NODETYPE_DIRENT (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 1)
0062 #define JFFS2_NODETYPE_INODE (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 2)
0063 #define JFFS2_NODETYPE_CLEANMARKER (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 3)
0064 #define JFFS2_NODETYPE_PADDING (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 4)
0065 
0066 #define JFFS2_NODETYPE_SUMMARY (JFFS2_FEATURE_RWCOMPAT_DELETE | JFFS2_NODE_ACCURATE | 6)
0067 
0068 #define JFFS2_NODETYPE_XATTR (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 8)
0069 #define JFFS2_NODETYPE_XREF (JFFS2_FEATURE_INCOMPAT | JFFS2_NODE_ACCURATE | 9)
0070 
0071 /* XATTR Related */
0072 #define JFFS2_XPREFIX_USER      1   /* for "user." */
0073 #define JFFS2_XPREFIX_SECURITY      2   /* for "security." */
0074 #define JFFS2_XPREFIX_ACL_ACCESS    3   /* for "system.posix_acl_access" */
0075 #define JFFS2_XPREFIX_ACL_DEFAULT   4   /* for "system.posix_acl_default" */
0076 #define JFFS2_XPREFIX_TRUSTED       5   /* for "trusted.*" */
0077 
0078 #define JFFS2_ACL_VERSION       0x0001
0079 
0080 #define JFFS2_INO_FLAG_PREREAD    1 /* Do read_inode() for this one at
0081                        mount time, don't wait for it to
0082                        happen later */
0083 #define JFFS2_INO_FLAG_USERCOMPR  2 /* User has requested a specific
0084                        compression type */
0085 
0086 
0087 /* These can go once we've made sure we've caught all uses without
0088    byteswapping */
0089 
0090 typedef struct {
0091     __u32 v32;
0092 } __attribute__((packed)) jint32_t;
0093 
0094 typedef struct {
0095     __u32 m;
0096 } __attribute__((packed)) jmode_t;
0097 
0098 typedef struct {
0099     __u16 v16;
0100 } __attribute__((packed)) jint16_t;
0101 
0102 struct jffs2_unknown_node
0103 {
0104     /* All start like this */
0105     jint16_t magic;
0106     jint16_t nodetype;
0107     jint32_t totlen; /* So we can skip over nodes we don't grok */
0108     jint32_t hdr_crc;
0109 };
0110 
0111 struct jffs2_raw_dirent
0112 {
0113     jint16_t magic;
0114     jint16_t nodetype;  /* == JFFS2_NODETYPE_DIRENT */
0115     jint32_t totlen;
0116     jint32_t hdr_crc;
0117     jint32_t pino;
0118     jint32_t version;
0119     jint32_t ino; /* == zero for unlink */
0120     jint32_t mctime;
0121     __u8 nsize;
0122     __u8 type;
0123     __u8 unused[2];
0124     jint32_t node_crc;
0125     jint32_t name_crc;
0126     __u8 name[];
0127 };
0128 
0129 /* The JFFS2 raw inode structure: Used for storage on physical media.  */
0130 /* The uid, gid, atime, mtime and ctime members could be longer, but
0131    are left like this for space efficiency. If and when people decide
0132    they really need them extended, it's simple enough to add support for
0133    a new type of raw node.
0134 */
0135 struct jffs2_raw_inode
0136 {
0137     jint16_t magic;      /* A constant magic number.  */
0138     jint16_t nodetype;   /* == JFFS2_NODETYPE_INODE */
0139     jint32_t totlen;     /* Total length of this node (inc data, etc.) */
0140     jint32_t hdr_crc;
0141     jint32_t ino;        /* Inode number.  */
0142     jint32_t version;    /* Version number.  */
0143     jmode_t mode;       /* The file's type or mode.  */
0144     jint16_t uid;        /* The file's owner.  */
0145     jint16_t gid;        /* The file's group.  */
0146     jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
0147     jint32_t atime;      /* Last access time.  */
0148     jint32_t mtime;      /* Last modification time.  */
0149     jint32_t ctime;      /* Change time.  */
0150     jint32_t offset;     /* Where to begin to write.  */
0151     jint32_t csize;      /* (Compressed) data size */
0152     jint32_t dsize;      /* Size of the node's data. (after decompression) */
0153     __u8 compr;       /* Compression algorithm used */
0154     __u8 usercompr;   /* Compression algorithm requested by the user */
0155     jint16_t flags;      /* See JFFS2_INO_FLAG_* */
0156     jint32_t data_crc;   /* CRC for the (compressed) data.  */
0157     jint32_t node_crc;   /* CRC for the raw inode (excluding data)  */
0158     __u8 data[];
0159 };
0160 
0161 struct jffs2_raw_xattr {
0162     jint16_t magic;
0163     jint16_t nodetype;  /* = JFFS2_NODETYPE_XATTR */
0164     jint32_t totlen;
0165     jint32_t hdr_crc;
0166     jint32_t xid;       /* XATTR identifier number */
0167     jint32_t version;
0168     __u8 xprefix;
0169     __u8 name_len;
0170     jint16_t value_len;
0171     jint32_t data_crc;
0172     jint32_t node_crc;
0173     __u8 data[];
0174 } __attribute__((packed));
0175 
0176 struct jffs2_raw_xref
0177 {
0178     jint16_t magic;
0179     jint16_t nodetype;  /* = JFFS2_NODETYPE_XREF */
0180     jint32_t totlen;
0181     jint32_t hdr_crc;
0182     jint32_t ino;       /* inode number */
0183     jint32_t xid;       /* XATTR identifier number */
0184     jint32_t xseqno;    /* xref sequential number */
0185     jint32_t node_crc;
0186 } __attribute__((packed));
0187 
0188 struct jffs2_raw_summary
0189 {
0190     jint16_t magic;
0191     jint16_t nodetype;  /* = JFFS2_NODETYPE_SUMMARY */
0192     jint32_t totlen;
0193     jint32_t hdr_crc;
0194     jint32_t sum_num;   /* number of sum entries*/
0195     jint32_t cln_mkr;   /* clean marker size, 0 = no cleanmarker */
0196     jint32_t padded;    /* sum of the size of padding nodes */
0197     jint32_t sum_crc;   /* summary information crc */
0198     jint32_t node_crc;  /* node crc */
0199     jint32_t sum[];     /* inode summary info */
0200 };
0201 
0202 union jffs2_node_union
0203 {
0204     struct jffs2_raw_inode i;
0205     struct jffs2_raw_dirent d;
0206     struct jffs2_raw_xattr x;
0207     struct jffs2_raw_xref r;
0208     struct jffs2_raw_summary s;
0209     struct jffs2_unknown_node u;
0210 };
0211 
0212 /* Data payload for device nodes. */
0213 union jffs2_device_node {
0214     jint16_t old_id;
0215     jint32_t new_id;
0216 };
0217 
0218 #endif /* __LINUX_JFFS2_H__ */