squashfs_fs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. #ifndef SQUASHFS_FS
  2. #define SQUASHFS_FS
  3. /*
  4. * Squashfs
  5. *
  6. * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
  7. * Phillip Lougher <phillip@squashfs.org.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2,
  12. * or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. *
  23. * squashfs_fs.h
  24. */
  25. #define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
  26. #define SQUASHFS_MAJOR 4
  27. #define SQUASHFS_MINOR 0
  28. #define SQUASHFS_START 0
  29. /* size of metadata (inode and directory) blocks */
  30. #define SQUASHFS_METADATA_SIZE 8192
  31. /* default size of block device I/O */
  32. #ifdef CONFIG_SQUASHFS_4K_DEVBLK_SIZE
  33. #define SQUASHFS_DEVBLK_SIZE 4096
  34. #else
  35. #define SQUASHFS_DEVBLK_SIZE 1024
  36. #endif
  37. #define SQUASHFS_FILE_MAX_SIZE 1048576
  38. #define SQUASHFS_FILE_MAX_LOG 20
  39. /* Max length of filename (not 255) */
  40. #define SQUASHFS_NAME_LEN 256
  41. /* Max value for directory header count*/
  42. #define SQUASHFS_DIR_COUNT 256
  43. #define SQUASHFS_INVALID_FRAG (0xffffffffU)
  44. #define SQUASHFS_INVALID_XATTR (0xffffffffU)
  45. #define SQUASHFS_INVALID_BLK (-1LL)
  46. /* Filesystem flags */
  47. #define SQUASHFS_NOI 0
  48. #define SQUASHFS_NOD 1
  49. #define SQUASHFS_NOF 3
  50. #define SQUASHFS_NO_FRAG 4
  51. #define SQUASHFS_ALWAYS_FRAG 5
  52. #define SQUASHFS_DUPLICATE 6
  53. #define SQUASHFS_EXPORT 7
  54. #define SQUASHFS_COMP_OPT 10
  55. #define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
  56. #define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
  57. SQUASHFS_NOI)
  58. #define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
  59. SQUASHFS_NOD)
  60. #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  61. SQUASHFS_NOF)
  62. #define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  63. SQUASHFS_NO_FRAG)
  64. #define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  65. SQUASHFS_ALWAYS_FRAG)
  66. #define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
  67. SQUASHFS_DUPLICATE)
  68. #define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
  69. SQUASHFS_EXPORT)
  70. #define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
  71. SQUASHFS_COMP_OPT)
  72. /* Inode types including extended types */
  73. #define SQUASHFS_DIR_TYPE 1
  74. #define SQUASHFS_REG_TYPE 2
  75. #define SQUASHFS_SYMLINK_TYPE 3
  76. #define SQUASHFS_BLKDEV_TYPE 4
  77. #define SQUASHFS_CHRDEV_TYPE 5
  78. #define SQUASHFS_FIFO_TYPE 6
  79. #define SQUASHFS_SOCKET_TYPE 7
  80. #define SQUASHFS_LDIR_TYPE 8
  81. #define SQUASHFS_LREG_TYPE 9
  82. #define SQUASHFS_LSYMLINK_TYPE 10
  83. #define SQUASHFS_LBLKDEV_TYPE 11
  84. #define SQUASHFS_LCHRDEV_TYPE 12
  85. #define SQUASHFS_LFIFO_TYPE 13
  86. #define SQUASHFS_LSOCKET_TYPE 14
  87. /* Max type value stored in directory entry */
  88. #define SQUASHFS_MAX_DIR_TYPE 7
  89. /* Xattr types */
  90. #define SQUASHFS_XATTR_USER 0
  91. #define SQUASHFS_XATTR_TRUSTED 1
  92. #define SQUASHFS_XATTR_SECURITY 2
  93. #define SQUASHFS_XATTR_VALUE_OOL 256
  94. #define SQUASHFS_XATTR_PREFIX_MASK 0xff
  95. /* Flag whether block is compressed or uncompressed, bit is set if block is
  96. * uncompressed */
  97. #define SQUASHFS_COMPRESSED_BIT (1 << 15)
  98. #define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
  99. (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
  100. #define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
  101. #define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
  102. #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
  103. ~SQUASHFS_COMPRESSED_BIT_BLOCK)
  104. #define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
  105. static inline int squashfs_block_size(__le32 raw)
  106. {
  107. u32 size = le32_to_cpu(raw);
  108. return (size >> 25) ? -EIO : size;
  109. }
  110. /*
  111. * Inode number ops. Inodes consist of a compressed block number, and an
  112. * uncompressed offset within that block
  113. */
  114. #define SQUASHFS_INODE_BLK(A) ((unsigned int) ((A) >> 16))
  115. #define SQUASHFS_INODE_OFFSET(A) ((unsigned int) ((A) & 0xffff))
  116. #define SQUASHFS_MKINODE(A, B) ((long long)(((long long) (A)\
  117. << 16) + (B)))
  118. /* fragment and fragment table defines */
  119. #define SQUASHFS_FRAGMENT_BYTES(A) \
  120. ((A) * sizeof(struct squashfs_fragment_entry))
  121. #define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
  122. SQUASHFS_METADATA_SIZE)
  123. #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
  124. SQUASHFS_METADATA_SIZE)
  125. #define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
  126. SQUASHFS_METADATA_SIZE - 1) / \
  127. SQUASHFS_METADATA_SIZE)
  128. #define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
  129. sizeof(u64))
  130. /* inode lookup table defines */
  131. #define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(u64))
  132. #define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
  133. SQUASHFS_METADATA_SIZE)
  134. #define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
  135. SQUASHFS_METADATA_SIZE)
  136. #define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
  137. SQUASHFS_METADATA_SIZE - 1) / \
  138. SQUASHFS_METADATA_SIZE)
  139. #define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
  140. sizeof(u64))
  141. /* uid/gid lookup table defines */
  142. #define SQUASHFS_ID_BYTES(A) ((A) * sizeof(unsigned int))
  143. #define SQUASHFS_ID_BLOCK(A) (SQUASHFS_ID_BYTES(A) / \
  144. SQUASHFS_METADATA_SIZE)
  145. #define SQUASHFS_ID_BLOCK_OFFSET(A) (SQUASHFS_ID_BYTES(A) % \
  146. SQUASHFS_METADATA_SIZE)
  147. #define SQUASHFS_ID_BLOCKS(A) ((SQUASHFS_ID_BYTES(A) + \
  148. SQUASHFS_METADATA_SIZE - 1) / \
  149. SQUASHFS_METADATA_SIZE)
  150. #define SQUASHFS_ID_BLOCK_BYTES(A) (SQUASHFS_ID_BLOCKS(A) *\
  151. sizeof(u64))
  152. /* xattr id lookup table defines */
  153. #define SQUASHFS_XATTR_BYTES(A) ((A) * sizeof(struct squashfs_xattr_id))
  154. #define SQUASHFS_XATTR_BLOCK(A) (SQUASHFS_XATTR_BYTES(A) / \
  155. SQUASHFS_METADATA_SIZE)
  156. #define SQUASHFS_XATTR_BLOCK_OFFSET(A) (SQUASHFS_XATTR_BYTES(A) % \
  157. SQUASHFS_METADATA_SIZE)
  158. #define SQUASHFS_XATTR_BLOCKS(A) ((SQUASHFS_XATTR_BYTES(A) + \
  159. SQUASHFS_METADATA_SIZE - 1) / \
  160. SQUASHFS_METADATA_SIZE)
  161. #define SQUASHFS_XATTR_BLOCK_BYTES(A) (SQUASHFS_XATTR_BLOCKS(A) *\
  162. sizeof(u64))
  163. #define SQUASHFS_XATTR_BLK(A) ((unsigned int) ((A) >> 16))
  164. #define SQUASHFS_XATTR_OFFSET(A) ((unsigned int) ((A) & 0xffff))
  165. /* cached data constants for filesystem */
  166. #define SQUASHFS_CACHED_BLKS 8
  167. /* meta index cache */
  168. #define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
  169. #define SQUASHFS_META_ENTRIES 127
  170. #define SQUASHFS_META_SLOTS 8
  171. struct meta_entry {
  172. u64 data_block;
  173. unsigned int index_block;
  174. unsigned short offset;
  175. unsigned short pad;
  176. };
  177. struct meta_index {
  178. unsigned int inode_number;
  179. unsigned int offset;
  180. unsigned short entries;
  181. unsigned short skip;
  182. unsigned short locked;
  183. unsigned short pad;
  184. struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
  185. };
  186. /*
  187. * definitions for structures on disk
  188. */
  189. #define ZLIB_COMPRESSION 1
  190. #define LZMA_COMPRESSION 2
  191. #define LZO_COMPRESSION 3
  192. #define XZ_COMPRESSION 4
  193. #define LZ4_COMPRESSION 5
  194. #define ZSTD_COMPRESSION 6
  195. struct squashfs_super_block {
  196. __le32 s_magic;
  197. __le32 inodes;
  198. __le32 mkfs_time;
  199. __le32 block_size;
  200. __le32 fragments;
  201. __le16 compression;
  202. __le16 block_log;
  203. __le16 flags;
  204. __le16 no_ids;
  205. __le16 s_major;
  206. __le16 s_minor;
  207. __le64 root_inode;
  208. __le64 bytes_used;
  209. __le64 id_table_start;
  210. __le64 xattr_id_table_start;
  211. __le64 inode_table_start;
  212. __le64 directory_table_start;
  213. __le64 fragment_table_start;
  214. __le64 lookup_table_start;
  215. };
  216. struct squashfs_dir_index {
  217. __le32 index;
  218. __le32 start_block;
  219. __le32 size;
  220. unsigned char name[0];
  221. };
  222. struct squashfs_base_inode {
  223. __le16 inode_type;
  224. __le16 mode;
  225. __le16 uid;
  226. __le16 guid;
  227. __le32 mtime;
  228. __le32 inode_number;
  229. };
  230. struct squashfs_ipc_inode {
  231. __le16 inode_type;
  232. __le16 mode;
  233. __le16 uid;
  234. __le16 guid;
  235. __le32 mtime;
  236. __le32 inode_number;
  237. __le32 nlink;
  238. };
  239. struct squashfs_lipc_inode {
  240. __le16 inode_type;
  241. __le16 mode;
  242. __le16 uid;
  243. __le16 guid;
  244. __le32 mtime;
  245. __le32 inode_number;
  246. __le32 nlink;
  247. __le32 xattr;
  248. };
  249. struct squashfs_dev_inode {
  250. __le16 inode_type;
  251. __le16 mode;
  252. __le16 uid;
  253. __le16 guid;
  254. __le32 mtime;
  255. __le32 inode_number;
  256. __le32 nlink;
  257. __le32 rdev;
  258. };
  259. struct squashfs_ldev_inode {
  260. __le16 inode_type;
  261. __le16 mode;
  262. __le16 uid;
  263. __le16 guid;
  264. __le32 mtime;
  265. __le32 inode_number;
  266. __le32 nlink;
  267. __le32 rdev;
  268. __le32 xattr;
  269. };
  270. struct squashfs_symlink_inode {
  271. __le16 inode_type;
  272. __le16 mode;
  273. __le16 uid;
  274. __le16 guid;
  275. __le32 mtime;
  276. __le32 inode_number;
  277. __le32 nlink;
  278. __le32 symlink_size;
  279. char symlink[0];
  280. };
  281. struct squashfs_reg_inode {
  282. __le16 inode_type;
  283. __le16 mode;
  284. __le16 uid;
  285. __le16 guid;
  286. __le32 mtime;
  287. __le32 inode_number;
  288. __le32 start_block;
  289. __le32 fragment;
  290. __le32 offset;
  291. __le32 file_size;
  292. __le16 block_list[0];
  293. };
  294. struct squashfs_lreg_inode {
  295. __le16 inode_type;
  296. __le16 mode;
  297. __le16 uid;
  298. __le16 guid;
  299. __le32 mtime;
  300. __le32 inode_number;
  301. __le64 start_block;
  302. __le64 file_size;
  303. __le64 sparse;
  304. __le32 nlink;
  305. __le32 fragment;
  306. __le32 offset;
  307. __le32 xattr;
  308. __le16 block_list[0];
  309. };
  310. struct squashfs_dir_inode {
  311. __le16 inode_type;
  312. __le16 mode;
  313. __le16 uid;
  314. __le16 guid;
  315. __le32 mtime;
  316. __le32 inode_number;
  317. __le32 start_block;
  318. __le32 nlink;
  319. __le16 file_size;
  320. __le16 offset;
  321. __le32 parent_inode;
  322. };
  323. struct squashfs_ldir_inode {
  324. __le16 inode_type;
  325. __le16 mode;
  326. __le16 uid;
  327. __le16 guid;
  328. __le32 mtime;
  329. __le32 inode_number;
  330. __le32 nlink;
  331. __le32 file_size;
  332. __le32 start_block;
  333. __le32 parent_inode;
  334. __le16 i_count;
  335. __le16 offset;
  336. __le32 xattr;
  337. struct squashfs_dir_index index[0];
  338. };
  339. union squashfs_inode {
  340. struct squashfs_base_inode base;
  341. struct squashfs_dev_inode dev;
  342. struct squashfs_ldev_inode ldev;
  343. struct squashfs_symlink_inode symlink;
  344. struct squashfs_reg_inode reg;
  345. struct squashfs_lreg_inode lreg;
  346. struct squashfs_dir_inode dir;
  347. struct squashfs_ldir_inode ldir;
  348. struct squashfs_ipc_inode ipc;
  349. struct squashfs_lipc_inode lipc;
  350. };
  351. struct squashfs_dir_entry {
  352. __le16 offset;
  353. __le16 inode_number;
  354. __le16 type;
  355. __le16 size;
  356. char name[0];
  357. };
  358. struct squashfs_dir_header {
  359. __le32 count;
  360. __le32 start_block;
  361. __le32 inode_number;
  362. };
  363. struct squashfs_fragment_entry {
  364. __le64 start_block;
  365. __le32 size;
  366. unsigned int unused;
  367. };
  368. struct squashfs_xattr_entry {
  369. __le16 type;
  370. __le16 size;
  371. char data[0];
  372. };
  373. struct squashfs_xattr_val {
  374. __le32 vsize;
  375. char value[0];
  376. };
  377. struct squashfs_xattr_id {
  378. __le64 xattr;
  379. __le32 count;
  380. __le32 size;
  381. };
  382. struct squashfs_xattr_id_table {
  383. __le64 xattr_table_start;
  384. __le32 xattr_ids;
  385. __le32 unused;
  386. };
  387. #endif