• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SQUASHFS_FS
2 #define SQUASHFS_FS
3 /*
4  * Squashfs
5  *
6  * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012,
7  * 2013, 2014
8  * Phillip Lougher <phillip@squashfs.org.uk>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2,
13  * or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  * squashfs_fs.h
25  */
26 
27 #define SQUASHFS_CACHED_FRAGMENTS	CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
28 #define SQUASHFS_MAJOR			4
29 #define SQUASHFS_MINOR			0
30 #define SQUASHFS_MAGIC			0x73717368
31 #define SQUASHFS_MAGIC_SWAP		0x68737173
32 #define SQUASHFS_START			0
33 
34 /* size of metadata (inode and directory) blocks */
35 #define SQUASHFS_METADATA_SIZE		8192
36 #define SQUASHFS_METADATA_LOG		13
37 
38 /* default size of data blocks */
39 #define SQUASHFS_FILE_SIZE		131072
40 
41 #define SQUASHFS_FILE_MAX_SIZE		1048576
42 #define SQUASHFS_FILE_MAX_LOG		20
43 
44 /* Max number of uids and gids */
45 #define SQUASHFS_IDS			65536
46 
47 /* Max length of filename (not 255) */
48 #define SQUASHFS_NAME_LEN		256
49 
50 #define SQUASHFS_INVALID		((long long) 0xffffffffffff)
51 #define SQUASHFS_INVALID_FRAG		((unsigned int) 0xffffffff)
52 #define SQUASHFS_INVALID_XATTR		((unsigned int) 0xffffffff)
53 #define SQUASHFS_INVALID_BLK		((long long) -1)
54 #define SQUASHFS_USED_BLK		((long long) -2)
55 
56 /* Filesystem flags */
57 #define SQUASHFS_NOI			0
58 #define SQUASHFS_NOD			1
59 #define SQUASHFS_CHECK			2
60 #define SQUASHFS_NOF			3
61 #define SQUASHFS_NO_FRAG		4
62 #define SQUASHFS_ALWAYS_FRAG		5
63 #define SQUASHFS_DUPLICATE		6
64 #define SQUASHFS_EXPORT			7
65 #define SQUASHFS_NOX			8
66 #define SQUASHFS_NO_XATTR		9
67 #define SQUASHFS_COMP_OPT		10
68 
69 #define SQUASHFS_BIT(flag, bit)		((flag >> bit) & 1)
70 
71 #define SQUASHFS_UNCOMPRESSED_INODES(flags)	SQUASHFS_BIT(flags, \
72 						SQUASHFS_NOI)
73 
74 #define SQUASHFS_UNCOMPRESSED_DATA(flags)	SQUASHFS_BIT(flags, \
75 						SQUASHFS_NOD)
76 
77 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)	SQUASHFS_BIT(flags, \
78 						SQUASHFS_NOF)
79 
80 #define SQUASHFS_NO_FRAGMENTS(flags)		SQUASHFS_BIT(flags, \
81 						SQUASHFS_NO_FRAG)
82 
83 #define SQUASHFS_ALWAYS_FRAGMENTS(flags)	SQUASHFS_BIT(flags, \
84 						SQUASHFS_ALWAYS_FRAG)
85 
86 #define SQUASHFS_DUPLICATES(flags)		SQUASHFS_BIT(flags, \
87 						SQUASHFS_DUPLICATE)
88 
89 #define SQUASHFS_EXPORTABLE(flags)		SQUASHFS_BIT(flags, \
90 						SQUASHFS_EXPORT)
91 
92 #define SQUASHFS_UNCOMPRESSED_XATTRS(flags)	SQUASHFS_BIT(flags, \
93 						SQUASHFS_NOX)
94 
95 #define SQUASHFS_NO_XATTRS(flags)		SQUASHFS_BIT(flags, \
96 						SQUASHFS_NO_XATTR)
97 
98 #define SQUASHFS_COMP_OPTS(flags)		SQUASHFS_BIT(flags, \
99 						SQUASHFS_COMP_OPT)
100 
101 #define SQUASHFS_MKFLAGS(noi, nod, nof, nox, no_frag, always_frag, \
102 		duplicate_checking, exportable, no_xattr, comp_opt) (noi | \
103 		(nod << 1) | (nof << 3) | (no_frag << 4) | \
104 		(always_frag << 5) | (duplicate_checking << 6) | \
105 		(exportable << 7) | (nox << 8) | (no_xattr << 9) | \
106 		(comp_opt << 10))
107 
108 /* Max number of types and file types */
109 #define SQUASHFS_DIR_TYPE		1
110 #define SQUASHFS_FILE_TYPE		2
111 #define SQUASHFS_SYMLINK_TYPE		3
112 #define SQUASHFS_BLKDEV_TYPE		4
113 #define SQUASHFS_CHRDEV_TYPE		5
114 #define SQUASHFS_FIFO_TYPE		6
115 #define SQUASHFS_SOCKET_TYPE		7
116 #define SQUASHFS_LDIR_TYPE		8
117 #define SQUASHFS_LREG_TYPE		9
118 #define SQUASHFS_LSYMLINK_TYPE		10
119 #define SQUASHFS_LBLKDEV_TYPE		11
120 #define SQUASHFS_LCHRDEV_TYPE		12
121 #define SQUASHFS_LFIFO_TYPE		13
122 #define SQUASHFS_LSOCKET_TYPE		14
123 
124 /* Xattr types */
125 #define SQUASHFS_XATTR_USER		0
126 #define SQUASHFS_XATTR_TRUSTED		1
127 #define SQUASHFS_XATTR_SECURITY		2
128 #define SQUASHFS_XATTR_VALUE_OOL	256
129 #define SQUASHFS_XATTR_PREFIX_MASK	0xff
130 
131 /* Flag whether block is compressed or uncompressed, bit is set if block is
132  * uncompressed */
133 #define SQUASHFS_COMPRESSED_BIT		(1 << 15)
134 
135 #define SQUASHFS_COMPRESSED_SIZE(B)	(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
136 		(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)
137 
138 #define SQUASHFS_COMPRESSED(B)		(!((B) & SQUASHFS_COMPRESSED_BIT))
139 
140 #define SQUASHFS_COMPRESSED_BIT_BLOCK		(1 << 24)
141 
142 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)	((B) & \
143 	~SQUASHFS_COMPRESSED_BIT_BLOCK)
144 
145 #define SQUASHFS_COMPRESSED_BLOCK(B)	(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
146 
147 /*
148  * Inode number ops.  Inodes consist of a compressed block number, and an
149  * uncompressed  offset within that block
150  */
151 #define SQUASHFS_INODE_BLK(a)		((unsigned int) ((a) >> 16))
152 
153 #define SQUASHFS_INODE_OFFSET(a)	((unsigned int) ((a) & 0xffff))
154 
155 #define SQUASHFS_MKINODE(A, B)		((squashfs_inode)(((squashfs_inode) (A)\
156 					<< 16) + (B)))
157 
158 /* Compute 32 bit VFS inode number from squashfs inode number */
159 #define SQUASHFS_MK_VFS_INODE(a, b)	((unsigned int) (((a) << 8) + \
160 					((b) >> 2) + 1))
161 
162 /* Translate between VFS mode and squashfs mode */
163 #define SQUASHFS_MODE(a)		((a) & 0xfff)
164 
165 /* fragment and fragment table defines */
166 #define SQUASHFS_FRAGMENT_BYTES(A)	((A) * \
167 					sizeof(struct squashfs_fragment_entry))
168 
169 #define SQUASHFS_FRAGMENT_INDEX(A)	(SQUASHFS_FRAGMENT_BYTES(A) / \
170 					SQUASHFS_METADATA_SIZE)
171 
172 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)	(SQUASHFS_FRAGMENT_BYTES(A) % \
173 						SQUASHFS_METADATA_SIZE)
174 
175 #define SQUASHFS_FRAGMENT_INDEXES(A)	((SQUASHFS_FRAGMENT_BYTES(A) + \
176 					SQUASHFS_METADATA_SIZE - 1) / \
177 					SQUASHFS_METADATA_SIZE)
178 
179 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A)	(SQUASHFS_FRAGMENT_INDEXES(A) *\
180 						sizeof(long long))
181 
182 /* inode lookup table defines */
183 #define SQUASHFS_LOOKUP_BYTES(A)	((A) * sizeof(squashfs_inode))
184 
185 #define SQUASHFS_LOOKUP_BLOCK(A)		(SQUASHFS_LOOKUP_BYTES(A) / \
186 						SQUASHFS_METADATA_SIZE)
187 
188 #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)		(SQUASHFS_LOOKUP_BYTES(A) % \
189 						SQUASHFS_METADATA_SIZE)
190 
191 #define SQUASHFS_LOOKUP_BLOCKS(A)	((SQUASHFS_LOOKUP_BYTES(A) + \
192 					SQUASHFS_METADATA_SIZE - 1) / \
193 					SQUASHFS_METADATA_SIZE)
194 
195 #define SQUASHFS_LOOKUP_BLOCK_BYTES(A)	(SQUASHFS_LOOKUP_BLOCKS(A) *\
196 					sizeof(long long))
197 
198 /* uid lookup table defines */
199 #define SQUASHFS_ID_BYTES(A)	((A) * sizeof(unsigned int))
200 
201 #define SQUASHFS_ID_BLOCK(A)		(SQUASHFS_ID_BYTES(A) / \
202 						SQUASHFS_METADATA_SIZE)
203 
204 #define SQUASHFS_ID_BLOCK_OFFSET(A)		(SQUASHFS_ID_BYTES(A) % \
205 						SQUASHFS_METADATA_SIZE)
206 
207 #define SQUASHFS_ID_BLOCKS(A)	((SQUASHFS_ID_BYTES(A) + \
208 					SQUASHFS_METADATA_SIZE - 1) / \
209 					SQUASHFS_METADATA_SIZE)
210 
211 #define SQUASHFS_ID_BLOCK_BYTES(A)	(SQUASHFS_ID_BLOCKS(A) *\
212 					sizeof(long long))
213 
214 /* xattr id lookup table defines */
215 #define SQUASHFS_XATTR_BYTES(A)		((A) * sizeof(struct squashfs_xattr_id))
216 
217 #define SQUASHFS_XATTR_BLOCK(A)		(SQUASHFS_XATTR_BYTES(A) / \
218 					SQUASHFS_METADATA_SIZE)
219 
220 #define SQUASHFS_XATTR_BLOCK_OFFSET(A)	(SQUASHFS_XATTR_BYTES(A) % \
221 					SQUASHFS_METADATA_SIZE)
222 
223 #define SQUASHFS_XATTR_BLOCKS(A)	((SQUASHFS_XATTR_BYTES(A) + \
224 					SQUASHFS_METADATA_SIZE - 1) / \
225 					SQUASHFS_METADATA_SIZE)
226 
227 #define SQUASHFS_XATTR_BLOCK_BYTES(A)	(SQUASHFS_XATTR_BLOCKS(A) *\
228 					sizeof(long long))
229 
230 #define SQUASHFS_XATTR_BLK(A)		((unsigned int) ((A) >> 16))
231 
232 #define SQUASHFS_XATTR_OFFSET(A)	((unsigned int) ((A) & 0xffff))
233 
234 /* cached data constants for filesystem */
235 #define SQUASHFS_CACHED_BLKS		8
236 
237 #define SQUASHFS_MAX_FILE_SIZE_LOG	64
238 
239 #define SQUASHFS_MAX_FILE_SIZE		((long long) 1 << \
240 					(SQUASHFS_MAX_FILE_SIZE_LOG - 2))
241 
242 #define SQUASHFS_MARKER_BYTE		0xff
243 
244 /* meta index cache */
245 #define SQUASHFS_META_INDEXES	(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
246 #define SQUASHFS_META_ENTRIES	31
247 #define SQUASHFS_META_NUMBER	8
248 #define SQUASHFS_SLOTS		4
249 
250 struct meta_entry {
251 	long long		data_block;
252 	unsigned int		index_block;
253 	unsigned short		offset;
254 	unsigned short		pad;
255 };
256 
257 struct meta_index {
258 	unsigned int		inode_number;
259 	unsigned int		offset;
260 	unsigned short		entries;
261 	unsigned short		skip;
262 	unsigned short		locked;
263 	unsigned short		pad;
264 	struct meta_entry	meta_entry[SQUASHFS_META_ENTRIES];
265 };
266 
267 
268 /*
269  * definitions for structures on disk
270  */
271 
272 typedef long long		squashfs_block;
273 typedef long long		squashfs_inode;
274 
275 #define ZLIB_COMPRESSION	1
276 #define LZMA_COMPRESSION	2
277 #define LZO_COMPRESSION		3
278 #define XZ_COMPRESSION		4
279 #define LZ4_COMPRESSION		5
280 
281 struct squashfs_super_block {
282 	unsigned int		s_magic;
283 	unsigned int		inodes;
284 	int			mkfs_time /* time of filesystem creation */;
285 	unsigned int		block_size;
286 	unsigned int		fragments;
287 	unsigned short		compression;
288 	unsigned short		block_log;
289 	unsigned short		flags;
290 	unsigned short		no_ids;
291 	unsigned short		s_major;
292 	unsigned short		s_minor;
293 	squashfs_inode		root_inode;
294 	long long		bytes_used;
295 	long long		id_table_start;
296 	long long		xattr_id_table_start;
297 	long long		inode_table_start;
298 	long long		directory_table_start;
299 	long long		fragment_table_start;
300 	long long		lookup_table_start;
301 };
302 
303 struct squashfs_dir_index {
304 	unsigned int		index;
305 	unsigned int		start_block;
306 	unsigned int		size;
307 	unsigned char		name[0];
308 };
309 
310 struct squashfs_base_inode_header {
311 	unsigned short		inode_type;
312 	unsigned short		mode;
313 	unsigned short		uid;
314 	unsigned short		guid;
315 	int			mtime;
316 	unsigned int 		inode_number;
317 };
318 
319 struct squashfs_ipc_inode_header {
320 	unsigned short		inode_type;
321 	unsigned short		mode;
322 	unsigned short		uid;
323 	unsigned short		guid;
324 	int			mtime;
325 	unsigned int 		inode_number;
326 	unsigned int		nlink;
327 };
328 
329 struct squashfs_lipc_inode_header {
330 	unsigned short		inode_type;
331 	unsigned short		mode;
332 	unsigned short		uid;
333 	unsigned short		guid;
334 	int			mtime;
335 	unsigned int 		inode_number;
336 	unsigned int		nlink;
337 	unsigned int		xattr;
338 };
339 
340 struct squashfs_dev_inode_header {
341 	unsigned short		inode_type;
342 	unsigned short		mode;
343 	unsigned short		uid;
344 	unsigned short		guid;
345 	int			mtime;
346 	unsigned int 		inode_number;
347 	unsigned int		nlink;
348 	unsigned int		rdev;
349 };
350 
351 struct squashfs_ldev_inode_header {
352 	unsigned short		inode_type;
353 	unsigned short		mode;
354 	unsigned short		uid;
355 	unsigned short		guid;
356 	int			mtime;
357 	unsigned int 		inode_number;
358 	unsigned int		nlink;
359 	unsigned int		rdev;
360 	unsigned int		xattr;
361 };
362 
363 struct squashfs_symlink_inode_header {
364 	unsigned short		inode_type;
365 	unsigned short		mode;
366 	unsigned short		uid;
367 	unsigned short		guid;
368 	int			mtime;
369 	unsigned int 		inode_number;
370 	unsigned int		nlink;
371 	unsigned int		symlink_size;
372 	char			symlink[0];
373 };
374 
375 struct squashfs_reg_inode_header {
376 	unsigned short		inode_type;
377 	unsigned short		mode;
378 	unsigned short		uid;
379 	unsigned short		guid;
380 	int			mtime;
381 	unsigned int 		inode_number;
382 	unsigned int		start_block;
383 	unsigned int		fragment;
384 	unsigned int		offset;
385 	unsigned int		file_size;
386 	unsigned int		block_list[0];
387 };
388 
389 struct squashfs_lreg_inode_header {
390 	unsigned short		inode_type;
391 	unsigned short		mode;
392 	unsigned short		uid;
393 	unsigned short		guid;
394 	int			mtime;
395 	unsigned int 		inode_number;
396 	squashfs_block		start_block;
397 	long long		file_size;
398 	long long		sparse;
399 	unsigned int		nlink;
400 	unsigned int		fragment;
401 	unsigned int		offset;
402 	unsigned int		xattr;
403 	unsigned int		block_list[0];
404 };
405 
406 struct squashfs_dir_inode_header {
407 	unsigned short		inode_type;
408 	unsigned short		mode;
409 	unsigned short		uid;
410 	unsigned short		guid;
411 	int			mtime;
412 	unsigned int 		inode_number;
413 	unsigned int		start_block;
414 	unsigned int		nlink;
415 	unsigned short		file_size;
416 	unsigned short		offset;
417 	unsigned int		parent_inode;
418 };
419 
420 struct squashfs_ldir_inode_header {
421 	unsigned short		inode_type;
422 	unsigned short		mode;
423 	unsigned short		uid;
424 	unsigned short		guid;
425 	int			mtime;
426 	unsigned int 		inode_number;
427 	unsigned int		nlink;
428 	unsigned int		file_size;
429 	unsigned int		start_block;
430 	unsigned int		parent_inode;
431 	unsigned short		i_count;
432 	unsigned short		offset;
433 	unsigned int		xattr;
434 	struct squashfs_dir_index	index[0];
435 };
436 
437 union squashfs_inode_header {
438 	struct squashfs_base_inode_header	base;
439 	struct squashfs_dev_inode_header	dev;
440 	struct squashfs_ldev_inode_header	ldev;
441 	struct squashfs_symlink_inode_header	symlink;
442 	struct squashfs_reg_inode_header	reg;
443 	struct squashfs_lreg_inode_header	lreg;
444 	struct squashfs_dir_inode_header	dir;
445 	struct squashfs_ldir_inode_header	ldir;
446 	struct squashfs_ipc_inode_header	ipc;
447 	struct squashfs_lipc_inode_header	lipc;
448 };
449 
450 struct squashfs_dir_entry {
451 	unsigned short		offset;
452 	short			inode_number;
453 	unsigned short		type;
454 	unsigned short		size;
455 	char			name[0];
456 };
457 
458 struct squashfs_dir_header {
459 	unsigned int		count;
460 	unsigned int		start_block;
461 	unsigned int		inode_number;
462 };
463 
464 struct squashfs_fragment_entry {
465 	long long		start_block;
466 	unsigned int		size;
467 	unsigned int		unused;
468 };
469 
470 struct squashfs_xattr_entry {
471 	unsigned short		type;
472 	unsigned short		size;
473 };
474 
475 struct squashfs_xattr_val {
476 	unsigned int		vsize;
477 };
478 
479 struct squashfs_xattr_id {
480 	long long		xattr;
481 	unsigned int		count;
482 	unsigned int		size;
483 };
484 
485 struct squashfs_xattr_table {
486 	long long		xattr_table_start;
487 	unsigned int		xattr_ids;
488 	unsigned int		unused;
489 };
490 
491 #endif
492