1*79398b25SAndroid Build Coastguard Worker SQUASHFS 4.3 - A squashed read-only filesystem for Linux 2*79398b25SAndroid Build Coastguard Worker 3*79398b25SAndroid Build Coastguard Worker Copyright 2002-2014 Phillip Lougher <[email protected]> 4*79398b25SAndroid Build Coastguard Worker 5*79398b25SAndroid Build Coastguard Worker Released under the GPL licence (version 2 or later). 6*79398b25SAndroid Build Coastguard Worker 7*79398b25SAndroid Build Coastguard WorkerWelcome to Squashfs version 4.3. Please read the README-4.3 and CHANGES files 8*79398b25SAndroid Build Coastguard Workerfor details of changes. 9*79398b25SAndroid Build Coastguard Worker 10*79398b25SAndroid Build Coastguard WorkerSquashfs is a highly compressed read-only filesystem for Linux. 11*79398b25SAndroid Build Coastguard WorkerIt uses either gzip/xz/lzo/lz4 compression to compress both files, inodes 12*79398b25SAndroid Build Coastguard Workerand directories. Inodes in the system are very small and all blocks are 13*79398b25SAndroid Build Coastguard Workerpacked to minimise data overhead. Block sizes greater than 4K are supported 14*79398b25SAndroid Build Coastguard Workerup to a maximum of 1Mbytes (default block size 128K). 15*79398b25SAndroid Build Coastguard Worker 16*79398b25SAndroid Build Coastguard WorkerSquashfs is intended for general read-only filesystem use, for archival 17*79398b25SAndroid Build Coastguard Workeruse (i.e. in cases where a .tar.gz file may be used), and in constrained 18*79398b25SAndroid Build Coastguard Workerblock device/memory systems (e.g. embedded systems) where low overhead is 19*79398b25SAndroid Build Coastguard Workerneeded. 20*79398b25SAndroid Build Coastguard Worker 21*79398b25SAndroid Build Coastguard Worker1. SQUASHFS OVERVIEW 22*79398b25SAndroid Build Coastguard Worker-------------------- 23*79398b25SAndroid Build Coastguard Worker 24*79398b25SAndroid Build Coastguard Worker1. Data, inodes and directories are compressed. 25*79398b25SAndroid Build Coastguard Worker 26*79398b25SAndroid Build Coastguard Worker2. Squashfs stores full uid/gids (32 bits), and file creation time. 27*79398b25SAndroid Build Coastguard Worker 28*79398b25SAndroid Build Coastguard Worker3. In theory files up to 2^64 bytes are supported. In theory filesystems can 29*79398b25SAndroid Build Coastguard Worker be up to 2^64 bytes. 30*79398b25SAndroid Build Coastguard Worker 31*79398b25SAndroid Build Coastguard Worker4. Inode and directory data are highly compacted, and packed on byte 32*79398b25SAndroid Build Coastguard Worker boundaries. Each compressed inode is on average 8 bytes in length 33*79398b25SAndroid Build Coastguard Worker (the exact length varies on file type, i.e. regular file, directory, 34*79398b25SAndroid Build Coastguard Worker symbolic link, and block/char device inodes have different sizes). 35*79398b25SAndroid Build Coastguard Worker 36*79398b25SAndroid Build Coastguard Worker5. Squashfs can use block sizes up to 1Mbyte (the default size is 128K). 37*79398b25SAndroid Build Coastguard Worker Using 128K blocks achieves greater compression ratios than the normal 38*79398b25SAndroid Build Coastguard Worker 4K block size. 39*79398b25SAndroid Build Coastguard Worker 40*79398b25SAndroid Build Coastguard Worker6. File duplicates are detected and removed. 41*79398b25SAndroid Build Coastguard Worker 42*79398b25SAndroid Build Coastguard Worker7. Filesystems can be compressed with gzip, xz (lzma2), lzo or lz4 43*79398b25SAndroid Build Coastguard Worker compression algorithms. 44*79398b25SAndroid Build Coastguard Worker 45*79398b25SAndroid Build Coastguard Worker1.1 Extended attributes (xattrs) 46*79398b25SAndroid Build Coastguard Worker-------------------------------- 47*79398b25SAndroid Build Coastguard Worker 48*79398b25SAndroid Build Coastguard WorkerSquashfs filesystems now have extended attribute support. The 49*79398b25SAndroid Build Coastguard Workerextended attribute implementation has the following features: 50*79398b25SAndroid Build Coastguard Worker 51*79398b25SAndroid Build Coastguard Worker1. Layout can store up to 2^48 bytes of compressed xattr data. 52*79398b25SAndroid Build Coastguard Worker2. Number of xattrs per inode unlimited. 53*79398b25SAndroid Build Coastguard Worker3. Total size of xattr data per inode 2^48 bytes of compressed data. 54*79398b25SAndroid Build Coastguard Worker4. Up to 4 Gbytes of data per xattr value. 55*79398b25SAndroid Build Coastguard Worker5. Inline and out-of-line xattr values supported for higher performance 56*79398b25SAndroid Build Coastguard Worker in xattr scanning (listxattr & getxattr), and to allow xattr value 57*79398b25SAndroid Build Coastguard Worker de-duplication. 58*79398b25SAndroid Build Coastguard Worker6. Both whole inode xattr duplicate detection and individual xattr value 59*79398b25SAndroid Build Coastguard Worker duplicate detection supported. These can obviously nest, file C's 60*79398b25SAndroid Build Coastguard Worker xattrs can be a complete duplicate of file B, and file B's xattrs 61*79398b25SAndroid Build Coastguard Worker can be a partial duplicate of file A. 62*79398b25SAndroid Build Coastguard Worker7. Xattr name prefix types stored, allowing the redundant "user.", "trusted." 63*79398b25SAndroid Build Coastguard Worker etc. characters to be eliminated and more concisely stored. 64*79398b25SAndroid Build Coastguard Worker8. Support for files, directories, symbolic links, device nodes, fifos 65*79398b25SAndroid Build Coastguard Worker and sockets. 66*79398b25SAndroid Build Coastguard Worker 67*79398b25SAndroid Build Coastguard WorkerExtended attribute support is in 2.6.35 and later kernels. Filesystems 68*79398b25SAndroid Build Coastguard Workerwith extended attributes can be mounted on 2.6.29 and later kernels, the 69*79398b25SAndroid Build Coastguard Workerextended attributes will be ignored with a warning. 70*79398b25SAndroid Build Coastguard Worker 71*79398b25SAndroid Build Coastguard Worker2. USING SQUASHFS 72*79398b25SAndroid Build Coastguard Worker----------------- 73*79398b25SAndroid Build Coastguard Worker 74*79398b25SAndroid Build Coastguard WorkerSquashfs filesystems should be mounted with 'mount' with the filesystem type 75*79398b25SAndroid Build Coastguard Worker'squashfs'. If the filesystem is on a block device, the filesystem can be 76*79398b25SAndroid Build Coastguard Workermounted directly, e.g. 77*79398b25SAndroid Build Coastguard Worker 78*79398b25SAndroid Build Coastguard Worker%mount -t squashfs /dev/sda1 /mnt 79*79398b25SAndroid Build Coastguard Worker 80*79398b25SAndroid Build Coastguard WorkerWill mount the squashfs filesystem on "/dev/sda1" under the directory "/mnt". 81*79398b25SAndroid Build Coastguard Worker 82*79398b25SAndroid Build Coastguard WorkerIf the squashfs filesystem has been written to a file, the loopback device 83*79398b25SAndroid Build Coastguard Workercan be used to mount it (loopback support must be in the kernel), e.g. 84*79398b25SAndroid Build Coastguard Worker 85*79398b25SAndroid Build Coastguard Worker%mount -t squashfs image /mnt -o loop 86*79398b25SAndroid Build Coastguard Worker 87*79398b25SAndroid Build Coastguard WorkerWill mount the squashfs filesystem in the file "image" under 88*79398b25SAndroid Build Coastguard Workerthe directory "/mnt". 89*79398b25SAndroid Build Coastguard Worker 90*79398b25SAndroid Build Coastguard Worker3. MKSQUASHFS 91*79398b25SAndroid Build Coastguard Worker------------- 92*79398b25SAndroid Build Coastguard Worker 93*79398b25SAndroid Build Coastguard Worker3.1 Mksquashfs options and overview 94*79398b25SAndroid Build Coastguard Worker----------------------------------- 95*79398b25SAndroid Build Coastguard Worker 96*79398b25SAndroid Build Coastguard WorkerAs squashfs is a read-only filesystem, the mksquashfs program must be used to 97*79398b25SAndroid Build Coastguard Workercreate populated squashfs filesystems. 98*79398b25SAndroid Build Coastguard Worker 99*79398b25SAndroid Build Coastguard WorkerSYNTAX:./mksquashfs source1 source2 ... dest [options] [-e list of exclude 100*79398b25SAndroid Build Coastguard Workerdirs/files] 101*79398b25SAndroid Build Coastguard Worker 102*79398b25SAndroid Build Coastguard WorkerFilesystem build options: 103*79398b25SAndroid Build Coastguard Worker-comp <comp> select <comp> compression 104*79398b25SAndroid Build Coastguard Worker Compressors available: 105*79398b25SAndroid Build Coastguard Worker gzip (default) 106*79398b25SAndroid Build Coastguard Worker lzo 107*79398b25SAndroid Build Coastguard Worker lz4 108*79398b25SAndroid Build Coastguard Worker xz 109*79398b25SAndroid Build Coastguard Worker-b <block_size> set data block to <block_size>. Default 128 Kbytes 110*79398b25SAndroid Build Coastguard Worker Optionally a suffix of K or M can be given to specify 111*79398b25SAndroid Build Coastguard Worker Kbytes or Mbytes respectively 112*79398b25SAndroid Build Coastguard Worker-no-exports don't make the filesystem exportable via NFS 113*79398b25SAndroid Build Coastguard Worker-no-sparse don't detect sparse files 114*79398b25SAndroid Build Coastguard Worker-no-xattrs don't store extended attributes 115*79398b25SAndroid Build Coastguard Worker-xattrs store extended attributes (default) 116*79398b25SAndroid Build Coastguard Worker-noI do not compress inode table 117*79398b25SAndroid Build Coastguard Worker-noD do not compress data blocks 118*79398b25SAndroid Build Coastguard Worker-noF do not compress fragment blocks 119*79398b25SAndroid Build Coastguard Worker-noX do not compress extended attributes 120*79398b25SAndroid Build Coastguard Worker-no-fragments do not use fragments 121*79398b25SAndroid Build Coastguard Worker-always-use-fragments use fragment blocks for files larger than block size 122*79398b25SAndroid Build Coastguard Worker-no-duplicates do not perform duplicate checking 123*79398b25SAndroid Build Coastguard Worker-all-root make all files owned by root 124*79398b25SAndroid Build Coastguard Worker-force-uid uid set all file uids to uid 125*79398b25SAndroid Build Coastguard Worker-force-gid gid set all file gids to gid 126*79398b25SAndroid Build Coastguard Worker-nopad do not pad filesystem to a multiple of 4K 127*79398b25SAndroid Build Coastguard Worker-keep-as-directory if one source directory is specified, create a root 128*79398b25SAndroid Build Coastguard Worker directory containing that directory, rather than the 129*79398b25SAndroid Build Coastguard Worker contents of the directory 130*79398b25SAndroid Build Coastguard Worker 131*79398b25SAndroid Build Coastguard WorkerFilesystem filter options: 132*79398b25SAndroid Build Coastguard Worker-p <pseudo-definition> Add pseudo file definition 133*79398b25SAndroid Build Coastguard Worker-pf <pseudo-file> Add list of pseudo file definitions 134*79398b25SAndroid Build Coastguard Worker-sort <sort_file> sort files according to priorities in <sort_file>. One 135*79398b25SAndroid Build Coastguard Worker file or dir with priority per line. Priority -32768 to 136*79398b25SAndroid Build Coastguard Worker 32767, default priority 0 137*79398b25SAndroid Build Coastguard Worker-ef <exclude_file> list of exclude dirs/files. One per line 138*79398b25SAndroid Build Coastguard Worker-wildcards Allow extended shell wildcards (globbing) to be used in 139*79398b25SAndroid Build Coastguard Worker exclude dirs/files 140*79398b25SAndroid Build Coastguard Worker-regex Allow POSIX regular expressions to be used in exclude 141*79398b25SAndroid Build Coastguard Worker dirs/files 142*79398b25SAndroid Build Coastguard Worker 143*79398b25SAndroid Build Coastguard WorkerFilesystem append options: 144*79398b25SAndroid Build Coastguard Worker-noappend do not append to existing filesystem 145*79398b25SAndroid Build Coastguard Worker-root-becomes <name> when appending source files/directories, make the 146*79398b25SAndroid Build Coastguard Worker original root become a subdirectory in the new root 147*79398b25SAndroid Build Coastguard Worker called <name>, rather than adding the new source items 148*79398b25SAndroid Build Coastguard Worker to the original root 149*79398b25SAndroid Build Coastguard Worker 150*79398b25SAndroid Build Coastguard WorkerMksquashfs runtime options: 151*79398b25SAndroid Build Coastguard Worker-version print version, licence and copyright message 152*79398b25SAndroid Build Coastguard Worker-exit-on-error treat normally ignored errors as fatal 153*79398b25SAndroid Build Coastguard Worker-recover <name> recover filesystem data using recovery file <name> 154*79398b25SAndroid Build Coastguard Worker-no-recovery don't generate a recovery file 155*79398b25SAndroid Build Coastguard Worker-info print files written to filesystem 156*79398b25SAndroid Build Coastguard Worker-no-progress don't display the progress bar 157*79398b25SAndroid Build Coastguard Worker-progress display progress bar when using the -info option 158*79398b25SAndroid Build Coastguard Worker-processors <number> Use <number> processors. By default will use number of 159*79398b25SAndroid Build Coastguard Worker processors available 160*79398b25SAndroid Build Coastguard Worker-mem <size> Use <size> physical memory. Currently set to 1922M 161*79398b25SAndroid Build Coastguard Worker Optionally a suffix of K, M or G can be given to specify 162*79398b25SAndroid Build Coastguard Worker Kbytes, Mbytes or Gbytes respectively 163*79398b25SAndroid Build Coastguard Worker 164*79398b25SAndroid Build Coastguard WorkerMiscellaneous options: 165*79398b25SAndroid Build Coastguard Worker-root-owned alternative name for -all-root 166*79398b25SAndroid Build Coastguard Worker-noInodeCompression alternative name for -noI 167*79398b25SAndroid Build Coastguard Worker-noDataCompression alternative name for -noD 168*79398b25SAndroid Build Coastguard Worker-noFragmentCompression alternative name for -noF 169*79398b25SAndroid Build Coastguard Worker-noXattrCompression alternative name for -noX 170*79398b25SAndroid Build Coastguard Worker 171*79398b25SAndroid Build Coastguard Worker-Xhelp print compressor options for selected compressor 172*79398b25SAndroid Build Coastguard Worker 173*79398b25SAndroid Build Coastguard WorkerCompressors available and compressor specific options: 174*79398b25SAndroid Build Coastguard Worker gzip (default) 175*79398b25SAndroid Build Coastguard Worker -Xcompression-level <compression-level> 176*79398b25SAndroid Build Coastguard Worker <compression-level> should be 1 .. 9 (default 9) 177*79398b25SAndroid Build Coastguard Worker -Xwindow-size <window-size> 178*79398b25SAndroid Build Coastguard Worker <window-size> should be 8 .. 15 (default 15) 179*79398b25SAndroid Build Coastguard Worker -Xstrategy strategy1,strategy2,...,strategyN 180*79398b25SAndroid Build Coastguard Worker Compress using strategy1,strategy2,...,strategyN in turn 181*79398b25SAndroid Build Coastguard Worker and choose the best compression. 182*79398b25SAndroid Build Coastguard Worker Available strategies: default, filtered, huffman_only, 183*79398b25SAndroid Build Coastguard Worker run_length_encoded and fixed 184*79398b25SAndroid Build Coastguard Worker lzo 185*79398b25SAndroid Build Coastguard Worker -Xalgorithm <algorithm> 186*79398b25SAndroid Build Coastguard Worker Where <algorithm> is one of: 187*79398b25SAndroid Build Coastguard Worker lzo1x_1 188*79398b25SAndroid Build Coastguard Worker lzo1x_1_11 189*79398b25SAndroid Build Coastguard Worker lzo1x_1_12 190*79398b25SAndroid Build Coastguard Worker lzo1x_1_15 191*79398b25SAndroid Build Coastguard Worker lzo1x_999 (default) 192*79398b25SAndroid Build Coastguard Worker -Xcompression-level <compression-level> 193*79398b25SAndroid Build Coastguard Worker <compression-level> should be 1 .. 9 (default 8) 194*79398b25SAndroid Build Coastguard Worker Only applies to lzo1x_999 algorithm 195*79398b25SAndroid Build Coastguard Worker lz4 196*79398b25SAndroid Build Coastguard Worker -Xhc 197*79398b25SAndroid Build Coastguard Worker Compress using LZ4 High Compression 198*79398b25SAndroid Build Coastguard Worker xz 199*79398b25SAndroid Build Coastguard Worker -Xbcj filter1,filter2,...,filterN 200*79398b25SAndroid Build Coastguard Worker Compress using filter1,filter2,...,filterN in turn 201*79398b25SAndroid Build Coastguard Worker (in addition to no filter), and choose the best compression. 202*79398b25SAndroid Build Coastguard Worker Available filters: x86, arm, armthumb, powerpc, sparc, ia64 203*79398b25SAndroid Build Coastguard Worker -Xdict-size <dict-size> 204*79398b25SAndroid Build Coastguard Worker Use <dict-size> as the XZ dictionary size. The dictionary size 205*79398b25SAndroid Build Coastguard Worker can be specified as a percentage of the block size, or as an 206*79398b25SAndroid Build Coastguard Worker absolute value. The dictionary size must be less than or equal 207*79398b25SAndroid Build Coastguard Worker to the block size and 8192 bytes or larger. It must also be 208*79398b25SAndroid Build Coastguard Worker storable in the xz header as either 2^n or as 2^n+2^(n+1). 209*79398b25SAndroid Build Coastguard Worker Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K 210*79398b25SAndroid Build Coastguard Worker etc. 211*79398b25SAndroid Build Coastguard Worker 212*79398b25SAndroid Build Coastguard WorkerSource1 source2 ... are the source directories/files containing the 213*79398b25SAndroid Build Coastguard Workerfiles/directories that will form the squashfs filesystem. If a single 214*79398b25SAndroid Build Coastguard Workerdirectory is specified (i.e. mksquashfs source output_fs) the squashfs 215*79398b25SAndroid Build Coastguard Workerfilesystem will consist of that directory, with the top-level root 216*79398b25SAndroid Build Coastguard Workerdirectory corresponding to the source directory. 217*79398b25SAndroid Build Coastguard Worker 218*79398b25SAndroid Build Coastguard WorkerIf multiple source directories or files are specified, mksquashfs will merge 219*79398b25SAndroid Build Coastguard Workerthe specified sources into a single filesystem, with the root directory 220*79398b25SAndroid Build Coastguard Workercontaining each of the source files/directories. The name of each directory 221*79398b25SAndroid Build Coastguard Workerentry will be the basename of the source path. If more than one source 222*79398b25SAndroid Build Coastguard Workerentry maps to the same name, the conflicts are named xxx_1, xxx_2, etc. where 223*79398b25SAndroid Build Coastguard Workerxxx is the original name. 224*79398b25SAndroid Build Coastguard Worker 225*79398b25SAndroid Build Coastguard WorkerTo make this clear, take two example directories. Source directory 226*79398b25SAndroid Build Coastguard Worker"/home/phillip/test" contains "file1", "file2" and "dir1". 227*79398b25SAndroid Build Coastguard WorkerSource directory "goodies" contains "goodies1", "goodies2" and "goodies3". 228*79398b25SAndroid Build Coastguard Worker 229*79398b25SAndroid Build Coastguard Workerusage example 1: 230*79398b25SAndroid Build Coastguard Worker 231*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test output_fs 232*79398b25SAndroid Build Coastguard Worker 233*79398b25SAndroid Build Coastguard WorkerThis will generate a squashfs filesystem with root entries 234*79398b25SAndroid Build Coastguard Worker"file1", "file2" and "dir1". 235*79398b25SAndroid Build Coastguard Worker 236*79398b25SAndroid Build Coastguard Workerexample 2: 237*79398b25SAndroid Build Coastguard Worker 238*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test goodies output_fs 239*79398b25SAndroid Build Coastguard Worker 240*79398b25SAndroid Build Coastguard WorkerThis will create a squashfs filesystem with the root containing 241*79398b25SAndroid Build Coastguard Workerentries "test" and "goodies" corresponding to the source 242*79398b25SAndroid Build Coastguard Workerdirectories "/home/phillip/test" and "goodies". 243*79398b25SAndroid Build Coastguard Worker 244*79398b25SAndroid Build Coastguard Workerexample 3: 245*79398b25SAndroid Build Coastguard Worker 246*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test goodies test output_fs 247*79398b25SAndroid Build Coastguard Worker 248*79398b25SAndroid Build Coastguard WorkerThis is the same as the previous example, except a third 249*79398b25SAndroid Build Coastguard Workersource directory "test" has been specified. This conflicts 250*79398b25SAndroid Build Coastguard Workerwith the first directory named "test" and will be renamed "test_1". 251*79398b25SAndroid Build Coastguard Worker 252*79398b25SAndroid Build Coastguard WorkerMultiple sources allow filesystems to be generated without needing to 253*79398b25SAndroid Build Coastguard Workercopy all source files into a common directory. This simplifies creating 254*79398b25SAndroid Build Coastguard Workerfilesystems. 255*79398b25SAndroid Build Coastguard Worker 256*79398b25SAndroid Build Coastguard WorkerThe -keep-as-directory option can be used when only one source directory 257*79398b25SAndroid Build Coastguard Workeris specified, and you wish the root to contain that directory, rather than 258*79398b25SAndroid Build Coastguard Workerthe contents of the directory. For example: 259*79398b25SAndroid Build Coastguard Worker 260*79398b25SAndroid Build Coastguard Workerexample 4: 261*79398b25SAndroid Build Coastguard Worker 262*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test output_fs -keep-as-directory 263*79398b25SAndroid Build Coastguard Worker 264*79398b25SAndroid Build Coastguard WorkerThis is the same as example 1, except for -keep-as-directory. 265*79398b25SAndroid Build Coastguard WorkerThis will generate a root directory containing directory "test", 266*79398b25SAndroid Build Coastguard Workerrather than the "test" directory contents "file1", "file2" and "dir1". 267*79398b25SAndroid Build Coastguard Worker 268*79398b25SAndroid Build Coastguard WorkerThe Dest argument is the destination where the squashfs filesystem will be 269*79398b25SAndroid Build Coastguard Workerwritten. This can either be a conventional file or a block device. If the file 270*79398b25SAndroid Build Coastguard Workerdoesn't exist it will be created, if it does exist and a squashfs 271*79398b25SAndroid Build Coastguard Workerfilesystem exists on it, mksquashfs will append. The -noappend option will 272*79398b25SAndroid Build Coastguard Workerwrite a new filesystem irrespective of whether an existing filesystem is 273*79398b25SAndroid Build Coastguard Workerpresent. 274*79398b25SAndroid Build Coastguard Worker 275*79398b25SAndroid Build Coastguard Worker3.2 Changing compression algorithm and compression specific options 276*79398b25SAndroid Build Coastguard Worker------------------------------------------------------------------- 277*79398b25SAndroid Build Coastguard Worker 278*79398b25SAndroid Build Coastguard WorkerBy default Mksquashfs will compress using the gzip compression 279*79398b25SAndroid Build Coastguard Workeralgorithm. This algorithm offers a good trade-off between compression 280*79398b25SAndroid Build Coastguard Workerratio, and memory and time taken to decompress. 281*79398b25SAndroid Build Coastguard Worker 282*79398b25SAndroid Build Coastguard WorkerSquashfs also supports LZ4, LZO and XZ (LZMA2) compression. LZO offers worse 283*79398b25SAndroid Build Coastguard Workercompression ratio than gzip, but is faster to decompress. XZ offers better 284*79398b25SAndroid Build Coastguard Workercompression ratio than gzip, but at the expense of greater memory and time 285*79398b25SAndroid Build Coastguard Workerto decompress (and significantly more time to compress). LZ4 is similar 286*79398b25SAndroid Build Coastguard Workerto LZO, but, support for it is not yet in the mainline kernel, and so 287*79398b25SAndroid Build Coastguard Workerits usefulness is currently limited to using Squashfs with Mksquashfs/Unsquashfs 288*79398b25SAndroid Build Coastguard Workeras an archival system like tar. 289*79398b25SAndroid Build Coastguard Worker 290*79398b25SAndroid Build Coastguard WorkerIf you're not building the squashfs-tools and kernel from source, then 291*79398b25SAndroid Build Coastguard Workerthe tools and kernel may or may not have been built with support for LZ4, LZO or 292*79398b25SAndroid Build Coastguard WorkerXZ compression. The compression algorithms supported by the build of 293*79398b25SAndroid Build Coastguard WorkerMksquashfs can be found by typing mksquashfs without any arguments. The 294*79398b25SAndroid Build Coastguard Workercompressors available are displayed at the end of the help message, e.g. 295*79398b25SAndroid Build Coastguard Worker 296*79398b25SAndroid Build Coastguard WorkerCompressors available and compressor specific options: 297*79398b25SAndroid Build Coastguard Worker gzip (default) 298*79398b25SAndroid Build Coastguard Worker -Xcompression-level <compression-level> 299*79398b25SAndroid Build Coastguard Worker <compression-level> should be 1 .. 9 (default 9) 300*79398b25SAndroid Build Coastguard Worker -Xwindow-size <window-size> 301*79398b25SAndroid Build Coastguard Worker <window-size> should be 8 .. 15 (default 15) 302*79398b25SAndroid Build Coastguard Worker -Xstrategy strategy1,strategy2,...,strategyN 303*79398b25SAndroid Build Coastguard Worker Compress using strategy1,strategy2,...,strategyN in turn 304*79398b25SAndroid Build Coastguard Worker and choose the best compression. 305*79398b25SAndroid Build Coastguard Worker Available strategies: default, filtered, huffman_only, 306*79398b25SAndroid Build Coastguard Worker run_length_encoded and fixed 307*79398b25SAndroid Build Coastguard Worker lzo 308*79398b25SAndroid Build Coastguard Worker -Xalgorithm <algorithm> 309*79398b25SAndroid Build Coastguard Worker Where <algorithm> is one of: 310*79398b25SAndroid Build Coastguard Worker lzo1x_1 311*79398b25SAndroid Build Coastguard Worker lzo1x_1_11 312*79398b25SAndroid Build Coastguard Worker lzo1x_1_12 313*79398b25SAndroid Build Coastguard Worker lzo1x_1_15 314*79398b25SAndroid Build Coastguard Worker lzo1x_999 (default) 315*79398b25SAndroid Build Coastguard Worker -Xcompression-level <compression-level> 316*79398b25SAndroid Build Coastguard Worker <compression-level> should be 1 .. 9 (default 8) 317*79398b25SAndroid Build Coastguard Worker Only applies to lzo1x_999 algorithm 318*79398b25SAndroid Build Coastguard Worker lz4 319*79398b25SAndroid Build Coastguard Worker -Xhc 320*79398b25SAndroid Build Coastguard Worker Compress using LZ4 High Compression 321*79398b25SAndroid Build Coastguard Worker xz 322*79398b25SAndroid Build Coastguard Worker -Xbcj filter1,filter2,...,filterN 323*79398b25SAndroid Build Coastguard Worker Compress using filter1,filter2,...,filterN in turn 324*79398b25SAndroid Build Coastguard Worker (in addition to no filter), and choose the best compression. 325*79398b25SAndroid Build Coastguard Worker Available filters: x86, arm, armthumb, powerpc, sparc, ia64 326*79398b25SAndroid Build Coastguard Worker -Xdict-size <dict-size> 327*79398b25SAndroid Build Coastguard Worker Use <dict-size> as the XZ dictionary size. The dictionary size 328*79398b25SAndroid Build Coastguard Worker can be specified as a percentage of the block size, or as an 329*79398b25SAndroid Build Coastguard Worker absolute value. The dictionary size must be less than or equal 330*79398b25SAndroid Build Coastguard Worker to the block size and 8192 bytes or larger. It must also be 331*79398b25SAndroid Build Coastguard Worker storable in the xz header as either 2^n or as 2^n+2^(n+1). 332*79398b25SAndroid Build Coastguard Worker Example dict-sizes are 75%, 50%, 37.5%, 25%, or 32K, 16K, 8K 333*79398b25SAndroid Build Coastguard Worker etc. 334*79398b25SAndroid Build Coastguard Worker 335*79398b25SAndroid Build Coastguard WorkerIf the compressor offers compression specific options (all the compressors now 336*79398b25SAndroid Build Coastguard Workerhave compression specific options except the deprecated lzma1 compressor) 337*79398b25SAndroid Build Coastguard Workerthen these options are also displayed (.i.e. in the above XZ is shown with two 338*79398b25SAndroid Build Coastguard Workercompression specific options). The compression specific options are, obviously, 339*79398b25SAndroid Build Coastguard Workerspecific to the compressor in question, and the compressor documentation and 340*79398b25SAndroid Build Coastguard Workerweb sites should be consulted to understand their behaviour. In general 341*79398b25SAndroid Build Coastguard Workerthe Mksquashfs compression defaults for each compressor are optimised to 342*79398b25SAndroid Build Coastguard Workergive the best performance for each compressor, where what constitutes 343*79398b25SAndroid Build Coastguard Workerbest depends on the compressor. For gzip/xz best means highest compression, 344*79398b25SAndroid Build Coastguard Workerfor LZO/LZ4 best means a tradeoff between compression and (de)-compression 345*79398b25SAndroid Build Coastguard Workeroverhead (LZO/LZ4 by definition are intended for weaker processors). 346*79398b25SAndroid Build Coastguard Worker 347*79398b25SAndroid Build Coastguard Worker3.3 Changing global compression defaults used in mksquashfs 348*79398b25SAndroid Build Coastguard Worker----------------------------------------------------------- 349*79398b25SAndroid Build Coastguard Worker 350*79398b25SAndroid Build Coastguard WorkerThere are a large number of options that can be used to control the 351*79398b25SAndroid Build Coastguard Workercompression in mksquashfs. By and large the defaults are the most 352*79398b25SAndroid Build Coastguard Workeroptimum settings and should only be changed in exceptional circumstances! 353*79398b25SAndroid Build Coastguard WorkerNote, this does not apply to the block size, increasing the block size 354*79398b25SAndroid Build Coastguard Workerfrom the default of 128Kbytes will increase compression (especially 355*79398b25SAndroid Build Coastguard Workerfor the xz compressor) and should increase I/O performance too. However, 356*79398b25SAndroid Build Coastguard Workera block size of greater than 128Kbytes may increase latency in certain 357*79398b25SAndroid Build Coastguard Workercases (where the filesystem contains lots of fragments, and no locality 358*79398b25SAndroid Build Coastguard Workerof reference is observed). For this reason the block size default is 359*79398b25SAndroid Build Coastguard Workerconfigured to the less optimal 128Kbytes. Users should experiment 360*79398b25SAndroid Build Coastguard Workerwith 256Kbyte sizes or above. 361*79398b25SAndroid Build Coastguard Worker 362*79398b25SAndroid Build Coastguard WorkerThe -noI, -noD and -noF options (also -noInodeCompression, -noDataCompression 363*79398b25SAndroid Build Coastguard Workerand -noFragmentCompression) can be used to force mksquashfs to not compress 364*79398b25SAndroid Build Coastguard Workerinodes/directories, data and fragments respectively. Giving all options 365*79398b25SAndroid Build Coastguard Workergenerates an uncompressed filesystem. 366*79398b25SAndroid Build Coastguard Worker 367*79398b25SAndroid Build Coastguard WorkerThe -no-fragments tells mksquashfs to not generate fragment blocks, and rather 368*79398b25SAndroid Build Coastguard Workergenerate a filesystem similar to a Squashfs 1.x filesystem. It will of course 369*79398b25SAndroid Build Coastguard Workerstill be a Squashfs 4.0 filesystem but without fragments, and so it won't be 370*79398b25SAndroid Build Coastguard Workermountable on a Squashfs 1.x system. 371*79398b25SAndroid Build Coastguard Worker 372*79398b25SAndroid Build Coastguard WorkerThe -always-use-fragments option tells mksquashfs to always generate 373*79398b25SAndroid Build Coastguard Workerfragments for files irrespective of the file length. By default only small 374*79398b25SAndroid Build Coastguard Workerfiles less than the block size are packed into fragment blocks. The ends of 375*79398b25SAndroid Build Coastguard Workerfiles which do not fit fully into a block, are NOT by default packed into 376*79398b25SAndroid Build Coastguard Workerfragments. To illustrate this, a 100K file has an initial 64K block and a 36K 377*79398b25SAndroid Build Coastguard Workerremainder. This 36K remainder is not packed into a fragment by default. This 378*79398b25SAndroid Build Coastguard Workeris because to do so leads to a 10 - 20% drop in sequential I/O performance, as a 379*79398b25SAndroid Build Coastguard Workerdisk head seek is needed to seek to the initial file data and another disk seek 380*79398b25SAndroid Build Coastguard Workeris need to seek to the fragment block. Specify this option if you want file 381*79398b25SAndroid Build Coastguard Workerremainders to be packed into fragment blocks. Doing so may increase the 382*79398b25SAndroid Build Coastguard Workercompression obtained BUT at the expense of I/O speed. 383*79398b25SAndroid Build Coastguard Worker 384*79398b25SAndroid Build Coastguard WorkerThe -no-duplicates option tells mksquashfs to not check the files being 385*79398b25SAndroid Build Coastguard Workeradded to the filesystem for duplicates. This can result in quicker filesystem 386*79398b25SAndroid Build Coastguard Workergeneration and appending although obviously compression will suffer badly if 387*79398b25SAndroid Build Coastguard Workerthere is a lot of duplicate files. 388*79398b25SAndroid Build Coastguard Worker 389*79398b25SAndroid Build Coastguard WorkerThe -b option allows the block size to be selected, both "K" and "M" postfixes 390*79398b25SAndroid Build Coastguard Workerare supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or 391*79398b25SAndroid Build Coastguard Worker1M bytes. 392*79398b25SAndroid Build Coastguard Worker 393*79398b25SAndroid Build Coastguard Worker3.4 Specifying the UIDs/GIDs used in the filesystem 394*79398b25SAndroid Build Coastguard Worker--------------------------------------------------- 395*79398b25SAndroid Build Coastguard Worker 396*79398b25SAndroid Build Coastguard WorkerBy default files in the generated filesystem inherit the UID and GID ownership 397*79398b25SAndroid Build Coastguard Workerof the original file. However, mksquashfs provides a number of options which 398*79398b25SAndroid Build Coastguard Workercan be used to override the ownership. 399*79398b25SAndroid Build Coastguard Worker 400*79398b25SAndroid Build Coastguard WorkerThe options -all-root and -root-owned (both do exactly the same thing) force all 401*79398b25SAndroid Build Coastguard Workerfile uids/gids in the generated Squashfs filesystem to be root. This allows 402*79398b25SAndroid Build Coastguard Workerroot owned filesystems to be built without root access on the host machine. 403*79398b25SAndroid Build Coastguard Worker 404*79398b25SAndroid Build Coastguard WorkerThe "-force-uid uid" option forces all files in the generated Squashfs 405*79398b25SAndroid Build Coastguard Workerfilesystem to be owned by the specified uid. The uid can be specified either by 406*79398b25SAndroid Build Coastguard Workername (i.e. "root") or by number. 407*79398b25SAndroid Build Coastguard Worker 408*79398b25SAndroid Build Coastguard WorkerThe "-force-gid gid" option forces all files in the generated Squashfs 409*79398b25SAndroid Build Coastguard Workerfilesystem to be group owned by the specified gid. The gid can be specified 410*79398b25SAndroid Build Coastguard Workereither by name (i.e. "root") or by number. 411*79398b25SAndroid Build Coastguard Worker 412*79398b25SAndroid Build Coastguard Worker3.5 Excluding files from the filesystem 413*79398b25SAndroid Build Coastguard Worker--------------------------------------- 414*79398b25SAndroid Build Coastguard Worker 415*79398b25SAndroid Build Coastguard WorkerThe -e and -ef options allow files/directories to be specified which are 416*79398b25SAndroid Build Coastguard Workerexcluded from the output filesystem. The -e option takes the exclude 417*79398b25SAndroid Build Coastguard Workerfiles/directories from the command line, the -ef option takes the 418*79398b25SAndroid Build Coastguard Workerexlude files/directories from the specified exclude file, one file/directory 419*79398b25SAndroid Build Coastguard Workerper line. 420*79398b25SAndroid Build Coastguard Worker 421*79398b25SAndroid Build Coastguard WorkerTwo styles of exclude file matching are supported: basic exclude matching, and 422*79398b25SAndroid Build Coastguard Workerextended wildcard matching. Basic exclude matching is a legacy feature 423*79398b25SAndroid Build Coastguard Workerretained for backwards compatibility with earlier versions of Mksquashfs. 424*79398b25SAndroid Build Coastguard WorkerExtended wildcard matching should be used in preference. 425*79398b25SAndroid Build Coastguard Worker 426*79398b25SAndroid Build Coastguard Worker3.5.1 Basic exclude matching 427*79398b25SAndroid Build Coastguard Worker---------------------------- 428*79398b25SAndroid Build Coastguard Worker 429*79398b25SAndroid Build Coastguard WorkerEach exclude file is treated as an exact match of a file/directory in 430*79398b25SAndroid Build Coastguard Workerthe source directories. If an exclude file/directory is absolute (i.e. 431*79398b25SAndroid Build Coastguard Workerprefixed with /, ../, or ./) the entry is treated as absolute, however, if an 432*79398b25SAndroid Build Coastguard Workerexclude file/directory is relative, it is treated as being relative to each of 433*79398b25SAndroid Build Coastguard Workerthe sources in turn, i.e. 434*79398b25SAndroid Build Coastguard Worker 435*79398b25SAndroid Build Coastguard Worker%mksquashfs /tmp/source1 source2 output_fs -e ex1 /tmp/source1/ex2 out/ex3 436*79398b25SAndroid Build Coastguard Worker 437*79398b25SAndroid Build Coastguard WorkerWill generate exclude files /tmp/source1/ex2, /tmp/source1/ex1, source2/ex1, 438*79398b25SAndroid Build Coastguard Worker/tmp/source1/out/ex3 and source2/out/ex3. 439*79398b25SAndroid Build Coastguard Worker 440*79398b25SAndroid Build Coastguard Worker3.5.2 Extended exclude file handling 441*79398b25SAndroid Build Coastguard Worker------------------------------------ 442*79398b25SAndroid Build Coastguard Worker 443*79398b25SAndroid Build Coastguard WorkerExtended exclude file matching treats each exclude file as a wildcard or 444*79398b25SAndroid Build Coastguard Workerregex expression. To enable wildcard matching specify the -wildcards 445*79398b25SAndroid Build Coastguard Workeroption, and to enable regex matching specify the -regex option. In most 446*79398b25SAndroid Build Coastguard Workercases the -wildcards option should be used rather than -regex because wildcard 447*79398b25SAndroid Build Coastguard Workermatching behaviour is significantly easier to understand! 448*79398b25SAndroid Build Coastguard Worker 449*79398b25SAndroid Build Coastguard WorkerIn addition to wildcards/regex expressions, exclude files can be "anchored" or 450*79398b25SAndroid Build Coastguard Worker"non-anchored". An anchored exclude is one which matches from the root of the 451*79398b25SAndroid Build Coastguard Workerdirectory and nowhere else, a non-anchored exclude matches anywhere. For 452*79398b25SAndroid Build Coastguard Workerexample given the directory hierarchy "a/b/c/a/b", the anchored exclude 453*79398b25SAndroid Build Coastguard Worker"a/b" will match "a/b" at the root of the directory hierarchy, but 454*79398b25SAndroid Build Coastguard Workerit will not match the "/a/b" sub-directory within directory "c", whereas a 455*79398b25SAndroid Build Coastguard Workernon-anchored exclude would. 456*79398b25SAndroid Build Coastguard Worker 457*79398b25SAndroid Build Coastguard WorkerA couple of examples should make this clearer. 458*79398b25SAndroid Build Coastguard Worker 459*79398b25SAndroid Build Coastguard WorkerAnchored excludes 460*79398b25SAndroid Build Coastguard Worker 461*79398b25SAndroid Build Coastguard Worker 1. mksquashfs example image.sqsh -wildcards -e 'test/*.gz' 462*79398b25SAndroid Build Coastguard Worker 463*79398b25SAndroid Build Coastguard Worker Exclude all files matching "*.gz" in the top level directory "test". 464*79398b25SAndroid Build Coastguard Worker 465*79398b25SAndroid Build Coastguard Worker 2. mksquashfs example image.sqsh -wildcards -e '*/[Tt]est/example*' 466*79398b25SAndroid Build Coastguard Worker 467*79398b25SAndroid Build Coastguard Worker Exclude all files beginning with "example" inside directories called 468*79398b25SAndroid Build Coastguard Worker "Test" or "test", that occur inside any top level directory. 469*79398b25SAndroid Build Coastguard Worker 470*79398b25SAndroid Build Coastguard Worker Using extended wildcards, negative matching is also possible. 471*79398b25SAndroid Build Coastguard Worker 472*79398b25SAndroid Build Coastguard Worker 3. mksquashfs example image.sqsh -wildcards -e 'test/!(*data*).gz' 473*79398b25SAndroid Build Coastguard Worker 474*79398b25SAndroid Build Coastguard Worker Exclude all files matching "*.gz" in top level directory "test", 475*79398b25SAndroid Build Coastguard Worker except those with "data" in the name. 476*79398b25SAndroid Build Coastguard Worker 477*79398b25SAndroid Build Coastguard WorkerNon-anchored excludes 478*79398b25SAndroid Build Coastguard Worker 479*79398b25SAndroid Build Coastguard Worker By default excludes match from the top level directory, but it is 480*79398b25SAndroid Build Coastguard Worker often useful to exclude a file matching anywhere in the source directories. 481*79398b25SAndroid Build Coastguard Worker For this non-anchored excludes can be used, specified by pre-fixing the 482*79398b25SAndroid Build Coastguard Worker exclude with "...". 483*79398b25SAndroid Build Coastguard Worker 484*79398b25SAndroid Build Coastguard Worker Examples: 485*79398b25SAndroid Build Coastguard Worker 486*79398b25SAndroid Build Coastguard Worker 1. mksquashfs example image.sqsh -wildcards -e '... *.gz' 487*79398b25SAndroid Build Coastguard Worker 488*79398b25SAndroid Build Coastguard Worker Exclude files matching "*.gz" anywhere in the source directories. 489*79398b25SAndroid Build Coastguard Worker For example this will match "example.gz", "test/example.gz", and 490*79398b25SAndroid Build Coastguard Worker "test/test/example.gz". 491*79398b25SAndroid Build Coastguard Worker 492*79398b25SAndroid Build Coastguard Worker 2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz' 493*79398b25SAndroid Build Coastguard Worker 494*79398b25SAndroid Build Coastguard Worker Exclude files matching "*.gz" inside directories called "Test" or 495*79398b25SAndroid Build Coastguard Worker "test" that occur anywhere in the source directories. 496*79398b25SAndroid Build Coastguard Worker 497*79398b25SAndroid Build Coastguard Worker Again, using extended wildcards, negative matching is also possible. 498*79398b25SAndroid Build Coastguard Worker 499*79398b25SAndroid Build Coastguard Worker 3. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz' 500*79398b25SAndroid Build Coastguard Worker 501*79398b25SAndroid Build Coastguard Worker Exclude all files matching "*.gz" anywhere in the source directories, 502*79398b25SAndroid Build Coastguard Worker except those with "data" in the name. 503*79398b25SAndroid Build Coastguard Worker 504*79398b25SAndroid Build Coastguard Worker3.5.3 Exclude files summary 505*79398b25SAndroid Build Coastguard Worker--------------------------- 506*79398b25SAndroid Build Coastguard Worker 507*79398b25SAndroid Build Coastguard WorkerThe -e and -ef exclude options are usefully used in archiving the entire 508*79398b25SAndroid Build Coastguard Workerfilesystem, where it is wished to avoid archiving /proc, and the filesystem 509*79398b25SAndroid Build Coastguard Workerbeing generated, i.e. 510*79398b25SAndroid Build Coastguard Worker 511*79398b25SAndroid Build Coastguard Worker%mksquashfs / /tmp/root.sqsh -e proc /tmp/root.sqsh 512*79398b25SAndroid Build Coastguard Worker 513*79398b25SAndroid Build Coastguard WorkerMultiple -ef options can be specified on the command line, and the -ef 514*79398b25SAndroid Build Coastguard Workeroption can be used in conjuction with the -e option. 515*79398b25SAndroid Build Coastguard Worker 516*79398b25SAndroid Build Coastguard Worker3.6 Appending to squashfs filesystems 517*79398b25SAndroid Build Coastguard Worker------------------------------------- 518*79398b25SAndroid Build Coastguard Worker 519*79398b25SAndroid Build Coastguard WorkerRunning squashfs with the destination directory containing an existing 520*79398b25SAndroid Build Coastguard Workerfilesystem will add the source items to the existing filesystem. By default, 521*79398b25SAndroid Build Coastguard Workerthe source items are added to the existing root directory. 522*79398b25SAndroid Build Coastguard Worker 523*79398b25SAndroid Build Coastguard WorkerTo make this clear... An existing filesystem "image" contains root entries 524*79398b25SAndroid Build Coastguard Worker"old1", and "old2". Source directory "/home/phillip/test" contains "file1", 525*79398b25SAndroid Build Coastguard Worker"file2" and "dir1". 526*79398b25SAndroid Build Coastguard Worker 527*79398b25SAndroid Build Coastguard Workerexample 1: 528*79398b25SAndroid Build Coastguard Worker 529*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test image 530*79398b25SAndroid Build Coastguard Worker 531*79398b25SAndroid Build Coastguard WorkerWill create a new "image" with root entries "old1", "old2", "file1", "file2" and 532*79398b25SAndroid Build Coastguard Worker"dir1" 533*79398b25SAndroid Build Coastguard Worker 534*79398b25SAndroid Build Coastguard Workerexample 2: 535*79398b25SAndroid Build Coastguard Worker 536*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test image -keep-as-directory 537*79398b25SAndroid Build Coastguard Worker 538*79398b25SAndroid Build Coastguard WorkerWill create a new "image" with root entries "old1", "old2", and "test". 539*79398b25SAndroid Build Coastguard WorkerAs shown in the previous section, for single source directories 540*79398b25SAndroid Build Coastguard Worker'-keep-as-directory' adds the source directory rather than the 541*79398b25SAndroid Build Coastguard Workercontents of the directory. 542*79398b25SAndroid Build Coastguard Worker 543*79398b25SAndroid Build Coastguard Workerexample 3: 544*79398b25SAndroid Build Coastguard Worker 545*79398b25SAndroid Build Coastguard Worker%mksquashfs /home/phillip/test image -keep-as-directory -root-becomes 546*79398b25SAndroid Build Coastguard Workeroriginal-root 547*79398b25SAndroid Build Coastguard Worker 548*79398b25SAndroid Build Coastguard WorkerWill create a new "image" with root entries "original-root", and "test". The 549*79398b25SAndroid Build Coastguard Worker'-root-becomes' option specifies that the original root becomes a subdirectory 550*79398b25SAndroid Build Coastguard Workerin the new root, with the specified name. 551*79398b25SAndroid Build Coastguard Worker 552*79398b25SAndroid Build Coastguard WorkerThe append option with file duplicate detection, means squashfs can be 553*79398b25SAndroid Build Coastguard Workerused as a simple versioning archiving filesystem. A squashfs filesystem can 554*79398b25SAndroid Build Coastguard Workerbe created with for example the linux-2.4.19 source. Appending the linux-2.4.20 555*79398b25SAndroid Build Coastguard Workersource will create a filesystem with the two source trees, but only the 556*79398b25SAndroid Build Coastguard Workerchanged files will take extra room, the unchanged files will be detected as 557*79398b25SAndroid Build Coastguard Workerduplicates. 558*79398b25SAndroid Build Coastguard Worker 559*79398b25SAndroid Build Coastguard Worker3.7 Appending recovery file feature 560*79398b25SAndroid Build Coastguard Worker----------------------------------- 561*79398b25SAndroid Build Coastguard Worker 562*79398b25SAndroid Build Coastguard WorkerRecovery files are created when appending to existing Squashfs 563*79398b25SAndroid Build Coastguard Workerfilesystems. This allows the original filesystem to be recovered 564*79398b25SAndroid Build Coastguard Workerif Mksquashfs aborts unexpectedly (i.e. power failure). 565*79398b25SAndroid Build Coastguard Worker 566*79398b25SAndroid Build Coastguard WorkerThe recovery files are called squashfs_recovery_xxx_yyy, where 567*79398b25SAndroid Build Coastguard Worker"xxx" is the name of the filesystem being appended to, and "yyy" is a 568*79398b25SAndroid Build Coastguard Workernumber to guarantee filename uniqueness (the PID of the parent Mksquashfs 569*79398b25SAndroid Build Coastguard Workerprocess). 570*79398b25SAndroid Build Coastguard Worker 571*79398b25SAndroid Build Coastguard WorkerNormally if Mksquashfs exits correctly the recovery file is deleted to 572*79398b25SAndroid Build Coastguard Workeravoid cluttering the filesystem. If Mksquashfs aborts, the "-recover" 573*79398b25SAndroid Build Coastguard Workeroption can be used to recover the filesystem, giving the previously 574*79398b25SAndroid Build Coastguard Workercreated recovery file as a parameter, i.e. 575*79398b25SAndroid Build Coastguard Worker 576*79398b25SAndroid Build Coastguard Workermksquashfs dummy image.sqsh -recover squashfs_recovery_image.sqsh_1234 577*79398b25SAndroid Build Coastguard Worker 578*79398b25SAndroid Build Coastguard WorkerThe writing of the recovery file can be disabled by specifying the 579*79398b25SAndroid Build Coastguard Worker"-no-recovery" option. 580*79398b25SAndroid Build Coastguard Worker 581*79398b25SAndroid Build Coastguard Worker3.8 Pseudo file support 582*79398b25SAndroid Build Coastguard Worker----------------------- 583*79398b25SAndroid Build Coastguard Worker 584*79398b25SAndroid Build Coastguard WorkerMksquashfs supports pseudo files, these allow fake files, directories, character 585*79398b25SAndroid Build Coastguard Workerand block devices to be specified and added to the Squashfs filesystem being 586*79398b25SAndroid Build Coastguard Workerbuilt, rather than requiring them to be present in the source directories. 587*79398b25SAndroid Build Coastguard WorkerThis, for example, allows device nodes to be added to the filesystem without 588*79398b25SAndroid Build Coastguard Workerrequiring root access. 589*79398b25SAndroid Build Coastguard Worker 590*79398b25SAndroid Build Coastguard WorkerMksquashfs 4.1 added support for "dynamic pseudo files" and a modify operation. 591*79398b25SAndroid Build Coastguard WorkerDynamic pseudo files allow files to be dynamically created when Mksquashfs 592*79398b25SAndroid Build Coastguard Workeris run, their contents being the result of running a command or piece of 593*79398b25SAndroid Build Coastguard Workershell script. The modifiy operation allows the mode/uid/gid of an existing 594*79398b25SAndroid Build Coastguard Workerfile in the source filesystem to be modified. 595*79398b25SAndroid Build Coastguard Worker 596*79398b25SAndroid Build Coastguard WorkerTwo Mksquashfs options are supported, -p allows one pseudo file to be specified 597*79398b25SAndroid Build Coastguard Workeron the command line, and -pf allows a pseudo file to be specified containing a 598*79398b25SAndroid Build Coastguard Workerlist of pseduo definitions, one per line. 599*79398b25SAndroid Build Coastguard Worker 600*79398b25SAndroid Build Coastguard Worker3.8.1. Creating a dynamic file 601*79398b25SAndroid Build Coastguard Worker------------------------------ 602*79398b25SAndroid Build Coastguard Worker 603*79398b25SAndroid Build Coastguard WorkerPseudo definition 604*79398b25SAndroid Build Coastguard Worker 605*79398b25SAndroid Build Coastguard WorkerFilename f mode uid gid command 606*79398b25SAndroid Build Coastguard Worker 607*79398b25SAndroid Build Coastguard Workermode is the octal mode specifier, similar to that expected by chmod. 608*79398b25SAndroid Build Coastguard Worker 609*79398b25SAndroid Build Coastguard Workeruid and gid can be either specified as a decimal number, or by name. 610*79398b25SAndroid Build Coastguard Worker 611*79398b25SAndroid Build Coastguard Workercommand can be an executable or a piece of shell script, and it is executed 612*79398b25SAndroid Build Coastguard Workerby running "/bin/sh -c command". The stdout becomes the contents of 613*79398b25SAndroid Build Coastguard Worker"Filename". 614*79398b25SAndroid Build Coastguard Worker 615*79398b25SAndroid Build Coastguard WorkerExamples: 616*79398b25SAndroid Build Coastguard Worker 617*79398b25SAndroid Build Coastguard WorkerRunning a basic command 618*79398b25SAndroid Build Coastguard Worker----------------------- 619*79398b25SAndroid Build Coastguard Worker 620*79398b25SAndroid Build Coastguard Worker/somedir/dmesg f 444 root root dmesg 621*79398b25SAndroid Build Coastguard Worker 622*79398b25SAndroid Build Coastguard Workercreates a file "/somedir/dmesg" containing the output from dmesg. 623*79398b25SAndroid Build Coastguard Worker 624*79398b25SAndroid Build Coastguard WorkerExecuting shell script 625*79398b25SAndroid Build Coastguard Worker---------------------- 626*79398b25SAndroid Build Coastguard Worker 627*79398b25SAndroid Build Coastguard WorkerRELEASE f 444 root root \ 628*79398b25SAndroid Build Coastguard Worker if [ ! -e /tmp/ver ]; then \ 629*79398b25SAndroid Build Coastguard Worker echo 0 > /tmp/ver; \ 630*79398b25SAndroid Build Coastguard Worker fi; \ 631*79398b25SAndroid Build Coastguard Worker ver=`cat /tmp/ver`; \ 632*79398b25SAndroid Build Coastguard Worker ver=$((ver +1)); \ 633*79398b25SAndroid Build Coastguard Worker echo $ver > /tmp/ver; \ 634*79398b25SAndroid Build Coastguard Worker echo -n `cat /tmp/release`; \ 635*79398b25SAndroid Build Coastguard Worker echo "-dev #"$ver `date` "Build host" `hostname` 636*79398b25SAndroid Build Coastguard Worker 637*79398b25SAndroid Build Coastguard WorkerCreates a file RELEASE containing the release name, date, build host, and 638*79398b25SAndroid Build Coastguard Workeran incrementing version number. The incrementing version is a side-effect 639*79398b25SAndroid Build Coastguard Workerof executing the shell script, and ensures every time Mksquashfs is run a 640*79398b25SAndroid Build Coastguard Workernew version number is used without requiring any other shell scripting. 641*79398b25SAndroid Build Coastguard Worker 642*79398b25SAndroid Build Coastguard WorkerThe above example also shows that commands can be split across multiple lines 643*79398b25SAndroid Build Coastguard Workerusing "\". Obviously as the script will be presented to the shell as a single 644*79398b25SAndroid Build Coastguard Workerline, a semicolon is need to separate individual shell commands within the 645*79398b25SAndroid Build Coastguard Workershell script. 646*79398b25SAndroid Build Coastguard Worker 647*79398b25SAndroid Build Coastguard WorkerReading from a device (or fifo/named socket) 648*79398b25SAndroid Build Coastguard Worker-------------------------------------------- 649*79398b25SAndroid Build Coastguard Worker 650*79398b25SAndroid Build Coastguard Workerinput f 444 root root dd if=/dev/sda1 bs=1024 count=10 651*79398b25SAndroid Build Coastguard Worker 652*79398b25SAndroid Build Coastguard WorkerCopies 10K from the device /dev/sda1 into the file input. Ordinarily Mksquashfs 653*79398b25SAndroid Build Coastguard Workergiven a device, fifo, or named socket will place that special file within the 654*79398b25SAndroid Build Coastguard WorkerSquashfs filesystem, the above allows input from these special files to be 655*79398b25SAndroid Build Coastguard Workercaptured and placed in the Squashfs filesystem. 656*79398b25SAndroid Build Coastguard Worker 657*79398b25SAndroid Build Coastguard Worker3.8.2. Creating a block or character device 658*79398b25SAndroid Build Coastguard Worker------------------------------------------- 659*79398b25SAndroid Build Coastguard Worker 660*79398b25SAndroid Build Coastguard WorkerPseudo definition 661*79398b25SAndroid Build Coastguard Worker 662*79398b25SAndroid Build Coastguard WorkerFilename type mode uid gid major minor 663*79398b25SAndroid Build Coastguard Worker 664*79398b25SAndroid Build Coastguard WorkerWhere type is either 665*79398b25SAndroid Build Coastguard Worker b - for block devices, and 666*79398b25SAndroid Build Coastguard Worker c - for character devices 667*79398b25SAndroid Build Coastguard Worker 668*79398b25SAndroid Build Coastguard Workermode is the octal mode specifier, similar to that expected by chmod. 669*79398b25SAndroid Build Coastguard Worker 670*79398b25SAndroid Build Coastguard Workeruid and gid can be either specified as a decimal number, or by name. 671*79398b25SAndroid Build Coastguard Worker 672*79398b25SAndroid Build Coastguard WorkerFor example: 673*79398b25SAndroid Build Coastguard Worker 674*79398b25SAndroid Build Coastguard Worker/dev/chr_dev c 666 root root 100 1 675*79398b25SAndroid Build Coastguard Worker/dev/blk_dev b 666 0 0 200 200 676*79398b25SAndroid Build Coastguard Worker 677*79398b25SAndroid Build Coastguard Workercreates a character device "/dev/chr_dev" with major:minor 100:1 and 678*79398b25SAndroid Build Coastguard Workera block device "/dev/blk_dev" with major:minor 200:200, both with root 679*79398b25SAndroid Build Coastguard Workeruid/gid and a mode of rw-rw-rw. 680*79398b25SAndroid Build Coastguard Worker 681*79398b25SAndroid Build Coastguard Worker3.8.3. Creating a directory 682*79398b25SAndroid Build Coastguard Worker--------------------------- 683*79398b25SAndroid Build Coastguard Worker 684*79398b25SAndroid Build Coastguard WorkerPseudo definition 685*79398b25SAndroid Build Coastguard Worker 686*79398b25SAndroid Build Coastguard WorkerFilename d mode uid gid 687*79398b25SAndroid Build Coastguard Worker 688*79398b25SAndroid Build Coastguard Workermode is the octal mode specifier, similar to that expected by chmod. 689*79398b25SAndroid Build Coastguard Worker 690*79398b25SAndroid Build Coastguard Workeruid and gid can be either specified as a decimal number, or by name. 691*79398b25SAndroid Build Coastguard Worker 692*79398b25SAndroid Build Coastguard WorkerFor example: 693*79398b25SAndroid Build Coastguard Worker 694*79398b25SAndroid Build Coastguard Worker/pseudo_dir d 666 root root 695*79398b25SAndroid Build Coastguard Worker 696*79398b25SAndroid Build Coastguard Workercreates a directory "/pseudo_dir" with root uid/gid and mode of rw-rw-rw. 697*79398b25SAndroid Build Coastguard Worker 698*79398b25SAndroid Build Coastguard Worker3.8.4. Modifying attributes of an existing file 699*79398b25SAndroid Build Coastguard Worker----------------------------------------------- 700*79398b25SAndroid Build Coastguard Worker 701*79398b25SAndroid Build Coastguard WorkerPseudo definition 702*79398b25SAndroid Build Coastguard Worker 703*79398b25SAndroid Build Coastguard WorkerFilename m mode uid gid 704*79398b25SAndroid Build Coastguard Worker 705*79398b25SAndroid Build Coastguard Workermode is the octal mode specifier, similar to that expected by chmod. 706*79398b25SAndroid Build Coastguard Worker 707*79398b25SAndroid Build Coastguard Workeruid and gid can be either specified as a decimal number, or by name. 708*79398b25SAndroid Build Coastguard Worker 709*79398b25SAndroid Build Coastguard WorkerFor example: 710*79398b25SAndroid Build Coastguard Worker 711*79398b25SAndroid Build Coastguard Workerdmesg m 666 root root 712*79398b25SAndroid Build Coastguard Worker 713*79398b25SAndroid Build Coastguard WorkerChanges the attributes of the file "dmesg" in the filesystem to have 714*79398b25SAndroid Build Coastguard Workerroot uid/gid and a mode of rw-rw-rw, overriding the attributes obtained 715*79398b25SAndroid Build Coastguard Workerfrom the source filesystem. 716*79398b25SAndroid Build Coastguard Worker 717*79398b25SAndroid Build Coastguard Worker3.9 Miscellaneous options 718*79398b25SAndroid Build Coastguard Worker------------------------- 719*79398b25SAndroid Build Coastguard Worker 720*79398b25SAndroid Build Coastguard WorkerThe -info option displays the files/directories as they are compressed and 721*79398b25SAndroid Build Coastguard Workeradded to the filesystem. The original uncompressed size of each file 722*79398b25SAndroid Build Coastguard Workeris printed, along with DUPLICATE if the file is a duplicate of a 723*79398b25SAndroid Build Coastguard Workerfile in the filesystem. 724*79398b25SAndroid Build Coastguard Worker 725*79398b25SAndroid Build Coastguard WorkerThe -nopad option informs mksquashfs to not pad the filesystem to a 4K multiple. 726*79398b25SAndroid Build Coastguard WorkerThis is performed by default to enable the output filesystem file to be mounted 727*79398b25SAndroid Build Coastguard Workerby loopback, which requires files to be a 4K multiple. If the filesystem is 728*79398b25SAndroid Build Coastguard Workerbeing written to a block device, or is to be stored in a bootimage, the extra 729*79398b25SAndroid Build Coastguard Workerpad bytes are not needed. 730*79398b25SAndroid Build Coastguard Worker 731*79398b25SAndroid Build Coastguard Worker4. UNSQUASHFS 732*79398b25SAndroid Build Coastguard Worker------------- 733*79398b25SAndroid Build Coastguard Worker 734*79398b25SAndroid Build Coastguard WorkerUnsquashfs allows you to decompress and extract a Squashfs filesystem without 735*79398b25SAndroid Build Coastguard Workermounting it. It can extract the entire filesystem, or a specific 736*79398b25SAndroid Build Coastguard Workerfile or directory. 737*79398b25SAndroid Build Coastguard Worker 738*79398b25SAndroid Build Coastguard WorkerThe Unsquashfs usage info is: 739*79398b25SAndroid Build Coastguard Worker 740*79398b25SAndroid Build Coastguard WorkerSYNTAX: ./unsquashfs [options] filesystem [directories or files to extract] 741*79398b25SAndroid Build Coastguard Worker -v[ersion] print version, licence and copyright information 742*79398b25SAndroid Build Coastguard Worker -d[est] <pathname> unsquash to <pathname>, default "squashfs-root" 743*79398b25SAndroid Build Coastguard Worker -n[o-progress] don't display the progress bar 744*79398b25SAndroid Build Coastguard Worker -no[-xattrs] don't extract xattrs in file system 745*79398b25SAndroid Build Coastguard Worker -x[attrs] extract xattrs in file system (default) 746*79398b25SAndroid Build Coastguard Worker -u[ser-xattrs] only extract user xattrs in file system. 747*79398b25SAndroid Build Coastguard Worker Enables extracting xattrs 748*79398b25SAndroid Build Coastguard Worker -p[rocessors] <number> use <number> processors. By default will use 749*79398b25SAndroid Build Coastguard Worker number of processors available 750*79398b25SAndroid Build Coastguard Worker -i[nfo] print files as they are unsquashed 751*79398b25SAndroid Build Coastguard Worker -li[nfo] print files as they are unsquashed with file 752*79398b25SAndroid Build Coastguard Worker attributes (like ls -l output) 753*79398b25SAndroid Build Coastguard Worker -l[s] list filesystem, but don't unsquash 754*79398b25SAndroid Build Coastguard Worker -ll[s] list filesystem with file attributes (like 755*79398b25SAndroid Build Coastguard Worker ls -l output), but don't unsquash 756*79398b25SAndroid Build Coastguard Worker -f[orce] if file already exists then overwrite 757*79398b25SAndroid Build Coastguard Worker -s[tat] display filesystem superblock information 758*79398b25SAndroid Build Coastguard Worker -e[f] <extract file> list of directories or files to extract. 759*79398b25SAndroid Build Coastguard Worker One per line 760*79398b25SAndroid Build Coastguard Worker -da[ta-queue] <size> Set data queue to <size> Mbytes. Default 256 761*79398b25SAndroid Build Coastguard Worker Mbytes 762*79398b25SAndroid Build Coastguard Worker -fr[ag-queue] <size> Set fragment queue to <size> Mbytes. Default 763*79398b25SAndroid Build Coastguard Worker 256 Mbytes 764*79398b25SAndroid Build Coastguard Worker -r[egex] treat extract names as POSIX regular expressions 765*79398b25SAndroid Build Coastguard Worker rather than use the default shell wildcard 766*79398b25SAndroid Build Coastguard Worker expansion (globbing) 767*79398b25SAndroid Build Coastguard Worker 768*79398b25SAndroid Build Coastguard WorkerDecompressors available: 769*79398b25SAndroid Build Coastguard Worker gzip 770*79398b25SAndroid Build Coastguard Worker lzo 771*79398b25SAndroid Build Coastguard Worker lz4 772*79398b25SAndroid Build Coastguard Worker xz 773*79398b25SAndroid Build Coastguard Worker 774*79398b25SAndroid Build Coastguard WorkerTo extract a subset of the filesystem, the filenames or directory 775*79398b25SAndroid Build Coastguard Workertrees that are to be extracted can be specified on the command line. The 776*79398b25SAndroid Build Coastguard Workerfiles/directories should be specified using the full path to the 777*79398b25SAndroid Build Coastguard Workerfiles/directories as they appear within the Squashfs filesystem. The 778*79398b25SAndroid Build Coastguard Workerfiles/directories will also be extracted to those positions within the specified 779*79398b25SAndroid Build Coastguard Workerdestination directory. 780*79398b25SAndroid Build Coastguard Worker 781*79398b25SAndroid Build Coastguard WorkerThe extract files can also be given in a file using the "-e[f]" option. 782*79398b25SAndroid Build Coastguard Worker 783*79398b25SAndroid Build Coastguard WorkerSimilarly to Mksquashfs, wildcard matching is performed on the extract 784*79398b25SAndroid Build Coastguard Workerfiles. Wildcard matching is enabled by default. 785*79398b25SAndroid Build Coastguard Worker 786*79398b25SAndroid Build Coastguard WorkerExamples: 787*79398b25SAndroid Build Coastguard Worker 788*79398b25SAndroid Build Coastguard Worker 1. unsquashfs image.sqsh 'test/*.gz' 789*79398b25SAndroid Build Coastguard Worker 790*79398b25SAndroid Build Coastguard Worker Extract all files matching "*.gz" in the top level directory "test". 791*79398b25SAndroid Build Coastguard Worker 792*79398b25SAndroid Build Coastguard Worker 2. unsquashfs image.sqsh '[Tt]est/example*' 793*79398b25SAndroid Build Coastguard Worker 794*79398b25SAndroid Build Coastguard Worker Extract all files beginning with "example" inside top level directories 795*79398b25SAndroid Build Coastguard Worker called "Test" or "test". 796*79398b25SAndroid Build Coastguard Worker 797*79398b25SAndroid Build Coastguard Worker Using extended wildcards, negative matching is also possible. 798*79398b25SAndroid Build Coastguard Worker 799*79398b25SAndroid Build Coastguard Worker 3. unsquashfs image.sqsh 'test/!(*data*).gz' 800*79398b25SAndroid Build Coastguard Worker 801*79398b25SAndroid Build Coastguard Worker Extract all files matching "*.gz" in top level directory "test", 802*79398b25SAndroid Build Coastguard Worker except those with "data" in the name. 803*79398b25SAndroid Build Coastguard Worker 804*79398b25SAndroid Build Coastguard Worker 805*79398b25SAndroid Build Coastguard Worker4.1 Unsquashfs options 806*79398b25SAndroid Build Coastguard Worker---------------------- 807*79398b25SAndroid Build Coastguard Worker 808*79398b25SAndroid Build Coastguard WorkerThe "-ls" option can be used to list the contents of a filesystem without 809*79398b25SAndroid Build Coastguard Workerdecompressing the filesystem data itself. The "-lls" option is similar 810*79398b25SAndroid Build Coastguard Workerbut it also displays file attributes (ls -l style output). 811*79398b25SAndroid Build Coastguard Worker 812*79398b25SAndroid Build Coastguard WorkerThe "-info" option forces Unsquashfs to print each file as it is decompressed. 813*79398b25SAndroid Build Coastguard WorkerThe -"linfo" is similar but it also displays file attributes. 814*79398b25SAndroid Build Coastguard Worker 815*79398b25SAndroid Build Coastguard WorkerThe "-dest" option specifies the directory that is used to decompress 816*79398b25SAndroid Build Coastguard Workerthe filesystem data. If this option is not given then the filesystem is 817*79398b25SAndroid Build Coastguard Workerdecompressed to the directory "squashfs-root" in the current working directory. 818*79398b25SAndroid Build Coastguard Worker 819*79398b25SAndroid Build Coastguard WorkerThe "-force" option forces Unsquashfs to output to the destination 820*79398b25SAndroid Build Coastguard Workerdirectory even if files or directories already exist. This allows you 821*79398b25SAndroid Build Coastguard Workerto update an existing directory tree, or to Unsquashfs to a partially 822*79398b25SAndroid Build Coastguard Workerfilled directory. Without the "-force" option, Unsquashfs will 823*79398b25SAndroid Build Coastguard Workerrefuse to overwrite any existing files, or to create any directories if they 824*79398b25SAndroid Build Coastguard Workeralready exist. This is done to protect data in case of mistakes, and 825*79398b25SAndroid Build Coastguard Workerso the "-force" option should be used with caution. 826*79398b25SAndroid Build Coastguard Worker 827*79398b25SAndroid Build Coastguard WorkerThe "-stat" option displays filesystem superblock information. This is 828*79398b25SAndroid Build Coastguard Workeruseful to discover the filesystem version, byte ordering, whether it has a NFS 829*79398b25SAndroid Build Coastguard Workerexport table, and what options were used to compress the filesystem, etc. 830*79398b25SAndroid Build Coastguard Worker 831*79398b25SAndroid Build Coastguard WorkerUnsquashfs can decompress all Squashfs filesystem versions, 1.x, 2.x, 3.x and 832*79398b25SAndroid Build Coastguard Worker4.0 filesystems. 833*79398b25SAndroid Build Coastguard Worker 834*79398b25SAndroid Build Coastguard Worker5. FILESYSTEM LAYOUT 835*79398b25SAndroid Build Coastguard Worker-------------------- 836*79398b25SAndroid Build Coastguard Worker 837*79398b25SAndroid Build Coastguard WorkerA squashfs filesystem consists of a maximum of nine parts, packed together on a 838*79398b25SAndroid Build Coastguard Workerbyte alignment: 839*79398b25SAndroid Build Coastguard Worker 840*79398b25SAndroid Build Coastguard Worker --------------- 841*79398b25SAndroid Build Coastguard Worker | superblock | 842*79398b25SAndroid Build Coastguard Worker |---------------| 843*79398b25SAndroid Build Coastguard Worker | compression | 844*79398b25SAndroid Build Coastguard Worker | options | 845*79398b25SAndroid Build Coastguard Worker |---------------| 846*79398b25SAndroid Build Coastguard Worker | datablocks | 847*79398b25SAndroid Build Coastguard Worker | & fragments | 848*79398b25SAndroid Build Coastguard Worker |---------------| 849*79398b25SAndroid Build Coastguard Worker | inode table | 850*79398b25SAndroid Build Coastguard Worker |---------------| 851*79398b25SAndroid Build Coastguard Worker | directory | 852*79398b25SAndroid Build Coastguard Worker | table | 853*79398b25SAndroid Build Coastguard Worker |---------------| 854*79398b25SAndroid Build Coastguard Worker | fragment | 855*79398b25SAndroid Build Coastguard Worker | table | 856*79398b25SAndroid Build Coastguard Worker |---------------| 857*79398b25SAndroid Build Coastguard Worker | export | 858*79398b25SAndroid Build Coastguard Worker | table | 859*79398b25SAndroid Build Coastguard Worker |---------------| 860*79398b25SAndroid Build Coastguard Worker | uid/gid | 861*79398b25SAndroid Build Coastguard Worker | lookup table | 862*79398b25SAndroid Build Coastguard Worker |---------------| 863*79398b25SAndroid Build Coastguard Worker | xattr | 864*79398b25SAndroid Build Coastguard Worker | table | 865*79398b25SAndroid Build Coastguard Worker --------------- 866*79398b25SAndroid Build Coastguard Worker 867*79398b25SAndroid Build Coastguard WorkerCompressed data blocks are written to the filesystem as files are read from 868*79398b25SAndroid Build Coastguard Workerthe source directory, and checked for duplicates. Once all file data has been 869*79398b25SAndroid Build Coastguard Workerwritten the completed super-block, compression options, inode, directory, 870*79398b25SAndroid Build Coastguard Workerfragment, export, uid/gid lookup and xattr tables are written. 871*79398b25SAndroid Build Coastguard Worker 872*79398b25SAndroid Build Coastguard Worker5.1 Compression options 873*79398b25SAndroid Build Coastguard Worker----------------------- 874*79398b25SAndroid Build Coastguard Worker 875*79398b25SAndroid Build Coastguard WorkerCompressors can optionally support compression specific options (e.g. 876*79398b25SAndroid Build Coastguard Workerdictionary size). If non-default compression options have been used, then 877*79398b25SAndroid Build Coastguard Workerthese are stored here. 878*79398b25SAndroid Build Coastguard Worker 879*79398b25SAndroid Build Coastguard Worker5.2 Inodes 880*79398b25SAndroid Build Coastguard Worker---------- 881*79398b25SAndroid Build Coastguard Worker 882*79398b25SAndroid Build Coastguard WorkerMetadata (inodes and directories) are compressed in 8Kbyte blocks. Each 883*79398b25SAndroid Build Coastguard Workercompressed block is prefixed by a two byte length, the top bit is set if the 884*79398b25SAndroid Build Coastguard Workerblock is uncompressed. A block will be uncompressed if the -noI option is set, 885*79398b25SAndroid Build Coastguard Workeror if the compressed block was larger than the uncompressed block. 886*79398b25SAndroid Build Coastguard Worker 887*79398b25SAndroid Build Coastguard WorkerInodes are packed into the metadata blocks, and are not aligned to block 888*79398b25SAndroid Build Coastguard Workerboundaries, therefore inodes overlap compressed blocks. Inodes are identified 889*79398b25SAndroid Build Coastguard Workerby a 48-bit number which encodes the location of the compressed metadata block 890*79398b25SAndroid Build Coastguard Workercontaining the inode, and the byte offset into that block where the inode is 891*79398b25SAndroid Build Coastguard Workerplaced (<block, offset>). 892*79398b25SAndroid Build Coastguard Worker 893*79398b25SAndroid Build Coastguard WorkerTo maximise compression there are different inodes for each file type 894*79398b25SAndroid Build Coastguard Worker(regular file, directory, device, etc.), the inode contents and length 895*79398b25SAndroid Build Coastguard Workervarying with the type. 896*79398b25SAndroid Build Coastguard Worker 897*79398b25SAndroid Build Coastguard WorkerTo further maximise compression, two types of regular file inode and 898*79398b25SAndroid Build Coastguard Workerdirectory inode are defined: inodes optimised for frequently occurring 899*79398b25SAndroid Build Coastguard Workerregular files and directories, and extended types where extra 900*79398b25SAndroid Build Coastguard Workerinformation has to be stored. 901*79398b25SAndroid Build Coastguard Worker 902*79398b25SAndroid Build Coastguard Worker5.3 Directories 903*79398b25SAndroid Build Coastguard Worker--------------- 904*79398b25SAndroid Build Coastguard Worker 905*79398b25SAndroid Build Coastguard WorkerLike inodes, directories are packed into compressed metadata blocks, stored 906*79398b25SAndroid Build Coastguard Workerin a directory table. Directories are accessed using the start address of 907*79398b25SAndroid Build Coastguard Workerthe metablock containing the directory and the offset into the 908*79398b25SAndroid Build Coastguard Workerdecompressed block (<block, offset>). 909*79398b25SAndroid Build Coastguard Worker 910*79398b25SAndroid Build Coastguard WorkerDirectories are organised in a slightly complex way, and are not simply 911*79398b25SAndroid Build Coastguard Workera list of file names. The organisation takes advantage of the 912*79398b25SAndroid Build Coastguard Workerfact that (in most cases) the inodes of the files will be in the same 913*79398b25SAndroid Build Coastguard Workercompressed metadata block, and therefore, can share the start block. 914*79398b25SAndroid Build Coastguard WorkerDirectories are therefore organised in a two level list, a directory 915*79398b25SAndroid Build Coastguard Workerheader containing the shared start block value, and a sequence of directory 916*79398b25SAndroid Build Coastguard Workerentries, each of which share the shared start block. A new directory header 917*79398b25SAndroid Build Coastguard Workeris written once/if the inode start block changes. The directory 918*79398b25SAndroid Build Coastguard Workerheader/directory entry list is repeated as many times as necessary. 919*79398b25SAndroid Build Coastguard Worker 920*79398b25SAndroid Build Coastguard WorkerDirectories are sorted, and can contain a directory index to speed up 921*79398b25SAndroid Build Coastguard Workerfile lookup. Directory indexes store one entry per metablock, each entry 922*79398b25SAndroid Build Coastguard Workerstoring the index/filename mapping to the first directory header 923*79398b25SAndroid Build Coastguard Workerin each metadata block. Directories are sorted in alphabetical order, 924*79398b25SAndroid Build Coastguard Workerand at lookup the index is scanned linearly looking for the first filename 925*79398b25SAndroid Build Coastguard Workeralphabetically larger than the filename being looked up. At this point the 926*79398b25SAndroid Build Coastguard Workerlocation of the metadata block the filename is in has been found. 927*79398b25SAndroid Build Coastguard WorkerThe general idea of the index is ensure only one metadata block needs to be 928*79398b25SAndroid Build Coastguard Workerdecompressed to do a lookup irrespective of the length of the directory. 929*79398b25SAndroid Build Coastguard WorkerThis scheme has the advantage that it doesn't require extra memory overhead 930*79398b25SAndroid Build Coastguard Workerand doesn't require much extra storage on disk. 931*79398b25SAndroid Build Coastguard Worker 932*79398b25SAndroid Build Coastguard Worker5.4 File data 933*79398b25SAndroid Build Coastguard Worker------------- 934*79398b25SAndroid Build Coastguard Worker 935*79398b25SAndroid Build Coastguard WorkerRegular files consist of a sequence of contiguous compressed blocks, and/or a 936*79398b25SAndroid Build Coastguard Workercompressed fragment block (tail-end packed block). The compressed size 937*79398b25SAndroid Build Coastguard Workerof each datablock is stored in a block list contained within the 938*79398b25SAndroid Build Coastguard Workerfile inode. 939*79398b25SAndroid Build Coastguard Worker 940*79398b25SAndroid Build Coastguard WorkerTo speed up access to datablocks when reading 'large' files (256 Mbytes or 941*79398b25SAndroid Build Coastguard Workerlarger), the code implements an index cache that caches the mapping from 942*79398b25SAndroid Build Coastguard Workerblock index to datablock location on disk. 943*79398b25SAndroid Build Coastguard Worker 944*79398b25SAndroid Build Coastguard WorkerThe index cache allows Squashfs to handle large files (up to 1.75 TiB) while 945*79398b25SAndroid Build Coastguard Workerretaining a simple and space-efficient block list on disk. The cache 946*79398b25SAndroid Build Coastguard Workeris split into slots, caching up to eight 224 GiB files (128 KiB blocks). 947*79398b25SAndroid Build Coastguard WorkerLarger files use multiple slots, with 1.75 TiB files using all 8 slots. 948*79398b25SAndroid Build Coastguard WorkerThe index cache is designed to be memory efficient, and by default uses 949*79398b25SAndroid Build Coastguard Worker16 KiB. 950*79398b25SAndroid Build Coastguard Worker 951*79398b25SAndroid Build Coastguard Worker5.5 Fragment lookup table 952*79398b25SAndroid Build Coastguard Worker------------------------- 953*79398b25SAndroid Build Coastguard Worker 954*79398b25SAndroid Build Coastguard WorkerRegular files can contain a fragment index which is mapped to a fragment 955*79398b25SAndroid Build Coastguard Workerlocation on disk and compressed size using a fragment lookup table. This 956*79398b25SAndroid Build Coastguard Workerfragment lookup table is itself stored compressed into metadata blocks. 957*79398b25SAndroid Build Coastguard WorkerA second index table is used to locate these. This second index table for 958*79398b25SAndroid Build Coastguard Workerspeed of access (and because it is small) is read at mount time and cached 959*79398b25SAndroid Build Coastguard Workerin memory. 960*79398b25SAndroid Build Coastguard Worker 961*79398b25SAndroid Build Coastguard Worker5.6 Uid/gid lookup table 962*79398b25SAndroid Build Coastguard Worker------------------------ 963*79398b25SAndroid Build Coastguard Worker 964*79398b25SAndroid Build Coastguard WorkerFor space efficiency regular files store uid and gid indexes, which are 965*79398b25SAndroid Build Coastguard Workerconverted to 32-bit uids/gids using an id look up table. This table is 966*79398b25SAndroid Build Coastguard Workerstored compressed into metadata blocks. A second index table is used to 967*79398b25SAndroid Build Coastguard Workerlocate these. This second index table for speed of access (and because it 968*79398b25SAndroid Build Coastguard Workeris small) is read at mount time and cached in memory. 969*79398b25SAndroid Build Coastguard Worker 970*79398b25SAndroid Build Coastguard Worker5.7 Export table 971*79398b25SAndroid Build Coastguard Worker---------------- 972*79398b25SAndroid Build Coastguard Worker 973*79398b25SAndroid Build Coastguard WorkerTo enable Squashfs filesystems to be exportable (via NFS etc.) filesystems 974*79398b25SAndroid Build Coastguard Workercan optionally (disabled with the -no-exports Mksquashfs option) contain 975*79398b25SAndroid Build Coastguard Workeran inode number to inode disk location lookup table. This is required to 976*79398b25SAndroid Build Coastguard Workerenable Squashfs to map inode numbers passed in filehandles to the inode 977*79398b25SAndroid Build Coastguard Workerlocation on disk, which is necessary when the export code reinstantiates 978*79398b25SAndroid Build Coastguard Workerexpired/flushed inodes. 979*79398b25SAndroid Build Coastguard Worker 980*79398b25SAndroid Build Coastguard WorkerThis table is stored compressed into metadata blocks. A second index table is 981*79398b25SAndroid Build Coastguard Workerused to locate these. This second index table for speed of access (and because 982*79398b25SAndroid Build Coastguard Workerit is small) is read at mount time and cached in memory. 983*79398b25SAndroid Build Coastguard Worker 984*79398b25SAndroid Build Coastguard Worker5.8 Xattr table 985*79398b25SAndroid Build Coastguard Worker--------------- 986*79398b25SAndroid Build Coastguard Worker 987*79398b25SAndroid Build Coastguard WorkerThe xattr table contains extended attributes for each inode. The xattrs 988*79398b25SAndroid Build Coastguard Workerfor each inode are stored in a list, each list entry containing a type, 989*79398b25SAndroid Build Coastguard Workername and value field. The type field encodes the xattr prefix 990*79398b25SAndroid Build Coastguard Worker("user.", "trusted." etc) and it also encodes how the name/value fields 991*79398b25SAndroid Build Coastguard Workershould be interpreted. Currently the type indicates whether the value 992*79398b25SAndroid Build Coastguard Workeris stored inline (in which case the value field contains the xattr value), 993*79398b25SAndroid Build Coastguard Workeror if it is stored out of line (in which case the value field stores a 994*79398b25SAndroid Build Coastguard Workerreference to where the actual value is stored). This allows large values 995*79398b25SAndroid Build Coastguard Workerto be stored out of line improving scanning and lookup performance and it 996*79398b25SAndroid Build Coastguard Workeralso allows values to be de-duplicated, the value being stored once, and 997*79398b25SAndroid Build Coastguard Workerall other occurences holding an out of line reference to that value. 998*79398b25SAndroid Build Coastguard Worker 999*79398b25SAndroid Build Coastguard WorkerThe xattr lists are packed into compressed 8K metadata blocks. 1000*79398b25SAndroid Build Coastguard WorkerTo reduce overhead in inodes, rather than storing the on-disk 1001*79398b25SAndroid Build Coastguard Workerlocation of the xattr list inside each inode, a 32-bit xattr id 1002*79398b25SAndroid Build Coastguard Workeris stored. This xattr id is mapped into the location of the xattr 1003*79398b25SAndroid Build Coastguard Workerlist using a second xattr id lookup table. 1004*79398b25SAndroid Build Coastguard Worker 1005*79398b25SAndroid Build Coastguard Worker6. AUTHOR INFO 1006*79398b25SAndroid Build Coastguard Worker-------------- 1007*79398b25SAndroid Build Coastguard Worker 1008*79398b25SAndroid Build Coastguard WorkerSquashfs was written by Phillip Lougher, email [email protected], 1009*79398b25SAndroid Build Coastguard Workerin Chepstow, Wales, UK. If you like the program, or have any problems, 1010*79398b25SAndroid Build Coastguard Workerthen please email me, as it's nice to get feedback! 1011