This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / squashfs_fs.h
1 #ifndef SQUASHFS_FS
2 #define SQUASHFS_FS
3 /*
4  * Squashfs
5  *
6  * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2,
11  * or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * squashfs_fs.h
23  */
24
25 #ifdef  CONFIG_SQUASHFS_VMALLOC
26 #define SQUASHFS_ALLOC(a)               vmalloc(a)
27 #define SQUASHFS_FREE(a)                vfree(a)
28 #else
29 #define SQUASHFS_ALLOC(a)               kmalloc(a, GFP_KERNEL)
30 #define SQUASHFS_FREE(a)                kfree(a)
31 #endif
32 #define SQUASHFS_CACHED_FRAGMENTS       CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE     
33 #define SQUASHFS_MAJOR                  2
34 #define SQUASHFS_MINOR                  1
35 #define SQUASHFS_MAGIC                  0x73717368
36 #define SQUASHFS_MAGIC_SWAP             0x68737173
37 #define SQUASHFS_START                  0
38
39 /* size of metadata (inode and directory) blocks */
40 #define SQUASHFS_METADATA_SIZE          8192
41 #define SQUASHFS_METADATA_LOG           13
42
43 /* default size of data blocks */
44 #define SQUASHFS_FILE_SIZE              65536
45 #define SQUASHFS_FILE_LOG               16
46
47 #define SQUASHFS_FILE_MAX_SIZE          65536
48
49 /* Max number of uids and gids */
50 #define SQUASHFS_UIDS                   256
51 #define SQUASHFS_GUIDS                  255
52
53 /* Max length of filename (not 255) */
54 #define SQUASHFS_NAME_LEN               256
55
56 #define SQUASHFS_INVALID                ((long long) 0xffffffffffff)
57 #define SQUASHFS_INVALID_BLK            ((long long) 0xffffffff)
58 #define SQUASHFS_USED_BLK               ((long long) 0xfffffffe)
59
60 /* Filesystem flags */
61 #define SQUASHFS_NOI                    0
62 #define SQUASHFS_NOD                    1
63 #define SQUASHFS_CHECK                  2
64 #define SQUASHFS_NOF                    3
65 #define SQUASHFS_NO_FRAG                4
66 #define SQUASHFS_ALWAYS_FRAG            5
67 #define SQUASHFS_DUPLICATE              6
68 #define SQUASHFS_BIT(flag, bit)         ((flag >> bit) & 1)
69 #define SQUASHFS_UNCOMPRESSED_INODES(flags)     SQUASHFS_BIT(flags, SQUASHFS_NOI)
70 #define SQUASHFS_UNCOMPRESSED_DATA(flags)       SQUASHFS_BIT(flags, SQUASHFS_NOD)
71 #define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags)  SQUASHFS_BIT(flags, SQUASHFS_NOF)
72 #define SQUASHFS_NO_FRAGMENTS(flags)            SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
73 #define SQUASHFS_ALWAYS_FRAGMENTS(flags)        SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
74 #define SQUASHFS_DUPLICATES(flags)              SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
75 #define SQUASHFS_CHECK_DATA(flags)              SQUASHFS_BIT(flags, SQUASHFS_CHECK)
76 #define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking)   (noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))
77
78 /* Max number of types and file types */
79 #define SQUASHFS_DIR_TYPE               1
80 #define SQUASHFS_FILE_TYPE              2
81 #define SQUASHFS_SYMLINK_TYPE           3
82 #define SQUASHFS_BLKDEV_TYPE            4
83 #define SQUASHFS_CHRDEV_TYPE            5
84 #define SQUASHFS_FIFO_TYPE              6
85 #define SQUASHFS_SOCKET_TYPE            7
86 #define SQUASHFS_LDIR_TYPE              8
87
88 /* 1.0 filesystem type definitions */
89 #define SQUASHFS_TYPES                  5
90 #define SQUASHFS_IPC_TYPE               0
91
92 /* Flag whether block is compressed or uncompressed, bit is set if block is 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
97 #define SQUASHFS_COMPRESSED(B)          (!((B) & SQUASHFS_COMPRESSED_BIT))
98
99 #define SQUASHFS_COMPRESSED_BIT_BLOCK           (1 << 24)
100 #define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)       (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
101                                         (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
102
103 #define SQUASHFS_COMPRESSED_BLOCK(B)            (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
104
105 /*
106  * Inode number ops.  Inodes consist of a compressed block number, and an uncompressed
107  * offset within that block
108  */
109 #define SQUASHFS_INODE_BLK(a)           ((unsigned int) ((a) >> 16))
110 #define SQUASHFS_INODE_OFFSET(a)        ((unsigned int) ((a) & 0xffff))
111 #define SQUASHFS_MKINODE(A, B)          ((squashfs_inode)(((squashfs_inode) (A) << 16)\
112                                         + (B)))
113
114 /* Compute 32 bit VFS inode number from squashfs inode number */
115 #define SQUASHFS_MK_VFS_INODE(a, b)     ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
116
117 /* Translate between VFS mode and squashfs mode */
118 #define SQUASHFS_MODE(a)                ((a) & 0xfff)
119
120 /* fragment and fragment table defines */
121 typedef unsigned int                    squashfs_fragment_index;
122 #define SQUASHFS_FRAGMENT_BYTES(A)      (A * sizeof(squashfs_fragment_entry))
123 #define SQUASHFS_FRAGMENT_INDEX(A)      (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
124 #define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)       (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
125 #define SQUASHFS_FRAGMENT_INDEXES(A)    ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
126 #define SQUASHFS_FRAGMENT_INDEX_BYTES(A)        (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
127
128 /* cached data constants for filesystem */
129 #define SQUASHFS_CACHED_BLKS            8
130
131 #define SQUASHFS_MAX_FILE_SIZE_LOG      32
132 #define SQUASHFS_MAX_FILE_SIZE          ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
133
134 #define SQUASHFS_MARKER_BYTE            0xff
135
136
137 /*
138  * definitions for structures on disk
139  */
140
141 typedef unsigned int            squashfs_block;
142 typedef long long               squashfs_inode;
143
144 typedef unsigned int            squashfs_uid;
145
146 typedef struct squashfs_super_block {
147         unsigned int            s_magic;
148         unsigned int            inodes;
149         unsigned int            bytes_used;
150         unsigned int            uid_start;
151         unsigned int            guid_start;
152         unsigned int            inode_table_start;
153         unsigned int            directory_table_start;
154         unsigned int            s_major:16;
155         unsigned int            s_minor:16;
156         unsigned int            block_size_1:16;
157         unsigned int            block_log:16;
158         unsigned int            flags:8;
159         unsigned int            no_uids:8;
160         unsigned int            no_guids:8;
161         unsigned int            mkfs_time /* time of filesystem creation */;
162         squashfs_inode          root_inode;
163         unsigned int            block_size;
164         unsigned int            fragments;
165         unsigned int            fragment_table_start;
166 } __attribute__ ((packed)) squashfs_super_block;
167
168 typedef struct {
169         unsigned int            index:27;
170         unsigned int            start_block:29;
171         unsigned char           size;
172         unsigned char           name[0];
173 } __attribute__ ((packed)) squashfs_dir_index;
174
175 typedef struct {
176         unsigned int            inode_type:4;
177         unsigned int            mode:12; /* protection */
178         unsigned int            uid:8; /* index into uid table */
179         unsigned int            guid:8; /* index into guid table */
180 } __attribute__ ((packed)) squashfs_base_inode_header;
181
182 typedef squashfs_base_inode_header squashfs_ipc_inode_header;
183
184 typedef struct {
185         unsigned int            inode_type:4;
186         unsigned int            mode:12; /* protection */
187         unsigned int            uid:8; /* index into uid table */
188         unsigned int            guid:8; /* index into guid table */
189         unsigned short          rdev;
190 } __attribute__ ((packed)) squashfs_dev_inode_header;
191         
192 typedef struct {
193         unsigned int            inode_type:4;
194         unsigned int            mode:12; /* protection */
195         unsigned int            uid:8; /* index into uid table */
196         unsigned int            guid:8; /* index into guid table */
197         unsigned short          symlink_size;
198         char                    symlink[0];
199 } __attribute__ ((packed)) squashfs_symlink_inode_header;
200
201 typedef struct {
202         unsigned int            inode_type:4;
203         unsigned int            mode:12; /* protection */
204         unsigned int            uid:8; /* index into uid table */
205         unsigned int            guid:8; /* index into guid table */
206         unsigned int            mtime;
207         squashfs_block          start_block;
208         unsigned int            fragment;
209         unsigned int            offset;
210         unsigned int            file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
211         unsigned short          block_list[0];
212 } __attribute__ ((packed)) squashfs_reg_inode_header;
213
214 typedef struct {
215         unsigned int            inode_type:4;
216         unsigned int            mode:12; /* protection */
217         unsigned int            uid:8; /* index into uid table */
218         unsigned int            guid:8; /* index into guid table */
219         unsigned int            file_size:19;
220         unsigned int            offset:13;
221         unsigned int            mtime;
222         unsigned int            start_block:24;
223 } __attribute__  ((packed)) squashfs_dir_inode_header;
224
225 typedef struct {
226         unsigned int            inode_type:4;
227         unsigned int            mode:12; /* protection */
228         unsigned int            uid:8; /* index into uid table */
229         unsigned int            guid:8; /* index into guid table */
230         unsigned int            file_size:27;
231         unsigned int            offset:13;
232         unsigned int            mtime;
233         unsigned int            start_block:24;
234         unsigned int            i_count:16;
235         squashfs_dir_index      index[0];
236 } __attribute__  ((packed)) squashfs_ldir_inode_header;
237
238 typedef union {
239         squashfs_base_inode_header      base;
240         squashfs_dev_inode_header       dev;
241         squashfs_symlink_inode_header   symlink;
242         squashfs_reg_inode_header       reg;
243         squashfs_dir_inode_header       dir;
244         squashfs_ldir_inode_header      ldir;
245         squashfs_ipc_inode_header       ipc;
246 } squashfs_inode_header;
247         
248 typedef struct {
249         unsigned int            offset:13;
250         unsigned int            type:3;
251         unsigned int            size:8;
252         char                    name[0];
253 } __attribute__ ((packed)) squashfs_dir_entry;
254
255 typedef struct {
256         unsigned int            count:8;
257         unsigned int            start_block:24;
258 } __attribute__ ((packed)) squashfs_dir_header;
259
260 typedef struct {
261         unsigned int            start_block;
262         unsigned int            size;
263 } __attribute__ ((packed)) squashfs_fragment_entry;
264
265 extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
266 extern int squashfs_uncompress_init(void);
267 extern int squashfs_uncompress_exit(void);
268
269 /*
270  * macros to convert each packed bitfield structure from little endian to big
271  * endian and vice versa.  These are needed when creating or using a filesystem on a
272  * machine with different byte ordering to the target architecture.
273  *
274  */
275
276 #define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
277         SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
278         SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
279         SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
280         SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
281         SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
282         SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
283         SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
284         SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
285         SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
286         SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
287         SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
288         SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
289         SQUASHFS_SWAP((s)->flags, d, 288, 8);\
290         SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
291         SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
292         SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
293         SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
294         SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
295         SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
296         SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
297 }
298
299 #define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
300         SQUASHFS_MEMSET(s, d, n);\
301         SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
302         SQUASHFS_SWAP((s)->mode, d, 4, 12);\
303         SQUASHFS_SWAP((s)->uid, d, 16, 8);\
304         SQUASHFS_SWAP((s)->guid, d, 24, 8);\
305 }
306
307 #define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
308
309 #define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
310         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
311         SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
312 }
313
314 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
315         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
316         SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
317 }
318
319 #define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
320         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
321         SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
322         SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
323         SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
324         SQUASHFS_SWAP((s)->offset, d, 128, 32);\
325         SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
326 }
327
328 #define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
329         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
330         SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
331         SQUASHFS_SWAP((s)->offset, d, 51, 13);\
332         SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
333         SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
334 }
335
336 #define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
337         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ldir_inode_header));\
338         SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
339         SQUASHFS_SWAP((s)->offset, d, 59, 13);\
340         SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
341         SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
342         SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
343 }
344
345 #define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
346         SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_index));\
347         SQUASHFS_SWAP((s)->index, d, 0, 27);\
348         SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
349         SQUASHFS_SWAP((s)->size, d, 56, 8);\
350 }
351
352 #define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
353         SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
354         SQUASHFS_SWAP((s)->count, d, 0, 8);\
355         SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
356 }
357
358 #define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
359         SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
360         SQUASHFS_SWAP((s)->offset, d, 0, 13);\
361         SQUASHFS_SWAP((s)->type, d, 13, 3);\
362         SQUASHFS_SWAP((s)->size, d, 16, 8);\
363 }
364
365 #define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
366         SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
367         SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
368         SQUASHFS_SWAP((s)->size, d, 32, 32);\
369 }
370
371 #define SQUASHFS_SWAP_SHORTS(s, d, n) {\
372         int entry;\
373         int bit_position;\
374         SQUASHFS_MEMSET(s, d, n * 2);\
375         for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
376                 SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
377 }
378
379 #define SQUASHFS_SWAP_INTS(s, d, n) {\
380         int entry;\
381         int bit_position;\
382         SQUASHFS_MEMSET(s, d, n * 4);\
383         for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
384                 SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
385 }
386
387 #define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
388         int entry;\
389         int bit_position;\
390         SQUASHFS_MEMSET(s, d, n * bits / 8);\
391         for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
392                 SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
393 }
394
395 #define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
396
397 #ifdef SQUASHFS_1_0_COMPATIBILITY
398 typedef struct {
399         unsigned int            inode_type:4;
400         unsigned int            mode:12; /* protection */
401         unsigned int            uid:4; /* index into uid table */
402         unsigned int            guid:4; /* index into guid table */
403 } __attribute__ ((packed)) squashfs_base_inode_header_1;
404
405 typedef struct {
406         unsigned int            inode_type:4;
407         unsigned int            mode:12; /* protection */
408         unsigned int            uid:4; /* index into uid table */
409         unsigned int            guid:4; /* index into guid table */
410         unsigned int            type:4;
411         unsigned int            offset:4;
412 } __attribute__ ((packed)) squashfs_ipc_inode_header_1;
413
414 typedef struct {
415         unsigned int            inode_type:4;
416         unsigned int            mode:12; /* protection */
417         unsigned int            uid:4; /* index into uid table */
418         unsigned int            guid:4; /* index into guid table */
419         unsigned short          rdev;
420 } __attribute__ ((packed)) squashfs_dev_inode_header_1;
421         
422 typedef struct {
423         unsigned int            inode_type:4;
424         unsigned int            mode:12; /* protection */
425         unsigned int            uid:4; /* index into uid table */
426         unsigned int            guid:4; /* index into guid table */
427         unsigned short          symlink_size;
428         char                    symlink[0];
429 } __attribute__ ((packed)) squashfs_symlink_inode_header_1;
430
431 typedef struct {
432         unsigned int            inode_type:4;
433         unsigned int            mode:12; /* protection */
434         unsigned int            uid:4; /* index into uid table */
435         unsigned int            guid:4; /* index into guid table */
436         unsigned int            mtime;
437         squashfs_block          start_block;
438         unsigned int            file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
439         unsigned short          block_list[0];
440 } __attribute__ ((packed)) squashfs_reg_inode_header_1;
441
442 typedef struct {
443         unsigned int            inode_type:4;
444         unsigned int            mode:12; /* protection */
445         unsigned int            uid:4; /* index into uid table */
446         unsigned int            guid:4; /* index into guid table */
447         unsigned int            file_size:19;
448         unsigned int            offset:13;
449         unsigned int            mtime;
450         unsigned int            start_block:24;
451 } __attribute__  ((packed)) squashfs_dir_inode_header_1;
452
453 #define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
454         SQUASHFS_MEMSET(s, d, n);\
455         SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
456         SQUASHFS_SWAP((s)->mode, d, 4, 12);\
457         SQUASHFS_SWAP((s)->uid, d, 16, 4);\
458         SQUASHFS_SWAP((s)->guid, d, 20, 4);\
459 }
460
461 #define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
462         SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
463         SQUASHFS_SWAP((s)->type, d, 24, 4);\
464         SQUASHFS_SWAP((s)->offset, d, 28, 4);\
465 }
466
467 #define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
468         SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
469         SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
470 }
471
472 #define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
473         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
474         SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
475 }
476
477 #define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
478         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
479         SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
480         SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
481         SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
482 }
483
484 #define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
485         SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
486         SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
487         SQUASHFS_SWAP((s)->offset, d, 43, 13);\
488         SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
489         SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
490 }
491 #endif
492
493 #ifdef __KERNEL__
494 /*
495  * macros used to swap each structure entry, taking into account
496  * bitfields and different bitfield placing conventions on differing architectures
497  */
498 #include <asm/byteorder.h>
499 #ifdef __BIG_ENDIAN
500         /* convert from little endian to big endian */
501 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
502 #else
503         /* convert from big endian to little endian */ 
504 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
505 #endif
506
507 #define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
508         int bits;\
509         int b_pos = pos % 8;\
510         unsigned long long val = 0;\
511         unsigned char *s = (unsigned char *)p + (pos / 8);\
512         unsigned char *d = ((unsigned char *) &val) + 7;\
513         for(bits = 0; bits < (tbits + b_pos); bits += 8) \
514                 *d-- = *s++;\
515         value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
516 }
517 #define SQUASHFS_MEMSET(s, d, n)        memset(s, 0, n);
518 #endif
519 #endif