blob: 9e2349d07cb1c98334fd19ffbeb5441361f65edf [file] [log] [blame]
Phillip Lougherffae2cd2009-01-05 08:46:27 +00001#ifndef SQUASHFS_FS
2#define SQUASHFS_FS
3/*
4 * Squashfs
5 *
6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
Phillip Lougherd7f2ff62011-05-26 10:39:56 +01007 * Phillip Lougher <phillip@squashfs.org.uk>
Phillip Lougherffae2cd2009-01-05 08:46:27 +00008 *
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.
13 *
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.
18 *
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.
22 *
23 * squashfs_fs.h
24 */
25
26#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
27#define SQUASHFS_MAJOR 4
28#define SQUASHFS_MINOR 0
Phillip Lougherffae2cd2009-01-05 08:46:27 +000029#define SQUASHFS_START 0
30
31/* size of metadata (inode and directory) blocks */
32#define SQUASHFS_METADATA_SIZE 8192
Phillip Lougherffae2cd2009-01-05 08:46:27 +000033
Phillip Lougher7657cac2011-10-22 01:34:48 +010034/* default size of block device I/O */
35#ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
36#define SQUASHFS_DEVBLK_SIZE 4096
37#else
38#define SQUASHFS_DEVBLK_SIZE 1024
39#endif
40
Phillip Lougherffae2cd2009-01-05 08:46:27 +000041#define SQUASHFS_FILE_MAX_SIZE 1048576
42#define SQUASHFS_FILE_MAX_LOG 20
43
Phillip Lougherffae2cd2009-01-05 08:46:27 +000044/* Max length of filename (not 255) */
45#define SQUASHFS_NAME_LEN 256
46
Ajeet Yadav4826d832012-02-02 13:04:49 +053047/* Max value for directory header count*/
48#define SQUASHFS_DIR_COUNT 256
49
Phillip Lougherffae2cd2009-01-05 08:46:27 +000050#define SQUASHFS_INVALID_FRAG (0xffffffffU)
Phillip Lougherf41d2072010-05-17 03:17:04 +010051#define SQUASHFS_INVALID_XATTR (0xffffffffU)
Phillip Lougherffae2cd2009-01-05 08:46:27 +000052#define SQUASHFS_INVALID_BLK (-1LL)
53
54/* Filesystem flags */
55#define SQUASHFS_NOI 0
56#define SQUASHFS_NOD 1
57#define SQUASHFS_NOF 3
58#define SQUASHFS_NO_FRAG 4
59#define SQUASHFS_ALWAYS_FRAG 5
60#define SQUASHFS_DUPLICATE 6
61#define SQUASHFS_EXPORT 7
Phillip Lougherb7fc0ff2011-02-28 01:45:42 +000062#define SQUASHFS_COMP_OPT 10
Phillip Lougherffae2cd2009-01-05 08:46:27 +000063
64#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
65
66#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
67 SQUASHFS_NOI)
68
69#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
70 SQUASHFS_NOD)
71
72#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
73 SQUASHFS_NOF)
74
75#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
76 SQUASHFS_NO_FRAG)
77
78#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
79 SQUASHFS_ALWAYS_FRAG)
80
81#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
82 SQUASHFS_DUPLICATE)
83
84#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
85 SQUASHFS_EXPORT)
86
Phillip Lougherb7fc0ff2011-02-28 01:45:42 +000087#define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
88 SQUASHFS_COMP_OPT)
89
Phillip Lougherffae2cd2009-01-05 08:46:27 +000090/* Max number of types and file types */
91#define SQUASHFS_DIR_TYPE 1
92#define SQUASHFS_REG_TYPE 2
93#define SQUASHFS_SYMLINK_TYPE 3
94#define SQUASHFS_BLKDEV_TYPE 4
95#define SQUASHFS_CHRDEV_TYPE 5
96#define SQUASHFS_FIFO_TYPE 6
97#define SQUASHFS_SOCKET_TYPE 7
98#define SQUASHFS_LDIR_TYPE 8
99#define SQUASHFS_LREG_TYPE 9
100#define SQUASHFS_LSYMLINK_TYPE 10
101#define SQUASHFS_LBLKDEV_TYPE 11
102#define SQUASHFS_LCHRDEV_TYPE 12
103#define SQUASHFS_LFIFO_TYPE 13
104#define SQUASHFS_LSOCKET_TYPE 14
105
Phillip Lougherf41d2072010-05-17 03:17:04 +0100106/* Xattr types */
107#define SQUASHFS_XATTR_USER 0
108#define SQUASHFS_XATTR_TRUSTED 1
109#define SQUASHFS_XATTR_SECURITY 2
110#define SQUASHFS_XATTR_VALUE_OOL 256
111#define SQUASHFS_XATTR_PREFIX_MASK 0xff
112
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000113/* Flag whether block is compressed or uncompressed, bit is set if block is
114 * uncompressed */
115#define SQUASHFS_COMPRESSED_BIT (1 << 15)
116
117#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
118 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
119
120#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
121
122#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
123
124#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
125 ~SQUASHFS_COMPRESSED_BIT_BLOCK)
126
127#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
128
129/*
130 * Inode number ops. Inodes consist of a compressed block number, and an
131 * uncompressed offset within that block
132 */
133#define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
134
135#define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
136
137#define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
138 << 16) + (B)))
139
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000140/* fragment and fragment table defines */
141#define SQUASHFS_FRAGMENT_BYTES(A) \
142 ((A) * sizeof(struct squashfs_fragment_entry))
143
144#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
145 SQUASHFS_METADATA_SIZE)
146
147#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
148 SQUASHFS_METADATA_SIZE)
149
150#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
151 SQUASHFS_METADATA_SIZE - 1) / \
152 SQUASHFS_METADATA_SIZE)
153
154#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
155 sizeof(u64))
156
157/* inode lookup table defines */
158#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
159
160#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
161 SQUASHFS_METADATA_SIZE)
162
163#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
164 SQUASHFS_METADATA_SIZE)
165
166#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
167 SQUASHFS_METADATA_SIZE - 1) / \
168 SQUASHFS_METADATA_SIZE)
169
170#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
171 sizeof(u64))
172
173/* uid/gid lookup table defines */
174#define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
175
176#define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
177 SQUASHFS_METADATA_SIZE)
178
179#define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
180 SQUASHFS_METADATA_SIZE)
181
182#define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
183 SQUASHFS_METADATA_SIZE - 1) / \
184 SQUASHFS_METADATA_SIZE)
185
186#define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
187 sizeof(u64))
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100188/* xattr id lookup table defines */
189#define SQUASHFS_XATTR_BYTES(A) ((A) * sizeof(struct squashfs_xattr_id))
190
191#define SQUASHFS_XATTR_BLOCK(A) (SQUASHFS_XATTR_BYTES(A) / \
192 SQUASHFS_METADATA_SIZE)
193
194#define SQUASHFS_XATTR_BLOCK_OFFSET(A) (SQUASHFS_XATTR_BYTES(A) % \
195 SQUASHFS_METADATA_SIZE)
196
197#define SQUASHFS_XATTR_BLOCKS(A) ((SQUASHFS_XATTR_BYTES(A) + \
198 SQUASHFS_METADATA_SIZE - 1) / \
199 SQUASHFS_METADATA_SIZE)
200
201#define SQUASHFS_XATTR_BLOCK_BYTES(A) (SQUASHFS_XATTR_BLOCKS(A) *\
202 sizeof(u64))
203#define SQUASHFS_XATTR_BLK(A) ((unsigned int) ((A) >> 16))
204
205#define SQUASHFS_XATTR_OFFSET(A) ((unsigned int) ((A) & 0xffff))
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000206
207/* cached data constants for filesystem */
208#define SQUASHFS_CACHED_BLKS 8
209
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000210/* meta index cache */
211#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
212#define SQUASHFS_META_ENTRIES 127
213#define SQUASHFS_META_SLOTS 8
214
215struct meta_entry {
216 u64 data_block;
217 unsigned int index_block;
218 unsigned short offset;
219 unsigned short pad;
220};
221
222struct meta_index {
223 unsigned int inode_number;
224 unsigned int offset;
225 unsigned short entries;
226 unsigned short skip;
227 unsigned short locked;
228 unsigned short pad;
229 struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
230};
231
232
233/*
234 * definitions for structures on disk
235 */
Phillip Lougherdc325672009-10-14 03:58:11 +0100236#define ZLIB_COMPRESSION 1
237#define LZMA_COMPRESSION 2
238#define LZO_COMPRESSION 3
Phillip Lougher81bb8de2010-12-09 02:02:29 +0000239#define XZ_COMPRESSION 4
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000240
241struct squashfs_super_block {
242 __le32 s_magic;
243 __le32 inodes;
244 __le32 mkfs_time;
245 __le32 block_size;
246 __le32 fragments;
247 __le16 compression;
248 __le16 block_log;
249 __le16 flags;
250 __le16 no_ids;
251 __le16 s_major;
252 __le16 s_minor;
253 __le64 root_inode;
254 __le64 bytes_used;
255 __le64 id_table_start;
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100256 __le64 xattr_id_table_start;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000257 __le64 inode_table_start;
258 __le64 directory_table_start;
259 __le64 fragment_table_start;
260 __le64 lookup_table_start;
261};
262
263struct squashfs_dir_index {
264 __le32 index;
265 __le32 start_block;
266 __le32 size;
267 unsigned char name[0];
268};
269
270struct squashfs_base_inode {
271 __le16 inode_type;
272 __le16 mode;
273 __le16 uid;
274 __le16 guid;
275 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000276 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000277};
278
279struct squashfs_ipc_inode {
280 __le16 inode_type;
281 __le16 mode;
282 __le16 uid;
283 __le16 guid;
284 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000285 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000286 __le32 nlink;
287};
288
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100289struct squashfs_lipc_inode {
290 __le16 inode_type;
291 __le16 mode;
292 __le16 uid;
293 __le16 guid;
294 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000295 __le32 inode_number;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100296 __le32 nlink;
297 __le32 xattr;
298};
299
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000300struct squashfs_dev_inode {
301 __le16 inode_type;
302 __le16 mode;
303 __le16 uid;
304 __le16 guid;
305 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000306 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000307 __le32 nlink;
308 __le32 rdev;
309};
310
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100311struct squashfs_ldev_inode {
312 __le16 inode_type;
313 __le16 mode;
314 __le16 uid;
315 __le16 guid;
316 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000317 __le32 inode_number;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100318 __le32 nlink;
319 __le32 rdev;
320 __le32 xattr;
321};
322
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000323struct squashfs_symlink_inode {
324 __le16 inode_type;
325 __le16 mode;
326 __le16 uid;
327 __le16 guid;
328 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000329 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000330 __le32 nlink;
331 __le32 symlink_size;
332 char symlink[0];
333};
334
335struct squashfs_reg_inode {
336 __le16 inode_type;
337 __le16 mode;
338 __le16 uid;
339 __le16 guid;
340 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000341 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000342 __le32 start_block;
343 __le32 fragment;
344 __le32 offset;
345 __le32 file_size;
346 __le16 block_list[0];
347};
348
349struct squashfs_lreg_inode {
350 __le16 inode_type;
351 __le16 mode;
352 __le16 uid;
353 __le16 guid;
354 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000355 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000356 __le64 start_block;
357 __le64 file_size;
358 __le64 sparse;
359 __le32 nlink;
360 __le32 fragment;
361 __le32 offset;
362 __le32 xattr;
363 __le16 block_list[0];
364};
365
366struct squashfs_dir_inode {
367 __le16 inode_type;
368 __le16 mode;
369 __le16 uid;
370 __le16 guid;
371 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000372 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000373 __le32 start_block;
374 __le32 nlink;
375 __le16 file_size;
376 __le16 offset;
377 __le32 parent_inode;
378};
379
380struct squashfs_ldir_inode {
381 __le16 inode_type;
382 __le16 mode;
383 __le16 uid;
384 __le16 guid;
385 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000386 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000387 __le32 nlink;
388 __le32 file_size;
389 __le32 start_block;
390 __le32 parent_inode;
391 __le16 i_count;
392 __le16 offset;
393 __le32 xattr;
394 struct squashfs_dir_index index[0];
395};
396
397union squashfs_inode {
398 struct squashfs_base_inode base;
399 struct squashfs_dev_inode dev;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100400 struct squashfs_ldev_inode ldev;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000401 struct squashfs_symlink_inode symlink;
402 struct squashfs_reg_inode reg;
403 struct squashfs_lreg_inode lreg;
404 struct squashfs_dir_inode dir;
405 struct squashfs_ldir_inode ldir;
406 struct squashfs_ipc_inode ipc;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100407 struct squashfs_lipc_inode lipc;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000408};
409
410struct squashfs_dir_entry {
411 __le16 offset;
412 __le16 inode_number;
413 __le16 type;
414 __le16 size;
415 char name[0];
416};
417
418struct squashfs_dir_header {
419 __le32 count;
420 __le32 start_block;
421 __le32 inode_number;
422};
423
424struct squashfs_fragment_entry {
425 __le64 start_block;
426 __le32 size;
427 unsigned int unused;
428};
429
Phillip Lougherf41d2072010-05-17 03:17:04 +0100430struct squashfs_xattr_entry {
431 __le16 type;
432 __le16 size;
433 char data[0];
434};
435
436struct squashfs_xattr_val {
437 __le32 vsize;
438 char value[0];
439};
440
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100441struct squashfs_xattr_id {
442 __le64 xattr;
443 __le32 count;
444 __le32 size;
445};
446
447struct squashfs_xattr_id_table {
448 __le64 xattr_table_start;
449 __le32 xattr_ids;
450 __le32 unused;
451};
452
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000453#endif