6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
7 * Phillip Lougher <phillip@lougher.demon.co.uk>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2,
12 * or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
27 #define SQUASHFS_MAJOR 4
28 #define SQUASHFS_MINOR 0
29 #define SQUASHFS_START 0
31 /* size of metadata (inode and directory) blocks */
32 #define SQUASHFS_METADATA_SIZE 8192
33 #define SQUASHFS_METADATA_LOG 13
35 /* default size of data blocks */
36 #define SQUASHFS_FILE_SIZE 131072
37 #define SQUASHFS_FILE_LOG 17
39 #define SQUASHFS_FILE_MAX_SIZE 1048576
40 #define SQUASHFS_FILE_MAX_LOG 20
42 /* Max number of uids and gids */
43 #define SQUASHFS_IDS 65536
45 /* Max length of filename (not 255) */
46 #define SQUASHFS_NAME_LEN 256
48 #define SQUASHFS_INVALID_FRAG (0xffffffffU)
49 #define SQUASHFS_INVALID_BLK (-1LL)
51 /* Filesystem flags */
52 #define SQUASHFS_NOI 0
53 #define SQUASHFS_NOD 1
54 #define SQUASHFS_NOF 3
55 #define SQUASHFS_NO_FRAG 4
56 #define SQUASHFS_ALWAYS_FRAG 5
57 #define SQUASHFS_DUPLICATE 6
58 #define SQUASHFS_EXPORT 7
60 #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
62 #define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
65 #define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
68 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
71 #define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
74 #define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
77 #define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
80 #define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
83 /* Max number of types and file types */
84 #define SQUASHFS_DIR_TYPE 1
85 #define SQUASHFS_REG_TYPE 2
86 #define SQUASHFS_SYMLINK_TYPE 3
87 #define SQUASHFS_BLKDEV_TYPE 4
88 #define SQUASHFS_CHRDEV_TYPE 5
89 #define SQUASHFS_FIFO_TYPE 6
90 #define SQUASHFS_SOCKET_TYPE 7
91 #define SQUASHFS_LDIR_TYPE 8
92 #define SQUASHFS_LREG_TYPE 9
93 #define SQUASHFS_LSYMLINK_TYPE 10
94 #define SQUASHFS_LBLKDEV_TYPE 11
95 #define SQUASHFS_LCHRDEV_TYPE 12
96 #define SQUASHFS_LFIFO_TYPE 13
97 #define SQUASHFS_LSOCKET_TYPE 14
99 /* Flag whether block is compressed or uncompressed, bit is set if block is
101 #define SQUASHFS_COMPRESSED_BIT (1 << 15)
103 #define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
104 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
106 #define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
108 #define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
110 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
111 ~SQUASHFS_COMPRESSED_BIT_BLOCK)
113 #define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
116 * Inode number ops. Inodes consist of a compressed block number, and an
117 * uncompressed offset within that block
119 #define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
121 #define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
123 #define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
126 /* Translate between VFS mode and squashfs mode */
127 #define SQUASHFS_MODE(A) ((A) & 0xfff)
129 /* fragment and fragment table defines */
130 #define SQUASHFS_FRAGMENT_BYTES(A) \
131 ((A) * sizeof(struct squashfs_fragment_entry))
133 #define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
134 SQUASHFS_METADATA_SIZE)
136 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
137 SQUASHFS_METADATA_SIZE)
139 #define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
140 SQUASHFS_METADATA_SIZE - 1) / \
141 SQUASHFS_METADATA_SIZE)
143 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
146 /* inode lookup table defines */
147 #define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
149 #define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
150 SQUASHFS_METADATA_SIZE)
152 #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
153 SQUASHFS_METADATA_SIZE)
155 #define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
156 SQUASHFS_METADATA_SIZE - 1) / \
157 SQUASHFS_METADATA_SIZE)
159 #define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
162 /* uid/gid lookup table defines */
163 #define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
165 #define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
166 SQUASHFS_METADATA_SIZE)
168 #define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
169 SQUASHFS_METADATA_SIZE)
171 #define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
172 SQUASHFS_METADATA_SIZE - 1) / \
173 SQUASHFS_METADATA_SIZE)
175 #define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
178 /* cached data constants for filesystem */
179 #define SQUASHFS_CACHED_BLKS 8
181 #define SQUASHFS_MAX_FILE_SIZE_LOG 64
183 #define SQUASHFS_MAX_FILE_SIZE (1LL << \
184 (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
186 /* meta index cache */
187 #define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
188 #define SQUASHFS_META_ENTRIES 127
189 #define SQUASHFS_META_SLOTS 8
193 unsigned int index_block
;
194 unsigned short offset
;
199 unsigned int inode_number
;
201 unsigned short entries
;
203 unsigned short locked
;
205 struct meta_entry meta_entry
[SQUASHFS_META_ENTRIES
];
210 * definitions for structures on disk
212 #define ZLIB_COMPRESSION 1
213 #define LZMA_COMPRESSION 2
214 #define LZO_COMPRESSION 3
216 struct squashfs_super_block
{
230 __le64 id_table_start
;
231 __le64 xattr_table_start
;
232 __le64 inode_table_start
;
233 __le64 directory_table_start
;
234 __le64 fragment_table_start
;
235 __le64 lookup_table_start
;
238 struct squashfs_dir_index
{
242 unsigned char name
[0];
245 struct squashfs_base_inode
{
254 struct squashfs_ipc_inode
{
264 struct squashfs_dev_inode
{
275 struct squashfs_symlink_inode
{
287 struct squashfs_reg_inode
{
298 __le16 block_list
[0];
301 struct squashfs_lreg_inode
{
315 __le16 block_list
[0];
318 struct squashfs_dir_inode
{
332 struct squashfs_ldir_inode
{
346 struct squashfs_dir_index index
[0];
349 union squashfs_inode
{
350 struct squashfs_base_inode base
;
351 struct squashfs_dev_inode dev
;
352 struct squashfs_symlink_inode symlink
;
353 struct squashfs_reg_inode reg
;
354 struct squashfs_lreg_inode lreg
;
355 struct squashfs_dir_inode dir
;
356 struct squashfs_ldir_inode ldir
;
357 struct squashfs_ipc_inode ipc
;
360 struct squashfs_dir_entry
{
368 struct squashfs_dir_header
{
374 struct squashfs_fragment_entry
{