1 diff --new-file -urp linux-2.4.32/fs/Config.in linux-2.4.32-squashfs3.0/fs/Config.in
2 --- linux-2.4.32/fs/Config.in 2004-11-17 11:54:21.000000000 +0000
3 +++ linux-2.4.32-squashfs3.0/fs/Config.in 2006-03-07 21:12:36.000000000 +0000
4 @@ -51,6 +51,14 @@ if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFI
5 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
7 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
8 +tristate 'Squashed file system support' CONFIG_SQUASHFS
9 +if [ "$CONFIG_SQUASHFS" = "y" -o "$CONFIG_SQUASHFS" = "m" ] ; then
10 +bool 'Additional options for memory constrained systems ' CONFIG_SQUASHFS_EMBEDDED
12 +if [ "$CONFIG_SQUASHFS_EMBEDDED" = "y" ] ; then
13 +int 'Number of fragments cached' CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE 3
14 +bool 'Use Vmalloc rather than Kmalloc' CONFIG_SQUASHFS_VMALLOC
16 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
17 define_bool CONFIG_RAMFS y
19 diff --new-file -urp linux-2.4.32/fs/Makefile linux-2.4.32-squashfs3.0/fs/Makefile
20 --- linux-2.4.32/fs/Makefile 2004-02-18 13:36:31.000000000 +0000
21 +++ linux-2.4.32-squashfs3.0/fs/Makefile 2006-03-07 21:12:36.000000000 +0000
22 @@ -65,6 +65,7 @@ subdir-$(CONFIG_REISERFS_FS) += reiserfs
23 subdir-$(CONFIG_DEVPTS_FS) += devpts
24 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
25 subdir-$(CONFIG_BEFS_FS) += befs
26 +subdir-$(CONFIG_SQUASHFS) += squashfs
27 subdir-$(CONFIG_JFS_FS) += jfs
28 subdir-$(CONFIG_XFS_FS) += xfs
30 diff --new-file -urp linux-2.4.32/fs/squashfs/inode.c linux-2.4.32-squashfs3.0/fs/squashfs/inode.c
31 --- linux-2.4.32/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
32 +++ linux-2.4.32-squashfs3.0/fs/squashfs/inode.c 2006-03-07 21:12:36.000000000 +0000
35 + * Squashfs - a compressed read only filesystem for Linux
37 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
38 + * Phillip Lougher <phillip@lougher.org.uk>
40 + * This program is free software; you can redistribute it and/or
41 + * modify it under the terms of the GNU General Public License
42 + * as published by the Free Software Foundation; either version 2,
43 + * or (at your option) any later version.
45 + * This program is distributed in the hope that it will be useful,
46 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 + * GNU General Public License for more details.
50 + * You should have received a copy of the GNU General Public License
51 + * along with this program; if not, write to the Free Software
52 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
57 +#include <linux/types.h>
58 +#include <linux/squashfs_fs.h>
59 +#include <linux/module.h>
60 +#include <linux/errno.h>
61 +#include <linux/slab.h>
62 +#include <linux/fs.h>
63 +#include <linux/smp_lock.h>
64 +#include <linux/locks.h>
65 +#include <linux/init.h>
66 +#include <linux/dcache.h>
67 +#include <linux/wait.h>
68 +#include <linux/zlib.h>
69 +#include <linux/blkdev.h>
70 +#include <linux/vmalloc.h>
71 +#include <asm/uaccess.h>
72 +#include <asm/semaphore.h>
74 +#include "squashfs.h"
76 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
77 +static void squashfs_put_super(struct super_block *);
78 +static int squashfs_statfs(struct super_block *, struct statfs *);
79 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
80 +static int squashfs_readpage(struct file *file, struct page *page);
81 +static int squashfs_readpage4K(struct file *file, struct page *page);
82 +static int squashfs_readdir(struct file *, void *, filldir_t);
83 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
84 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
85 +static long long read_blocklist(struct inode *inode, int index,
86 + int readahead_blks, char *block_list,
87 + unsigned short **block_p, unsigned int *bsize);
89 +static z_stream stream;
91 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
93 +static unsigned char squashfs_filetype_table[] = {
94 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
97 +static struct super_operations squashfs_ops = {
98 + .statfs = squashfs_statfs,
99 + .put_super = squashfs_put_super,
102 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
103 + .readpage = squashfs_symlink_readpage
106 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
107 + .readpage = squashfs_readpage
110 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
111 + .readpage = squashfs_readpage4K
114 +static struct file_operations squashfs_dir_ops = {
115 + .read = generic_read_dir,
116 + .readdir = squashfs_readdir
119 +static struct inode_operations squashfs_dir_inode_ops = {
120 + .lookup = squashfs_lookup
123 +static struct buffer_head *get_block_length(struct super_block *s,
124 + int *cur_index, int *offset, int *c_byte)
126 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
127 + unsigned short temp;
128 + struct buffer_head *bh;
130 + if (!(bh = sb_bread(s, *cur_index)))
133 + if (msblk->devblksize - *offset == 1) {
135 + ((unsigned char *) &temp)[1] = *((unsigned char *)
136 + (bh->b_data + *offset));
138 + ((unsigned char *) &temp)[0] = *((unsigned char *)
139 + (bh->b_data + *offset));
141 + if (!(bh = sb_bread(s, ++(*cur_index))))
144 + ((unsigned char *) &temp)[0] = *((unsigned char *)
147 + ((unsigned char *) &temp)[1] = *((unsigned char *)
153 + ((unsigned char *) &temp)[1] = *((unsigned char *)
154 + (bh->b_data + *offset));
155 + ((unsigned char *) &temp)[0] = *((unsigned char *)
156 + (bh->b_data + *offset + 1));
158 + ((unsigned char *) &temp)[0] = *((unsigned char *)
159 + (bh->b_data + *offset));
160 + ((unsigned char *) &temp)[1] = *((unsigned char *)
161 + (bh->b_data + *offset + 1));
167 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
168 + if (*offset == msblk->devblksize) {
170 + if (!(bh = sb_bread(s, ++(*cur_index))))
174 + if (*((unsigned char *) (bh->b_data + *offset)) !=
175 + SQUASHFS_MARKER_BYTE) {
176 + ERROR("Metadata block marker corrupt @ %x\n",
190 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
191 + long long index, unsigned int length,
192 + long long *next_index)
194 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
195 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
196 + msblk->devblksize_log2) + 2];
197 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
198 + unsigned int cur_index = index >> msblk->devblksize_log2;
199 + int bytes, avail_bytes, b = 0, k;
201 + unsigned int compressed;
202 + unsigned int c_byte = length;
205 + bytes = msblk->devblksize - offset;
206 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
207 + c_buffer = compressed ? msblk->read_data : buffer;
208 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
210 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
211 + ? "" : "un", (unsigned int) c_byte);
213 + if (!(bh[0] = sb_getblk(s, cur_index)))
214 + goto block_release;
216 + for (b = 1; bytes < c_byte; b++) {
217 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
218 + goto block_release;
219 + bytes += msblk->devblksize;
221 + ll_rw_block(READ, b, bh);
223 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
227 + bytes = msblk->devblksize - offset;
228 + compressed = SQUASHFS_COMPRESSED(c_byte);
229 + c_buffer = compressed ? msblk->read_data : buffer;
230 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
232 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
233 + ? "" : "un", (unsigned int) c_byte);
235 + for (b = 1; bytes < c_byte; b++) {
236 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
237 + goto block_release;
238 + bytes += msblk->devblksize;
240 + ll_rw_block(READ, b - 1, bh + 1);
244 + down(&msblk->read_data_mutex);
246 + for (bytes = 0, k = 0; k < b; k++) {
247 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
248 + msblk->devblksize - offset :
250 + wait_on_buffer(bh[k]);
251 + if (!buffer_uptodate(bh[k]))
252 + goto block_release;
253 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
254 + bytes += avail_bytes;
265 + stream.next_in = c_buffer;
266 + stream.avail_in = c_byte;
267 + stream.next_out = buffer;
268 + stream.avail_out = msblk->read_size;
270 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
271 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
272 + != Z_STREAM_END) || ((zlib_err =
273 + zlib_inflateEnd(&stream)) != Z_OK)) {
274 + ERROR("zlib_fs returned unexpected result 0x%x\n",
278 + bytes = stream.total_out;
280 + up(&msblk->read_data_mutex);
284 + *next_index = index + c_byte + (length ? 0 :
285 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
294 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
299 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
300 + long long block, unsigned int offset,
301 + int length, long long *next_block,
302 + unsigned int *next_offset)
304 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
305 + int n, i, bytes, return_length = length;
306 + long long next_index;
308 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
311 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
312 + if (msblk->block_cache[i].block == block)
315 + down(&msblk->block_cache_mutex);
317 + if (i == SQUASHFS_CACHED_BLKS) {
318 + /* read inode header block */
319 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
320 + n ; n --, i = (i + 1) %
321 + SQUASHFS_CACHED_BLKS)
322 + if (msblk->block_cache[i].block !=
329 + init_waitqueue_entry(&wait, current);
330 + add_wait_queue(&msblk->waitq, &wait);
331 + set_current_state(TASK_UNINTERRUPTIBLE);
332 + up(&msblk->block_cache_mutex);
334 + set_current_state(TASK_RUNNING);
335 + remove_wait_queue(&msblk->waitq, &wait);
338 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
340 + if (msblk->block_cache[i].block ==
341 + SQUASHFS_INVALID_BLK) {
342 + if (!(msblk->block_cache[i].data =
343 + kmalloc(SQUASHFS_METADATA_SIZE,
345 + ERROR("Failed to allocate cache"
347 + up(&msblk->block_cache_mutex);
352 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
353 + up(&msblk->block_cache_mutex);
355 + if (!(msblk->block_cache[i].length =
356 + squashfs_read_data(s,
357 + msblk->block_cache[i].data,
358 + block, 0, &next_index))) {
359 + ERROR("Unable to read cache block [%llx:%x]\n",
364 + down(&msblk->block_cache_mutex);
365 + wake_up(&msblk->waitq);
366 + msblk->block_cache[i].block = block;
367 + msblk->block_cache[i].next_index = next_index;
368 + TRACE("Read cache block [%llx:%x]\n", block, offset);
371 + if (msblk->block_cache[i].block != block) {
372 + up(&msblk->block_cache_mutex);
376 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
378 + memcpy(buffer, msblk->block_cache[i].data +
380 + if (msblk->block_cache[i].length - offset == length) {
381 + *next_block = msblk->block_cache[i].next_index;
384 + *next_block = block;
385 + *next_offset = offset + length;
387 + up(&msblk->block_cache_mutex);
391 + memcpy(buffer, msblk->block_cache[i].data +
395 + block = msblk->block_cache[i].next_index;
396 + up(&msblk->block_cache_mutex);
403 + return return_length;
409 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
410 + long long *fragment_start_block,
411 + unsigned int *fragment_size)
413 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
414 + long long start_block =
415 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
416 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
417 + struct squashfs_fragment_entry fragment_entry;
420 + struct squashfs_fragment_entry sfragment_entry;
422 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
423 + start_block, offset,
424 + sizeof(sfragment_entry), &start_block,
427 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
429 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
430 + start_block, offset,
431 + sizeof(fragment_entry), &start_block,
435 + *fragment_start_block = fragment_entry.start_block;
436 + *fragment_size = fragment_entry.size;
445 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
446 + squashfs_fragment_cache *fragment)
448 + down(&msblk->fragment_mutex);
449 + fragment->locked --;
450 + wake_up(&msblk->fragment_wait_queue);
451 + up(&msblk->fragment_mutex);
455 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
456 + *s, long long start_block,
460 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
463 + down(&msblk->fragment_mutex);
465 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
466 + msblk->fragment[i].block != start_block; i++);
468 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
469 + for (i = msblk->next_fragment, n =
470 + SQUASHFS_CACHED_FRAGMENTS; n &&
471 + msblk->fragment[i].locked; n--, i = (i + 1) %
472 + SQUASHFS_CACHED_FRAGMENTS);
477 + init_waitqueue_entry(&wait, current);
478 + add_wait_queue(&msblk->fragment_wait_queue,
480 + set_current_state(TASK_UNINTERRUPTIBLE);
481 + up(&msblk->fragment_mutex);
483 + set_current_state(TASK_RUNNING);
484 + remove_wait_queue(&msblk->fragment_wait_queue,
488 + msblk->next_fragment = (msblk->next_fragment + 1) %
489 + SQUASHFS_CACHED_FRAGMENTS;
491 + if (msblk->fragment[i].data == NULL)
492 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
493 + (SQUASHFS_FILE_MAX_SIZE))) {
494 + ERROR("Failed to allocate fragment "
496 + up(&msblk->fragment_mutex);
500 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
501 + msblk->fragment[i].locked = 1;
502 + up(&msblk->fragment_mutex);
504 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
505 + msblk->fragment[i].data,
506 + start_block, length, NULL))) {
507 + ERROR("Unable to read fragment cache block "
508 + "[%llx]\n", start_block);
509 + msblk->fragment[i].locked = 0;
513 + msblk->fragment[i].block = start_block;
514 + TRACE("New fragment %d, start block %lld, locked %d\n",
515 + i, msblk->fragment[i].block,
516 + msblk->fragment[i].locked);
520 + msblk->fragment[i].locked++;
521 + up(&msblk->fragment_mutex);
522 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
523 + msblk->fragment[i].block,
524 + msblk->fragment[i].locked);
528 + return &msblk->fragment[i];
535 +static struct inode *squashfs_new_inode(struct super_block *s,
536 + struct squashfs_base_inode_header *inodeb)
538 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
539 + struct inode *i = new_inode(s);
542 + i->i_ino = inodeb->inode_number;
543 + i->i_mtime = inodeb->mtime;
544 + i->i_atime = inodeb->mtime;
545 + i->i_ctime = inodeb->mtime;
546 + i->i_uid = msblk->uid[inodeb->uid];
547 + i->i_mode = inodeb->mode;
549 + if (inodeb->guid == SQUASHFS_GUIDS)
550 + i->i_gid = i->i_uid;
552 + i->i_gid = msblk->guid[inodeb->guid];
559 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
562 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
563 + struct squashfs_super_block *sblk = &msblk->sblk;
564 + long long block = SQUASHFS_INODE_BLK(inode) +
565 + sblk->inode_table_start;
566 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
567 + long long next_block;
568 + unsigned int next_offset;
569 + union squashfs_inode_header id, sid;
570 + struct squashfs_base_inode_header *inodeb = &id.base,
571 + *sinodeb = &sid.base;
573 + TRACE("Entered squashfs_iget\n");
576 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
577 + offset, sizeof(*sinodeb), &next_block,
580 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
583 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
584 + offset, sizeof(*inodeb), &next_block,
588 + switch(inodeb->inode_type) {
589 + case SQUASHFS_FILE_TYPE: {
590 + unsigned int frag_size;
591 + long long frag_blk;
592 + struct squashfs_reg_inode_header *inodep = &id.reg;
593 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
596 + if (!squashfs_get_cached_block(s, (char *)
597 + sinodep, block, offset,
598 + sizeof(*sinodep), &next_block,
601 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
603 + if (!squashfs_get_cached_block(s, (char *)
604 + inodep, block, offset,
605 + sizeof(*inodep), &next_block,
609 + frag_blk = SQUASHFS_INVALID_BLK;
610 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
611 + !get_fragment_location(s,
612 + inodep->fragment, &frag_blk, &frag_size))
615 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
619 + i->i_size = inodep->file_size;
620 + i->i_fop = &generic_ro_fops;
621 + i->i_mode |= S_IFREG;
622 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
623 + i->i_blksize = PAGE_CACHE_SIZE;
624 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
625 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
626 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
627 + SQUASHFS_I(i)->start_block = inodep->start_block;
628 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
629 + SQUASHFS_I(i)->offset = next_offset;
630 + if (sblk->block_size > 4096)
631 + i->i_data.a_ops = &squashfs_aops;
633 + i->i_data.a_ops = &squashfs_aops_4K;
635 + TRACE("File inode %x:%x, start_block %llx, "
636 + "block_list_start %llx, offset %x\n",
637 + SQUASHFS_INODE_BLK(inode), offset,
638 + inodep->start_block, next_block,
642 + case SQUASHFS_LREG_TYPE: {
643 + unsigned int frag_size;
644 + long long frag_blk;
645 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
646 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
649 + if (!squashfs_get_cached_block(s, (char *)
650 + sinodep, block, offset,
651 + sizeof(*sinodep), &next_block,
654 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
656 + if (!squashfs_get_cached_block(s, (char *)
657 + inodep, block, offset,
658 + sizeof(*inodep), &next_block,
662 + frag_blk = SQUASHFS_INVALID_BLK;
663 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
664 + !get_fragment_location(s,
665 + inodep->fragment, &frag_blk, &frag_size))
668 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
671 + i->i_nlink = inodep->nlink;
672 + i->i_size = inodep->file_size;
673 + i->i_fop = &generic_ro_fops;
674 + i->i_mode |= S_IFREG;
675 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
676 + i->i_blksize = PAGE_CACHE_SIZE;
677 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
678 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
679 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
680 + SQUASHFS_I(i)->start_block = inodep->start_block;
681 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
682 + SQUASHFS_I(i)->offset = next_offset;
683 + if (sblk->block_size > 4096)
684 + i->i_data.a_ops = &squashfs_aops;
686 + i->i_data.a_ops = &squashfs_aops_4K;
688 + TRACE("File inode %x:%x, start_block %llx, "
689 + "block_list_start %llx, offset %x\n",
690 + SQUASHFS_INODE_BLK(inode), offset,
691 + inodep->start_block, next_block,
695 + case SQUASHFS_DIR_TYPE: {
696 + struct squashfs_dir_inode_header *inodep = &id.dir;
697 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
700 + if (!squashfs_get_cached_block(s, (char *)
701 + sinodep, block, offset,
702 + sizeof(*sinodep), &next_block,
705 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
707 + if (!squashfs_get_cached_block(s, (char *)
708 + inodep, block, offset,
709 + sizeof(*inodep), &next_block,
713 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
716 + i->i_nlink = inodep->nlink;
717 + i->i_size = inodep->file_size;
718 + i->i_op = &squashfs_dir_inode_ops;
719 + i->i_fop = &squashfs_dir_ops;
720 + i->i_mode |= S_IFDIR;
721 + SQUASHFS_I(i)->start_block = inodep->start_block;
722 + SQUASHFS_I(i)->offset = inodep->offset;
723 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
724 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
726 + TRACE("Directory inode %x:%x, start_block %x, offset "
727 + "%x\n", SQUASHFS_INODE_BLK(inode),
728 + offset, inodep->start_block,
732 + case SQUASHFS_LDIR_TYPE: {
733 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
734 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
737 + if (!squashfs_get_cached_block(s, (char *)
738 + sinodep, block, offset,
739 + sizeof(*sinodep), &next_block,
742 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
745 + if (!squashfs_get_cached_block(s, (char *)
746 + inodep, block, offset,
747 + sizeof(*inodep), &next_block,
751 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
754 + i->i_nlink = inodep->nlink;
755 + i->i_size = inodep->file_size;
756 + i->i_op = &squashfs_dir_inode_ops;
757 + i->i_fop = &squashfs_dir_ops;
758 + i->i_mode |= S_IFDIR;
759 + SQUASHFS_I(i)->start_block = inodep->start_block;
760 + SQUASHFS_I(i)->offset = inodep->offset;
761 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
762 + SQUASHFS_I(i)->u.s2.directory_index_offset =
764 + SQUASHFS_I(i)->u.s2.directory_index_count =
766 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
768 + TRACE("Long directory inode %x:%x, start_block %x, "
770 + SQUASHFS_INODE_BLK(inode), offset,
771 + inodep->start_block, inodep->offset);
774 + case SQUASHFS_SYMLINK_TYPE: {
775 + struct squashfs_symlink_inode_header *inodep =
777 + struct squashfs_symlink_inode_header *sinodep =
781 + if (!squashfs_get_cached_block(s, (char *)
782 + sinodep, block, offset,
783 + sizeof(*sinodep), &next_block,
786 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
789 + if (!squashfs_get_cached_block(s, (char *)
790 + inodep, block, offset,
791 + sizeof(*inodep), &next_block,
795 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
798 + i->i_nlink = inodep->nlink;
799 + i->i_size = inodep->symlink_size;
800 + i->i_op = &page_symlink_inode_operations;
801 + i->i_data.a_ops = &squashfs_symlink_aops;
802 + i->i_mode |= S_IFLNK;
803 + SQUASHFS_I(i)->start_block = next_block;
804 + SQUASHFS_I(i)->offset = next_offset;
806 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
808 + SQUASHFS_INODE_BLK(inode), offset,
809 + next_block, next_offset);
812 + case SQUASHFS_BLKDEV_TYPE:
813 + case SQUASHFS_CHRDEV_TYPE: {
814 + struct squashfs_dev_inode_header *inodep = &id.dev;
815 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
818 + if (!squashfs_get_cached_block(s, (char *)
819 + sinodep, block, offset,
820 + sizeof(*sinodep), &next_block,
823 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
825 + if (!squashfs_get_cached_block(s, (char *)
826 + inodep, block, offset,
827 + sizeof(*inodep), &next_block,
831 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
834 + i->i_nlink = inodep->nlink;
835 + i->i_mode |= (inodeb->inode_type ==
836 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
838 + init_special_inode(i, i->i_mode, inodep->rdev);
840 + TRACE("Device inode %x:%x, rdev %x\n",
841 + SQUASHFS_INODE_BLK(inode), offset,
845 + case SQUASHFS_FIFO_TYPE:
846 + case SQUASHFS_SOCKET_TYPE: {
847 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
848 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
851 + if (!squashfs_get_cached_block(s, (char *)
852 + sinodep, block, offset,
853 + sizeof(*sinodep), &next_block,
856 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
858 + if (!squashfs_get_cached_block(s, (char *)
859 + inodep, block, offset,
860 + sizeof(*inodep), &next_block,
864 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
867 + i->i_nlink = inodep->nlink;
868 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
869 + ? S_IFIFO : S_IFSOCK;
870 + init_special_inode(i, i->i_mode, 0);
874 + ERROR("Unknown inode type %d in squashfs_iget!\n",
875 + inodeb->inode_type);
879 + insert_inode_hash(i);
883 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
890 +int read_fragment_index_table(struct super_block *s)
892 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
893 + struct squashfs_super_block *sblk = &msblk->sblk;
895 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
896 + (sblk->fragments), GFP_KERNEL))) {
897 + ERROR("Failed to allocate uid/gid table\n");
901 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
902 + !squashfs_read_data(s, (char *)
903 + msblk->fragment_index,
904 + sblk->fragment_table_start,
905 + SQUASHFS_FRAGMENT_INDEX_BYTES
906 + (sblk->fragments) |
907 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
908 + ERROR("unable to read fragment index table\n");
914 + long long fragment;
916 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
918 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
919 + &msblk->fragment_index[i], 1);
920 + msblk->fragment_index[i] = fragment;
928 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
930 + struct squashfs_super_block *sblk = &msblk->sblk;
932 + msblk->iget = squashfs_iget;
933 + msblk->read_blocklist = read_blocklist;
934 + msblk->read_fragment_index_table = read_fragment_index_table;
936 + if (sblk->s_major == 1) {
937 + if (!squashfs_1_0_supported(msblk)) {
938 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
939 + "are unsupported\n");
940 + SERROR("Please recompile with "
941 + "Squashfs 1.0 support enabled\n");
944 + } else if (sblk->s_major == 2) {
945 + if (!squashfs_2_0_supported(msblk)) {
946 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
947 + "are unsupported\n");
948 + SERROR("Please recompile with "
949 + "Squashfs 2.0 support enabled\n");
952 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
954 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
955 + "filesystem\n", sblk->s_major, sblk->s_minor);
956 + SERROR("Please update your kernel\n");
964 +static struct super_block *squashfs_read_super(struct super_block *s,
965 + void *data, int silent)
967 + kdev_t dev = s->s_dev;
968 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
969 + struct squashfs_super_block *sblk = &msblk->sblk;
971 + struct inode *root;
973 + msblk->devblksize = get_hardsect_size(dev);
974 + if(msblk->devblksize < BLOCK_SIZE)
975 + msblk->devblksize = BLOCK_SIZE;
976 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
977 + set_blocksize(dev, msblk->devblksize);
978 + s->s_blocksize = msblk->devblksize;
979 + s->s_blocksize_bits = msblk->devblksize_log2;
981 + init_MUTEX(&msblk->read_data_mutex);
982 + init_MUTEX(&msblk->read_page_mutex);
983 + init_MUTEX(&msblk->block_cache_mutex);
984 + init_MUTEX(&msblk->fragment_mutex);
986 + init_waitqueue_head(&msblk->waitq);
987 + init_waitqueue_head(&msblk->fragment_wait_queue);
989 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
990 + sizeof(struct squashfs_super_block) |
991 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
992 + SERROR("unable to read superblock\n");
996 + /* Check it is a SQUASHFS superblock */
998 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
999 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1000 + struct squashfs_super_block ssblk;
1002 + WARNING("Mounting a different endian SQUASHFS "
1003 + "filesystem on %s\n", bdevname(dev));
1005 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1006 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1009 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1011 + goto failed_mount;
1015 + /* Check the MAJOR & MINOR versions */
1016 + if(!supported_squashfs_filesystem(msblk, silent))
1017 + goto failed_mount;
1019 + TRACE("Found valid superblock on %s\n", bdevname(dev));
1020 + TRACE("Inodes are %scompressed\n",
1021 + SQUASHFS_UNCOMPRESSED_INODES
1022 + (sblk->flags) ? "un" : "");
1023 + TRACE("Data is %scompressed\n",
1024 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1026 + TRACE("Check data is %s present in the filesystem\n",
1027 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1029 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1030 + TRACE("Block size %d\n", sblk->block_size);
1031 + TRACE("Number of inodes %d\n", sblk->inodes);
1032 + if (sblk->s_major > 1)
1033 + TRACE("Number of fragments %d\n", sblk->fragments);
1034 + TRACE("Number of uids %d\n", sblk->no_uids);
1035 + TRACE("Number of gids %d\n", sblk->no_guids);
1036 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1037 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1038 + if (sblk->s_major > 1)
1039 + TRACE("sblk->fragment_table_start %llx\n",
1040 + sblk->fragment_table_start);
1041 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1043 + s->s_flags |= MS_RDONLY;
1044 + s->s_op = &squashfs_ops;
1046 + /* Init inode_table block pointer array */
1047 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1048 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1049 + ERROR("Failed to allocate block cache\n");
1050 + goto failed_mount;
1053 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1054 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1056 + msblk->next_cache = 0;
1058 + /* Allocate read_data block */
1059 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1060 + SQUASHFS_METADATA_SIZE :
1063 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1064 + ERROR("Failed to allocate read_data block\n");
1065 + goto failed_mount;
1068 + /* Allocate read_page block */
1069 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1070 + ERROR("Failed to allocate read_page block\n");
1071 + goto failed_mount;
1074 + /* Allocate uid and gid tables */
1075 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1076 + sizeof(unsigned int), GFP_KERNEL))) {
1077 + ERROR("Failed to allocate uid/gid table\n");
1078 + goto failed_mount;
1080 + msblk->guid = msblk->uid + sblk->no_uids;
1082 + if (msblk->swap) {
1083 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1085 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1086 + ((sblk->no_uids + sblk->no_guids) *
1087 + sizeof(unsigned int)) |
1088 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1089 + ERROR("unable to read uid/gid table\n");
1090 + goto failed_mount;
1093 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1094 + sblk->no_guids), (sizeof(unsigned int) * 8));
1096 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1097 + ((sblk->no_uids + sblk->no_guids) *
1098 + sizeof(unsigned int)) |
1099 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1100 + ERROR("unable to read uid/gid table\n");
1101 + goto failed_mount;
1105 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1106 + goto allocate_root;
1108 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1109 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1110 + ERROR("Failed to allocate fragment block cache\n");
1111 + goto failed_mount;
1114 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1115 + msblk->fragment[i].locked = 0;
1116 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1117 + msblk->fragment[i].data = NULL;
1120 + msblk->next_fragment = 0;
1122 + /* Allocate fragment index table */
1123 + if(msblk->read_fragment_index_table(s) == 0)
1124 + goto failed_mount;
1127 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1128 + goto failed_mount;
1130 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1131 + ERROR("Root inode create failed\n");
1133 + goto failed_mount;
1136 + TRACE("Leaving squashfs_read_super\n");
1140 + kfree(msblk->fragment_index);
1141 + kfree(msblk->fragment);
1142 + kfree(msblk->uid);
1143 + kfree(msblk->read_page);
1144 + kfree(msblk->read_data);
1145 + kfree(msblk->block_cache);
1146 + kfree(msblk->fragment_index_2);
1151 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1153 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1154 + struct squashfs_super_block *sblk = &msblk->sblk;
1156 + TRACE("Entered squashfs_statfs\n");
1158 + buf->f_type = SQUASHFS_MAGIC;
1159 + buf->f_bsize = sblk->block_size;
1160 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1161 + buf->f_bfree = buf->f_bavail = 0;
1162 + buf->f_files = sblk->inodes;
1164 + buf->f_namelen = SQUASHFS_NAME_LEN;
1170 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1172 + struct inode *inode = page->mapping->host;
1173 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1174 + long long block = SQUASHFS_I(inode)->start_block;
1175 + int offset = SQUASHFS_I(inode)->offset;
1176 + void *pageaddr = kmap(page);
1178 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1179 + "%llx, offset %x\n", page->index,
1180 + SQUASHFS_I(inode)->start_block,
1181 + SQUASHFS_I(inode)->offset);
1183 + for (length = 0; length < index; length += bytes) {
1184 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1185 + block, offset, PAGE_CACHE_SIZE, &block,
1187 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1193 + if (length != index) {
1194 + ERROR("(squashfs_symlink_readpage) length != index\n");
1199 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1200 + i_size_read(inode) - length;
1202 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1203 + offset, bytes, &block, &offset)))
1204 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1207 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1209 + SetPageUptodate(page);
1216 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1218 + struct meta_index *meta = NULL;
1219 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1222 + down(&msblk->meta_index_mutex);
1224 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1226 + if(msblk->meta_index == NULL)
1227 + goto not_allocated;
1229 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1230 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1231 + msblk->meta_index[i].offset >= offset &&
1232 + msblk->meta_index[i].offset <= index &&
1233 + msblk->meta_index[i].locked == 0) {
1234 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1235 + msblk->meta_index[i].offset);
1236 + meta = &msblk->meta_index[i];
1237 + offset = meta->offset;
1244 + up(&msblk->meta_index_mutex);
1250 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1252 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1253 + struct meta_index *meta = NULL;
1256 + down(&msblk->meta_index_mutex);
1258 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1260 + if(msblk->meta_index == NULL) {
1261 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1262 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1263 + ERROR("Failed to allocate meta_index\n");
1266 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1267 + msblk->meta_index[i].inode_number = 0;
1268 + msblk->meta_index[i].locked = 0;
1270 + msblk->next_meta_index = 0;
1273 + for(i = SQUASHFS_META_NUMBER; i &&
1274 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1275 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1276 + SQUASHFS_META_NUMBER;
1279 + TRACE("empty_meta_index: failed!\n");
1283 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1284 + msblk->next_meta_index,
1285 + &msblk->meta_index[msblk->next_meta_index]);
1287 + meta = &msblk->meta_index[msblk->next_meta_index];
1288 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1289 + SQUASHFS_META_NUMBER;
1291 + meta->inode_number = inode->i_ino;
1292 + meta->offset = offset;
1293 + meta->skip = skip;
1294 + meta->entries = 0;
1298 + up(&msblk->meta_index_mutex);
1303 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1309 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1310 + long long *start_block, int *offset)
1312 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1313 + unsigned int *block_listp;
1316 + if (msblk->swap) {
1317 + char sblock_list[blocks << 2];
1319 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1320 + *offset, blocks << 2, start_block, offset)) {
1321 + ERROR("Unable to read block list [%llx:%x]\n",
1322 + *start_block, *offset);
1325 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1326 + ((unsigned int *)sblock_list), blocks);
1328 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1329 + *offset, blocks << 2, start_block, offset)) {
1330 + ERROR("Unable to read block list [%llx:%x]\n",
1331 + *start_block, *offset);
1335 + for (block_listp = (unsigned int *) block_list; blocks;
1336 + block_listp++, blocks --)
1337 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1348 +static inline int calculate_skip(int blocks) {
1349 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1350 + return skip >= 7 ? 7 : skip + 1;
1354 +static int get_meta_index(struct inode *inode, int index,
1355 + long long *index_block, int *index_offset,
1356 + long long *data_block, char *block_list)
1358 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1359 + struct squashfs_super_block *sblk = &msblk->sblk;
1360 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1362 + struct meta_index *meta;
1363 + struct meta_entry *meta_entry;
1364 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1365 + int cur_offset = SQUASHFS_I(inode)->offset;
1366 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1369 + index /= SQUASHFS_META_INDEXES * skip;
1371 + while ( offset < index ) {
1372 + meta = locate_meta_index(inode, index, offset + 1);
1374 + if (meta == NULL) {
1375 + if ((meta = empty_meta_index(inode, offset + 1,
1379 + offset = index < meta->offset + meta->entries ? index :
1380 + meta->offset + meta->entries - 1;
1381 + meta_entry = &meta->meta_entry[offset - meta->offset];
1382 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1383 + cur_offset = meta_entry->offset;
1384 + cur_data_block = meta_entry->data_block;
1385 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1386 + "meta->entries %d\n", offset, meta->offset,
1388 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1389 + " data_block 0x%llx\n", cur_index_block,
1390 + cur_offset, cur_data_block);
1393 + for (i = meta->offset + meta->entries; i <= index &&
1394 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1395 + int blocks = skip * SQUASHFS_META_INDEXES;
1398 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1400 + int res = read_block_index(inode->i_sb, block,
1401 + block_list, &cur_index_block,
1407 + cur_data_block += res;
1411 + meta_entry = &meta->meta_entry[i - meta->offset];
1412 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1413 + meta_entry->offset = cur_offset;
1414 + meta_entry->data_block = cur_data_block;
1419 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1420 + meta->offset, meta->entries);
1422 + release_meta_index(inode, meta);
1426 + *index_block = cur_index_block;
1427 + *index_offset = cur_offset;
1428 + *data_block = cur_data_block;
1430 + return offset * SQUASHFS_META_INDEXES * skip;
1433 + release_meta_index(inode, meta);
1438 +static long long read_blocklist(struct inode *inode, int index,
1439 + int readahead_blks, char *block_list,
1440 + unsigned short **block_p, unsigned int *bsize)
1442 + long long block_ptr;
1445 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1448 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1449 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1458 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1459 + int res = read_block_index(inode->i_sb, blocks, block_list,
1460 + &block_ptr, &offset);
1467 + if (read_block_index(inode->i_sb, 1, block_list,
1468 + &block_ptr, &offset) == -1)
1470 + *bsize = *((unsigned int *) block_list);
1479 +static int squashfs_readpage(struct file *file, struct page *page)
1481 + struct inode *inode = page->mapping->host;
1482 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1483 + struct squashfs_super_block *sblk = &msblk->sblk;
1484 + unsigned char block_list[SIZE];
1486 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1487 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1489 + struct squashfs_fragment_cache *fragment = NULL;
1490 + char *data_ptr = msblk->read_page;
1492 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1493 + int start_index = page->index & ~mask;
1494 + int end_index = start_index | mask;
1496 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1498 + SQUASHFS_I(inode)->start_block);
1500 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1501 + PAGE_CACHE_SHIFT))
1504 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1505 + || index < (i_size_read(inode) >>
1506 + sblk->block_log)) {
1507 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1508 + block_list, NULL, &bsize)) == 0)
1511 + down(&msblk->read_page_mutex);
1513 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1514 + block, bsize, NULL))) {
1515 + ERROR("Unable to read page, block %llx, size %x\n", block,
1517 + up(&msblk->read_page_mutex);
1521 + if ((fragment = get_cached_fragment(inode->i_sb,
1522 + SQUASHFS_I(inode)->
1523 + u.s1.fragment_start_block,
1524 + SQUASHFS_I(inode)->u.s1.fragment_size))
1526 + ERROR("Unable to read page, block %llx, size %x\n",
1527 + SQUASHFS_I(inode)->
1528 + u.s1.fragment_start_block,
1529 + (int) SQUASHFS_I(inode)->
1530 + u.s1.fragment_size);
1533 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1534 + (i_size_read(inode) & (sblk->block_size
1536 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1537 + data_ptr = fragment->data;
1540 + for (i = start_index; i <= end_index && byte_offset < bytes;
1541 + i++, byte_offset += PAGE_CACHE_SIZE) {
1542 + struct page *push_page;
1543 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1544 + PAGE_CACHE_SIZE : bytes - byte_offset;
1546 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1547 + bytes, i, byte_offset, available_bytes);
1549 + if (i == page->index) {
1550 + pageaddr = kmap_atomic(page, KM_USER0);
1551 + memcpy(pageaddr, data_ptr + byte_offset,
1553 + memset(pageaddr + available_bytes, 0,
1554 + PAGE_CACHE_SIZE - available_bytes);
1555 + kunmap_atomic(pageaddr, KM_USER0);
1556 + flush_dcache_page(page);
1557 + SetPageUptodate(page);
1559 + } else if ((push_page =
1560 + grab_cache_page_nowait(page->mapping, i))) {
1561 + pageaddr = kmap_atomic(push_page, KM_USER0);
1563 + memcpy(pageaddr, data_ptr + byte_offset,
1565 + memset(pageaddr + available_bytes, 0,
1566 + PAGE_CACHE_SIZE - available_bytes);
1567 + kunmap_atomic(pageaddr, KM_USER0);
1568 + flush_dcache_page(push_page);
1569 + SetPageUptodate(push_page);
1570 + UnlockPage(push_page);
1571 + page_cache_release(push_page);
1575 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1576 + || index < (i_size_read(inode) >>
1578 + up(&msblk->read_page_mutex);
1580 + release_cached_fragment(msblk, fragment);
1585 + pageaddr = kmap_atomic(page, KM_USER0);
1586 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1587 + kunmap_atomic(pageaddr, KM_USER0);
1588 + flush_dcache_page(page);
1589 + SetPageUptodate(page);
1596 +static int squashfs_readpage4K(struct file *file, struct page *page)
1598 + struct inode *inode = page->mapping->host;
1599 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1600 + struct squashfs_super_block *sblk = &msblk->sblk;
1601 + unsigned char block_list[SIZE];
1603 + unsigned int bsize, bytes = 0;
1606 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1608 + SQUASHFS_I(inode)->start_block);
1610 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1611 + PAGE_CACHE_SHIFT)) {
1612 + pageaddr = kmap_atomic(page, KM_USER0);
1616 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1617 + || page->index < (i_size_read(inode) >>
1618 + sblk->block_log)) {
1619 + block = (msblk->read_blocklist)(inode, page->index, 1,
1620 + block_list, NULL, &bsize);
1622 + down(&msblk->read_page_mutex);
1623 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1625 + pageaddr = kmap_atomic(page, KM_USER0);
1627 + memcpy(pageaddr, msblk->read_page, bytes);
1629 + ERROR("Unable to read page, block %llx, size %x\n",
1631 + up(&msblk->read_page_mutex);
1633 + struct squashfs_fragment_cache *fragment =
1634 + get_cached_fragment(inode->i_sb,
1635 + SQUASHFS_I(inode)->
1636 + u.s1.fragment_start_block,
1637 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1638 + pageaddr = kmap_atomic(page, KM_USER0);
1640 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1641 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1642 + u.s1.fragment_offset, bytes);
1643 + release_cached_fragment(msblk, fragment);
1645 + ERROR("Unable to read page, block %llx, size %x\n",
1646 + SQUASHFS_I(inode)->
1647 + u.s1.fragment_start_block, (int)
1648 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1652 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1653 + kunmap_atomic(pageaddr, KM_USER0);
1654 + flush_dcache_page(page);
1655 + SetPageUptodate(page);
1662 +static int get_dir_index_using_offset(struct super_block *s, long long
1663 + *next_block, unsigned int *next_offset,
1664 + long long index_start,
1665 + unsigned int index_offset, int i_count,
1668 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1669 + struct squashfs_super_block *sblk = &msblk->sblk;
1670 + int i, length = 0;
1671 + struct squashfs_dir_index index;
1673 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1674 + i_count, (unsigned int) f_pos);
1680 + for (i = 0; i < i_count; i++) {
1681 + if (msblk->swap) {
1682 + struct squashfs_dir_index sindex;
1683 + squashfs_get_cached_block(s, (char *) &sindex,
1684 + index_start, index_offset,
1685 + sizeof(sindex), &index_start,
1687 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1689 + squashfs_get_cached_block(s, (char *) &index,
1690 + index_start, index_offset,
1691 + sizeof(index), &index_start,
1694 + if (index.index > f_pos)
1697 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1698 + index.size + 1, &index_start,
1701 + length = index.index;
1702 + *next_block = index.start_block + sblk->directory_table_start;
1705 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1708 + return length + 3;
1712 +static int get_dir_index_using_name(struct super_block *s, long long
1713 + *next_block, unsigned int *next_offset,
1714 + long long index_start,
1715 + unsigned int index_offset, int i_count,
1716 + const char *name, int size)
1718 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1719 + struct squashfs_super_block *sblk = &msblk->sblk;
1720 + int i, length = 0;
1721 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1722 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1723 + char str[SQUASHFS_NAME_LEN + 1];
1725 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1727 + strncpy(str, name, size);
1730 + for (i = 0; i < i_count; i++) {
1731 + if (msblk->swap) {
1732 + struct squashfs_dir_index sindex;
1733 + squashfs_get_cached_block(s, (char *) &sindex,
1734 + index_start, index_offset,
1735 + sizeof(sindex), &index_start,
1737 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1739 + squashfs_get_cached_block(s, (char *) index,
1740 + index_start, index_offset,
1741 + sizeof(struct squashfs_dir_index),
1742 + &index_start, &index_offset);
1744 + squashfs_get_cached_block(s, index->name, index_start,
1745 + index_offset, index->size + 1,
1746 + &index_start, &index_offset);
1748 + index->name[index->size + 1] = '\0';
1750 + if (strcmp(index->name, str) > 0)
1753 + length = index->index;
1754 + *next_block = index->start_block + sblk->directory_table_start;
1757 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1758 + return length + 3;
1762 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1764 + struct inode *i = file->f_dentry->d_inode;
1765 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1766 + struct squashfs_super_block *sblk = &msblk->sblk;
1767 + long long next_block = SQUASHFS_I(i)->start_block +
1768 + sblk->directory_table_start;
1769 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1771 + struct squashfs_dir_header dirh;
1772 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1773 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1775 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1777 + while(file->f_pos < 3) {
1781 + if(file->f_pos == 0) {
1788 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1790 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1791 + (unsigned int) dirent, name, size, (int)
1792 + file->f_pos, i_ino,
1793 + squashfs_filetype_table[1]);
1795 + if (filldir(dirent, name, size,
1796 + file->f_pos, i_ino,
1797 + squashfs_filetype_table[1]) < 0) {
1798 + TRACE("Filldir returned less than 0\n");
1801 + file->f_pos += size;
1805 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1806 + SQUASHFS_I(i)->u.s2.directory_index_start,
1807 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1808 + SQUASHFS_I(i)->u.s2.directory_index_count,
1811 + while (length < i_size_read(i)) {
1812 + /* read directory header */
1813 + if (msblk->swap) {
1814 + struct squashfs_dir_header sdirh;
1816 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1817 + next_block, next_offset, sizeof(sdirh),
1818 + &next_block, &next_offset))
1821 + length += sizeof(sdirh);
1822 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1824 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1825 + next_block, next_offset, sizeof(dirh),
1826 + &next_block, &next_offset))
1829 + length += sizeof(dirh);
1832 + dir_count = dirh.count + 1;
1833 + while (dir_count--) {
1834 + if (msblk->swap) {
1835 + struct squashfs_dir_entry sdire;
1836 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1837 + &sdire, next_block, next_offset,
1838 + sizeof(sdire), &next_block,
1842 + length += sizeof(sdire);
1843 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1845 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1846 + dire, next_block, next_offset,
1847 + sizeof(*dire), &next_block,
1851 + length += sizeof(*dire);
1854 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1855 + next_block, next_offset,
1856 + dire->size + 1, &next_block,
1860 + length += dire->size + 1;
1862 + if (file->f_pos >= length)
1865 + dire->name[dire->size + 1] = '\0';
1867 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1868 + (unsigned int) dirent, dire->name,
1869 + dire->size + 1, (int) file->f_pos,
1870 + dirh.start_block, dire->offset,
1871 + dirh.inode_number + dire->inode_number,
1872 + squashfs_filetype_table[dire->type]);
1874 + if (filldir(dirent, dire->name, dire->size + 1,
1876 + dirh.inode_number + dire->inode_number,
1877 + squashfs_filetype_table[dire->type])
1879 + TRACE("Filldir returned less than 0\n");
1882 + file->f_pos = length;
1891 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1897 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1899 + const unsigned char *name = dentry->d_name.name;
1900 + int len = dentry->d_name.len;
1901 + struct inode *inode = NULL;
1902 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1903 + struct squashfs_super_block *sblk = &msblk->sblk;
1904 + long long next_block = SQUASHFS_I(i)->start_block +
1905 + sblk->directory_table_start;
1906 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1908 + struct squashfs_dir_header dirh;
1909 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1910 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1912 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
1914 + if (len > SQUASHFS_NAME_LEN)
1917 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
1918 + SQUASHFS_I(i)->u.s2.directory_index_start,
1919 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1920 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
1923 + while (length < i_size_read(i)) {
1924 + /* read directory header */
1925 + if (msblk->swap) {
1926 + struct squashfs_dir_header sdirh;
1927 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1928 + next_block, next_offset, sizeof(sdirh),
1929 + &next_block, &next_offset))
1932 + length += sizeof(sdirh);
1933 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1935 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1936 + next_block, next_offset, sizeof(dirh),
1937 + &next_block, &next_offset))
1940 + length += sizeof(dirh);
1943 + dir_count = dirh.count + 1;
1944 + while (dir_count--) {
1945 + if (msblk->swap) {
1946 + struct squashfs_dir_entry sdire;
1947 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1948 + &sdire, next_block,next_offset,
1949 + sizeof(sdire), &next_block,
1953 + length += sizeof(sdire);
1954 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1956 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1957 + dire, next_block,next_offset,
1958 + sizeof(*dire), &next_block,
1962 + length += sizeof(*dire);
1965 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1966 + next_block, next_offset, dire->size + 1,
1967 + &next_block, &next_offset))
1970 + length += dire->size + 1;
1972 + if (name[0] < dire->name[0])
1975 + if ((len == dire->size + 1) && !strncmp(name,
1976 + dire->name, len)) {
1977 + squashfs_inode_t ino =
1978 + SQUASHFS_MKINODE(dirh.start_block,
1981 + TRACE("calling squashfs_iget for directory "
1982 + "entry %s, inode %x:%x, %d\n", name,
1983 + dirh.start_block, dire->offset,
1984 + dirh.inode_number + dire->inode_number);
1986 + inode = (msblk->iget)(i->i_sb, ino);
1994 + d_add(dentry, inode);
1995 + return ERR_PTR(0);
1998 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2004 +static void squashfs_put_super(struct super_block *s)
2008 + struct squashfs_sb_info *sbi = &s->u.squashfs_sb;
2009 + if (sbi->block_cache)
2010 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2011 + if (sbi->block_cache[i].block !=
2012 + SQUASHFS_INVALID_BLK)
2013 + kfree(sbi->block_cache[i].data);
2014 + if (sbi->fragment)
2015 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2016 + SQUASHFS_FREE(sbi->fragment[i].data);
2017 + kfree(sbi->fragment);
2018 + kfree(sbi->block_cache);
2019 + kfree(sbi->read_data);
2020 + kfree(sbi->read_page);
2022 + kfree(sbi->fragment_index);
2023 + kfree(sbi->fragment_index_2);
2024 + sbi->block_cache = NULL;
2026 + sbi->read_data = NULL;
2027 + sbi->read_page = NULL;
2028 + sbi->fragment = NULL;
2029 + sbi->fragment_index = NULL;
2030 + sbi->fragment_index_2 = NULL;
2034 +static int __init init_squashfs_fs(void)
2037 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2038 + "Phillip Lougher\n");
2040 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2041 + ERROR("Failed to allocate zlib workspace\n");
2044 + return register_filesystem(&squashfs_fs_type);
2048 +static void __exit exit_squashfs_fs(void)
2050 + vfree(stream.workspace);
2051 + unregister_filesystem(&squashfs_fs_type);
2057 +module_init(init_squashfs_fs);
2058 +module_exit(exit_squashfs_fs);
2059 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2060 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2061 +MODULE_LICENSE("GPL");
2062 diff --new-file -urp linux-2.4.32/fs/squashfs/Makefile linux-2.4.32-squashfs3.0/fs/squashfs/Makefile
2063 --- linux-2.4.32/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2064 +++ linux-2.4.32-squashfs3.0/fs/squashfs/Makefile 2006-03-07 21:12:36.000000000 +0000
2067 +# Makefile for the linux squashfs routines.
2070 +O_TARGET := squashfs.o
2072 +obj-y := inode.o squashfs2_0.o
2074 +obj-m := $(O_TARGET)
2076 +include $(TOPDIR)/Rules.make
2077 diff --new-file -urp linux-2.4.32/fs/squashfs/squashfs2_0.c linux-2.4.32-squashfs3.0/fs/squashfs/squashfs2_0.c
2078 --- linux-2.4.32/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2079 +++ linux-2.4.32-squashfs3.0/fs/squashfs/squashfs2_0.c 2006-03-07 21:12:36.000000000 +0000
2082 + * Squashfs - a compressed read only filesystem for Linux
2084 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2085 + * Phillip Lougher <phillip@lougher.org.uk>
2087 + * This program is free software; you can redistribute it and/or
2088 + * modify it under the terms of the GNU General Public License
2089 + * as published by the Free Software Foundation; either version 2,
2090 + * or (at your option) any later version.
2092 + * This program is distributed in the hope that it will be useful,
2093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2095 + * GNU General Public License for more details.
2097 + * You should have received a copy of the GNU General Public License
2098 + * along with this program; if not, write to the Free Software
2099 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2104 +#include <linux/types.h>
2105 +#include <linux/squashfs_fs.h>
2106 +#include <linux/module.h>
2107 +#include <linux/errno.h>
2108 +#include <linux/slab.h>
2109 +#include <linux/fs.h>
2110 +#include <linux/smp_lock.h>
2111 +#include <linux/locks.h>
2112 +#include <linux/init.h>
2113 +#include <linux/dcache.h>
2114 +#include <linux/wait.h>
2115 +#include <linux/zlib.h>
2116 +#include <linux/blkdev.h>
2117 +#include <linux/vmalloc.h>
2118 +#include <asm/uaccess.h>
2119 +#include <asm/semaphore.h>
2120 +#include "squashfs.h"
2122 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2123 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry);
2125 +static struct file_operations squashfs_dir_ops_2 = {
2126 + .read = generic_read_dir,
2127 + .readdir = squashfs_readdir_2
2130 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2131 + .lookup = squashfs_lookup_2
2134 +static unsigned char squashfs_filetype_table[] = {
2135 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2138 +static int read_fragment_index_table_2(struct super_block *s)
2140 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2141 + struct squashfs_super_block *sblk = &msblk->sblk;
2143 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2144 + (sblk->fragments), GFP_KERNEL))) {
2145 + ERROR("Failed to allocate uid/gid table\n");
2149 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2150 + !squashfs_read_data(s, (char *)
2151 + msblk->fragment_index_2,
2152 + sblk->fragment_table_start,
2153 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2154 + (sblk->fragments) |
2155 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2156 + ERROR("unable to read fragment index table\n");
2160 + if (msblk->swap) {
2162 + unsigned int fragment;
2164 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2166 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2167 + &msblk->fragment_index_2[i], 1);
2168 + msblk->fragment_index_2[i] = fragment;
2176 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2177 + long long *fragment_start_block,
2178 + unsigned int *fragment_size)
2180 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2181 + long long start_block =
2182 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2183 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2184 + struct squashfs_fragment_entry_2 fragment_entry;
2186 + if (msblk->swap) {
2187 + struct squashfs_fragment_entry_2 sfragment_entry;
2189 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2190 + start_block, offset,
2191 + sizeof(sfragment_entry), &start_block,
2194 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2196 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2197 + start_block, offset,
2198 + sizeof(fragment_entry), &start_block,
2202 + *fragment_start_block = fragment_entry.start_block;
2203 + *fragment_size = fragment_entry.size;
2212 +static struct inode *squashfs_new_inode(struct super_block *s,
2213 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2215 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2216 + struct squashfs_super_block *sblk = &msblk->sblk;
2217 + struct inode *i = new_inode(s);
2221 + i->i_mtime = sblk->mkfs_time;
2222 + i->i_atime = sblk->mkfs_time;
2223 + i->i_ctime = sblk->mkfs_time;
2224 + i->i_uid = msblk->uid[inodeb->uid];
2225 + i->i_mode = inodeb->mode;
2228 + if (inodeb->guid == SQUASHFS_GUIDS)
2229 + i->i_gid = i->i_uid;
2231 + i->i_gid = msblk->guid[inodeb->guid];
2238 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2241 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2242 + struct squashfs_super_block *sblk = &msblk->sblk;
2243 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2244 + sblk->inode_table_start;
2245 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2246 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2247 + - sblk->inode_table_start, offset);
2248 + long long next_block;
2249 + unsigned int next_offset;
2250 + union squashfs_inode_header_2 id, sid;
2251 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2252 + *sinodeb = &sid.base;
2254 + TRACE("Entered squashfs_iget\n");
2256 + if (msblk->swap) {
2257 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2258 + offset, sizeof(*sinodeb), &next_block,
2261 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2262 + sizeof(*sinodeb));
2264 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2265 + offset, sizeof(*inodeb), &next_block,
2269 + switch(inodeb->inode_type) {
2270 + case SQUASHFS_FILE_TYPE: {
2271 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2272 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2273 + long long frag_blk;
2274 + unsigned int frag_size;
2276 + if (msblk->swap) {
2277 + if (!squashfs_get_cached_block(s, (char *)
2278 + sinodep, block, offset,
2279 + sizeof(*sinodep), &next_block,
2282 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2284 + if (!squashfs_get_cached_block(s, (char *)
2285 + inodep, block, offset,
2286 + sizeof(*inodep), &next_block,
2290 + frag_blk = SQUASHFS_INVALID_BLK;
2291 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2292 + !get_fragment_location_2(s,
2293 + inodep->fragment, &frag_blk, &frag_size))
2296 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2297 + goto failed_read1;
2299 + i->i_size = inodep->file_size;
2300 + i->i_fop = &generic_ro_fops;
2301 + i->i_mode |= S_IFREG;
2302 + i->i_mtime = inodep->mtime;
2303 + i->i_atime = inodep->mtime;
2304 + i->i_ctime = inodep->mtime;
2305 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2306 + i->i_blksize = PAGE_CACHE_SIZE;
2307 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2308 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2309 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2310 + SQUASHFS_I(i)->start_block = inodep->start_block;
2311 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2312 + SQUASHFS_I(i)->offset = next_offset;
2313 + if (sblk->block_size > 4096)
2314 + i->i_data.a_ops = &squashfs_aops;
2316 + i->i_data.a_ops = &squashfs_aops_4K;
2318 + TRACE("File inode %x:%x, start_block %x, "
2319 + "block_list_start %llx, offset %x\n",
2320 + SQUASHFS_INODE_BLK(inode), offset,
2321 + inodep->start_block, next_block,
2325 + case SQUASHFS_DIR_TYPE: {
2326 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2327 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2329 + if (msblk->swap) {
2330 + if (!squashfs_get_cached_block(s, (char *)
2331 + sinodep, block, offset,
2332 + sizeof(*sinodep), &next_block,
2335 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2337 + if (!squashfs_get_cached_block(s, (char *)
2338 + inodep, block, offset,
2339 + sizeof(*inodep), &next_block,
2343 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2344 + goto failed_read1;
2346 + i->i_size = inodep->file_size;
2347 + i->i_op = &squashfs_dir_inode_ops_2;
2348 + i->i_fop = &squashfs_dir_ops_2;
2349 + i->i_mode |= S_IFDIR;
2350 + i->i_mtime = inodep->mtime;
2351 + i->i_atime = inodep->mtime;
2352 + i->i_ctime = inodep->mtime;
2353 + SQUASHFS_I(i)->start_block = inodep->start_block;
2354 + SQUASHFS_I(i)->offset = inodep->offset;
2355 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2356 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2358 + TRACE("Directory inode %x:%x, start_block %x, offset "
2359 + "%x\n", SQUASHFS_INODE_BLK(inode),
2360 + offset, inodep->start_block,
2364 + case SQUASHFS_LDIR_TYPE: {
2365 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2366 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2368 + if (msblk->swap) {
2369 + if (!squashfs_get_cached_block(s, (char *)
2370 + sinodep, block, offset,
2371 + sizeof(*sinodep), &next_block,
2374 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2377 + if (!squashfs_get_cached_block(s, (char *)
2378 + inodep, block, offset,
2379 + sizeof(*inodep), &next_block,
2383 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2384 + goto failed_read1;
2386 + i->i_size = inodep->file_size;
2387 + i->i_op = &squashfs_dir_inode_ops_2;
2388 + i->i_fop = &squashfs_dir_ops_2;
2389 + i->i_mode |= S_IFDIR;
2390 + i->i_mtime = inodep->mtime;
2391 + i->i_atime = inodep->mtime;
2392 + i->i_ctime = inodep->mtime;
2393 + SQUASHFS_I(i)->start_block = inodep->start_block;
2394 + SQUASHFS_I(i)->offset = inodep->offset;
2395 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2396 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2398 + SQUASHFS_I(i)->u.s2.directory_index_count =
2400 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2402 + TRACE("Long directory inode %x:%x, start_block %x, "
2404 + SQUASHFS_INODE_BLK(inode), offset,
2405 + inodep->start_block, inodep->offset);
2408 + case SQUASHFS_SYMLINK_TYPE: {
2409 + struct squashfs_symlink_inode_header_2 *inodep =
2411 + struct squashfs_symlink_inode_header_2 *sinodep =
2414 + if (msblk->swap) {
2415 + if (!squashfs_get_cached_block(s, (char *)
2416 + sinodep, block, offset,
2417 + sizeof(*sinodep), &next_block,
2420 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2423 + if (!squashfs_get_cached_block(s, (char *)
2424 + inodep, block, offset,
2425 + sizeof(*inodep), &next_block,
2429 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2430 + goto failed_read1;
2432 + i->i_size = inodep->symlink_size;
2433 + i->i_op = &page_symlink_inode_operations;
2434 + i->i_data.a_ops = &squashfs_symlink_aops;
2435 + i->i_mode |= S_IFLNK;
2436 + SQUASHFS_I(i)->start_block = next_block;
2437 + SQUASHFS_I(i)->offset = next_offset;
2439 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2441 + SQUASHFS_INODE_BLK(inode), offset,
2442 + next_block, next_offset);
2445 + case SQUASHFS_BLKDEV_TYPE:
2446 + case SQUASHFS_CHRDEV_TYPE: {
2447 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2448 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2450 + if (msblk->swap) {
2451 + if (!squashfs_get_cached_block(s, (char *)
2452 + sinodep, block, offset,
2453 + sizeof(*sinodep), &next_block,
2456 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2458 + if (!squashfs_get_cached_block(s, (char *)
2459 + inodep, block, offset,
2460 + sizeof(*inodep), &next_block,
2464 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2465 + goto failed_read1;
2467 + i->i_mode |= (inodeb->inode_type ==
2468 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2470 + init_special_inode(i, i->i_mode, inodep->rdev);
2472 + TRACE("Device inode %x:%x, rdev %x\n",
2473 + SQUASHFS_INODE_BLK(inode), offset,
2477 + case SQUASHFS_FIFO_TYPE:
2478 + case SQUASHFS_SOCKET_TYPE: {
2479 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2480 + goto failed_read1;
2482 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2483 + ? S_IFIFO : S_IFSOCK;
2484 + init_special_inode(i, i->i_mode, 0);
2488 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2489 + inodeb->inode_type);
2490 + goto failed_read1;
2493 + insert_inode_hash(i);
2497 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2504 +static int get_dir_index_using_offset(struct super_block *s, long long
2505 + *next_block, unsigned int *next_offset,
2506 + long long index_start,
2507 + unsigned int index_offset, int i_count,
2510 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2511 + struct squashfs_super_block *sblk = &msblk->sblk;
2512 + int i, length = 0;
2513 + struct squashfs_dir_index_2 index;
2515 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2516 + i_count, (unsigned int) f_pos);
2521 + for (i = 0; i < i_count; i++) {
2522 + if (msblk->swap) {
2523 + struct squashfs_dir_index_2 sindex;
2524 + squashfs_get_cached_block(s, (char *) &sindex,
2525 + index_start, index_offset,
2526 + sizeof(sindex), &index_start,
2528 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2530 + squashfs_get_cached_block(s, (char *) &index,
2531 + index_start, index_offset,
2532 + sizeof(index), &index_start,
2535 + if (index.index > f_pos)
2538 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2539 + index.size + 1, &index_start,
2542 + length = index.index;
2543 + *next_block = index.start_block + sblk->directory_table_start;
2546 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2553 +static int get_dir_index_using_name(struct super_block *s, long long
2554 + *next_block, unsigned int *next_offset,
2555 + long long index_start,
2556 + unsigned int index_offset, int i_count,
2557 + const char *name, int size)
2559 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2560 + struct squashfs_super_block *sblk = &msblk->sblk;
2561 + int i, length = 0;
2562 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2563 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2564 + char str[SQUASHFS_NAME_LEN + 1];
2566 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2568 + strncpy(str, name, size);
2571 + for (i = 0; i < i_count; i++) {
2572 + if (msblk->swap) {
2573 + struct squashfs_dir_index_2 sindex;
2574 + squashfs_get_cached_block(s, (char *) &sindex,
2575 + index_start, index_offset,
2576 + sizeof(sindex), &index_start,
2578 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2580 + squashfs_get_cached_block(s, (char *) index,
2581 + index_start, index_offset,
2582 + sizeof(struct squashfs_dir_index_2),
2583 + &index_start, &index_offset);
2585 + squashfs_get_cached_block(s, index->name, index_start,
2586 + index_offset, index->size + 1,
2587 + &index_start, &index_offset);
2589 + index->name[index->size + 1] = '\0';
2591 + if (strcmp(index->name, str) > 0)
2594 + length = index->index;
2595 + *next_block = index->start_block + sblk->directory_table_start;
2598 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2603 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2605 + struct inode *i = file->f_dentry->d_inode;
2606 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2607 + struct squashfs_super_block *sblk = &msblk->sblk;
2608 + long long next_block = SQUASHFS_I(i)->start_block +
2609 + sblk->directory_table_start;
2610 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2612 + struct squashfs_dir_header_2 dirh;
2613 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2614 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2616 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2618 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2619 + SQUASHFS_I(i)->u.s2.directory_index_start,
2620 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2621 + SQUASHFS_I(i)->u.s2.directory_index_count,
2624 + while (length < i_size_read(i)) {
2625 + /* read directory header */
2626 + if (msblk->swap) {
2627 + struct squashfs_dir_header_2 sdirh;
2629 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2630 + next_block, next_offset, sizeof(sdirh),
2631 + &next_block, &next_offset))
2634 + length += sizeof(sdirh);
2635 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2637 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2638 + next_block, next_offset, sizeof(dirh),
2639 + &next_block, &next_offset))
2642 + length += sizeof(dirh);
2645 + dir_count = dirh.count + 1;
2646 + while (dir_count--) {
2647 + if (msblk->swap) {
2648 + struct squashfs_dir_entry_2 sdire;
2649 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2650 + &sdire, next_block, next_offset,
2651 + sizeof(sdire), &next_block,
2655 + length += sizeof(sdire);
2656 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2658 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2659 + dire, next_block, next_offset,
2660 + sizeof(*dire), &next_block,
2664 + length += sizeof(*dire);
2667 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2668 + next_block, next_offset,
2669 + dire->size + 1, &next_block,
2673 + length += dire->size + 1;
2675 + if (file->f_pos >= length)
2678 + dire->name[dire->size + 1] = '\0';
2680 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2681 + (unsigned int) dirent, dire->name,
2682 + dire->size + 1, (int) file->f_pos,
2683 + dirh.start_block, dire->offset,
2684 + squashfs_filetype_table[dire->type]);
2686 + if (filldir(dirent, dire->name, dire->size + 1,
2687 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2688 + dirh.start_block, dire->offset),
2689 + squashfs_filetype_table[dire->type])
2691 + TRACE("Filldir returned less than 0\n");
2694 + file->f_pos = length;
2703 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2709 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry)
2711 + const unsigned char *name = dentry->d_name.name;
2712 + int len = dentry->d_name.len;
2713 + struct inode *inode = NULL;
2714 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2715 + struct squashfs_super_block *sblk = &msblk->sblk;
2716 + long long next_block = SQUASHFS_I(i)->start_block +
2717 + sblk->directory_table_start;
2718 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2720 + struct squashfs_dir_header_2 dirh;
2721 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2722 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2723 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2725 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2727 + if (len > SQUASHFS_NAME_LEN)
2730 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2731 + SQUASHFS_I(i)->u.s2.directory_index_start,
2732 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2733 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2736 + while (length < i_size_read(i)) {
2737 + /* read directory header */
2738 + if (msblk->swap) {
2739 + struct squashfs_dir_header_2 sdirh;
2740 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2741 + next_block, next_offset, sizeof(sdirh),
2742 + &next_block, &next_offset))
2745 + length += sizeof(sdirh);
2746 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2748 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2749 + next_block, next_offset, sizeof(dirh),
2750 + &next_block, &next_offset))
2753 + length += sizeof(dirh);
2756 + dir_count = dirh.count + 1;
2757 + while (dir_count--) {
2758 + if (msblk->swap) {
2759 + struct squashfs_dir_entry_2 sdire;
2760 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2761 + &sdire, next_block,next_offset,
2762 + sizeof(sdire), &next_block,
2766 + length += sizeof(sdire);
2767 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2769 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2770 + dire, next_block,next_offset,
2771 + sizeof(*dire), &next_block,
2775 + length += sizeof(*dire);
2778 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2779 + next_block, next_offset, dire->size + 1,
2780 + &next_block, &next_offset))
2783 + length += dire->size + 1;
2785 + if (sorted && name[0] < dire->name[0])
2788 + if ((len == dire->size + 1) && !strncmp(name,
2789 + dire->name, len)) {
2790 + squashfs_inode_t ino =
2791 + SQUASHFS_MKINODE(dirh.start_block,
2794 + TRACE("calling squashfs_iget for directory "
2795 + "entry %s, inode %x:%x, %d\n", name,
2796 + dirh.start_block, dire->offset, ino);
2798 + inode = (msblk->iget)(i->i_sb, ino);
2806 + d_add(dentry, inode);
2807 + return ERR_PTR(0);
2810 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2816 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2818 + struct squashfs_super_block *sblk = &msblk->sblk;
2820 + msblk->iget = squashfs_iget_2;
2821 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2823 + sblk->bytes_used = sblk->bytes_used_2;
2824 + sblk->uid_start = sblk->uid_start_2;
2825 + sblk->guid_start = sblk->guid_start_2;
2826 + sblk->inode_table_start = sblk->inode_table_start_2;
2827 + sblk->directory_table_start = sblk->directory_table_start_2;
2828 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2832 diff --new-file -urp linux-2.4.32/fs/squashfs/squashfs.h linux-2.4.32-squashfs3.0/fs/squashfs/squashfs.h
2833 --- linux-2.4.32/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
2834 +++ linux-2.4.32-squashfs3.0/fs/squashfs/squashfs.h 2006-03-07 21:12:36.000000000 +0000
2837 + * Squashfs - a compressed read only filesystem for Linux
2839 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2840 + * Phillip Lougher <phillip@lougher.org.uk>
2842 + * This program is free software; you can redistribute it and/or
2843 + * modify it under the terms of the GNU General Public License
2844 + * as published by the Free Software Foundation; either version 2,
2845 + * or (at your option) any later version.
2847 + * This program is distributed in the hope that it will be useful,
2848 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2849 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2850 + * GNU General Public License for more details.
2852 + * You should have received a copy of the GNU General Public License
2853 + * along with this program; if not, write to the Free Software
2854 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2859 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2860 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2862 +#ifdef SQUASHFS_TRACE
2863 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
2865 +#define TRACE(s, args...) {}
2868 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
2870 +#define SERROR(s, args...) do { \
2872 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
2875 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
2877 +#define SQUASHFS_I(INO) (&INO->u.squashfs_i)
2879 +#define i_size_read(INO) (INO->i_size)
2881 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
2882 +#define SQSH_EXTERN
2883 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
2884 + long long index, unsigned int length,
2885 + long long *next_index);
2886 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
2887 + long long block, unsigned int offset,
2888 + int length, long long *next_block,
2889 + unsigned int *next_offset);
2890 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
2891 + squashfs_fragment_cache *fragment);
2892 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
2893 + *s, long long start_block,
2895 +extern struct address_space_operations squashfs_symlink_aops;
2896 +extern struct address_space_operations squashfs_aops;
2897 +extern struct address_space_operations squashfs_aops_4K;
2898 +extern struct file_operations squashfs_dir_ops;
2899 +extern struct inode_operations squashfs_dir_inode_ops;
2901 +#define SQSH_EXTERN static
2904 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2905 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
2907 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
2913 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2914 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
2916 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2921 diff --new-file -urp linux-2.4.32/include/linux/fs.h linux-2.4.32-squashfs3.0/include/linux/fs.h
2922 --- linux-2.4.32/include/linux/fs.h 2005-04-04 02:42:20.000000000 +0100
2923 +++ linux-2.4.32-squashfs3.0/include/linux/fs.h 2006-03-07 21:12:36.000000000 +0000
2924 @@ -324,6 +324,7 @@ extern void set_bh_page(struct buffer_he
2925 #include <linux/usbdev_fs_i.h>
2926 #include <linux/jffs2_fs_i.h>
2927 #include <linux/cramfs_fs_sb.h>
2928 +#include <linux/squashfs_fs_i.h>
2931 * Attribute flags. These should be or-ed together to figure out what
2932 @@ -519,6 +520,7 @@ struct inode {
2933 struct socket socket_i;
2934 struct usbdev_inode_info usbdev_i;
2935 struct jffs2_inode_info jffs2_i;
2936 + struct squashfs_inode_info squashfs_i;
2940 @@ -734,6 +736,7 @@ struct nameidata {
2941 #include <linux/usbdev_fs_sb.h>
2942 #include <linux/cramfs_fs_sb.h>
2943 #include <linux/jffs2_fs_sb.h>
2944 +#include <linux/squashfs_fs_sb.h>
2946 extern struct list_head super_blocks;
2947 extern spinlock_t sb_lock;
2948 @@ -793,6 +796,7 @@ struct super_block {
2949 struct usbdev_sb_info usbdevfs_sb;
2950 struct jffs2_sb_info jffs2_sb;
2951 struct cramfs_sb_info cramfs_sb;
2952 + struct squashfs_sb_info squashfs_sb;
2956 diff --new-file -urp linux-2.4.32/include/linux/squashfs_fs.h linux-2.4.32-squashfs3.0/include/linux/squashfs_fs.h
2957 --- linux-2.4.32/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
2958 +++ linux-2.4.32-squashfs3.0/include/linux/squashfs_fs.h 2006-03-07 21:12:36.000000000 +0000
2960 +#ifndef SQUASHFS_FS
2961 +#define SQUASHFS_FS
2966 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2967 + * Phillip Lougher <phillip@lougher.org.uk>
2969 + * This program is free software; you can redistribute it and/or
2970 + * modify it under the terms of the GNU General Public License
2971 + * as published by the Free Software Foundation; either version 2,
2972 + * or (at your option) any later version.
2974 + * This program is distributed in the hope that it will be useful,
2975 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2976 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2977 + * GNU General Public License for more details.
2979 + * You should have received a copy of the GNU General Public License
2980 + * along with this program; if not, write to the Free Software
2981 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2986 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2987 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
2990 +#ifdef CONFIG_SQUASHFS_VMALLOC
2991 +#define SQUASHFS_ALLOC(a) vmalloc(a)
2992 +#define SQUASHFS_FREE(a) vfree(a)
2994 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
2995 +#define SQUASHFS_FREE(a) kfree(a)
2997 +#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
2998 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3000 +#define SQUASHFS_CACHED_FRAGMENTS 3
3002 +#define SQUASHFS_MAJOR 3
3003 +#define SQUASHFS_MINOR 0
3004 +#define SQUASHFS_MAGIC 0x73717368
3005 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3006 +#define SQUASHFS_START 0
3008 +/* size of metadata (inode and directory) blocks */
3009 +#define SQUASHFS_METADATA_SIZE 8192
3010 +#define SQUASHFS_METADATA_LOG 13
3012 +/* default size of data blocks */
3013 +#define SQUASHFS_FILE_SIZE 65536
3014 +#define SQUASHFS_FILE_LOG 16
3016 +#define SQUASHFS_FILE_MAX_SIZE 65536
3018 +/* Max number of uids and gids */
3019 +#define SQUASHFS_UIDS 256
3020 +#define SQUASHFS_GUIDS 255
3022 +/* Max length of filename (not 255) */
3023 +#define SQUASHFS_NAME_LEN 256
3025 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3026 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3027 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3028 +#define SQUASHFS_USED_BLK ((long long) -2)
3030 +/* Filesystem flags */
3031 +#define SQUASHFS_NOI 0
3032 +#define SQUASHFS_NOD 1
3033 +#define SQUASHFS_CHECK 2
3034 +#define SQUASHFS_NOF 3
3035 +#define SQUASHFS_NO_FRAG 4
3036 +#define SQUASHFS_ALWAYS_FRAG 5
3037 +#define SQUASHFS_DUPLICATE 6
3039 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3041 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3044 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3047 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3050 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3053 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3054 + SQUASHFS_ALWAYS_FRAG)
3056 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3057 + SQUASHFS_DUPLICATE)
3059 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3062 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3063 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3064 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3065 + (duplicate_checking << 6))
3067 +/* Max number of types and file types */
3068 +#define SQUASHFS_DIR_TYPE 1
3069 +#define SQUASHFS_FILE_TYPE 2
3070 +#define SQUASHFS_SYMLINK_TYPE 3
3071 +#define SQUASHFS_BLKDEV_TYPE 4
3072 +#define SQUASHFS_CHRDEV_TYPE 5
3073 +#define SQUASHFS_FIFO_TYPE 6
3074 +#define SQUASHFS_SOCKET_TYPE 7
3075 +#define SQUASHFS_LDIR_TYPE 8
3076 +#define SQUASHFS_LREG_TYPE 9
3078 +/* 1.0 filesystem type definitions */
3079 +#define SQUASHFS_TYPES 5
3080 +#define SQUASHFS_IPC_TYPE 0
3082 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3084 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3086 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3087 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3089 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3091 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3093 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3094 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3095 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3097 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3100 + * Inode number ops. Inodes consist of a compressed block number, and an
3101 + * uncompressed offset within that block
3103 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3105 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3107 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3110 +/* Compute 32 bit VFS inode number from squashfs inode number */
3111 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3115 +/* Translate between VFS mode and squashfs mode */
3116 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3118 +/* fragment and fragment table defines */
3119 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3121 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3122 + SQUASHFS_METADATA_SIZE)
3124 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3125 + SQUASHFS_METADATA_SIZE)
3127 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3128 + SQUASHFS_METADATA_SIZE - 1) / \
3129 + SQUASHFS_METADATA_SIZE)
3131 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3132 + sizeof(long long))
3134 +/* cached data constants for filesystem */
3135 +#define SQUASHFS_CACHED_BLKS 8
3137 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3139 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3140 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3142 +#define SQUASHFS_MARKER_BYTE 0xff
3144 +/* meta index cache */
3145 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3146 +#define SQUASHFS_META_ENTRIES 31
3147 +#define SQUASHFS_META_NUMBER 8
3148 +#define SQUASHFS_SLOTS 4
3150 +struct meta_entry {
3151 + long long data_block;
3152 + unsigned int index_block;
3153 + unsigned short offset;
3154 + unsigned short pad;
3157 +struct meta_index {
3158 + unsigned int inode_number;
3159 + unsigned int offset;
3160 + unsigned short entries;
3161 + unsigned short skip;
3162 + unsigned short locked;
3163 + unsigned short pad;
3164 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3169 + * definitions for structures on disk
3172 +typedef long long squashfs_block_t;
3173 +typedef long long squashfs_inode_t;
3175 +struct squashfs_super_block {
3176 + unsigned int s_magic;
3177 + unsigned int inodes;
3178 + unsigned int bytes_used_2;
3179 + unsigned int uid_start_2;
3180 + unsigned int guid_start_2;
3181 + unsigned int inode_table_start_2;
3182 + unsigned int directory_table_start_2;
3183 + unsigned int s_major:16;
3184 + unsigned int s_minor:16;
3185 + unsigned int block_size_1:16;
3186 + unsigned int block_log:16;
3187 + unsigned int flags:8;
3188 + unsigned int no_uids:8;
3189 + unsigned int no_guids:8;
3190 + unsigned int mkfs_time /* time of filesystem creation */;
3191 + squashfs_inode_t root_inode;
3192 + unsigned int block_size;
3193 + unsigned int fragments;
3194 + unsigned int fragment_table_start_2;
3195 + long long bytes_used;
3196 + long long uid_start;
3197 + long long guid_start;
3198 + long long inode_table_start;
3199 + long long directory_table_start;
3200 + long long fragment_table_start;
3202 +} __attribute__ ((packed));
3204 +struct squashfs_dir_index {
3205 + unsigned int index;
3206 + unsigned int start_block;
3207 + unsigned char size;
3208 + unsigned char name[0];
3209 +} __attribute__ ((packed));
3211 +#define SQUASHFS_BASE_INODE_HEADER \
3212 + unsigned int inode_type:4; \
3213 + unsigned int mode:12; \
3214 + unsigned int uid:8; \
3215 + unsigned int guid:8; \
3216 + unsigned int mtime; \
3217 + unsigned int inode_number;
3219 +struct squashfs_base_inode_header {
3220 + SQUASHFS_BASE_INODE_HEADER;
3221 +} __attribute__ ((packed));
3223 +struct squashfs_ipc_inode_header {
3224 + SQUASHFS_BASE_INODE_HEADER;
3225 + unsigned int nlink;
3226 +} __attribute__ ((packed));
3228 +struct squashfs_dev_inode_header {
3229 + SQUASHFS_BASE_INODE_HEADER;
3230 + unsigned int nlink;
3231 + unsigned short rdev;
3232 +} __attribute__ ((packed));
3234 +struct squashfs_symlink_inode_header {
3235 + SQUASHFS_BASE_INODE_HEADER;
3236 + unsigned int nlink;
3237 + unsigned short symlink_size;
3239 +} __attribute__ ((packed));
3241 +struct squashfs_reg_inode_header {
3242 + SQUASHFS_BASE_INODE_HEADER;
3243 + squashfs_block_t start_block;
3244 + unsigned int fragment;
3245 + unsigned int offset;
3246 + unsigned int file_size;
3247 + unsigned short block_list[0];
3248 +} __attribute__ ((packed));
3250 +struct squashfs_lreg_inode_header {
3251 + SQUASHFS_BASE_INODE_HEADER;
3252 + unsigned int nlink;
3253 + squashfs_block_t start_block;
3254 + unsigned int fragment;
3255 + unsigned int offset;
3256 + long long file_size;
3257 + unsigned short block_list[0];
3258 +} __attribute__ ((packed));
3260 +struct squashfs_dir_inode_header {
3261 + SQUASHFS_BASE_INODE_HEADER;
3262 + unsigned int nlink;
3263 + unsigned int file_size:19;
3264 + unsigned int offset:13;
3265 + unsigned int start_block;
3266 + unsigned int parent_inode;
3267 +} __attribute__ ((packed));
3269 +struct squashfs_ldir_inode_header {
3270 + SQUASHFS_BASE_INODE_HEADER;
3271 + unsigned int nlink;
3272 + unsigned int file_size:27;
3273 + unsigned int offset:13;
3274 + unsigned int start_block;
3275 + unsigned int i_count:16;
3276 + unsigned int parent_inode;
3277 + struct squashfs_dir_index index[0];
3278 +} __attribute__ ((packed));
3280 +union squashfs_inode_header {
3281 + struct squashfs_base_inode_header base;
3282 + struct squashfs_dev_inode_header dev;
3283 + struct squashfs_symlink_inode_header symlink;
3284 + struct squashfs_reg_inode_header reg;
3285 + struct squashfs_lreg_inode_header lreg;
3286 + struct squashfs_dir_inode_header dir;
3287 + struct squashfs_ldir_inode_header ldir;
3288 + struct squashfs_ipc_inode_header ipc;
3291 +struct squashfs_dir_entry {
3292 + unsigned int offset:13;
3293 + unsigned int type:3;
3294 + unsigned int size:8;
3295 + int inode_number:16;
3297 +} __attribute__ ((packed));
3299 +struct squashfs_dir_header {
3300 + unsigned int count:8;
3301 + unsigned int start_block;
3302 + unsigned int inode_number;
3303 +} __attribute__ ((packed));
3305 +struct squashfs_fragment_entry {
3306 + long long start_block;
3307 + unsigned int size;
3308 + unsigned int unused;
3309 +} __attribute__ ((packed));
3311 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3312 +extern int squashfs_uncompress_init(void);
3313 +extern int squashfs_uncompress_exit(void);
3316 + * macros to convert each packed bitfield structure from little endian to big
3317 + * endian and vice versa. These are needed when creating or using a filesystem
3318 + * on a machine with different byte ordering to the target architecture.
3322 +#define SQUASHFS_SWAP_START \
3325 + unsigned long long val;\
3326 + unsigned char *s;\
3329 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3330 + SQUASHFS_SWAP_START\
3331 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3332 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3333 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3334 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3335 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3336 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3337 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3338 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3339 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3340 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3341 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3342 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3343 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3344 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3345 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3346 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3347 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3348 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3349 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3350 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3351 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3352 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3353 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3354 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3355 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3356 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3357 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3360 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3361 + SQUASHFS_MEMSET(s, d, n);\
3362 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3363 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3364 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3365 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3366 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3367 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3369 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3370 + SQUASHFS_SWAP_START\
3371 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3374 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3375 + SQUASHFS_SWAP_START\
3376 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3377 + sizeof(struct squashfs_ipc_inode_header))\
3378 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3381 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3382 + SQUASHFS_SWAP_START\
3383 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3384 + sizeof(struct squashfs_dev_inode_header)); \
3385 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3386 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3389 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3390 + SQUASHFS_SWAP_START\
3391 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3392 + sizeof(struct squashfs_symlink_inode_header));\
3393 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3394 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3397 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3398 + SQUASHFS_SWAP_START\
3399 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3400 + sizeof(struct squashfs_reg_inode_header));\
3401 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3402 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3403 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3404 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3407 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3408 + SQUASHFS_SWAP_START\
3409 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3410 + sizeof(struct squashfs_lreg_inode_header));\
3411 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3412 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3413 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3414 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3415 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3418 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3419 + SQUASHFS_SWAP_START\
3420 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3421 + sizeof(struct squashfs_dir_inode_header));\
3422 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3423 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3424 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3425 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3426 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3429 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3430 + SQUASHFS_SWAP_START\
3431 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3432 + sizeof(struct squashfs_ldir_inode_header));\
3433 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3434 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3435 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3436 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3437 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3438 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3441 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3442 + SQUASHFS_SWAP_START\
3443 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3444 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3445 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3446 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3449 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3450 + SQUASHFS_SWAP_START\
3451 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3452 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3453 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3454 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3457 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3458 + SQUASHFS_SWAP_START\
3459 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3460 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3461 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3462 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3463 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3466 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3467 + SQUASHFS_SWAP_START\
3468 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3469 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3470 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3473 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3475 + int bit_position;\
3476 + SQUASHFS_SWAP_START\
3477 + SQUASHFS_MEMSET(s, d, n * 2);\
3478 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3480 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3483 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3485 + int bit_position;\
3486 + SQUASHFS_SWAP_START\
3487 + SQUASHFS_MEMSET(s, d, n * 4);\
3488 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3490 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3493 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3495 + int bit_position;\
3496 + SQUASHFS_SWAP_START\
3497 + SQUASHFS_MEMSET(s, d, n * 8);\
3498 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3500 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3503 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3505 + int bit_position;\
3506 + SQUASHFS_SWAP_START\
3507 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3508 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3510 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3513 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3515 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3517 +struct squashfs_base_inode_header_1 {
3518 + unsigned int inode_type:4;
3519 + unsigned int mode:12; /* protection */
3520 + unsigned int uid:4; /* index into uid table */
3521 + unsigned int guid:4; /* index into guid table */
3522 +} __attribute__ ((packed));
3524 +struct squashfs_ipc_inode_header_1 {
3525 + unsigned int inode_type:4;
3526 + unsigned int mode:12; /* protection */
3527 + unsigned int uid:4; /* index into uid table */
3528 + unsigned int guid:4; /* index into guid table */
3529 + unsigned int type:4;
3530 + unsigned int offset:4;
3531 +} __attribute__ ((packed));
3533 +struct squashfs_dev_inode_header_1 {
3534 + unsigned int inode_type:4;
3535 + unsigned int mode:12; /* protection */
3536 + unsigned int uid:4; /* index into uid table */
3537 + unsigned int guid:4; /* index into guid table */
3538 + unsigned short rdev;
3539 +} __attribute__ ((packed));
3541 +struct squashfs_symlink_inode_header_1 {
3542 + unsigned int inode_type:4;
3543 + unsigned int mode:12; /* protection */
3544 + unsigned int uid:4; /* index into uid table */
3545 + unsigned int guid:4; /* index into guid table */
3546 + unsigned short symlink_size;
3548 +} __attribute__ ((packed));
3550 +struct squashfs_reg_inode_header_1 {
3551 + unsigned int inode_type:4;
3552 + unsigned int mode:12; /* protection */
3553 + unsigned int uid:4; /* index into uid table */
3554 + unsigned int guid:4; /* index into guid table */
3555 + unsigned int mtime;
3556 + unsigned int start_block;
3557 + unsigned int file_size:32;
3558 + unsigned short block_list[0];
3559 +} __attribute__ ((packed));
3561 +struct squashfs_dir_inode_header_1 {
3562 + unsigned int inode_type:4;
3563 + unsigned int mode:12; /* protection */
3564 + unsigned int uid:4; /* index into uid table */
3565 + unsigned int guid:4; /* index into guid table */
3566 + unsigned int file_size:19;
3567 + unsigned int offset:13;
3568 + unsigned int mtime;
3569 + unsigned int start_block:24;
3570 +} __attribute__ ((packed));
3572 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3573 + SQUASHFS_MEMSET(s, d, n);\
3574 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3575 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3576 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3577 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3579 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3580 + SQUASHFS_SWAP_START\
3581 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3584 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3585 + SQUASHFS_SWAP_START\
3586 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3587 + sizeof(struct squashfs_ipc_inode_header_1));\
3588 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3589 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3592 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3593 + SQUASHFS_SWAP_START\
3594 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3595 + sizeof(struct squashfs_dev_inode_header_1));\
3596 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3599 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3600 + SQUASHFS_SWAP_START\
3601 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3602 + sizeof(struct squashfs_symlink_inode_header_1));\
3603 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3606 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3609 + sizeof(struct squashfs_reg_inode_header_1));\
3610 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3611 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3612 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3615 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3616 + SQUASHFS_SWAP_START\
3617 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3618 + sizeof(struct squashfs_dir_inode_header_1));\
3619 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3620 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3621 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3622 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3627 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3629 +struct squashfs_dir_index_2 {
3630 + unsigned int index:27;
3631 + unsigned int start_block:29;
3632 + unsigned char size;
3633 + unsigned char name[0];
3634 +} __attribute__ ((packed));
3636 +struct squashfs_base_inode_header_2 {
3637 + unsigned int inode_type:4;
3638 + unsigned int mode:12; /* protection */
3639 + unsigned int uid:8; /* index into uid table */
3640 + unsigned int guid:8; /* index into guid table */
3641 +} __attribute__ ((packed));
3643 +struct squashfs_ipc_inode_header_2 {
3644 + unsigned int inode_type:4;
3645 + unsigned int mode:12; /* protection */
3646 + unsigned int uid:8; /* index into uid table */
3647 + unsigned int guid:8; /* index into guid table */
3648 +} __attribute__ ((packed));
3650 +struct squashfs_dev_inode_header_2 {
3651 + unsigned int inode_type:4;
3652 + unsigned int mode:12; /* protection */
3653 + unsigned int uid:8; /* index into uid table */
3654 + unsigned int guid:8; /* index into guid table */
3655 + unsigned short rdev;
3656 +} __attribute__ ((packed));
3658 +struct squashfs_symlink_inode_header_2 {
3659 + unsigned int inode_type:4;
3660 + unsigned int mode:12; /* protection */
3661 + unsigned int uid:8; /* index into uid table */
3662 + unsigned int guid:8; /* index into guid table */
3663 + unsigned short symlink_size;
3665 +} __attribute__ ((packed));
3667 +struct squashfs_reg_inode_header_2 {
3668 + unsigned int inode_type:4;
3669 + unsigned int mode:12; /* protection */
3670 + unsigned int uid:8; /* index into uid table */
3671 + unsigned int guid:8; /* index into guid table */
3672 + unsigned int mtime;
3673 + unsigned int start_block;
3674 + unsigned int fragment;
3675 + unsigned int offset;
3676 + unsigned int file_size:32;
3677 + unsigned short block_list[0];
3678 +} __attribute__ ((packed));
3680 +struct squashfs_dir_inode_header_2 {
3681 + unsigned int inode_type:4;
3682 + unsigned int mode:12; /* protection */
3683 + unsigned int uid:8; /* index into uid table */
3684 + unsigned int guid:8; /* index into guid table */
3685 + unsigned int file_size:19;
3686 + unsigned int offset:13;
3687 + unsigned int mtime;
3688 + unsigned int start_block:24;
3689 +} __attribute__ ((packed));
3691 +struct squashfs_ldir_inode_header_2 {
3692 + unsigned int inode_type:4;
3693 + unsigned int mode:12; /* protection */
3694 + unsigned int uid:8; /* index into uid table */
3695 + unsigned int guid:8; /* index into guid table */
3696 + unsigned int file_size:27;
3697 + unsigned int offset:13;
3698 + unsigned int mtime;
3699 + unsigned int start_block:24;
3700 + unsigned int i_count:16;
3701 + struct squashfs_dir_index_2 index[0];
3702 +} __attribute__ ((packed));
3704 +union squashfs_inode_header_2 {
3705 + struct squashfs_base_inode_header_2 base;
3706 + struct squashfs_dev_inode_header_2 dev;
3707 + struct squashfs_symlink_inode_header_2 symlink;
3708 + struct squashfs_reg_inode_header_2 reg;
3709 + struct squashfs_dir_inode_header_2 dir;
3710 + struct squashfs_ldir_inode_header_2 ldir;
3711 + struct squashfs_ipc_inode_header_2 ipc;
3714 +struct squashfs_dir_header_2 {
3715 + unsigned int count:8;
3716 + unsigned int start_block:24;
3717 +} __attribute__ ((packed));
3719 +struct squashfs_dir_entry_2 {
3720 + unsigned int offset:13;
3721 + unsigned int type:3;
3722 + unsigned int size:8;
3724 +} __attribute__ ((packed));
3726 +struct squashfs_fragment_entry_2 {
3727 + unsigned int start_block;
3728 + unsigned int size;
3729 +} __attribute__ ((packed));
3731 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3732 + SQUASHFS_MEMSET(s, d, n);\
3733 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3734 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3735 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3736 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3738 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3739 + SQUASHFS_SWAP_START\
3740 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3743 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3744 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3746 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3747 + SQUASHFS_SWAP_START\
3748 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3749 + sizeof(struct squashfs_dev_inode_header_2)); \
3750 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3753 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3754 + SQUASHFS_SWAP_START\
3755 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3756 + sizeof(struct squashfs_symlink_inode_header_2));\
3757 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3760 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3761 + SQUASHFS_SWAP_START\
3762 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3763 + sizeof(struct squashfs_reg_inode_header_2));\
3764 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3765 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3766 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3767 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3768 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3771 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3772 + SQUASHFS_SWAP_START\
3773 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3774 + sizeof(struct squashfs_dir_inode_header_2));\
3775 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3776 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3777 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3778 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3781 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3782 + SQUASHFS_SWAP_START\
3783 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3784 + sizeof(struct squashfs_ldir_inode_header_2));\
3785 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3786 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3787 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3788 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3789 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3792 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3793 + SQUASHFS_SWAP_START\
3794 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3795 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3796 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3797 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3799 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3800 + SQUASHFS_SWAP_START\
3801 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3802 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3803 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3806 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3807 + SQUASHFS_SWAP_START\
3808 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3809 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3810 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3811 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3814 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3815 + SQUASHFS_SWAP_START\
3816 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3817 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3818 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3821 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3823 +/* fragment and fragment table defines */
3824 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3826 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3827 + SQUASHFS_METADATA_SIZE)
3829 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3830 + SQUASHFS_METADATA_SIZE)
3832 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3833 + SQUASHFS_METADATA_SIZE - 1) / \
3834 + SQUASHFS_METADATA_SIZE)
3836 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3844 + * macros used to swap each structure entry, taking into account
3845 + * bitfields and different bitfield placing conventions on differing
3849 +#include <asm/byteorder.h>
3851 +#ifdef __BIG_ENDIAN
3852 + /* convert from little endian to big endian */
3853 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3856 + /* convert from big endian to little endian */
3857 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3858 + tbits, 64 - tbits - b_pos)
3861 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3864 + s = (unsigned char *)p + (pos / 8);\
3865 + d = ((unsigned char *) &val) + 7;\
3866 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3868 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3871 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3875 diff --new-file -urp linux-2.4.32/include/linux/squashfs_fs_i.h linux-2.4.32-squashfs3.0/include/linux/squashfs_fs_i.h
3876 --- linux-2.4.32/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
3877 +++ linux-2.4.32-squashfs3.0/include/linux/squashfs_fs_i.h 2006-03-07 21:12:36.000000000 +0000
3879 +#ifndef SQUASHFS_FS_I
3880 +#define SQUASHFS_FS_I
3884 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3885 + * Phillip Lougher <phillip@lougher.org.uk>
3887 + * This program is free software; you can redistribute it and/or
3888 + * modify it under the terms of the GNU General Public License
3889 + * as published by the Free Software Foundation; either version 2,
3890 + * or (at your option) any later version.
3892 + * This program is distributed in the hope that it will be useful,
3893 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3894 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3895 + * GNU General Public License for more details.
3897 + * You should have received a copy of the GNU General Public License
3898 + * along with this program; if not, write to the Free Software
3899 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3904 +struct squashfs_inode_info {
3905 + long long start_block;
3906 + unsigned int offset;
3909 + long long fragment_start_block;
3910 + unsigned int fragment_size;
3911 + unsigned int fragment_offset;
3912 + long long block_list_start;
3915 + long long directory_index_start;
3916 + unsigned int directory_index_offset;
3917 + unsigned int directory_index_count;
3918 + unsigned int parent_inode;
3923 diff --new-file -urp linux-2.4.32/include/linux/squashfs_fs_sb.h linux-2.4.32-squashfs3.0/include/linux/squashfs_fs_sb.h
3924 --- linux-2.4.32/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
3925 +++ linux-2.4.32-squashfs3.0/include/linux/squashfs_fs_sb.h 2006-03-07 21:12:36.000000000 +0000
3927 +#ifndef SQUASHFS_FS_SB
3928 +#define SQUASHFS_FS_SB
3932 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3933 + * Phillip Lougher <phillip@lougher.org.uk>
3935 + * This program is free software; you can redistribute it and/or
3936 + * modify it under the terms of the GNU General Public License
3937 + * as published by the Free Software Foundation; either version 2,
3938 + * or (at your option) any later version.
3940 + * This program is distributed in the hope that it will be useful,
3941 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3942 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3943 + * GNU General Public License for more details.
3945 + * You should have received a copy of the GNU General Public License
3946 + * along with this program; if not, write to the Free Software
3947 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3949 + * squashfs_fs_sb.h
3952 +#include <linux/squashfs_fs.h>
3954 +struct squashfs_cache {
3957 + long long next_index;
3961 +struct squashfs_fragment_cache {
3964 + unsigned int locked;
3968 +struct squashfs_sb_info {
3969 + struct squashfs_super_block sblk;
3971 + int devblksize_log2;
3973 + struct squashfs_cache *block_cache;
3974 + struct squashfs_fragment_cache *fragment;
3976 + int next_fragment;
3977 + int next_meta_index;
3978 + unsigned int *uid;
3979 + unsigned int *guid;
3980 + long long *fragment_index;
3981 + unsigned int *fragment_index_2;
3982 + unsigned int read_size;
3985 + struct semaphore read_data_mutex;
3986 + struct semaphore read_page_mutex;
3987 + struct semaphore block_cache_mutex;
3988 + struct semaphore fragment_mutex;
3989 + struct semaphore meta_index_mutex;
3990 + wait_queue_head_t waitq;
3991 + wait_queue_head_t fragment_wait_queue;
3992 + struct meta_index *meta_index;
3993 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
3995 + long long (*read_blocklist)(struct inode *inode, int \
3996 + index, int readahead_blks, char *block_list, \
3997 + unsigned short **block_p, unsigned int *bsize);
3998 + int (*read_fragment_index_table)(struct super_block *s);
4001 diff --new-file -urp linux-2.4.32/init/do_mounts.c linux-2.4.32-squashfs3.0/init/do_mounts.c
4002 --- linux-2.4.32/init/do_mounts.c 2003-11-28 18:26:21.000000000 +0000
4003 +++ linux-2.4.32-squashfs3.0/init/do_mounts.c 2006-03-07 21:12:36.000000000 +0000
4005 #include <linux/minix_fs.h>
4006 #include <linux/ext2_fs.h>
4007 #include <linux/romfs_fs.h>
4008 +#include <linux/squashfs_fs.h>
4009 #include <linux/cramfs_fs.h>
4011 #define BUILD_CRAMDISK
4012 @@ -476,6 +477,7 @@ static int __init crd_load(int in_fd, in
4020 @@ -486,6 +488,7 @@ identify_ramdisk_image(int fd, int start
4021 struct minix_super_block *minixsb;
4022 struct ext2_super_block *ext2sb;
4023 struct romfs_super_block *romfsb;
4024 + struct squashfs_super_block *squashfsb;
4025 struct cramfs_super *cramfsb;
4028 @@ -497,6 +500,7 @@ identify_ramdisk_image(int fd, int start
4029 minixsb = (struct minix_super_block *) buf;
4030 ext2sb = (struct ext2_super_block *) buf;
4031 romfsb = (struct romfs_super_block *) buf;
4032 + squashfsb = (struct squashfs_super_block *) buf;
4033 cramfsb = (struct cramfs_super *) buf;
4034 memset(buf, 0xe5, size);
4036 @@ -535,6 +539,15 @@ identify_ramdisk_image(int fd, int start
4040 + /* squashfs is at block zero too */
4041 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4042 + printk(KERN_NOTICE
4043 + "RAMDISK: squashfs filesystem found at block %d\n",
4045 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4050 * Read block 1 to test for minix and ext2 superblock
4052 diff --new-file -urp linux-2.4.32/lib/Config.in linux-2.4.32-squashfs3.0/lib/Config.in
4053 --- linux-2.4.32/lib/Config.in 2003-11-28 18:26:21.000000000 +0000
4054 +++ linux-2.4.32-squashfs3.0/lib/Config.in 2006-03-07 21:12:36.000000000 +0000
4055 @@ -10,6 +10,7 @@ tristate 'CRC32 functions' CONFIG_CRC32
4056 # Do we need the compression support?
4058 if [ "$CONFIG_CRAMFS" = "y" -o \
4059 + "$CONFIG_SQUASHFS" = "y" -o \
4060 "$CONFIG_PPP_DEFLATE" = "y" -o \
4061 "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
4062 "$CONFIG_JFFS2_FS" = "y" -o \
4063 @@ -17,6 +18,7 @@ if [ "$CONFIG_CRAMFS" = "y" -o \
4064 define_tristate CONFIG_ZLIB_INFLATE y
4066 if [ "$CONFIG_CRAMFS" = "m" -o \
4067 + "$CONFIG_SQUASHFS" = "m" -o \
4068 "$CONFIG_PPP_DEFLATE" = "m" -o \
4069 "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
4070 "$CONFIG_JFFS2_FS" = "m" -o \