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