Linux Audio

Check our new training course

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