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