blob: 2fd1262cc1bd403dc2cf6f3adc260bde8fd8708e [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
Sean Nyekjaer31daf162021-03-24 21:37:32 -070033#define SQUASHFS_BLOCK_OFFSET 2
Phillip Lougherffae2cd2009-01-05 08:46:27 +000034
Phillip Lougher7657cac2011-10-22 01:34:48 +010035/* default size of block device I/O */
36#ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
37#define SQUASHFS_DEVBLK_SIZE 4096
38#else
39#define SQUASHFS_DEVBLK_SIZE 1024
40#endif
41
Phillip Lougherffae2cd2009-01-05 08:46:27 +000042#define SQUASHFS_FILE_MAX_SIZE 1048576
43#define SQUASHFS_FILE_MAX_LOG 20
44
Phillip Lougherffae2cd2009-01-05 08:46:27 +000045/* Max length of filename (not 255) */
46#define SQUASHFS_NAME_LEN 256
47
Ajeet Yadav4826d832012-02-02 13:04:49 +053048/* Max value for directory header count*/
49#define SQUASHFS_DIR_COUNT 256
50
Phillip Lougherffae2cd2009-01-05 08:46:27 +000051#define SQUASHFS_INVALID_FRAG (0xffffffffU)
Phillip Lougherf41d2072010-05-17 03:17:04 +010052#define SQUASHFS_INVALID_XATTR (0xffffffffU)
Phillip Lougherffae2cd2009-01-05 08:46:27 +000053#define SQUASHFS_INVALID_BLK (-1LL)
54
55/* Filesystem flags */
56#define SQUASHFS_NOI 0
57#define SQUASHFS_NOD 1
58#define SQUASHFS_NOF 3
59#define SQUASHFS_NO_FRAG 4
60#define SQUASHFS_ALWAYS_FRAG 5
61#define SQUASHFS_DUPLICATE 6
62#define SQUASHFS_EXPORT 7
Phillip Lougherb7fc0ff2011-02-28 01:45:42 +000063#define SQUASHFS_COMP_OPT 10
Phillip Lougherffae2cd2009-01-05 08:46:27 +000064
65#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
66
67#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
68 SQUASHFS_NOI)
69
70#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
71 SQUASHFS_NOD)
72
73#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
74 SQUASHFS_NOF)
75
76#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
77 SQUASHFS_NO_FRAG)
78
79#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
80 SQUASHFS_ALWAYS_FRAG)
81
82#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
83 SQUASHFS_DUPLICATE)
84
85#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
86 SQUASHFS_EXPORT)
87
Phillip Lougherb7fc0ff2011-02-28 01:45:42 +000088#define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
89 SQUASHFS_COMP_OPT)
90
Phillip Lougher9e012422013-09-04 02:58:12 +010091/* Inode types including extended types */
Phillip Lougherffae2cd2009-01-05 08:46:27 +000092#define SQUASHFS_DIR_TYPE 1
93#define SQUASHFS_REG_TYPE 2
94#define SQUASHFS_SYMLINK_TYPE 3
95#define SQUASHFS_BLKDEV_TYPE 4
96#define SQUASHFS_CHRDEV_TYPE 5
97#define SQUASHFS_FIFO_TYPE 6
98#define SQUASHFS_SOCKET_TYPE 7
99#define SQUASHFS_LDIR_TYPE 8
100#define SQUASHFS_LREG_TYPE 9
101#define SQUASHFS_LSYMLINK_TYPE 10
102#define SQUASHFS_LBLKDEV_TYPE 11
103#define SQUASHFS_LCHRDEV_TYPE 12
104#define SQUASHFS_LFIFO_TYPE 13
105#define SQUASHFS_LSOCKET_TYPE 14
106
Phillip Lougher9e012422013-09-04 02:58:12 +0100107/* Max type value stored in directory entry */
108#define SQUASHFS_MAX_DIR_TYPE 7
109
Phillip Lougherf41d2072010-05-17 03:17:04 +0100110/* Xattr types */
111#define SQUASHFS_XATTR_USER 0
112#define SQUASHFS_XATTR_TRUSTED 1
113#define SQUASHFS_XATTR_SECURITY 2
114#define SQUASHFS_XATTR_VALUE_OOL 256
115#define SQUASHFS_XATTR_PREFIX_MASK 0xff
116
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000117/* Flag whether block is compressed or uncompressed, bit is set if block is
118 * uncompressed */
119#define SQUASHFS_COMPRESSED_BIT (1 << 15)
120
121#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
122 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
123
124#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
125
126#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
127
128#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
129 ~SQUASHFS_COMPRESSED_BIT_BLOCK)
130
131#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
132
Linus Torvalds1aecbe42018-07-29 12:44:46 -0700133static inline int squashfs_block_size(__le32 raw)
134{
135 u32 size = le32_to_cpu(raw);
136 return (size >> 25) ? -EIO : size;
137}
138
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000139/*
140 * Inode number ops. Inodes consist of a compressed block number, and an
141 * uncompressed offset within that block
142 */
143#define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
144
145#define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
146
147#define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
148 << 16) + (B)))
149
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000150/* fragment and fragment table defines */
151#define SQUASHFS_FRAGMENT_BYTES(A) \
152 ((A) * sizeof(struct squashfs_fragment_entry))
153
154#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
155 SQUASHFS_METADATA_SIZE)
156
157#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
158 SQUASHFS_METADATA_SIZE)
159
160#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
161 SQUASHFS_METADATA_SIZE - 1) / \
162 SQUASHFS_METADATA_SIZE)
163
164#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
165 sizeof(u64))
166
167/* inode lookup table defines */
168#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
169
170#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
171 SQUASHFS_METADATA_SIZE)
172
173#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
174 SQUASHFS_METADATA_SIZE)
175
176#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
177 SQUASHFS_METADATA_SIZE - 1) / \
178 SQUASHFS_METADATA_SIZE)
179
180#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
181 sizeof(u64))
182
183/* uid/gid lookup table defines */
184#define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
185
186#define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
187 SQUASHFS_METADATA_SIZE)
188
189#define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
190 SQUASHFS_METADATA_SIZE)
191
192#define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
193 SQUASHFS_METADATA_SIZE - 1) / \
194 SQUASHFS_METADATA_SIZE)
195
196#define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
197 sizeof(u64))
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100198/* xattr id lookup table defines */
199#define SQUASHFS_XATTR_BYTES(A) ((A) * sizeof(struct squashfs_xattr_id))
200
201#define SQUASHFS_XATTR_BLOCK(A) (SQUASHFS_XATTR_BYTES(A) / \
202 SQUASHFS_METADATA_SIZE)
203
204#define SQUASHFS_XATTR_BLOCK_OFFSET(A) (SQUASHFS_XATTR_BYTES(A) % \
205 SQUASHFS_METADATA_SIZE)
206
207#define SQUASHFS_XATTR_BLOCKS(A) ((SQUASHFS_XATTR_BYTES(A) + \
208 SQUASHFS_METADATA_SIZE - 1) / \
209 SQUASHFS_METADATA_SIZE)
210
211#define SQUASHFS_XATTR_BLOCK_BYTES(A) (SQUASHFS_XATTR_BLOCKS(A) *\
212 sizeof(u64))
213#define SQUASHFS_XATTR_BLK(A) ((unsigned int) ((A) >> 16))
214
215#define SQUASHFS_XATTR_OFFSET(A) ((unsigned int) ((A) & 0xffff))
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000216
217/* cached data constants for filesystem */
218#define SQUASHFS_CACHED_BLKS 8
219
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000220/* meta index cache */
221#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
222#define SQUASHFS_META_ENTRIES 127
223#define SQUASHFS_META_SLOTS 8
224
225struct meta_entry {
226 u64 data_block;
227 unsigned int index_block;
228 unsigned short offset;
229 unsigned short pad;
230};
231
232struct meta_index {
233 unsigned int inode_number;
234 unsigned int offset;
235 unsigned short entries;
236 unsigned short skip;
237 unsigned short locked;
238 unsigned short pad;
239 struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
240};
241
242
243/*
244 * definitions for structures on disk
245 */
Phillip Lougherdc325672009-10-14 03:58:11 +0100246#define ZLIB_COMPRESSION 1
247#define LZMA_COMPRESSION 2
248#define LZO_COMPRESSION 3
Phillip Lougher81bb8de2010-12-09 02:02:29 +0000249#define XZ_COMPRESSION 4
Phillip Lougher9c06a462014-11-27 06:49:14 +0000250#define LZ4_COMPRESSION 5
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000251
252struct squashfs_super_block {
253 __le32 s_magic;
254 __le32 inodes;
255 __le32 mkfs_time;
256 __le32 block_size;
257 __le32 fragments;
258 __le16 compression;
259 __le16 block_log;
260 __le16 flags;
261 __le16 no_ids;
262 __le16 s_major;
263 __le16 s_minor;
264 __le64 root_inode;
265 __le64 bytes_used;
266 __le64 id_table_start;
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100267 __le64 xattr_id_table_start;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000268 __le64 inode_table_start;
269 __le64 directory_table_start;
270 __le64 fragment_table_start;
271 __le64 lookup_table_start;
272};
273
274struct squashfs_dir_index {
275 __le32 index;
276 __le32 start_block;
277 __le32 size;
278 unsigned char name[0];
279};
280
281struct squashfs_base_inode {
282 __le16 inode_type;
283 __le16 mode;
284 __le16 uid;
285 __le16 guid;
286 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000287 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000288};
289
290struct squashfs_ipc_inode {
291 __le16 inode_type;
292 __le16 mode;
293 __le16 uid;
294 __le16 guid;
295 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000296 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000297 __le32 nlink;
298};
299
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100300struct squashfs_lipc_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 Lougher67f66cc2010-05-17 04:06:56 +0100307 __le32 nlink;
308 __le32 xattr;
309};
310
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000311struct squashfs_dev_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 Lougherffae2cd2009-01-05 08:46:27 +0000318 __le32 nlink;
319 __le32 rdev;
320};
321
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100322struct squashfs_ldev_inode {
323 __le16 inode_type;
324 __le16 mode;
325 __le16 uid;
326 __le16 guid;
327 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000328 __le32 inode_number;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100329 __le32 nlink;
330 __le32 rdev;
331 __le32 xattr;
332};
333
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000334struct squashfs_symlink_inode {
335 __le16 inode_type;
336 __le16 mode;
337 __le16 uid;
338 __le16 guid;
339 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000340 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000341 __le32 nlink;
342 __le32 symlink_size;
343 char symlink[0];
344};
345
346struct squashfs_reg_inode {
347 __le16 inode_type;
348 __le16 mode;
349 __le16 uid;
350 __le16 guid;
351 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000352 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000353 __le32 start_block;
354 __le32 fragment;
355 __le32 offset;
356 __le32 file_size;
357 __le16 block_list[0];
358};
359
360struct squashfs_lreg_inode {
361 __le16 inode_type;
362 __le16 mode;
363 __le16 uid;
364 __le16 guid;
365 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000366 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000367 __le64 start_block;
368 __le64 file_size;
369 __le64 sparse;
370 __le32 nlink;
371 __le32 fragment;
372 __le32 offset;
373 __le32 xattr;
374 __le16 block_list[0];
375};
376
377struct squashfs_dir_inode {
378 __le16 inode_type;
379 __le16 mode;
380 __le16 uid;
381 __le16 guid;
382 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000383 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000384 __le32 start_block;
385 __le32 nlink;
386 __le16 file_size;
387 __le16 offset;
388 __le32 parent_inode;
389};
390
391struct squashfs_ldir_inode {
392 __le16 inode_type;
393 __le16 mode;
394 __le16 uid;
395 __le16 guid;
396 __le32 mtime;
Phillip Lougher66048c32010-08-08 22:29:33 +0000397 __le32 inode_number;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000398 __le32 nlink;
399 __le32 file_size;
400 __le32 start_block;
401 __le32 parent_inode;
402 __le16 i_count;
403 __le16 offset;
404 __le32 xattr;
405 struct squashfs_dir_index index[0];
406};
407
408union squashfs_inode {
409 struct squashfs_base_inode base;
410 struct squashfs_dev_inode dev;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100411 struct squashfs_ldev_inode ldev;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000412 struct squashfs_symlink_inode symlink;
413 struct squashfs_reg_inode reg;
414 struct squashfs_lreg_inode lreg;
415 struct squashfs_dir_inode dir;
416 struct squashfs_ldir_inode ldir;
417 struct squashfs_ipc_inode ipc;
Phillip Lougher67f66cc2010-05-17 04:06:56 +0100418 struct squashfs_lipc_inode lipc;
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000419};
420
421struct squashfs_dir_entry {
422 __le16 offset;
423 __le16 inode_number;
424 __le16 type;
425 __le16 size;
426 char name[0];
427};
428
429struct squashfs_dir_header {
430 __le32 count;
431 __le32 start_block;
432 __le32 inode_number;
433};
434
435struct squashfs_fragment_entry {
436 __le64 start_block;
437 __le32 size;
438 unsigned int unused;
439};
440
Phillip Lougherf41d2072010-05-17 03:17:04 +0100441struct squashfs_xattr_entry {
442 __le16 type;
443 __le16 size;
444 char data[0];
445};
446
447struct squashfs_xattr_val {
448 __le32 vsize;
449 char value[0];
450};
451
Phillip Lougher4b5397d2010-05-14 20:48:47 +0100452struct squashfs_xattr_id {
453 __le64 xattr;
454 __le32 count;
455 __le32 size;
456};
457
458struct squashfs_xattr_id_table {
459 __le64 xattr_table_start;
460 __le32 xattr_ids;
461 __le32 unused;
462};
463
Phillip Lougherffae2cd2009-01-05 08:46:27 +0000464#endif