squashfs.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. SQUASHFS 4.0 FILESYSTEM
  2. =======================
  3. Squashfs is a compressed read-only filesystem for Linux.
  4. It uses zlib, lz4, lzo, or xz compression to compress files, inodes and
  5. directories. Inodes in the system are very small and all blocks are packed to
  6. minimise data overhead. Block sizes greater than 4K are supported up to a
  7. maximum of 1Mbytes (default block size 128K).
  8. Squashfs is intended for general read-only filesystem use, for archival
  9. use (i.e. in cases where a .tar.gz file may be used), and in constrained
  10. block device/memory systems (e.g. embedded systems) where low overhead is
  11. needed.
  12. Mailing list: squashfs-devel@lists.sourceforge.net
  13. Web site: www.squashfs.org
  14. 1. FILESYSTEM FEATURES
  15. ----------------------
  16. Squashfs filesystem features versus Cramfs:
  17. Squashfs Cramfs
  18. Max filesystem size: 2^64 256 MiB
  19. Max file size: ~ 2 TiB 16 MiB
  20. Max files: unlimited unlimited
  21. Max directories: unlimited unlimited
  22. Max entries per directory: unlimited unlimited
  23. Max block size: 1 MiB 4 KiB
  24. Metadata compression: yes no
  25. Directory indexes: yes no
  26. Sparse file support: yes no
  27. Tail-end packing (fragments): yes no
  28. Exportable (NFS etc.): yes no
  29. Hard link support: yes no
  30. "." and ".." in readdir: yes no
  31. Real inode numbers: yes no
  32. 32-bit uids/gids: yes no
  33. File creation time: yes no
  34. Xattr support: yes no
  35. ACL support: no no
  36. Squashfs compresses data, inodes and directories. In addition, inode and
  37. directory data are highly compacted, and packed on byte boundaries. Each
  38. compressed inode is on average 8 bytes in length (the exact length varies on
  39. file type, i.e. regular file, directory, symbolic link, and block/char device
  40. inodes have different sizes).
  41. 2. USING SQUASHFS
  42. -----------------
  43. As squashfs is a read-only filesystem, the mksquashfs program must be used to
  44. create populated squashfs filesystems. This and other squashfs utilities
  45. can be obtained from http://www.squashfs.org. Usage instructions can be
  46. obtained from this site also.
  47. The squashfs-tools development tree is now located on kernel.org
  48. git://git.kernel.org/pub/scm/fs/squashfs/squashfs-tools.git
  49. 3. SQUASHFS FILESYSTEM DESIGN
  50. -----------------------------
  51. A squashfs filesystem consists of a maximum of nine parts, packed together on a
  52. byte alignment:
  53. ---------------
  54. | superblock |
  55. |---------------|
  56. | compression |
  57. | options |
  58. |---------------|
  59. | datablocks |
  60. | & fragments |
  61. |---------------|
  62. | inode table |
  63. |---------------|
  64. | directory |
  65. | table |
  66. |---------------|
  67. | fragment |
  68. | table |
  69. |---------------|
  70. | export |
  71. | table |
  72. |---------------|
  73. | uid/gid |
  74. | lookup table |
  75. |---------------|
  76. | xattr |
  77. | table |
  78. ---------------
  79. Compressed data blocks are written to the filesystem as files are read from
  80. the source directory, and checked for duplicates. Once all file data has been
  81. written the completed inode, directory, fragment, export, uid/gid lookup and
  82. xattr tables are written.
  83. 3.1 Compression options
  84. -----------------------
  85. Compressors can optionally support compression specific options (e.g.
  86. dictionary size). If non-default compression options have been used, then
  87. these are stored here.
  88. 3.2 Inodes
  89. ----------
  90. Metadata (inodes and directories) are compressed in 8Kbyte blocks. Each
  91. compressed block is prefixed by a two byte length, the top bit is set if the
  92. block is uncompressed. A block will be uncompressed if the -noI option is set,
  93. or if the compressed block was larger than the uncompressed block.
  94. Inodes are packed into the metadata blocks, and are not aligned to block
  95. boundaries, therefore inodes overlap compressed blocks. Inodes are identified
  96. by a 48-bit number which encodes the location of the compressed metadata block
  97. containing the inode, and the byte offset into that block where the inode is
  98. placed (<block, offset>).
  99. To maximise compression there are different inodes for each file type
  100. (regular file, directory, device, etc.), the inode contents and length
  101. varying with the type.
  102. To further maximise compression, two types of regular file inode and
  103. directory inode are defined: inodes optimised for frequently occurring
  104. regular files and directories, and extended types where extra
  105. information has to be stored.
  106. 3.3 Directories
  107. ---------------
  108. Like inodes, directories are packed into compressed metadata blocks, stored
  109. in a directory table. Directories are accessed using the start address of
  110. the metablock containing the directory and the offset into the
  111. decompressed block (<block, offset>).
  112. Directories are organised in a slightly complex way, and are not simply
  113. a list of file names. The organisation takes advantage of the
  114. fact that (in most cases) the inodes of the files will be in the same
  115. compressed metadata block, and therefore, can share the start block.
  116. Directories are therefore organised in a two level list, a directory
  117. header containing the shared start block value, and a sequence of directory
  118. entries, each of which share the shared start block. A new directory header
  119. is written once/if the inode start block changes. The directory
  120. header/directory entry list is repeated as many times as necessary.
  121. Directories are sorted, and can contain a directory index to speed up
  122. file lookup. Directory indexes store one entry per metablock, each entry
  123. storing the index/filename mapping to the first directory header
  124. in each metadata block. Directories are sorted in alphabetical order,
  125. and at lookup the index is scanned linearly looking for the first filename
  126. alphabetically larger than the filename being looked up. At this point the
  127. location of the metadata block the filename is in has been found.
  128. The general idea of the index is to ensure only one metadata block needs to be
  129. decompressed to do a lookup irrespective of the length of the directory.
  130. This scheme has the advantage that it doesn't require extra memory overhead
  131. and doesn't require much extra storage on disk.
  132. 3.4 File data
  133. -------------
  134. Regular files consist of a sequence of contiguous compressed blocks, and/or a
  135. compressed fragment block (tail-end packed block). The compressed size
  136. of each datablock is stored in a block list contained within the
  137. file inode.
  138. To speed up access to datablocks when reading 'large' files (256 Mbytes or
  139. larger), the code implements an index cache that caches the mapping from
  140. block index to datablock location on disk.
  141. The index cache allows Squashfs to handle large files (up to 1.75 TiB) while
  142. retaining a simple and space-efficient block list on disk. The cache
  143. is split into slots, caching up to eight 224 GiB files (128 KiB blocks).
  144. Larger files use multiple slots, with 1.75 TiB files using all 8 slots.
  145. The index cache is designed to be memory efficient, and by default uses
  146. 16 KiB.
  147. 3.5 Fragment lookup table
  148. -------------------------
  149. Regular files can contain a fragment index which is mapped to a fragment
  150. location on disk and compressed size using a fragment lookup table. This
  151. fragment lookup table is itself stored compressed into metadata blocks.
  152. A second index table is used to locate these. This second index table for
  153. speed of access (and because it is small) is read at mount time and cached
  154. in memory.
  155. 3.6 Uid/gid lookup table
  156. ------------------------
  157. For space efficiency regular files store uid and gid indexes, which are
  158. converted to 32-bit uids/gids using an id look up table. This table is
  159. stored compressed into metadata blocks. A second index table is used to
  160. locate these. This second index table for speed of access (and because it
  161. is small) is read at mount time and cached in memory.
  162. 3.7 Export table
  163. ----------------
  164. To enable Squashfs filesystems to be exportable (via NFS etc.) filesystems
  165. can optionally (disabled with the -no-exports Mksquashfs option) contain
  166. an inode number to inode disk location lookup table. This is required to
  167. enable Squashfs to map inode numbers passed in filehandles to the inode
  168. location on disk, which is necessary when the export code reinstantiates
  169. expired/flushed inodes.
  170. This table is stored compressed into metadata blocks. A second index table is
  171. used to locate these. This second index table for speed of access (and because
  172. it is small) is read at mount time and cached in memory.
  173. 3.8 Xattr table
  174. ---------------
  175. The xattr table contains extended attributes for each inode. The xattrs
  176. for each inode are stored in a list, each list entry containing a type,
  177. name and value field. The type field encodes the xattr prefix
  178. ("user.", "trusted." etc) and it also encodes how the name/value fields
  179. should be interpreted. Currently the type indicates whether the value
  180. is stored inline (in which case the value field contains the xattr value),
  181. or if it is stored out of line (in which case the value field stores a
  182. reference to where the actual value is stored). This allows large values
  183. to be stored out of line improving scanning and lookup performance and it
  184. also allows values to be de-duplicated, the value being stored once, and
  185. all other occurrences holding an out of line reference to that value.
  186. The xattr lists are packed into compressed 8K metadata blocks.
  187. To reduce overhead in inodes, rather than storing the on-disk
  188. location of the xattr list inside each inode, a 32-bit xattr id
  189. is stored. This xattr id is mapped into the location of the xattr
  190. list using a second xattr id lookup table.
  191. 4. TODOS AND OUTSTANDING ISSUES
  192. -------------------------------
  193. 4.1 Todo list
  194. -------------
  195. Implement ACL support.
  196. 4.2 Squashfs internal cache
  197. ---------------------------
  198. Blocks in Squashfs are compressed. To avoid repeatedly decompressing
  199. recently accessed data Squashfs uses two small metadata and fragment caches.
  200. The cache is not used for file datablocks, these are decompressed and cached in
  201. the page-cache in the normal way. The cache is used to temporarily cache
  202. fragment and metadata blocks which have been read as a result of a metadata
  203. (i.e. inode or directory) or fragment access. Because metadata and fragments
  204. are packed together into blocks (to gain greater compression) the read of a
  205. particular piece of metadata or fragment will retrieve other metadata/fragments
  206. which have been packed with it, these because of locality-of-reference may be
  207. read in the near future. Temporarily caching them ensures they are available
  208. for near future access without requiring an additional read and decompress.
  209. In the future this internal cache may be replaced with an implementation which
  210. uses the kernel page cache. Because the page cache operates on page sized
  211. units this may introduce additional complexity in terms of locking and
  212. associated race conditions.