]>
Commit | Line | Data |
---|---|---|
06f25585 DB |
1 | /* |
2 | * cramfs_common - cramfs common code | |
3 | * | |
4 | * Copyright (c) 2008 Roy Peled, the.roy.peled -at- gmail | |
5 | * Copyright (c) 2004-2006 by Michael Holzt, kju -at- fqdn.org | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | */ | |
18 | ||
63cccae4 KZ |
19 | #ifndef __CRAMFS_H |
20 | #define __CRAMFS_H | |
21 | ||
22 | typedef unsigned char u8; | |
23 | typedef unsigned short u16; | |
24 | typedef unsigned int u32; | |
25 | ||
26 | #define CRAMFS_MAGIC 0x28cd3d45 /* some random number */ | |
27 | #define CRAMFS_SIGNATURE "Compressed ROMFS" | |
28 | ||
29 | /* | |
30 | * Width of various bitfields in struct cramfs_inode. | |
31 | * Primarily used to generate warnings in mkcramfs. | |
32 | */ | |
33 | #define CRAMFS_MODE_WIDTH 16 | |
34 | #define CRAMFS_UID_WIDTH 16 | |
35 | #define CRAMFS_SIZE_WIDTH 24 | |
36 | #define CRAMFS_GID_WIDTH 8 | |
37 | #define CRAMFS_NAMELEN_WIDTH 6 | |
38 | #define CRAMFS_OFFSET_WIDTH 26 | |
39 | ||
06f25585 DB |
40 | #ifndef HOST_IS_BIG_ENDIAN |
41 | #ifdef WORDS_BIGENDIAN | |
42 | #define HOST_IS_BIG_ENDIAN 1 | |
43 | #else | |
44 | #define HOST_IS_BIG_ENDIAN 0 | |
45 | #endif | |
46 | #endif | |
63cccae4 KZ |
47 | |
48 | /* | |
49 | * Reasonably terse representation of the inode data. | |
50 | */ | |
51 | struct cramfs_inode { | |
52 | u32 mode:16, uid:16; | |
53 | /* SIZE for device files is i_rdev */ | |
54 | u32 size:24, gid:8; | |
55 | /* NAMELEN is the length of the file name, divided by 4 and | |
56 | rounded up. (cramfs doesn't support hard links.) */ | |
57 | /* OFFSET: For symlinks and non-empty regular files, this | |
58 | contains the offset (divided by 4) of the file data in | |
59 | compressed form (starting with an array of block pointers; | |
60 | see README). For non-empty directories it is the offset | |
61 | (divided by 4) of the inode of the first file in that | |
62 | directory. For anything else, offset is zero. */ | |
63 | u32 namelen:6, offset:26; | |
64 | }; | |
65 | ||
66 | struct cramfs_info { | |
67 | u32 crc; | |
68 | u32 edition; | |
69 | u32 blocks; | |
70 | u32 files; | |
71 | }; | |
72 | ||
73 | /* | |
74 | * Superblock information at the beginning of the FS. | |
75 | */ | |
76 | struct cramfs_super { | |
77 | u32 magic; /* 0x28cd3d45 - random number */ | |
78 | u32 size; /* Not used. mkcramfs currently | |
79 | writes a constant 1<<16 here. */ | |
80 | u32 flags; /* 0 */ | |
81 | u32 future; /* 0 */ | |
82 | u8 signature[16]; /* "Compressed ROMFS" */ | |
83 | struct cramfs_info fsid;/* unique filesystem info */ | |
84 | u8 name[16]; /* user-defined name */ | |
85 | struct cramfs_inode root; /* Root inode data */ | |
86 | }; | |
87 | ||
88 | #define CRAMFS_FLAG_FSID_VERSION_2 0x00000001 /* fsid version #2 */ | |
89 | #define CRAMFS_FLAG_SORTED_DIRS 0x00000002 /* sorted dirs */ | |
90 | #define CRAMFS_FLAG_HOLES 0x00000100 /* support for holes */ | |
91 | #define CRAMFS_FLAG_WRONG_SIGNATURE 0x00000200 /* reserved */ | |
92 | #define CRAMFS_FLAG_SHIFTED_ROOT_OFFSET 0x00000400 /* shifted root fs */ | |
93 | ||
94 | /* | |
95 | * Valid values in super.flags. Currently we refuse to mount | |
96 | * if (flags & ~CRAMFS_SUPPORTED_FLAGS). Maybe that should be | |
97 | * changed to test super.future instead. | |
98 | */ | |
99 | #define CRAMFS_SUPPORTED_FLAGS (0xff) | |
100 | ||
101 | /* Uncompression interfaces to the underlying zlib */ | |
102 | int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen); | |
103 | int cramfs_uncompress_init(void); | |
104 | int cramfs_uncompress_exit(void); | |
105 | ||
06f25585 DB |
106 | u32 u32_toggle_endianness(int big_endian, u32 what); |
107 | void super_toggle_endianness(int from_big_endian, struct cramfs_super *super); | |
108 | void inode_to_host(int from_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out); | |
109 | void inode_from_host(int to_big_endian, struct cramfs_inode *inode_in, struct cramfs_inode *inode_out); | |
110 | ||
63cccae4 | 111 | #endif |