blob: 3be4e5a27d82f4f3bbf24d1fa1eb78af78516dfc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __CRAMFS_H
2#define __CRAMFS_H
3
David Woodhouse05f75fd2006-05-04 17:50:04 +01004#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
6#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
Andi Drebesac8d35c2007-10-16 23:27:12 -07007#define CRAMFS_MAGIC_WEND 0x453dcd28 /* magic number with the wrong endianess */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#define CRAMFS_SIGNATURE "Compressed ROMFS"
9
10/*
11 * Width of various bitfields in struct cramfs_inode.
12 * Primarily used to generate warnings in mkcramfs.
13 */
14#define CRAMFS_MODE_WIDTH 16
15#define CRAMFS_UID_WIDTH 16
16#define CRAMFS_SIZE_WIDTH 24
17#define CRAMFS_GID_WIDTH 8
18#define CRAMFS_NAMELEN_WIDTH 6
19#define CRAMFS_OFFSET_WIDTH 26
20
21/*
22 * Since inode.namelen is a unsigned 6-bit number, the maximum cramfs
23 * path length is 63 << 2 = 252.
24 */
25#define CRAMFS_MAXPATHLEN (((1 << CRAMFS_NAMELEN_WIDTH) - 1) << 2)
26
27/*
28 * Reasonably terse representation of the inode data.
29 */
30struct cramfs_inode {
David Woodhouse05f75fd2006-05-04 17:50:04 +010031 __u32 mode:CRAMFS_MODE_WIDTH, uid:CRAMFS_UID_WIDTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 /* SIZE for device files is i_rdev */
David Woodhouse05f75fd2006-05-04 17:50:04 +010033 __u32 size:CRAMFS_SIZE_WIDTH, gid:CRAMFS_GID_WIDTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 /* NAMELEN is the length of the file name, divided by 4 and
35 rounded up. (cramfs doesn't support hard links.) */
36 /* OFFSET: For symlinks and non-empty regular files, this
37 contains the offset (divided by 4) of the file data in
38 compressed form (starting with an array of block pointers;
39 see README). For non-empty directories it is the offset
40 (divided by 4) of the inode of the first file in that
41 directory. For anything else, offset is zero. */
David Woodhouse05f75fd2006-05-04 17:50:04 +010042 __u32 namelen:CRAMFS_NAMELEN_WIDTH, offset:CRAMFS_OFFSET_WIDTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
45struct cramfs_info {
David Woodhouse05f75fd2006-05-04 17:50:04 +010046 __u32 crc;
47 __u32 edition;
48 __u32 blocks;
49 __u32 files;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050};
51
52/*
53 * Superblock information at the beginning of the FS.
54 */
55struct cramfs_super {
David Woodhouse05f75fd2006-05-04 17:50:04 +010056 __u32 magic; /* 0x28cd3d45 - random number */
57 __u32 size; /* length in bytes */
58 __u32 flags; /* feature flags */
59 __u32 future; /* reserved for future use */
60 __u8 signature[16]; /* "Compressed ROMFS" */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct cramfs_info fsid; /* unique filesystem info */
David Woodhouse05f75fd2006-05-04 17:50:04 +010062 __u8 name[16]; /* user-defined name */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 struct cramfs_inode root; /* root inode data */
64};
65
66/*
67 * Feature flags
68 *
69 * 0x00000000 - 0x000000ff: features that work for all past kernels
70 * 0x00000100 - 0xffffffff: features that don't work for past kernels
71 */
72#define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */
73#define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */
74#define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */
75#define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */
76#define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */
77
78/*
79 * Valid values in super.flags. Currently we refuse to mount
80 * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be
81 * changed to test super.future instead.
82 */
83#define CRAMFS_SUPPORTED_FLAGS ( 0x000000ff \
84 | CRAMFS_FLAG_HOLES \
85 | CRAMFS_FLAG_WRONG_SIGNATURE \
86 | CRAMFS_FLAG_SHIFTED_ROOT_OFFSET )
87
88/* Uncompression interfaces to the underlying zlib */
89int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen);
90int cramfs_uncompress_init(void);
Alexey Dobriyan368bdb32006-09-29 02:01:05 -070091void cramfs_uncompress_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#endif