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