7 * Copyright (c) 2002, 2003, 2004, 2005, 2006
8 * Phillip Lougher <phillip@lougher.org.uk>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2,
13 * or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
28 #define CONFIG_SQUASHFS_2_0_COMPATIBILITY
31 #ifdef CONFIG_SQUASHFS_VMALLOC
32 #define SQUASHFS_ALLOC(a) vmalloc(a)
33 #define SQUASHFS_FREE(a) vfree(a)
35 #define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
36 #define SQUASHFS_FREE(a) kfree(a)
38 #define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
39 #define SQUASHFS_MAJOR 3
40 #define SQUASHFS_MINOR 0
41 #define SQUASHFS_MAGIC 0x73717368
42 #define SQUASHFS_MAGIC_SWAP 0x68737173
43 #define SQUASHFS_START 0
45 /* size of metadata (inode and directory) blocks */
46 #define SQUASHFS_METADATA_SIZE 8192
47 #define SQUASHFS_METADATA_LOG 13
49 /* default size of data blocks */
50 #define SQUASHFS_FILE_SIZE 65536
51 #define SQUASHFS_FILE_LOG 16
53 #define SQUASHFS_FILE_MAX_SIZE 65536
55 /* Max number of uids and gids */
56 #define SQUASHFS_UIDS 256
57 #define SQUASHFS_GUIDS 255
59 /* Max length of filename (not 255) */
60 #define SQUASHFS_NAME_LEN 256
62 #define SQUASHFS_INVALID ((long long) 0xffffffffffff)
63 #define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
64 #define SQUASHFS_INVALID_BLK ((long long) -1)
65 #define SQUASHFS_USED_BLK ((long long) -2)
67 /* Filesystem flags */
68 #define SQUASHFS_NOI 0
69 #define SQUASHFS_NOD 1
70 #define SQUASHFS_CHECK 2
71 #define SQUASHFS_NOF 3
72 #define SQUASHFS_NO_FRAG 4
73 #define SQUASHFS_ALWAYS_FRAG 5
74 #define SQUASHFS_DUPLICATE 6
76 #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
78 #define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
81 #define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
84 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
87 #define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
90 #define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
93 #define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
96 #define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
99 #define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
100 duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
101 | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
102 (duplicate_checking << 6))
104 /* Max number of types and file types */
105 #define SQUASHFS_DIR_TYPE 1
106 #define SQUASHFS_FILE_TYPE 2
107 #define SQUASHFS_SYMLINK_TYPE 3
108 #define SQUASHFS_BLKDEV_TYPE 4
109 #define SQUASHFS_CHRDEV_TYPE 5
110 #define SQUASHFS_FIFO_TYPE 6
111 #define SQUASHFS_SOCKET_TYPE 7
112 #define SQUASHFS_LDIR_TYPE 8
113 #define SQUASHFS_LREG_TYPE 9
115 /* 1.0 filesystem type definitions */
116 #define SQUASHFS_TYPES 5
117 #define SQUASHFS_IPC_TYPE 0
119 /* Flag whether block is compressed or uncompressed, bit is set if block is
121 #define SQUASHFS_COMPRESSED_BIT (1 << 15)
123 #define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
124 (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
126 #define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
128 #define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
130 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
131 ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
132 ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
134 #define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
137 * Inode number ops. Inodes consist of a compressed block number, and an
138 * uncompressed offset within that block
140 #define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
142 #define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
144 #define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
147 /* Compute 32 bit VFS inode number from squashfs inode number */
148 #define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
152 /* Translate between VFS mode and squashfs mode */
153 #define SQUASHFS_MODE(a) ((a) & 0xfff)
155 /* fragment and fragment table defines */
156 #define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
158 #define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
159 SQUASHFS_METADATA_SIZE)
161 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
162 SQUASHFS_METADATA_SIZE)
164 #define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
165 SQUASHFS_METADATA_SIZE - 1) / \
166 SQUASHFS_METADATA_SIZE)
168 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
171 /* cached data constants for filesystem */
172 #define SQUASHFS_CACHED_BLKS 8
174 #define SQUASHFS_MAX_FILE_SIZE_LOG 64
176 #define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
177 (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
179 #define SQUASHFS_MARKER_BYTE 0xff
181 /* meta index cache */
182 #define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
183 #define SQUASHFS_META_ENTRIES 31
184 #define SQUASHFS_META_NUMBER 8
185 #define SQUASHFS_SLOTS 4
188 long long data_block;
189 unsigned int index_block;
190 unsigned short offset;
195 unsigned int inode_number;
197 unsigned short entries;
199 unsigned short locked;
201 struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
206 * definitions for structures on disk
209 typedef long long squashfs_block_t;
210 typedef long long squashfs_inode_t;
212 struct squashfs_super_block {
213 unsigned int s_magic;
215 unsigned int bytes_used_2;
216 unsigned int uid_start_2;
217 unsigned int guid_start_2;
218 unsigned int inode_table_start_2;
219 unsigned int directory_table_start_2;
220 unsigned int s_major:16;
221 unsigned int s_minor:16;
222 unsigned int block_size_1:16;
223 unsigned int block_log:16;
224 unsigned int flags:8;
225 unsigned int no_uids:8;
226 unsigned int no_guids:8;
227 unsigned int mkfs_time /* time of filesystem creation */;
228 squashfs_inode_t root_inode;
229 unsigned int block_size;
230 unsigned int fragments;
231 unsigned int fragment_table_start_2;
232 long long bytes_used;
234 long long guid_start;
235 long long inode_table_start;
236 long long directory_table_start;
237 long long fragment_table_start;
239 } __attribute__ ((packed));
241 struct squashfs_dir_index {
243 unsigned int start_block;
245 unsigned char name[0];
246 } __attribute__ ((packed));
248 #define SQUASHFS_BASE_INODE_HEADER \
249 unsigned int inode_type:4; \
250 unsigned int mode:12; \
251 unsigned int uid:8; \
252 unsigned int guid:8; \
253 unsigned int mtime; \
254 unsigned int inode_number;
256 struct squashfs_base_inode_header {
257 SQUASHFS_BASE_INODE_HEADER;
258 } __attribute__ ((packed));
260 struct squashfs_ipc_inode_header {
261 SQUASHFS_BASE_INODE_HEADER;
263 } __attribute__ ((packed));
265 struct squashfs_dev_inode_header {
266 SQUASHFS_BASE_INODE_HEADER;
269 } __attribute__ ((packed));
271 struct squashfs_symlink_inode_header {
272 SQUASHFS_BASE_INODE_HEADER;
274 unsigned short symlink_size;
276 } __attribute__ ((packed));
278 struct squashfs_reg_inode_header {
279 SQUASHFS_BASE_INODE_HEADER;
280 squashfs_block_t start_block;
281 unsigned int fragment;
283 unsigned int file_size;
284 unsigned short block_list[0];
285 } __attribute__ ((packed));
287 struct squashfs_lreg_inode_header {
288 SQUASHFS_BASE_INODE_HEADER;
290 squashfs_block_t start_block;
291 unsigned int fragment;
294 unsigned short block_list[0];
295 } __attribute__ ((packed));
297 struct squashfs_dir_inode_header {
298 SQUASHFS_BASE_INODE_HEADER;
300 unsigned int file_size:19;
301 unsigned int offset:13;
302 unsigned int start_block;
303 unsigned int parent_inode;
304 } __attribute__ ((packed));
306 struct squashfs_ldir_inode_header {
307 SQUASHFS_BASE_INODE_HEADER;
309 unsigned int file_size:27;
310 unsigned int offset:13;
311 unsigned int start_block;
312 unsigned int i_count:16;
313 unsigned int parent_inode;
314 struct squashfs_dir_index index[0];
315 } __attribute__ ((packed));
317 union squashfs_inode_header {
318 struct squashfs_base_inode_header base;
319 struct squashfs_dev_inode_header dev;
320 struct squashfs_symlink_inode_header symlink;
321 struct squashfs_reg_inode_header reg;
322 struct squashfs_lreg_inode_header lreg;
323 struct squashfs_dir_inode_header dir;
324 struct squashfs_ldir_inode_header ldir;
325 struct squashfs_ipc_inode_header ipc;
328 struct squashfs_dir_entry {
329 unsigned int offset:13;
334 } __attribute__ ((packed));
336 struct squashfs_dir_header {
337 unsigned int count:8;
338 unsigned int start_block;
339 unsigned int inode_number;
340 } __attribute__ ((packed));
342 struct squashfs_fragment_entry {
343 long long start_block;
346 } __attribute__ ((packed));
348 extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
349 extern int squashfs_uncompress_init(void);
350 extern int squashfs_uncompress_exit(void);
353 * macros to convert each packed bitfield structure from little endian to big
354 * endian and vice versa. These are needed when creating or using a filesystem
355 * on a machine with different byte ordering to the target architecture.
359 #define SQUASHFS_SWAP_START \
362 unsigned long long val;\
366 #define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
368 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
369 SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
370 SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
371 SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
372 SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
373 SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
374 SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
375 SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
376 SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
377 SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
378 SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
379 SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
380 SQUASHFS_SWAP((s)->flags, d, 288, 8);\
381 SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
382 SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
383 SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
384 SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
385 SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
386 SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
387 SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
388 SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
389 SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
390 SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
391 SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
392 SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
393 SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
394 SQUASHFS_SWAP((s)->unused, d, 888, 64);\
397 #define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
398 SQUASHFS_MEMSET(s, d, n);\
399 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
400 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
401 SQUASHFS_SWAP((s)->uid, d, 16, 8);\
402 SQUASHFS_SWAP((s)->guid, d, 24, 8);\
403 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
404 SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
406 #define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
408 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
411 #define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
413 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
414 sizeof(struct squashfs_ipc_inode_header))\
415 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
418 #define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
420 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
421 sizeof(struct squashfs_dev_inode_header)); \
422 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
423 SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
426 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
428 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
429 sizeof(struct squashfs_symlink_inode_header));\
430 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
431 SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
434 #define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
436 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
437 sizeof(struct squashfs_reg_inode_header));\
438 SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
439 SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
440 SQUASHFS_SWAP((s)->offset, d, 192, 32);\
441 SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
444 #define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
446 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
447 sizeof(struct squashfs_lreg_inode_header));\
448 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
449 SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
450 SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
451 SQUASHFS_SWAP((s)->offset, d, 224, 32);\
452 SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
455 #define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
457 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
458 sizeof(struct squashfs_dir_inode_header));\
459 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
460 SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
461 SQUASHFS_SWAP((s)->offset, d, 147, 13);\
462 SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
463 SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
466 #define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
468 SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
469 sizeof(struct squashfs_ldir_inode_header));\
470 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
471 SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
472 SQUASHFS_SWAP((s)->offset, d, 155, 13);\
473 SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
474 SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
475 SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
478 #define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
480 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
481 SQUASHFS_SWAP((s)->index, d, 0, 32);\
482 SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
483 SQUASHFS_SWAP((s)->size, d, 64, 8);\
486 #define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
488 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
489 SQUASHFS_SWAP((s)->count, d, 0, 8);\
490 SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
491 SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
494 #define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
496 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
497 SQUASHFS_SWAP((s)->offset, d, 0, 13);\
498 SQUASHFS_SWAP((s)->type, d, 13, 3);\
499 SQUASHFS_SWAP((s)->size, d, 16, 8);\
500 SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
503 #define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
505 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
506 SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
507 SQUASHFS_SWAP((s)->size, d, 64, 32);\
510 #define SQUASHFS_SWAP_SHORTS(s, d, n) {\
514 SQUASHFS_MEMSET(s, d, n * 2);\
515 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
517 SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
520 #define SQUASHFS_SWAP_INTS(s, d, n) {\
524 SQUASHFS_MEMSET(s, d, n * 4);\
525 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
527 SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
530 #define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
534 SQUASHFS_MEMSET(s, d, n * 8);\
535 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
537 SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
540 #define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
544 SQUASHFS_MEMSET(s, d, n * bits / 8);\
545 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
547 SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
550 #define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
552 #ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
554 struct squashfs_base_inode_header_1 {
555 unsigned int inode_type:4;
556 unsigned int mode:12; /* protection */
557 unsigned int uid:4; /* index into uid table */
558 unsigned int guid:4; /* index into guid table */
559 } __attribute__ ((packed));
561 struct squashfs_ipc_inode_header_1 {
562 unsigned int inode_type:4;
563 unsigned int mode:12; /* protection */
564 unsigned int uid:4; /* index into uid table */
565 unsigned int guid:4; /* index into guid table */
567 unsigned int offset:4;
568 } __attribute__ ((packed));
570 struct squashfs_dev_inode_header_1 {
571 unsigned int inode_type:4;
572 unsigned int mode:12; /* protection */
573 unsigned int uid:4; /* index into uid table */
574 unsigned int guid:4; /* index into guid table */
576 } __attribute__ ((packed));
578 struct squashfs_symlink_inode_header_1 {
579 unsigned int inode_type:4;
580 unsigned int mode:12; /* protection */
581 unsigned int uid:4; /* index into uid table */
582 unsigned int guid:4; /* index into guid table */
583 unsigned short symlink_size;
585 } __attribute__ ((packed));
587 struct squashfs_reg_inode_header_1 {
588 unsigned int inode_type:4;
589 unsigned int mode:12; /* protection */
590 unsigned int uid:4; /* index into uid table */
591 unsigned int guid:4; /* index into guid table */
593 unsigned int start_block;
594 unsigned int file_size:32;
595 unsigned short block_list[0];
596 } __attribute__ ((packed));
598 struct squashfs_dir_inode_header_1 {
599 unsigned int inode_type:4;
600 unsigned int mode:12; /* protection */
601 unsigned int uid:4; /* index into uid table */
602 unsigned int guid:4; /* index into guid table */
603 unsigned int file_size:19;
604 unsigned int offset:13;
606 unsigned int start_block:24;
607 } __attribute__ ((packed));
609 #define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
610 SQUASHFS_MEMSET(s, d, n);\
611 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
612 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
613 SQUASHFS_SWAP((s)->uid, d, 16, 4);\
614 SQUASHFS_SWAP((s)->guid, d, 20, 4);
616 #define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
618 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
621 #define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
623 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
624 sizeof(struct squashfs_ipc_inode_header_1));\
625 SQUASHFS_SWAP((s)->type, d, 24, 4);\
626 SQUASHFS_SWAP((s)->offset, d, 28, 4);\
629 #define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
631 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
632 sizeof(struct squashfs_dev_inode_header_1));\
633 SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
636 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
638 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
639 sizeof(struct squashfs_symlink_inode_header_1));\
640 SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
643 #define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
645 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
646 sizeof(struct squashfs_reg_inode_header_1));\
647 SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
648 SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
649 SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
652 #define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
654 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
655 sizeof(struct squashfs_dir_inode_header_1));\
656 SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
657 SQUASHFS_SWAP((s)->offset, d, 43, 13);\
658 SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
659 SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
664 #ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
666 struct squashfs_dir_index_2 {
667 unsigned int index:27;
668 unsigned int start_block:29;
670 unsigned char name[0];
671 } __attribute__ ((packed));
673 struct squashfs_base_inode_header_2 {
674 unsigned int inode_type:4;
675 unsigned int mode:12; /* protection */
676 unsigned int uid:8; /* index into uid table */
677 unsigned int guid:8; /* index into guid table */
678 } __attribute__ ((packed));
680 struct squashfs_ipc_inode_header_2 {
681 unsigned int inode_type:4;
682 unsigned int mode:12; /* protection */
683 unsigned int uid:8; /* index into uid table */
684 unsigned int guid:8; /* index into guid table */
685 } __attribute__ ((packed));
687 struct squashfs_dev_inode_header_2 {
688 unsigned int inode_type:4;
689 unsigned int mode:12; /* protection */
690 unsigned int uid:8; /* index into uid table */
691 unsigned int guid:8; /* index into guid table */
693 } __attribute__ ((packed));
695 struct squashfs_symlink_inode_header_2 {
696 unsigned int inode_type:4;
697 unsigned int mode:12; /* protection */
698 unsigned int uid:8; /* index into uid table */
699 unsigned int guid:8; /* index into guid table */
700 unsigned short symlink_size;
702 } __attribute__ ((packed));
704 struct squashfs_reg_inode_header_2 {
705 unsigned int inode_type:4;
706 unsigned int mode:12; /* protection */
707 unsigned int uid:8; /* index into uid table */
708 unsigned int guid:8; /* index into guid table */
710 unsigned int start_block;
711 unsigned int fragment;
713 unsigned int file_size:32;
714 unsigned short block_list[0];
715 } __attribute__ ((packed));
717 struct squashfs_dir_inode_header_2 {
718 unsigned int inode_type:4;
719 unsigned int mode:12; /* protection */
720 unsigned int uid:8; /* index into uid table */
721 unsigned int guid:8; /* index into guid table */
722 unsigned int file_size:19;
723 unsigned int offset:13;
725 unsigned int start_block:24;
726 } __attribute__ ((packed));
728 struct squashfs_ldir_inode_header_2 {
729 unsigned int inode_type:4;
730 unsigned int mode:12; /* protection */
731 unsigned int uid:8; /* index into uid table */
732 unsigned int guid:8; /* index into guid table */
733 unsigned int file_size:27;
734 unsigned int offset:13;
736 unsigned int start_block:24;
737 unsigned int i_count:16;
738 struct squashfs_dir_index_2 index[0];
739 } __attribute__ ((packed));
741 union squashfs_inode_header_2 {
742 struct squashfs_base_inode_header_2 base;
743 struct squashfs_dev_inode_header_2 dev;
744 struct squashfs_symlink_inode_header_2 symlink;
745 struct squashfs_reg_inode_header_2 reg;
746 struct squashfs_dir_inode_header_2 dir;
747 struct squashfs_ldir_inode_header_2 ldir;
748 struct squashfs_ipc_inode_header_2 ipc;
751 struct squashfs_dir_header_2 {
752 unsigned int count:8;
753 unsigned int start_block:24;
754 } __attribute__ ((packed));
756 struct squashfs_dir_entry_2 {
757 unsigned int offset:13;
761 } __attribute__ ((packed));
763 struct squashfs_fragment_entry_2 {
764 unsigned int start_block;
766 } __attribute__ ((packed));
768 #define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
769 SQUASHFS_MEMSET(s, d, n);\
770 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
771 SQUASHFS_SWAP((s)->mode, d, 4, 12);\
772 SQUASHFS_SWAP((s)->uid, d, 16, 8);\
773 SQUASHFS_SWAP((s)->guid, d, 24, 8);\
775 #define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
777 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
780 #define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
781 SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
783 #define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
785 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
786 sizeof(struct squashfs_dev_inode_header_2)); \
787 SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
790 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
792 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
793 sizeof(struct squashfs_symlink_inode_header_2));\
794 SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
797 #define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
799 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
800 sizeof(struct squashfs_reg_inode_header_2));\
801 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
802 SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
803 SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
804 SQUASHFS_SWAP((s)->offset, d, 128, 32);\
805 SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
808 #define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
810 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
811 sizeof(struct squashfs_dir_inode_header_2));\
812 SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
813 SQUASHFS_SWAP((s)->offset, d, 51, 13);\
814 SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
815 SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
818 #define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
820 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
821 sizeof(struct squashfs_ldir_inode_header_2));\
822 SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
823 SQUASHFS_SWAP((s)->offset, d, 59, 13);\
824 SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
825 SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
826 SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
829 #define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
831 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
832 SQUASHFS_SWAP((s)->index, d, 0, 27);\
833 SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
834 SQUASHFS_SWAP((s)->size, d, 56, 8);\
836 #define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
838 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
839 SQUASHFS_SWAP((s)->count, d, 0, 8);\
840 SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
843 #define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
845 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
846 SQUASHFS_SWAP((s)->offset, d, 0, 13);\
847 SQUASHFS_SWAP((s)->type, d, 13, 3);\
848 SQUASHFS_SWAP((s)->size, d, 16, 8);\
851 #define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
853 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
854 SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
855 SQUASHFS_SWAP((s)->size, d, 32, 32);\
858 #define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
860 /* fragment and fragment table defines */
861 #define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
863 #define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
864 SQUASHFS_METADATA_SIZE)
866 #define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
867 SQUASHFS_METADATA_SIZE)
869 #define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
870 SQUASHFS_METADATA_SIZE - 1) / \
871 SQUASHFS_METADATA_SIZE)
873 #define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
881 * macros used to swap each structure entry, taking into account
882 * bitfields and different bitfield placing conventions on differing
886 #include <asm/byteorder.h>
889 /* convert from little endian to big endian */
890 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
893 /* convert from big endian to little endian */
894 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
895 tbits, 64 - tbits - b_pos)
898 #define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
901 s = (unsigned char *)p + (pos / 8);\
902 d = ((unsigned char *) &val) + 7;\
903 for(bits = 0; bits < (tbits + b_pos); bits += 8) \
905 value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
908 #define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);