1*4882a593Smuzhiyun #ifndef __CRAMFS_H 2*4882a593Smuzhiyun #define __CRAMFS_H 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */ 5*4882a593Smuzhiyun #define CRAMFS_SIGNATURE "Compressed ROMFS" 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun /* 8*4882a593Smuzhiyun * Width of various bitfields in struct cramfs_inode. 9*4882a593Smuzhiyun * Primarily used to generate warnings in mkcramfs. 10*4882a593Smuzhiyun */ 11*4882a593Smuzhiyun #define CRAMFS_MODE_WIDTH 16 12*4882a593Smuzhiyun #define CRAMFS_UID_WIDTH 16 13*4882a593Smuzhiyun #define CRAMFS_SIZE_WIDTH 24 14*4882a593Smuzhiyun #define CRAMFS_GID_WIDTH 8 15*4882a593Smuzhiyun #define CRAMFS_NAMELEN_WIDTH 6 16*4882a593Smuzhiyun #define CRAMFS_OFFSET_WIDTH 26 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun /* 19*4882a593Smuzhiyun * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs 20*4882a593Smuzhiyun * path length is 63 << 2 = 252. 21*4882a593Smuzhiyun */ 22*4882a593Smuzhiyun #define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2) 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun /* 25*4882a593Smuzhiyun * Reasonably terse representation of the inode data. 26*4882a593Smuzhiyun */ 27*4882a593Smuzhiyun struct cramfs_inode { 28*4882a593Smuzhiyun u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH; 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /* SIZE for device files is i_rdev */ 31*4882a593Smuzhiyun u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH; 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun /* NAMELEN is the length of the file name, divided by 4 and 34*4882a593Smuzhiyun rounded up. (cramfs doesn't support hard links.) */ 35*4882a593Smuzhiyun /* OFFSET: For symlinks and non-empty regular files, this 36*4882a593Smuzhiyun contains the offset (divided by 4) of the file data in 37*4882a593Smuzhiyun compressed form (starting with an array of block pointers; 38*4882a593Smuzhiyun see README). For non-empty directories it is the offset 39*4882a593Smuzhiyun (divided by 4) of the inode of the first file in that 40*4882a593Smuzhiyun directory. For anything else, offset is zero. */ 41*4882a593Smuzhiyun u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH; 42*4882a593Smuzhiyun }; 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun struct cramfs_info { 45*4882a593Smuzhiyun u32 crc; 46*4882a593Smuzhiyun u32 edition; 47*4882a593Smuzhiyun u32 blocks; 48*4882a593Smuzhiyun u32 files; 49*4882a593Smuzhiyun }; 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun /* 52*4882a593Smuzhiyun * Superblock information at the beginning of the FS. 53*4882a593Smuzhiyun */ 54*4882a593Smuzhiyun struct cramfs_super { 55*4882a593Smuzhiyun u32 magic; /* 0x28cd3d45 - random number */ 56*4882a593Smuzhiyun u32 size; /* length in bytes */ 57*4882a593Smuzhiyun u32 flags; /* feature flags */ 58*4882a593Smuzhiyun u32 future; /* reserved for future use */ 59*4882a593Smuzhiyun u8 signature[16]; /* "Compressed ROMFS" */ 60*4882a593Smuzhiyun struct cramfs_info fsid; /* unique filesystem info */ 61*4882a593Smuzhiyun u8 name[16]; /* user-defined name */ 62*4882a593Smuzhiyun struct cramfs_inode root; /* root inode data */ 63*4882a593Smuzhiyun }; 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun /* 66*4882a593Smuzhiyun * Feature flags 67*4882a593Smuzhiyun * 68*4882a593Smuzhiyun * 0x00000000 - 0x000000ff: features that work for all past kernels 69*4882a593Smuzhiyun * 0x00000100 - 0xffffffff: features that don't work for past kernels 70*4882a593Smuzhiyun */ 71*4882a593Smuzhiyun #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */ 72*4882a593Smuzhiyun #define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */ 73*4882a593Smuzhiyun #define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */ 74*4882a593Smuzhiyun #define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */ 75*4882a593Smuzhiyun #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */ 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun /* 78*4882a593Smuzhiyun * Valid values in super.flags. Currently we refuse to mount 79*4882a593Smuzhiyun * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be 80*4882a593Smuzhiyun * changed to test super.future instead. 81*4882a593Smuzhiyun */ 82*4882a593Smuzhiyun #define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \ 83*4882a593Smuzhiyun | CRAMFS_FLAG_HOLES \ 84*4882a593Smuzhiyun | CRAMFS_FLAG_WRONG_SIGNATURE \ 85*4882a593Smuzhiyun | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET ) 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun #define CRAMFS_16(x) (x) 88*4882a593Smuzhiyun #define CRAMFS_24(x) (x) 89*4882a593Smuzhiyun #define CRAMFS_32(x) (x) 90*4882a593Smuzhiyun #define CRAMFS_GET_NAMELEN(x) ((x)->namelen) 91*4882a593Smuzhiyun #define CRAMFS_GET_OFFSET(x) ((x)->offset) 92*4882a593Smuzhiyun #define CRAMFS_SET_OFFSET(x,y) ((x)->offset = (y)) 93*4882a593Smuzhiyun #define CRAMFS_SET_NAMELEN(x,y) ((x)->namelen = (y)) 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun /* Uncompression interfaces to the underlying zlib */ 96*4882a593Smuzhiyun int cramfs_uncompress_block(void *dst, void *src, int srclen); 97*4882a593Smuzhiyun int cramfs_uncompress_init(void); 98*4882a593Smuzhiyun int cramfs_uncompress_exit(void); 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun #endif /* __CRAMFS_H */ 101