1 /* SPDX-License-Identifier: GPL-2.0-or-later */
7 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
8 * Phillip Lougher <phillip@squashfs.org.uk>
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
18 /* size of metadata (inode and directory) blocks */
19 #define SQUASHFS_METADATA_SIZE 8192
21 /* default size of block device I/O */
22 #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
23 #define SQUASHFS_DEVBLK_SIZE 4096
25 #define SQUASHFS_DEVBLK_SIZE 1024
28 #define SQUASHFS_FILE_MAX_SIZE 1048576
29 #define SQUASHFS_FILE_MAX_LOG 20
31 /* Max length of filename (not 255) */
32 #define SQUASHFS_NAME_LEN 256
34 /* Max value for directory header count*/
35 #define SQUASHFS_DIR_COUNT 256
37 #define SQUASHFS_INVALID_FRAG (0xffffffffU)
38 #define SQUASHFS_INVALID_XATTR (0xffffffffU)
39 #define SQUASHFS_INVALID_BLK (-1LL)
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
51 #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
53 #define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
56 #define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
59 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
62 #define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
65 #define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
68 #define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
71 #define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
74 #define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
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
93 /* Max type value stored in directory entry */
94 #define SQUASHFS_MAX_DIR_TYPE 7
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
103 /* Flag whether block is compressed or uncompressed, bit is set if block is
105 #define SQUASHFS_COMPRESSED_BIT (1 << 15)
107 #define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
108 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
110 #define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
112 #define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
114 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
115 ~SQUASHFS_COMPRESSED_BIT_BLOCK)
117 #define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
119 static inline int squashfs_block_size(__le32 raw
)
121 u32 size
= le32_to_cpu(raw
);
122 return (size
>> 25) ? -EIO
: size
;
126 * Inode number ops. Inodes consist of a compressed block number, and an
127 * uncompressed offset within that block
129 #define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
131 #define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
133 #define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
136 /* fragment and fragment table defines */
137 #define SQUASHFS_FRAGMENT_BYTES(A) \
138 ((A) * sizeof(struct squashfs_fragment_entry))
140 #define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
141 SQUASHFS_METADATA_SIZE)
143 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
144 SQUASHFS_METADATA_SIZE)
146 #define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
147 SQUASHFS_METADATA_SIZE - 1) / \
148 SQUASHFS_METADATA_SIZE)
150 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
153 /* inode lookup table defines */
154 #define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
156 #define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
157 SQUASHFS_METADATA_SIZE)
159 #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
160 SQUASHFS_METADATA_SIZE)
162 #define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
163 SQUASHFS_METADATA_SIZE - 1) / \
164 SQUASHFS_METADATA_SIZE)
166 #define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
169 /* uid/gid lookup table defines */
170 #define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
172 #define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
173 SQUASHFS_METADATA_SIZE)
175 #define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
176 SQUASHFS_METADATA_SIZE)
178 #define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
179 SQUASHFS_METADATA_SIZE - 1) / \
180 SQUASHFS_METADATA_SIZE)
182 #define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
184 /* xattr id lookup table defines */
185 #define SQUASHFS_XATTR_BYTES(A) ((A) * sizeof(struct squashfs_xattr_id))
187 #define SQUASHFS_XATTR_BLOCK(A) (SQUASHFS_XATTR_BYTES(A) / \
188 SQUASHFS_METADATA_SIZE)
190 #define SQUASHFS_XATTR_BLOCK_OFFSET(A) (SQUASHFS_XATTR_BYTES(A) % \
191 SQUASHFS_METADATA_SIZE)
193 #define SQUASHFS_XATTR_BLOCKS(A) ((SQUASHFS_XATTR_BYTES(A) + \
194 SQUASHFS_METADATA_SIZE - 1) / \
195 SQUASHFS_METADATA_SIZE)
197 #define SQUASHFS_XATTR_BLOCK_BYTES(A) (SQUASHFS_XATTR_BLOCKS(A) *\
199 #define SQUASHFS_XATTR_BLK(A) ((unsigned int) ((A) >> 16))
201 #define SQUASHFS_XATTR_OFFSET(A) ((unsigned int) ((A) & 0xffff))
203 /* cached data constants for filesystem */
204 #define SQUASHFS_CACHED_BLKS 8
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
213 unsigned int index_block
;
214 unsigned short offset
;
219 unsigned int inode_number
;
221 unsigned short entries
;
223 unsigned short locked
;
225 struct meta_entry meta_entry
[SQUASHFS_META_ENTRIES
];
230 * definitions for structures on disk
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
239 struct squashfs_super_block
{
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
;
261 struct squashfs_dir_index
{
265 unsigned char name
[0];
268 struct squashfs_base_inode
{
277 struct squashfs_ipc_inode
{
287 struct squashfs_lipc_inode
{
298 struct squashfs_dev_inode
{
309 struct squashfs_ldev_inode
{
321 struct squashfs_symlink_inode
{
333 struct squashfs_reg_inode
{
344 __le16 block_list
[0];
347 struct squashfs_lreg_inode
{
361 __le16 block_list
[0];
364 struct squashfs_dir_inode
{
378 struct squashfs_ldir_inode
{
392 struct squashfs_dir_index index
[0];
395 union 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
;
408 struct squashfs_dir_entry
{
416 struct squashfs_dir_header
{
422 struct squashfs_fragment_entry
{
428 struct squashfs_xattr_entry
{
434 struct squashfs_xattr_val
{
439 struct squashfs_xattr_id
{
445 struct squashfs_xattr_id_table
{
446 __le64 xattr_table_start
;