6 #include <asm/byteorder.h>
8 /* Uncompression interfaces to the underlying zlib */
9 int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
10 int cramfs_uncompress_init(void);
11 int cramfs_uncompress_exit(void);
13 #else /* not __KERNEL__ */
18 typedef unsigned char u8;
19 typedef unsigned short u16;
20 typedef unsigned int u32;
22 #endif /* not __KERNEL__ */
24 #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
25 #define CRAMFS_SIGNATURE "Compressed ROMFS"
28 * Width of various bitfields in struct cramfs_inode.
29 * Primarily used to generate warnings in mkcramfs.
31 #define CRAMFS_MODE_WIDTH 16
32 #define CRAMFS_UID_WIDTH 16
33 #define CRAMFS_SIZE_WIDTH 24
34 #define CRAMFS_GID_WIDTH 8
35 #define CRAMFS_NAMELEN_WIDTH 6
36 #define CRAMFS_OFFSET_WIDTH 26
39 * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
40 * path length is 63 << 2 = 252.
42 #define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
45 * Reasonably terse representation of the inode data.
48 u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
49 /* SIZE for device files is i_rdev */
50 u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
51 /* NAMELEN is the length of the file name, divided by 4 and
52 rounded up. (cramfs doesn't support hard links.) */
53 /* OFFSET: For symlinks and non-empty regular files, this
54 contains the offset (divided by 4) of the file data in
55 compressed form (starting with an array of block pointers;
56 see README). For non-empty directories it is the offset
57 (divided by 4) of the inode of the first file in that
58 directory. For anything else, offset is zero. */
59 u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
70 * Superblock information at the beginning of the FS.
73 u32 magic; /* 0x28cd3d45 - random number */
74 u32 size; /* length in bytes */
75 u32 flags; /* feature flags */
76 u32 future; /* reserved for future use */
77 u8 signature[16]; /* "Compressed ROMFS" */
78 struct cramfs_info fsid; /* unique filesystem info */
79 u8 name[16]; /* user-defined name */
80 struct cramfs_inode root; /* root inode data */
86 * 0x00000000 - 0x000000ff: features that work for all past kernels
87 * 0x00000100 - 0xffffffff: features that don't work for past kernels
89 #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
90 #define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
91 #define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
92 #define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
93 #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
96 * Valid values in super.flags. Currently we refuse to mount
97 * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
98 * changed to test super.future instead.
100 #define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \
101 | CRAMFS_FLAG_HOLES \
102 | CRAMFS_FLAG_WRONG_SIGNATURE \
103 | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
106 * Since cramfs is little-endian, provide macros to swab the bitfields.
109 //#ifndef __BYTE_ORDER
110 //#if defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
111 //#define __BYTE_ORDER __LITTLE_ENDIAN
112 //#elif defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN)
113 //#define __BYTE_ORDER __BIG_ENDIAN
115 //#error "unable to define __BYTE_ORDER"
117 //#endif /* not __BYTE_ORDER */
119 //#if __BYTE_ORDER == __LITTLE_ENDIAN
120 //#warning "__BYTE_ORDER == __LITTLE_ENDIAN"
121 //#define CRAMFS_16(x) (x)
122 //#define CRAMFS_24(x) (x)
123 //#define CRAMFS_32(x) (x)
124 //#define CRAMFS_GET_NAMELEN(x) ((x)->namelen)
125 //#define CRAMFS_GET_OFFSET(x) ((x)->offset)
126 //#define CRAMFS_SET_OFFSET(x,y) ((x)->offset = (y))
127 //#define CRAMFS_SET_NAMELEN(x,y) ((x)->namelen = (y))
128 //#elif __BYTE_ORDER == __BIG_ENDIAN
129 #warning "__BYTE_ORDER == __BIG_ENDIAN"
131 #define CRAMFS_16(x) swab16(x)
132 #define CRAMFS_24(x) ((swab32(x)) >> 8)
133 #define CRAMFS_32(x) swab32(x)
134 #else /* not __KERNEL__ */
135 #define CRAMFS_16(x) bswap_16(x)
136 #define CRAMFS_24(x) ((bswap_32(x)) >> 8)
137 #define CRAMFS_32(x) bswap_32(x)
138 #endif /* not __KERNEL__ */
139 #define CRAMFS_GET_NAMELEN(x) (((u8*)(x))[8] & 0x3f)
140 #define CRAMFS_GET_OFFSET(x) ((CRAMFS_24(((u32*)(x))[2] & 0xffffff) << 2) |\
141 ((((u32*)(x))[2] & 0xc0000000) >> 30))
142 #define CRAMFS_SET_NAMELEN(x,y) (((u8*)(x))[8] = (((0x3f & (y))) | \
143 (0xc0 & ((u8*)(x))[8])))
144 #define CRAMFS_SET_OFFSET(x,y) (((u32*)(x))[2] = (((y) & 3) << 30) | \
145 CRAMFS_24((((y) & 0x03ffffff) >> 2)) | \
146 (((u32)(((u8*)(x))[8] & 0x3f)) << 24))
148 //#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN"
151 #endif /* not __CRAMFS_FS_H */