1 #ifndef SQUASHFS_FS
2 #define SQUASHFS_FS
3 /*
4 * Squashfs
5 *
6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
7 * Phillip Lougher <phillip@squashfs.org.uk>
8 *
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
29 #define SQUASHFS_START 0
30
31 /* size of metadata (inode and directory) blocks */
32 #define SQUASHFS_METADATA_SIZE 8192
33 #define SQUASHFS_BLOCK_OFFSET 2
34
35 /* 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
42 #define SQUASHFS_FILE_MAX_SIZE 1048576
43 #define SQUASHFS_FILE_MAX_LOG 20
44
45 /* Max length of filename (not 255) */
46 #define SQUASHFS_NAME_LEN 256
47
48 /* Max value for directory header count*/
49 #define SQUASHFS_DIR_COUNT 256
50
51 #define SQUASHFS_INVALID_FRAG (0xffffffffU)
52 #define SQUASHFS_INVALID_XATTR (0xffffffffU)
53 #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
63 #define SQUASHFS_COMP_OPT 10
64
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
88 #define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
89 SQUASHFS_COMP_OPT)
90
91 /* Inode types including extended types */
92 #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
107 /* Max type value stored in directory entry */
108 #define SQUASHFS_MAX_DIR_TYPE 7
109
110 /* 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
117 /* 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
squashfs_block_size(__le32 raw)133 static inline int squashfs_block_size(__le32 raw)
134 {
135 u32 size = le32_to_cpu(raw);
136 return (size >> 25) ? -EIO : size;
137 }
138
139 /*
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
150 /* 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))
198 /* xattr id lookup table defines */
199 #define SQUASHFS_XATTR_BYTES(A) (((u64) (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))
216
217 /* cached data constants for filesystem */
218 #define SQUASHFS_CACHED_BLKS 8
219
220 /* 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
225 struct meta_entry {
226 u64 data_block;
227 unsigned int index_block;
228 unsigned short offset;
229 unsigned short pad;
230 };
231
232 struct 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 */
246 #define ZLIB_COMPRESSION 1
247 #define LZMA_COMPRESSION 2
248 #define LZO_COMPRESSION 3
249 #define XZ_COMPRESSION 4
250 #define LZ4_COMPRESSION 5
251 #define ZSTD_COMPRESSION 6
252
253 struct squashfs_super_block {
254 __le32 s_magic;
255 __le32 inodes;
256 __le32 mkfs_time;
257 __le32 block_size;
258 __le32 fragments;
259 __le16 compression;
260 __le16 block_log;
261 __le16 flags;
262 __le16 no_ids;
263 __le16 s_major;
264 __le16 s_minor;
265 __le64 root_inode;
266 __le64 bytes_used;
267 __le64 id_table_start;
268 __le64 xattr_id_table_start;
269 __le64 inode_table_start;
270 __le64 directory_table_start;
271 __le64 fragment_table_start;
272 __le64 lookup_table_start;
273 };
274
275 struct squashfs_dir_index {
276 __le32 index;
277 __le32 start_block;
278 __le32 size;
279 unsigned char name[0];
280 };
281
282 struct squashfs_base_inode {
283 __le16 inode_type;
284 __le16 mode;
285 __le16 uid;
286 __le16 guid;
287 __le32 mtime;
288 __le32 inode_number;
289 };
290
291 struct squashfs_ipc_inode {
292 __le16 inode_type;
293 __le16 mode;
294 __le16 uid;
295 __le16 guid;
296 __le32 mtime;
297 __le32 inode_number;
298 __le32 nlink;
299 };
300
301 struct squashfs_lipc_inode {
302 __le16 inode_type;
303 __le16 mode;
304 __le16 uid;
305 __le16 guid;
306 __le32 mtime;
307 __le32 inode_number;
308 __le32 nlink;
309 __le32 xattr;
310 };
311
312 struct squashfs_dev_inode {
313 __le16 inode_type;
314 __le16 mode;
315 __le16 uid;
316 __le16 guid;
317 __le32 mtime;
318 __le32 inode_number;
319 __le32 nlink;
320 __le32 rdev;
321 };
322
323 struct squashfs_ldev_inode {
324 __le16 inode_type;
325 __le16 mode;
326 __le16 uid;
327 __le16 guid;
328 __le32 mtime;
329 __le32 inode_number;
330 __le32 nlink;
331 __le32 rdev;
332 __le32 xattr;
333 };
334
335 struct squashfs_symlink_inode {
336 __le16 inode_type;
337 __le16 mode;
338 __le16 uid;
339 __le16 guid;
340 __le32 mtime;
341 __le32 inode_number;
342 __le32 nlink;
343 __le32 symlink_size;
344 char symlink[0];
345 };
346
347 struct squashfs_reg_inode {
348 __le16 inode_type;
349 __le16 mode;
350 __le16 uid;
351 __le16 guid;
352 __le32 mtime;
353 __le32 inode_number;
354 __le32 start_block;
355 __le32 fragment;
356 __le32 offset;
357 __le32 file_size;
358 __le16 block_list[0];
359 };
360
361 struct squashfs_lreg_inode {
362 __le16 inode_type;
363 __le16 mode;
364 __le16 uid;
365 __le16 guid;
366 __le32 mtime;
367 __le32 inode_number;
368 __le64 start_block;
369 __le64 file_size;
370 __le64 sparse;
371 __le32 nlink;
372 __le32 fragment;
373 __le32 offset;
374 __le32 xattr;
375 __le16 block_list[0];
376 };
377
378 struct squashfs_dir_inode {
379 __le16 inode_type;
380 __le16 mode;
381 __le16 uid;
382 __le16 guid;
383 __le32 mtime;
384 __le32 inode_number;
385 __le32 start_block;
386 __le32 nlink;
387 __le16 file_size;
388 __le16 offset;
389 __le32 parent_inode;
390 };
391
392 struct squashfs_ldir_inode {
393 __le16 inode_type;
394 __le16 mode;
395 __le16 uid;
396 __le16 guid;
397 __le32 mtime;
398 __le32 inode_number;
399 __le32 nlink;
400 __le32 file_size;
401 __le32 start_block;
402 __le32 parent_inode;
403 __le16 i_count;
404 __le16 offset;
405 __le32 xattr;
406 struct squashfs_dir_index index[0];
407 };
408
409 union squashfs_inode {
410 struct squashfs_base_inode base;
411 struct squashfs_dev_inode dev;
412 struct squashfs_ldev_inode ldev;
413 struct squashfs_symlink_inode symlink;
414 struct squashfs_reg_inode reg;
415 struct squashfs_lreg_inode lreg;
416 struct squashfs_dir_inode dir;
417 struct squashfs_ldir_inode ldir;
418 struct squashfs_ipc_inode ipc;
419 struct squashfs_lipc_inode lipc;
420 };
421
422 struct squashfs_dir_entry {
423 __le16 offset;
424 __le16 inode_number;
425 __le16 type;
426 __le16 size;
427 char name[0];
428 };
429
430 struct squashfs_dir_header {
431 __le32 count;
432 __le32 start_block;
433 __le32 inode_number;
434 };
435
436 struct squashfs_fragment_entry {
437 __le64 start_block;
438 __le32 size;
439 unsigned int unused;
440 };
441
442 struct squashfs_xattr_entry {
443 __le16 type;
444 __le16 size;
445 char data[0];
446 };
447
448 struct squashfs_xattr_val {
449 __le32 vsize;
450 char value[0];
451 };
452
453 struct squashfs_xattr_id {
454 __le64 xattr;
455 __le32 count;
456 __le32 size;
457 };
458
459 struct squashfs_xattr_id_table {
460 __le64 xattr_table_start;
461 __le32 xattr_ids;
462 __le32 unused;
463 };
464
465 #endif
466