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