1#ifndef SQUASHFS_COMPAT 2#define SQUASHFS_COMPAT 3/* 4 * Squashfs 5 * 6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 7 * Phillip Lougher <phillip@lougher.demon.co.uk> 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 * squashfs_compat.h 24 */ 25 26/* 27 * definitions for structures on disk - layout 3.x 28 */ 29 30#define SQUASHFS_CHECK 2 31#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \ 32 SQUASHFS_CHECK) 33 34/* Max number of uids and gids */ 35#define SQUASHFS_UIDS 256 36#define SQUASHFS_GUIDS 255 37 38struct squashfs_super_block_3 { 39 unsigned int s_magic; 40 unsigned int inodes; 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; 50 unsigned int flags:8; 51 unsigned int no_uids:8; 52 unsigned int no_guids:8; 53 unsigned 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; 58 long long bytes_used; 59 long long uid_start; 60 long long guid_start; 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)); 66 67struct squashfs_dir_index_3 { 68 unsigned int index; 69 unsigned int start_block; 70 unsigned char size; 71 unsigned char name[0]; 72} __attribute__ ((packed)); 73 74#define SQUASHFS_BASE_INODE_HEADER_3 \ 75 unsigned int inode_type:4; \ 76 unsigned int mode:12; \ 77 unsigned int uid:8; \ 78 unsigned int guid:8; \ 79 unsigned int mtime; \ 80 unsigned int inode_number; 81 82struct squashfs_base_inode_header_3 { 83 SQUASHFS_BASE_INODE_HEADER_3; 84} __attribute__ ((packed)); 85 86struct squashfs_ipc_inode_header_3 { 87 SQUASHFS_BASE_INODE_HEADER_3; 88 unsigned int nlink; 89} __attribute__ ((packed)); 90 91struct squashfs_dev_inode_header_3 { 92 SQUASHFS_BASE_INODE_HEADER_3; 93 unsigned int nlink; 94 unsigned short rdev; 95} __attribute__ ((packed)); 96 97struct squashfs_symlink_inode_header_3 { 98 SQUASHFS_BASE_INODE_HEADER_3; 99 unsigned int nlink; 100 unsigned short symlink_size; 101 char symlink[0]; 102} __attribute__ ((packed)); 103 104struct squashfs_reg_inode_header_3 { 105 SQUASHFS_BASE_INODE_HEADER_3; 106 squashfs_block start_block; 107 unsigned int fragment; 108 unsigned int offset; 109 unsigned int file_size; 110 unsigned short block_list[0]; 111} __attribute__ ((packed)); 112 113struct squashfs_lreg_inode_header_3 { 114 SQUASHFS_BASE_INODE_HEADER_3; 115 unsigned int nlink; 116 squashfs_block start_block; 117 unsigned int fragment; 118 unsigned int offset; 119 long long file_size; 120 unsigned short block_list[0]; 121} __attribute__ ((packed)); 122 123struct squashfs_dir_inode_header_3 { 124 SQUASHFS_BASE_INODE_HEADER_3; 125 unsigned int nlink; 126 unsigned int file_size:19; 127 unsigned int offset:13; 128 unsigned int start_block; 129 unsigned int parent_inode; 130} __attribute__ ((packed)); 131 132struct squashfs_ldir_inode_header_3 { 133 SQUASHFS_BASE_INODE_HEADER_3; 134 unsigned int nlink; 135 unsigned int file_size:27; 136 unsigned int offset:13; 137 unsigned int start_block; 138 unsigned int i_count:16; 139 unsigned int parent_inode; 140 struct squashfs_dir_index_3 index[0]; 141} __attribute__ ((packed)); 142 143union squashfs_inode_header_3 { 144 struct squashfs_base_inode_header_3 base; 145 struct squashfs_dev_inode_header_3 dev; 146 struct squashfs_symlink_inode_header_3 symlink; 147 struct squashfs_reg_inode_header_3 reg; 148 struct squashfs_lreg_inode_header_3 lreg; 149 struct squashfs_dir_inode_header_3 dir; 150 struct squashfs_ldir_inode_header_3 ldir; 151 struct squashfs_ipc_inode_header_3 ipc; 152}; 153 154struct squashfs_dir_entry_3 { 155 unsigned int offset:13; 156 unsigned int type:3; 157 unsigned int size:8; 158 int inode_number:16; 159 char name[0]; 160} __attribute__ ((packed)); 161 162struct squashfs_dir_header_3 { 163 unsigned int count:8; 164 unsigned int start_block; 165 unsigned int inode_number; 166} __attribute__ ((packed)); 167 168struct squashfs_fragment_entry_3 { 169 long long start_block; 170 unsigned int size; 171 unsigned int pending; 172} __attribute__ ((packed)); 173 174 175typedef struct squashfs_super_block_3 squashfs_super_block_3; 176typedef struct squashfs_dir_index_3 squashfs_dir_index_3; 177typedef struct squashfs_base_inode_header_3 squashfs_base_inode_header_3; 178typedef struct squashfs_ipc_inode_header_3 squashfs_ipc_inode_header_3; 179typedef struct squashfs_dev_inode_header_3 squashfs_dev_inode_header_3; 180typedef struct squashfs_symlink_inode_header_3 squashfs_symlink_inode_header_3; 181typedef struct squashfs_reg_inode_header_3 squashfs_reg_inode_header_3; 182typedef struct squashfs_lreg_inode_header_3 squashfs_lreg_inode_header_3; 183typedef struct squashfs_dir_inode_header_3 squashfs_dir_inode_header_3; 184typedef struct squashfs_ldir_inode_header_3 squashfs_ldir_inode_header_3; 185typedef struct squashfs_dir_entry_3 squashfs_dir_entry_3; 186typedef struct squashfs_dir_header_3 squashfs_dir_header_3; 187typedef struct squashfs_fragment_entry_3 squashfs_fragment_entry_3; 188 189/* 190 * macros to convert each packed bitfield structure from little endian to big 191 * endian and vice versa. These are needed when creating or using a filesystem 192 * on a machine with different byte ordering to the target architecture. 193 * 194 */ 195 196#define SQUASHFS_SWAP_START \ 197 int bits;\ 198 int b_pos;\ 199 unsigned long long val;\ 200 unsigned char *s;\ 201 unsigned char *d; 202 203#define SQUASHFS_SWAP_SUPER_BLOCK_3(s, d) {\ 204 SQUASHFS_SWAP_START\ 205 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block_3));\ 206 SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\ 207 SQUASHFS_SWAP((s)->inodes, d, 32, 32);\ 208 SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\ 209 SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\ 210 SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\ 211 SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\ 212 SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\ 213 SQUASHFS_SWAP((s)->s_major, d, 224, 16);\ 214 SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\ 215 SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\ 216 SQUASHFS_SWAP((s)->block_log, d, 272, 16);\ 217 SQUASHFS_SWAP((s)->flags, d, 288, 8);\ 218 SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\ 219 SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\ 220 SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\ 221 SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\ 222 SQUASHFS_SWAP((s)->block_size, d, 408, 32);\ 223 SQUASHFS_SWAP((s)->fragments, d, 440, 32);\ 224 SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\ 225 SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\ 226 SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\ 227 SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\ 228 SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\ 229 SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\ 230 SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\ 231 SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\ 232} 233 234#define SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\ 235 SQUASHFS_MEMSET(s, d, n);\ 236 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\ 237 SQUASHFS_SWAP((s)->mode, d, 4, 12);\ 238 SQUASHFS_SWAP((s)->uid, d, 16, 8);\ 239 SQUASHFS_SWAP((s)->guid, d, 24, 8);\ 240 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\ 241 SQUASHFS_SWAP((s)->inode_number, d, 64, 32); 242 243#define SQUASHFS_SWAP_BASE_INODE_HEADER_3(s, d, n) {\ 244 SQUASHFS_SWAP_START\ 245 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, n)\ 246} 247 248#define SQUASHFS_SWAP_IPC_INODE_HEADER_3(s, d) {\ 249 SQUASHFS_SWAP_START\ 250 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 251 sizeof(struct squashfs_ipc_inode_header_3))\ 252 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 253} 254 255#define SQUASHFS_SWAP_DEV_INODE_HEADER_3(s, d) {\ 256 SQUASHFS_SWAP_START\ 257 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 258 sizeof(struct squashfs_dev_inode_header_3)); \ 259 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 260 SQUASHFS_SWAP((s)->rdev, d, 128, 16);\ 261} 262 263#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_3(s, d) {\ 264 SQUASHFS_SWAP_START\ 265 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 266 sizeof(struct squashfs_symlink_inode_header_3));\ 267 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 268 SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\ 269} 270 271#define SQUASHFS_SWAP_REG_INODE_HEADER_3(s, d) {\ 272 SQUASHFS_SWAP_START\ 273 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 274 sizeof(struct squashfs_reg_inode_header_3));\ 275 SQUASHFS_SWAP((s)->start_block, d, 96, 64);\ 276 SQUASHFS_SWAP((s)->fragment, d, 160, 32);\ 277 SQUASHFS_SWAP((s)->offset, d, 192, 32);\ 278 SQUASHFS_SWAP((s)->file_size, d, 224, 32);\ 279} 280 281#define SQUASHFS_SWAP_LREG_INODE_HEADER_3(s, d) {\ 282 SQUASHFS_SWAP_START\ 283 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 284 sizeof(struct squashfs_lreg_inode_header_3));\ 285 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 286 SQUASHFS_SWAP((s)->start_block, d, 128, 64);\ 287 SQUASHFS_SWAP((s)->fragment, d, 192, 32);\ 288 SQUASHFS_SWAP((s)->offset, d, 224, 32);\ 289 SQUASHFS_SWAP((s)->file_size, d, 256, 64);\ 290} 291 292#define SQUASHFS_SWAP_DIR_INODE_HEADER_3(s, d) {\ 293 SQUASHFS_SWAP_START\ 294 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 295 sizeof(struct squashfs_dir_inode_header_3));\ 296 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 297 SQUASHFS_SWAP((s)->file_size, d, 128, 19);\ 298 SQUASHFS_SWAP((s)->offset, d, 147, 13);\ 299 SQUASHFS_SWAP((s)->start_block, d, 160, 32);\ 300 SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\ 301} 302 303#define SQUASHFS_SWAP_LDIR_INODE_HEADER_3(s, d) {\ 304 SQUASHFS_SWAP_START\ 305 SQUASHFS_SWAP_BASE_INODE_CORE_3(s, d, \ 306 sizeof(struct squashfs_ldir_inode_header_3));\ 307 SQUASHFS_SWAP((s)->nlink, d, 96, 32);\ 308 SQUASHFS_SWAP((s)->file_size, d, 128, 27);\ 309 SQUASHFS_SWAP((s)->offset, d, 155, 13);\ 310 SQUASHFS_SWAP((s)->start_block, d, 168, 32);\ 311 SQUASHFS_SWAP((s)->i_count, d, 200, 16);\ 312 SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\ 313} 314 315#define SQUASHFS_SWAP_DIR_INDEX_3(s, d) {\ 316 SQUASHFS_SWAP_START\ 317 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_3));\ 318 SQUASHFS_SWAP((s)->index, d, 0, 32);\ 319 SQUASHFS_SWAP((s)->start_block, d, 32, 32);\ 320 SQUASHFS_SWAP((s)->size, d, 64, 8);\ 321} 322 323#define SQUASHFS_SWAP_DIR_HEADER_3(s, d) {\ 324 SQUASHFS_SWAP_START\ 325 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_3));\ 326 SQUASHFS_SWAP((s)->count, d, 0, 8);\ 327 SQUASHFS_SWAP((s)->start_block, d, 8, 32);\ 328 SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\ 329} 330 331#define SQUASHFS_SWAP_DIR_ENTRY_3(s, d) {\ 332 SQUASHFS_SWAP_START\ 333 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_3));\ 334 SQUASHFS_SWAP((s)->offset, d, 0, 13);\ 335 SQUASHFS_SWAP((s)->type, d, 13, 3);\ 336 SQUASHFS_SWAP((s)->size, d, 16, 8);\ 337 SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\ 338} 339 340#define SQUASHFS_SWAP_INODE_T_3(s, d) SQUASHFS_SWAP_LONG_LONGS_3(s, d, 1) 341 342#define SQUASHFS_SWAP_SHORTS_3(s, d, n) {\ 343 int entry;\ 344 int bit_position;\ 345 SQUASHFS_SWAP_START\ 346 SQUASHFS_MEMSET(s, d, n * 2);\ 347 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \ 348 16)\ 349 SQUASHFS_SWAP(s[entry], d, bit_position, 16);\ 350} 351 352#define SQUASHFS_SWAP_INTS_3(s, d, n) {\ 353 int entry;\ 354 int bit_position;\ 355 SQUASHFS_SWAP_START\ 356 SQUASHFS_MEMSET(s, d, n * 4);\ 357 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \ 358 32)\ 359 SQUASHFS_SWAP(s[entry], d, bit_position, 32);\ 360} 361 362#define SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) {\ 363 int entry;\ 364 int bit_position;\ 365 SQUASHFS_SWAP_START\ 366 SQUASHFS_MEMSET(s, d, n * 8);\ 367 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \ 368 64)\ 369 SQUASHFS_SWAP(s[entry], d, bit_position, 64);\ 370} 371 372#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\ 373 int entry;\ 374 int bit_position;\ 375 SQUASHFS_SWAP_START\ 376 SQUASHFS_MEMSET(s, d, n * bits / 8);\ 377 for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \ 378 bits)\ 379 SQUASHFS_SWAP(s[entry], d, bit_position, bits);\ 380} 381 382#define SQUASHFS_SWAP_FRAGMENT_INDEXES_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) 383#define SQUASHFS_SWAP_LOOKUP_BLOCKS_3(s, d, n) SQUASHFS_SWAP_LONG_LONGS_3(s, d, n) 384 385#define SQUASHFS_SWAP_FRAGMENT_ENTRY_3(s, d) {\ 386 SQUASHFS_SWAP_START\ 387 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_3));\ 388 SQUASHFS_SWAP((s)->start_block, d, 0, 64);\ 389 SQUASHFS_SWAP((s)->size, d, 64, 32);\ 390} 391 392/* fragment and fragment table defines */ 393#define SQUASHFS_FRAGMENT_BYTES_3(A) ((A) * sizeof(struct squashfs_fragment_entry_3)) 394 395#define SQUASHFS_FRAGMENT_INDEX_3(A) (SQUASHFS_FRAGMENT_BYTES_3(A) / \ 396 SQUASHFS_METADATA_SIZE) 397 398#define SQUASHFS_FRAGMENT_INDEX_OFFSET_3(A) (SQUASHFS_FRAGMENT_BYTES_3(A) % \ 399 SQUASHFS_METADATA_SIZE) 400 401#define SQUASHFS_FRAGMENT_INDEXES_3(A) ((SQUASHFS_FRAGMENT_BYTES_3(A) + \ 402 SQUASHFS_METADATA_SIZE - 1) / \ 403 SQUASHFS_METADATA_SIZE) 404 405#define SQUASHFS_FRAGMENT_INDEX_BYTES_3(A) (SQUASHFS_FRAGMENT_INDEXES_3(A) *\ 406 sizeof(long long)) 407 408/* 409 * definitions for structures on disk - layout 1.x 410 */ 411#define SQUASHFS_TYPES 5 412#define SQUASHFS_IPC_TYPE 0 413 414struct squashfs_base_inode_header_1 { 415 unsigned int inode_type:4; 416 unsigned int mode:12; /* protection */ 417 unsigned int uid:4; /* index into uid table */ 418 unsigned int guid:4; /* index into guid table */ 419} __attribute__ ((packed)); 420 421struct squashfs_ipc_inode_header_1 { 422 unsigned int inode_type:4; 423 unsigned int mode:12; /* protection */ 424 unsigned int uid:4; /* index into uid table */ 425 unsigned int guid:4; /* index into guid table */ 426 unsigned int type:4; 427 unsigned int offset:4; 428} __attribute__ ((packed)); 429 430struct squashfs_dev_inode_header_1 { 431 unsigned int inode_type:4; 432 unsigned int mode:12; /* protection */ 433 unsigned int uid:4; /* index into uid table */ 434 unsigned int guid:4; /* index into guid table */ 435 unsigned short rdev; 436} __attribute__ ((packed)); 437 438struct squashfs_symlink_inode_header_1 { 439 unsigned int inode_type:4; 440 unsigned int mode:12; /* protection */ 441 unsigned int uid:4; /* index into uid table */ 442 unsigned int guid:4; /* index into guid table */ 443 unsigned short symlink_size; 444 char symlink[0]; 445} __attribute__ ((packed)); 446 447struct squashfs_reg_inode_header_1 { 448 unsigned int inode_type:4; 449 unsigned int mode:12; /* protection */ 450 unsigned int uid:4; /* index into uid table */ 451 unsigned int guid:4; /* index into guid table */ 452 unsigned int mtime; 453 unsigned int start_block; 454 unsigned int file_size:32; 455 unsigned short block_list[0]; 456} __attribute__ ((packed)); 457 458struct squashfs_dir_inode_header_1 { 459 unsigned int inode_type:4; 460 unsigned int mode:12; /* protection */ 461 unsigned int uid:4; /* index into uid table */ 462 unsigned int guid:4; /* index into guid table */ 463 unsigned int file_size:19; 464 unsigned int offset:13; 465 unsigned int mtime; 466 unsigned int start_block:24; 467} __attribute__ ((packed)); 468 469union squashfs_inode_header_1 { 470 struct squashfs_base_inode_header_1 base; 471 struct squashfs_dev_inode_header_1 dev; 472 struct squashfs_symlink_inode_header_1 symlink; 473 struct squashfs_reg_inode_header_1 reg; 474 struct squashfs_dir_inode_header_1 dir; 475 struct squashfs_ipc_inode_header_1 ipc; 476}; 477 478typedef struct squashfs_dir_index_1 squashfs_dir_index_1; 479typedef struct squashfs_base_inode_header_1 squashfs_base_inode_header_1; 480typedef struct squashfs_ipc_inode_header_1 squashfs_ipc_inode_header_1; 481typedef struct squashfs_dev_inode_header_1 squashfs_dev_inode_header_1; 482typedef struct squashfs_symlink_inode_header_1 squashfs_symlink_inode_header_1; 483typedef struct squashfs_reg_inode_header_1 squashfs_reg_inode_header_1; 484typedef struct squashfs_dir_inode_header_1 squashfs_dir_inode_header_1; 485 486#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \ 487 SQUASHFS_MEMSET(s, d, n);\ 488 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\ 489 SQUASHFS_SWAP((s)->mode, d, 4, 12);\ 490 SQUASHFS_SWAP((s)->uid, d, 16, 4);\ 491 SQUASHFS_SWAP((s)->guid, d, 20, 4); 492 493#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\ 494 SQUASHFS_SWAP_START\ 495 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\ 496} 497 498#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\ 499 SQUASHFS_SWAP_START\ 500 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \ 501 sizeof(struct squashfs_ipc_inode_header_1));\ 502 SQUASHFS_SWAP((s)->type, d, 24, 4);\ 503 SQUASHFS_SWAP((s)->offset, d, 28, 4);\ 504} 505 506#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\ 507 SQUASHFS_SWAP_START\ 508 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \ 509 sizeof(struct squashfs_dev_inode_header_1));\ 510 SQUASHFS_SWAP((s)->rdev, d, 24, 16);\ 511} 512 513#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\ 514 SQUASHFS_SWAP_START\ 515 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \ 516 sizeof(struct squashfs_symlink_inode_header_1));\ 517 SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\ 518} 519 520#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\ 521 SQUASHFS_SWAP_START\ 522 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \ 523 sizeof(struct squashfs_reg_inode_header_1));\ 524 SQUASHFS_SWAP((s)->mtime, d, 24, 32);\ 525 SQUASHFS_SWAP((s)->start_block, d, 56, 32);\ 526 SQUASHFS_SWAP((s)->file_size, d, 88, 32);\ 527} 528 529#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\ 530 SQUASHFS_SWAP_START\ 531 SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \ 532 sizeof(struct squashfs_dir_inode_header_1));\ 533 SQUASHFS_SWAP((s)->file_size, d, 24, 19);\ 534 SQUASHFS_SWAP((s)->offset, d, 43, 13);\ 535 SQUASHFS_SWAP((s)->mtime, d, 56, 32);\ 536 SQUASHFS_SWAP((s)->start_block, d, 88, 24);\ 537} 538 539/* 540 * definitions for structures on disk - layout 2.x 541 */ 542struct squashfs_dir_index_2 { 543 unsigned int index:27; 544 unsigned int start_block:29; 545 unsigned char size; 546 unsigned char name[0]; 547} __attribute__ ((packed)); 548 549struct squashfs_base_inode_header_2 { 550 unsigned int inode_type:4; 551 unsigned int mode:12; /* protection */ 552 unsigned int uid:8; /* index into uid table */ 553 unsigned int guid:8; /* index into guid table */ 554} __attribute__ ((packed)); 555 556struct squashfs_ipc_inode_header_2 { 557 unsigned int inode_type:4; 558 unsigned int mode:12; /* protection */ 559 unsigned int uid:8; /* index into uid table */ 560 unsigned int guid:8; /* index into guid table */ 561} __attribute__ ((packed)); 562 563struct squashfs_dev_inode_header_2 { 564 unsigned int inode_type:4; 565 unsigned int mode:12; /* protection */ 566 unsigned int uid:8; /* index into uid table */ 567 unsigned int guid:8; /* index into guid table */ 568 unsigned short rdev; 569} __attribute__ ((packed)); 570 571struct squashfs_symlink_inode_header_2 { 572 unsigned int inode_type:4; 573 unsigned int mode:12; /* protection */ 574 unsigned int uid:8; /* index into uid table */ 575 unsigned int guid:8; /* index into guid table */ 576 unsigned short symlink_size; 577 char symlink[0]; 578} __attribute__ ((packed)); 579 580struct squashfs_reg_inode_header_2 { 581 unsigned int inode_type:4; 582 unsigned int mode:12; /* protection */ 583 unsigned int uid:8; /* index into uid table */ 584 unsigned int guid:8; /* index into guid table */ 585 unsigned int mtime; 586 unsigned int start_block; 587 unsigned int fragment; 588 unsigned int offset; 589 unsigned int file_size:32; 590 unsigned short block_list[0]; 591} __attribute__ ((packed)); 592 593struct squashfs_dir_inode_header_2 { 594 unsigned int inode_type:4; 595 unsigned int mode:12; /* protection */ 596 unsigned int uid:8; /* index into uid table */ 597 unsigned int guid:8; /* index into guid table */ 598 unsigned int file_size:19; 599 unsigned int offset:13; 600 unsigned int mtime; 601 unsigned int start_block:24; 602} __attribute__ ((packed)); 603 604struct squashfs_ldir_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 unsigned int file_size:27; 610 unsigned int offset:13; 611 unsigned int mtime; 612 unsigned int start_block:24; 613 unsigned int i_count:16; 614 struct squashfs_dir_index_2 index[0]; 615} __attribute__ ((packed)); 616 617union squashfs_inode_header_2 { 618 struct squashfs_base_inode_header_2 base; 619 struct squashfs_dev_inode_header_2 dev; 620 struct squashfs_symlink_inode_header_2 symlink; 621 struct squashfs_reg_inode_header_2 reg; 622 struct squashfs_dir_inode_header_2 dir; 623 struct squashfs_ldir_inode_header_2 ldir; 624 struct squashfs_ipc_inode_header_2 ipc; 625}; 626 627struct squashfs_dir_header_2 { 628 unsigned int count:8; 629 unsigned int start_block:24; 630} __attribute__ ((packed)); 631 632struct squashfs_dir_entry_2 { 633 unsigned int offset:13; 634 unsigned int type:3; 635 unsigned int size:8; 636 char name[0]; 637} __attribute__ ((packed)); 638 639struct squashfs_fragment_entry_2 { 640 unsigned int start_block; 641 unsigned int size; 642} __attribute__ ((packed)); 643 644typedef struct squashfs_dir_index_2 squashfs_dir_index_2; 645typedef struct squashfs_base_inode_header_2 squashfs_base_inode_header_2; 646typedef struct squashfs_ipc_inode_header_2 squashfs_ipc_inode_header_2; 647typedef struct squashfs_dev_inode_header_2 squashfs_dev_inode_header_2; 648typedef struct squashfs_symlink_inode_header_2 squashfs_symlink_inode_header_2; 649typedef struct squashfs_reg_inode_header_2 squashfs_reg_inode_header_2; 650typedef struct squashfs_lreg_inode_header_2 squashfs_lreg_inode_header_2; 651typedef struct squashfs_dir_inode_header_2 squashfs_dir_inode_header_2; 652typedef struct squashfs_ldir_inode_header_2 squashfs_ldir_inode_header_2; 653typedef struct squashfs_dir_entry_2 squashfs_dir_entry_2; 654typedef struct squashfs_dir_header_2 squashfs_dir_header_2; 655typedef struct squashfs_fragment_entry_2 squashfs_fragment_entry_2; 656 657#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\ 658 SQUASHFS_MEMSET(s, d, n);\ 659 SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\ 660 SQUASHFS_SWAP((s)->mode, d, 4, 12);\ 661 SQUASHFS_SWAP((s)->uid, d, 16, 8);\ 662 SQUASHFS_SWAP((s)->guid, d, 24, 8);\ 663 664#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\ 665 SQUASHFS_SWAP_START\ 666 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\ 667} 668 669#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \ 670 SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2)) 671 672#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\ 673 SQUASHFS_SWAP_START\ 674 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \ 675 sizeof(struct squashfs_dev_inode_header_2)); \ 676 SQUASHFS_SWAP((s)->rdev, d, 32, 16);\ 677} 678 679#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\ 680 SQUASHFS_SWAP_START\ 681 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \ 682 sizeof(struct squashfs_symlink_inode_header_2));\ 683 SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\ 684} 685 686#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\ 687 SQUASHFS_SWAP_START\ 688 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \ 689 sizeof(struct squashfs_reg_inode_header_2));\ 690 SQUASHFS_SWAP((s)->mtime, d, 32, 32);\ 691 SQUASHFS_SWAP((s)->start_block, d, 64, 32);\ 692 SQUASHFS_SWAP((s)->fragment, d, 96, 32);\ 693 SQUASHFS_SWAP((s)->offset, d, 128, 32);\ 694 SQUASHFS_SWAP((s)->file_size, d, 160, 32);\ 695} 696 697#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\ 698 SQUASHFS_SWAP_START\ 699 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \ 700 sizeof(struct squashfs_dir_inode_header_2));\ 701 SQUASHFS_SWAP((s)->file_size, d, 32, 19);\ 702 SQUASHFS_SWAP((s)->offset, d, 51, 13);\ 703 SQUASHFS_SWAP((s)->mtime, d, 64, 32);\ 704 SQUASHFS_SWAP((s)->start_block, d, 96, 24);\ 705} 706 707#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\ 708 SQUASHFS_SWAP_START\ 709 SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \ 710 sizeof(struct squashfs_ldir_inode_header_2));\ 711 SQUASHFS_SWAP((s)->file_size, d, 32, 27);\ 712 SQUASHFS_SWAP((s)->offset, d, 59, 13);\ 713 SQUASHFS_SWAP((s)->mtime, d, 72, 32);\ 714 SQUASHFS_SWAP((s)->start_block, d, 104, 24);\ 715 SQUASHFS_SWAP((s)->i_count, d, 128, 16);\ 716} 717 718#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\ 719 SQUASHFS_SWAP_START\ 720 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\ 721 SQUASHFS_SWAP((s)->index, d, 0, 27);\ 722 SQUASHFS_SWAP((s)->start_block, d, 27, 29);\ 723 SQUASHFS_SWAP((s)->size, d, 56, 8);\ 724} 725#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\ 726 SQUASHFS_SWAP_START\ 727 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\ 728 SQUASHFS_SWAP((s)->count, d, 0, 8);\ 729 SQUASHFS_SWAP((s)->start_block, d, 8, 24);\ 730} 731 732#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\ 733 SQUASHFS_SWAP_START\ 734 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\ 735 SQUASHFS_SWAP((s)->offset, d, 0, 13);\ 736 SQUASHFS_SWAP((s)->type, d, 13, 3);\ 737 SQUASHFS_SWAP((s)->size, d, 16, 8);\ 738} 739 740#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\ 741 SQUASHFS_SWAP_START\ 742 SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\ 743 SQUASHFS_SWAP((s)->start_block, d, 0, 32);\ 744 SQUASHFS_SWAP((s)->size, d, 32, 32);\ 745} 746 747#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS_3(s, d, n) 748 749/* fragment and fragment table defines */ 750#define SQUASHFS_FRAGMENT_BYTES_2(A) ((A) * sizeof(struct squashfs_fragment_entry_2)) 751 752#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \ 753 SQUASHFS_METADATA_SIZE) 754 755#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \ 756 SQUASHFS_METADATA_SIZE) 757 758#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \ 759 SQUASHFS_METADATA_SIZE - 1) / \ 760 SQUASHFS_METADATA_SIZE) 761 762#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\ 763 sizeof(int)) 764/* 765 * macros used to swap each structure entry, taking into account 766 * bitfields and different bitfield placing conventions on differing architectures 767 */ 768#if __BYTE_ORDER == __BIG_ENDIAN 769 /* convert from big endian to little endian */ 770#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos) 771#else 772 /* convert from little endian to big endian */ 773#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos) 774#endif 775 776#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\ 777 b_pos = pos % 8;\ 778 val = 0;\ 779 s = (unsigned char *)p + (pos / 8);\ 780 d = ((unsigned char *) &val) + 7;\ 781 for(bits = 0; bits < (tbits + b_pos); bits += 8) \ 782 *d-- = *s++;\ 783 value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\ 784} 785#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n); 786#endif 787