File Index
Files and directories
Sign in
FILE

squashfs_fs.h

File preview with syntax highlighting.

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