1 Index: linux-2.4.35.4/fs/Config.in
2 ===================================================================
3 --- linux-2.4.35.4.orig/fs/Config.in
4 +++ linux-2.4.35.4/fs/Config.in
5 @@ -51,6 +51,14 @@ if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFI
6 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
8 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
9 +tristate 'Squashed file system support' CONFIG_SQUASHFS
10 +if [ "$CONFIG_SQUASHFS" = "y" -o "$CONFIG_SQUASHFS" = "m" ] ; then
11 +bool 'Additional options for memory constrained systems ' CONFIG_SQUASHFS_EMBEDDED
13 +if [ "$CONFIG_SQUASHFS_EMBEDDED" = "y" ] ; then
14 +int 'Number of fragments cached' CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE 3
15 +bool 'Use Vmalloc rather than Kmalloc' CONFIG_SQUASHFS_VMALLOC
17 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
18 define_bool CONFIG_RAMFS y
20 Index: linux-2.4.35.4/fs/Makefile
21 ===================================================================
22 --- linux-2.4.35.4.orig/fs/Makefile
23 +++ linux-2.4.35.4/fs/Makefile
24 @@ -65,6 +65,7 @@ subdir-$(CONFIG_REISERFS_FS) += reiserfs
25 subdir-$(CONFIG_DEVPTS_FS) += devpts
26 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
27 subdir-$(CONFIG_BEFS_FS) += befs
28 +subdir-$(CONFIG_SQUASHFS) += squashfs
29 subdir-$(CONFIG_JFS_FS) += jfs
30 subdir-$(CONFIG_XFS_FS) += xfs
32 Index: linux-2.4.35.4/fs/squashfs/inode.c
33 ===================================================================
35 +++ linux-2.4.35.4/fs/squashfs/inode.c
38 + * Squashfs - a compressed read only filesystem for Linux
40 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
41 + * Phillip Lougher <phillip@lougher.org.uk>
43 + * This program is free software; you can redistribute it and/or
44 + * modify it under the terms of the GNU General Public License
45 + * as published by the Free Software Foundation; either version 2,
46 + * or (at your option) any later version.
48 + * This program is distributed in the hope that it will be useful,
49 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 + * GNU General Public License for more details.
53 + * You should have received a copy of the GNU General Public License
54 + * along with this program; if not, write to the Free Software
55 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
60 +#include <linux/types.h>
61 +#include <linux/squashfs_fs.h>
62 +#include <linux/module.h>
63 +#include <linux/errno.h>
64 +#include <linux/slab.h>
65 +#include <linux/fs.h>
66 +#include <linux/smp_lock.h>
67 +#include <linux/locks.h>
68 +#include <linux/init.h>
69 +#include <linux/dcache.h>
70 +#include <linux/wait.h>
71 +#include <linux/zlib.h>
72 +#include <linux/blkdev.h>
73 +#include <linux/vmalloc.h>
74 +#include <asm/uaccess.h>
75 +#include <asm/semaphore.h>
77 +#include "squashfs.h"
79 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
80 +static void squashfs_put_super(struct super_block *);
81 +static int squashfs_statfs(struct super_block *, struct statfs *);
82 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
83 +static int squashfs_readpage(struct file *file, struct page *page);
84 +static int squashfs_readpage4K(struct file *file, struct page *page);
85 +static int squashfs_readdir(struct file *, void *, filldir_t);
86 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
87 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
88 +static long long read_blocklist(struct inode *inode, int index,
89 + int readahead_blks, char *block_list,
90 + unsigned short **block_p, unsigned int *bsize);
92 +static z_stream stream;
94 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
96 +static unsigned char squashfs_filetype_table[] = {
97 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
100 +static struct super_operations squashfs_ops = {
101 + .statfs = squashfs_statfs,
102 + .put_super = squashfs_put_super,
105 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
106 + .readpage = squashfs_symlink_readpage
109 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
110 + .readpage = squashfs_readpage
113 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
114 + .readpage = squashfs_readpage4K
117 +static struct file_operations squashfs_dir_ops = {
118 + .read = generic_read_dir,
119 + .readdir = squashfs_readdir
122 +static struct inode_operations squashfs_dir_inode_ops = {
123 + .lookup = squashfs_lookup
126 +static struct buffer_head *get_block_length(struct super_block *s,
127 + int *cur_index, int *offset, int *c_byte)
129 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
130 + unsigned short temp;
131 + struct buffer_head *bh;
133 + if (!(bh = sb_bread(s, *cur_index)))
136 + if (msblk->devblksize - *offset == 1) {
138 + ((unsigned char *) &temp)[1] = *((unsigned char *)
139 + (bh->b_data + *offset));
141 + ((unsigned char *) &temp)[0] = *((unsigned char *)
142 + (bh->b_data + *offset));
144 + if (!(bh = sb_bread(s, ++(*cur_index))))
147 + ((unsigned char *) &temp)[0] = *((unsigned char *)
150 + ((unsigned char *) &temp)[1] = *((unsigned char *)
156 + ((unsigned char *) &temp)[1] = *((unsigned char *)
157 + (bh->b_data + *offset));
158 + ((unsigned char *) &temp)[0] = *((unsigned char *)
159 + (bh->b_data + *offset + 1));
161 + ((unsigned char *) &temp)[0] = *((unsigned char *)
162 + (bh->b_data + *offset));
163 + ((unsigned char *) &temp)[1] = *((unsigned char *)
164 + (bh->b_data + *offset + 1));
170 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
171 + if (*offset == msblk->devblksize) {
173 + if (!(bh = sb_bread(s, ++(*cur_index))))
177 + if (*((unsigned char *) (bh->b_data + *offset)) !=
178 + SQUASHFS_MARKER_BYTE) {
179 + ERROR("Metadata block marker corrupt @ %x\n",
193 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
194 + long long index, unsigned int length,
195 + long long *next_index)
197 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
198 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
199 + msblk->devblksize_log2) + 2];
200 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
201 + unsigned int cur_index = index >> msblk->devblksize_log2;
202 + int bytes, avail_bytes, b = 0, k;
204 + unsigned int compressed;
205 + unsigned int c_byte = length;
208 + bytes = msblk->devblksize - offset;
209 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
210 + c_buffer = compressed ? msblk->read_data : buffer;
211 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
213 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
214 + ? "" : "un", (unsigned int) c_byte);
216 + if (!(bh[0] = sb_getblk(s, cur_index)))
217 + goto block_release;
219 + for (b = 1; bytes < c_byte; b++) {
220 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
221 + goto block_release;
222 + bytes += msblk->devblksize;
224 + ll_rw_block(READ, b, bh);
226 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
230 + bytes = msblk->devblksize - offset;
231 + compressed = SQUASHFS_COMPRESSED(c_byte);
232 + c_buffer = compressed ? msblk->read_data : buffer;
233 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
235 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
236 + ? "" : "un", (unsigned int) c_byte);
238 + for (b = 1; bytes < c_byte; b++) {
239 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
240 + goto block_release;
241 + bytes += msblk->devblksize;
243 + ll_rw_block(READ, b - 1, bh + 1);
247 + down(&msblk->read_data_mutex);
249 + for (bytes = 0, k = 0; k < b; k++) {
250 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
251 + msblk->devblksize - offset :
253 + wait_on_buffer(bh[k]);
254 + if (!buffer_uptodate(bh[k]))
255 + goto block_release;
256 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
257 + bytes += avail_bytes;
268 + stream.next_in = c_buffer;
269 + stream.avail_in = c_byte;
270 + stream.next_out = buffer;
271 + stream.avail_out = msblk->read_size;
273 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
274 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
275 + != Z_STREAM_END) || ((zlib_err =
276 + zlib_inflateEnd(&stream)) != Z_OK)) {
277 + ERROR("zlib_fs returned unexpected result 0x%x\n",
281 + bytes = stream.total_out;
283 + up(&msblk->read_data_mutex);
287 + *next_index = index + c_byte + (length ? 0 :
288 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
297 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
302 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
303 + long long block, unsigned int offset,
304 + int length, long long *next_block,
305 + unsigned int *next_offset)
307 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
308 + int n, i, bytes, return_length = length;
309 + long long next_index;
311 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
314 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
315 + if (msblk->block_cache[i].block == block)
318 + down(&msblk->block_cache_mutex);
320 + if (i == SQUASHFS_CACHED_BLKS) {
321 + /* read inode header block */
322 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
323 + n ; n --, i = (i + 1) %
324 + SQUASHFS_CACHED_BLKS)
325 + if (msblk->block_cache[i].block !=
332 + init_waitqueue_entry(&wait, current);
333 + add_wait_queue(&msblk->waitq, &wait);
334 + set_current_state(TASK_UNINTERRUPTIBLE);
335 + up(&msblk->block_cache_mutex);
337 + set_current_state(TASK_RUNNING);
338 + remove_wait_queue(&msblk->waitq, &wait);
341 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
343 + if (msblk->block_cache[i].block ==
344 + SQUASHFS_INVALID_BLK) {
345 + if (!(msblk->block_cache[i].data =
346 + kmalloc(SQUASHFS_METADATA_SIZE,
348 + ERROR("Failed to allocate cache"
350 + up(&msblk->block_cache_mutex);
355 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
356 + up(&msblk->block_cache_mutex);
358 + if (!(msblk->block_cache[i].length =
359 + squashfs_read_data(s,
360 + msblk->block_cache[i].data,
361 + block, 0, &next_index))) {
362 + ERROR("Unable to read cache block [%llx:%x]\n",
367 + down(&msblk->block_cache_mutex);
368 + wake_up(&msblk->waitq);
369 + msblk->block_cache[i].block = block;
370 + msblk->block_cache[i].next_index = next_index;
371 + TRACE("Read cache block [%llx:%x]\n", block, offset);
374 + if (msblk->block_cache[i].block != block) {
375 + up(&msblk->block_cache_mutex);
379 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
381 + memcpy(buffer, msblk->block_cache[i].data +
383 + if (msblk->block_cache[i].length - offset == length) {
384 + *next_block = msblk->block_cache[i].next_index;
387 + *next_block = block;
388 + *next_offset = offset + length;
390 + up(&msblk->block_cache_mutex);
394 + memcpy(buffer, msblk->block_cache[i].data +
398 + block = msblk->block_cache[i].next_index;
399 + up(&msblk->block_cache_mutex);
406 + return return_length;
412 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
413 + long long *fragment_start_block,
414 + unsigned int *fragment_size)
416 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
417 + long long start_block =
418 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
419 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
420 + struct squashfs_fragment_entry fragment_entry;
423 + struct squashfs_fragment_entry sfragment_entry;
425 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
426 + start_block, offset,
427 + sizeof(sfragment_entry), &start_block,
430 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
432 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
433 + start_block, offset,
434 + sizeof(fragment_entry), &start_block,
438 + *fragment_start_block = fragment_entry.start_block;
439 + *fragment_size = fragment_entry.size;
448 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
449 + squashfs_fragment_cache *fragment)
451 + down(&msblk->fragment_mutex);
452 + fragment->locked --;
453 + wake_up(&msblk->fragment_wait_queue);
454 + up(&msblk->fragment_mutex);
458 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
459 + *s, long long start_block,
463 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
466 + down(&msblk->fragment_mutex);
468 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
469 + msblk->fragment[i].block != start_block; i++);
471 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
472 + for (i = msblk->next_fragment, n =
473 + SQUASHFS_CACHED_FRAGMENTS; n &&
474 + msblk->fragment[i].locked; n--, i = (i + 1) %
475 + SQUASHFS_CACHED_FRAGMENTS);
480 + init_waitqueue_entry(&wait, current);
481 + add_wait_queue(&msblk->fragment_wait_queue,
483 + set_current_state(TASK_UNINTERRUPTIBLE);
484 + up(&msblk->fragment_mutex);
486 + set_current_state(TASK_RUNNING);
487 + remove_wait_queue(&msblk->fragment_wait_queue,
491 + msblk->next_fragment = (msblk->next_fragment + 1) %
492 + SQUASHFS_CACHED_FRAGMENTS;
494 + if (msblk->fragment[i].data == NULL)
495 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
496 + (SQUASHFS_FILE_MAX_SIZE))) {
497 + ERROR("Failed to allocate fragment "
499 + up(&msblk->fragment_mutex);
503 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
504 + msblk->fragment[i].locked = 1;
505 + up(&msblk->fragment_mutex);
507 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
508 + msblk->fragment[i].data,
509 + start_block, length, NULL))) {
510 + ERROR("Unable to read fragment cache block "
511 + "[%llx]\n", start_block);
512 + msblk->fragment[i].locked = 0;
516 + msblk->fragment[i].block = start_block;
517 + TRACE("New fragment %d, start block %lld, locked %d\n",
518 + i, msblk->fragment[i].block,
519 + msblk->fragment[i].locked);
523 + msblk->fragment[i].locked++;
524 + up(&msblk->fragment_mutex);
525 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
526 + msblk->fragment[i].block,
527 + msblk->fragment[i].locked);
531 + return &msblk->fragment[i];
538 +static struct inode *squashfs_new_inode(struct super_block *s,
539 + struct squashfs_base_inode_header *inodeb)
541 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
542 + struct inode *i = new_inode(s);
545 + i->i_ino = inodeb->inode_number;
546 + i->i_mtime = inodeb->mtime;
547 + i->i_atime = inodeb->mtime;
548 + i->i_ctime = inodeb->mtime;
549 + i->i_uid = msblk->uid[inodeb->uid];
550 + i->i_mode = inodeb->mode;
552 + if (inodeb->guid == SQUASHFS_GUIDS)
553 + i->i_gid = i->i_uid;
555 + i->i_gid = msblk->guid[inodeb->guid];
562 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
565 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
566 + struct squashfs_super_block *sblk = &msblk->sblk;
567 + long long block = SQUASHFS_INODE_BLK(inode) +
568 + sblk->inode_table_start;
569 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
570 + long long next_block;
571 + unsigned int next_offset;
572 + union squashfs_inode_header id, sid;
573 + struct squashfs_base_inode_header *inodeb = &id.base,
574 + *sinodeb = &sid.base;
576 + TRACE("Entered squashfs_iget\n");
579 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
580 + offset, sizeof(*sinodeb), &next_block,
583 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
586 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
587 + offset, sizeof(*inodeb), &next_block,
591 + switch(inodeb->inode_type) {
592 + case SQUASHFS_FILE_TYPE: {
593 + unsigned int frag_size;
594 + long long frag_blk;
595 + struct squashfs_reg_inode_header *inodep = &id.reg;
596 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
599 + if (!squashfs_get_cached_block(s, (char *)
600 + sinodep, block, offset,
601 + sizeof(*sinodep), &next_block,
604 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
606 + if (!squashfs_get_cached_block(s, (char *)
607 + inodep, block, offset,
608 + sizeof(*inodep), &next_block,
612 + frag_blk = SQUASHFS_INVALID_BLK;
613 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
614 + !get_fragment_location(s,
615 + inodep->fragment, &frag_blk, &frag_size))
618 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
622 + i->i_size = inodep->file_size;
623 + i->i_fop = &generic_ro_fops;
624 + i->i_mode |= S_IFREG;
625 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
626 + i->i_blksize = PAGE_CACHE_SIZE;
627 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
628 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
629 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
630 + SQUASHFS_I(i)->start_block = inodep->start_block;
631 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
632 + SQUASHFS_I(i)->offset = next_offset;
633 + if (sblk->block_size > 4096)
634 + i->i_data.a_ops = &squashfs_aops;
636 + i->i_data.a_ops = &squashfs_aops_4K;
638 + TRACE("File inode %x:%x, start_block %llx, "
639 + "block_list_start %llx, offset %x\n",
640 + SQUASHFS_INODE_BLK(inode), offset,
641 + inodep->start_block, next_block,
645 + case SQUASHFS_LREG_TYPE: {
646 + unsigned int frag_size;
647 + long long frag_blk;
648 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
649 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
652 + if (!squashfs_get_cached_block(s, (char *)
653 + sinodep, block, offset,
654 + sizeof(*sinodep), &next_block,
657 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
659 + if (!squashfs_get_cached_block(s, (char *)
660 + inodep, block, offset,
661 + sizeof(*inodep), &next_block,
665 + frag_blk = SQUASHFS_INVALID_BLK;
666 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
667 + !get_fragment_location(s,
668 + inodep->fragment, &frag_blk, &frag_size))
671 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
674 + i->i_nlink = inodep->nlink;
675 + i->i_size = inodep->file_size;
676 + i->i_fop = &generic_ro_fops;
677 + i->i_mode |= S_IFREG;
678 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
679 + i->i_blksize = PAGE_CACHE_SIZE;
680 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
681 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
682 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
683 + SQUASHFS_I(i)->start_block = inodep->start_block;
684 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
685 + SQUASHFS_I(i)->offset = next_offset;
686 + if (sblk->block_size > 4096)
687 + i->i_data.a_ops = &squashfs_aops;
689 + i->i_data.a_ops = &squashfs_aops_4K;
691 + TRACE("File inode %x:%x, start_block %llx, "
692 + "block_list_start %llx, offset %x\n",
693 + SQUASHFS_INODE_BLK(inode), offset,
694 + inodep->start_block, next_block,
698 + case SQUASHFS_DIR_TYPE: {
699 + struct squashfs_dir_inode_header *inodep = &id.dir;
700 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
703 + if (!squashfs_get_cached_block(s, (char *)
704 + sinodep, block, offset,
705 + sizeof(*sinodep), &next_block,
708 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
710 + if (!squashfs_get_cached_block(s, (char *)
711 + inodep, block, offset,
712 + sizeof(*inodep), &next_block,
716 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
719 + i->i_nlink = inodep->nlink;
720 + i->i_size = inodep->file_size;
721 + i->i_op = &squashfs_dir_inode_ops;
722 + i->i_fop = &squashfs_dir_ops;
723 + i->i_mode |= S_IFDIR;
724 + SQUASHFS_I(i)->start_block = inodep->start_block;
725 + SQUASHFS_I(i)->offset = inodep->offset;
726 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
727 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
729 + TRACE("Directory inode %x:%x, start_block %x, offset "
730 + "%x\n", SQUASHFS_INODE_BLK(inode),
731 + offset, inodep->start_block,
735 + case SQUASHFS_LDIR_TYPE: {
736 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
737 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
740 + if (!squashfs_get_cached_block(s, (char *)
741 + sinodep, block, offset,
742 + sizeof(*sinodep), &next_block,
745 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
748 + if (!squashfs_get_cached_block(s, (char *)
749 + inodep, block, offset,
750 + sizeof(*inodep), &next_block,
754 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
757 + i->i_nlink = inodep->nlink;
758 + i->i_size = inodep->file_size;
759 + i->i_op = &squashfs_dir_inode_ops;
760 + i->i_fop = &squashfs_dir_ops;
761 + i->i_mode |= S_IFDIR;
762 + SQUASHFS_I(i)->start_block = inodep->start_block;
763 + SQUASHFS_I(i)->offset = inodep->offset;
764 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
765 + SQUASHFS_I(i)->u.s2.directory_index_offset =
767 + SQUASHFS_I(i)->u.s2.directory_index_count =
769 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
771 + TRACE("Long directory inode %x:%x, start_block %x, "
773 + SQUASHFS_INODE_BLK(inode), offset,
774 + inodep->start_block, inodep->offset);
777 + case SQUASHFS_SYMLINK_TYPE: {
778 + struct squashfs_symlink_inode_header *inodep =
780 + struct squashfs_symlink_inode_header *sinodep =
784 + if (!squashfs_get_cached_block(s, (char *)
785 + sinodep, block, offset,
786 + sizeof(*sinodep), &next_block,
789 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
792 + if (!squashfs_get_cached_block(s, (char *)
793 + inodep, block, offset,
794 + sizeof(*inodep), &next_block,
798 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
801 + i->i_nlink = inodep->nlink;
802 + i->i_size = inodep->symlink_size;
803 + i->i_op = &page_symlink_inode_operations;
804 + i->i_data.a_ops = &squashfs_symlink_aops;
805 + i->i_mode |= S_IFLNK;
806 + SQUASHFS_I(i)->start_block = next_block;
807 + SQUASHFS_I(i)->offset = next_offset;
809 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
811 + SQUASHFS_INODE_BLK(inode), offset,
812 + next_block, next_offset);
815 + case SQUASHFS_BLKDEV_TYPE:
816 + case SQUASHFS_CHRDEV_TYPE: {
817 + struct squashfs_dev_inode_header *inodep = &id.dev;
818 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
821 + if (!squashfs_get_cached_block(s, (char *)
822 + sinodep, block, offset,
823 + sizeof(*sinodep), &next_block,
826 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
828 + if (!squashfs_get_cached_block(s, (char *)
829 + inodep, block, offset,
830 + sizeof(*inodep), &next_block,
834 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
837 + i->i_nlink = inodep->nlink;
838 + i->i_mode |= (inodeb->inode_type ==
839 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
841 + init_special_inode(i, i->i_mode, inodep->rdev);
843 + TRACE("Device inode %x:%x, rdev %x\n",
844 + SQUASHFS_INODE_BLK(inode), offset,
848 + case SQUASHFS_FIFO_TYPE:
849 + case SQUASHFS_SOCKET_TYPE: {
850 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
851 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
854 + if (!squashfs_get_cached_block(s, (char *)
855 + sinodep, block, offset,
856 + sizeof(*sinodep), &next_block,
859 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
861 + if (!squashfs_get_cached_block(s, (char *)
862 + inodep, block, offset,
863 + sizeof(*inodep), &next_block,
867 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
870 + i->i_nlink = inodep->nlink;
871 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
872 + ? S_IFIFO : S_IFSOCK;
873 + init_special_inode(i, i->i_mode, 0);
877 + ERROR("Unknown inode type %d in squashfs_iget!\n",
878 + inodeb->inode_type);
882 + insert_inode_hash(i);
886 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
893 +int read_fragment_index_table(struct super_block *s)
895 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
896 + struct squashfs_super_block *sblk = &msblk->sblk;
898 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
899 + (sblk->fragments), GFP_KERNEL))) {
900 + ERROR("Failed to allocate uid/gid table\n");
904 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
905 + !squashfs_read_data(s, (char *)
906 + msblk->fragment_index,
907 + sblk->fragment_table_start,
908 + SQUASHFS_FRAGMENT_INDEX_BYTES
909 + (sblk->fragments) |
910 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
911 + ERROR("unable to read fragment index table\n");
917 + long long fragment;
919 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
921 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
922 + &msblk->fragment_index[i], 1);
923 + msblk->fragment_index[i] = fragment;
931 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
933 + struct squashfs_super_block *sblk = &msblk->sblk;
935 + msblk->iget = squashfs_iget;
936 + msblk->read_blocklist = read_blocklist;
937 + msblk->read_fragment_index_table = read_fragment_index_table;
939 + if (sblk->s_major == 1) {
940 + if (!squashfs_1_0_supported(msblk)) {
941 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
942 + "are unsupported\n");
943 + SERROR("Please recompile with "
944 + "Squashfs 1.0 support enabled\n");
947 + } else if (sblk->s_major == 2) {
948 + if (!squashfs_2_0_supported(msblk)) {
949 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
950 + "are unsupported\n");
951 + SERROR("Please recompile with "
952 + "Squashfs 2.0 support enabled\n");
955 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
957 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
958 + "filesystem\n", sblk->s_major, sblk->s_minor);
959 + SERROR("Please update your kernel\n");
967 +static struct super_block *squashfs_read_super(struct super_block *s,
968 + void *data, int silent)
970 + kdev_t dev = s->s_dev;
971 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
972 + struct squashfs_super_block *sblk = &msblk->sblk;
974 + struct inode *root;
976 + msblk->devblksize = get_hardsect_size(dev);
977 + if(msblk->devblksize < BLOCK_SIZE)
978 + msblk->devblksize = BLOCK_SIZE;
979 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
980 + set_blocksize(dev, msblk->devblksize);
981 + s->s_blocksize = msblk->devblksize;
982 + s->s_blocksize_bits = msblk->devblksize_log2;
984 + init_MUTEX(&msblk->read_data_mutex);
985 + init_MUTEX(&msblk->read_page_mutex);
986 + init_MUTEX(&msblk->block_cache_mutex);
987 + init_MUTEX(&msblk->fragment_mutex);
989 + init_waitqueue_head(&msblk->waitq);
990 + init_waitqueue_head(&msblk->fragment_wait_queue);
992 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
993 + sizeof(struct squashfs_super_block) |
994 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
995 + SERROR("unable to read superblock\n");
999 + /* Check it is a SQUASHFS superblock */
1001 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1002 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1003 + struct squashfs_super_block ssblk;
1005 + WARNING("Mounting a different endian SQUASHFS "
1006 + "filesystem on %s\n", bdevname(dev));
1008 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1009 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1012 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1014 + goto failed_mount;
1018 + /* Check the MAJOR & MINOR versions */
1019 + if(!supported_squashfs_filesystem(msblk, silent))
1020 + goto failed_mount;
1022 + TRACE("Found valid superblock on %s\n", bdevname(dev));
1023 + TRACE("Inodes are %scompressed\n",
1024 + SQUASHFS_UNCOMPRESSED_INODES
1025 + (sblk->flags) ? "un" : "");
1026 + TRACE("Data is %scompressed\n",
1027 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1029 + TRACE("Check data is %s present in the filesystem\n",
1030 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1032 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1033 + TRACE("Block size %d\n", sblk->block_size);
1034 + TRACE("Number of inodes %d\n", sblk->inodes);
1035 + if (sblk->s_major > 1)
1036 + TRACE("Number of fragments %d\n", sblk->fragments);
1037 + TRACE("Number of uids %d\n", sblk->no_uids);
1038 + TRACE("Number of gids %d\n", sblk->no_guids);
1039 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1040 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1041 + if (sblk->s_major > 1)
1042 + TRACE("sblk->fragment_table_start %llx\n",
1043 + sblk->fragment_table_start);
1044 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1046 + s->s_flags |= MS_RDONLY;
1047 + s->s_op = &squashfs_ops;
1049 + /* Init inode_table block pointer array */
1050 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1051 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1052 + ERROR("Failed to allocate block cache\n");
1053 + goto failed_mount;
1056 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1057 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1059 + msblk->next_cache = 0;
1061 + /* Allocate read_data block */
1062 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1063 + SQUASHFS_METADATA_SIZE :
1066 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1067 + ERROR("Failed to allocate read_data block\n");
1068 + goto failed_mount;
1071 + /* Allocate read_page block */
1072 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1073 + ERROR("Failed to allocate read_page block\n");
1074 + goto failed_mount;
1077 + /* Allocate uid and gid tables */
1078 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1079 + sizeof(unsigned int), GFP_KERNEL))) {
1080 + ERROR("Failed to allocate uid/gid table\n");
1081 + goto failed_mount;
1083 + msblk->guid = msblk->uid + sblk->no_uids;
1085 + if (msblk->swap) {
1086 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1088 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1089 + ((sblk->no_uids + sblk->no_guids) *
1090 + sizeof(unsigned int)) |
1091 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1092 + ERROR("unable to read uid/gid table\n");
1093 + goto failed_mount;
1096 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1097 + sblk->no_guids), (sizeof(unsigned int) * 8));
1099 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1100 + ((sblk->no_uids + sblk->no_guids) *
1101 + sizeof(unsigned int)) |
1102 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1103 + ERROR("unable to read uid/gid table\n");
1104 + goto failed_mount;
1108 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1109 + goto allocate_root;
1111 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1112 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1113 + ERROR("Failed to allocate fragment block cache\n");
1114 + goto failed_mount;
1117 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1118 + msblk->fragment[i].locked = 0;
1119 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1120 + msblk->fragment[i].data = NULL;
1123 + msblk->next_fragment = 0;
1125 + /* Allocate fragment index table */
1126 + if(msblk->read_fragment_index_table(s) == 0)
1127 + goto failed_mount;
1130 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1131 + goto failed_mount;
1133 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1134 + ERROR("Root inode create failed\n");
1136 + goto failed_mount;
1139 + TRACE("Leaving squashfs_read_super\n");
1143 + kfree(msblk->fragment_index);
1144 + kfree(msblk->fragment);
1145 + kfree(msblk->uid);
1146 + kfree(msblk->read_page);
1147 + kfree(msblk->read_data);
1148 + kfree(msblk->block_cache);
1149 + kfree(msblk->fragment_index_2);
1154 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1156 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1157 + struct squashfs_super_block *sblk = &msblk->sblk;
1159 + TRACE("Entered squashfs_statfs\n");
1161 + buf->f_type = SQUASHFS_MAGIC;
1162 + buf->f_bsize = sblk->block_size;
1163 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1164 + buf->f_bfree = buf->f_bavail = 0;
1165 + buf->f_files = sblk->inodes;
1167 + buf->f_namelen = SQUASHFS_NAME_LEN;
1173 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1175 + struct inode *inode = page->mapping->host;
1176 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1177 + long long block = SQUASHFS_I(inode)->start_block;
1178 + int offset = SQUASHFS_I(inode)->offset;
1179 + void *pageaddr = kmap(page);
1181 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1182 + "%llx, offset %x\n", page->index,
1183 + SQUASHFS_I(inode)->start_block,
1184 + SQUASHFS_I(inode)->offset);
1186 + for (length = 0; length < index; length += bytes) {
1187 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1188 + block, offset, PAGE_CACHE_SIZE, &block,
1190 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1196 + if (length != index) {
1197 + ERROR("(squashfs_symlink_readpage) length != index\n");
1202 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1203 + i_size_read(inode) - length;
1205 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1206 + offset, bytes, &block, &offset)))
1207 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1210 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1212 + SetPageUptodate(page);
1219 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1221 + struct meta_index *meta = NULL;
1222 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1225 + down(&msblk->meta_index_mutex);
1227 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1229 + if(msblk->meta_index == NULL)
1230 + goto not_allocated;
1232 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1233 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1234 + msblk->meta_index[i].offset >= offset &&
1235 + msblk->meta_index[i].offset <= index &&
1236 + msblk->meta_index[i].locked == 0) {
1237 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1238 + msblk->meta_index[i].offset);
1239 + meta = &msblk->meta_index[i];
1240 + offset = meta->offset;
1247 + up(&msblk->meta_index_mutex);
1253 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1255 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1256 + struct meta_index *meta = NULL;
1259 + down(&msblk->meta_index_mutex);
1261 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1263 + if(msblk->meta_index == NULL) {
1264 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1265 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1266 + ERROR("Failed to allocate meta_index\n");
1269 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1270 + msblk->meta_index[i].inode_number = 0;
1271 + msblk->meta_index[i].locked = 0;
1273 + msblk->next_meta_index = 0;
1276 + for(i = SQUASHFS_META_NUMBER; i &&
1277 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1278 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1279 + SQUASHFS_META_NUMBER;
1282 + TRACE("empty_meta_index: failed!\n");
1286 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1287 + msblk->next_meta_index,
1288 + &msblk->meta_index[msblk->next_meta_index]);
1290 + meta = &msblk->meta_index[msblk->next_meta_index];
1291 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1292 + SQUASHFS_META_NUMBER;
1294 + meta->inode_number = inode->i_ino;
1295 + meta->offset = offset;
1296 + meta->skip = skip;
1297 + meta->entries = 0;
1301 + up(&msblk->meta_index_mutex);
1306 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1312 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1313 + long long *start_block, int *offset)
1315 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1316 + unsigned int *block_listp;
1319 + if (msblk->swap) {
1320 + char sblock_list[blocks << 2];
1322 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1323 + *offset, blocks << 2, start_block, offset)) {
1324 + ERROR("Unable to read block list [%llx:%x]\n",
1325 + *start_block, *offset);
1328 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1329 + ((unsigned int *)sblock_list), blocks);
1331 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1332 + *offset, blocks << 2, start_block, offset)) {
1333 + ERROR("Unable to read block list [%llx:%x]\n",
1334 + *start_block, *offset);
1338 + for (block_listp = (unsigned int *) block_list; blocks;
1339 + block_listp++, blocks --)
1340 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1351 +static inline int calculate_skip(int blocks) {
1352 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1353 + return skip >= 7 ? 7 : skip + 1;
1357 +static int get_meta_index(struct inode *inode, int index,
1358 + long long *index_block, int *index_offset,
1359 + long long *data_block, char *block_list)
1361 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1362 + struct squashfs_super_block *sblk = &msblk->sblk;
1363 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1365 + struct meta_index *meta;
1366 + struct meta_entry *meta_entry;
1367 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1368 + int cur_offset = SQUASHFS_I(inode)->offset;
1369 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1372 + index /= SQUASHFS_META_INDEXES * skip;
1374 + while ( offset < index ) {
1375 + meta = locate_meta_index(inode, index, offset + 1);
1377 + if (meta == NULL) {
1378 + if ((meta = empty_meta_index(inode, offset + 1,
1382 + offset = index < meta->offset + meta->entries ? index :
1383 + meta->offset + meta->entries - 1;
1384 + meta_entry = &meta->meta_entry[offset - meta->offset];
1385 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1386 + cur_offset = meta_entry->offset;
1387 + cur_data_block = meta_entry->data_block;
1388 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1389 + "meta->entries %d\n", offset, meta->offset,
1391 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1392 + " data_block 0x%llx\n", cur_index_block,
1393 + cur_offset, cur_data_block);
1396 + for (i = meta->offset + meta->entries; i <= index &&
1397 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1398 + int blocks = skip * SQUASHFS_META_INDEXES;
1401 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1403 + int res = read_block_index(inode->i_sb, block,
1404 + block_list, &cur_index_block,
1410 + cur_data_block += res;
1414 + meta_entry = &meta->meta_entry[i - meta->offset];
1415 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1416 + meta_entry->offset = cur_offset;
1417 + meta_entry->data_block = cur_data_block;
1422 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1423 + meta->offset, meta->entries);
1425 + release_meta_index(inode, meta);
1429 + *index_block = cur_index_block;
1430 + *index_offset = cur_offset;
1431 + *data_block = cur_data_block;
1433 + return offset * SQUASHFS_META_INDEXES * skip;
1436 + release_meta_index(inode, meta);
1441 +static long long read_blocklist(struct inode *inode, int index,
1442 + int readahead_blks, char *block_list,
1443 + unsigned short **block_p, unsigned int *bsize)
1445 + long long block_ptr;
1448 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1451 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1452 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1461 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1462 + int res = read_block_index(inode->i_sb, blocks, block_list,
1463 + &block_ptr, &offset);
1470 + if (read_block_index(inode->i_sb, 1, block_list,
1471 + &block_ptr, &offset) == -1)
1473 + *bsize = *((unsigned int *) block_list);
1482 +static int squashfs_readpage(struct file *file, struct page *page)
1484 + struct inode *inode = page->mapping->host;
1485 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1486 + struct squashfs_super_block *sblk = &msblk->sblk;
1487 + unsigned char block_list[SIZE];
1489 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1490 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1492 + struct squashfs_fragment_cache *fragment = NULL;
1493 + char *data_ptr = msblk->read_page;
1495 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1496 + int start_index = page->index & ~mask;
1497 + int end_index = start_index | mask;
1499 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1501 + SQUASHFS_I(inode)->start_block);
1503 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1504 + PAGE_CACHE_SHIFT))
1507 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1508 + || index < (i_size_read(inode) >>
1509 + sblk->block_log)) {
1510 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1511 + block_list, NULL, &bsize)) == 0)
1514 + down(&msblk->read_page_mutex);
1516 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1517 + block, bsize, NULL))) {
1518 + ERROR("Unable to read page, block %llx, size %x\n", block,
1520 + up(&msblk->read_page_mutex);
1524 + if ((fragment = get_cached_fragment(inode->i_sb,
1525 + SQUASHFS_I(inode)->
1526 + u.s1.fragment_start_block,
1527 + SQUASHFS_I(inode)->u.s1.fragment_size))
1529 + ERROR("Unable to read page, block %llx, size %x\n",
1530 + SQUASHFS_I(inode)->
1531 + u.s1.fragment_start_block,
1532 + (int) SQUASHFS_I(inode)->
1533 + u.s1.fragment_size);
1536 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1537 + (i_size_read(inode) & (sblk->block_size
1539 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1540 + data_ptr = fragment->data;
1543 + for (i = start_index; i <= end_index && byte_offset < bytes;
1544 + i++, byte_offset += PAGE_CACHE_SIZE) {
1545 + struct page *push_page;
1546 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1547 + PAGE_CACHE_SIZE : bytes - byte_offset;
1549 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1550 + bytes, i, byte_offset, available_bytes);
1552 + if (i == page->index) {
1553 + pageaddr = kmap_atomic(page, KM_USER0);
1554 + memcpy(pageaddr, data_ptr + byte_offset,
1556 + memset(pageaddr + available_bytes, 0,
1557 + PAGE_CACHE_SIZE - available_bytes);
1558 + kunmap_atomic(pageaddr, KM_USER0);
1559 + flush_dcache_page(page);
1560 + SetPageUptodate(page);
1562 + } else if ((push_page =
1563 + grab_cache_page_nowait(page->mapping, i))) {
1564 + pageaddr = kmap_atomic(push_page, KM_USER0);
1566 + memcpy(pageaddr, data_ptr + byte_offset,
1568 + memset(pageaddr + available_bytes, 0,
1569 + PAGE_CACHE_SIZE - available_bytes);
1570 + kunmap_atomic(pageaddr, KM_USER0);
1571 + flush_dcache_page(push_page);
1572 + SetPageUptodate(push_page);
1573 + UnlockPage(push_page);
1574 + page_cache_release(push_page);
1578 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1579 + || index < (i_size_read(inode) >>
1581 + up(&msblk->read_page_mutex);
1583 + release_cached_fragment(msblk, fragment);
1588 + pageaddr = kmap_atomic(page, KM_USER0);
1589 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1590 + kunmap_atomic(pageaddr, KM_USER0);
1591 + flush_dcache_page(page);
1592 + SetPageUptodate(page);
1599 +static int squashfs_readpage4K(struct file *file, struct page *page)
1601 + struct inode *inode = page->mapping->host;
1602 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1603 + struct squashfs_super_block *sblk = &msblk->sblk;
1604 + unsigned char block_list[SIZE];
1606 + unsigned int bsize, bytes = 0;
1609 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1611 + SQUASHFS_I(inode)->start_block);
1613 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1614 + PAGE_CACHE_SHIFT)) {
1615 + pageaddr = kmap_atomic(page, KM_USER0);
1619 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1620 + || page->index < (i_size_read(inode) >>
1621 + sblk->block_log)) {
1622 + block = (msblk->read_blocklist)(inode, page->index, 1,
1623 + block_list, NULL, &bsize);
1625 + down(&msblk->read_page_mutex);
1626 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1628 + pageaddr = kmap_atomic(page, KM_USER0);
1630 + memcpy(pageaddr, msblk->read_page, bytes);
1632 + ERROR("Unable to read page, block %llx, size %x\n",
1634 + up(&msblk->read_page_mutex);
1636 + struct squashfs_fragment_cache *fragment =
1637 + get_cached_fragment(inode->i_sb,
1638 + SQUASHFS_I(inode)->
1639 + u.s1.fragment_start_block,
1640 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1641 + pageaddr = kmap_atomic(page, KM_USER0);
1643 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1644 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1645 + u.s1.fragment_offset, bytes);
1646 + release_cached_fragment(msblk, fragment);
1648 + ERROR("Unable to read page, block %llx, size %x\n",
1649 + SQUASHFS_I(inode)->
1650 + u.s1.fragment_start_block, (int)
1651 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1655 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1656 + kunmap_atomic(pageaddr, KM_USER0);
1657 + flush_dcache_page(page);
1658 + SetPageUptodate(page);
1665 +static int get_dir_index_using_offset(struct super_block *s, long long
1666 + *next_block, unsigned int *next_offset,
1667 + long long index_start,
1668 + unsigned int index_offset, int i_count,
1671 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1672 + struct squashfs_super_block *sblk = &msblk->sblk;
1673 + int i, length = 0;
1674 + struct squashfs_dir_index index;
1676 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1677 + i_count, (unsigned int) f_pos);
1683 + for (i = 0; i < i_count; i++) {
1684 + if (msblk->swap) {
1685 + struct squashfs_dir_index sindex;
1686 + squashfs_get_cached_block(s, (char *) &sindex,
1687 + index_start, index_offset,
1688 + sizeof(sindex), &index_start,
1690 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1692 + squashfs_get_cached_block(s, (char *) &index,
1693 + index_start, index_offset,
1694 + sizeof(index), &index_start,
1697 + if (index.index > f_pos)
1700 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1701 + index.size + 1, &index_start,
1704 + length = index.index;
1705 + *next_block = index.start_block + sblk->directory_table_start;
1708 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1711 + return length + 3;
1715 +static int get_dir_index_using_name(struct super_block *s, long long
1716 + *next_block, unsigned int *next_offset,
1717 + long long index_start,
1718 + unsigned int index_offset, int i_count,
1719 + const char *name, int size)
1721 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1722 + struct squashfs_super_block *sblk = &msblk->sblk;
1723 + int i, length = 0;
1724 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1725 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1726 + char str[SQUASHFS_NAME_LEN + 1];
1728 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1730 + strncpy(str, name, size);
1733 + for (i = 0; i < i_count; i++) {
1734 + if (msblk->swap) {
1735 + struct squashfs_dir_index sindex;
1736 + squashfs_get_cached_block(s, (char *) &sindex,
1737 + index_start, index_offset,
1738 + sizeof(sindex), &index_start,
1740 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1742 + squashfs_get_cached_block(s, (char *) index,
1743 + index_start, index_offset,
1744 + sizeof(struct squashfs_dir_index),
1745 + &index_start, &index_offset);
1747 + squashfs_get_cached_block(s, index->name, index_start,
1748 + index_offset, index->size + 1,
1749 + &index_start, &index_offset);
1751 + index->name[index->size + 1] = '\0';
1753 + if (strcmp(index->name, str) > 0)
1756 + length = index->index;
1757 + *next_block = index->start_block + sblk->directory_table_start;
1760 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1761 + return length + 3;
1765 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1767 + struct inode *i = file->f_dentry->d_inode;
1768 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1769 + struct squashfs_super_block *sblk = &msblk->sblk;
1770 + long long next_block = SQUASHFS_I(i)->start_block +
1771 + sblk->directory_table_start;
1772 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1774 + struct squashfs_dir_header dirh;
1775 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1776 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1778 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1780 + while(file->f_pos < 3) {
1784 + if(file->f_pos == 0) {
1791 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1793 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1794 + (unsigned int) dirent, name, size, (int)
1795 + file->f_pos, i_ino,
1796 + squashfs_filetype_table[1]);
1798 + if (filldir(dirent, name, size,
1799 + file->f_pos, i_ino,
1800 + squashfs_filetype_table[1]) < 0) {
1801 + TRACE("Filldir returned less than 0\n");
1804 + file->f_pos += size;
1808 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1809 + SQUASHFS_I(i)->u.s2.directory_index_start,
1810 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1811 + SQUASHFS_I(i)->u.s2.directory_index_count,
1814 + while (length < i_size_read(i)) {
1815 + /* read directory header */
1816 + if (msblk->swap) {
1817 + struct squashfs_dir_header sdirh;
1819 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1820 + next_block, next_offset, sizeof(sdirh),
1821 + &next_block, &next_offset))
1824 + length += sizeof(sdirh);
1825 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1827 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1828 + next_block, next_offset, sizeof(dirh),
1829 + &next_block, &next_offset))
1832 + length += sizeof(dirh);
1835 + dir_count = dirh.count + 1;
1836 + while (dir_count--) {
1837 + if (msblk->swap) {
1838 + struct squashfs_dir_entry sdire;
1839 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1840 + &sdire, next_block, next_offset,
1841 + sizeof(sdire), &next_block,
1845 + length += sizeof(sdire);
1846 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1848 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1849 + dire, next_block, next_offset,
1850 + sizeof(*dire), &next_block,
1854 + length += sizeof(*dire);
1857 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1858 + next_block, next_offset,
1859 + dire->size + 1, &next_block,
1863 + length += dire->size + 1;
1865 + if (file->f_pos >= length)
1868 + dire->name[dire->size + 1] = '\0';
1870 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1871 + (unsigned int) dirent, dire->name,
1872 + dire->size + 1, (int) file->f_pos,
1873 + dirh.start_block, dire->offset,
1874 + dirh.inode_number + dire->inode_number,
1875 + squashfs_filetype_table[dire->type]);
1877 + if (filldir(dirent, dire->name, dire->size + 1,
1879 + dirh.inode_number + dire->inode_number,
1880 + squashfs_filetype_table[dire->type])
1882 + TRACE("Filldir returned less than 0\n");
1885 + file->f_pos = length;
1894 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1900 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1902 + const unsigned char *name = dentry->d_name.name;
1903 + int len = dentry->d_name.len;
1904 + struct inode *inode = NULL;
1905 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1906 + struct squashfs_super_block *sblk = &msblk->sblk;
1907 + long long next_block = SQUASHFS_I(i)->start_block +
1908 + sblk->directory_table_start;
1909 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1911 + struct squashfs_dir_header dirh;
1912 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1913 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1915 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
1917 + if (len > SQUASHFS_NAME_LEN)
1920 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
1921 + SQUASHFS_I(i)->u.s2.directory_index_start,
1922 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1923 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
1926 + while (length < i_size_read(i)) {
1927 + /* read directory header */
1928 + if (msblk->swap) {
1929 + struct squashfs_dir_header sdirh;
1930 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1931 + next_block, next_offset, sizeof(sdirh),
1932 + &next_block, &next_offset))
1935 + length += sizeof(sdirh);
1936 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1938 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1939 + next_block, next_offset, sizeof(dirh),
1940 + &next_block, &next_offset))
1943 + length += sizeof(dirh);
1946 + dir_count = dirh.count + 1;
1947 + while (dir_count--) {
1948 + if (msblk->swap) {
1949 + struct squashfs_dir_entry sdire;
1950 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1951 + &sdire, next_block,next_offset,
1952 + sizeof(sdire), &next_block,
1956 + length += sizeof(sdire);
1957 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1959 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1960 + dire, next_block,next_offset,
1961 + sizeof(*dire), &next_block,
1965 + length += sizeof(*dire);
1968 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1969 + next_block, next_offset, dire->size + 1,
1970 + &next_block, &next_offset))
1973 + length += dire->size + 1;
1975 + if (name[0] < dire->name[0])
1978 + if ((len == dire->size + 1) && !strncmp(name,
1979 + dire->name, len)) {
1980 + squashfs_inode_t ino =
1981 + SQUASHFS_MKINODE(dirh.start_block,
1984 + TRACE("calling squashfs_iget for directory "
1985 + "entry %s, inode %x:%x, %d\n", name,
1986 + dirh.start_block, dire->offset,
1987 + dirh.inode_number + dire->inode_number);
1989 + inode = (msblk->iget)(i->i_sb, ino);
1997 + d_add(dentry, inode);
1998 + return ERR_PTR(0);
2001 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2007 +static void squashfs_put_super(struct super_block *s)
2011 + struct squashfs_sb_info *sbi = &s->u.squashfs_sb;
2012 + if (sbi->block_cache)
2013 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2014 + if (sbi->block_cache[i].block !=
2015 + SQUASHFS_INVALID_BLK)
2016 + kfree(sbi->block_cache[i].data);
2017 + if (sbi->fragment)
2018 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2019 + SQUASHFS_FREE(sbi->fragment[i].data);
2020 + kfree(sbi->fragment);
2021 + kfree(sbi->block_cache);
2022 + kfree(sbi->read_data);
2023 + kfree(sbi->read_page);
2025 + kfree(sbi->fragment_index);
2026 + kfree(sbi->fragment_index_2);
2027 + sbi->block_cache = NULL;
2029 + sbi->read_data = NULL;
2030 + sbi->read_page = NULL;
2031 + sbi->fragment = NULL;
2032 + sbi->fragment_index = NULL;
2033 + sbi->fragment_index_2 = NULL;
2037 +static int __init init_squashfs_fs(void)
2040 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2041 + "Phillip Lougher\n");
2043 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2044 + ERROR("Failed to allocate zlib workspace\n");
2047 + return register_filesystem(&squashfs_fs_type);
2051 +static void __exit exit_squashfs_fs(void)
2053 + vfree(stream.workspace);
2054 + unregister_filesystem(&squashfs_fs_type);
2060 +module_init(init_squashfs_fs);
2061 +module_exit(exit_squashfs_fs);
2062 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2063 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2064 +MODULE_LICENSE("GPL");
2065 Index: linux-2.4.35.4/fs/squashfs/Makefile
2066 ===================================================================
2068 +++ linux-2.4.35.4/fs/squashfs/Makefile
2071 +# Makefile for the linux squashfs routines.
2074 +O_TARGET := squashfs.o
2076 +obj-y := inode.o squashfs2_0.o
2078 +obj-m := $(O_TARGET)
2080 +include $(TOPDIR)/Rules.make
2081 Index: linux-2.4.35.4/fs/squashfs/squashfs2_0.c
2082 ===================================================================
2084 +++ linux-2.4.35.4/fs/squashfs/squashfs2_0.c
2087 + * Squashfs - a compressed read only filesystem for Linux
2089 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2090 + * Phillip Lougher <phillip@lougher.org.uk>
2092 + * This program is free software; you can redistribute it and/or
2093 + * modify it under the terms of the GNU General Public License
2094 + * as published by the Free Software Foundation; either version 2,
2095 + * or (at your option) any later version.
2097 + * This program is distributed in the hope that it will be useful,
2098 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2099 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2100 + * GNU General Public License for more details.
2102 + * You should have received a copy of the GNU General Public License
2103 + * along with this program; if not, write to the Free Software
2104 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2109 +#include <linux/types.h>
2110 +#include <linux/squashfs_fs.h>
2111 +#include <linux/module.h>
2112 +#include <linux/errno.h>
2113 +#include <linux/slab.h>
2114 +#include <linux/fs.h>
2115 +#include <linux/smp_lock.h>
2116 +#include <linux/locks.h>
2117 +#include <linux/init.h>
2118 +#include <linux/dcache.h>
2119 +#include <linux/wait.h>
2120 +#include <linux/zlib.h>
2121 +#include <linux/blkdev.h>
2122 +#include <linux/vmalloc.h>
2123 +#include <asm/uaccess.h>
2124 +#include <asm/semaphore.h>
2125 +#include "squashfs.h"
2127 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2128 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry);
2130 +static struct file_operations squashfs_dir_ops_2 = {
2131 + .read = generic_read_dir,
2132 + .readdir = squashfs_readdir_2
2135 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2136 + .lookup = squashfs_lookup_2
2139 +static unsigned char squashfs_filetype_table[] = {
2140 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2143 +static int read_fragment_index_table_2(struct super_block *s)
2145 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2146 + struct squashfs_super_block *sblk = &msblk->sblk;
2148 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2149 + (sblk->fragments), GFP_KERNEL))) {
2150 + ERROR("Failed to allocate uid/gid table\n");
2154 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2155 + !squashfs_read_data(s, (char *)
2156 + msblk->fragment_index_2,
2157 + sblk->fragment_table_start,
2158 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2159 + (sblk->fragments) |
2160 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2161 + ERROR("unable to read fragment index table\n");
2165 + if (msblk->swap) {
2167 + unsigned int fragment;
2169 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2171 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2172 + &msblk->fragment_index_2[i], 1);
2173 + msblk->fragment_index_2[i] = fragment;
2181 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2182 + long long *fragment_start_block,
2183 + unsigned int *fragment_size)
2185 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2186 + long long start_block =
2187 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2188 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2189 + struct squashfs_fragment_entry_2 fragment_entry;
2191 + if (msblk->swap) {
2192 + struct squashfs_fragment_entry_2 sfragment_entry;
2194 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2195 + start_block, offset,
2196 + sizeof(sfragment_entry), &start_block,
2199 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2201 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2202 + start_block, offset,
2203 + sizeof(fragment_entry), &start_block,
2207 + *fragment_start_block = fragment_entry.start_block;
2208 + *fragment_size = fragment_entry.size;
2217 +static struct inode *squashfs_new_inode(struct super_block *s,
2218 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2220 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2221 + struct squashfs_super_block *sblk = &msblk->sblk;
2222 + struct inode *i = new_inode(s);
2226 + i->i_mtime = sblk->mkfs_time;
2227 + i->i_atime = sblk->mkfs_time;
2228 + i->i_ctime = sblk->mkfs_time;
2229 + i->i_uid = msblk->uid[inodeb->uid];
2230 + i->i_mode = inodeb->mode;
2233 + if (inodeb->guid == SQUASHFS_GUIDS)
2234 + i->i_gid = i->i_uid;
2236 + i->i_gid = msblk->guid[inodeb->guid];
2243 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2246 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2247 + struct squashfs_super_block *sblk = &msblk->sblk;
2248 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2249 + sblk->inode_table_start;
2250 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2251 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2252 + - sblk->inode_table_start, offset);
2253 + long long next_block;
2254 + unsigned int next_offset;
2255 + union squashfs_inode_header_2 id, sid;
2256 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2257 + *sinodeb = &sid.base;
2259 + TRACE("Entered squashfs_iget\n");
2261 + if (msblk->swap) {
2262 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2263 + offset, sizeof(*sinodeb), &next_block,
2266 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2267 + sizeof(*sinodeb));
2269 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2270 + offset, sizeof(*inodeb), &next_block,
2274 + switch(inodeb->inode_type) {
2275 + case SQUASHFS_FILE_TYPE: {
2276 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2277 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2278 + long long frag_blk;
2279 + unsigned int frag_size;
2281 + if (msblk->swap) {
2282 + if (!squashfs_get_cached_block(s, (char *)
2283 + sinodep, block, offset,
2284 + sizeof(*sinodep), &next_block,
2287 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2289 + if (!squashfs_get_cached_block(s, (char *)
2290 + inodep, block, offset,
2291 + sizeof(*inodep), &next_block,
2295 + frag_blk = SQUASHFS_INVALID_BLK;
2296 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2297 + !get_fragment_location_2(s,
2298 + inodep->fragment, &frag_blk, &frag_size))
2301 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2302 + goto failed_read1;
2304 + i->i_size = inodep->file_size;
2305 + i->i_fop = &generic_ro_fops;
2306 + i->i_mode |= S_IFREG;
2307 + i->i_mtime = inodep->mtime;
2308 + i->i_atime = inodep->mtime;
2309 + i->i_ctime = inodep->mtime;
2310 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2311 + i->i_blksize = PAGE_CACHE_SIZE;
2312 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2313 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2314 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2315 + SQUASHFS_I(i)->start_block = inodep->start_block;
2316 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2317 + SQUASHFS_I(i)->offset = next_offset;
2318 + if (sblk->block_size > 4096)
2319 + i->i_data.a_ops = &squashfs_aops;
2321 + i->i_data.a_ops = &squashfs_aops_4K;
2323 + TRACE("File inode %x:%x, start_block %x, "
2324 + "block_list_start %llx, offset %x\n",
2325 + SQUASHFS_INODE_BLK(inode), offset,
2326 + inodep->start_block, next_block,
2330 + case SQUASHFS_DIR_TYPE: {
2331 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2332 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2334 + if (msblk->swap) {
2335 + if (!squashfs_get_cached_block(s, (char *)
2336 + sinodep, block, offset,
2337 + sizeof(*sinodep), &next_block,
2340 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2342 + if (!squashfs_get_cached_block(s, (char *)
2343 + inodep, block, offset,
2344 + sizeof(*inodep), &next_block,
2348 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2349 + goto failed_read1;
2351 + i->i_size = inodep->file_size;
2352 + i->i_op = &squashfs_dir_inode_ops_2;
2353 + i->i_fop = &squashfs_dir_ops_2;
2354 + i->i_mode |= S_IFDIR;
2355 + i->i_mtime = inodep->mtime;
2356 + i->i_atime = inodep->mtime;
2357 + i->i_ctime = inodep->mtime;
2358 + SQUASHFS_I(i)->start_block = inodep->start_block;
2359 + SQUASHFS_I(i)->offset = inodep->offset;
2360 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2361 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2363 + TRACE("Directory inode %x:%x, start_block %x, offset "
2364 + "%x\n", SQUASHFS_INODE_BLK(inode),
2365 + offset, inodep->start_block,
2369 + case SQUASHFS_LDIR_TYPE: {
2370 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2371 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2373 + if (msblk->swap) {
2374 + if (!squashfs_get_cached_block(s, (char *)
2375 + sinodep, block, offset,
2376 + sizeof(*sinodep), &next_block,
2379 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2382 + if (!squashfs_get_cached_block(s, (char *)
2383 + inodep, block, offset,
2384 + sizeof(*inodep), &next_block,
2388 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2389 + goto failed_read1;
2391 + i->i_size = inodep->file_size;
2392 + i->i_op = &squashfs_dir_inode_ops_2;
2393 + i->i_fop = &squashfs_dir_ops_2;
2394 + i->i_mode |= S_IFDIR;
2395 + i->i_mtime = inodep->mtime;
2396 + i->i_atime = inodep->mtime;
2397 + i->i_ctime = inodep->mtime;
2398 + SQUASHFS_I(i)->start_block = inodep->start_block;
2399 + SQUASHFS_I(i)->offset = inodep->offset;
2400 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2401 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2403 + SQUASHFS_I(i)->u.s2.directory_index_count =
2405 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2407 + TRACE("Long directory inode %x:%x, start_block %x, "
2409 + SQUASHFS_INODE_BLK(inode), offset,
2410 + inodep->start_block, inodep->offset);
2413 + case SQUASHFS_SYMLINK_TYPE: {
2414 + struct squashfs_symlink_inode_header_2 *inodep =
2416 + struct squashfs_symlink_inode_header_2 *sinodep =
2419 + if (msblk->swap) {
2420 + if (!squashfs_get_cached_block(s, (char *)
2421 + sinodep, block, offset,
2422 + sizeof(*sinodep), &next_block,
2425 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2428 + if (!squashfs_get_cached_block(s, (char *)
2429 + inodep, block, offset,
2430 + sizeof(*inodep), &next_block,
2434 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2435 + goto failed_read1;
2437 + i->i_size = inodep->symlink_size;
2438 + i->i_op = &page_symlink_inode_operations;
2439 + i->i_data.a_ops = &squashfs_symlink_aops;
2440 + i->i_mode |= S_IFLNK;
2441 + SQUASHFS_I(i)->start_block = next_block;
2442 + SQUASHFS_I(i)->offset = next_offset;
2444 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2446 + SQUASHFS_INODE_BLK(inode), offset,
2447 + next_block, next_offset);
2450 + case SQUASHFS_BLKDEV_TYPE:
2451 + case SQUASHFS_CHRDEV_TYPE: {
2452 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2453 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2455 + if (msblk->swap) {
2456 + if (!squashfs_get_cached_block(s, (char *)
2457 + sinodep, block, offset,
2458 + sizeof(*sinodep), &next_block,
2461 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2463 + if (!squashfs_get_cached_block(s, (char *)
2464 + inodep, block, offset,
2465 + sizeof(*inodep), &next_block,
2469 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2470 + goto failed_read1;
2472 + i->i_mode |= (inodeb->inode_type ==
2473 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2475 + init_special_inode(i, i->i_mode, inodep->rdev);
2477 + TRACE("Device inode %x:%x, rdev %x\n",
2478 + SQUASHFS_INODE_BLK(inode), offset,
2482 + case SQUASHFS_FIFO_TYPE:
2483 + case SQUASHFS_SOCKET_TYPE: {
2484 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2485 + goto failed_read1;
2487 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2488 + ? S_IFIFO : S_IFSOCK;
2489 + init_special_inode(i, i->i_mode, 0);
2493 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2494 + inodeb->inode_type);
2495 + goto failed_read1;
2498 + insert_inode_hash(i);
2502 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2509 +static int get_dir_index_using_offset(struct super_block *s, long long
2510 + *next_block, unsigned int *next_offset,
2511 + long long index_start,
2512 + unsigned int index_offset, int i_count,
2515 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2516 + struct squashfs_super_block *sblk = &msblk->sblk;
2517 + int i, length = 0;
2518 + struct squashfs_dir_index_2 index;
2520 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2521 + i_count, (unsigned int) f_pos);
2526 + for (i = 0; i < i_count; i++) {
2527 + if (msblk->swap) {
2528 + struct squashfs_dir_index_2 sindex;
2529 + squashfs_get_cached_block(s, (char *) &sindex,
2530 + index_start, index_offset,
2531 + sizeof(sindex), &index_start,
2533 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2535 + squashfs_get_cached_block(s, (char *) &index,
2536 + index_start, index_offset,
2537 + sizeof(index), &index_start,
2540 + if (index.index > f_pos)
2543 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2544 + index.size + 1, &index_start,
2547 + length = index.index;
2548 + *next_block = index.start_block + sblk->directory_table_start;
2551 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2558 +static int get_dir_index_using_name(struct super_block *s, long long
2559 + *next_block, unsigned int *next_offset,
2560 + long long index_start,
2561 + unsigned int index_offset, int i_count,
2562 + const char *name, int size)
2564 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2565 + struct squashfs_super_block *sblk = &msblk->sblk;
2566 + int i, length = 0;
2567 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2568 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2569 + char str[SQUASHFS_NAME_LEN + 1];
2571 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2573 + strncpy(str, name, size);
2576 + for (i = 0; i < i_count; i++) {
2577 + if (msblk->swap) {
2578 + struct squashfs_dir_index_2 sindex;
2579 + squashfs_get_cached_block(s, (char *) &sindex,
2580 + index_start, index_offset,
2581 + sizeof(sindex), &index_start,
2583 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2585 + squashfs_get_cached_block(s, (char *) index,
2586 + index_start, index_offset,
2587 + sizeof(struct squashfs_dir_index_2),
2588 + &index_start, &index_offset);
2590 + squashfs_get_cached_block(s, index->name, index_start,
2591 + index_offset, index->size + 1,
2592 + &index_start, &index_offset);
2594 + index->name[index->size + 1] = '\0';
2596 + if (strcmp(index->name, str) > 0)
2599 + length = index->index;
2600 + *next_block = index->start_block + sblk->directory_table_start;
2603 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2608 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2610 + struct inode *i = file->f_dentry->d_inode;
2611 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2612 + struct squashfs_super_block *sblk = &msblk->sblk;
2613 + long long next_block = SQUASHFS_I(i)->start_block +
2614 + sblk->directory_table_start;
2615 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2617 + struct squashfs_dir_header_2 dirh;
2618 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2619 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2621 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2623 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2624 + SQUASHFS_I(i)->u.s2.directory_index_start,
2625 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2626 + SQUASHFS_I(i)->u.s2.directory_index_count,
2629 + while (length < i_size_read(i)) {
2630 + /* read directory header */
2631 + if (msblk->swap) {
2632 + struct squashfs_dir_header_2 sdirh;
2634 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2635 + next_block, next_offset, sizeof(sdirh),
2636 + &next_block, &next_offset))
2639 + length += sizeof(sdirh);
2640 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2642 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2643 + next_block, next_offset, sizeof(dirh),
2644 + &next_block, &next_offset))
2647 + length += sizeof(dirh);
2650 + dir_count = dirh.count + 1;
2651 + while (dir_count--) {
2652 + if (msblk->swap) {
2653 + struct squashfs_dir_entry_2 sdire;
2654 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2655 + &sdire, next_block, next_offset,
2656 + sizeof(sdire), &next_block,
2660 + length += sizeof(sdire);
2661 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2663 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2664 + dire, next_block, next_offset,
2665 + sizeof(*dire), &next_block,
2669 + length += sizeof(*dire);
2672 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2673 + next_block, next_offset,
2674 + dire->size + 1, &next_block,
2678 + length += dire->size + 1;
2680 + if (file->f_pos >= length)
2683 + dire->name[dire->size + 1] = '\0';
2685 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2686 + (unsigned int) dirent, dire->name,
2687 + dire->size + 1, (int) file->f_pos,
2688 + dirh.start_block, dire->offset,
2689 + squashfs_filetype_table[dire->type]);
2691 + if (filldir(dirent, dire->name, dire->size + 1,
2692 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2693 + dirh.start_block, dire->offset),
2694 + squashfs_filetype_table[dire->type])
2696 + TRACE("Filldir returned less than 0\n");
2699 + file->f_pos = length;
2708 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2714 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry)
2716 + const unsigned char *name = dentry->d_name.name;
2717 + int len = dentry->d_name.len;
2718 + struct inode *inode = NULL;
2719 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2720 + struct squashfs_super_block *sblk = &msblk->sblk;
2721 + long long next_block = SQUASHFS_I(i)->start_block +
2722 + sblk->directory_table_start;
2723 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2725 + struct squashfs_dir_header_2 dirh;
2726 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2727 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2728 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2730 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2732 + if (len > SQUASHFS_NAME_LEN)
2735 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2736 + SQUASHFS_I(i)->u.s2.directory_index_start,
2737 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2738 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2741 + while (length < i_size_read(i)) {
2742 + /* read directory header */
2743 + if (msblk->swap) {
2744 + struct squashfs_dir_header_2 sdirh;
2745 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2746 + next_block, next_offset, sizeof(sdirh),
2747 + &next_block, &next_offset))
2750 + length += sizeof(sdirh);
2751 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2753 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2754 + next_block, next_offset, sizeof(dirh),
2755 + &next_block, &next_offset))
2758 + length += sizeof(dirh);
2761 + dir_count = dirh.count + 1;
2762 + while (dir_count--) {
2763 + if (msblk->swap) {
2764 + struct squashfs_dir_entry_2 sdire;
2765 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2766 + &sdire, next_block,next_offset,
2767 + sizeof(sdire), &next_block,
2771 + length += sizeof(sdire);
2772 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2774 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2775 + dire, next_block,next_offset,
2776 + sizeof(*dire), &next_block,
2780 + length += sizeof(*dire);
2783 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2784 + next_block, next_offset, dire->size + 1,
2785 + &next_block, &next_offset))
2788 + length += dire->size + 1;
2790 + if (sorted && name[0] < dire->name[0])
2793 + if ((len == dire->size + 1) && !strncmp(name,
2794 + dire->name, len)) {
2795 + squashfs_inode_t ino =
2796 + SQUASHFS_MKINODE(dirh.start_block,
2799 + TRACE("calling squashfs_iget for directory "
2800 + "entry %s, inode %x:%x, %d\n", name,
2801 + dirh.start_block, dire->offset, ino);
2803 + inode = (msblk->iget)(i->i_sb, ino);
2811 + d_add(dentry, inode);
2812 + return ERR_PTR(0);
2815 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2821 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2823 + struct squashfs_super_block *sblk = &msblk->sblk;
2825 + msblk->iget = squashfs_iget_2;
2826 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2828 + sblk->bytes_used = sblk->bytes_used_2;
2829 + sblk->uid_start = sblk->uid_start_2;
2830 + sblk->guid_start = sblk->guid_start_2;
2831 + sblk->inode_table_start = sblk->inode_table_start_2;
2832 + sblk->directory_table_start = sblk->directory_table_start_2;
2833 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2837 Index: linux-2.4.35.4/fs/squashfs/squashfs.h
2838 ===================================================================
2840 +++ linux-2.4.35.4/fs/squashfs/squashfs.h
2843 + * Squashfs - a compressed read only filesystem for Linux
2845 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2846 + * Phillip Lougher <phillip@lougher.org.uk>
2848 + * This program is free software; you can redistribute it and/or
2849 + * modify it under the terms of the GNU General Public License
2850 + * as published by the Free Software Foundation; either version 2,
2851 + * or (at your option) any later version.
2853 + * This program is distributed in the hope that it will be useful,
2854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2856 + * GNU General Public License for more details.
2858 + * You should have received a copy of the GNU General Public License
2859 + * along with this program; if not, write to the Free Software
2860 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2865 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2866 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2868 +#ifdef SQUASHFS_TRACE
2869 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
2871 +#define TRACE(s, args...) {}
2874 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
2876 +#define SERROR(s, args...) do { \
2878 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
2881 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
2883 +#define SQUASHFS_I(INO) (&INO->u.squashfs_i)
2885 +#define i_size_read(INO) (INO->i_size)
2887 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
2888 +#define SQSH_EXTERN
2889 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
2890 + long long index, unsigned int length,
2891 + long long *next_index);
2892 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
2893 + long long block, unsigned int offset,
2894 + int length, long long *next_block,
2895 + unsigned int *next_offset);
2896 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
2897 + squashfs_fragment_cache *fragment);
2898 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
2899 + *s, long long start_block,
2901 +extern struct address_space_operations squashfs_symlink_aops;
2902 +extern struct address_space_operations squashfs_aops;
2903 +extern struct address_space_operations squashfs_aops_4K;
2904 +extern struct file_operations squashfs_dir_ops;
2905 +extern struct inode_operations squashfs_dir_inode_ops;
2907 +#define SQSH_EXTERN static
2910 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2911 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
2913 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
2919 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2920 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
2922 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2927 Index: linux-2.4.35.4/include/linux/fs.h
2928 ===================================================================
2929 --- linux-2.4.35.4.orig/include/linux/fs.h
2930 +++ linux-2.4.35.4/include/linux/fs.h
2931 @@ -324,6 +324,7 @@ extern void set_bh_page(struct buffer_he
2932 #include <linux/usbdev_fs_i.h>
2933 #include <linux/jffs2_fs_i.h>
2934 #include <linux/cramfs_fs_sb.h>
2935 +#include <linux/squashfs_fs_i.h>
2938 * Attribute flags. These should be or-ed together to figure out what
2939 @@ -519,6 +520,7 @@ struct inode {
2940 struct socket socket_i;
2941 struct usbdev_inode_info usbdev_i;
2942 struct jffs2_inode_info jffs2_i;
2943 + struct squashfs_inode_info squashfs_i;
2947 @@ -734,6 +736,7 @@ struct nameidata {
2948 #include <linux/usbdev_fs_sb.h>
2949 #include <linux/cramfs_fs_sb.h>
2950 #include <linux/jffs2_fs_sb.h>
2951 +#include <linux/squashfs_fs_sb.h>
2953 extern struct list_head super_blocks;
2954 extern spinlock_t sb_lock;
2955 @@ -793,6 +796,7 @@ struct super_block {
2956 struct usbdev_sb_info usbdevfs_sb;
2957 struct jffs2_sb_info jffs2_sb;
2958 struct cramfs_sb_info cramfs_sb;
2959 + struct squashfs_sb_info squashfs_sb;
2963 Index: linux-2.4.35.4/include/linux/squashfs_fs.h
2964 ===================================================================
2966 +++ linux-2.4.35.4/include/linux/squashfs_fs.h
2968 +#ifndef SQUASHFS_FS
2969 +#define SQUASHFS_FS
2974 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2975 + * Phillip Lougher <phillip@lougher.org.uk>
2977 + * This program is free software; you can redistribute it and/or
2978 + * modify it under the terms of the GNU General Public License
2979 + * as published by the Free Software Foundation; either version 2,
2980 + * or (at your option) any later version.
2982 + * This program is distributed in the hope that it will be useful,
2983 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2984 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2985 + * GNU General Public License for more details.
2987 + * You should have received a copy of the GNU General Public License
2988 + * along with this program; if not, write to the Free Software
2989 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2994 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2995 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
2998 +#ifdef CONFIG_SQUASHFS_VMALLOC
2999 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3000 +#define SQUASHFS_FREE(a) vfree(a)
3002 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3003 +#define SQUASHFS_FREE(a) kfree(a)
3005 +#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3006 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3008 +#define SQUASHFS_CACHED_FRAGMENTS 3
3010 +#define SQUASHFS_MAJOR 3
3011 +#define SQUASHFS_MINOR 0
3012 +#define SQUASHFS_MAGIC 0x73717368
3013 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3014 +#define SQUASHFS_START 0
3016 +/* size of metadata (inode and directory) blocks */
3017 +#define SQUASHFS_METADATA_SIZE 8192
3018 +#define SQUASHFS_METADATA_LOG 13
3020 +/* default size of data blocks */
3021 +#define SQUASHFS_FILE_SIZE 65536
3022 +#define SQUASHFS_FILE_LOG 16
3024 +#define SQUASHFS_FILE_MAX_SIZE 65536
3026 +/* Max number of uids and gids */
3027 +#define SQUASHFS_UIDS 256
3028 +#define SQUASHFS_GUIDS 255
3030 +/* Max length of filename (not 255) */
3031 +#define SQUASHFS_NAME_LEN 256
3033 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3034 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3035 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3036 +#define SQUASHFS_USED_BLK ((long long) -2)
3038 +/* Filesystem flags */
3039 +#define SQUASHFS_NOI 0
3040 +#define SQUASHFS_NOD 1
3041 +#define SQUASHFS_CHECK 2
3042 +#define SQUASHFS_NOF 3
3043 +#define SQUASHFS_NO_FRAG 4
3044 +#define SQUASHFS_ALWAYS_FRAG 5
3045 +#define SQUASHFS_DUPLICATE 6
3047 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3049 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3052 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3055 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3058 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3061 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3062 + SQUASHFS_ALWAYS_FRAG)
3064 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3065 + SQUASHFS_DUPLICATE)
3067 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3070 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3071 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3072 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3073 + (duplicate_checking << 6))
3075 +/* Max number of types and file types */
3076 +#define SQUASHFS_DIR_TYPE 1
3077 +#define SQUASHFS_FILE_TYPE 2
3078 +#define SQUASHFS_SYMLINK_TYPE 3
3079 +#define SQUASHFS_BLKDEV_TYPE 4
3080 +#define SQUASHFS_CHRDEV_TYPE 5
3081 +#define SQUASHFS_FIFO_TYPE 6
3082 +#define SQUASHFS_SOCKET_TYPE 7
3083 +#define SQUASHFS_LDIR_TYPE 8
3084 +#define SQUASHFS_LREG_TYPE 9
3086 +/* 1.0 filesystem type definitions */
3087 +#define SQUASHFS_TYPES 5
3088 +#define SQUASHFS_IPC_TYPE 0
3090 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3092 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3094 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3095 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3097 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3099 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3101 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3102 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3103 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3105 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3108 + * Inode number ops. Inodes consist of a compressed block number, and an
3109 + * uncompressed offset within that block
3111 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3113 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3115 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3118 +/* Compute 32 bit VFS inode number from squashfs inode number */
3119 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3123 +/* Translate between VFS mode and squashfs mode */
3124 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3126 +/* fragment and fragment table defines */
3127 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3129 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3130 + SQUASHFS_METADATA_SIZE)
3132 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3133 + SQUASHFS_METADATA_SIZE)
3135 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3136 + SQUASHFS_METADATA_SIZE - 1) / \
3137 + SQUASHFS_METADATA_SIZE)
3139 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3140 + sizeof(long long))
3142 +/* cached data constants for filesystem */
3143 +#define SQUASHFS_CACHED_BLKS 8
3145 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3147 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3148 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3150 +#define SQUASHFS_MARKER_BYTE 0xff
3152 +/* meta index cache */
3153 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3154 +#define SQUASHFS_META_ENTRIES 31
3155 +#define SQUASHFS_META_NUMBER 8
3156 +#define SQUASHFS_SLOTS 4
3158 +struct meta_entry {
3159 + long long data_block;
3160 + unsigned int index_block;
3161 + unsigned short offset;
3162 + unsigned short pad;
3165 +struct meta_index {
3166 + unsigned int inode_number;
3167 + unsigned int offset;
3168 + unsigned short entries;
3169 + unsigned short skip;
3170 + unsigned short locked;
3171 + unsigned short pad;
3172 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3177 + * definitions for structures on disk
3180 +typedef long long squashfs_block_t;
3181 +typedef long long squashfs_inode_t;
3183 +struct squashfs_super_block {
3184 + unsigned int s_magic;
3185 + unsigned int inodes;
3186 + unsigned int bytes_used_2;
3187 + unsigned int uid_start_2;
3188 + unsigned int guid_start_2;
3189 + unsigned int inode_table_start_2;
3190 + unsigned int directory_table_start_2;
3191 + unsigned int s_major:16;
3192 + unsigned int s_minor:16;
3193 + unsigned int block_size_1:16;
3194 + unsigned int block_log:16;
3195 + unsigned int flags:8;
3196 + unsigned int no_uids:8;
3197 + unsigned int no_guids:8;
3198 + unsigned int mkfs_time /* time of filesystem creation */;
3199 + squashfs_inode_t root_inode;
3200 + unsigned int block_size;
3201 + unsigned int fragments;
3202 + unsigned int fragment_table_start_2;
3203 + long long bytes_used;
3204 + long long uid_start;
3205 + long long guid_start;
3206 + long long inode_table_start;
3207 + long long directory_table_start;
3208 + long long fragment_table_start;
3210 +} __attribute__ ((packed));
3212 +struct squashfs_dir_index {
3213 + unsigned int index;
3214 + unsigned int start_block;
3215 + unsigned char size;
3216 + unsigned char name[0];
3217 +} __attribute__ ((packed));
3219 +#define SQUASHFS_BASE_INODE_HEADER \
3220 + unsigned int inode_type:4; \
3221 + unsigned int mode:12; \
3222 + unsigned int uid:8; \
3223 + unsigned int guid:8; \
3224 + unsigned int mtime; \
3225 + unsigned int inode_number;
3227 +struct squashfs_base_inode_header {
3228 + SQUASHFS_BASE_INODE_HEADER;
3229 +} __attribute__ ((packed));
3231 +struct squashfs_ipc_inode_header {
3232 + SQUASHFS_BASE_INODE_HEADER;
3233 + unsigned int nlink;
3234 +} __attribute__ ((packed));
3236 +struct squashfs_dev_inode_header {
3237 + SQUASHFS_BASE_INODE_HEADER;
3238 + unsigned int nlink;
3239 + unsigned short rdev;
3240 +} __attribute__ ((packed));
3242 +struct squashfs_symlink_inode_header {
3243 + SQUASHFS_BASE_INODE_HEADER;
3244 + unsigned int nlink;
3245 + unsigned short symlink_size;
3247 +} __attribute__ ((packed));
3249 +struct squashfs_reg_inode_header {
3250 + SQUASHFS_BASE_INODE_HEADER;
3251 + squashfs_block_t start_block;
3252 + unsigned int fragment;
3253 + unsigned int offset;
3254 + unsigned int file_size;
3255 + unsigned short block_list[0];
3256 +} __attribute__ ((packed));
3258 +struct squashfs_lreg_inode_header {
3259 + SQUASHFS_BASE_INODE_HEADER;
3260 + unsigned int nlink;
3261 + squashfs_block_t start_block;
3262 + unsigned int fragment;
3263 + unsigned int offset;
3264 + long long file_size;
3265 + unsigned short block_list[0];
3266 +} __attribute__ ((packed));
3268 +struct squashfs_dir_inode_header {
3269 + SQUASHFS_BASE_INODE_HEADER;
3270 + unsigned int nlink;
3271 + unsigned int file_size:19;
3272 + unsigned int offset:13;
3273 + unsigned int start_block;
3274 + unsigned int parent_inode;
3275 +} __attribute__ ((packed));
3277 +struct squashfs_ldir_inode_header {
3278 + SQUASHFS_BASE_INODE_HEADER;
3279 + unsigned int nlink;
3280 + unsigned int file_size:27;
3281 + unsigned int offset:13;
3282 + unsigned int start_block;
3283 + unsigned int i_count:16;
3284 + unsigned int parent_inode;
3285 + struct squashfs_dir_index index[0];
3286 +} __attribute__ ((packed));
3288 +union squashfs_inode_header {
3289 + struct squashfs_base_inode_header base;
3290 + struct squashfs_dev_inode_header dev;
3291 + struct squashfs_symlink_inode_header symlink;
3292 + struct squashfs_reg_inode_header reg;
3293 + struct squashfs_lreg_inode_header lreg;
3294 + struct squashfs_dir_inode_header dir;
3295 + struct squashfs_ldir_inode_header ldir;
3296 + struct squashfs_ipc_inode_header ipc;
3299 +struct squashfs_dir_entry {
3300 + unsigned int offset:13;
3301 + unsigned int type:3;
3302 + unsigned int size:8;
3303 + int inode_number:16;
3305 +} __attribute__ ((packed));
3307 +struct squashfs_dir_header {
3308 + unsigned int count:8;
3309 + unsigned int start_block;
3310 + unsigned int inode_number;
3311 +} __attribute__ ((packed));
3313 +struct squashfs_fragment_entry {
3314 + long long start_block;
3315 + unsigned int size;
3316 + unsigned int unused;
3317 +} __attribute__ ((packed));
3319 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3320 +extern int squashfs_uncompress_init(void);
3321 +extern int squashfs_uncompress_exit(void);
3324 + * macros to convert each packed bitfield structure from little endian to big
3325 + * endian and vice versa. These are needed when creating or using a filesystem
3326 + * on a machine with different byte ordering to the target architecture.
3330 +#define SQUASHFS_SWAP_START \
3333 + unsigned long long val;\
3334 + unsigned char *s;\
3337 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3338 + SQUASHFS_SWAP_START\
3339 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3340 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3341 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3342 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3343 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3344 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3345 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3346 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3347 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3348 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3349 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3350 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3351 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3352 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3353 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3354 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3355 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3356 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3357 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3358 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3359 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3360 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3361 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3362 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3363 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3364 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3365 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3368 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3369 + SQUASHFS_MEMSET(s, d, n);\
3370 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3371 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3372 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3373 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3374 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3375 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3377 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3378 + SQUASHFS_SWAP_START\
3379 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3382 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3383 + SQUASHFS_SWAP_START\
3384 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3385 + sizeof(struct squashfs_ipc_inode_header))\
3386 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3389 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3390 + SQUASHFS_SWAP_START\
3391 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3392 + sizeof(struct squashfs_dev_inode_header)); \
3393 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3394 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3397 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3398 + SQUASHFS_SWAP_START\
3399 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3400 + sizeof(struct squashfs_symlink_inode_header));\
3401 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3402 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3405 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3406 + SQUASHFS_SWAP_START\
3407 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3408 + sizeof(struct squashfs_reg_inode_header));\
3409 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3410 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3411 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3412 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3415 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3416 + SQUASHFS_SWAP_START\
3417 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3418 + sizeof(struct squashfs_lreg_inode_header));\
3419 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3420 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3421 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3422 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3423 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3426 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3427 + SQUASHFS_SWAP_START\
3428 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3429 + sizeof(struct squashfs_dir_inode_header));\
3430 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3431 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3432 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3433 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3434 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3437 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3438 + SQUASHFS_SWAP_START\
3439 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3440 + sizeof(struct squashfs_ldir_inode_header));\
3441 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3442 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3443 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3444 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3445 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3446 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3449 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3450 + SQUASHFS_SWAP_START\
3451 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3452 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3453 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3454 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3457 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3458 + SQUASHFS_SWAP_START\
3459 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3460 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3461 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3462 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3465 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3466 + SQUASHFS_SWAP_START\
3467 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3468 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3469 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3470 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3471 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3474 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3475 + SQUASHFS_SWAP_START\
3476 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3477 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3478 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3481 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3483 + int bit_position;\
3484 + SQUASHFS_SWAP_START\
3485 + SQUASHFS_MEMSET(s, d, n * 2);\
3486 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3488 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3491 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3493 + int bit_position;\
3494 + SQUASHFS_SWAP_START\
3495 + SQUASHFS_MEMSET(s, d, n * 4);\
3496 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3498 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3501 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3503 + int bit_position;\
3504 + SQUASHFS_SWAP_START\
3505 + SQUASHFS_MEMSET(s, d, n * 8);\
3506 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3508 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3511 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3513 + int bit_position;\
3514 + SQUASHFS_SWAP_START\
3515 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3516 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3518 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3521 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3523 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3525 +struct squashfs_base_inode_header_1 {
3526 + unsigned int inode_type:4;
3527 + unsigned int mode:12; /* protection */
3528 + unsigned int uid:4; /* index into uid table */
3529 + unsigned int guid:4; /* index into guid table */
3530 +} __attribute__ ((packed));
3532 +struct squashfs_ipc_inode_header_1 {
3533 + unsigned int inode_type:4;
3534 + unsigned int mode:12; /* protection */
3535 + unsigned int uid:4; /* index into uid table */
3536 + unsigned int guid:4; /* index into guid table */
3537 + unsigned int type:4;
3538 + unsigned int offset:4;
3539 +} __attribute__ ((packed));
3541 +struct squashfs_dev_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 rdev;
3547 +} __attribute__ ((packed));
3549 +struct squashfs_symlink_inode_header_1 {
3550 + unsigned int inode_type:4;
3551 + unsigned int mode:12; /* protection */
3552 + unsigned int uid:4; /* index into uid table */
3553 + unsigned int guid:4; /* index into guid table */
3554 + unsigned short symlink_size;
3556 +} __attribute__ ((packed));
3558 +struct squashfs_reg_inode_header_1 {
3559 + unsigned int inode_type:4;
3560 + unsigned int mode:12; /* protection */
3561 + unsigned int uid:4; /* index into uid table */
3562 + unsigned int guid:4; /* index into guid table */
3563 + unsigned int mtime;
3564 + unsigned int start_block;
3565 + unsigned int file_size:32;
3566 + unsigned short block_list[0];
3567 +} __attribute__ ((packed));
3569 +struct squashfs_dir_inode_header_1 {
3570 + unsigned int inode_type:4;
3571 + unsigned int mode:12; /* protection */
3572 + unsigned int uid:4; /* index into uid table */
3573 + unsigned int guid:4; /* index into guid table */
3574 + unsigned int file_size:19;
3575 + unsigned int offset:13;
3576 + unsigned int mtime;
3577 + unsigned int start_block:24;
3578 +} __attribute__ ((packed));
3580 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3581 + SQUASHFS_MEMSET(s, d, n);\
3582 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3583 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3584 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3585 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3587 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3588 + SQUASHFS_SWAP_START\
3589 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3592 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3593 + SQUASHFS_SWAP_START\
3594 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3595 + sizeof(struct squashfs_ipc_inode_header_1));\
3596 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3597 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3600 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3601 + SQUASHFS_SWAP_START\
3602 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3603 + sizeof(struct squashfs_dev_inode_header_1));\
3604 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3607 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3608 + SQUASHFS_SWAP_START\
3609 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3610 + sizeof(struct squashfs_symlink_inode_header_1));\
3611 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3614 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3615 + SQUASHFS_SWAP_START\
3616 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3617 + sizeof(struct squashfs_reg_inode_header_1));\
3618 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3619 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3620 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3623 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3624 + SQUASHFS_SWAP_START\
3625 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3626 + sizeof(struct squashfs_dir_inode_header_1));\
3627 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3628 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3629 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3630 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3635 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3637 +struct squashfs_dir_index_2 {
3638 + unsigned int index:27;
3639 + unsigned int start_block:29;
3640 + unsigned char size;
3641 + unsigned char name[0];
3642 +} __attribute__ ((packed));
3644 +struct squashfs_base_inode_header_2 {
3645 + unsigned int inode_type:4;
3646 + unsigned int mode:12; /* protection */
3647 + unsigned int uid:8; /* index into uid table */
3648 + unsigned int guid:8; /* index into guid table */
3649 +} __attribute__ ((packed));
3651 +struct squashfs_ipc_inode_header_2 {
3652 + unsigned int inode_type:4;
3653 + unsigned int mode:12; /* protection */
3654 + unsigned int uid:8; /* index into uid table */
3655 + unsigned int guid:8; /* index into guid table */
3656 +} __attribute__ ((packed));
3658 +struct squashfs_dev_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 rdev;
3664 +} __attribute__ ((packed));
3666 +struct squashfs_symlink_inode_header_2 {
3667 + unsigned int inode_type:4;
3668 + unsigned int mode:12; /* protection */
3669 + unsigned int uid:8; /* index into uid table */
3670 + unsigned int guid:8; /* index into guid table */
3671 + unsigned short symlink_size;
3673 +} __attribute__ ((packed));
3675 +struct squashfs_reg_inode_header_2 {
3676 + unsigned int inode_type:4;
3677 + unsigned int mode:12; /* protection */
3678 + unsigned int uid:8; /* index into uid table */
3679 + unsigned int guid:8; /* index into guid table */
3680 + unsigned int mtime;
3681 + unsigned int start_block;
3682 + unsigned int fragment;
3683 + unsigned int offset;
3684 + unsigned int file_size:32;
3685 + unsigned short block_list[0];
3686 +} __attribute__ ((packed));
3688 +struct squashfs_dir_inode_header_2 {
3689 + unsigned int inode_type:4;
3690 + unsigned int mode:12; /* protection */
3691 + unsigned int uid:8; /* index into uid table */
3692 + unsigned int guid:8; /* index into guid table */
3693 + unsigned int file_size:19;
3694 + unsigned int offset:13;
3695 + unsigned int mtime;
3696 + unsigned int start_block:24;
3697 +} __attribute__ ((packed));
3699 +struct squashfs_ldir_inode_header_2 {
3700 + unsigned int inode_type:4;
3701 + unsigned int mode:12; /* protection */
3702 + unsigned int uid:8; /* index into uid table */
3703 + unsigned int guid:8; /* index into guid table */
3704 + unsigned int file_size:27;
3705 + unsigned int offset:13;
3706 + unsigned int mtime;
3707 + unsigned int start_block:24;
3708 + unsigned int i_count:16;
3709 + struct squashfs_dir_index_2 index[0];
3710 +} __attribute__ ((packed));
3712 +union squashfs_inode_header_2 {
3713 + struct squashfs_base_inode_header_2 base;
3714 + struct squashfs_dev_inode_header_2 dev;
3715 + struct squashfs_symlink_inode_header_2 symlink;
3716 + struct squashfs_reg_inode_header_2 reg;
3717 + struct squashfs_dir_inode_header_2 dir;
3718 + struct squashfs_ldir_inode_header_2 ldir;
3719 + struct squashfs_ipc_inode_header_2 ipc;
3722 +struct squashfs_dir_header_2 {
3723 + unsigned int count:8;
3724 + unsigned int start_block:24;
3725 +} __attribute__ ((packed));
3727 +struct squashfs_dir_entry_2 {
3728 + unsigned int offset:13;
3729 + unsigned int type:3;
3730 + unsigned int size:8;
3732 +} __attribute__ ((packed));
3734 +struct squashfs_fragment_entry_2 {
3735 + unsigned int start_block;
3736 + unsigned int size;
3737 +} __attribute__ ((packed));
3739 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3740 + SQUASHFS_MEMSET(s, d, n);\
3741 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3742 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3743 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3744 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3746 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3747 + SQUASHFS_SWAP_START\
3748 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3751 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3752 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3754 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3755 + SQUASHFS_SWAP_START\
3756 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3757 + sizeof(struct squashfs_dev_inode_header_2)); \
3758 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3761 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3762 + SQUASHFS_SWAP_START\
3763 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3764 + sizeof(struct squashfs_symlink_inode_header_2));\
3765 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3768 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3769 + SQUASHFS_SWAP_START\
3770 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3771 + sizeof(struct squashfs_reg_inode_header_2));\
3772 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3773 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3774 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3775 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3776 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3779 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3780 + SQUASHFS_SWAP_START\
3781 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3782 + sizeof(struct squashfs_dir_inode_header_2));\
3783 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3784 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3785 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3786 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3789 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3790 + SQUASHFS_SWAP_START\
3791 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3792 + sizeof(struct squashfs_ldir_inode_header_2));\
3793 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3794 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3795 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3796 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3797 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3800 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3801 + SQUASHFS_SWAP_START\
3802 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3803 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3804 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3805 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3807 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3808 + SQUASHFS_SWAP_START\
3809 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3810 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3811 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3814 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3815 + SQUASHFS_SWAP_START\
3816 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3817 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3818 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3819 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3822 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3823 + SQUASHFS_SWAP_START\
3824 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3825 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3826 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3829 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3831 +/* fragment and fragment table defines */
3832 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3834 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3835 + SQUASHFS_METADATA_SIZE)
3837 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3838 + SQUASHFS_METADATA_SIZE)
3840 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3841 + SQUASHFS_METADATA_SIZE - 1) / \
3842 + SQUASHFS_METADATA_SIZE)
3844 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3852 + * macros used to swap each structure entry, taking into account
3853 + * bitfields and different bitfield placing conventions on differing
3857 +#include <asm/byteorder.h>
3859 +#ifdef __BIG_ENDIAN
3860 + /* convert from little endian to big endian */
3861 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3864 + /* convert from big endian to little endian */
3865 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3866 + tbits, 64 - tbits - b_pos)
3869 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3872 + s = (unsigned char *)p + (pos / 8);\
3873 + d = ((unsigned char *) &val) + 7;\
3874 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3876 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3879 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3883 Index: linux-2.4.35.4/include/linux/squashfs_fs_i.h
3884 ===================================================================
3886 +++ linux-2.4.35.4/include/linux/squashfs_fs_i.h
3888 +#ifndef SQUASHFS_FS_I
3889 +#define SQUASHFS_FS_I
3893 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3894 + * Phillip Lougher <phillip@lougher.org.uk>
3896 + * This program is free software; you can redistribute it and/or
3897 + * modify it under the terms of the GNU General Public License
3898 + * as published by the Free Software Foundation; either version 2,
3899 + * or (at your option) any later version.
3901 + * This program is distributed in the hope that it will be useful,
3902 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3903 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3904 + * GNU General Public License for more details.
3906 + * You should have received a copy of the GNU General Public License
3907 + * along with this program; if not, write to the Free Software
3908 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3913 +struct squashfs_inode_info {
3914 + long long start_block;
3915 + unsigned int offset;
3918 + long long fragment_start_block;
3919 + unsigned int fragment_size;
3920 + unsigned int fragment_offset;
3921 + long long block_list_start;
3924 + long long directory_index_start;
3925 + unsigned int directory_index_offset;
3926 + unsigned int directory_index_count;
3927 + unsigned int parent_inode;
3932 Index: linux-2.4.35.4/include/linux/squashfs_fs_sb.h
3933 ===================================================================
3935 +++ linux-2.4.35.4/include/linux/squashfs_fs_sb.h
3937 +#ifndef SQUASHFS_FS_SB
3938 +#define SQUASHFS_FS_SB
3942 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3943 + * Phillip Lougher <phillip@lougher.org.uk>
3945 + * This program is free software; you can redistribute it and/or
3946 + * modify it under the terms of the GNU General Public License
3947 + * as published by the Free Software Foundation; either version 2,
3948 + * or (at your option) any later version.
3950 + * This program is distributed in the hope that it will be useful,
3951 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3952 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3953 + * GNU General Public License for more details.
3955 + * You should have received a copy of the GNU General Public License
3956 + * along with this program; if not, write to the Free Software
3957 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3959 + * squashfs_fs_sb.h
3962 +#include <linux/squashfs_fs.h>
3964 +struct squashfs_cache {
3967 + long long next_index;
3971 +struct squashfs_fragment_cache {
3974 + unsigned int locked;
3978 +struct squashfs_sb_info {
3979 + struct squashfs_super_block sblk;
3981 + int devblksize_log2;
3983 + struct squashfs_cache *block_cache;
3984 + struct squashfs_fragment_cache *fragment;
3986 + int next_fragment;
3987 + int next_meta_index;
3988 + unsigned int *uid;
3989 + unsigned int *guid;
3990 + long long *fragment_index;
3991 + unsigned int *fragment_index_2;
3992 + unsigned int read_size;
3995 + struct semaphore read_data_mutex;
3996 + struct semaphore read_page_mutex;
3997 + struct semaphore block_cache_mutex;
3998 + struct semaphore fragment_mutex;
3999 + struct semaphore meta_index_mutex;
4000 + wait_queue_head_t waitq;
4001 + wait_queue_head_t fragment_wait_queue;
4002 + struct meta_index *meta_index;
4003 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4005 + long long (*read_blocklist)(struct inode *inode, int \
4006 + index, int readahead_blks, char *block_list, \
4007 + unsigned short **block_p, unsigned int *bsize);
4008 + int (*read_fragment_index_table)(struct super_block *s);
4011 Index: linux-2.4.35.4/init/do_mounts.c
4012 ===================================================================
4013 --- linux-2.4.35.4.orig/init/do_mounts.c
4014 +++ linux-2.4.35.4/init/do_mounts.c
4016 #include <linux/minix_fs.h>
4017 #include <linux/ext2_fs.h>
4018 #include <linux/romfs_fs.h>
4019 +#include <linux/squashfs_fs.h>
4020 #include <linux/cramfs_fs.h>
4022 #define BUILD_CRAMDISK
4023 @@ -476,6 +477,7 @@ static int __init crd_load(int in_fd, in
4031 @@ -486,6 +488,7 @@ identify_ramdisk_image(int fd, int start
4032 struct minix_super_block *minixsb;
4033 struct ext2_super_block *ext2sb;
4034 struct romfs_super_block *romfsb;
4035 + struct squashfs_super_block *squashfsb;
4036 struct cramfs_super *cramfsb;
4039 @@ -497,6 +500,7 @@ identify_ramdisk_image(int fd, int start
4040 minixsb = (struct minix_super_block *) buf;
4041 ext2sb = (struct ext2_super_block *) buf;
4042 romfsb = (struct romfs_super_block *) buf;
4043 + squashfsb = (struct squashfs_super_block *) buf;
4044 cramfsb = (struct cramfs_super *) buf;
4045 memset(buf, 0xe5, size);
4047 @@ -535,6 +539,15 @@ identify_ramdisk_image(int fd, int start
4051 + /* squashfs is at block zero too */
4052 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4053 + printk(KERN_NOTICE
4054 + "RAMDISK: squashfs filesystem found at block %d\n",
4056 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4061 * Read block 1 to test for minix and ext2 superblock
4063 Index: linux-2.4.35.4/lib/Config.in
4064 ===================================================================
4065 --- linux-2.4.35.4.orig/lib/Config.in
4066 +++ linux-2.4.35.4/lib/Config.in
4067 @@ -10,6 +10,7 @@ tristate 'CRC32 functions' CONFIG_CRC32
4068 # Do we need the compression support?
4070 if [ "$CONFIG_CRAMFS" = "y" -o \
4071 + "$CONFIG_SQUASHFS" = "y" -o \
4072 "$CONFIG_PPP_DEFLATE" = "y" -o \
4073 "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
4074 "$CONFIG_JFFS2_FS" = "y" -o \
4075 @@ -17,6 +18,7 @@ if [ "$CONFIG_CRAMFS" = "y" -o \
4076 define_tristate CONFIG_ZLIB_INFLATE y
4078 if [ "$CONFIG_CRAMFS" = "m" -o \
4079 + "$CONFIG_SQUASHFS" = "m" -o \
4080 "$CONFIG_PPP_DEFLATE" = "m" -o \
4081 "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
4082 "$CONFIG_JFFS2_FS" = "m" -o \