squashfs_fs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. struct squashfs_super_block {
  195. __le32 s_magic;
  196. __le32 inodes;
  197. __le32 mkfs_time;
  198. __le32 block_size;
  199. __le32 fragments;
  200. __le16 compression;
  201. __le16 block_log;
  202. __le16 flags;
  203. __le16 no_ids;
  204. __le16 s_major;
  205. __le16 s_minor;
  206. __le64 root_inode;
  207. __le64 bytes_used;
  208. __le64 id_table_start;
  209. __le64 xattr_id_table_start;
  210. __le64 inode_table_start;
  211. __le64 directory_table_start;
  212. __le64 fragment_table_start;
  213. __le64 lookup_table_start;
  214. };
  215. struct squashfs_dir_index {
  216. __le32 index;
  217. __le32 start_block;
  218. __le32 size;
  219. unsigned char name[0];
  220. };
  221. struct squashfs_base_inode {
  222. __le16 inode_type;
  223. __le16 mode;
  224. __le16 uid;
  225. __le16 guid;
  226. __le32 mtime;
  227. __le32 inode_number;
  228. };
  229. struct squashfs_ipc_inode {
  230. __le16 inode_type;
  231. __le16 mode;
  232. __le16 uid;
  233. __le16 guid;
  234. __le32 mtime;
  235. __le32 inode_number;
  236. __le32 nlink;
  237. };
  238. struct squashfs_lipc_inode {
  239. __le16 inode_type;
  240. __le16 mode;
  241. __le16 uid;
  242. __le16 guid;
  243. __le32 mtime;
  244. __le32 inode_number;
  245. __le32 nlink;
  246. __le32 xattr;
  247. };
  248. struct squashfs_dev_inode {
  249. __le16 inode_type;
  250. __le16 mode;
  251. __le16 uid;
  252. __le16 guid;
  253. __le32 mtime;
  254. __le32 inode_number;
  255. __le32 nlink;
  256. __le32 rdev;
  257. };
  258. struct squashfs_ldev_inode {
  259. __le16 inode_type;
  260. __le16 mode;
  261. __le16 uid;
  262. __le16 guid;
  263. __le32 mtime;
  264. __le32 inode_number;
  265. __le32 nlink;
  266. __le32 rdev;
  267. __le32 xattr;
  268. };
  269. struct squashfs_symlink_inode {
  270. __le16 inode_type;
  271. __le16 mode;
  272. __le16 uid;
  273. __le16 guid;
  274. __le32 mtime;
  275. __le32 inode_number;
  276. __le32 nlink;
  277. __le32 symlink_size;
  278. char symlink[0];
  279. };
  280. struct squashfs_reg_inode {
  281. __le16 inode_type;
  282. __le16 mode;
  283. __le16 uid;
  284. __le16 guid;
  285. __le32 mtime;
  286. __le32 inode_number;
  287. __le32 start_block;
  288. __le32 fragment;
  289. __le32 offset;
  290. __le32 file_size;
  291. __le16 block_list[0];
  292. };
  293. struct squashfs_lreg_inode {
  294. __le16 inode_type;
  295. __le16 mode;
  296. __le16 uid;
  297. __le16 guid;
  298. __le32 mtime;
  299. __le32 inode_number;
  300. __le64 start_block;
  301. __le64 file_size;
  302. __le64 sparse;
  303. __le32 nlink;
  304. __le32 fragment;
  305. __le32 offset;
  306. __le32 xattr;
  307. __le16 block_list[0];
  308. };
  309. struct squashfs_dir_inode {
  310. __le16 inode_type;
  311. __le16 mode;
  312. __le16 uid;
  313. __le16 guid;
  314. __le32 mtime;
  315. __le32 inode_number;
  316. __le32 start_block;
  317. __le32 nlink;
  318. __le16 file_size;
  319. __le16 offset;
  320. __le32 parent_inode;
  321. };
  322. struct squashfs_ldir_inode {
  323. __le16 inode_type;
  324. __le16 mode;
  325. __le16 uid;
  326. __le16 guid;
  327. __le32 mtime;
  328. __le32 inode_number;
  329. __le32 nlink;
  330. __le32 file_size;
  331. __le32 start_block;
  332. __le32 parent_inode;
  333. __le16 i_count;
  334. __le16 offset;
  335. __le32 xattr;
  336. struct squashfs_dir_index index[0];
  337. };
  338. union squashfs_inode {
  339. struct squashfs_base_inode base;
  340. struct squashfs_dev_inode dev;
  341. struct squashfs_ldev_inode ldev;
  342. struct squashfs_symlink_inode symlink;
  343. struct squashfs_reg_inode reg;
  344. struct squashfs_lreg_inode lreg;
  345. struct squashfs_dir_inode dir;
  346. struct squashfs_ldir_inode ldir;
  347. struct squashfs_ipc_inode ipc;
  348. struct squashfs_lipc_inode lipc;
  349. };
  350. struct squashfs_dir_entry {
  351. __le16 offset;
  352. __le16 inode_number;
  353. __le16 type;
  354. __le16 size;
  355. char name[0];
  356. };
  357. struct squashfs_dir_header {
  358. __le32 count;
  359. __le32 start_block;
  360. __le32 inode_number;
  361. };
  362. struct squashfs_fragment_entry {
  363. __le64 start_block;
  364. __le32 size;
  365. unsigned int unused;
  366. };
  367. struct squashfs_xattr_entry {
  368. __le16 type;
  369. __le16 size;
  370. char data[0];
  371. };
  372. struct squashfs_xattr_val {
  373. __le32 vsize;
  374. char value[0];
  375. };
  376. struct squashfs_xattr_id {
  377. __le64 xattr;
  378. __le32 count;
  379. __le32 size;
  380. };
  381. struct squashfs_xattr_id_table {
  382. __le64 xattr_table_start;
  383. __le32 xattr_ids;
  384. __le32 unused;
  385. };
  386. #endif