xref: /openbmc/linux/fs/squashfs/squashfs_fs.h (revision 2359ccdd)
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 
34 /* 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 
41 #define SQUASHFS_FILE_MAX_SIZE		1048576
42 #define SQUASHFS_FILE_MAX_LOG		20
43 
44 /* Max length of filename (not 255) */
45 #define SQUASHFS_NAME_LEN		256
46 
47 /* Max value for directory header count*/
48 #define SQUASHFS_DIR_COUNT		256
49 
50 #define SQUASHFS_INVALID_FRAG		(0xffffffffU)
51 #define SQUASHFS_INVALID_XATTR		(0xffffffffU)
52 #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
62 #define SQUASHFS_COMP_OPT		10
63 
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 
87 #define SQUASHFS_COMP_OPTS(flags)		SQUASHFS_BIT(flags, \
88 						SQUASHFS_COMP_OPT)
89 
90 /* Inode types including extended 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 
106 /* Max type value stored in directory entry */
107 #define SQUASHFS_MAX_DIR_TYPE		7
108 
109 /* Xattr types */
110 #define SQUASHFS_XATTR_USER             0
111 #define SQUASHFS_XATTR_TRUSTED          1
112 #define SQUASHFS_XATTR_SECURITY         2
113 #define SQUASHFS_XATTR_VALUE_OOL        256
114 #define SQUASHFS_XATTR_PREFIX_MASK      0xff
115 
116 /* Flag whether block is compressed or uncompressed, bit is set if block is
117  * uncompressed */
118 #define SQUASHFS_COMPRESSED_BIT		(1 << 15)
119 
120 #define SQUASHFS_COMPRESSED_SIZE(B)	(((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
121 		(B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)
122 
123 #define SQUASHFS_COMPRESSED(B)		(!((B) & SQUASHFS_COMPRESSED_BIT))
124 
125 #define SQUASHFS_COMPRESSED_BIT_BLOCK	(1 << 24)
126 
127 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)	((B) & \
128 						~SQUASHFS_COMPRESSED_BIT_BLOCK)
129 
130 #define SQUASHFS_COMPRESSED_BLOCK(B)	(!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
131 
132 /*
133  * Inode number ops.  Inodes consist of a compressed block number, and an
134  * uncompressed offset within that block
135  */
136 #define SQUASHFS_INODE_BLK(A)		((unsigned int) ((A) >> 16))
137 
138 #define SQUASHFS_INODE_OFFSET(A)	((unsigned int) ((A) & 0xffff))
139 
140 #define SQUASHFS_MKINODE(A, B)		((long long)(((long long) (A)\
141 					<< 16) + (B)))
142 
143 /* fragment and fragment table defines */
144 #define SQUASHFS_FRAGMENT_BYTES(A)	\
145 				((A) * sizeof(struct squashfs_fragment_entry))
146 
147 #define SQUASHFS_FRAGMENT_INDEX(A)	(SQUASHFS_FRAGMENT_BYTES(A) / \
148 					SQUASHFS_METADATA_SIZE)
149 
150 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)	(SQUASHFS_FRAGMENT_BYTES(A) % \
151 						SQUASHFS_METADATA_SIZE)
152 
153 #define SQUASHFS_FRAGMENT_INDEXES(A)	((SQUASHFS_FRAGMENT_BYTES(A) + \
154 					SQUASHFS_METADATA_SIZE - 1) / \
155 					SQUASHFS_METADATA_SIZE)
156 
157 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A)	(SQUASHFS_FRAGMENT_INDEXES(A) *\
158 						sizeof(u64))
159 
160 /* inode lookup table defines */
161 #define SQUASHFS_LOOKUP_BYTES(A)	((A) * sizeof(u64))
162 
163 #define SQUASHFS_LOOKUP_BLOCK(A)	(SQUASHFS_LOOKUP_BYTES(A) / \
164 					SQUASHFS_METADATA_SIZE)
165 
166 #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A)	(SQUASHFS_LOOKUP_BYTES(A) % \
167 					SQUASHFS_METADATA_SIZE)
168 
169 #define SQUASHFS_LOOKUP_BLOCKS(A)	((SQUASHFS_LOOKUP_BYTES(A) + \
170 					SQUASHFS_METADATA_SIZE - 1) / \
171 					SQUASHFS_METADATA_SIZE)
172 
173 #define SQUASHFS_LOOKUP_BLOCK_BYTES(A)	(SQUASHFS_LOOKUP_BLOCKS(A) *\
174 					sizeof(u64))
175 
176 /* uid/gid lookup table defines */
177 #define SQUASHFS_ID_BYTES(A)		((A) * sizeof(unsigned int))
178 
179 #define SQUASHFS_ID_BLOCK(A)		(SQUASHFS_ID_BYTES(A) / \
180 					SQUASHFS_METADATA_SIZE)
181 
182 #define SQUASHFS_ID_BLOCK_OFFSET(A)	(SQUASHFS_ID_BYTES(A) % \
183 					SQUASHFS_METADATA_SIZE)
184 
185 #define SQUASHFS_ID_BLOCKS(A)		((SQUASHFS_ID_BYTES(A) + \
186 					SQUASHFS_METADATA_SIZE - 1) / \
187 					SQUASHFS_METADATA_SIZE)
188 
189 #define SQUASHFS_ID_BLOCK_BYTES(A)	(SQUASHFS_ID_BLOCKS(A) *\
190 					sizeof(u64))
191 /* xattr id lookup table defines */
192 #define SQUASHFS_XATTR_BYTES(A)		((A) * sizeof(struct squashfs_xattr_id))
193 
194 #define SQUASHFS_XATTR_BLOCK(A)		(SQUASHFS_XATTR_BYTES(A) / \
195 					SQUASHFS_METADATA_SIZE)
196 
197 #define SQUASHFS_XATTR_BLOCK_OFFSET(A)	(SQUASHFS_XATTR_BYTES(A) % \
198 					SQUASHFS_METADATA_SIZE)
199 
200 #define SQUASHFS_XATTR_BLOCKS(A)	((SQUASHFS_XATTR_BYTES(A) + \
201 					SQUASHFS_METADATA_SIZE - 1) / \
202 					SQUASHFS_METADATA_SIZE)
203 
204 #define SQUASHFS_XATTR_BLOCK_BYTES(A)	(SQUASHFS_XATTR_BLOCKS(A) *\
205 					sizeof(u64))
206 #define SQUASHFS_XATTR_BLK(A)		((unsigned int) ((A) >> 16))
207 
208 #define SQUASHFS_XATTR_OFFSET(A)	((unsigned int) ((A) & 0xffff))
209 
210 /* cached data constants for filesystem */
211 #define SQUASHFS_CACHED_BLKS		8
212 
213 /* meta index cache */
214 #define SQUASHFS_META_INDEXES	(SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
215 #define SQUASHFS_META_ENTRIES	127
216 #define SQUASHFS_META_SLOTS	8
217 
218 struct meta_entry {
219 	u64			data_block;
220 	unsigned int		index_block;
221 	unsigned short		offset;
222 	unsigned short		pad;
223 };
224 
225 struct meta_index {
226 	unsigned int		inode_number;
227 	unsigned int		offset;
228 	unsigned short		entries;
229 	unsigned short		skip;
230 	unsigned short		locked;
231 	unsigned short		pad;
232 	struct meta_entry	meta_entry[SQUASHFS_META_ENTRIES];
233 };
234 
235 
236 /*
237  * definitions for structures on disk
238  */
239 #define ZLIB_COMPRESSION	1
240 #define LZMA_COMPRESSION	2
241 #define LZO_COMPRESSION		3
242 #define XZ_COMPRESSION		4
243 #define LZ4_COMPRESSION		5
244 #define ZSTD_COMPRESSION	6
245 
246 struct squashfs_super_block {
247 	__le32			s_magic;
248 	__le32			inodes;
249 	__le32			mkfs_time;
250 	__le32			block_size;
251 	__le32			fragments;
252 	__le16			compression;
253 	__le16			block_log;
254 	__le16			flags;
255 	__le16			no_ids;
256 	__le16			s_major;
257 	__le16			s_minor;
258 	__le64			root_inode;
259 	__le64			bytes_used;
260 	__le64			id_table_start;
261 	__le64			xattr_id_table_start;
262 	__le64			inode_table_start;
263 	__le64			directory_table_start;
264 	__le64			fragment_table_start;
265 	__le64			lookup_table_start;
266 };
267 
268 struct squashfs_dir_index {
269 	__le32			index;
270 	__le32			start_block;
271 	__le32			size;
272 	unsigned char		name[0];
273 };
274 
275 struct squashfs_base_inode {
276 	__le16			inode_type;
277 	__le16			mode;
278 	__le16			uid;
279 	__le16			guid;
280 	__le32			mtime;
281 	__le32			inode_number;
282 };
283 
284 struct squashfs_ipc_inode {
285 	__le16			inode_type;
286 	__le16			mode;
287 	__le16			uid;
288 	__le16			guid;
289 	__le32			mtime;
290 	__le32			inode_number;
291 	__le32			nlink;
292 };
293 
294 struct squashfs_lipc_inode {
295 	__le16			inode_type;
296 	__le16			mode;
297 	__le16			uid;
298 	__le16			guid;
299 	__le32			mtime;
300 	__le32			inode_number;
301 	__le32			nlink;
302 	__le32			xattr;
303 };
304 
305 struct squashfs_dev_inode {
306 	__le16			inode_type;
307 	__le16			mode;
308 	__le16			uid;
309 	__le16			guid;
310 	__le32			mtime;
311 	__le32			inode_number;
312 	__le32			nlink;
313 	__le32			rdev;
314 };
315 
316 struct squashfs_ldev_inode {
317 	__le16			inode_type;
318 	__le16			mode;
319 	__le16			uid;
320 	__le16			guid;
321 	__le32			mtime;
322 	__le32			inode_number;
323 	__le32			nlink;
324 	__le32			rdev;
325 	__le32			xattr;
326 };
327 
328 struct squashfs_symlink_inode {
329 	__le16			inode_type;
330 	__le16			mode;
331 	__le16			uid;
332 	__le16			guid;
333 	__le32			mtime;
334 	__le32			inode_number;
335 	__le32			nlink;
336 	__le32			symlink_size;
337 	char			symlink[0];
338 };
339 
340 struct squashfs_reg_inode {
341 	__le16			inode_type;
342 	__le16			mode;
343 	__le16			uid;
344 	__le16			guid;
345 	__le32			mtime;
346 	__le32			inode_number;
347 	__le32			start_block;
348 	__le32			fragment;
349 	__le32			offset;
350 	__le32			file_size;
351 	__le16			block_list[0];
352 };
353 
354 struct squashfs_lreg_inode {
355 	__le16			inode_type;
356 	__le16			mode;
357 	__le16			uid;
358 	__le16			guid;
359 	__le32			mtime;
360 	__le32			inode_number;
361 	__le64			start_block;
362 	__le64			file_size;
363 	__le64			sparse;
364 	__le32			nlink;
365 	__le32			fragment;
366 	__le32			offset;
367 	__le32			xattr;
368 	__le16			block_list[0];
369 };
370 
371 struct squashfs_dir_inode {
372 	__le16			inode_type;
373 	__le16			mode;
374 	__le16			uid;
375 	__le16			guid;
376 	__le32			mtime;
377 	__le32			inode_number;
378 	__le32			start_block;
379 	__le32			nlink;
380 	__le16			file_size;
381 	__le16			offset;
382 	__le32			parent_inode;
383 };
384 
385 struct squashfs_ldir_inode {
386 	__le16			inode_type;
387 	__le16			mode;
388 	__le16			uid;
389 	__le16			guid;
390 	__le32			mtime;
391 	__le32			inode_number;
392 	__le32			nlink;
393 	__le32			file_size;
394 	__le32			start_block;
395 	__le32			parent_inode;
396 	__le16			i_count;
397 	__le16			offset;
398 	__le32			xattr;
399 	struct squashfs_dir_index	index[0];
400 };
401 
402 union squashfs_inode {
403 	struct squashfs_base_inode		base;
404 	struct squashfs_dev_inode		dev;
405 	struct squashfs_ldev_inode		ldev;
406 	struct squashfs_symlink_inode		symlink;
407 	struct squashfs_reg_inode		reg;
408 	struct squashfs_lreg_inode		lreg;
409 	struct squashfs_dir_inode		dir;
410 	struct squashfs_ldir_inode		ldir;
411 	struct squashfs_ipc_inode		ipc;
412 	struct squashfs_lipc_inode		lipc;
413 };
414 
415 struct squashfs_dir_entry {
416 	__le16			offset;
417 	__le16			inode_number;
418 	__le16			type;
419 	__le16			size;
420 	char			name[0];
421 };
422 
423 struct squashfs_dir_header {
424 	__le32			count;
425 	__le32			start_block;
426 	__le32			inode_number;
427 };
428 
429 struct squashfs_fragment_entry {
430 	__le64			start_block;
431 	__le32			size;
432 	unsigned int		unused;
433 };
434 
435 struct squashfs_xattr_entry {
436 	__le16			type;
437 	__le16			size;
438 	char			data[0];
439 };
440 
441 struct squashfs_xattr_val {
442 	__le32			vsize;
443 	char			value[0];
444 };
445 
446 struct squashfs_xattr_id {
447 	__le64			xattr;
448 	__le32			count;
449 	__le32			size;
450 };
451 
452 struct squashfs_xattr_id_table {
453 	__le64			xattr_table_start;
454 	__le32			xattr_ids;
455 	__le32			unused;
456 };
457 
458 #endif
459