[au1000] remove 2.6.27 patches
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.25 / 001-squashfs.patch
1 --- a/fs/Kconfig
2 +++ b/fs/Kconfig
3 @@ -1367,6 +1367,71 @@ config CRAMFS
4
5 If unsure, say N.
6
7 +config SQUASHFS
8 + tristate "SquashFS 3.0 - Squashed file system support"
9 + select ZLIB_INFLATE
10 + help
11 + Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
12 + System). Squashfs is a highly compressed read-only filesystem for Linux.
13 + It uses zlib compression to compress both files, inodes and directories.
14 + Inodes in the system are very small and all blocks are packed to minimise
15 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
16 + SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
17 + uid/gid information, hard links and timestamps.
18 +
19 + Squashfs is intended for general read-only filesystem use, for archival
20 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
21 + systems where low overhead is needed. Further information and filesystem tools
22 + are available from http://squashfs.sourceforge.net.
23 +
24 + If you want to compile this as a module ( = code which can be
25 + inserted in and removed from the running kernel whenever you want),
26 + say M here and read <file:Documentation/modules.txt>. The module
27 + will be called squashfs. Note that the root file system (the one
28 + containing the directory /) cannot be compiled as a module.
29 +
30 + If unsure, say N.
31 +
32 +config SQUASHFS_EMBEDDED
33 +
34 + bool "Additional options for memory-constrained systems"
35 + depends on SQUASHFS
36 + default n
37 + help
38 + Saying Y here allows you to specify cache sizes and how Squashfs
39 + allocates memory. This is only intended for memory constrained
40 + systems.
41 +
42 + If unsure, say N.
43 +
44 +config SQUASHFS_FRAGMENT_CACHE_SIZE
45 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
46 + depends on SQUASHFS
47 + default "3"
48 + help
49 + By default SquashFS caches the last 3 fragments read from
50 + the filesystem. Increasing this amount may mean SquashFS
51 + has to re-read fragments less often from disk, at the expense
52 + of extra system memory. Decreasing this amount will mean
53 + SquashFS uses less memory at the expense of extra reads from disk.
54 +
55 + Note there must be at least one cached fragment. Anything
56 + much more than three will probably not make much difference.
57 +
58 +config SQUASHFS_VMALLOC
59 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
60 + depends on SQUASHFS
61 + default n
62 + help
63 + By default SquashFS uses kmalloc to obtain fragment cache memory.
64 + Kmalloc memory is the standard kernel allocator, but it can fail
65 + on memory constrained systems. Because of the way Vmalloc works,
66 + Vmalloc can succeed when kmalloc fails. Specifying this option
67 + will make SquashFS always use Vmalloc to allocate the
68 + fragment cache memory.
69 +
70 + If unsure, say N.
71 +
72 config VXFS_FS
73 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
74 depends on BLOCK
75 --- a/fs/Makefile
76 +++ b/fs/Makefile
77 @@ -73,6 +73,7 @@ obj-$(CONFIG_JBD) += jbd/
78 obj-$(CONFIG_JBD2) += jbd2/
79 obj-$(CONFIG_EXT2_FS) += ext2/
80 obj-$(CONFIG_CRAMFS) += cramfs/
81 +obj-$(CONFIG_SQUASHFS) += squashfs/
82 obj-y += ramfs/
83 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
84 obj-$(CONFIG_CODA_FS) += coda/
85 --- /dev/null
86 +++ b/fs/squashfs/inode.c
87 @@ -0,0 +1,2122 @@
88 +/*
89 + * Squashfs - a compressed read only filesystem for Linux
90 + *
91 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
92 + * Phillip Lougher <phillip@lougher.org.uk>
93 + *
94 + * This program is free software; you can redistribute it and/or
95 + * modify it under the terms of the GNU General Public License
96 + * as published by the Free Software Foundation; either version 2,
97 + * or (at your option) any later version.
98 + *
99 + * This program is distributed in the hope that it will be useful,
100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 + * GNU General Public License for more details.
103 + *
104 + * You should have received a copy of the GNU General Public License
105 + * along with this program; if not, write to the Free Software
106 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
107 + *
108 + * inode.c
109 + */
110 +
111 +#include <linux/types.h>
112 +#include <linux/squashfs_fs.h>
113 +#include <linux/module.h>
114 +#include <linux/errno.h>
115 +#include <linux/slab.h>
116 +#include <linux/fs.h>
117 +#include <linux/smp_lock.h>
118 +#include <linux/slab.h>
119 +#include <linux/squashfs_fs_sb.h>
120 +#include <linux/squashfs_fs_i.h>
121 +#include <linux/buffer_head.h>
122 +#include <linux/vfs.h>
123 +#include <linux/init.h>
124 +#include <linux/dcache.h>
125 +#include <linux/wait.h>
126 +#include <linux/zlib.h>
127 +#include <linux/blkdev.h>
128 +#include <linux/vmalloc.h>
129 +#include <asm/uaccess.h>
130 +#include <asm/semaphore.h>
131 +
132 +#include "squashfs.h"
133 +
134 +static void squashfs_put_super(struct super_block *);
135 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
136 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
137 +static int squashfs_readpage(struct file *file, struct page *page);
138 +static int squashfs_readpage4K(struct file *file, struct page *page);
139 +static int squashfs_readdir(struct file *, void *, filldir_t);
140 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
141 +static void squashfs_destroy_inode(struct inode *inode);
142 +static int init_inodecache(void);
143 +static void destroy_inodecache(void);
144 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
145 + struct nameidata *);
146 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
147 +static long long read_blocklist(struct inode *inode, int index,
148 + int readahead_blks, char *block_list,
149 + unsigned short **block_p, unsigned int *bsize);
150 +static int squashfs_get_sb(struct file_system_type *, int,
151 + const char *, void *, struct vfsmount *);
152 +
153 +
154 +static z_stream stream;
155 +
156 +static struct file_system_type squashfs_fs_type = {
157 + .owner = THIS_MODULE,
158 + .name = "squashfs",
159 + .get_sb = squashfs_get_sb,
160 + .kill_sb = kill_block_super,
161 + .fs_flags = FS_REQUIRES_DEV
162 +};
163 +
164 +static unsigned char squashfs_filetype_table[] = {
165 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
166 +};
167 +
168 +static struct super_operations squashfs_ops = {
169 + .alloc_inode = squashfs_alloc_inode,
170 + .destroy_inode = squashfs_destroy_inode,
171 + .statfs = squashfs_statfs,
172 + .put_super = squashfs_put_super,
173 +};
174 +
175 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
176 + .readpage = squashfs_symlink_readpage
177 +};
178 +
179 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
180 + .readpage = squashfs_readpage
181 +};
182 +
183 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
184 + .readpage = squashfs_readpage4K
185 +};
186 +
187 +static struct file_operations squashfs_dir_ops = {
188 + .read = generic_read_dir,
189 + .readdir = squashfs_readdir
190 +};
191 +
192 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
193 + .lookup = squashfs_lookup
194 +};
195 +
196 +
197 +static struct buffer_head *get_block_length(struct super_block *s,
198 + int *cur_index, int *offset, int *c_byte)
199 +{
200 + struct squashfs_sb_info *msblk = s->s_fs_info;
201 + unsigned short temp;
202 + struct buffer_head *bh;
203 +
204 + if (!(bh = sb_bread(s, *cur_index)))
205 + goto out;
206 +
207 + if (msblk->devblksize - *offset == 1) {
208 + if (msblk->swap)
209 + ((unsigned char *) &temp)[1] = *((unsigned char *)
210 + (bh->b_data + *offset));
211 + else
212 + ((unsigned char *) &temp)[0] = *((unsigned char *)
213 + (bh->b_data + *offset));
214 + brelse(bh);
215 + if (!(bh = sb_bread(s, ++(*cur_index))))
216 + goto out;
217 + if (msblk->swap)
218 + ((unsigned char *) &temp)[0] = *((unsigned char *)
219 + bh->b_data);
220 + else
221 + ((unsigned char *) &temp)[1] = *((unsigned char *)
222 + bh->b_data);
223 + *c_byte = temp;
224 + *offset = 1;
225 + } else {
226 + if (msblk->swap) {
227 + ((unsigned char *) &temp)[1] = *((unsigned char *)
228 + (bh->b_data + *offset));
229 + ((unsigned char *) &temp)[0] = *((unsigned char *)
230 + (bh->b_data + *offset + 1));
231 + } else {
232 + ((unsigned char *) &temp)[0] = *((unsigned char *)
233 + (bh->b_data + *offset));
234 + ((unsigned char *) &temp)[1] = *((unsigned char *)
235 + (bh->b_data + *offset + 1));
236 + }
237 + *c_byte = temp;
238 + *offset += 2;
239 + }
240 +
241 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
242 + if (*offset == msblk->devblksize) {
243 + brelse(bh);
244 + if (!(bh = sb_bread(s, ++(*cur_index))))
245 + goto out;
246 + *offset = 0;
247 + }
248 + if (*((unsigned char *) (bh->b_data + *offset)) !=
249 + SQUASHFS_MARKER_BYTE) {
250 + ERROR("Metadata block marker corrupt @ %x\n",
251 + *cur_index);
252 + brelse(bh);
253 + goto out;
254 + }
255 + (*offset)++;
256 + }
257 + return bh;
258 +
259 +out:
260 + return NULL;
261 +}
262 +
263 +
264 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
265 + long long index, unsigned int length,
266 + long long *next_index)
267 +{
268 + struct squashfs_sb_info *msblk = s->s_fs_info;
269 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
270 + msblk->devblksize_log2) + 2];
271 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
272 + unsigned int cur_index = index >> msblk->devblksize_log2;
273 + int bytes, avail_bytes, b = 0, k;
274 + char *c_buffer;
275 + unsigned int compressed;
276 + unsigned int c_byte = length;
277 +
278 + if (c_byte) {
279 + bytes = msblk->devblksize - offset;
280 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
281 + c_buffer = compressed ? msblk->read_data : buffer;
282 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
283 +
284 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
285 + ? "" : "un", (unsigned int) c_byte);
286 +
287 + if (!(bh[0] = sb_getblk(s, cur_index)))
288 + goto block_release;
289 +
290 + for (b = 1; bytes < c_byte; b++) {
291 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
292 + goto block_release;
293 + bytes += msblk->devblksize;
294 + }
295 + ll_rw_block(READ, b, bh);
296 + } else {
297 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
298 + &c_byte)))
299 + goto read_failure;
300 +
301 + bytes = msblk->devblksize - offset;
302 + compressed = SQUASHFS_COMPRESSED(c_byte);
303 + c_buffer = compressed ? msblk->read_data : buffer;
304 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
305 +
306 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
307 + ? "" : "un", (unsigned int) c_byte);
308 +
309 + for (b = 1; bytes < c_byte; b++) {
310 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
311 + goto block_release;
312 + bytes += msblk->devblksize;
313 + }
314 + ll_rw_block(READ, b - 1, bh + 1);
315 + }
316 +
317 + if (compressed)
318 + down(&msblk->read_data_mutex);
319 +
320 + for (bytes = 0, k = 0; k < b; k++) {
321 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
322 + msblk->devblksize - offset :
323 + c_byte - bytes;
324 + wait_on_buffer(bh[k]);
325 + if (!buffer_uptodate(bh[k]))
326 + goto block_release;
327 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
328 + bytes += avail_bytes;
329 + offset = 0;
330 + brelse(bh[k]);
331 + }
332 +
333 + /*
334 + * uncompress block
335 + */
336 + if (compressed) {
337 + int zlib_err;
338 +
339 + stream.next_in = c_buffer;
340 + stream.avail_in = c_byte;
341 + stream.next_out = buffer;
342 + stream.avail_out = msblk->read_size;
343 +
344 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
345 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
346 + != Z_STREAM_END) || ((zlib_err =
347 + zlib_inflateEnd(&stream)) != Z_OK)) {
348 + ERROR("zlib_fs returned unexpected result 0x%x\n",
349 + zlib_err);
350 + bytes = 0;
351 + } else
352 + bytes = stream.total_out;
353 +
354 + up(&msblk->read_data_mutex);
355 + }
356 +
357 + if (next_index)
358 + *next_index = index + c_byte + (length ? 0 :
359 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
360 + ? 3 : 2));
361 + return bytes;
362 +
363 +block_release:
364 + while (--b >= 0)
365 + brelse(bh[b]);
366 +
367 +read_failure:
368 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
369 + return 0;
370 +}
371 +
372 +
373 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
374 + long long block, unsigned int offset,
375 + int length, long long *next_block,
376 + unsigned int *next_offset)
377 +{
378 + struct squashfs_sb_info *msblk = s->s_fs_info;
379 + int n, i, bytes, return_length = length;
380 + long long next_index;
381 +
382 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
383 +
384 + while ( 1 ) {
385 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
386 + if (msblk->block_cache[i].block == block)
387 + break;
388 +
389 + down(&msblk->block_cache_mutex);
390 +
391 + if (i == SQUASHFS_CACHED_BLKS) {
392 + /* read inode header block */
393 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
394 + n ; n --, i = (i + 1) %
395 + SQUASHFS_CACHED_BLKS)
396 + if (msblk->block_cache[i].block !=
397 + SQUASHFS_USED_BLK)
398 + break;
399 +
400 + if (n == 0) {
401 + wait_queue_t wait;
402 +
403 + init_waitqueue_entry(&wait, current);
404 + add_wait_queue(&msblk->waitq, &wait);
405 + set_current_state(TASK_UNINTERRUPTIBLE);
406 + up(&msblk->block_cache_mutex);
407 + schedule();
408 + set_current_state(TASK_RUNNING);
409 + remove_wait_queue(&msblk->waitq, &wait);
410 + continue;
411 + }
412 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
413 +
414 + if (msblk->block_cache[i].block ==
415 + SQUASHFS_INVALID_BLK) {
416 + if (!(msblk->block_cache[i].data =
417 + kmalloc(SQUASHFS_METADATA_SIZE,
418 + GFP_KERNEL))) {
419 + ERROR("Failed to allocate cache"
420 + "block\n");
421 + up(&msblk->block_cache_mutex);
422 + goto out;
423 + }
424 + }
425 +
426 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
427 + up(&msblk->block_cache_mutex);
428 +
429 + if (!(msblk->block_cache[i].length =
430 + squashfs_read_data(s,
431 + msblk->block_cache[i].data,
432 + block, 0, &next_index))) {
433 + ERROR("Unable to read cache block [%llx:%x]\n",
434 + block, offset);
435 + goto out;
436 + }
437 +
438 + down(&msblk->block_cache_mutex);
439 + wake_up(&msblk->waitq);
440 + msblk->block_cache[i].block = block;
441 + msblk->block_cache[i].next_index = next_index;
442 + TRACE("Read cache block [%llx:%x]\n", block, offset);
443 + }
444 +
445 + if (msblk->block_cache[i].block != block) {
446 + up(&msblk->block_cache_mutex);
447 + continue;
448 + }
449 +
450 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
451 + if (buffer)
452 + memcpy(buffer, msblk->block_cache[i].data +
453 + offset, length);
454 + if (msblk->block_cache[i].length - offset == length) {
455 + *next_block = msblk->block_cache[i].next_index;
456 + *next_offset = 0;
457 + } else {
458 + *next_block = block;
459 + *next_offset = offset + length;
460 + }
461 + up(&msblk->block_cache_mutex);
462 + goto finish;
463 + } else {
464 + if (buffer) {
465 + memcpy(buffer, msblk->block_cache[i].data +
466 + offset, bytes);
467 + buffer += bytes;
468 + }
469 + block = msblk->block_cache[i].next_index;
470 + up(&msblk->block_cache_mutex);
471 + length -= bytes;
472 + offset = 0;
473 + }
474 + }
475 +
476 +finish:
477 + return return_length;
478 +out:
479 + return 0;
480 +}
481 +
482 +
483 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
484 + long long *fragment_start_block,
485 + unsigned int *fragment_size)
486 +{
487 + struct squashfs_sb_info *msblk = s->s_fs_info;
488 + long long start_block =
489 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
490 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
491 + struct squashfs_fragment_entry fragment_entry;
492 +
493 + if (msblk->swap) {
494 + struct squashfs_fragment_entry sfragment_entry;
495 +
496 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
497 + start_block, offset,
498 + sizeof(sfragment_entry), &start_block,
499 + &offset))
500 + goto out;
501 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
502 + } else
503 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
504 + start_block, offset,
505 + sizeof(fragment_entry), &start_block,
506 + &offset))
507 + goto out;
508 +
509 + *fragment_start_block = fragment_entry.start_block;
510 + *fragment_size = fragment_entry.size;
511 +
512 + return 1;
513 +
514 +out:
515 + return 0;
516 +}
517 +
518 +
519 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
520 + squashfs_fragment_cache *fragment)
521 +{
522 + down(&msblk->fragment_mutex);
523 + fragment->locked --;
524 + wake_up(&msblk->fragment_wait_queue);
525 + up(&msblk->fragment_mutex);
526 +}
527 +
528 +
529 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
530 + *s, long long start_block,
531 + int length)
532 +{
533 + int i, n;
534 + struct squashfs_sb_info *msblk = s->s_fs_info;
535 +
536 + while ( 1 ) {
537 + down(&msblk->fragment_mutex);
538 +
539 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
540 + msblk->fragment[i].block != start_block; i++);
541 +
542 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
543 + for (i = msblk->next_fragment, n =
544 + SQUASHFS_CACHED_FRAGMENTS; n &&
545 + msblk->fragment[i].locked; n--, i = (i + 1) %
546 + SQUASHFS_CACHED_FRAGMENTS);
547 +
548 + if (n == 0) {
549 + wait_queue_t wait;
550 +
551 + init_waitqueue_entry(&wait, current);
552 + add_wait_queue(&msblk->fragment_wait_queue,
553 + &wait);
554 + set_current_state(TASK_UNINTERRUPTIBLE);
555 + up(&msblk->fragment_mutex);
556 + schedule();
557 + set_current_state(TASK_RUNNING);
558 + remove_wait_queue(&msblk->fragment_wait_queue,
559 + &wait);
560 + continue;
561 + }
562 + msblk->next_fragment = (msblk->next_fragment + 1) %
563 + SQUASHFS_CACHED_FRAGMENTS;
564 +
565 + if (msblk->fragment[i].data == NULL)
566 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
567 + (SQUASHFS_FILE_MAX_SIZE))) {
568 + ERROR("Failed to allocate fragment "
569 + "cache block\n");
570 + up(&msblk->fragment_mutex);
571 + goto out;
572 + }
573 +
574 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
575 + msblk->fragment[i].locked = 1;
576 + up(&msblk->fragment_mutex);
577 +
578 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
579 + msblk->fragment[i].data,
580 + start_block, length, NULL))) {
581 + ERROR("Unable to read fragment cache block "
582 + "[%llx]\n", start_block);
583 + msblk->fragment[i].locked = 0;
584 + goto out;
585 + }
586 +
587 + msblk->fragment[i].block = start_block;
588 + TRACE("New fragment %d, start block %lld, locked %d\n",
589 + i, msblk->fragment[i].block,
590 + msblk->fragment[i].locked);
591 + break;
592 + }
593 +
594 + msblk->fragment[i].locked++;
595 + up(&msblk->fragment_mutex);
596 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
597 + msblk->fragment[i].block,
598 + msblk->fragment[i].locked);
599 + break;
600 + }
601 +
602 + return &msblk->fragment[i];
603 +
604 +out:
605 + return NULL;
606 +}
607 +
608 +
609 +static struct inode *squashfs_new_inode(struct super_block *s,
610 + struct squashfs_base_inode_header *inodeb)
611 +{
612 + struct squashfs_sb_info *msblk = s->s_fs_info;
613 + struct inode *i = new_inode(s);
614 +
615 + if (i) {
616 + i->i_ino = inodeb->inode_number;
617 + i->i_mtime.tv_sec = inodeb->mtime;
618 + i->i_atime.tv_sec = inodeb->mtime;
619 + i->i_ctime.tv_sec = inodeb->mtime;
620 + i->i_uid = msblk->uid[inodeb->uid];
621 + i->i_mode = inodeb->mode;
622 + i->i_size = 0;
623 + if (inodeb->guid == SQUASHFS_GUIDS)
624 + i->i_gid = i->i_uid;
625 + else
626 + i->i_gid = msblk->guid[inodeb->guid];
627 + }
628 +
629 + return i;
630 +}
631 +
632 +
633 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
634 +{
635 + struct inode *i;
636 + struct squashfs_sb_info *msblk = s->s_fs_info;
637 + struct squashfs_super_block *sblk = &msblk->sblk;
638 + long long block = SQUASHFS_INODE_BLK(inode) +
639 + sblk->inode_table_start;
640 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
641 + long long next_block;
642 + unsigned int next_offset;
643 + union squashfs_inode_header id, sid;
644 + struct squashfs_base_inode_header *inodeb = &id.base,
645 + *sinodeb = &sid.base;
646 +
647 + TRACE("Entered squashfs_iget\n");
648 +
649 + if (msblk->swap) {
650 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
651 + offset, sizeof(*sinodeb), &next_block,
652 + &next_offset))
653 + goto failed_read;
654 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
655 + sizeof(*sinodeb));
656 + } else
657 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
658 + offset, sizeof(*inodeb), &next_block,
659 + &next_offset))
660 + goto failed_read;
661 +
662 + switch(inodeb->inode_type) {
663 + case SQUASHFS_FILE_TYPE: {
664 + unsigned int frag_size;
665 + long long frag_blk;
666 + struct squashfs_reg_inode_header *inodep = &id.reg;
667 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
668 +
669 + if (msblk->swap) {
670 + if (!squashfs_get_cached_block(s, (char *)
671 + sinodep, block, offset,
672 + sizeof(*sinodep), &next_block,
673 + &next_offset))
674 + goto failed_read;
675 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
676 + } else
677 + if (!squashfs_get_cached_block(s, (char *)
678 + inodep, block, offset,
679 + sizeof(*inodep), &next_block,
680 + &next_offset))
681 + goto failed_read;
682 +
683 + frag_blk = SQUASHFS_INVALID_BLK;
684 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
685 + !get_fragment_location(s,
686 + inodep->fragment, &frag_blk, &frag_size))
687 + goto failed_read;
688 +
689 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
690 + goto failed_read1;
691 +
692 + i->i_nlink = 1;
693 + i->i_size = inodep->file_size;
694 + i->i_fop = &generic_ro_fops;
695 + i->i_mode |= S_IFREG;
696 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
697 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
698 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
699 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
700 + SQUASHFS_I(i)->start_block = inodep->start_block;
701 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
702 + SQUASHFS_I(i)->offset = next_offset;
703 + if (sblk->block_size > 4096)
704 + i->i_data.a_ops = &squashfs_aops;
705 + else
706 + i->i_data.a_ops = &squashfs_aops_4K;
707 +
708 + TRACE("File inode %x:%x, start_block %llx, "
709 + "block_list_start %llx, offset %x\n",
710 + SQUASHFS_INODE_BLK(inode), offset,
711 + inodep->start_block, next_block,
712 + next_offset);
713 + break;
714 + }
715 + case SQUASHFS_LREG_TYPE: {
716 + unsigned int frag_size;
717 + long long frag_blk;
718 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
719 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
720 +
721 + if (msblk->swap) {
722 + if (!squashfs_get_cached_block(s, (char *)
723 + sinodep, block, offset,
724 + sizeof(*sinodep), &next_block,
725 + &next_offset))
726 + goto failed_read;
727 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
728 + } else
729 + if (!squashfs_get_cached_block(s, (char *)
730 + inodep, block, offset,
731 + sizeof(*inodep), &next_block,
732 + &next_offset))
733 + goto failed_read;
734 +
735 + frag_blk = SQUASHFS_INVALID_BLK;
736 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
737 + !get_fragment_location(s,
738 + inodep->fragment, &frag_blk, &frag_size))
739 + goto failed_read;
740 +
741 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
742 + goto failed_read1;
743 +
744 + i->i_nlink = inodep->nlink;
745 + i->i_size = inodep->file_size;
746 + i->i_fop = &generic_ro_fops;
747 + i->i_mode |= S_IFREG;
748 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
749 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
750 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
751 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
752 + SQUASHFS_I(i)->start_block = inodep->start_block;
753 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
754 + SQUASHFS_I(i)->offset = next_offset;
755 + if (sblk->block_size > 4096)
756 + i->i_data.a_ops = &squashfs_aops;
757 + else
758 + i->i_data.a_ops = &squashfs_aops_4K;
759 +
760 + TRACE("File inode %x:%x, start_block %llx, "
761 + "block_list_start %llx, offset %x\n",
762 + SQUASHFS_INODE_BLK(inode), offset,
763 + inodep->start_block, next_block,
764 + next_offset);
765 + break;
766 + }
767 + case SQUASHFS_DIR_TYPE: {
768 + struct squashfs_dir_inode_header *inodep = &id.dir;
769 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
770 +
771 + if (msblk->swap) {
772 + if (!squashfs_get_cached_block(s, (char *)
773 + sinodep, block, offset,
774 + sizeof(*sinodep), &next_block,
775 + &next_offset))
776 + goto failed_read;
777 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
778 + } else
779 + if (!squashfs_get_cached_block(s, (char *)
780 + inodep, block, offset,
781 + sizeof(*inodep), &next_block,
782 + &next_offset))
783 + goto failed_read;
784 +
785 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
786 + goto failed_read1;
787 +
788 + i->i_nlink = inodep->nlink;
789 + i->i_size = inodep->file_size;
790 + i->i_op = &squashfs_dir_inode_ops;
791 + i->i_fop = &squashfs_dir_ops;
792 + i->i_mode |= S_IFDIR;
793 + SQUASHFS_I(i)->start_block = inodep->start_block;
794 + SQUASHFS_I(i)->offset = inodep->offset;
795 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
796 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
797 +
798 + TRACE("Directory inode %x:%x, start_block %x, offset "
799 + "%x\n", SQUASHFS_INODE_BLK(inode),
800 + offset, inodep->start_block,
801 + inodep->offset);
802 + break;
803 + }
804 + case SQUASHFS_LDIR_TYPE: {
805 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
806 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
807 +
808 + if (msblk->swap) {
809 + if (!squashfs_get_cached_block(s, (char *)
810 + sinodep, block, offset,
811 + sizeof(*sinodep), &next_block,
812 + &next_offset))
813 + goto failed_read;
814 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
815 + sinodep);
816 + } else
817 + if (!squashfs_get_cached_block(s, (char *)
818 + inodep, block, offset,
819 + sizeof(*inodep), &next_block,
820 + &next_offset))
821 + goto failed_read;
822 +
823 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
824 + goto failed_read1;
825 +
826 + i->i_nlink = inodep->nlink;
827 + i->i_size = inodep->file_size;
828 + i->i_op = &squashfs_dir_inode_ops;
829 + i->i_fop = &squashfs_dir_ops;
830 + i->i_mode |= S_IFDIR;
831 + SQUASHFS_I(i)->start_block = inodep->start_block;
832 + SQUASHFS_I(i)->offset = inodep->offset;
833 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
834 + SQUASHFS_I(i)->u.s2.directory_index_offset =
835 + next_offset;
836 + SQUASHFS_I(i)->u.s2.directory_index_count =
837 + inodep->i_count;
838 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
839 +
840 + TRACE("Long directory inode %x:%x, start_block %x, "
841 + "offset %x\n",
842 + SQUASHFS_INODE_BLK(inode), offset,
843 + inodep->start_block, inodep->offset);
844 + break;
845 + }
846 + case SQUASHFS_SYMLINK_TYPE: {
847 + struct squashfs_symlink_inode_header *inodep =
848 + &id.symlink;
849 + struct squashfs_symlink_inode_header *sinodep =
850 + &sid.symlink;
851 +
852 + if (msblk->swap) {
853 + if (!squashfs_get_cached_block(s, (char *)
854 + sinodep, block, offset,
855 + sizeof(*sinodep), &next_block,
856 + &next_offset))
857 + goto failed_read;
858 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
859 + sinodep);
860 + } else
861 + if (!squashfs_get_cached_block(s, (char *)
862 + inodep, block, offset,
863 + sizeof(*inodep), &next_block,
864 + &next_offset))
865 + goto failed_read;
866 +
867 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
868 + goto failed_read1;
869 +
870 + i->i_nlink = inodep->nlink;
871 + i->i_size = inodep->symlink_size;
872 + i->i_op = &page_symlink_inode_operations;
873 + i->i_data.a_ops = &squashfs_symlink_aops;
874 + i->i_mode |= S_IFLNK;
875 + SQUASHFS_I(i)->start_block = next_block;
876 + SQUASHFS_I(i)->offset = next_offset;
877 +
878 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
879 + "offset %x\n",
880 + SQUASHFS_INODE_BLK(inode), offset,
881 + next_block, next_offset);
882 + break;
883 + }
884 + case SQUASHFS_BLKDEV_TYPE:
885 + case SQUASHFS_CHRDEV_TYPE: {
886 + struct squashfs_dev_inode_header *inodep = &id.dev;
887 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
888 +
889 + if (msblk->swap) {
890 + if (!squashfs_get_cached_block(s, (char *)
891 + sinodep, block, offset,
892 + sizeof(*sinodep), &next_block,
893 + &next_offset))
894 + goto failed_read;
895 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
896 + } else
897 + if (!squashfs_get_cached_block(s, (char *)
898 + inodep, block, offset,
899 + sizeof(*inodep), &next_block,
900 + &next_offset))
901 + goto failed_read;
902 +
903 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
904 + goto failed_read1;
905 +
906 + i->i_nlink = inodep->nlink;
907 + i->i_mode |= (inodeb->inode_type ==
908 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
909 + S_IFBLK;
910 + init_special_inode(i, i->i_mode,
911 + old_decode_dev(inodep->rdev));
912 +
913 + TRACE("Device inode %x:%x, rdev %x\n",
914 + SQUASHFS_INODE_BLK(inode), offset,
915 + inodep->rdev);
916 + break;
917 + }
918 + case SQUASHFS_FIFO_TYPE:
919 + case SQUASHFS_SOCKET_TYPE: {
920 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
921 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
922 +
923 + if (msblk->swap) {
924 + if (!squashfs_get_cached_block(s, (char *)
925 + sinodep, block, offset,
926 + sizeof(*sinodep), &next_block,
927 + &next_offset))
928 + goto failed_read;
929 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
930 + } else
931 + if (!squashfs_get_cached_block(s, (char *)
932 + inodep, block, offset,
933 + sizeof(*inodep), &next_block,
934 + &next_offset))
935 + goto failed_read;
936 +
937 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
938 + goto failed_read1;
939 +
940 + i->i_nlink = inodep->nlink;
941 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
942 + ? S_IFIFO : S_IFSOCK;
943 + init_special_inode(i, i->i_mode, 0);
944 + break;
945 + }
946 + default:
947 + ERROR("Unknown inode type %d in squashfs_iget!\n",
948 + inodeb->inode_type);
949 + goto failed_read1;
950 + }
951 +
952 + insert_inode_hash(i);
953 + return i;
954 +
955 +failed_read:
956 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
957 +
958 +failed_read1:
959 + return NULL;
960 +}
961 +
962 +
963 +static int read_fragment_index_table(struct super_block *s)
964 +{
965 + struct squashfs_sb_info *msblk = s->s_fs_info;
966 + struct squashfs_super_block *sblk = &msblk->sblk;
967 +
968 + /* Allocate fragment index table */
969 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
970 + (sblk->fragments), GFP_KERNEL))) {
971 + ERROR("Failed to allocate uid/gid table\n");
972 + return 0;
973 + }
974 +
975 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
976 + !squashfs_read_data(s, (char *)
977 + msblk->fragment_index,
978 + sblk->fragment_table_start,
979 + SQUASHFS_FRAGMENT_INDEX_BYTES
980 + (sblk->fragments) |
981 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
982 + ERROR("unable to read fragment index table\n");
983 + return 0;
984 + }
985 +
986 + if (msblk->swap) {
987 + int i;
988 + long long fragment;
989 +
990 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
991 + i++) {
992 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
993 + &msblk->fragment_index[i], 1);
994 + msblk->fragment_index[i] = fragment;
995 + }
996 + }
997 +
998 + return 1;
999 +}
1000 +
1001 +
1002 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1003 +{
1004 + struct squashfs_super_block *sblk = &msblk->sblk;
1005 +
1006 + msblk->iget = squashfs_iget;
1007 + msblk->read_blocklist = read_blocklist;
1008 + msblk->read_fragment_index_table = read_fragment_index_table;
1009 +
1010 + if (sblk->s_major == 1) {
1011 + if (!squashfs_1_0_supported(msblk)) {
1012 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1013 + "are unsupported\n");
1014 + SERROR("Please recompile with "
1015 + "Squashfs 1.0 support enabled\n");
1016 + return 0;
1017 + }
1018 + } else if (sblk->s_major == 2) {
1019 + if (!squashfs_2_0_supported(msblk)) {
1020 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1021 + "are unsupported\n");
1022 + SERROR("Please recompile with "
1023 + "Squashfs 2.0 support enabled\n");
1024 + return 0;
1025 + }
1026 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1027 + SQUASHFS_MINOR) {
1028 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1029 + "filesystem\n", sblk->s_major, sblk->s_minor);
1030 + SERROR("Please update your kernel\n");
1031 + return 0;
1032 + }
1033 +
1034 + return 1;
1035 +}
1036 +
1037 +
1038 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1039 +{
1040 + struct squashfs_sb_info *msblk;
1041 + struct squashfs_super_block *sblk;
1042 + int i;
1043 + char b[BDEVNAME_SIZE];
1044 + struct inode *root;
1045 +
1046 + TRACE("Entered squashfs_read_superblock\n");
1047 +
1048 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1049 + GFP_KERNEL))) {
1050 + ERROR("Failed to allocate superblock\n");
1051 + goto failure;
1052 + }
1053 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1054 + msblk = s->s_fs_info;
1055 + sblk = &msblk->sblk;
1056 +
1057 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1058 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1059 +
1060 + init_MUTEX(&msblk->read_data_mutex);
1061 + init_MUTEX(&msblk->read_page_mutex);
1062 + init_MUTEX(&msblk->block_cache_mutex);
1063 + init_MUTEX(&msblk->fragment_mutex);
1064 + init_MUTEX(&msblk->meta_index_mutex);
1065 +
1066 + init_waitqueue_head(&msblk->waitq);
1067 + init_waitqueue_head(&msblk->fragment_wait_queue);
1068 +
1069 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1070 + sizeof(struct squashfs_super_block) |
1071 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1072 + SERROR("unable to read superblock\n");
1073 + goto failed_mount;
1074 + }
1075 +
1076 + /* Check it is a SQUASHFS superblock */
1077 + msblk->swap = 0;
1078 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1079 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1080 + struct squashfs_super_block ssblk;
1081 +
1082 + WARNING("Mounting a different endian SQUASHFS "
1083 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1084 +
1085 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1086 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1087 + msblk->swap = 1;
1088 + } else {
1089 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1090 + bdevname(s->s_bdev, b));
1091 + goto failed_mount;
1092 + }
1093 + }
1094 +
1095 + /* Check the MAJOR & MINOR versions */
1096 + if(!supported_squashfs_filesystem(msblk, silent))
1097 + goto failed_mount;
1098 +
1099 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1100 + TRACE("Inodes are %scompressed\n",
1101 + SQUASHFS_UNCOMPRESSED_INODES
1102 + (sblk->flags) ? "un" : "");
1103 + TRACE("Data is %scompressed\n",
1104 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1105 + ? "un" : "");
1106 + TRACE("Check data is %s present in the filesystem\n",
1107 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1108 + "" : "not");
1109 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1110 + TRACE("Block size %d\n", sblk->block_size);
1111 + TRACE("Number of inodes %d\n", sblk->inodes);
1112 + if (sblk->s_major > 1)
1113 + TRACE("Number of fragments %d\n", sblk->fragments);
1114 + TRACE("Number of uids %d\n", sblk->no_uids);
1115 + TRACE("Number of gids %d\n", sblk->no_guids);
1116 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1117 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1118 + if (sblk->s_major > 1)
1119 + TRACE("sblk->fragment_table_start %llx\n",
1120 + sblk->fragment_table_start);
1121 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1122 +
1123 + s->s_flags |= MS_RDONLY;
1124 + s->s_op = &squashfs_ops;
1125 +
1126 + /* Init inode_table block pointer array */
1127 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1128 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1129 + ERROR("Failed to allocate block cache\n");
1130 + goto failed_mount;
1131 + }
1132 +
1133 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1134 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1135 +
1136 + msblk->next_cache = 0;
1137 +
1138 + /* Allocate read_data block */
1139 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1140 + SQUASHFS_METADATA_SIZE :
1141 + sblk->block_size;
1142 +
1143 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1144 + ERROR("Failed to allocate read_data block\n");
1145 + goto failed_mount;
1146 + }
1147 +
1148 + /* Allocate read_page block */
1149 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1150 + ERROR("Failed to allocate read_page block\n");
1151 + goto failed_mount;
1152 + }
1153 +
1154 + /* Allocate uid and gid tables */
1155 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1156 + sizeof(unsigned int), GFP_KERNEL))) {
1157 + ERROR("Failed to allocate uid/gid table\n");
1158 + goto failed_mount;
1159 + }
1160 + msblk->guid = msblk->uid + sblk->no_uids;
1161 +
1162 + if (msblk->swap) {
1163 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1164 +
1165 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1166 + ((sblk->no_uids + sblk->no_guids) *
1167 + sizeof(unsigned int)) |
1168 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1169 + ERROR("unable to read uid/gid table\n");
1170 + goto failed_mount;
1171 + }
1172 +
1173 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1174 + sblk->no_guids), (sizeof(unsigned int) * 8));
1175 + } else
1176 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1177 + ((sblk->no_uids + sblk->no_guids) *
1178 + sizeof(unsigned int)) |
1179 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1180 + ERROR("unable to read uid/gid table\n");
1181 + goto failed_mount;
1182 + }
1183 +
1184 +
1185 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1186 + goto allocate_root;
1187 +
1188 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1189 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1190 + ERROR("Failed to allocate fragment block cache\n");
1191 + goto failed_mount;
1192 + }
1193 +
1194 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1195 + msblk->fragment[i].locked = 0;
1196 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1197 + msblk->fragment[i].data = NULL;
1198 + }
1199 +
1200 + msblk->next_fragment = 0;
1201 +
1202 + /* Allocate fragment index table */
1203 + if (msblk->read_fragment_index_table(s) == 0)
1204 + goto failed_mount;
1205 +
1206 +allocate_root:
1207 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1208 + goto failed_mount;
1209 +
1210 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1211 + ERROR("Root inode create failed\n");
1212 + iput(root);
1213 + goto failed_mount;
1214 + }
1215 +
1216 + TRACE("Leaving squashfs_read_super\n");
1217 + return 0;
1218 +
1219 +failed_mount:
1220 + kfree(msblk->fragment_index);
1221 + kfree(msblk->fragment);
1222 + kfree(msblk->uid);
1223 + kfree(msblk->read_page);
1224 + kfree(msblk->read_data);
1225 + kfree(msblk->block_cache);
1226 + kfree(msblk->fragment_index_2);
1227 + kfree(s->s_fs_info);
1228 + s->s_fs_info = NULL;
1229 + return -EINVAL;
1230 +
1231 +failure:
1232 + return -ENOMEM;
1233 +}
1234 +
1235 +
1236 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1237 +{
1238 + struct squashfs_sb_info *msblk = dentry->d_inode->i_sb->s_fs_info;
1239 + struct squashfs_super_block *sblk = &msblk->sblk;
1240 +
1241 + TRACE("Entered squashfs_statfs\n");
1242 +
1243 + buf->f_type = SQUASHFS_MAGIC;
1244 + buf->f_bsize = sblk->block_size;
1245 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1246 + buf->f_bfree = buf->f_bavail = 0;
1247 + buf->f_files = sblk->inodes;
1248 + buf->f_ffree = 0;
1249 + buf->f_namelen = SQUASHFS_NAME_LEN;
1250 +
1251 + return 0;
1252 +}
1253 +
1254 +
1255 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1256 +{
1257 + struct inode *inode = page->mapping->host;
1258 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1259 + long long block = SQUASHFS_I(inode)->start_block;
1260 + int offset = SQUASHFS_I(inode)->offset;
1261 + void *pageaddr = kmap(page);
1262 +
1263 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1264 + "%llx, offset %x\n", page->index,
1265 + SQUASHFS_I(inode)->start_block,
1266 + SQUASHFS_I(inode)->offset);
1267 +
1268 + for (length = 0; length < index; length += bytes) {
1269 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1270 + block, offset, PAGE_CACHE_SIZE, &block,
1271 + &offset))) {
1272 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1273 + offset);
1274 + goto skip_read;
1275 + }
1276 + }
1277 +
1278 + if (length != index) {
1279 + ERROR("(squashfs_symlink_readpage) length != index\n");
1280 + bytes = 0;
1281 + goto skip_read;
1282 + }
1283 +
1284 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1285 + i_size_read(inode) - length;
1286 +
1287 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1288 + offset, bytes, &block, &offset)))
1289 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1290 +
1291 +skip_read:
1292 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1293 + kunmap(page);
1294 + SetPageUptodate(page);
1295 + unlock_page(page);
1296 +
1297 + return 0;
1298 +}
1299 +
1300 +
1301 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1302 +{
1303 + struct meta_index *meta = NULL;
1304 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1305 + int i;
1306 +
1307 + down(&msblk->meta_index_mutex);
1308 +
1309 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1310 +
1311 + if(msblk->meta_index == NULL)
1312 + goto not_allocated;
1313 +
1314 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1315 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1316 + msblk->meta_index[i].offset >= offset &&
1317 + msblk->meta_index[i].offset <= index &&
1318 + msblk->meta_index[i].locked == 0) {
1319 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1320 + msblk->meta_index[i].offset);
1321 + meta = &msblk->meta_index[i];
1322 + offset = meta->offset;
1323 + }
1324 +
1325 + if (meta)
1326 + meta->locked = 1;
1327 +
1328 +not_allocated:
1329 + up(&msblk->meta_index_mutex);
1330 +
1331 + return meta;
1332 +}
1333 +
1334 +
1335 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1336 +{
1337 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1338 + struct meta_index *meta = NULL;
1339 + int i;
1340 +
1341 + down(&msblk->meta_index_mutex);
1342 +
1343 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1344 +
1345 + if(msblk->meta_index == NULL) {
1346 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1347 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1348 + ERROR("Failed to allocate meta_index\n");
1349 + goto failed;
1350 + }
1351 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1352 + msblk->meta_index[i].inode_number = 0;
1353 + msblk->meta_index[i].locked = 0;
1354 + }
1355 + msblk->next_meta_index = 0;
1356 + }
1357 +
1358 + for(i = SQUASHFS_META_NUMBER; i &&
1359 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1360 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1361 + SQUASHFS_META_NUMBER;
1362 +
1363 + if(i == 0) {
1364 + TRACE("empty_meta_index: failed!\n");
1365 + goto failed;
1366 + }
1367 +
1368 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1369 + msblk->next_meta_index,
1370 + &msblk->meta_index[msblk->next_meta_index]);
1371 +
1372 + meta = &msblk->meta_index[msblk->next_meta_index];
1373 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1374 + SQUASHFS_META_NUMBER;
1375 +
1376 + meta->inode_number = inode->i_ino;
1377 + meta->offset = offset;
1378 + meta->skip = skip;
1379 + meta->entries = 0;
1380 + meta->locked = 1;
1381 +
1382 +failed:
1383 + up(&msblk->meta_index_mutex);
1384 + return meta;
1385 +}
1386 +
1387 +
1388 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1389 +{
1390 + meta->locked = 0;
1391 +}
1392 +
1393 +
1394 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1395 + long long *start_block, int *offset)
1396 +{
1397 + struct squashfs_sb_info *msblk = s->s_fs_info;
1398 + unsigned int *block_listp;
1399 + int block = 0;
1400 +
1401 + if (msblk->swap) {
1402 + char sblock_list[blocks << 2];
1403 +
1404 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1405 + *offset, blocks << 2, start_block, offset)) {
1406 + ERROR("Unable to read block list [%llx:%x]\n",
1407 + *start_block, *offset);
1408 + goto failure;
1409 + }
1410 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1411 + ((unsigned int *)sblock_list), blocks);
1412 + } else
1413 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1414 + *offset, blocks << 2, start_block, offset)) {
1415 + ERROR("Unable to read block list [%llx:%x]\n",
1416 + *start_block, *offset);
1417 + goto failure;
1418 + }
1419 +
1420 + for (block_listp = (unsigned int *) block_list; blocks;
1421 + block_listp++, blocks --)
1422 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1423 +
1424 + return block;
1425 +
1426 +failure:
1427 + return -1;
1428 +}
1429 +
1430 +
1431 +#define SIZE 256
1432 +
1433 +static inline int calculate_skip(int blocks) {
1434 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1435 + return skip >= 7 ? 7 : skip + 1;
1436 +}
1437 +
1438 +
1439 +static int get_meta_index(struct inode *inode, int index,
1440 + long long *index_block, int *index_offset,
1441 + long long *data_block, char *block_list)
1442 +{
1443 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1444 + struct squashfs_super_block *sblk = &msblk->sblk;
1445 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1446 + int offset = 0;
1447 + struct meta_index *meta;
1448 + struct meta_entry *meta_entry;
1449 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1450 + int cur_offset = SQUASHFS_I(inode)->offset;
1451 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1452 + int i;
1453 +
1454 + index /= SQUASHFS_META_INDEXES * skip;
1455 +
1456 + while ( offset < index ) {
1457 + meta = locate_meta_index(inode, index, offset + 1);
1458 +
1459 + if (meta == NULL) {
1460 + if ((meta = empty_meta_index(inode, offset + 1,
1461 + skip)) == NULL)
1462 + goto all_done;
1463 + } else {
1464 + offset = index < meta->offset + meta->entries ? index :
1465 + meta->offset + meta->entries - 1;
1466 + meta_entry = &meta->meta_entry[offset - meta->offset];
1467 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1468 + cur_offset = meta_entry->offset;
1469 + cur_data_block = meta_entry->data_block;
1470 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1471 + "meta->entries %d\n", offset, meta->offset,
1472 + meta->entries);
1473 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1474 + " data_block 0x%llx\n", cur_index_block,
1475 + cur_offset, cur_data_block);
1476 + }
1477 +
1478 + for (i = meta->offset + meta->entries; i <= index &&
1479 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1480 + int blocks = skip * SQUASHFS_META_INDEXES;
1481 +
1482 + while (blocks) {
1483 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1484 + blocks;
1485 + int res = read_block_index(inode->i_sb, block,
1486 + block_list, &cur_index_block,
1487 + &cur_offset);
1488 +
1489 + if (res == -1)
1490 + goto failed;
1491 +
1492 + cur_data_block += res;
1493 + blocks -= block;
1494 + }
1495 +
1496 + meta_entry = &meta->meta_entry[i - meta->offset];
1497 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1498 + meta_entry->offset = cur_offset;
1499 + meta_entry->data_block = cur_data_block;
1500 + meta->entries ++;
1501 + offset ++;
1502 + }
1503 +
1504 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1505 + meta->offset, meta->entries);
1506 +
1507 + release_meta_index(inode, meta);
1508 + }
1509 +
1510 +all_done:
1511 + *index_block = cur_index_block;
1512 + *index_offset = cur_offset;
1513 + *data_block = cur_data_block;
1514 +
1515 + return offset * SQUASHFS_META_INDEXES * skip;
1516 +
1517 +failed:
1518 + release_meta_index(inode, meta);
1519 + return -1;
1520 +}
1521 +
1522 +
1523 +static long long read_blocklist(struct inode *inode, int index,
1524 + int readahead_blks, char *block_list,
1525 + unsigned short **block_p, unsigned int *bsize)
1526 +{
1527 + long long block_ptr;
1528 + int offset;
1529 + long long block;
1530 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1531 + block_list);
1532 +
1533 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1534 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1535 + block);
1536 +
1537 + if(res == -1)
1538 + goto failure;
1539 +
1540 + index -= res;
1541 +
1542 + while ( index ) {
1543 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1544 + int res = read_block_index(inode->i_sb, blocks, block_list,
1545 + &block_ptr, &offset);
1546 + if (res == -1)
1547 + goto failure;
1548 + block += res;
1549 + index -= blocks;
1550 + }
1551 +
1552 + if (read_block_index(inode->i_sb, 1, block_list,
1553 + &block_ptr, &offset) == -1)
1554 + goto failure;
1555 + *bsize = *((unsigned int *) block_list);
1556 +
1557 + return block;
1558 +
1559 +failure:
1560 + return 0;
1561 +}
1562 +
1563 +
1564 +static int squashfs_readpage(struct file *file, struct page *page)
1565 +{
1566 + struct inode *inode = page->mapping->host;
1567 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1568 + struct squashfs_super_block *sblk = &msblk->sblk;
1569 + unsigned char block_list[SIZE];
1570 + long long block;
1571 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1572 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1573 + void *pageaddr;
1574 + struct squashfs_fragment_cache *fragment = NULL;
1575 + char *data_ptr = msblk->read_page;
1576 +
1577 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1578 + int start_index = page->index & ~mask;
1579 + int end_index = start_index | mask;
1580 +
1581 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1582 + page->index,
1583 + SQUASHFS_I(inode)->start_block);
1584 +
1585 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1586 + PAGE_CACHE_SHIFT))
1587 + goto skip_read;
1588 +
1589 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1590 + || index < (i_size_read(inode) >>
1591 + sblk->block_log)) {
1592 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1593 + block_list, NULL, &bsize)) == 0)
1594 + goto skip_read;
1595 +
1596 + down(&msblk->read_page_mutex);
1597 +
1598 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1599 + block, bsize, NULL))) {
1600 + ERROR("Unable to read page, block %llx, size %x\n", block,
1601 + bsize);
1602 + up(&msblk->read_page_mutex);
1603 + goto skip_read;
1604 + }
1605 + } else {
1606 + if ((fragment = get_cached_fragment(inode->i_sb,
1607 + SQUASHFS_I(inode)->
1608 + u.s1.fragment_start_block,
1609 + SQUASHFS_I(inode)->u.s1.fragment_size))
1610 + == NULL) {
1611 + ERROR("Unable to read page, block %llx, size %x\n",
1612 + SQUASHFS_I(inode)->
1613 + u.s1.fragment_start_block,
1614 + (int) SQUASHFS_I(inode)->
1615 + u.s1.fragment_size);
1616 + goto skip_read;
1617 + }
1618 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1619 + (i_size_read(inode) & (sblk->block_size
1620 + - 1));
1621 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1622 + data_ptr = fragment->data;
1623 + }
1624 +
1625 + for (i = start_index; i <= end_index && byte_offset < bytes;
1626 + i++, byte_offset += PAGE_CACHE_SIZE) {
1627 + struct page *push_page;
1628 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1629 + PAGE_CACHE_SIZE : bytes - byte_offset;
1630 +
1631 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1632 + bytes, i, byte_offset, available_bytes);
1633 +
1634 + if (i == page->index) {
1635 + pageaddr = kmap_atomic(page, KM_USER0);
1636 + memcpy(pageaddr, data_ptr + byte_offset,
1637 + available_bytes);
1638 + memset(pageaddr + available_bytes, 0,
1639 + PAGE_CACHE_SIZE - available_bytes);
1640 + kunmap_atomic(pageaddr, KM_USER0);
1641 + flush_dcache_page(page);
1642 + SetPageUptodate(page);
1643 + unlock_page(page);
1644 + } else if ((push_page =
1645 + grab_cache_page_nowait(page->mapping, i))) {
1646 + pageaddr = kmap_atomic(push_page, KM_USER0);
1647 +
1648 + memcpy(pageaddr, data_ptr + byte_offset,
1649 + available_bytes);
1650 + memset(pageaddr + available_bytes, 0,
1651 + PAGE_CACHE_SIZE - available_bytes);
1652 + kunmap_atomic(pageaddr, KM_USER0);
1653 + flush_dcache_page(push_page);
1654 + SetPageUptodate(push_page);
1655 + unlock_page(push_page);
1656 + page_cache_release(push_page);
1657 + }
1658 + }
1659 +
1660 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1661 + || index < (i_size_read(inode) >>
1662 + sblk->block_log))
1663 + up(&msblk->read_page_mutex);
1664 + else
1665 + release_cached_fragment(msblk, fragment);
1666 +
1667 + return 0;
1668 +
1669 +skip_read:
1670 + pageaddr = kmap_atomic(page, KM_USER0);
1671 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1672 + kunmap_atomic(pageaddr, KM_USER0);
1673 + flush_dcache_page(page);
1674 + SetPageUptodate(page);
1675 + unlock_page(page);
1676 +
1677 + return 0;
1678 +}
1679 +
1680 +
1681 +static int squashfs_readpage4K(struct file *file, struct page *page)
1682 +{
1683 + struct inode *inode = page->mapping->host;
1684 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1685 + struct squashfs_super_block *sblk = &msblk->sblk;
1686 + unsigned char block_list[SIZE];
1687 + long long block;
1688 + unsigned int bsize, bytes = 0;
1689 + void *pageaddr;
1690 +
1691 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1692 + page->index,
1693 + SQUASHFS_I(inode)->start_block);
1694 +
1695 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1696 + PAGE_CACHE_SHIFT)) {
1697 + pageaddr = kmap_atomic(page, KM_USER0);
1698 + goto skip_read;
1699 + }
1700 +
1701 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1702 + || page->index < (i_size_read(inode) >>
1703 + sblk->block_log)) {
1704 + block = (msblk->read_blocklist)(inode, page->index, 1,
1705 + block_list, NULL, &bsize);
1706 +
1707 + down(&msblk->read_page_mutex);
1708 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1709 + bsize, NULL);
1710 + pageaddr = kmap_atomic(page, KM_USER0);
1711 + if (bytes)
1712 + memcpy(pageaddr, msblk->read_page, bytes);
1713 + else
1714 + ERROR("Unable to read page, block %llx, size %x\n",
1715 + block, bsize);
1716 + up(&msblk->read_page_mutex);
1717 + } else {
1718 + struct squashfs_fragment_cache *fragment =
1719 + get_cached_fragment(inode->i_sb,
1720 + SQUASHFS_I(inode)->
1721 + u.s1.fragment_start_block,
1722 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1723 + pageaddr = kmap_atomic(page, KM_USER0);
1724 + if (fragment) {
1725 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1726 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1727 + u.s1.fragment_offset, bytes);
1728 + release_cached_fragment(msblk, fragment);
1729 + } else
1730 + ERROR("Unable to read page, block %llx, size %x\n",
1731 + SQUASHFS_I(inode)->
1732 + u.s1.fragment_start_block, (int)
1733 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1734 + }
1735 +
1736 +skip_read:
1737 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1738 + kunmap_atomic(pageaddr, KM_USER0);
1739 + flush_dcache_page(page);
1740 + SetPageUptodate(page);
1741 + unlock_page(page);
1742 +
1743 + return 0;
1744 +}
1745 +
1746 +
1747 +static int get_dir_index_using_offset(struct super_block *s, long long
1748 + *next_block, unsigned int *next_offset,
1749 + long long index_start,
1750 + unsigned int index_offset, int i_count,
1751 + long long f_pos)
1752 +{
1753 + struct squashfs_sb_info *msblk = s->s_fs_info;
1754 + struct squashfs_super_block *sblk = &msblk->sblk;
1755 + int i, length = 0;
1756 + struct squashfs_dir_index index;
1757 +
1758 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1759 + i_count, (unsigned int) f_pos);
1760 +
1761 + f_pos =- 3;
1762 + if (f_pos == 0)
1763 + goto finish;
1764 +
1765 + for (i = 0; i < i_count; i++) {
1766 + if (msblk->swap) {
1767 + struct squashfs_dir_index sindex;
1768 + squashfs_get_cached_block(s, (char *) &sindex,
1769 + index_start, index_offset,
1770 + sizeof(sindex), &index_start,
1771 + &index_offset);
1772 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1773 + } else
1774 + squashfs_get_cached_block(s, (char *) &index,
1775 + index_start, index_offset,
1776 + sizeof(index), &index_start,
1777 + &index_offset);
1778 +
1779 + if (index.index > f_pos)
1780 + break;
1781 +
1782 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1783 + index.size + 1, &index_start,
1784 + &index_offset);
1785 +
1786 + length = index.index;
1787 + *next_block = index.start_block + sblk->directory_table_start;
1788 + }
1789 +
1790 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1791 +
1792 +finish:
1793 + return length + 3;
1794 +}
1795 +
1796 +
1797 +static int get_dir_index_using_name(struct super_block *s, long long
1798 + *next_block, unsigned int *next_offset,
1799 + long long index_start,
1800 + unsigned int index_offset, int i_count,
1801 + const char *name, int size)
1802 +{
1803 + struct squashfs_sb_info *msblk = s->s_fs_info;
1804 + struct squashfs_super_block *sblk = &msblk->sblk;
1805 + int i, length = 0;
1806 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1807 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1808 + char str[SQUASHFS_NAME_LEN + 1];
1809 +
1810 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1811 +
1812 + strncpy(str, name, size);
1813 + str[size] = '\0';
1814 +
1815 + for (i = 0; i < i_count; i++) {
1816 + if (msblk->swap) {
1817 + struct squashfs_dir_index sindex;
1818 + squashfs_get_cached_block(s, (char *) &sindex,
1819 + index_start, index_offset,
1820 + sizeof(sindex), &index_start,
1821 + &index_offset);
1822 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1823 + } else
1824 + squashfs_get_cached_block(s, (char *) index,
1825 + index_start, index_offset,
1826 + sizeof(struct squashfs_dir_index),
1827 + &index_start, &index_offset);
1828 +
1829 + squashfs_get_cached_block(s, index->name, index_start,
1830 + index_offset, index->size + 1,
1831 + &index_start, &index_offset);
1832 +
1833 + index->name[index->size + 1] = '\0';
1834 +
1835 + if (strcmp(index->name, str) > 0)
1836 + break;
1837 +
1838 + length = index->index;
1839 + *next_block = index->start_block + sblk->directory_table_start;
1840 + }
1841 +
1842 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1843 + return length + 3;
1844 +}
1845 +
1846 +
1847 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1848 +{
1849 + struct inode *i = file->f_dentry->d_inode;
1850 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1851 + struct squashfs_super_block *sblk = &msblk->sblk;
1852 + long long next_block = SQUASHFS_I(i)->start_block +
1853 + sblk->directory_table_start;
1854 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1855 + dir_count;
1856 + struct squashfs_dir_header dirh;
1857 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1858 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1859 +
1860 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1861 +
1862 + while(file->f_pos < 3) {
1863 + char *name;
1864 + int size, i_ino;
1865 +
1866 + if(file->f_pos == 0) {
1867 + name = ".";
1868 + size = 1;
1869 + i_ino = i->i_ino;
1870 + } else {
1871 + name = "..";
1872 + size = 2;
1873 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1874 + }
1875 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1876 + (unsigned int) dirent, name, size, (int)
1877 + file->f_pos, i_ino,
1878 + squashfs_filetype_table[1]);
1879 +
1880 + if (filldir(dirent, name, size,
1881 + file->f_pos, i_ino,
1882 + squashfs_filetype_table[1]) < 0) {
1883 + TRACE("Filldir returned less than 0\n");
1884 + goto finish;
1885 + }
1886 + file->f_pos += size;
1887 + dirs_read++;
1888 + }
1889 +
1890 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1891 + SQUASHFS_I(i)->u.s2.directory_index_start,
1892 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1893 + SQUASHFS_I(i)->u.s2.directory_index_count,
1894 + file->f_pos);
1895 +
1896 + while (length < i_size_read(i)) {
1897 + /* read directory header */
1898 + if (msblk->swap) {
1899 + struct squashfs_dir_header sdirh;
1900 +
1901 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1902 + next_block, next_offset, sizeof(sdirh),
1903 + &next_block, &next_offset))
1904 + goto failed_read;
1905 +
1906 + length += sizeof(sdirh);
1907 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1908 + } else {
1909 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1910 + next_block, next_offset, sizeof(dirh),
1911 + &next_block, &next_offset))
1912 + goto failed_read;
1913 +
1914 + length += sizeof(dirh);
1915 + }
1916 +
1917 + dir_count = dirh.count + 1;
1918 + while (dir_count--) {
1919 + if (msblk->swap) {
1920 + struct squashfs_dir_entry sdire;
1921 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1922 + &sdire, next_block, next_offset,
1923 + sizeof(sdire), &next_block,
1924 + &next_offset))
1925 + goto failed_read;
1926 +
1927 + length += sizeof(sdire);
1928 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1929 + } else {
1930 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1931 + dire, next_block, next_offset,
1932 + sizeof(*dire), &next_block,
1933 + &next_offset))
1934 + goto failed_read;
1935 +
1936 + length += sizeof(*dire);
1937 + }
1938 +
1939 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1940 + next_block, next_offset,
1941 + dire->size + 1, &next_block,
1942 + &next_offset))
1943 + goto failed_read;
1944 +
1945 + length += dire->size + 1;
1946 +
1947 + if (file->f_pos >= length)
1948 + continue;
1949 +
1950 + dire->name[dire->size + 1] = '\0';
1951 +
1952 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1953 + (unsigned int) dirent, dire->name,
1954 + dire->size + 1, (int) file->f_pos,
1955 + dirh.start_block, dire->offset,
1956 + dirh.inode_number + dire->inode_number,
1957 + squashfs_filetype_table[dire->type]);
1958 +
1959 + if (filldir(dirent, dire->name, dire->size + 1,
1960 + file->f_pos,
1961 + dirh.inode_number + dire->inode_number,
1962 + squashfs_filetype_table[dire->type])
1963 + < 0) {
1964 + TRACE("Filldir returned less than 0\n");
1965 + goto finish;
1966 + }
1967 + file->f_pos = length;
1968 + dirs_read++;
1969 + }
1970 + }
1971 +
1972 +finish:
1973 + return dirs_read;
1974 +
1975 +failed_read:
1976 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1977 + next_offset);
1978 + return 0;
1979 +}
1980 +
1981 +
1982 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
1983 + struct nameidata *nd)
1984 +{
1985 + const unsigned char *name = dentry->d_name.name;
1986 + int len = dentry->d_name.len;
1987 + struct inode *inode = NULL;
1988 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1989 + struct squashfs_super_block *sblk = &msblk->sblk;
1990 + long long next_block = SQUASHFS_I(i)->start_block +
1991 + sblk->directory_table_start;
1992 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1993 + dir_count;
1994 + struct squashfs_dir_header dirh;
1995 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1996 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1997 +
1998 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
1999 +
2000 + if (len > SQUASHFS_NAME_LEN)
2001 + goto exit_loop;
2002 +
2003 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2004 + SQUASHFS_I(i)->u.s2.directory_index_start,
2005 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2006 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2007 + len);
2008 +
2009 + while (length < i_size_read(i)) {
2010 + /* read directory header */
2011 + if (msblk->swap) {
2012 + struct squashfs_dir_header sdirh;
2013 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2014 + next_block, next_offset, sizeof(sdirh),
2015 + &next_block, &next_offset))
2016 + goto failed_read;
2017 +
2018 + length += sizeof(sdirh);
2019 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2020 + } else {
2021 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2022 + next_block, next_offset, sizeof(dirh),
2023 + &next_block, &next_offset))
2024 + goto failed_read;
2025 +
2026 + length += sizeof(dirh);
2027 + }
2028 +
2029 + dir_count = dirh.count + 1;
2030 + while (dir_count--) {
2031 + if (msblk->swap) {
2032 + struct squashfs_dir_entry sdire;
2033 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2034 + &sdire, next_block,next_offset,
2035 + sizeof(sdire), &next_block,
2036 + &next_offset))
2037 + goto failed_read;
2038 +
2039 + length += sizeof(sdire);
2040 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2041 + } else {
2042 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2043 + dire, next_block,next_offset,
2044 + sizeof(*dire), &next_block,
2045 + &next_offset))
2046 + goto failed_read;
2047 +
2048 + length += sizeof(*dire);
2049 + }
2050 +
2051 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2052 + next_block, next_offset, dire->size + 1,
2053 + &next_block, &next_offset))
2054 + goto failed_read;
2055 +
2056 + length += dire->size + 1;
2057 +
2058 + if (name[0] < dire->name[0])
2059 + goto exit_loop;
2060 +
2061 + if ((len == dire->size + 1) && !strncmp(name,
2062 + dire->name, len)) {
2063 + squashfs_inode_t ino =
2064 + SQUASHFS_MKINODE(dirh.start_block,
2065 + dire->offset);
2066 +
2067 + TRACE("calling squashfs_iget for directory "
2068 + "entry %s, inode %x:%x, %d\n", name,
2069 + dirh.start_block, dire->offset,
2070 + dirh.inode_number + dire->inode_number);
2071 +
2072 + inode = (msblk->iget)(i->i_sb, ino);
2073 +
2074 + goto exit_loop;
2075 + }
2076 + }
2077 + }
2078 +
2079 +exit_loop:
2080 + d_add(dentry, inode);
2081 + return ERR_PTR(0);
2082 +
2083 +failed_read:
2084 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2085 + next_offset);
2086 + goto exit_loop;
2087 +}
2088 +
2089 +
2090 +static void squashfs_put_super(struct super_block *s)
2091 +{
2092 + int i;
2093 +
2094 + if (s->s_fs_info) {
2095 + struct squashfs_sb_info *sbi = s->s_fs_info;
2096 + if (sbi->block_cache)
2097 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2098 + if (sbi->block_cache[i].block !=
2099 + SQUASHFS_INVALID_BLK)
2100 + kfree(sbi->block_cache[i].data);
2101 + if (sbi->fragment)
2102 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2103 + SQUASHFS_FREE(sbi->fragment[i].data);
2104 + kfree(sbi->fragment);
2105 + kfree(sbi->block_cache);
2106 + kfree(sbi->read_data);
2107 + kfree(sbi->read_page);
2108 + kfree(sbi->uid);
2109 + kfree(sbi->fragment_index);
2110 + kfree(sbi->fragment_index_2);
2111 + kfree(sbi->meta_index);
2112 + kfree(s->s_fs_info);
2113 + s->s_fs_info = NULL;
2114 + }
2115 +}
2116 +
2117 +
2118 +static int squashfs_get_sb(struct file_system_type *fs_type,
2119 + int flags, const char *dev_name, void *data,
2120 + struct vfsmount *mnt)
2121 +{
2122 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
2123 +}
2124 +
2125 +
2126 +static int __init init_squashfs_fs(void)
2127 +{
2128 + int err = init_inodecache();
2129 + if (err)
2130 + goto out;
2131 +
2132 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2133 + "Phillip Lougher\n");
2134 +
2135 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2136 + ERROR("Failed to allocate zlib workspace\n");
2137 + destroy_inodecache();
2138 + err = -ENOMEM;
2139 + goto out;
2140 + }
2141 +
2142 + if ((err = register_filesystem(&squashfs_fs_type))) {
2143 + vfree(stream.workspace);
2144 + destroy_inodecache();
2145 + }
2146 +
2147 +out:
2148 + return err;
2149 +}
2150 +
2151 +
2152 +static void __exit exit_squashfs_fs(void)
2153 +{
2154 + vfree(stream.workspace);
2155 + unregister_filesystem(&squashfs_fs_type);
2156 + destroy_inodecache();
2157 +}
2158 +
2159 +
2160 +static struct kmem_cache * squashfs_inode_cachep;
2161 +
2162 +
2163 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2164 +{
2165 + struct squashfs_inode_info *ei;
2166 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2167 + if (!ei)
2168 + return NULL;
2169 + return &ei->vfs_inode;
2170 +}
2171 +
2172 +
2173 +static void squashfs_destroy_inode(struct inode *inode)
2174 +{
2175 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2176 +}
2177 +
2178 +
2179 +static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
2180 +{
2181 + struct squashfs_inode_info *ei = foo;
2182 +
2183 + inode_init_once(&ei->vfs_inode);
2184 +}
2185 +
2186 +
2187 +static int __init init_inodecache(void)
2188 +{
2189 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2190 + sizeof(struct squashfs_inode_info),
2191 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2192 + init_once);
2193 + if (squashfs_inode_cachep == NULL)
2194 + return -ENOMEM;
2195 + return 0;
2196 +}
2197 +
2198 +
2199 +static void destroy_inodecache(void)
2200 +{
2201 + kmem_cache_destroy(squashfs_inode_cachep);
2202 +}
2203 +
2204 +
2205 +module_init(init_squashfs_fs);
2206 +module_exit(exit_squashfs_fs);
2207 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2208 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2209 +MODULE_LICENSE("GPL");
2210 --- /dev/null
2211 +++ b/fs/squashfs/Makefile
2212 @@ -0,0 +1,7 @@
2213 +#
2214 +# Makefile for the linux squashfs routines.
2215 +#
2216 +
2217 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2218 +squashfs-y += inode.o
2219 +squashfs-y += squashfs2_0.o
2220 --- /dev/null
2221 +++ b/fs/squashfs/squashfs2_0.c
2222 @@ -0,0 +1,758 @@
2223 +/*
2224 + * Squashfs - a compressed read only filesystem for Linux
2225 + *
2226 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2227 + * Phillip Lougher <phillip@lougher.org.uk>
2228 + *
2229 + * This program is free software; you can redistribute it and/or
2230 + * modify it under the terms of the GNU General Public License
2231 + * as published by the Free Software Foundation; either version 2,
2232 + * or (at your option) any later version.
2233 + *
2234 + * This program is distributed in the hope that it will be useful,
2235 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2236 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2237 + * GNU General Public License for more details.
2238 + *
2239 + * You should have received a copy of the GNU General Public License
2240 + * along with this program; if not, write to the Free Software
2241 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2242 + *
2243 + * squashfs2_0.c
2244 + */
2245 +
2246 +#include <linux/types.h>
2247 +#include <linux/squashfs_fs.h>
2248 +#include <linux/module.h>
2249 +#include <linux/errno.h>
2250 +#include <linux/slab.h>
2251 +#include <linux/fs.h>
2252 +#include <linux/smp_lock.h>
2253 +#include <linux/slab.h>
2254 +#include <linux/squashfs_fs_sb.h>
2255 +#include <linux/squashfs_fs_i.h>
2256 +#include <linux/buffer_head.h>
2257 +#include <linux/vfs.h>
2258 +#include <linux/init.h>
2259 +#include <linux/dcache.h>
2260 +#include <linux/wait.h>
2261 +#include <linux/zlib.h>
2262 +#include <linux/blkdev.h>
2263 +#include <linux/vmalloc.h>
2264 +#include <asm/uaccess.h>
2265 +#include <asm/semaphore.h>
2266 +
2267 +#include "squashfs.h"
2268 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2269 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2270 + struct nameidata *);
2271 +
2272 +static struct file_operations squashfs_dir_ops_2 = {
2273 + .read = generic_read_dir,
2274 + .readdir = squashfs_readdir_2
2275 +};
2276 +
2277 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2278 + .lookup = squashfs_lookup_2
2279 +};
2280 +
2281 +static unsigned char squashfs_filetype_table[] = {
2282 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2283 +};
2284 +
2285 +static int read_fragment_index_table_2(struct super_block *s)
2286 +{
2287 + struct squashfs_sb_info *msblk = s->s_fs_info;
2288 + struct squashfs_super_block *sblk = &msblk->sblk;
2289 +
2290 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2291 + (sblk->fragments), GFP_KERNEL))) {
2292 + ERROR("Failed to allocate uid/gid table\n");
2293 + return 0;
2294 + }
2295 +
2296 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2297 + !squashfs_read_data(s, (char *)
2298 + msblk->fragment_index_2,
2299 + sblk->fragment_table_start,
2300 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2301 + (sblk->fragments) |
2302 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2303 + ERROR("unable to read fragment index table\n");
2304 + return 0;
2305 + }
2306 +
2307 + if (msblk->swap) {
2308 + int i;
2309 + unsigned int fragment;
2310 +
2311 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2312 + i++) {
2313 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2314 + &msblk->fragment_index_2[i], 1);
2315 + msblk->fragment_index_2[i] = fragment;
2316 + }
2317 + }
2318 +
2319 + return 1;
2320 +}
2321 +
2322 +
2323 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2324 + long long *fragment_start_block,
2325 + unsigned int *fragment_size)
2326 +{
2327 + struct squashfs_sb_info *msblk = s->s_fs_info;
2328 + long long start_block =
2329 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2330 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2331 + struct squashfs_fragment_entry_2 fragment_entry;
2332 +
2333 + if (msblk->swap) {
2334 + struct squashfs_fragment_entry_2 sfragment_entry;
2335 +
2336 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2337 + start_block, offset,
2338 + sizeof(sfragment_entry), &start_block,
2339 + &offset))
2340 + goto out;
2341 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2342 + } else
2343 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2344 + start_block, offset,
2345 + sizeof(fragment_entry), &start_block,
2346 + &offset))
2347 + goto out;
2348 +
2349 + *fragment_start_block = fragment_entry.start_block;
2350 + *fragment_size = fragment_entry.size;
2351 +
2352 + return 1;
2353 +
2354 +out:
2355 + return 0;
2356 +}
2357 +
2358 +
2359 +static struct inode *squashfs_new_inode(struct super_block *s,
2360 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2361 +{
2362 + struct squashfs_sb_info *msblk = s->s_fs_info;
2363 + struct squashfs_super_block *sblk = &msblk->sblk;
2364 + struct inode *i = new_inode(s);
2365 +
2366 + if (i) {
2367 + i->i_ino = ino;
2368 + i->i_mtime.tv_sec = sblk->mkfs_time;
2369 + i->i_atime.tv_sec = sblk->mkfs_time;
2370 + i->i_ctime.tv_sec = sblk->mkfs_time;
2371 + i->i_uid = msblk->uid[inodeb->uid];
2372 + i->i_mode = inodeb->mode;
2373 + i->i_nlink = 1;
2374 + i->i_size = 0;
2375 + if (inodeb->guid == SQUASHFS_GUIDS)
2376 + i->i_gid = i->i_uid;
2377 + else
2378 + i->i_gid = msblk->guid[inodeb->guid];
2379 + }
2380 +
2381 + return i;
2382 +}
2383 +
2384 +
2385 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2386 +{
2387 + struct inode *i;
2388 + struct squashfs_sb_info *msblk = s->s_fs_info;
2389 + struct squashfs_super_block *sblk = &msblk->sblk;
2390 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2391 + sblk->inode_table_start;
2392 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2393 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2394 + - sblk->inode_table_start, offset);
2395 + long long next_block;
2396 + unsigned int next_offset;
2397 + union squashfs_inode_header_2 id, sid;
2398 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2399 + *sinodeb = &sid.base;
2400 +
2401 + TRACE("Entered squashfs_iget\n");
2402 +
2403 + if (msblk->swap) {
2404 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2405 + offset, sizeof(*sinodeb), &next_block,
2406 + &next_offset))
2407 + goto failed_read;
2408 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2409 + sizeof(*sinodeb));
2410 + } else
2411 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2412 + offset, sizeof(*inodeb), &next_block,
2413 + &next_offset))
2414 + goto failed_read;
2415 +
2416 + switch(inodeb->inode_type) {
2417 + case SQUASHFS_FILE_TYPE: {
2418 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2419 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2420 + long long frag_blk;
2421 + unsigned int frag_size;
2422 +
2423 + if (msblk->swap) {
2424 + if (!squashfs_get_cached_block(s, (char *)
2425 + sinodep, block, offset,
2426 + sizeof(*sinodep), &next_block,
2427 + &next_offset))
2428 + goto failed_read;
2429 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2430 + } else
2431 + if (!squashfs_get_cached_block(s, (char *)
2432 + inodep, block, offset,
2433 + sizeof(*inodep), &next_block,
2434 + &next_offset))
2435 + goto failed_read;
2436 +
2437 + frag_blk = SQUASHFS_INVALID_BLK;
2438 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2439 + !get_fragment_location_2(s,
2440 + inodep->fragment, &frag_blk, &frag_size))
2441 + goto failed_read;
2442 +
2443 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2444 + goto failed_read1;
2445 +
2446 + i->i_size = inodep->file_size;
2447 + i->i_fop = &generic_ro_fops;
2448 + i->i_mode |= S_IFREG;
2449 + i->i_mtime.tv_sec = inodep->mtime;
2450 + i->i_atime.tv_sec = inodep->mtime;
2451 + i->i_ctime.tv_sec = inodep->mtime;
2452 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2453 + i->i_blksize = PAGE_CACHE_SIZE;
2454 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2455 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2456 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2457 + SQUASHFS_I(i)->start_block = inodep->start_block;
2458 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2459 + SQUASHFS_I(i)->offset = next_offset;
2460 + if (sblk->block_size > 4096)
2461 + i->i_data.a_ops = &squashfs_aops;
2462 + else
2463 + i->i_data.a_ops = &squashfs_aops_4K;
2464 +
2465 + TRACE("File inode %x:%x, start_block %x, "
2466 + "block_list_start %llx, offset %x\n",
2467 + SQUASHFS_INODE_BLK(inode), offset,
2468 + inodep->start_block, next_block,
2469 + next_offset);
2470 + break;
2471 + }
2472 + case SQUASHFS_DIR_TYPE: {
2473 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2474 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2475 +
2476 + if (msblk->swap) {
2477 + if (!squashfs_get_cached_block(s, (char *)
2478 + sinodep, block, offset,
2479 + sizeof(*sinodep), &next_block,
2480 + &next_offset))
2481 + goto failed_read;
2482 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2483 + } else
2484 + if (!squashfs_get_cached_block(s, (char *)
2485 + inodep, block, offset,
2486 + sizeof(*inodep), &next_block,
2487 + &next_offset))
2488 + goto failed_read;
2489 +
2490 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2491 + goto failed_read1;
2492 +
2493 + i->i_size = inodep->file_size;
2494 + i->i_op = &squashfs_dir_inode_ops_2;
2495 + i->i_fop = &squashfs_dir_ops_2;
2496 + i->i_mode |= S_IFDIR;
2497 + i->i_mtime.tv_sec = inodep->mtime;
2498 + i->i_atime.tv_sec = inodep->mtime;
2499 + i->i_ctime.tv_sec = inodep->mtime;
2500 + SQUASHFS_I(i)->start_block = inodep->start_block;
2501 + SQUASHFS_I(i)->offset = inodep->offset;
2502 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2503 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2504 +
2505 + TRACE("Directory inode %x:%x, start_block %x, offset "
2506 + "%x\n", SQUASHFS_INODE_BLK(inode),
2507 + offset, inodep->start_block,
2508 + inodep->offset);
2509 + break;
2510 + }
2511 + case SQUASHFS_LDIR_TYPE: {
2512 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2513 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2514 +
2515 + if (msblk->swap) {
2516 + if (!squashfs_get_cached_block(s, (char *)
2517 + sinodep, block, offset,
2518 + sizeof(*sinodep), &next_block,
2519 + &next_offset))
2520 + goto failed_read;
2521 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2522 + sinodep);
2523 + } else
2524 + if (!squashfs_get_cached_block(s, (char *)
2525 + inodep, block, offset,
2526 + sizeof(*inodep), &next_block,
2527 + &next_offset))
2528 + goto failed_read;
2529 +
2530 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2531 + goto failed_read1;
2532 +
2533 + i->i_size = inodep->file_size;
2534 + i->i_op = &squashfs_dir_inode_ops_2;
2535 + i->i_fop = &squashfs_dir_ops_2;
2536 + i->i_mode |= S_IFDIR;
2537 + i->i_mtime.tv_sec = inodep->mtime;
2538 + i->i_atime.tv_sec = inodep->mtime;
2539 + i->i_ctime.tv_sec = inodep->mtime;
2540 + SQUASHFS_I(i)->start_block = inodep->start_block;
2541 + SQUASHFS_I(i)->offset = inodep->offset;
2542 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2543 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2544 + next_offset;
2545 + SQUASHFS_I(i)->u.s2.directory_index_count =
2546 + inodep->i_count;
2547 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2548 +
2549 + TRACE("Long directory inode %x:%x, start_block %x, "
2550 + "offset %x\n",
2551 + SQUASHFS_INODE_BLK(inode), offset,
2552 + inodep->start_block, inodep->offset);
2553 + break;
2554 + }
2555 + case SQUASHFS_SYMLINK_TYPE: {
2556 + struct squashfs_symlink_inode_header_2 *inodep =
2557 + &id.symlink;
2558 + struct squashfs_symlink_inode_header_2 *sinodep =
2559 + &sid.symlink;
2560 +
2561 + if (msblk->swap) {
2562 + if (!squashfs_get_cached_block(s, (char *)
2563 + sinodep, block, offset,
2564 + sizeof(*sinodep), &next_block,
2565 + &next_offset))
2566 + goto failed_read;
2567 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2568 + sinodep);
2569 + } else
2570 + if (!squashfs_get_cached_block(s, (char *)
2571 + inodep, block, offset,
2572 + sizeof(*inodep), &next_block,
2573 + &next_offset))
2574 + goto failed_read;
2575 +
2576 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2577 + goto failed_read1;
2578 +
2579 + i->i_size = inodep->symlink_size;
2580 + i->i_op = &page_symlink_inode_operations;
2581 + i->i_data.a_ops = &squashfs_symlink_aops;
2582 + i->i_mode |= S_IFLNK;
2583 + SQUASHFS_I(i)->start_block = next_block;
2584 + SQUASHFS_I(i)->offset = next_offset;
2585 +
2586 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2587 + "offset %x\n",
2588 + SQUASHFS_INODE_BLK(inode), offset,
2589 + next_block, next_offset);
2590 + break;
2591 + }
2592 + case SQUASHFS_BLKDEV_TYPE:
2593 + case SQUASHFS_CHRDEV_TYPE: {
2594 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2595 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2596 +
2597 + if (msblk->swap) {
2598 + if (!squashfs_get_cached_block(s, (char *)
2599 + sinodep, block, offset,
2600 + sizeof(*sinodep), &next_block,
2601 + &next_offset))
2602 + goto failed_read;
2603 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2604 + } else
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + inodep, block, offset,
2607 + sizeof(*inodep), &next_block,
2608 + &next_offset))
2609 + goto failed_read;
2610 +
2611 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2612 + goto failed_read1;
2613 +
2614 + i->i_mode |= (inodeb->inode_type ==
2615 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2616 + S_IFBLK;
2617 + init_special_inode(i, i->i_mode,
2618 + old_decode_dev(inodep->rdev));
2619 +
2620 + TRACE("Device inode %x:%x, rdev %x\n",
2621 + SQUASHFS_INODE_BLK(inode), offset,
2622 + inodep->rdev);
2623 + break;
2624 + }
2625 + case SQUASHFS_FIFO_TYPE:
2626 + case SQUASHFS_SOCKET_TYPE: {
2627 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2628 + goto failed_read1;
2629 +
2630 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2631 + ? S_IFIFO : S_IFSOCK;
2632 + init_special_inode(i, i->i_mode, 0);
2633 + break;
2634 + }
2635 + default:
2636 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2637 + inodeb->inode_type);
2638 + goto failed_read1;
2639 + }
2640 +
2641 + insert_inode_hash(i);
2642 + return i;
2643 +
2644 +failed_read:
2645 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2646 +
2647 +failed_read1:
2648 + return NULL;
2649 +}
2650 +
2651 +
2652 +static int get_dir_index_using_offset(struct super_block *s, long long
2653 + *next_block, unsigned int *next_offset,
2654 + long long index_start,
2655 + unsigned int index_offset, int i_count,
2656 + long long f_pos)
2657 +{
2658 + struct squashfs_sb_info *msblk = s->s_fs_info;
2659 + struct squashfs_super_block *sblk = &msblk->sblk;
2660 + int i, length = 0;
2661 + struct squashfs_dir_index_2 index;
2662 +
2663 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2664 + i_count, (unsigned int) f_pos);
2665 +
2666 + if (f_pos == 0)
2667 + goto finish;
2668 +
2669 + for (i = 0; i < i_count; i++) {
2670 + if (msblk->swap) {
2671 + struct squashfs_dir_index_2 sindex;
2672 + squashfs_get_cached_block(s, (char *) &sindex,
2673 + index_start, index_offset,
2674 + sizeof(sindex), &index_start,
2675 + &index_offset);
2676 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2677 + } else
2678 + squashfs_get_cached_block(s, (char *) &index,
2679 + index_start, index_offset,
2680 + sizeof(index), &index_start,
2681 + &index_offset);
2682 +
2683 + if (index.index > f_pos)
2684 + break;
2685 +
2686 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2687 + index.size + 1, &index_start,
2688 + &index_offset);
2689 +
2690 + length = index.index;
2691 + *next_block = index.start_block + sblk->directory_table_start;
2692 + }
2693 +
2694 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2695 +
2696 +finish:
2697 + return length;
2698 +}
2699 +
2700 +
2701 +static int get_dir_index_using_name(struct super_block *s, long long
2702 + *next_block, unsigned int *next_offset,
2703 + long long index_start,
2704 + unsigned int index_offset, int i_count,
2705 + const char *name, int size)
2706 +{
2707 + struct squashfs_sb_info *msblk = s->s_fs_info;
2708 + struct squashfs_super_block *sblk = &msblk->sblk;
2709 + int i, length = 0;
2710 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2711 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2712 + char str[SQUASHFS_NAME_LEN + 1];
2713 +
2714 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2715 +
2716 + strncpy(str, name, size);
2717 + str[size] = '\0';
2718 +
2719 + for (i = 0; i < i_count; i++) {
2720 + if (msblk->swap) {
2721 + struct squashfs_dir_index_2 sindex;
2722 + squashfs_get_cached_block(s, (char *) &sindex,
2723 + index_start, index_offset,
2724 + sizeof(sindex), &index_start,
2725 + &index_offset);
2726 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2727 + } else
2728 + squashfs_get_cached_block(s, (char *) index,
2729 + index_start, index_offset,
2730 + sizeof(struct squashfs_dir_index_2),
2731 + &index_start, &index_offset);
2732 +
2733 + squashfs_get_cached_block(s, index->name, index_start,
2734 + index_offset, index->size + 1,
2735 + &index_start, &index_offset);
2736 +
2737 + index->name[index->size + 1] = '\0';
2738 +
2739 + if (strcmp(index->name, str) > 0)
2740 + break;
2741 +
2742 + length = index->index;
2743 + *next_block = index->start_block + sblk->directory_table_start;
2744 + }
2745 +
2746 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2747 + return length;
2748 +}
2749 +
2750 +
2751 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2752 +{
2753 + struct inode *i = file->f_dentry->d_inode;
2754 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2755 + struct squashfs_super_block *sblk = &msblk->sblk;
2756 + long long next_block = SQUASHFS_I(i)->start_block +
2757 + sblk->directory_table_start;
2758 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2759 + dir_count;
2760 + struct squashfs_dir_header_2 dirh;
2761 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2762 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2763 +
2764 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2765 +
2766 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2767 + SQUASHFS_I(i)->u.s2.directory_index_start,
2768 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2769 + SQUASHFS_I(i)->u.s2.directory_index_count,
2770 + file->f_pos);
2771 +
2772 + while (length < i_size_read(i)) {
2773 + /* read directory header */
2774 + if (msblk->swap) {
2775 + struct squashfs_dir_header_2 sdirh;
2776 +
2777 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2778 + next_block, next_offset, sizeof(sdirh),
2779 + &next_block, &next_offset))
2780 + goto failed_read;
2781 +
2782 + length += sizeof(sdirh);
2783 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2784 + } else {
2785 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2786 + next_block, next_offset, sizeof(dirh),
2787 + &next_block, &next_offset))
2788 + goto failed_read;
2789 +
2790 + length += sizeof(dirh);
2791 + }
2792 +
2793 + dir_count = dirh.count + 1;
2794 + while (dir_count--) {
2795 + if (msblk->swap) {
2796 + struct squashfs_dir_entry_2 sdire;
2797 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2798 + &sdire, next_block, next_offset,
2799 + sizeof(sdire), &next_block,
2800 + &next_offset))
2801 + goto failed_read;
2802 +
2803 + length += sizeof(sdire);
2804 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2805 + } else {
2806 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2807 + dire, next_block, next_offset,
2808 + sizeof(*dire), &next_block,
2809 + &next_offset))
2810 + goto failed_read;
2811 +
2812 + length += sizeof(*dire);
2813 + }
2814 +
2815 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2816 + next_block, next_offset,
2817 + dire->size + 1, &next_block,
2818 + &next_offset))
2819 + goto failed_read;
2820 +
2821 + length += dire->size + 1;
2822 +
2823 + if (file->f_pos >= length)
2824 + continue;
2825 +
2826 + dire->name[dire->size + 1] = '\0';
2827 +
2828 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2829 + (unsigned int) dirent, dire->name,
2830 + dire->size + 1, (int) file->f_pos,
2831 + dirh.start_block, dire->offset,
2832 + squashfs_filetype_table[dire->type]);
2833 +
2834 + if (filldir(dirent, dire->name, dire->size + 1,
2835 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2836 + dirh.start_block, dire->offset),
2837 + squashfs_filetype_table[dire->type])
2838 + < 0) {
2839 + TRACE("Filldir returned less than 0\n");
2840 + goto finish;
2841 + }
2842 + file->f_pos = length;
2843 + dirs_read++;
2844 + }
2845 + }
2846 +
2847 +finish:
2848 + return dirs_read;
2849 +
2850 +failed_read:
2851 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2852 + next_offset);
2853 + return 0;
2854 +}
2855 +
2856 +
2857 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2858 + struct nameidata *nd)
2859 +{
2860 + const unsigned char *name = dentry->d_name.name;
2861 + int len = dentry->d_name.len;
2862 + struct inode *inode = NULL;
2863 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2864 + struct squashfs_super_block *sblk = &msblk->sblk;
2865 + long long next_block = SQUASHFS_I(i)->start_block +
2866 + sblk->directory_table_start;
2867 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2868 + dir_count;
2869 + struct squashfs_dir_header_2 dirh;
2870 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2871 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2872 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2873 +
2874 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2875 +
2876 + if (len > SQUASHFS_NAME_LEN)
2877 + goto exit_loop;
2878 +
2879 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2880 + SQUASHFS_I(i)->u.s2.directory_index_start,
2881 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2882 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2883 + len);
2884 +
2885 + while (length < i_size_read(i)) {
2886 + /* read directory header */
2887 + if (msblk->swap) {
2888 + struct squashfs_dir_header_2 sdirh;
2889 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2890 + next_block, next_offset, sizeof(sdirh),
2891 + &next_block, &next_offset))
2892 + goto failed_read;
2893 +
2894 + length += sizeof(sdirh);
2895 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2896 + } else {
2897 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2898 + next_block, next_offset, sizeof(dirh),
2899 + &next_block, &next_offset))
2900 + goto failed_read;
2901 +
2902 + length += sizeof(dirh);
2903 + }
2904 +
2905 + dir_count = dirh.count + 1;
2906 + while (dir_count--) {
2907 + if (msblk->swap) {
2908 + struct squashfs_dir_entry_2 sdire;
2909 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2910 + &sdire, next_block,next_offset,
2911 + sizeof(sdire), &next_block,
2912 + &next_offset))
2913 + goto failed_read;
2914 +
2915 + length += sizeof(sdire);
2916 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2917 + } else {
2918 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2919 + dire, next_block,next_offset,
2920 + sizeof(*dire), &next_block,
2921 + &next_offset))
2922 + goto failed_read;
2923 +
2924 + length += sizeof(*dire);
2925 + }
2926 +
2927 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2928 + next_block, next_offset, dire->size + 1,
2929 + &next_block, &next_offset))
2930 + goto failed_read;
2931 +
2932 + length += dire->size + 1;
2933 +
2934 + if (sorted && name[0] < dire->name[0])
2935 + goto exit_loop;
2936 +
2937 + if ((len == dire->size + 1) && !strncmp(name,
2938 + dire->name, len)) {
2939 + squashfs_inode_t ino =
2940 + SQUASHFS_MKINODE(dirh.start_block,
2941 + dire->offset);
2942 +
2943 + TRACE("calling squashfs_iget for directory "
2944 + "entry %s, inode %x:%x, %lld\n", name,
2945 + dirh.start_block, dire->offset, ino);
2946 +
2947 + inode = (msblk->iget)(i->i_sb, ino);
2948 +
2949 + goto exit_loop;
2950 + }
2951 + }
2952 + }
2953 +
2954 +exit_loop:
2955 + d_add(dentry, inode);
2956 + return ERR_PTR(0);
2957 +
2958 +failed_read:
2959 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2960 + next_offset);
2961 + goto exit_loop;
2962 +}
2963 +
2964 +
2965 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2966 +{
2967 + struct squashfs_super_block *sblk = &msblk->sblk;
2968 +
2969 + msblk->iget = squashfs_iget_2;
2970 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2971 +
2972 + sblk->bytes_used = sblk->bytes_used_2;
2973 + sblk->uid_start = sblk->uid_start_2;
2974 + sblk->guid_start = sblk->guid_start_2;
2975 + sblk->inode_table_start = sblk->inode_table_start_2;
2976 + sblk->directory_table_start = sblk->directory_table_start_2;
2977 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2978 +
2979 + return 1;
2980 +}
2981 --- /dev/null
2982 +++ b/fs/squashfs/squashfs.h
2983 @@ -0,0 +1,86 @@
2984 +/*
2985 + * Squashfs - a compressed read only filesystem for Linux
2986 + *
2987 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2988 + * Phillip Lougher <phillip@lougher.org.uk>
2989 + *
2990 + * This program is free software; you can redistribute it and/or
2991 + * modify it under the terms of the GNU General Public License
2992 + * as published by the Free Software Foundation; either version 2,
2993 + * or (at your option) any later version.
2994 + *
2995 + * This program is distributed in the hope that it will be useful,
2996 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2997 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2998 + * GNU General Public License for more details.
2999 + *
3000 + * You should have received a copy of the GNU General Public License
3001 + * along with this program; if not, write to the Free Software
3002 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3003 + *
3004 + * squashfs.h
3005 + */
3006 +
3007 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3008 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3009 +#endif
3010 +
3011 +#ifdef SQUASHFS_TRACE
3012 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3013 +#else
3014 +#define TRACE(s, args...) {}
3015 +#endif
3016 +
3017 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3018 +
3019 +#define SERROR(s, args...) do { \
3020 + if (!silent) \
3021 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3022 + } while(0)
3023 +
3024 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3025 +
3026 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3027 +{
3028 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3029 +}
3030 +
3031 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3032 +#define SQSH_EXTERN
3033 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3034 + long long index, unsigned int length,
3035 + long long *next_index);
3036 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3037 + long long block, unsigned int offset,
3038 + int length, long long *next_block,
3039 + unsigned int *next_offset);
3040 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3041 + squashfs_fragment_cache *fragment);
3042 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3043 + *s, long long start_block,
3044 + int length);
3045 +extern struct address_space_operations squashfs_symlink_aops;
3046 +extern struct address_space_operations squashfs_aops;
3047 +extern struct address_space_operations squashfs_aops_4K;
3048 +extern struct inode_operations squashfs_dir_inode_ops;
3049 +#else
3050 +#define SQSH_EXTERN static
3051 +#endif
3052 +
3053 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3054 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3055 +#else
3056 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3057 +{
3058 + return 0;
3059 +}
3060 +#endif
3061 +
3062 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3063 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3064 +#else
3065 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3066 +{
3067 + return 0;
3068 +}
3069 +#endif
3070 --- a/include/linux/magic.h
3071 +++ b/include/linux/magic.h
3072 @@ -35,6 +35,9 @@
3073 #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
3074 #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
3075
3076 +#define SQUASHFS_MAGIC 0x73717368
3077 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3078 +
3079 #define SMB_SUPER_MAGIC 0x517B
3080 #define USBDEVICE_SUPER_MAGIC 0x9fa2
3081 #define CGROUP_SUPER_MAGIC 0x27e0eb
3082 --- /dev/null
3083 +++ b/include/linux/squashfs_fs.h
3084 @@ -0,0 +1,911 @@
3085 +#ifndef SQUASHFS_FS
3086 +#define SQUASHFS_FS
3087 +
3088 +/*
3089 + * Squashfs
3090 + *
3091 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3092 + * Phillip Lougher <phillip@lougher.org.uk>
3093 + *
3094 + * This program is free software; you can redistribute it and/or
3095 + * modify it under the terms of the GNU General Public License
3096 + * as published by the Free Software Foundation; either version 2,
3097 + * or (at your option) any later version.
3098 + *
3099 + * This program is distributed in the hope that it will be useful,
3100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3102 + * GNU General Public License for more details.
3103 + *
3104 + * You should have received a copy of the GNU General Public License
3105 + * along with this program; if not, write to the Free Software
3106 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3107 + *
3108 + * squashfs_fs.h
3109 + */
3110 +
3111 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3112 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3113 +#endif
3114 +
3115 +#ifdef CONFIG_SQUASHFS_VMALLOC
3116 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3117 +#define SQUASHFS_FREE(a) vfree(a)
3118 +#else
3119 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3120 +#define SQUASHFS_FREE(a) kfree(a)
3121 +#endif
3122 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3123 +#define SQUASHFS_MAJOR 3
3124 +#define SQUASHFS_MINOR 0
3125 +#define SQUASHFS_START 0
3126 +
3127 +/* size of metadata (inode and directory) blocks */
3128 +#define SQUASHFS_METADATA_SIZE 8192
3129 +#define SQUASHFS_METADATA_LOG 13
3130 +
3131 +/* default size of data blocks */
3132 +#define SQUASHFS_FILE_SIZE 65536
3133 +#define SQUASHFS_FILE_LOG 16
3134 +
3135 +#define SQUASHFS_FILE_MAX_SIZE 65536
3136 +
3137 +/* Max number of uids and gids */
3138 +#define SQUASHFS_UIDS 256
3139 +#define SQUASHFS_GUIDS 255
3140 +
3141 +/* Max length of filename (not 255) */
3142 +#define SQUASHFS_NAME_LEN 256
3143 +
3144 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3145 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3146 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3147 +#define SQUASHFS_USED_BLK ((long long) -2)
3148 +
3149 +/* Filesystem flags */
3150 +#define SQUASHFS_NOI 0
3151 +#define SQUASHFS_NOD 1
3152 +#define SQUASHFS_CHECK 2
3153 +#define SQUASHFS_NOF 3
3154 +#define SQUASHFS_NO_FRAG 4
3155 +#define SQUASHFS_ALWAYS_FRAG 5
3156 +#define SQUASHFS_DUPLICATE 6
3157 +
3158 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3159 +
3160 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3161 + SQUASHFS_NOI)
3162 +
3163 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3164 + SQUASHFS_NOD)
3165 +
3166 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3167 + SQUASHFS_NOF)
3168 +
3169 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3170 + SQUASHFS_NO_FRAG)
3171 +
3172 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3173 + SQUASHFS_ALWAYS_FRAG)
3174 +
3175 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3176 + SQUASHFS_DUPLICATE)
3177 +
3178 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3179 + SQUASHFS_CHECK)
3180 +
3181 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3182 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3183 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3184 + (duplicate_checking << 6))
3185 +
3186 +/* Max number of types and file types */
3187 +#define SQUASHFS_DIR_TYPE 1
3188 +#define SQUASHFS_FILE_TYPE 2
3189 +#define SQUASHFS_SYMLINK_TYPE 3
3190 +#define SQUASHFS_BLKDEV_TYPE 4
3191 +#define SQUASHFS_CHRDEV_TYPE 5
3192 +#define SQUASHFS_FIFO_TYPE 6
3193 +#define SQUASHFS_SOCKET_TYPE 7
3194 +#define SQUASHFS_LDIR_TYPE 8
3195 +#define SQUASHFS_LREG_TYPE 9
3196 +
3197 +/* 1.0 filesystem type definitions */
3198 +#define SQUASHFS_TYPES 5
3199 +#define SQUASHFS_IPC_TYPE 0
3200 +
3201 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3202 + * uncompressed */
3203 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3204 +
3205 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3206 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3207 +
3208 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3209 +
3210 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3211 +
3212 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3213 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3214 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3215 +
3216 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3217 +
3218 +/*
3219 + * Inode number ops. Inodes consist of a compressed block number, and an
3220 + * uncompressed offset within that block
3221 + */
3222 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3223 +
3224 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3225 +
3226 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3227 + << 16) + (B)))
3228 +
3229 +/* Compute 32 bit VFS inode number from squashfs inode number */
3230 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3231 + ((b) >> 2) + 1))
3232 +/* XXX */
3233 +
3234 +/* Translate between VFS mode and squashfs mode */
3235 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3236 +
3237 +/* fragment and fragment table defines */
3238 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3239 +
3240 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3241 + SQUASHFS_METADATA_SIZE)
3242 +
3243 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3244 + SQUASHFS_METADATA_SIZE)
3245 +
3246 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3247 + SQUASHFS_METADATA_SIZE - 1) / \
3248 + SQUASHFS_METADATA_SIZE)
3249 +
3250 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3251 + sizeof(long long))
3252 +
3253 +/* cached data constants for filesystem */
3254 +#define SQUASHFS_CACHED_BLKS 8
3255 +
3256 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3257 +
3258 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3259 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3260 +
3261 +#define SQUASHFS_MARKER_BYTE 0xff
3262 +
3263 +/* meta index cache */
3264 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3265 +#define SQUASHFS_META_ENTRIES 31
3266 +#define SQUASHFS_META_NUMBER 8
3267 +#define SQUASHFS_SLOTS 4
3268 +
3269 +#include <linux/magic.h>
3270 +
3271 +struct meta_entry {
3272 + long long data_block;
3273 + unsigned int index_block;
3274 + unsigned short offset;
3275 + unsigned short pad;
3276 +};
3277 +
3278 +struct meta_index {
3279 + unsigned int inode_number;
3280 + unsigned int offset;
3281 + unsigned short entries;
3282 + unsigned short skip;
3283 + unsigned short locked;
3284 + unsigned short pad;
3285 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3286 +};
3287 +
3288 +
3289 +/*
3290 + * definitions for structures on disk
3291 + */
3292 +
3293 +typedef long long squashfs_block_t;
3294 +typedef long long squashfs_inode_t;
3295 +
3296 +struct squashfs_super_block {
3297 + unsigned int s_magic;
3298 + unsigned int inodes;
3299 + unsigned int bytes_used_2;
3300 + unsigned int uid_start_2;
3301 + unsigned int guid_start_2;
3302 + unsigned int inode_table_start_2;
3303 + unsigned int directory_table_start_2;
3304 + unsigned int s_major:16;
3305 + unsigned int s_minor:16;
3306 + unsigned int block_size_1:16;
3307 + unsigned int block_log:16;
3308 + unsigned int flags:8;
3309 + unsigned int no_uids:8;
3310 + unsigned int no_guids:8;
3311 + unsigned int mkfs_time /* time of filesystem creation */;
3312 + squashfs_inode_t root_inode;
3313 + unsigned int block_size;
3314 + unsigned int fragments;
3315 + unsigned int fragment_table_start_2;
3316 + long long bytes_used;
3317 + long long uid_start;
3318 + long long guid_start;
3319 + long long inode_table_start;
3320 + long long directory_table_start;
3321 + long long fragment_table_start;
3322 + long long unused;
3323 +} __attribute__ ((packed));
3324 +
3325 +struct squashfs_dir_index {
3326 + unsigned int index;
3327 + unsigned int start_block;
3328 + unsigned char size;
3329 + unsigned char name[0];
3330 +} __attribute__ ((packed));
3331 +
3332 +#define SQUASHFS_BASE_INODE_HEADER \
3333 + unsigned int inode_type:4; \
3334 + unsigned int mode:12; \
3335 + unsigned int uid:8; \
3336 + unsigned int guid:8; \
3337 + unsigned int mtime; \
3338 + unsigned int inode_number;
3339 +
3340 +struct squashfs_base_inode_header {
3341 + SQUASHFS_BASE_INODE_HEADER;
3342 +} __attribute__ ((packed));
3343 +
3344 +struct squashfs_ipc_inode_header {
3345 + SQUASHFS_BASE_INODE_HEADER;
3346 + unsigned int nlink;
3347 +} __attribute__ ((packed));
3348 +
3349 +struct squashfs_dev_inode_header {
3350 + SQUASHFS_BASE_INODE_HEADER;
3351 + unsigned int nlink;
3352 + unsigned short rdev;
3353 +} __attribute__ ((packed));
3354 +
3355 +struct squashfs_symlink_inode_header {
3356 + SQUASHFS_BASE_INODE_HEADER;
3357 + unsigned int nlink;
3358 + unsigned short symlink_size;
3359 + char symlink[0];
3360 +} __attribute__ ((packed));
3361 +
3362 +struct squashfs_reg_inode_header {
3363 + SQUASHFS_BASE_INODE_HEADER;
3364 + squashfs_block_t start_block;
3365 + unsigned int fragment;
3366 + unsigned int offset;
3367 + unsigned int file_size;
3368 + unsigned short block_list[0];
3369 +} __attribute__ ((packed));
3370 +
3371 +struct squashfs_lreg_inode_header {
3372 + SQUASHFS_BASE_INODE_HEADER;
3373 + unsigned int nlink;
3374 + squashfs_block_t start_block;
3375 + unsigned int fragment;
3376 + unsigned int offset;
3377 + long long file_size;
3378 + unsigned short block_list[0];
3379 +} __attribute__ ((packed));
3380 +
3381 +struct squashfs_dir_inode_header {
3382 + SQUASHFS_BASE_INODE_HEADER;
3383 + unsigned int nlink;
3384 + unsigned int file_size:19;
3385 + unsigned int offset:13;
3386 + unsigned int start_block;
3387 + unsigned int parent_inode;
3388 +} __attribute__ ((packed));
3389 +
3390 +struct squashfs_ldir_inode_header {
3391 + SQUASHFS_BASE_INODE_HEADER;
3392 + unsigned int nlink;
3393 + unsigned int file_size:27;
3394 + unsigned int offset:13;
3395 + unsigned int start_block;
3396 + unsigned int i_count:16;
3397 + unsigned int parent_inode;
3398 + struct squashfs_dir_index index[0];
3399 +} __attribute__ ((packed));
3400 +
3401 +union squashfs_inode_header {
3402 + struct squashfs_base_inode_header base;
3403 + struct squashfs_dev_inode_header dev;
3404 + struct squashfs_symlink_inode_header symlink;
3405 + struct squashfs_reg_inode_header reg;
3406 + struct squashfs_lreg_inode_header lreg;
3407 + struct squashfs_dir_inode_header dir;
3408 + struct squashfs_ldir_inode_header ldir;
3409 + struct squashfs_ipc_inode_header ipc;
3410 +};
3411 +
3412 +struct squashfs_dir_entry {
3413 + unsigned int offset:13;
3414 + unsigned int type:3;
3415 + unsigned int size:8;
3416 + int inode_number:16;
3417 + char name[0];
3418 +} __attribute__ ((packed));
3419 +
3420 +struct squashfs_dir_header {
3421 + unsigned int count:8;
3422 + unsigned int start_block;
3423 + unsigned int inode_number;
3424 +} __attribute__ ((packed));
3425 +
3426 +struct squashfs_fragment_entry {
3427 + long long start_block;
3428 + unsigned int size;
3429 + unsigned int unused;
3430 +} __attribute__ ((packed));
3431 +
3432 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3433 +extern int squashfs_uncompress_init(void);
3434 +extern int squashfs_uncompress_exit(void);
3435 +
3436 +/*
3437 + * macros to convert each packed bitfield structure from little endian to big
3438 + * endian and vice versa. These are needed when creating or using a filesystem
3439 + * on a machine with different byte ordering to the target architecture.
3440 + *
3441 + */
3442 +
3443 +#define SQUASHFS_SWAP_START \
3444 + int bits;\
3445 + int b_pos;\
3446 + unsigned long long val;\
3447 + unsigned char *s;\
3448 + unsigned char *d;
3449 +
3450 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3451 + SQUASHFS_SWAP_START\
3452 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3453 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3454 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3455 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3456 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3457 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3458 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3459 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3460 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3461 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3462 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3463 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3464 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3465 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3466 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3467 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3468 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3469 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3470 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3471 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3472 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3473 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3474 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3475 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3476 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3477 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3478 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3479 +}
3480 +
3481 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3482 + SQUASHFS_MEMSET(s, d, n);\
3483 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3484 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3485 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3486 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3487 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3488 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3489 +
3490 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3491 + SQUASHFS_SWAP_START\
3492 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3493 +}
3494 +
3495 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3496 + SQUASHFS_SWAP_START\
3497 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3498 + sizeof(struct squashfs_ipc_inode_header))\
3499 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3500 +}
3501 +
3502 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3503 + SQUASHFS_SWAP_START\
3504 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3505 + sizeof(struct squashfs_dev_inode_header)); \
3506 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3507 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3508 +}
3509 +
3510 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3511 + SQUASHFS_SWAP_START\
3512 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3513 + sizeof(struct squashfs_symlink_inode_header));\
3514 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3515 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3516 +}
3517 +
3518 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3519 + SQUASHFS_SWAP_START\
3520 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3521 + sizeof(struct squashfs_reg_inode_header));\
3522 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3523 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3524 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3525 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3526 +}
3527 +
3528 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3529 + SQUASHFS_SWAP_START\
3530 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3531 + sizeof(struct squashfs_lreg_inode_header));\
3532 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3533 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3534 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3535 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3536 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3537 +}
3538 +
3539 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3540 + SQUASHFS_SWAP_START\
3541 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3542 + sizeof(struct squashfs_dir_inode_header));\
3543 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3544 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3545 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3546 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3547 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3548 +}
3549 +
3550 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3551 + SQUASHFS_SWAP_START\
3552 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3553 + sizeof(struct squashfs_ldir_inode_header));\
3554 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3555 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3556 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3557 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3558 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3559 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3560 +}
3561 +
3562 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3563 + SQUASHFS_SWAP_START\
3564 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3565 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3566 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3567 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3568 +}
3569 +
3570 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3571 + SQUASHFS_SWAP_START\
3572 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3573 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3574 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3575 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3576 +}
3577 +
3578 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3579 + SQUASHFS_SWAP_START\
3580 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3581 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3582 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3583 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3584 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3585 +}
3586 +
3587 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3588 + SQUASHFS_SWAP_START\
3589 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3590 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3591 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3592 +}
3593 +
3594 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3595 + int entry;\
3596 + int bit_position;\
3597 + SQUASHFS_SWAP_START\
3598 + SQUASHFS_MEMSET(s, d, n * 2);\
3599 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3600 + 16)\
3601 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3602 +}
3603 +
3604 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3605 + int entry;\
3606 + int bit_position;\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_MEMSET(s, d, n * 4);\
3609 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3610 + 32)\
3611 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3612 +}
3613 +
3614 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3615 + int entry;\
3616 + int bit_position;\
3617 + SQUASHFS_SWAP_START\
3618 + SQUASHFS_MEMSET(s, d, n * 8);\
3619 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3620 + 64)\
3621 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3622 +}
3623 +
3624 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3625 + int entry;\
3626 + int bit_position;\
3627 + SQUASHFS_SWAP_START\
3628 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3629 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3630 + bits)\
3631 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3632 +}
3633 +
3634 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3635 +
3636 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3637 +
3638 +struct squashfs_base_inode_header_1 {
3639 + unsigned int inode_type:4;
3640 + unsigned int mode:12; /* protection */
3641 + unsigned int uid:4; /* index into uid table */
3642 + unsigned int guid:4; /* index into guid table */
3643 +} __attribute__ ((packed));
3644 +
3645 +struct squashfs_ipc_inode_header_1 {
3646 + unsigned int inode_type:4;
3647 + unsigned int mode:12; /* protection */
3648 + unsigned int uid:4; /* index into uid table */
3649 + unsigned int guid:4; /* index into guid table */
3650 + unsigned int type:4;
3651 + unsigned int offset:4;
3652 +} __attribute__ ((packed));
3653 +
3654 +struct squashfs_dev_inode_header_1 {
3655 + unsigned int inode_type:4;
3656 + unsigned int mode:12; /* protection */
3657 + unsigned int uid:4; /* index into uid table */
3658 + unsigned int guid:4; /* index into guid table */
3659 + unsigned short rdev;
3660 +} __attribute__ ((packed));
3661 +
3662 +struct squashfs_symlink_inode_header_1 {
3663 + unsigned int inode_type:4;
3664 + unsigned int mode:12; /* protection */
3665 + unsigned int uid:4; /* index into uid table */
3666 + unsigned int guid:4; /* index into guid table */
3667 + unsigned short symlink_size;
3668 + char symlink[0];
3669 +} __attribute__ ((packed));
3670 +
3671 +struct squashfs_reg_inode_header_1 {
3672 + unsigned int inode_type:4;
3673 + unsigned int mode:12; /* protection */
3674 + unsigned int uid:4; /* index into uid table */
3675 + unsigned int guid:4; /* index into guid table */
3676 + unsigned int mtime;
3677 + unsigned int start_block;
3678 + unsigned int file_size:32;
3679 + unsigned short block_list[0];
3680 +} __attribute__ ((packed));
3681 +
3682 +struct squashfs_dir_inode_header_1 {
3683 + unsigned int inode_type:4;
3684 + unsigned int mode:12; /* protection */
3685 + unsigned int uid:4; /* index into uid table */
3686 + unsigned int guid:4; /* index into guid table */
3687 + unsigned int file_size:19;
3688 + unsigned int offset:13;
3689 + unsigned int mtime;
3690 + unsigned int start_block:24;
3691 +} __attribute__ ((packed));
3692 +
3693 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3694 + SQUASHFS_MEMSET(s, d, n);\
3695 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3696 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3697 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3698 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3699 +
3700 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3701 + SQUASHFS_SWAP_START\
3702 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3703 +}
3704 +
3705 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3706 + SQUASHFS_SWAP_START\
3707 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3708 + sizeof(struct squashfs_ipc_inode_header_1));\
3709 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3710 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3711 +}
3712 +
3713 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3714 + SQUASHFS_SWAP_START\
3715 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3716 + sizeof(struct squashfs_dev_inode_header_1));\
3717 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3718 +}
3719 +
3720 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3721 + SQUASHFS_SWAP_START\
3722 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3723 + sizeof(struct squashfs_symlink_inode_header_1));\
3724 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3725 +}
3726 +
3727 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3728 + SQUASHFS_SWAP_START\
3729 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3730 + sizeof(struct squashfs_reg_inode_header_1));\
3731 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3732 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3733 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3734 +}
3735 +
3736 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3737 + SQUASHFS_SWAP_START\
3738 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3739 + sizeof(struct squashfs_dir_inode_header_1));\
3740 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3741 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3742 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3743 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3744 +}
3745 +
3746 +#endif
3747 +
3748 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3749 +
3750 +struct squashfs_dir_index_2 {
3751 + unsigned int index:27;
3752 + unsigned int start_block:29;
3753 + unsigned char size;
3754 + unsigned char name[0];
3755 +} __attribute__ ((packed));
3756 +
3757 +struct squashfs_base_inode_header_2 {
3758 + unsigned int inode_type:4;
3759 + unsigned int mode:12; /* protection */
3760 + unsigned int uid:8; /* index into uid table */
3761 + unsigned int guid:8; /* index into guid table */
3762 +} __attribute__ ((packed));
3763 +
3764 +struct squashfs_ipc_inode_header_2 {
3765 + unsigned int inode_type:4;
3766 + unsigned int mode:12; /* protection */
3767 + unsigned int uid:8; /* index into uid table */
3768 + unsigned int guid:8; /* index into guid table */
3769 +} __attribute__ ((packed));
3770 +
3771 +struct squashfs_dev_inode_header_2 {
3772 + unsigned int inode_type:4;
3773 + unsigned int mode:12; /* protection */
3774 + unsigned int uid:8; /* index into uid table */
3775 + unsigned int guid:8; /* index into guid table */
3776 + unsigned short rdev;
3777 +} __attribute__ ((packed));
3778 +
3779 +struct squashfs_symlink_inode_header_2 {
3780 + unsigned int inode_type:4;
3781 + unsigned int mode:12; /* protection */
3782 + unsigned int uid:8; /* index into uid table */
3783 + unsigned int guid:8; /* index into guid table */
3784 + unsigned short symlink_size;
3785 + char symlink[0];
3786 +} __attribute__ ((packed));
3787 +
3788 +struct squashfs_reg_inode_header_2 {
3789 + unsigned int inode_type:4;
3790 + unsigned int mode:12; /* protection */
3791 + unsigned int uid:8; /* index into uid table */
3792 + unsigned int guid:8; /* index into guid table */
3793 + unsigned int mtime;
3794 + unsigned int start_block;
3795 + unsigned int fragment;
3796 + unsigned int offset;
3797 + unsigned int file_size:32;
3798 + unsigned short block_list[0];
3799 +} __attribute__ ((packed));
3800 +
3801 +struct squashfs_dir_inode_header_2 {
3802 + unsigned int inode_type:4;
3803 + unsigned int mode:12; /* protection */
3804 + unsigned int uid:8; /* index into uid table */
3805 + unsigned int guid:8; /* index into guid table */
3806 + unsigned int file_size:19;
3807 + unsigned int offset:13;
3808 + unsigned int mtime;
3809 + unsigned int start_block:24;
3810 +} __attribute__ ((packed));
3811 +
3812 +struct squashfs_ldir_inode_header_2 {
3813 + unsigned int inode_type:4;
3814 + unsigned int mode:12; /* protection */
3815 + unsigned int uid:8; /* index into uid table */
3816 + unsigned int guid:8; /* index into guid table */
3817 + unsigned int file_size:27;
3818 + unsigned int offset:13;
3819 + unsigned int mtime;
3820 + unsigned int start_block:24;
3821 + unsigned int i_count:16;
3822 + struct squashfs_dir_index_2 index[0];
3823 +} __attribute__ ((packed));
3824 +
3825 +union squashfs_inode_header_2 {
3826 + struct squashfs_base_inode_header_2 base;
3827 + struct squashfs_dev_inode_header_2 dev;
3828 + struct squashfs_symlink_inode_header_2 symlink;
3829 + struct squashfs_reg_inode_header_2 reg;
3830 + struct squashfs_dir_inode_header_2 dir;
3831 + struct squashfs_ldir_inode_header_2 ldir;
3832 + struct squashfs_ipc_inode_header_2 ipc;
3833 +};
3834 +
3835 +struct squashfs_dir_header_2 {
3836 + unsigned int count:8;
3837 + unsigned int start_block:24;
3838 +} __attribute__ ((packed));
3839 +
3840 +struct squashfs_dir_entry_2 {
3841 + unsigned int offset:13;
3842 + unsigned int type:3;
3843 + unsigned int size:8;
3844 + char name[0];
3845 +} __attribute__ ((packed));
3846 +
3847 +struct squashfs_fragment_entry_2 {
3848 + unsigned int start_block;
3849 + unsigned int size;
3850 +} __attribute__ ((packed));
3851 +
3852 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3853 + SQUASHFS_MEMSET(s, d, n);\
3854 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3855 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3856 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3857 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3858 +
3859 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3860 + SQUASHFS_SWAP_START\
3861 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3862 +}
3863 +
3864 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3865 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3866 +
3867 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3868 + SQUASHFS_SWAP_START\
3869 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3870 + sizeof(struct squashfs_dev_inode_header_2)); \
3871 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3872 +}
3873 +
3874 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3875 + SQUASHFS_SWAP_START\
3876 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3877 + sizeof(struct squashfs_symlink_inode_header_2));\
3878 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3879 +}
3880 +
3881 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3882 + SQUASHFS_SWAP_START\
3883 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3884 + sizeof(struct squashfs_reg_inode_header_2));\
3885 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3886 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3887 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3888 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3889 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3890 +}
3891 +
3892 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3893 + SQUASHFS_SWAP_START\
3894 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3895 + sizeof(struct squashfs_dir_inode_header_2));\
3896 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3897 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3898 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3899 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3900 +}
3901 +
3902 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3903 + SQUASHFS_SWAP_START\
3904 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3905 + sizeof(struct squashfs_ldir_inode_header_2));\
3906 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3907 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3908 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3909 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3910 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3911 +}
3912 +
3913 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3914 + SQUASHFS_SWAP_START\
3915 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3916 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3917 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3918 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3919 +}
3920 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3921 + SQUASHFS_SWAP_START\
3922 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3923 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3924 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3925 +}
3926 +
3927 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3928 + SQUASHFS_SWAP_START\
3929 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3930 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3931 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3932 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3933 +}
3934 +
3935 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3936 + SQUASHFS_SWAP_START\
3937 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3938 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3939 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3940 +}
3941 +
3942 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3943 +
3944 +/* fragment and fragment table defines */
3945 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3946 +
3947 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3948 + SQUASHFS_METADATA_SIZE)
3949 +
3950 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3951 + SQUASHFS_METADATA_SIZE)
3952 +
3953 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3954 + SQUASHFS_METADATA_SIZE - 1) / \
3955 + SQUASHFS_METADATA_SIZE)
3956 +
3957 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3958 + sizeof(int))
3959 +
3960 +#endif
3961 +
3962 +#ifdef __KERNEL__
3963 +
3964 +/*
3965 + * macros used to swap each structure entry, taking into account
3966 + * bitfields and different bitfield placing conventions on differing
3967 + * architectures
3968 + */
3969 +
3970 +#include <asm/byteorder.h>
3971 +
3972 +#ifdef __BIG_ENDIAN
3973 + /* convert from little endian to big endian */
3974 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3975 + tbits, b_pos)
3976 +#else
3977 + /* convert from big endian to little endian */
3978 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3979 + tbits, 64 - tbits - b_pos)
3980 +#endif
3981 +
3982 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3983 + b_pos = pos % 8;\
3984 + val = 0;\
3985 + s = (unsigned char *)p + (pos / 8);\
3986 + d = ((unsigned char *) &val) + 7;\
3987 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3988 + *d-- = *s++;\
3989 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3990 +}
3991 +
3992 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3993 +
3994 +#endif
3995 +#endif
3996 --- /dev/null
3997 +++ b/include/linux/squashfs_fs_i.h
3998 @@ -0,0 +1,45 @@
3999 +#ifndef SQUASHFS_FS_I
4000 +#define SQUASHFS_FS_I
4001 +/*
4002 + * Squashfs
4003 + *
4004 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4005 + * Phillip Lougher <phillip@lougher.org.uk>
4006 + *
4007 + * This program is free software; you can redistribute it and/or
4008 + * modify it under the terms of the GNU General Public License
4009 + * as published by the Free Software Foundation; either version 2,
4010 + * or (at your option) any later version.
4011 + *
4012 + * This program is distributed in the hope that it will be useful,
4013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4015 + * GNU General Public License for more details.
4016 + *
4017 + * You should have received a copy of the GNU General Public License
4018 + * along with this program; if not, write to the Free Software
4019 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4020 + *
4021 + * squashfs_fs_i.h
4022 + */
4023 +
4024 +struct squashfs_inode_info {
4025 + long long start_block;
4026 + unsigned int offset;
4027 + union {
4028 + struct {
4029 + long long fragment_start_block;
4030 + unsigned int fragment_size;
4031 + unsigned int fragment_offset;
4032 + long long block_list_start;
4033 + } s1;
4034 + struct {
4035 + long long directory_index_start;
4036 + unsigned int directory_index_offset;
4037 + unsigned int directory_index_count;
4038 + unsigned int parent_inode;
4039 + } s2;
4040 + } u;
4041 + struct inode vfs_inode;
4042 +};
4043 +#endif
4044 --- /dev/null
4045 +++ b/include/linux/squashfs_fs_sb.h
4046 @@ -0,0 +1,74 @@
4047 +#ifndef SQUASHFS_FS_SB
4048 +#define SQUASHFS_FS_SB
4049 +/*
4050 + * Squashfs
4051 + *
4052 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4053 + * Phillip Lougher <phillip@lougher.org.uk>
4054 + *
4055 + * This program is free software; you can redistribute it and/or
4056 + * modify it under the terms of the GNU General Public License
4057 + * as published by the Free Software Foundation; either version 2,
4058 + * or (at your option) any later version.
4059 + *
4060 + * This program is distributed in the hope that it will be useful,
4061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4063 + * GNU General Public License for more details.
4064 + *
4065 + * You should have received a copy of the GNU General Public License
4066 + * along with this program; if not, write to the Free Software
4067 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4068 + *
4069 + * squashfs_fs_sb.h
4070 + */
4071 +
4072 +#include <linux/squashfs_fs.h>
4073 +
4074 +struct squashfs_cache {
4075 + long long block;
4076 + int length;
4077 + long long next_index;
4078 + char *data;
4079 +};
4080 +
4081 +struct squashfs_fragment_cache {
4082 + long long block;
4083 + int length;
4084 + unsigned int locked;
4085 + char *data;
4086 +};
4087 +
4088 +struct squashfs_sb_info {
4089 + struct squashfs_super_block sblk;
4090 + int devblksize;
4091 + int devblksize_log2;
4092 + int swap;
4093 + struct squashfs_cache *block_cache;
4094 + struct squashfs_fragment_cache *fragment;
4095 + int next_cache;
4096 + int next_fragment;
4097 + int next_meta_index;
4098 + unsigned int *uid;
4099 + unsigned int *guid;
4100 + long long *fragment_index;
4101 + unsigned int *fragment_index_2;
4102 + unsigned int read_size;
4103 + char *read_data;
4104 + char *read_page;
4105 + struct semaphore read_data_mutex;
4106 + struct semaphore read_page_mutex;
4107 + struct semaphore block_cache_mutex;
4108 + struct semaphore fragment_mutex;
4109 + struct semaphore meta_index_mutex;
4110 + wait_queue_head_t waitq;
4111 + wait_queue_head_t fragment_wait_queue;
4112 + struct meta_index *meta_index;
4113 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4114 + inode);
4115 + long long (*read_blocklist)(struct inode *inode, int \
4116 + index, int readahead_blks, char *block_list, \
4117 + unsigned short **block_p, unsigned int *bsize);
4118 + int (*read_fragment_index_table)(struct super_block *s);
4119 +};
4120 +#endif
4121 --- a/init/do_mounts_rd.c
4122 +++ b/init/do_mounts_rd.c
4123 @@ -5,6 +5,7 @@
4124 #include <linux/ext2_fs.h>
4125 #include <linux/romfs_fs.h>
4126 #include <linux/cramfs_fs.h>
4127 +#include <linux/squashfs_fs.h>
4128 #include <linux/initrd.h>
4129 #include <linux/string.h>
4130
4131 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4132 * numbers could not be found.
4133 *
4134 * We currently check for the following magic numbers:
4135 + * squashfs
4136 * minix
4137 * ext2
4138 * romfs
4139 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4140 struct ext2_super_block *ext2sb;
4141 struct romfs_super_block *romfsb;
4142 struct cramfs_super *cramfsb;
4143 + struct squashfs_super_block *squashfsb;
4144 int nblocks = -1;
4145 unsigned char *buf;
4146
4147 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4148 ext2sb = (struct ext2_super_block *) buf;
4149 romfsb = (struct romfs_super_block *) buf;
4150 cramfsb = (struct cramfs_super *) buf;
4151 + squashfsb = (struct squashfs_super_block *) buf;
4152 memset(buf, 0xe5, size);
4153
4154 /*
4155 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
4156 goto done;
4157 }
4158
4159 + /* squashfs is at block zero too */
4160 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4161 + printk(KERN_NOTICE
4162 + "RAMDISK: squashfs filesystem found at block %d\n",
4163 + start_block);
4164 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4165 + goto done;
4166 + }
4167 +
4168 /*
4169 * Read block 1 to test for minix and ext2 superblock
4170 */
This page took 0.240389 seconds and 5 git commands to generate.