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