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_MAGIC 0x73717368
30 #define SQUASHFS_START 0
32 /* size of metadata (inode and directory) blocks */
33 #define SQUASHFS_METADATA_SIZE 8192
34 #define SQUASHFS_METADATA_LOG 13
36 /* default size of data blocks */
37 #define SQUASHFS_FILE_SIZE 131072
38 #define SQUASHFS_FILE_LOG 17
40 #define SQUASHFS_FILE_MAX_SIZE 1048576
41 #define SQUASHFS_FILE_MAX_LOG 20
43 /* Max number of uids and gids */
44 #define SQUASHFS_IDS 65536
46 /* Max length of filename (not 255) */
47 #define SQUASHFS_NAME_LEN 256
49 #define SQUASHFS_INVALID_FRAG (0xffffffffU)
50 #define SQUASHFS_INVALID_BLK (-1LL)
52 /* Filesystem flags */
53 #define SQUASHFS_NOI 0
54 #define SQUASHFS_NOD 1
55 #define SQUASHFS_NOF 3
56 #define SQUASHFS_NO_FRAG 4
57 #define SQUASHFS_ALWAYS_FRAG 5
58 #define SQUASHFS_DUPLICATE 6
59 #define SQUASHFS_EXPORT 7
61 #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
63 #define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
66 #define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
69 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
72 #define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
75 #define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
78 #define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
81 #define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
84 /* Max number of types and file types */
85 #define SQUASHFS_DIR_TYPE 1
86 #define SQUASHFS_REG_TYPE 2
87 #define SQUASHFS_SYMLINK_TYPE 3
88 #define SQUASHFS_BLKDEV_TYPE 4
89 #define SQUASHFS_CHRDEV_TYPE 5
90 #define SQUASHFS_FIFO_TYPE 6
91 #define SQUASHFS_SOCKET_TYPE 7
92 #define SQUASHFS_LDIR_TYPE 8
93 #define SQUASHFS_LREG_TYPE 9
94 #define SQUASHFS_LSYMLINK_TYPE 10
95 #define SQUASHFS_LBLKDEV_TYPE 11
96 #define SQUASHFS_LCHRDEV_TYPE 12
97 #define SQUASHFS_LFIFO_TYPE 13
98 #define SQUASHFS_LSOCKET_TYPE 14
100 /* Flag whether block is compressed or uncompressed, bit is set if block is
102 #define SQUASHFS_COMPRESSED_BIT (1 << 15)
104 #define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
105 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
107 #define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
109 #define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
111 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
112 ~SQUASHFS_COMPRESSED_BIT_BLOCK)
114 #define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
117 * Inode number ops. Inodes consist of a compressed block number, and an
118 * uncompressed offset within that block
120 #define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
122 #define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
124 #define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
127 /* Translate between VFS mode and squashfs mode */
128 #define SQUASHFS_MODE(A) ((A) & 0xfff)
130 /* fragment and fragment table defines */
131 #define SQUASHFS_FRAGMENT_BYTES(A) \
132 ((A) * sizeof(struct squashfs_fragment_entry))
134 #define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
135 SQUASHFS_METADATA_SIZE)
137 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
138 SQUASHFS_METADATA_SIZE)
140 #define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
141 SQUASHFS_METADATA_SIZE - 1) / \
142 SQUASHFS_METADATA_SIZE)
144 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
147 /* inode lookup table defines */
148 #define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
150 #define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
151 SQUASHFS_METADATA_SIZE)
153 #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
154 SQUASHFS_METADATA_SIZE)
156 #define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
157 SQUASHFS_METADATA_SIZE - 1) / \
158 SQUASHFS_METADATA_SIZE)
160 #define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
163 /* uid/gid lookup table defines */
164 #define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
166 #define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
167 SQUASHFS_METADATA_SIZE)
169 #define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
170 SQUASHFS_METADATA_SIZE)
172 #define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
173 SQUASHFS_METADATA_SIZE - 1) / \
174 SQUASHFS_METADATA_SIZE)
176 #define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
179 /* cached data constants for filesystem */
180 #define SQUASHFS_CACHED_BLKS 8
182 #define SQUASHFS_MAX_FILE_SIZE_LOG 64
184 #define SQUASHFS_MAX_FILE_SIZE (1LL << \
185 (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
187 #define SQUASHFS_MARKER_BYTE 0xff
189 /* meta index cache */
190 #define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
191 #define SQUASHFS_META_ENTRIES 127
192 #define SQUASHFS_META_SLOTS 8
196 unsigned int index_block
;
197 unsigned short offset
;
202 unsigned int inode_number
;
204 unsigned short entries
;
206 unsigned short locked
;
208 struct meta_entry meta_entry
[SQUASHFS_META_ENTRIES
];
213 * definitions for structures on disk
215 #define ZLIB_COMPRESSION 1
217 struct squashfs_super_block
{
231 __le64 id_table_start
;
232 __le64 xattr_table_start
;
233 __le64 inode_table_start
;
234 __le64 directory_table_start
;
235 __le64 fragment_table_start
;
236 __le64 lookup_table_start
;
239 struct squashfs_dir_index
{
243 unsigned char name
[0];
246 struct squashfs_base_inode
{
255 struct squashfs_ipc_inode
{
265 struct squashfs_dev_inode
{
276 struct squashfs_symlink_inode
{
288 struct squashfs_reg_inode
{
299 __le16 block_list
[0];
302 struct squashfs_lreg_inode
{
316 __le16 block_list
[0];
319 struct squashfs_dir_inode
{
333 struct squashfs_ldir_inode
{
347 struct squashfs_dir_index index
[0];
350 union squashfs_inode
{
351 struct squashfs_base_inode base
;
352 struct squashfs_dev_inode dev
;
353 struct squashfs_symlink_inode symlink
;
354 struct squashfs_reg_inode reg
;
355 struct squashfs_lreg_inode lreg
;
356 struct squashfs_dir_inode dir
;
357 struct squashfs_ldir_inode ldir
;
358 struct squashfs_ipc_inode ipc
;
361 struct squashfs_dir_entry
{
369 struct squashfs_dir_header
{
375 struct squashfs_fragment_entry
{