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