squashfs_fs.h 11 KB

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