1 #ifndef SQUASHFS_COMPAT
2 #define SQUASHFS_COMPAT
6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2014, 2019
7 * Phillip Lougher <phillip@squashfs.org.uk>
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.
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.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 * definitions for structures on disk - layout 3.x
30 #define SQUASHFS_CHECK 2
31 #define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
34 /* Max number of uids and gids */
35 #define SQUASHFS_UIDS 256
36 #define SQUASHFS_GUIDS 255
38 struct squashfs_super_block_3
{
41 unsigned int bytes_used_2
;
42 unsigned int uid_start_2
;
43 unsigned int guid_start_2
;
44 unsigned int inode_table_start_2
;
45 unsigned int directory_table_start_2
;
46 unsigned int s_major
:16;
47 unsigned int s_minor
:16;
48 unsigned int block_size_1
:16;
49 unsigned int block_log
:16;
51 unsigned int no_uids
:8;
52 unsigned int no_guids
:8;
53 int mkfs_time
/* time of filesystem creation */;
54 squashfs_inode root_inode
;
55 unsigned int block_size
;
56 unsigned int fragments
;
57 unsigned int fragment_table_start_2
;
61 long long inode_table_start
;
62 long long directory_table_start
;
63 long long fragment_table_start
;
64 long long lookup_table_start
;
65 } __attribute__ ((packed
));
67 struct squashfs_dir_index_3
{
69 unsigned int start_block
;
71 unsigned char name
[0];
72 } __attribute__ ((packed
));
74 struct squashfs_base_inode_header_3
{
75 unsigned int inode_type
:4;
80 unsigned int inode_number
;
81 } __attribute__ ((packed
));
83 struct squashfs_ipc_inode_header_3
{
84 unsigned int inode_type
:4;
89 unsigned int inode_number
;
91 } __attribute__ ((packed
));
93 struct squashfs_dev_inode_header_3
{
94 unsigned int inode_type
:4;
99 unsigned int inode_number
;
102 } __attribute__ ((packed
));
104 struct squashfs_symlink_inode_header_3
{
105 unsigned int inode_type
:4;
106 unsigned int mode
:12;
110 unsigned int inode_number
;
112 unsigned short symlink_size
;
114 } __attribute__ ((packed
));
116 struct squashfs_reg_inode_header_3
{
117 unsigned int inode_type
:4;
118 unsigned int mode
:12;
122 unsigned int inode_number
;
123 squashfs_block start_block
;
124 unsigned int fragment
;
126 unsigned int file_size
;
127 unsigned short block_list
[0];
128 } __attribute__ ((packed
));
130 struct squashfs_lreg_inode_header_3
{
131 unsigned int inode_type
:4;
132 unsigned int mode
:12;
136 unsigned int inode_number
;
138 squashfs_block start_block
;
139 unsigned int fragment
;
142 unsigned short block_list
[0];
143 } __attribute__ ((packed
));
145 struct squashfs_dir_inode_header_3
{
146 unsigned int inode_type
:4;
147 unsigned int mode
:12;
151 unsigned int inode_number
;
153 unsigned int file_size
:19;
154 unsigned int offset
:13;
155 unsigned int start_block
;
156 unsigned int parent_inode
;
157 } __attribute__ ((packed
));
159 struct squashfs_ldir_inode_header_3
{
160 unsigned int inode_type
:4;
161 unsigned int mode
:12;
165 unsigned int inode_number
;
167 unsigned int file_size
:27;
168 unsigned int offset
:13;
169 unsigned int start_block
;
170 unsigned int i_count
:16;
171 unsigned int parent_inode
;
172 struct squashfs_dir_index_3 index
[0];
173 } __attribute__ ((packed
));
175 union squashfs_inode_header_3
{
176 struct squashfs_base_inode_header_3 base
;
177 struct squashfs_dev_inode_header_3 dev
;
178 struct squashfs_symlink_inode_header_3 symlink
;
179 struct squashfs_reg_inode_header_3 reg
;
180 struct squashfs_lreg_inode_header_3 lreg
;
181 struct squashfs_dir_inode_header_3 dir
;
182 struct squashfs_ldir_inode_header_3 ldir
;
183 struct squashfs_ipc_inode_header_3 ipc
;
186 struct squashfs_dir_entry_3
{
187 unsigned int offset
:13;
192 } __attribute__ ((packed
));
194 struct squashfs_dir_header_3
{
195 unsigned int count
:8;
196 unsigned int start_block
;
197 unsigned int inode_number
;
198 } __attribute__ ((packed
));
200 struct squashfs_fragment_entry_3
{
201 long long start_block
;
203 unsigned int pending
;
204 } __attribute__ ((packed
));
207 typedef struct squashfs_super_block_3 squashfs_super_block_3
;
208 typedef struct squashfs_dir_index_3 squashfs_dir_index_3
;
209 typedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3
;
210 typedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3
;
211 typedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3
;
212 typedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3
;
213 typedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3
;
214 typedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3
;
215 typedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3
;
216 typedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3
;
217 typedef struct squashfs_dir_entry_3 squashfs_dir_entry_3
;
218 typedef struct squashfs_dir_header_3 squashfs_dir_header_3
;
219 typedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3
;
222 * macros to convert each packed bitfield structure from little endian to big
223 * endian and vice versa. These are needed when creating or using a filesystem
224 * on a machine with different byte ordering to the target architecture.
228 #define SQUASHFS_SWAP_START \
231 unsigned long long val;\
235 #define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\
237 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\
238 SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
239 SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
240 SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
241 SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
242 SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
243 SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
244 SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
245 SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
246 SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
247 SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
248 SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
249 SQUASHFS_SWAP((s)->flags, d, 288, 8);\
250 SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
251 SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
252 SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
253 SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
254 SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
255 SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
256 SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
257 SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
258 SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
259 SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
260 SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
261 SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
262 SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
263 SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
266 #define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\
267 SQUASHFS_MEMSET(s, d, n);\
268 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
269 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
270 SQUASHFS_SWAP((s)->uid, d, 16, 8);\
271 SQUASHFS_SWAP((s)->guid, d, 24, 8);\
272 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
273 SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
275 #define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\
277 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\
280 #define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\
282 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
283 sizeof(struct squashfs_ipc_inode_header_3))\
284 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
287 #define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\
289 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
290 sizeof(struct squashfs_dev_inode_header_3)); \
291 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
292 SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
295 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\
297 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
298 sizeof(struct squashfs_symlink_inode_header_3));\
299 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
300 SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
303 #define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\
305 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
306 sizeof(struct squashfs_reg_inode_header_3));\
307 SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
308 SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
309 SQUASHFS_SWAP((s)->offset, d, 192, 32);\
310 SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
313 #define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\
315 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
316 sizeof(struct squashfs_lreg_inode_header_3));\
317 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
318 SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
319 SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
320 SQUASHFS_SWAP((s)->offset, d, 224, 32);\
321 SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
324 #define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\
326 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
327 sizeof(struct squashfs_dir_inode_header_3));\
328 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
329 SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
330 SQUASHFS_SWAP((s)->offset, d, 147, 13);\
331 SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
332 SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
335 #define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\
337 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \
338 sizeof(struct squashfs_ldir_inode_header_3));\
339 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
340 SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
341 SQUASHFS_SWAP((s)->offset, d, 155, 13);\
342 SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
343 SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
344 SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
347 #define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\
349 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\
350 SQUASHFS_SWAP((s)->index, d, 0, 32);\
351 SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
352 SQUASHFS_SWAP((s)->size, d, 64, 8);\
355 #define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\
357 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\
358 SQUASHFS_SWAP((s)->count, d, 0, 8);\
359 SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
360 SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
363 #define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\
365 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\
366 SQUASHFS_SWAP((s)->offset, d, 0, 13);\
367 SQUASHFS_SWAP((s)->type, d, 13, 3);\
368 SQUASHFS_SWAP((s)->size, d, 16, 8);\
369 SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
372 #define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1)
374 #define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\
378 SQUASHFS_MEMSET(s, d, n * 2);\
379 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
381 SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
384 #define SQUASHFS_SWAP_INTS_3(s, d, n) {\
388 SQUASHFS_MEMSET(s, d, n * 4);\
389 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
391 SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
394 #define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\
398 SQUASHFS_MEMSET(s, d, n * 8);\
399 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
401 SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
404 #define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
408 SQUASHFS_MEMSET(s, d, n * bits / 8);\
409 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
411 SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
414 #define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)
415 #define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n)
417 #define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\
419 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\
420 SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
421 SQUASHFS_SWAP((s)->size, d, 64, 32);\
424 /* fragment and fragment table defines */
425 #define SQUASHFS_FRAGMENT_BYTES_3(A) ((A) * sizeof(struct squashfs_fragment_entry_3))
427 #define SQUASHFS_FRAGMENT_INDEX_3(A) (SQUASHFS_FRAGMENT_BYTES_3(A) / \
428 SQUASHFS_METADATA_SIZE)
430 #define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A) (SQUASHFS_FRAGMENT_BYTES_3(A) % \
431 SQUASHFS_METADATA_SIZE)
433 #define SQUASHFS_FRAGMENT_INDEXES_3(A) ((SQUASHFS_FRAGMENT_BYTES_3(A) + \
434 SQUASHFS_METADATA_SIZE - 1) / \
435 SQUASHFS_METADATA_SIZE)
437 #define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A) (SQUASHFS_FRAGMENT_INDEXES_3(A) *\
440 /* inode lookup table defines */
441 #define SQUASHFS_LOOKUP_BYTES_3(A) ((A) * sizeof(squashfs_inode))
443 #define SQUASHFS_LOOKUP_BLOCK_3(A) (SQUASHFS_LOOKUP_BYTES_3(A) / \
444 SQUASHFS_METADATA_SIZE)
446 #define SQUASHFS_LOOKUP_BLOCK_OFFSET_3(A) (SQUASHFS_LOOKUP_BYTES_3(A) % \
447 SQUASHFS_METADATA_SIZE)
449 #define SQUASHFS_LOOKUP_BLOCKS_3(A) ((SQUASHFS_LOOKUP_BYTES_3(A) + \
450 SQUASHFS_METADATA_SIZE - 1) / \
451 SQUASHFS_METADATA_SIZE)
453 #define SQUASHFS_LOOKUP_BLOCK_BYTES_3(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
457 * definitions for structures on disk - layout 1.x
459 #define SQUASHFS_TYPES 5
460 #define SQUASHFS_IPC_TYPE 0
462 struct squashfs_base_inode_header_1
{
463 unsigned int inode_type
:4;
464 unsigned int mode
:12; /* protection */
465 unsigned int uid
:4; /* index into uid table */
466 unsigned int guid
:4; /* index into guid table */
467 } __attribute__ ((packed
));
469 struct squashfs_ipc_inode_header_1
{
470 unsigned int inode_type
:4;
471 unsigned int mode
:12; /* protection */
472 unsigned int uid
:4; /* index into uid table */
473 unsigned int guid
:4; /* index into guid table */
475 unsigned int offset
:4;
476 } __attribute__ ((packed
));
478 struct squashfs_dev_inode_header_1
{
479 unsigned int inode_type
:4;
480 unsigned int mode
:12; /* protection */
481 unsigned int uid
:4; /* index into uid table */
482 unsigned int guid
:4; /* index into guid table */
484 } __attribute__ ((packed
));
486 struct squashfs_symlink_inode_header_1
{
487 unsigned int inode_type
:4;
488 unsigned int mode
:12; /* protection */
489 unsigned int uid
:4; /* index into uid table */
490 unsigned int guid
:4; /* index into guid table */
491 unsigned short symlink_size
;
493 } __attribute__ ((packed
));
495 struct squashfs_reg_inode_header_1
{
496 unsigned int inode_type
:4;
497 unsigned int mode
:12; /* protection */
498 unsigned int uid
:4; /* index into uid table */
499 unsigned int guid
:4; /* index into guid table */
501 unsigned int start_block
;
502 unsigned int file_size
:32;
503 unsigned short block_list
[0];
504 } __attribute__ ((packed
));
506 struct squashfs_dir_inode_header_1
{
507 unsigned int inode_type
:4;
508 unsigned int mode
:12; /* protection */
509 unsigned int uid
:4; /* index into uid table */
510 unsigned int guid
:4; /* index into guid table */
511 unsigned int file_size
:19;
512 unsigned int offset
:13;
514 unsigned int start_block
:24;
515 } __attribute__ ((packed
));
517 union squashfs_inode_header_1
{
518 struct squashfs_base_inode_header_1 base
;
519 struct squashfs_dev_inode_header_1 dev
;
520 struct squashfs_symlink_inode_header_1 symlink
;
521 struct squashfs_reg_inode_header_1 reg
;
522 struct squashfs_dir_inode_header_1 dir
;
523 struct squashfs_ipc_inode_header_1 ipc
;
526 typedef struct squashfs_dir_index_1 squashfs_dir_index_1
;
527 typedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1
;
528 typedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1
;
529 typedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1
;
530 typedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1
;
531 typedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1
;
532 typedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1
;
534 #define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
535 SQUASHFS_MEMSET(s, d, n);\
536 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
537 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
538 SQUASHFS_SWAP((s)->uid, d, 16, 4);\
539 SQUASHFS_SWAP((s)->guid, d, 20, 4);
541 #define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
543 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
546 #define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
548 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
549 sizeof(struct squashfs_ipc_inode_header_1));\
550 SQUASHFS_SWAP((s)->type, d, 24, 4);\
551 SQUASHFS_SWAP((s)->offset, d, 28, 4);\
554 #define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
556 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
557 sizeof(struct squashfs_dev_inode_header_1));\
558 SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
561 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
563 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
564 sizeof(struct squashfs_symlink_inode_header_1));\
565 SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
568 #define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
570 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
571 sizeof(struct squashfs_reg_inode_header_1));\
572 SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
573 SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
574 SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
577 #define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
579 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
580 sizeof(struct squashfs_dir_inode_header_1));\
581 SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
582 SQUASHFS_SWAP((s)->offset, d, 43, 13);\
583 SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
584 SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
588 * definitions for structures on disk - layout 2.x
590 struct squashfs_dir_index_2
{
591 unsigned int index
:27;
592 unsigned int start_block
:29;
594 unsigned char name
[0];
595 } __attribute__ ((packed
));
597 struct squashfs_base_inode_header_2
{
598 unsigned int inode_type
:4;
599 unsigned int mode
:12; /* protection */
600 unsigned int uid
:8; /* index into uid table */
601 unsigned int guid
:8; /* index into guid table */
602 } __attribute__ ((packed
));
604 struct squashfs_ipc_inode_header_2
{
605 unsigned int inode_type
:4;
606 unsigned int mode
:12; /* protection */
607 unsigned int uid
:8; /* index into uid table */
608 unsigned int guid
:8; /* index into guid table */
609 } __attribute__ ((packed
));
611 struct squashfs_dev_inode_header_2
{
612 unsigned int inode_type
:4;
613 unsigned int mode
:12; /* protection */
614 unsigned int uid
:8; /* index into uid table */
615 unsigned int guid
:8; /* index into guid table */
617 } __attribute__ ((packed
));
619 struct squashfs_symlink_inode_header_2
{
620 unsigned int inode_type
:4;
621 unsigned int mode
:12; /* protection */
622 unsigned int uid
:8; /* index into uid table */
623 unsigned int guid
:8; /* index into guid table */
624 unsigned short symlink_size
;
626 } __attribute__ ((packed
));
628 struct squashfs_reg_inode_header_2
{
629 unsigned int inode_type
:4;
630 unsigned int mode
:12; /* protection */
631 unsigned int uid
:8; /* index into uid table */
632 unsigned int guid
:8; /* index into guid table */
634 unsigned int start_block
;
635 unsigned int fragment
;
637 unsigned int file_size
:32;
638 unsigned short block_list
[0];
639 } __attribute__ ((packed
));
641 struct squashfs_dir_inode_header_2
{
642 unsigned int inode_type
:4;
643 unsigned int mode
:12; /* protection */
644 unsigned int uid
:8; /* index into uid table */
645 unsigned int guid
:8; /* index into guid table */
646 unsigned int file_size
:19;
647 unsigned int offset
:13;
649 unsigned int start_block
:24;
650 } __attribute__ ((packed
));
652 struct squashfs_ldir_inode_header_2
{
653 unsigned int inode_type
:4;
654 unsigned int mode
:12; /* protection */
655 unsigned int uid
:8; /* index into uid table */
656 unsigned int guid
:8; /* index into guid table */
657 unsigned int file_size
:27;
658 unsigned int offset
:13;
660 unsigned int start_block
:24;
661 unsigned int i_count
:16;
662 struct squashfs_dir_index_2 index
[0];
663 } __attribute__ ((packed
));
665 union squashfs_inode_header_2
{
666 struct squashfs_base_inode_header_2 base
;
667 struct squashfs_dev_inode_header_2 dev
;
668 struct squashfs_symlink_inode_header_2 symlink
;
669 struct squashfs_reg_inode_header_2 reg
;
670 struct squashfs_dir_inode_header_2 dir
;
671 struct squashfs_ldir_inode_header_2 ldir
;
672 struct squashfs_ipc_inode_header_2 ipc
;
675 struct squashfs_dir_header_2
{
676 unsigned int count
:8;
677 unsigned int start_block
:24;
678 } __attribute__ ((packed
));
680 struct squashfs_dir_entry_2
{
681 unsigned int offset
:13;
685 } __attribute__ ((packed
));
687 struct squashfs_fragment_entry_2
{
688 unsigned int start_block
;
690 } __attribute__ ((packed
));
692 typedef struct squashfs_dir_index_2 squashfs_dir_index_2
;
693 typedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2
;
694 typedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2
;
695 typedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2
;
696 typedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2
;
697 typedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2
;
698 typedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2
;
699 typedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2
;
700 typedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2
;
701 typedef struct squashfs_dir_entry_2 squashfs_dir_entry_2
;
702 typedef struct squashfs_dir_header_2 squashfs_dir_header_2
;
703 typedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2
;
705 #define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
706 SQUASHFS_MEMSET(s, d, n);\
707 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
708 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
709 SQUASHFS_SWAP((s)->uid, d, 16, 8);\
710 SQUASHFS_SWAP((s)->guid, d, 24, 8);\
712 #define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
714 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
717 #define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
718 SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
720 #define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
722 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
723 sizeof(struct squashfs_dev_inode_header_2)); \
724 SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
727 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
729 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
730 sizeof(struct squashfs_symlink_inode_header_2));\
731 SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
734 #define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
736 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
737 sizeof(struct squashfs_reg_inode_header_2));\
738 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
739 SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
740 SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
741 SQUASHFS_SWAP((s)->offset, d, 128, 32);\
742 SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
745 #define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
747 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
748 sizeof(struct squashfs_dir_inode_header_2));\
749 SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
750 SQUASHFS_SWAP((s)->offset, d, 51, 13);\
751 SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
752 SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
755 #define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
757 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
758 sizeof(struct squashfs_ldir_inode_header_2));\
759 SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
760 SQUASHFS_SWAP((s)->offset, d, 59, 13);\
761 SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
762 SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
763 SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
766 #define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
768 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
769 SQUASHFS_SWAP((s)->index, d, 0, 27);\
770 SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
771 SQUASHFS_SWAP((s)->size, d, 56, 8);\
773 #define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
775 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
776 SQUASHFS_SWAP((s)->count, d, 0, 8);\
777 SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
780 #define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
782 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
783 SQUASHFS_SWAP((s)->offset, d, 0, 13);\
784 SQUASHFS_SWAP((s)->type, d, 13, 3);\
785 SQUASHFS_SWAP((s)->size, d, 16, 8);\
788 #define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
790 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
791 SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
792 SQUASHFS_SWAP((s)->size, d, 32, 32);\
795 #define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n)
797 /* fragment and fragment table defines */
798 #define SQUASHFS_FRAGMENT_BYTES_2(A) ((A) * sizeof(struct squashfs_fragment_entry_2))
800 #define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
801 SQUASHFS_METADATA_SIZE)
803 #define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
804 SQUASHFS_METADATA_SIZE)
806 #define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
807 SQUASHFS_METADATA_SIZE - 1) / \
808 SQUASHFS_METADATA_SIZE)
810 #define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
813 * macros used to swap each structure entry, taking into account
814 * bitfields and different bitfield placing conventions on differing architectures
816 #if __BYTE_ORDER == __BIG_ENDIAN
817 /* convert from little endian to big endian */
818 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
820 /* convert from big endian to little endian */
821 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
824 #define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
827 s = (unsigned char *)p + (pos / 8);\
828 d = ((unsigned char *) &val) + 7;\
829 for(bits = 0; bits < (tbits + b_pos); bits += 8) \
831 value = (val >> (SHIFT));\
833 #define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);