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