3 @@ -51,6 +51,14 @@ if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFI
4 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
6 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
7 +tristate 'Squashed file system support' CONFIG_SQUASHFS
8 +if [ "$CONFIG_SQUASHFS" = "y" -o "$CONFIG_SQUASHFS" = "m" ] ; then
9 +bool 'Additional options for memory constrained systems ' CONFIG_SQUASHFS_EMBEDDED
11 +if [ "$CONFIG_SQUASHFS_EMBEDDED" = "y" ] ; then
12 +int 'Number of fragments cached' CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE 3
13 +bool 'Use Vmalloc rather than Kmalloc' CONFIG_SQUASHFS_VMALLOC
15 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
16 define_bool CONFIG_RAMFS y
20 @@ -65,6 +65,7 @@ subdir-$(CONFIG_REISERFS_FS) += reiserfs
21 subdir-$(CONFIG_DEVPTS_FS) += devpts
22 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
23 subdir-$(CONFIG_BEFS_FS) += befs
24 +subdir-$(CONFIG_SQUASHFS) += squashfs
25 subdir-$(CONFIG_JFS_FS) += jfs
26 subdir-$(CONFIG_XFS_FS) += xfs
29 +++ b/fs/squashfs/inode.c
32 + * Squashfs - a compressed read only filesystem for Linux
34 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
35 + * Phillip Lougher <phillip@lougher.org.uk>
37 + * This program is free software; you can redistribute it and/or
38 + * modify it under the terms of the GNU General Public License
39 + * as published by the Free Software Foundation; either version 2,
40 + * or (at your option) any later version.
42 + * This program is distributed in the hope that it will be useful,
43 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 + * GNU General Public License for more details.
47 + * You should have received a copy of the GNU General Public License
48 + * along with this program; if not, write to the Free Software
49 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54 +#include <linux/types.h>
55 +#include <linux/squashfs_fs.h>
56 +#include <linux/module.h>
57 +#include <linux/errno.h>
58 +#include <linux/slab.h>
59 +#include <linux/fs.h>
60 +#include <linux/smp_lock.h>
61 +#include <linux/locks.h>
62 +#include <linux/init.h>
63 +#include <linux/dcache.h>
64 +#include <linux/wait.h>
65 +#include <linux/zlib.h>
66 +#include <linux/blkdev.h>
67 +#include <linux/vmalloc.h>
68 +#include <asm/uaccess.h>
69 +#include <asm/semaphore.h>
71 +#include "squashfs.h"
73 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
74 +static void squashfs_put_super(struct super_block *);
75 +static int squashfs_statfs(struct super_block *, struct statfs *);
76 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
77 +static int squashfs_readpage(struct file *file, struct page *page);
78 +static int squashfs_readpage4K(struct file *file, struct page *page);
79 +static int squashfs_readdir(struct file *, void *, filldir_t);
80 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
81 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
82 +static long long read_blocklist(struct inode *inode, int index,
83 + int readahead_blks, char *block_list,
84 + unsigned short **block_p, unsigned int *bsize);
86 +static z_stream stream;
88 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
90 +static unsigned char squashfs_filetype_table[] = {
91 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
94 +static struct super_operations squashfs_ops = {
95 + .statfs = squashfs_statfs,
96 + .put_super = squashfs_put_super,
99 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
100 + .readpage = squashfs_symlink_readpage
103 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
104 + .readpage = squashfs_readpage
107 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
108 + .readpage = squashfs_readpage4K
111 +static struct file_operations squashfs_dir_ops = {
112 + .read = generic_read_dir,
113 + .readdir = squashfs_readdir
116 +static struct inode_operations squashfs_dir_inode_ops = {
117 + .lookup = squashfs_lookup
120 +static struct buffer_head *get_block_length(struct super_block *s,
121 + int *cur_index, int *offset, int *c_byte)
123 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
124 + unsigned short temp;
125 + struct buffer_head *bh;
127 + if (!(bh = sb_bread(s, *cur_index)))
130 + if (msblk->devblksize - *offset == 1) {
132 + ((unsigned char *) &temp)[1] = *((unsigned char *)
133 + (bh->b_data + *offset));
135 + ((unsigned char *) &temp)[0] = *((unsigned char *)
136 + (bh->b_data + *offset));
138 + if (!(bh = sb_bread(s, ++(*cur_index))))
141 + ((unsigned char *) &temp)[0] = *((unsigned char *)
144 + ((unsigned char *) &temp)[1] = *((unsigned char *)
150 + ((unsigned char *) &temp)[1] = *((unsigned char *)
151 + (bh->b_data + *offset));
152 + ((unsigned char *) &temp)[0] = *((unsigned char *)
153 + (bh->b_data + *offset + 1));
155 + ((unsigned char *) &temp)[0] = *((unsigned char *)
156 + (bh->b_data + *offset));
157 + ((unsigned char *) &temp)[1] = *((unsigned char *)
158 + (bh->b_data + *offset + 1));
164 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
165 + if (*offset == msblk->devblksize) {
167 + if (!(bh = sb_bread(s, ++(*cur_index))))
171 + if (*((unsigned char *) (bh->b_data + *offset)) !=
172 + SQUASHFS_MARKER_BYTE) {
173 + ERROR("Metadata block marker corrupt @ %x\n",
187 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
188 + long long index, unsigned int length,
189 + long long *next_index)
191 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
192 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
193 + msblk->devblksize_log2) + 2];
194 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
195 + unsigned int cur_index = index >> msblk->devblksize_log2;
196 + int bytes, avail_bytes, b = 0, k;
198 + unsigned int compressed;
199 + unsigned int c_byte = length;
202 + bytes = msblk->devblksize - offset;
203 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
204 + c_buffer = compressed ? msblk->read_data : buffer;
205 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
207 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
208 + ? "" : "un", (unsigned int) c_byte);
210 + if (!(bh[0] = sb_getblk(s, cur_index)))
211 + goto block_release;
213 + for (b = 1; bytes < c_byte; b++) {
214 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
215 + goto block_release;
216 + bytes += msblk->devblksize;
218 + ll_rw_block(READ, b, bh);
220 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
224 + bytes = msblk->devblksize - offset;
225 + compressed = SQUASHFS_COMPRESSED(c_byte);
226 + c_buffer = compressed ? msblk->read_data : buffer;
227 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
229 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
230 + ? "" : "un", (unsigned int) c_byte);
232 + for (b = 1; bytes < c_byte; b++) {
233 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
234 + goto block_release;
235 + bytes += msblk->devblksize;
237 + ll_rw_block(READ, b - 1, bh + 1);
241 + down(&msblk->read_data_mutex);
243 + for (bytes = 0, k = 0; k < b; k++) {
244 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
245 + msblk->devblksize - offset :
247 + wait_on_buffer(bh[k]);
248 + if (!buffer_uptodate(bh[k]))
249 + goto block_release;
250 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
251 + bytes += avail_bytes;
262 + stream.next_in = c_buffer;
263 + stream.avail_in = c_byte;
264 + stream.next_out = buffer;
265 + stream.avail_out = msblk->read_size;
267 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
268 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
269 + != Z_STREAM_END) || ((zlib_err =
270 + zlib_inflateEnd(&stream)) != Z_OK)) {
271 + ERROR("zlib_fs returned unexpected result 0x%x\n",
275 + bytes = stream.total_out;
277 + up(&msblk->read_data_mutex);
281 + *next_index = index + c_byte + (length ? 0 :
282 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
291 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
296 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
297 + long long block, unsigned int offset,
298 + int length, long long *next_block,
299 + unsigned int *next_offset)
301 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
302 + int n, i, bytes, return_length = length;
303 + long long next_index;
305 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
308 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
309 + if (msblk->block_cache[i].block == block)
312 + down(&msblk->block_cache_mutex);
314 + if (i == SQUASHFS_CACHED_BLKS) {
315 + /* read inode header block */
316 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
317 + n ; n --, i = (i + 1) %
318 + SQUASHFS_CACHED_BLKS)
319 + if (msblk->block_cache[i].block !=
326 + init_waitqueue_entry(&wait, current);
327 + add_wait_queue(&msblk->waitq, &wait);
328 + set_current_state(TASK_UNINTERRUPTIBLE);
329 + up(&msblk->block_cache_mutex);
331 + set_current_state(TASK_RUNNING);
332 + remove_wait_queue(&msblk->waitq, &wait);
335 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
337 + if (msblk->block_cache[i].block ==
338 + SQUASHFS_INVALID_BLK) {
339 + if (!(msblk->block_cache[i].data =
340 + kmalloc(SQUASHFS_METADATA_SIZE,
342 + ERROR("Failed to allocate cache"
344 + up(&msblk->block_cache_mutex);
349 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
350 + up(&msblk->block_cache_mutex);
352 + if (!(msblk->block_cache[i].length =
353 + squashfs_read_data(s,
354 + msblk->block_cache[i].data,
355 + block, 0, &next_index))) {
356 + ERROR("Unable to read cache block [%llx:%x]\n",
361 + down(&msblk->block_cache_mutex);
362 + wake_up(&msblk->waitq);
363 + msblk->block_cache[i].block = block;
364 + msblk->block_cache[i].next_index = next_index;
365 + TRACE("Read cache block [%llx:%x]\n", block, offset);
368 + if (msblk->block_cache[i].block != block) {
369 + up(&msblk->block_cache_mutex);
373 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
375 + memcpy(buffer, msblk->block_cache[i].data +
377 + if (msblk->block_cache[i].length - offset == length) {
378 + *next_block = msblk->block_cache[i].next_index;
381 + *next_block = block;
382 + *next_offset = offset + length;
384 + up(&msblk->block_cache_mutex);
388 + memcpy(buffer, msblk->block_cache[i].data +
392 + block = msblk->block_cache[i].next_index;
393 + up(&msblk->block_cache_mutex);
400 + return return_length;
406 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
407 + long long *fragment_start_block,
408 + unsigned int *fragment_size)
410 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
411 + long long start_block =
412 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
413 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
414 + struct squashfs_fragment_entry fragment_entry;
417 + struct squashfs_fragment_entry sfragment_entry;
419 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
420 + start_block, offset,
421 + sizeof(sfragment_entry), &start_block,
424 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
426 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
427 + start_block, offset,
428 + sizeof(fragment_entry), &start_block,
432 + *fragment_start_block = fragment_entry.start_block;
433 + *fragment_size = fragment_entry.size;
442 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
443 + squashfs_fragment_cache *fragment)
445 + down(&msblk->fragment_mutex);
446 + fragment->locked --;
447 + wake_up(&msblk->fragment_wait_queue);
448 + up(&msblk->fragment_mutex);
452 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
453 + *s, long long start_block,
457 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
460 + down(&msblk->fragment_mutex);
462 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
463 + msblk->fragment[i].block != start_block; i++);
465 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
466 + for (i = msblk->next_fragment, n =
467 + SQUASHFS_CACHED_FRAGMENTS; n &&
468 + msblk->fragment[i].locked; n--, i = (i + 1) %
469 + SQUASHFS_CACHED_FRAGMENTS);
474 + init_waitqueue_entry(&wait, current);
475 + add_wait_queue(&msblk->fragment_wait_queue,
477 + set_current_state(TASK_UNINTERRUPTIBLE);
478 + up(&msblk->fragment_mutex);
480 + set_current_state(TASK_RUNNING);
481 + remove_wait_queue(&msblk->fragment_wait_queue,
485 + msblk->next_fragment = (msblk->next_fragment + 1) %
486 + SQUASHFS_CACHED_FRAGMENTS;
488 + if (msblk->fragment[i].data == NULL)
489 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
490 + (SQUASHFS_FILE_MAX_SIZE))) {
491 + ERROR("Failed to allocate fragment "
493 + up(&msblk->fragment_mutex);
497 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
498 + msblk->fragment[i].locked = 1;
499 + up(&msblk->fragment_mutex);
501 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
502 + msblk->fragment[i].data,
503 + start_block, length, NULL))) {
504 + ERROR("Unable to read fragment cache block "
505 + "[%llx]\n", start_block);
506 + msblk->fragment[i].locked = 0;
510 + msblk->fragment[i].block = start_block;
511 + TRACE("New fragment %d, start block %lld, locked %d\n",
512 + i, msblk->fragment[i].block,
513 + msblk->fragment[i].locked);
517 + msblk->fragment[i].locked++;
518 + up(&msblk->fragment_mutex);
519 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
520 + msblk->fragment[i].block,
521 + msblk->fragment[i].locked);
525 + return &msblk->fragment[i];
532 +static struct inode *squashfs_new_inode(struct super_block *s,
533 + struct squashfs_base_inode_header *inodeb)
535 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
536 + struct inode *i = new_inode(s);
539 + i->i_ino = inodeb->inode_number;
540 + i->i_mtime = inodeb->mtime;
541 + i->i_atime = inodeb->mtime;
542 + i->i_ctime = inodeb->mtime;
543 + i->i_uid = msblk->uid[inodeb->uid];
544 + i->i_mode = inodeb->mode;
546 + if (inodeb->guid == SQUASHFS_GUIDS)
547 + i->i_gid = i->i_uid;
549 + i->i_gid = msblk->guid[inodeb->guid];
556 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
559 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
560 + struct squashfs_super_block *sblk = &msblk->sblk;
561 + long long block = SQUASHFS_INODE_BLK(inode) +
562 + sblk->inode_table_start;
563 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
564 + long long next_block;
565 + unsigned int next_offset;
566 + union squashfs_inode_header id, sid;
567 + struct squashfs_base_inode_header *inodeb = &id.base,
568 + *sinodeb = &sid.base;
570 + TRACE("Entered squashfs_iget\n");
573 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
574 + offset, sizeof(*sinodeb), &next_block,
577 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
580 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
581 + offset, sizeof(*inodeb), &next_block,
585 + switch(inodeb->inode_type) {
586 + case SQUASHFS_FILE_TYPE: {
587 + unsigned int frag_size;
588 + long long frag_blk;
589 + struct squashfs_reg_inode_header *inodep = &id.reg;
590 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
593 + if (!squashfs_get_cached_block(s, (char *)
594 + sinodep, block, offset,
595 + sizeof(*sinodep), &next_block,
598 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
600 + if (!squashfs_get_cached_block(s, (char *)
601 + inodep, block, offset,
602 + sizeof(*inodep), &next_block,
606 + frag_blk = SQUASHFS_INVALID_BLK;
607 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
608 + !get_fragment_location(s,
609 + inodep->fragment, &frag_blk, &frag_size))
612 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
616 + i->i_size = inodep->file_size;
617 + i->i_fop = &generic_ro_fops;
618 + i->i_mode |= S_IFREG;
619 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
620 + i->i_blksize = PAGE_CACHE_SIZE;
621 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
622 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
623 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
624 + SQUASHFS_I(i)->start_block = inodep->start_block;
625 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
626 + SQUASHFS_I(i)->offset = next_offset;
627 + if (sblk->block_size > 4096)
628 + i->i_data.a_ops = &squashfs_aops;
630 + i->i_data.a_ops = &squashfs_aops_4K;
632 + TRACE("File inode %x:%x, start_block %llx, "
633 + "block_list_start %llx, offset %x\n",
634 + SQUASHFS_INODE_BLK(inode), offset,
635 + inodep->start_block, next_block,
639 + case SQUASHFS_LREG_TYPE: {
640 + unsigned int frag_size;
641 + long long frag_blk;
642 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
643 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
646 + if (!squashfs_get_cached_block(s, (char *)
647 + sinodep, block, offset,
648 + sizeof(*sinodep), &next_block,
651 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
653 + if (!squashfs_get_cached_block(s, (char *)
654 + inodep, block, offset,
655 + sizeof(*inodep), &next_block,
659 + frag_blk = SQUASHFS_INVALID_BLK;
660 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
661 + !get_fragment_location(s,
662 + inodep->fragment, &frag_blk, &frag_size))
665 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
668 + i->i_nlink = inodep->nlink;
669 + i->i_size = inodep->file_size;
670 + i->i_fop = &generic_ro_fops;
671 + i->i_mode |= S_IFREG;
672 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
673 + i->i_blksize = PAGE_CACHE_SIZE;
674 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
675 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
676 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
677 + SQUASHFS_I(i)->start_block = inodep->start_block;
678 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
679 + SQUASHFS_I(i)->offset = next_offset;
680 + if (sblk->block_size > 4096)
681 + i->i_data.a_ops = &squashfs_aops;
683 + i->i_data.a_ops = &squashfs_aops_4K;
685 + TRACE("File inode %x:%x, start_block %llx, "
686 + "block_list_start %llx, offset %x\n",
687 + SQUASHFS_INODE_BLK(inode), offset,
688 + inodep->start_block, next_block,
692 + case SQUASHFS_DIR_TYPE: {
693 + struct squashfs_dir_inode_header *inodep = &id.dir;
694 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
697 + if (!squashfs_get_cached_block(s, (char *)
698 + sinodep, block, offset,
699 + sizeof(*sinodep), &next_block,
702 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
704 + if (!squashfs_get_cached_block(s, (char *)
705 + inodep, block, offset,
706 + sizeof(*inodep), &next_block,
710 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
713 + i->i_nlink = inodep->nlink;
714 + i->i_size = inodep->file_size;
715 + i->i_op = &squashfs_dir_inode_ops;
716 + i->i_fop = &squashfs_dir_ops;
717 + i->i_mode |= S_IFDIR;
718 + SQUASHFS_I(i)->start_block = inodep->start_block;
719 + SQUASHFS_I(i)->offset = inodep->offset;
720 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
721 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
723 + TRACE("Directory inode %x:%x, start_block %x, offset "
724 + "%x\n", SQUASHFS_INODE_BLK(inode),
725 + offset, inodep->start_block,
729 + case SQUASHFS_LDIR_TYPE: {
730 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
731 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
734 + if (!squashfs_get_cached_block(s, (char *)
735 + sinodep, block, offset,
736 + sizeof(*sinodep), &next_block,
739 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
742 + if (!squashfs_get_cached_block(s, (char *)
743 + inodep, block, offset,
744 + sizeof(*inodep), &next_block,
748 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
751 + i->i_nlink = inodep->nlink;
752 + i->i_size = inodep->file_size;
753 + i->i_op = &squashfs_dir_inode_ops;
754 + i->i_fop = &squashfs_dir_ops;
755 + i->i_mode |= S_IFDIR;
756 + SQUASHFS_I(i)->start_block = inodep->start_block;
757 + SQUASHFS_I(i)->offset = inodep->offset;
758 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
759 + SQUASHFS_I(i)->u.s2.directory_index_offset =
761 + SQUASHFS_I(i)->u.s2.directory_index_count =
763 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
765 + TRACE("Long directory inode %x:%x, start_block %x, "
767 + SQUASHFS_INODE_BLK(inode), offset,
768 + inodep->start_block, inodep->offset);
771 + case SQUASHFS_SYMLINK_TYPE: {
772 + struct squashfs_symlink_inode_header *inodep =
774 + struct squashfs_symlink_inode_header *sinodep =
778 + if (!squashfs_get_cached_block(s, (char *)
779 + sinodep, block, offset,
780 + sizeof(*sinodep), &next_block,
783 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
786 + if (!squashfs_get_cached_block(s, (char *)
787 + inodep, block, offset,
788 + sizeof(*inodep), &next_block,
792 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
795 + i->i_nlink = inodep->nlink;
796 + i->i_size = inodep->symlink_size;
797 + i->i_op = &page_symlink_inode_operations;
798 + i->i_data.a_ops = &squashfs_symlink_aops;
799 + i->i_mode |= S_IFLNK;
800 + SQUASHFS_I(i)->start_block = next_block;
801 + SQUASHFS_I(i)->offset = next_offset;
803 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
805 + SQUASHFS_INODE_BLK(inode), offset,
806 + next_block, next_offset);
809 + case SQUASHFS_BLKDEV_TYPE:
810 + case SQUASHFS_CHRDEV_TYPE: {
811 + struct squashfs_dev_inode_header *inodep = &id.dev;
812 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
815 + if (!squashfs_get_cached_block(s, (char *)
816 + sinodep, block, offset,
817 + sizeof(*sinodep), &next_block,
820 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
822 + if (!squashfs_get_cached_block(s, (char *)
823 + inodep, block, offset,
824 + sizeof(*inodep), &next_block,
828 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
831 + i->i_nlink = inodep->nlink;
832 + i->i_mode |= (inodeb->inode_type ==
833 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
835 + init_special_inode(i, i->i_mode, inodep->rdev);
837 + TRACE("Device inode %x:%x, rdev %x\n",
838 + SQUASHFS_INODE_BLK(inode), offset,
842 + case SQUASHFS_FIFO_TYPE:
843 + case SQUASHFS_SOCKET_TYPE: {
844 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
845 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
848 + if (!squashfs_get_cached_block(s, (char *)
849 + sinodep, block, offset,
850 + sizeof(*sinodep), &next_block,
853 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
855 + if (!squashfs_get_cached_block(s, (char *)
856 + inodep, block, offset,
857 + sizeof(*inodep), &next_block,
861 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
864 + i->i_nlink = inodep->nlink;
865 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
866 + ? S_IFIFO : S_IFSOCK;
867 + init_special_inode(i, i->i_mode, 0);
871 + ERROR("Unknown inode type %d in squashfs_iget!\n",
872 + inodeb->inode_type);
876 + insert_inode_hash(i);
880 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
887 +int read_fragment_index_table(struct super_block *s)
889 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
890 + struct squashfs_super_block *sblk = &msblk->sblk;
892 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
893 + (sblk->fragments), GFP_KERNEL))) {
894 + ERROR("Failed to allocate uid/gid table\n");
898 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
899 + !squashfs_read_data(s, (char *)
900 + msblk->fragment_index,
901 + sblk->fragment_table_start,
902 + SQUASHFS_FRAGMENT_INDEX_BYTES
903 + (sblk->fragments) |
904 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
905 + ERROR("unable to read fragment index table\n");
911 + long long fragment;
913 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
915 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
916 + &msblk->fragment_index[i], 1);
917 + msblk->fragment_index[i] = fragment;
925 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
927 + struct squashfs_super_block *sblk = &msblk->sblk;
929 + msblk->iget = squashfs_iget;
930 + msblk->read_blocklist = read_blocklist;
931 + msblk->read_fragment_index_table = read_fragment_index_table;
933 + if (sblk->s_major == 1) {
934 + if (!squashfs_1_0_supported(msblk)) {
935 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
936 + "are unsupported\n");
937 + SERROR("Please recompile with "
938 + "Squashfs 1.0 support enabled\n");
941 + } else if (sblk->s_major == 2) {
942 + if (!squashfs_2_0_supported(msblk)) {
943 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
944 + "are unsupported\n");
945 + SERROR("Please recompile with "
946 + "Squashfs 2.0 support enabled\n");
949 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
951 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
952 + "filesystem\n", sblk->s_major, sblk->s_minor);
953 + SERROR("Please update your kernel\n");
961 +static struct super_block *squashfs_read_super(struct super_block *s,
962 + void *data, int silent)
964 + kdev_t dev = s->s_dev;
965 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
966 + struct squashfs_super_block *sblk = &msblk->sblk;
968 + struct inode *root;
970 + msblk->devblksize = get_hardsect_size(dev);
971 + if(msblk->devblksize < BLOCK_SIZE)
972 + msblk->devblksize = BLOCK_SIZE;
973 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
974 + set_blocksize(dev, msblk->devblksize);
975 + s->s_blocksize = msblk->devblksize;
976 + s->s_blocksize_bits = msblk->devblksize_log2;
978 + init_MUTEX(&msblk->read_data_mutex);
979 + init_MUTEX(&msblk->read_page_mutex);
980 + init_MUTEX(&msblk->block_cache_mutex);
981 + init_MUTEX(&msblk->fragment_mutex);
983 + init_waitqueue_head(&msblk->waitq);
984 + init_waitqueue_head(&msblk->fragment_wait_queue);
986 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
987 + sizeof(struct squashfs_super_block) |
988 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
989 + SERROR("unable to read superblock\n");
993 + /* Check it is a SQUASHFS superblock */
995 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
996 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
997 + struct squashfs_super_block ssblk;
999 + WARNING("Mounting a different endian SQUASHFS "
1000 + "filesystem on %s\n", bdevname(dev));
1002 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1003 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1006 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1008 + goto failed_mount;
1012 + /* Check the MAJOR & MINOR versions */
1013 + if(!supported_squashfs_filesystem(msblk, silent))
1014 + goto failed_mount;
1016 + TRACE("Found valid superblock on %s\n", bdevname(dev));
1017 + TRACE("Inodes are %scompressed\n",
1018 + SQUASHFS_UNCOMPRESSED_INODES
1019 + (sblk->flags) ? "un" : "");
1020 + TRACE("Data is %scompressed\n",
1021 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1023 + TRACE("Check data is %s present in the filesystem\n",
1024 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1026 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1027 + TRACE("Block size %d\n", sblk->block_size);
1028 + TRACE("Number of inodes %d\n", sblk->inodes);
1029 + if (sblk->s_major > 1)
1030 + TRACE("Number of fragments %d\n", sblk->fragments);
1031 + TRACE("Number of uids %d\n", sblk->no_uids);
1032 + TRACE("Number of gids %d\n", sblk->no_guids);
1033 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1034 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1035 + if (sblk->s_major > 1)
1036 + TRACE("sblk->fragment_table_start %llx\n",
1037 + sblk->fragment_table_start);
1038 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1040 + s->s_flags |= MS_RDONLY;
1041 + s->s_op = &squashfs_ops;
1043 + /* Init inode_table block pointer array */
1044 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1045 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1046 + ERROR("Failed to allocate block cache\n");
1047 + goto failed_mount;
1050 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1051 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1053 + msblk->next_cache = 0;
1055 + /* Allocate read_data block */
1056 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1057 + SQUASHFS_METADATA_SIZE :
1060 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1061 + ERROR("Failed to allocate read_data block\n");
1062 + goto failed_mount;
1065 + /* Allocate read_page block */
1066 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1067 + ERROR("Failed to allocate read_page block\n");
1068 + goto failed_mount;
1071 + /* Allocate uid and gid tables */
1072 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1073 + sizeof(unsigned int), GFP_KERNEL))) {
1074 + ERROR("Failed to allocate uid/gid table\n");
1075 + goto failed_mount;
1077 + msblk->guid = msblk->uid + sblk->no_uids;
1079 + if (msblk->swap) {
1080 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1082 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1083 + ((sblk->no_uids + sblk->no_guids) *
1084 + sizeof(unsigned int)) |
1085 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1086 + ERROR("unable to read uid/gid table\n");
1087 + goto failed_mount;
1090 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1091 + sblk->no_guids), (sizeof(unsigned int) * 8));
1093 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1094 + ((sblk->no_uids + sblk->no_guids) *
1095 + sizeof(unsigned int)) |
1096 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1097 + ERROR("unable to read uid/gid table\n");
1098 + goto failed_mount;
1102 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1103 + goto allocate_root;
1105 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1106 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1107 + ERROR("Failed to allocate fragment block cache\n");
1108 + goto failed_mount;
1111 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1112 + msblk->fragment[i].locked = 0;
1113 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1114 + msblk->fragment[i].data = NULL;
1117 + msblk->next_fragment = 0;
1119 + /* Allocate fragment index table */
1120 + if(msblk->read_fragment_index_table(s) == 0)
1121 + goto failed_mount;
1124 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1125 + goto failed_mount;
1127 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1128 + ERROR("Root inode create failed\n");
1130 + goto failed_mount;
1133 + TRACE("Leaving squashfs_read_super\n");
1137 + kfree(msblk->fragment_index);
1138 + kfree(msblk->fragment);
1139 + kfree(msblk->uid);
1140 + kfree(msblk->read_page);
1141 + kfree(msblk->read_data);
1142 + kfree(msblk->block_cache);
1143 + kfree(msblk->fragment_index_2);
1148 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1150 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1151 + struct squashfs_super_block *sblk = &msblk->sblk;
1153 + TRACE("Entered squashfs_statfs\n");
1155 + buf->f_type = SQUASHFS_MAGIC;
1156 + buf->f_bsize = sblk->block_size;
1157 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1158 + buf->f_bfree = buf->f_bavail = 0;
1159 + buf->f_files = sblk->inodes;
1161 + buf->f_namelen = SQUASHFS_NAME_LEN;
1167 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1169 + struct inode *inode = page->mapping->host;
1170 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1171 + long long block = SQUASHFS_I(inode)->start_block;
1172 + int offset = SQUASHFS_I(inode)->offset;
1173 + void *pageaddr = kmap(page);
1175 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1176 + "%llx, offset %x\n", page->index,
1177 + SQUASHFS_I(inode)->start_block,
1178 + SQUASHFS_I(inode)->offset);
1180 + for (length = 0; length < index; length += bytes) {
1181 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1182 + block, offset, PAGE_CACHE_SIZE, &block,
1184 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1190 + if (length != index) {
1191 + ERROR("(squashfs_symlink_readpage) length != index\n");
1196 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1197 + i_size_read(inode) - length;
1199 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1200 + offset, bytes, &block, &offset)))
1201 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1204 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1206 + SetPageUptodate(page);
1213 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1215 + struct meta_index *meta = NULL;
1216 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1219 + down(&msblk->meta_index_mutex);
1221 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1223 + if(msblk->meta_index == NULL)
1224 + goto not_allocated;
1226 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1227 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1228 + msblk->meta_index[i].offset >= offset &&
1229 + msblk->meta_index[i].offset <= index &&
1230 + msblk->meta_index[i].locked == 0) {
1231 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1232 + msblk->meta_index[i].offset);
1233 + meta = &msblk->meta_index[i];
1234 + offset = meta->offset;
1241 + up(&msblk->meta_index_mutex);
1247 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1249 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1250 + struct meta_index *meta = NULL;
1253 + down(&msblk->meta_index_mutex);
1255 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1257 + if(msblk->meta_index == NULL) {
1258 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1259 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1260 + ERROR("Failed to allocate meta_index\n");
1263 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1264 + msblk->meta_index[i].inode_number = 0;
1265 + msblk->meta_index[i].locked = 0;
1267 + msblk->next_meta_index = 0;
1270 + for(i = SQUASHFS_META_NUMBER; i &&
1271 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1272 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1273 + SQUASHFS_META_NUMBER;
1276 + TRACE("empty_meta_index: failed!\n");
1280 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1281 + msblk->next_meta_index,
1282 + &msblk->meta_index[msblk->next_meta_index]);
1284 + meta = &msblk->meta_index[msblk->next_meta_index];
1285 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1286 + SQUASHFS_META_NUMBER;
1288 + meta->inode_number = inode->i_ino;
1289 + meta->offset = offset;
1290 + meta->skip = skip;
1291 + meta->entries = 0;
1295 + up(&msblk->meta_index_mutex);
1300 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1306 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1307 + long long *start_block, int *offset)
1309 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1310 + unsigned int *block_listp;
1313 + if (msblk->swap) {
1314 + char sblock_list[blocks << 2];
1316 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1317 + *offset, blocks << 2, start_block, offset)) {
1318 + ERROR("Unable to read block list [%llx:%x]\n",
1319 + *start_block, *offset);
1322 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1323 + ((unsigned int *)sblock_list), blocks);
1325 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1326 + *offset, blocks << 2, start_block, offset)) {
1327 + ERROR("Unable to read block list [%llx:%x]\n",
1328 + *start_block, *offset);
1332 + for (block_listp = (unsigned int *) block_list; blocks;
1333 + block_listp++, blocks --)
1334 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1345 +static inline int calculate_skip(int blocks) {
1346 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1347 + return skip >= 7 ? 7 : skip + 1;
1351 +static int get_meta_index(struct inode *inode, int index,
1352 + long long *index_block, int *index_offset,
1353 + long long *data_block, char *block_list)
1355 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1356 + struct squashfs_super_block *sblk = &msblk->sblk;
1357 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1359 + struct meta_index *meta;
1360 + struct meta_entry *meta_entry;
1361 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1362 + int cur_offset = SQUASHFS_I(inode)->offset;
1363 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1366 + index /= SQUASHFS_META_INDEXES * skip;
1368 + while ( offset < index ) {
1369 + meta = locate_meta_index(inode, index, offset + 1);
1371 + if (meta == NULL) {
1372 + if ((meta = empty_meta_index(inode, offset + 1,
1376 + offset = index < meta->offset + meta->entries ? index :
1377 + meta->offset + meta->entries - 1;
1378 + meta_entry = &meta->meta_entry[offset - meta->offset];
1379 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1380 + cur_offset = meta_entry->offset;
1381 + cur_data_block = meta_entry->data_block;
1382 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1383 + "meta->entries %d\n", offset, meta->offset,
1385 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1386 + " data_block 0x%llx\n", cur_index_block,
1387 + cur_offset, cur_data_block);
1390 + for (i = meta->offset + meta->entries; i <= index &&
1391 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1392 + int blocks = skip * SQUASHFS_META_INDEXES;
1395 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1397 + int res = read_block_index(inode->i_sb, block,
1398 + block_list, &cur_index_block,
1404 + cur_data_block += res;
1408 + meta_entry = &meta->meta_entry[i - meta->offset];
1409 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1410 + meta_entry->offset = cur_offset;
1411 + meta_entry->data_block = cur_data_block;
1416 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1417 + meta->offset, meta->entries);
1419 + release_meta_index(inode, meta);
1423 + *index_block = cur_index_block;
1424 + *index_offset = cur_offset;
1425 + *data_block = cur_data_block;
1427 + return offset * SQUASHFS_META_INDEXES * skip;
1430 + release_meta_index(inode, meta);
1435 +static long long read_blocklist(struct inode *inode, int index,
1436 + int readahead_blks, char *block_list,
1437 + unsigned short **block_p, unsigned int *bsize)
1439 + long long block_ptr;
1442 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1445 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1446 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1455 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1456 + int res = read_block_index(inode->i_sb, blocks, block_list,
1457 + &block_ptr, &offset);
1464 + if (read_block_index(inode->i_sb, 1, block_list,
1465 + &block_ptr, &offset) == -1)
1467 + *bsize = *((unsigned int *) block_list);
1476 +static int squashfs_readpage(struct file *file, struct page *page)
1478 + struct inode *inode = page->mapping->host;
1479 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1480 + struct squashfs_super_block *sblk = &msblk->sblk;
1481 + unsigned char block_list[SIZE];
1483 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1484 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1486 + struct squashfs_fragment_cache *fragment = NULL;
1487 + char *data_ptr = msblk->read_page;
1489 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1490 + int start_index = page->index & ~mask;
1491 + int end_index = start_index | mask;
1493 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1495 + SQUASHFS_I(inode)->start_block);
1497 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1498 + PAGE_CACHE_SHIFT))
1501 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1502 + || index < (i_size_read(inode) >>
1503 + sblk->block_log)) {
1504 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1505 + block_list, NULL, &bsize)) == 0)
1508 + down(&msblk->read_page_mutex);
1510 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1511 + block, bsize, NULL))) {
1512 + ERROR("Unable to read page, block %llx, size %x\n", block,
1514 + up(&msblk->read_page_mutex);
1518 + if ((fragment = get_cached_fragment(inode->i_sb,
1519 + SQUASHFS_I(inode)->
1520 + u.s1.fragment_start_block,
1521 + SQUASHFS_I(inode)->u.s1.fragment_size))
1523 + ERROR("Unable to read page, block %llx, size %x\n",
1524 + SQUASHFS_I(inode)->
1525 + u.s1.fragment_start_block,
1526 + (int) SQUASHFS_I(inode)->
1527 + u.s1.fragment_size);
1530 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1531 + (i_size_read(inode) & (sblk->block_size
1533 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1534 + data_ptr = fragment->data;
1537 + for (i = start_index; i <= end_index && byte_offset < bytes;
1538 + i++, byte_offset += PAGE_CACHE_SIZE) {
1539 + struct page *push_page;
1540 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1541 + PAGE_CACHE_SIZE : bytes - byte_offset;
1543 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1544 + bytes, i, byte_offset, available_bytes);
1546 + if (i == page->index) {
1547 + pageaddr = kmap_atomic(page, KM_USER0);
1548 + memcpy(pageaddr, data_ptr + byte_offset,
1550 + memset(pageaddr + available_bytes, 0,
1551 + PAGE_CACHE_SIZE - available_bytes);
1552 + kunmap_atomic(pageaddr, KM_USER0);
1553 + flush_dcache_page(page);
1554 + SetPageUptodate(page);
1556 + } else if ((push_page =
1557 + grab_cache_page_nowait(page->mapping, i))) {
1558 + pageaddr = kmap_atomic(push_page, KM_USER0);
1560 + memcpy(pageaddr, data_ptr + byte_offset,
1562 + memset(pageaddr + available_bytes, 0,
1563 + PAGE_CACHE_SIZE - available_bytes);
1564 + kunmap_atomic(pageaddr, KM_USER0);
1565 + flush_dcache_page(push_page);
1566 + SetPageUptodate(push_page);
1567 + UnlockPage(push_page);
1568 + page_cache_release(push_page);
1572 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1573 + || index < (i_size_read(inode) >>
1575 + up(&msblk->read_page_mutex);
1577 + release_cached_fragment(msblk, fragment);
1582 + pageaddr = kmap_atomic(page, KM_USER0);
1583 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1584 + kunmap_atomic(pageaddr, KM_USER0);
1585 + flush_dcache_page(page);
1586 + SetPageUptodate(page);
1593 +static int squashfs_readpage4K(struct file *file, struct page *page)
1595 + struct inode *inode = page->mapping->host;
1596 + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
1597 + struct squashfs_super_block *sblk = &msblk->sblk;
1598 + unsigned char block_list[SIZE];
1600 + unsigned int bsize, bytes = 0;
1603 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1605 + SQUASHFS_I(inode)->start_block);
1607 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1608 + PAGE_CACHE_SHIFT)) {
1609 + pageaddr = kmap_atomic(page, KM_USER0);
1613 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1614 + || page->index < (i_size_read(inode) >>
1615 + sblk->block_log)) {
1616 + block = (msblk->read_blocklist)(inode, page->index, 1,
1617 + block_list, NULL, &bsize);
1619 + down(&msblk->read_page_mutex);
1620 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1622 + pageaddr = kmap_atomic(page, KM_USER0);
1624 + memcpy(pageaddr, msblk->read_page, bytes);
1626 + ERROR("Unable to read page, block %llx, size %x\n",
1628 + up(&msblk->read_page_mutex);
1630 + struct squashfs_fragment_cache *fragment =
1631 + get_cached_fragment(inode->i_sb,
1632 + SQUASHFS_I(inode)->
1633 + u.s1.fragment_start_block,
1634 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1635 + pageaddr = kmap_atomic(page, KM_USER0);
1637 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1638 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1639 + u.s1.fragment_offset, bytes);
1640 + release_cached_fragment(msblk, fragment);
1642 + ERROR("Unable to read page, block %llx, size %x\n",
1643 + SQUASHFS_I(inode)->
1644 + u.s1.fragment_start_block, (int)
1645 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1649 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1650 + kunmap_atomic(pageaddr, KM_USER0);
1651 + flush_dcache_page(page);
1652 + SetPageUptodate(page);
1659 +static int get_dir_index_using_offset(struct super_block *s, long long
1660 + *next_block, unsigned int *next_offset,
1661 + long long index_start,
1662 + unsigned int index_offset, int i_count,
1665 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1666 + struct squashfs_super_block *sblk = &msblk->sblk;
1667 + int i, length = 0;
1668 + struct squashfs_dir_index index;
1670 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1671 + i_count, (unsigned int) f_pos);
1677 + for (i = 0; i < i_count; i++) {
1678 + if (msblk->swap) {
1679 + struct squashfs_dir_index sindex;
1680 + squashfs_get_cached_block(s, (char *) &sindex,
1681 + index_start, index_offset,
1682 + sizeof(sindex), &index_start,
1684 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1686 + squashfs_get_cached_block(s, (char *) &index,
1687 + index_start, index_offset,
1688 + sizeof(index), &index_start,
1691 + if (index.index > f_pos)
1694 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1695 + index.size + 1, &index_start,
1698 + length = index.index;
1699 + *next_block = index.start_block + sblk->directory_table_start;
1702 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1705 + return length + 3;
1709 +static int get_dir_index_using_name(struct super_block *s, long long
1710 + *next_block, unsigned int *next_offset,
1711 + long long index_start,
1712 + unsigned int index_offset, int i_count,
1713 + const char *name, int size)
1715 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
1716 + struct squashfs_super_block *sblk = &msblk->sblk;
1717 + int i, length = 0;
1718 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1719 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1720 + char str[SQUASHFS_NAME_LEN + 1];
1722 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1724 + strncpy(str, name, size);
1727 + for (i = 0; i < i_count; i++) {
1728 + if (msblk->swap) {
1729 + struct squashfs_dir_index sindex;
1730 + squashfs_get_cached_block(s, (char *) &sindex,
1731 + index_start, index_offset,
1732 + sizeof(sindex), &index_start,
1734 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1736 + squashfs_get_cached_block(s, (char *) index,
1737 + index_start, index_offset,
1738 + sizeof(struct squashfs_dir_index),
1739 + &index_start, &index_offset);
1741 + squashfs_get_cached_block(s, index->name, index_start,
1742 + index_offset, index->size + 1,
1743 + &index_start, &index_offset);
1745 + index->name[index->size + 1] = '\0';
1747 + if (strcmp(index->name, str) > 0)
1750 + length = index->index;
1751 + *next_block = index->start_block + sblk->directory_table_start;
1754 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1755 + return length + 3;
1759 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1761 + struct inode *i = file->f_dentry->d_inode;
1762 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1763 + struct squashfs_super_block *sblk = &msblk->sblk;
1764 + long long next_block = SQUASHFS_I(i)->start_block +
1765 + sblk->directory_table_start;
1766 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1768 + struct squashfs_dir_header dirh;
1769 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1770 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1772 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1774 + while(file->f_pos < 3) {
1778 + if(file->f_pos == 0) {
1785 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1787 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1788 + (unsigned int) dirent, name, size, (int)
1789 + file->f_pos, i_ino,
1790 + squashfs_filetype_table[1]);
1792 + if (filldir(dirent, name, size,
1793 + file->f_pos, i_ino,
1794 + squashfs_filetype_table[1]) < 0) {
1795 + TRACE("Filldir returned less than 0\n");
1798 + file->f_pos += size;
1802 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1803 + SQUASHFS_I(i)->u.s2.directory_index_start,
1804 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1805 + SQUASHFS_I(i)->u.s2.directory_index_count,
1808 + while (length < i_size_read(i)) {
1809 + /* read directory header */
1810 + if (msblk->swap) {
1811 + struct squashfs_dir_header sdirh;
1813 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1814 + next_block, next_offset, sizeof(sdirh),
1815 + &next_block, &next_offset))
1818 + length += sizeof(sdirh);
1819 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1821 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1822 + next_block, next_offset, sizeof(dirh),
1823 + &next_block, &next_offset))
1826 + length += sizeof(dirh);
1829 + dir_count = dirh.count + 1;
1830 + while (dir_count--) {
1831 + if (msblk->swap) {
1832 + struct squashfs_dir_entry sdire;
1833 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1834 + &sdire, next_block, next_offset,
1835 + sizeof(sdire), &next_block,
1839 + length += sizeof(sdire);
1840 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1842 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1843 + dire, next_block, next_offset,
1844 + sizeof(*dire), &next_block,
1848 + length += sizeof(*dire);
1851 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1852 + next_block, next_offset,
1853 + dire->size + 1, &next_block,
1857 + length += dire->size + 1;
1859 + if (file->f_pos >= length)
1862 + dire->name[dire->size + 1] = '\0';
1864 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1865 + (unsigned int) dirent, dire->name,
1866 + dire->size + 1, (int) file->f_pos,
1867 + dirh.start_block, dire->offset,
1868 + dirh.inode_number + dire->inode_number,
1869 + squashfs_filetype_table[dire->type]);
1871 + if (filldir(dirent, dire->name, dire->size + 1,
1873 + dirh.inode_number + dire->inode_number,
1874 + squashfs_filetype_table[dire->type])
1876 + TRACE("Filldir returned less than 0\n");
1879 + file->f_pos = length;
1888 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1894 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1896 + const unsigned char *name = dentry->d_name.name;
1897 + int len = dentry->d_name.len;
1898 + struct inode *inode = NULL;
1899 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
1900 + struct squashfs_super_block *sblk = &msblk->sblk;
1901 + long long next_block = SQUASHFS_I(i)->start_block +
1902 + sblk->directory_table_start;
1903 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1905 + struct squashfs_dir_header dirh;
1906 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1907 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1909 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
1911 + if (len > SQUASHFS_NAME_LEN)
1914 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
1915 + SQUASHFS_I(i)->u.s2.directory_index_start,
1916 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1917 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
1920 + while (length < i_size_read(i)) {
1921 + /* read directory header */
1922 + if (msblk->swap) {
1923 + struct squashfs_dir_header sdirh;
1924 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1925 + next_block, next_offset, sizeof(sdirh),
1926 + &next_block, &next_offset))
1929 + length += sizeof(sdirh);
1930 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1932 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1933 + next_block, next_offset, sizeof(dirh),
1934 + &next_block, &next_offset))
1937 + length += sizeof(dirh);
1940 + dir_count = dirh.count + 1;
1941 + while (dir_count--) {
1942 + if (msblk->swap) {
1943 + struct squashfs_dir_entry sdire;
1944 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1945 + &sdire, next_block,next_offset,
1946 + sizeof(sdire), &next_block,
1950 + length += sizeof(sdire);
1951 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1953 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1954 + dire, next_block,next_offset,
1955 + sizeof(*dire), &next_block,
1959 + length += sizeof(*dire);
1962 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1963 + next_block, next_offset, dire->size + 1,
1964 + &next_block, &next_offset))
1967 + length += dire->size + 1;
1969 + if (name[0] < dire->name[0])
1972 + if ((len == dire->size + 1) && !strncmp(name,
1973 + dire->name, len)) {
1974 + squashfs_inode_t ino =
1975 + SQUASHFS_MKINODE(dirh.start_block,
1978 + TRACE("calling squashfs_iget for directory "
1979 + "entry %s, inode %x:%x, %d\n", name,
1980 + dirh.start_block, dire->offset,
1981 + dirh.inode_number + dire->inode_number);
1983 + inode = (msblk->iget)(i->i_sb, ino);
1991 + d_add(dentry, inode);
1992 + return ERR_PTR(0);
1995 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2001 +static void squashfs_put_super(struct super_block *s)
2005 + struct squashfs_sb_info *sbi = &s->u.squashfs_sb;
2006 + if (sbi->block_cache)
2007 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2008 + if (sbi->block_cache[i].block !=
2009 + SQUASHFS_INVALID_BLK)
2010 + kfree(sbi->block_cache[i].data);
2011 + if (sbi->fragment)
2012 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2013 + SQUASHFS_FREE(sbi->fragment[i].data);
2014 + kfree(sbi->fragment);
2015 + kfree(sbi->block_cache);
2016 + kfree(sbi->read_data);
2017 + kfree(sbi->read_page);
2019 + kfree(sbi->fragment_index);
2020 + kfree(sbi->fragment_index_2);
2021 + sbi->block_cache = NULL;
2023 + sbi->read_data = NULL;
2024 + sbi->read_page = NULL;
2025 + sbi->fragment = NULL;
2026 + sbi->fragment_index = NULL;
2027 + sbi->fragment_index_2 = NULL;
2031 +static int __init init_squashfs_fs(void)
2034 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2035 + "Phillip Lougher\n");
2037 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2038 + ERROR("Failed to allocate zlib workspace\n");
2041 + return register_filesystem(&squashfs_fs_type);
2045 +static void __exit exit_squashfs_fs(void)
2047 + vfree(stream.workspace);
2048 + unregister_filesystem(&squashfs_fs_type);
2054 +module_init(init_squashfs_fs);
2055 +module_exit(exit_squashfs_fs);
2056 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2057 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2058 +MODULE_LICENSE("GPL");
2060 +++ b/fs/squashfs/Makefile
2063 +# Makefile for the linux squashfs routines.
2066 +O_TARGET := squashfs.o
2068 +obj-y := inode.o squashfs2_0.o
2070 +obj-m := $(O_TARGET)
2072 +include $(TOPDIR)/Rules.make
2074 +++ b/fs/squashfs/squashfs2_0.c
2077 + * Squashfs - a compressed read only filesystem for Linux
2079 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2080 + * Phillip Lougher <phillip@lougher.org.uk>
2082 + * This program is free software; you can redistribute it and/or
2083 + * modify it under the terms of the GNU General Public License
2084 + * as published by the Free Software Foundation; either version 2,
2085 + * or (at your option) any later version.
2087 + * This program is distributed in the hope that it will be useful,
2088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2090 + * GNU General Public License for more details.
2092 + * You should have received a copy of the GNU General Public License
2093 + * along with this program; if not, write to the Free Software
2094 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2099 +#include <linux/types.h>
2100 +#include <linux/squashfs_fs.h>
2101 +#include <linux/module.h>
2102 +#include <linux/errno.h>
2103 +#include <linux/slab.h>
2104 +#include <linux/fs.h>
2105 +#include <linux/smp_lock.h>
2106 +#include <linux/locks.h>
2107 +#include <linux/init.h>
2108 +#include <linux/dcache.h>
2109 +#include <linux/wait.h>
2110 +#include <linux/zlib.h>
2111 +#include <linux/blkdev.h>
2112 +#include <linux/vmalloc.h>
2113 +#include <asm/uaccess.h>
2114 +#include <asm/semaphore.h>
2115 +#include "squashfs.h"
2117 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2118 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry);
2120 +static struct file_operations squashfs_dir_ops_2 = {
2121 + .read = generic_read_dir,
2122 + .readdir = squashfs_readdir_2
2125 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2126 + .lookup = squashfs_lookup_2
2129 +static unsigned char squashfs_filetype_table[] = {
2130 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2133 +static int read_fragment_index_table_2(struct super_block *s)
2135 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2136 + struct squashfs_super_block *sblk = &msblk->sblk;
2138 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2139 + (sblk->fragments), GFP_KERNEL))) {
2140 + ERROR("Failed to allocate uid/gid table\n");
2144 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2145 + !squashfs_read_data(s, (char *)
2146 + msblk->fragment_index_2,
2147 + sblk->fragment_table_start,
2148 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2149 + (sblk->fragments) |
2150 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2151 + ERROR("unable to read fragment index table\n");
2155 + if (msblk->swap) {
2157 + unsigned int fragment;
2159 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2161 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2162 + &msblk->fragment_index_2[i], 1);
2163 + msblk->fragment_index_2[i] = fragment;
2171 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2172 + long long *fragment_start_block,
2173 + unsigned int *fragment_size)
2175 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2176 + long long start_block =
2177 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2178 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2179 + struct squashfs_fragment_entry_2 fragment_entry;
2181 + if (msblk->swap) {
2182 + struct squashfs_fragment_entry_2 sfragment_entry;
2184 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2185 + start_block, offset,
2186 + sizeof(sfragment_entry), &start_block,
2189 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2191 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2192 + start_block, offset,
2193 + sizeof(fragment_entry), &start_block,
2197 + *fragment_start_block = fragment_entry.start_block;
2198 + *fragment_size = fragment_entry.size;
2207 +static struct inode *squashfs_new_inode(struct super_block *s,
2208 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2210 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2211 + struct squashfs_super_block *sblk = &msblk->sblk;
2212 + struct inode *i = new_inode(s);
2216 + i->i_mtime = sblk->mkfs_time;
2217 + i->i_atime = sblk->mkfs_time;
2218 + i->i_ctime = sblk->mkfs_time;
2219 + i->i_uid = msblk->uid[inodeb->uid];
2220 + i->i_mode = inodeb->mode;
2223 + if (inodeb->guid == SQUASHFS_GUIDS)
2224 + i->i_gid = i->i_uid;
2226 + i->i_gid = msblk->guid[inodeb->guid];
2233 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2236 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2237 + struct squashfs_super_block *sblk = &msblk->sblk;
2238 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2239 + sblk->inode_table_start;
2240 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2241 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2242 + - sblk->inode_table_start, offset);
2243 + long long next_block;
2244 + unsigned int next_offset;
2245 + union squashfs_inode_header_2 id, sid;
2246 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2247 + *sinodeb = &sid.base;
2249 + TRACE("Entered squashfs_iget\n");
2251 + if (msblk->swap) {
2252 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2253 + offset, sizeof(*sinodeb), &next_block,
2256 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2257 + sizeof(*sinodeb));
2259 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2260 + offset, sizeof(*inodeb), &next_block,
2264 + switch(inodeb->inode_type) {
2265 + case SQUASHFS_FILE_TYPE: {
2266 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2267 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2268 + long long frag_blk;
2269 + unsigned int frag_size;
2271 + if (msblk->swap) {
2272 + if (!squashfs_get_cached_block(s, (char *)
2273 + sinodep, block, offset,
2274 + sizeof(*sinodep), &next_block,
2277 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2279 + if (!squashfs_get_cached_block(s, (char *)
2280 + inodep, block, offset,
2281 + sizeof(*inodep), &next_block,
2285 + frag_blk = SQUASHFS_INVALID_BLK;
2286 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2287 + !get_fragment_location_2(s,
2288 + inodep->fragment, &frag_blk, &frag_size))
2291 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2292 + goto failed_read1;
2294 + i->i_size = inodep->file_size;
2295 + i->i_fop = &generic_ro_fops;
2296 + i->i_mode |= S_IFREG;
2297 + i->i_mtime = inodep->mtime;
2298 + i->i_atime = inodep->mtime;
2299 + i->i_ctime = inodep->mtime;
2300 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2301 + i->i_blksize = PAGE_CACHE_SIZE;
2302 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2303 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2304 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2305 + SQUASHFS_I(i)->start_block = inodep->start_block;
2306 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2307 + SQUASHFS_I(i)->offset = next_offset;
2308 + if (sblk->block_size > 4096)
2309 + i->i_data.a_ops = &squashfs_aops;
2311 + i->i_data.a_ops = &squashfs_aops_4K;
2313 + TRACE("File inode %x:%x, start_block %x, "
2314 + "block_list_start %llx, offset %x\n",
2315 + SQUASHFS_INODE_BLK(inode), offset,
2316 + inodep->start_block, next_block,
2320 + case SQUASHFS_DIR_TYPE: {
2321 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2322 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2324 + if (msblk->swap) {
2325 + if (!squashfs_get_cached_block(s, (char *)
2326 + sinodep, block, offset,
2327 + sizeof(*sinodep), &next_block,
2330 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2332 + if (!squashfs_get_cached_block(s, (char *)
2333 + inodep, block, offset,
2334 + sizeof(*inodep), &next_block,
2338 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2339 + goto failed_read1;
2341 + i->i_size = inodep->file_size;
2342 + i->i_op = &squashfs_dir_inode_ops_2;
2343 + i->i_fop = &squashfs_dir_ops_2;
2344 + i->i_mode |= S_IFDIR;
2345 + i->i_mtime = inodep->mtime;
2346 + i->i_atime = inodep->mtime;
2347 + i->i_ctime = inodep->mtime;
2348 + SQUASHFS_I(i)->start_block = inodep->start_block;
2349 + SQUASHFS_I(i)->offset = inodep->offset;
2350 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2351 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2353 + TRACE("Directory inode %x:%x, start_block %x, offset "
2354 + "%x\n", SQUASHFS_INODE_BLK(inode),
2355 + offset, inodep->start_block,
2359 + case SQUASHFS_LDIR_TYPE: {
2360 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2361 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2363 + if (msblk->swap) {
2364 + if (!squashfs_get_cached_block(s, (char *)
2365 + sinodep, block, offset,
2366 + sizeof(*sinodep), &next_block,
2369 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2372 + if (!squashfs_get_cached_block(s, (char *)
2373 + inodep, block, offset,
2374 + sizeof(*inodep), &next_block,
2378 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2379 + goto failed_read1;
2381 + i->i_size = inodep->file_size;
2382 + i->i_op = &squashfs_dir_inode_ops_2;
2383 + i->i_fop = &squashfs_dir_ops_2;
2384 + i->i_mode |= S_IFDIR;
2385 + i->i_mtime = inodep->mtime;
2386 + i->i_atime = inodep->mtime;
2387 + i->i_ctime = inodep->mtime;
2388 + SQUASHFS_I(i)->start_block = inodep->start_block;
2389 + SQUASHFS_I(i)->offset = inodep->offset;
2390 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2391 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2393 + SQUASHFS_I(i)->u.s2.directory_index_count =
2395 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2397 + TRACE("Long directory inode %x:%x, start_block %x, "
2399 + SQUASHFS_INODE_BLK(inode), offset,
2400 + inodep->start_block, inodep->offset);
2403 + case SQUASHFS_SYMLINK_TYPE: {
2404 + struct squashfs_symlink_inode_header_2 *inodep =
2406 + struct squashfs_symlink_inode_header_2 *sinodep =
2409 + if (msblk->swap) {
2410 + if (!squashfs_get_cached_block(s, (char *)
2411 + sinodep, block, offset,
2412 + sizeof(*sinodep), &next_block,
2415 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2418 + if (!squashfs_get_cached_block(s, (char *)
2419 + inodep, block, offset,
2420 + sizeof(*inodep), &next_block,
2424 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2425 + goto failed_read1;
2427 + i->i_size = inodep->symlink_size;
2428 + i->i_op = &page_symlink_inode_operations;
2429 + i->i_data.a_ops = &squashfs_symlink_aops;
2430 + i->i_mode |= S_IFLNK;
2431 + SQUASHFS_I(i)->start_block = next_block;
2432 + SQUASHFS_I(i)->offset = next_offset;
2434 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2436 + SQUASHFS_INODE_BLK(inode), offset,
2437 + next_block, next_offset);
2440 + case SQUASHFS_BLKDEV_TYPE:
2441 + case SQUASHFS_CHRDEV_TYPE: {
2442 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2443 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2445 + if (msblk->swap) {
2446 + if (!squashfs_get_cached_block(s, (char *)
2447 + sinodep, block, offset,
2448 + sizeof(*sinodep), &next_block,
2451 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2453 + if (!squashfs_get_cached_block(s, (char *)
2454 + inodep, block, offset,
2455 + sizeof(*inodep), &next_block,
2459 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2460 + goto failed_read1;
2462 + i->i_mode |= (inodeb->inode_type ==
2463 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2465 + init_special_inode(i, i->i_mode, inodep->rdev);
2467 + TRACE("Device inode %x:%x, rdev %x\n",
2468 + SQUASHFS_INODE_BLK(inode), offset,
2472 + case SQUASHFS_FIFO_TYPE:
2473 + case SQUASHFS_SOCKET_TYPE: {
2474 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2475 + goto failed_read1;
2477 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2478 + ? S_IFIFO : S_IFSOCK;
2479 + init_special_inode(i, i->i_mode, 0);
2483 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2484 + inodeb->inode_type);
2485 + goto failed_read1;
2488 + insert_inode_hash(i);
2492 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2499 +static int get_dir_index_using_offset(struct super_block *s, long long
2500 + *next_block, unsigned int *next_offset,
2501 + long long index_start,
2502 + unsigned int index_offset, int i_count,
2505 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2506 + struct squashfs_super_block *sblk = &msblk->sblk;
2507 + int i, length = 0;
2508 + struct squashfs_dir_index_2 index;
2510 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2511 + i_count, (unsigned int) f_pos);
2516 + for (i = 0; i < i_count; i++) {
2517 + if (msblk->swap) {
2518 + struct squashfs_dir_index_2 sindex;
2519 + squashfs_get_cached_block(s, (char *) &sindex,
2520 + index_start, index_offset,
2521 + sizeof(sindex), &index_start,
2523 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2525 + squashfs_get_cached_block(s, (char *) &index,
2526 + index_start, index_offset,
2527 + sizeof(index), &index_start,
2530 + if (index.index > f_pos)
2533 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2534 + index.size + 1, &index_start,
2537 + length = index.index;
2538 + *next_block = index.start_block + sblk->directory_table_start;
2541 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2548 +static int get_dir_index_using_name(struct super_block *s, long long
2549 + *next_block, unsigned int *next_offset,
2550 + long long index_start,
2551 + unsigned int index_offset, int i_count,
2552 + const char *name, int size)
2554 + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
2555 + struct squashfs_super_block *sblk = &msblk->sblk;
2556 + int i, length = 0;
2557 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2558 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2559 + char str[SQUASHFS_NAME_LEN + 1];
2561 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2563 + strncpy(str, name, size);
2566 + for (i = 0; i < i_count; i++) {
2567 + if (msblk->swap) {
2568 + struct squashfs_dir_index_2 sindex;
2569 + squashfs_get_cached_block(s, (char *) &sindex,
2570 + index_start, index_offset,
2571 + sizeof(sindex), &index_start,
2573 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2575 + squashfs_get_cached_block(s, (char *) index,
2576 + index_start, index_offset,
2577 + sizeof(struct squashfs_dir_index_2),
2578 + &index_start, &index_offset);
2580 + squashfs_get_cached_block(s, index->name, index_start,
2581 + index_offset, index->size + 1,
2582 + &index_start, &index_offset);
2584 + index->name[index->size + 1] = '\0';
2586 + if (strcmp(index->name, str) > 0)
2589 + length = index->index;
2590 + *next_block = index->start_block + sblk->directory_table_start;
2593 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2598 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2600 + struct inode *i = file->f_dentry->d_inode;
2601 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2602 + struct squashfs_super_block *sblk = &msblk->sblk;
2603 + long long next_block = SQUASHFS_I(i)->start_block +
2604 + sblk->directory_table_start;
2605 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2607 + struct squashfs_dir_header_2 dirh;
2608 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2609 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2611 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2613 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2614 + SQUASHFS_I(i)->u.s2.directory_index_start,
2615 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2616 + SQUASHFS_I(i)->u.s2.directory_index_count,
2619 + while (length < i_size_read(i)) {
2620 + /* read directory header */
2621 + if (msblk->swap) {
2622 + struct squashfs_dir_header_2 sdirh;
2624 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2625 + next_block, next_offset, sizeof(sdirh),
2626 + &next_block, &next_offset))
2629 + length += sizeof(sdirh);
2630 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2632 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2633 + next_block, next_offset, sizeof(dirh),
2634 + &next_block, &next_offset))
2637 + length += sizeof(dirh);
2640 + dir_count = dirh.count + 1;
2641 + while (dir_count--) {
2642 + if (msblk->swap) {
2643 + struct squashfs_dir_entry_2 sdire;
2644 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2645 + &sdire, next_block, next_offset,
2646 + sizeof(sdire), &next_block,
2650 + length += sizeof(sdire);
2651 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2653 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2654 + dire, next_block, next_offset,
2655 + sizeof(*dire), &next_block,
2659 + length += sizeof(*dire);
2662 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2663 + next_block, next_offset,
2664 + dire->size + 1, &next_block,
2668 + length += dire->size + 1;
2670 + if (file->f_pos >= length)
2673 + dire->name[dire->size + 1] = '\0';
2675 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2676 + (unsigned int) dirent, dire->name,
2677 + dire->size + 1, (int) file->f_pos,
2678 + dirh.start_block, dire->offset,
2679 + squashfs_filetype_table[dire->type]);
2681 + if (filldir(dirent, dire->name, dire->size + 1,
2682 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2683 + dirh.start_block, dire->offset),
2684 + squashfs_filetype_table[dire->type])
2686 + TRACE("Filldir returned less than 0\n");
2689 + file->f_pos = length;
2698 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2704 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry)
2706 + const unsigned char *name = dentry->d_name.name;
2707 + int len = dentry->d_name.len;
2708 + struct inode *inode = NULL;
2709 + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
2710 + struct squashfs_super_block *sblk = &msblk->sblk;
2711 + long long next_block = SQUASHFS_I(i)->start_block +
2712 + sblk->directory_table_start;
2713 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2715 + struct squashfs_dir_header_2 dirh;
2716 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2717 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2718 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2720 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2722 + if (len > SQUASHFS_NAME_LEN)
2725 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2726 + SQUASHFS_I(i)->u.s2.directory_index_start,
2727 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2728 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2731 + while (length < i_size_read(i)) {
2732 + /* read directory header */
2733 + if (msblk->swap) {
2734 + struct squashfs_dir_header_2 sdirh;
2735 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2736 + next_block, next_offset, sizeof(sdirh),
2737 + &next_block, &next_offset))
2740 + length += sizeof(sdirh);
2741 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2743 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2744 + next_block, next_offset, sizeof(dirh),
2745 + &next_block, &next_offset))
2748 + length += sizeof(dirh);
2751 + dir_count = dirh.count + 1;
2752 + while (dir_count--) {
2753 + if (msblk->swap) {
2754 + struct squashfs_dir_entry_2 sdire;
2755 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2756 + &sdire, next_block,next_offset,
2757 + sizeof(sdire), &next_block,
2761 + length += sizeof(sdire);
2762 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2764 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2765 + dire, next_block,next_offset,
2766 + sizeof(*dire), &next_block,
2770 + length += sizeof(*dire);
2773 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2774 + next_block, next_offset, dire->size + 1,
2775 + &next_block, &next_offset))
2778 + length += dire->size + 1;
2780 + if (sorted && name[0] < dire->name[0])
2783 + if ((len == dire->size + 1) && !strncmp(name,
2784 + dire->name, len)) {
2785 + squashfs_inode_t ino =
2786 + SQUASHFS_MKINODE(dirh.start_block,
2789 + TRACE("calling squashfs_iget for directory "
2790 + "entry %s, inode %x:%x, %d\n", name,
2791 + dirh.start_block, dire->offset, ino);
2793 + inode = (msblk->iget)(i->i_sb, ino);
2801 + d_add(dentry, inode);
2802 + return ERR_PTR(0);
2805 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2811 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2813 + struct squashfs_super_block *sblk = &msblk->sblk;
2815 + msblk->iget = squashfs_iget_2;
2816 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2818 + sblk->bytes_used = sblk->bytes_used_2;
2819 + sblk->uid_start = sblk->uid_start_2;
2820 + sblk->guid_start = sblk->guid_start_2;
2821 + sblk->inode_table_start = sblk->inode_table_start_2;
2822 + sblk->directory_table_start = sblk->directory_table_start_2;
2823 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2828 +++ b/fs/squashfs/squashfs.h
2831 + * Squashfs - a compressed read only filesystem for Linux
2833 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2834 + * Phillip Lougher <phillip@lougher.org.uk>
2836 + * This program is free software; you can redistribute it and/or
2837 + * modify it under the terms of the GNU General Public License
2838 + * as published by the Free Software Foundation; either version 2,
2839 + * or (at your option) any later version.
2841 + * This program is distributed in the hope that it will be useful,
2842 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2843 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2844 + * GNU General Public License for more details.
2846 + * You should have received a copy of the GNU General Public License
2847 + * along with this program; if not, write to the Free Software
2848 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2853 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2854 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2856 +#ifdef SQUASHFS_TRACE
2857 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
2859 +#define TRACE(s, args...) {}
2862 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
2864 +#define SERROR(s, args...) do { \
2866 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
2869 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
2871 +#define SQUASHFS_I(INO) (&INO->u.squashfs_i)
2873 +#define i_size_read(INO) (INO->i_size)
2875 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
2876 +#define SQSH_EXTERN
2877 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
2878 + long long index, unsigned int length,
2879 + long long *next_index);
2880 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
2881 + long long block, unsigned int offset,
2882 + int length, long long *next_block,
2883 + unsigned int *next_offset);
2884 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
2885 + squashfs_fragment_cache *fragment);
2886 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
2887 + *s, long long start_block,
2889 +extern struct address_space_operations squashfs_symlink_aops;
2890 +extern struct address_space_operations squashfs_aops;
2891 +extern struct address_space_operations squashfs_aops_4K;
2892 +extern struct file_operations squashfs_dir_ops;
2893 +extern struct inode_operations squashfs_dir_inode_ops;
2895 +#define SQSH_EXTERN static
2898 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2899 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
2901 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
2907 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2908 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
2910 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2915 --- a/include/linux/fs.h
2916 +++ b/include/linux/fs.h
2917 @@ -324,6 +324,7 @@ extern void set_bh_page(struct buffer_he
2918 #include <linux/usbdev_fs_i.h>
2919 #include <linux/jffs2_fs_i.h>
2920 #include <linux/cramfs_fs_sb.h>
2921 +#include <linux/squashfs_fs_i.h>
2924 * Attribute flags. These should be or-ed together to figure out what
2925 @@ -519,6 +520,7 @@ struct inode {
2926 struct socket socket_i;
2927 struct usbdev_inode_info usbdev_i;
2928 struct jffs2_inode_info jffs2_i;
2929 + struct squashfs_inode_info squashfs_i;
2933 @@ -734,6 +736,7 @@ struct nameidata {
2934 #include <linux/usbdev_fs_sb.h>
2935 #include <linux/cramfs_fs_sb.h>
2936 #include <linux/jffs2_fs_sb.h>
2937 +#include <linux/squashfs_fs_sb.h>
2939 extern struct list_head super_blocks;
2940 extern spinlock_t sb_lock;
2941 @@ -793,6 +796,7 @@ struct super_block {
2942 struct usbdev_sb_info usbdevfs_sb;
2943 struct jffs2_sb_info jffs2_sb;
2944 struct cramfs_sb_info cramfs_sb;
2945 + struct squashfs_sb_info squashfs_sb;
2950 +++ b/include/linux/squashfs_fs.h
2952 +#ifndef SQUASHFS_FS
2953 +#define SQUASHFS_FS
2958 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2959 + * Phillip Lougher <phillip@lougher.org.uk>
2961 + * This program is free software; you can redistribute it and/or
2962 + * modify it under the terms of the GNU General Public License
2963 + * as published by the Free Software Foundation; either version 2,
2964 + * or (at your option) any later version.
2966 + * This program is distributed in the hope that it will be useful,
2967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2969 + * GNU General Public License for more details.
2971 + * You should have received a copy of the GNU General Public License
2972 + * along with this program; if not, write to the Free Software
2973 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2978 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2979 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
2982 +#ifdef CONFIG_SQUASHFS_VMALLOC
2983 +#define SQUASHFS_ALLOC(a) vmalloc(a)
2984 +#define SQUASHFS_FREE(a) vfree(a)
2986 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
2987 +#define SQUASHFS_FREE(a) kfree(a)
2989 +#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
2990 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
2992 +#define SQUASHFS_CACHED_FRAGMENTS 3
2994 +#define SQUASHFS_MAJOR 3
2995 +#define SQUASHFS_MINOR 0
2996 +#define SQUASHFS_MAGIC 0x73717368
2997 +#define SQUASHFS_MAGIC_SWAP 0x68737173
2998 +#define SQUASHFS_START 0
3000 +/* size of metadata (inode and directory) blocks */
3001 +#define SQUASHFS_METADATA_SIZE 8192
3002 +#define SQUASHFS_METADATA_LOG 13
3004 +/* default size of data blocks */
3005 +#define SQUASHFS_FILE_SIZE 65536
3006 +#define SQUASHFS_FILE_LOG 16
3008 +#define SQUASHFS_FILE_MAX_SIZE 65536
3010 +/* Max number of uids and gids */
3011 +#define SQUASHFS_UIDS 256
3012 +#define SQUASHFS_GUIDS 255
3014 +/* Max length of filename (not 255) */
3015 +#define SQUASHFS_NAME_LEN 256
3017 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3018 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3019 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3020 +#define SQUASHFS_USED_BLK ((long long) -2)
3022 +/* Filesystem flags */
3023 +#define SQUASHFS_NOI 0
3024 +#define SQUASHFS_NOD 1
3025 +#define SQUASHFS_CHECK 2
3026 +#define SQUASHFS_NOF 3
3027 +#define SQUASHFS_NO_FRAG 4
3028 +#define SQUASHFS_ALWAYS_FRAG 5
3029 +#define SQUASHFS_DUPLICATE 6
3031 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3033 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3036 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3039 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3042 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3045 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3046 + SQUASHFS_ALWAYS_FRAG)
3048 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3049 + SQUASHFS_DUPLICATE)
3051 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3054 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3055 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3056 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3057 + (duplicate_checking << 6))
3059 +/* Max number of types and file types */
3060 +#define SQUASHFS_DIR_TYPE 1
3061 +#define SQUASHFS_FILE_TYPE 2
3062 +#define SQUASHFS_SYMLINK_TYPE 3
3063 +#define SQUASHFS_BLKDEV_TYPE 4
3064 +#define SQUASHFS_CHRDEV_TYPE 5
3065 +#define SQUASHFS_FIFO_TYPE 6
3066 +#define SQUASHFS_SOCKET_TYPE 7
3067 +#define SQUASHFS_LDIR_TYPE 8
3068 +#define SQUASHFS_LREG_TYPE 9
3070 +/* 1.0 filesystem type definitions */
3071 +#define SQUASHFS_TYPES 5
3072 +#define SQUASHFS_IPC_TYPE 0
3074 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3076 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3078 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3079 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3081 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3083 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3085 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3086 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3087 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3089 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3092 + * Inode number ops. Inodes consist of a compressed block number, and an
3093 + * uncompressed offset within that block
3095 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3097 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3099 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3102 +/* Compute 32 bit VFS inode number from squashfs inode number */
3103 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3107 +/* Translate between VFS mode and squashfs mode */
3108 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3110 +/* fragment and fragment table defines */
3111 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3113 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3114 + SQUASHFS_METADATA_SIZE)
3116 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3117 + SQUASHFS_METADATA_SIZE)
3119 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3120 + SQUASHFS_METADATA_SIZE - 1) / \
3121 + SQUASHFS_METADATA_SIZE)
3123 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3124 + sizeof(long long))
3126 +/* cached data constants for filesystem */
3127 +#define SQUASHFS_CACHED_BLKS 8
3129 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3131 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3132 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3134 +#define SQUASHFS_MARKER_BYTE 0xff
3136 +/* meta index cache */
3137 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3138 +#define SQUASHFS_META_ENTRIES 31
3139 +#define SQUASHFS_META_NUMBER 8
3140 +#define SQUASHFS_SLOTS 4
3142 +struct meta_entry {
3143 + long long data_block;
3144 + unsigned int index_block;
3145 + unsigned short offset;
3146 + unsigned short pad;
3149 +struct meta_index {
3150 + unsigned int inode_number;
3151 + unsigned int offset;
3152 + unsigned short entries;
3153 + unsigned short skip;
3154 + unsigned short locked;
3155 + unsigned short pad;
3156 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3161 + * definitions for structures on disk
3164 +typedef long long squashfs_block_t;
3165 +typedef long long squashfs_inode_t;
3167 +struct squashfs_super_block {
3168 + unsigned int s_magic;
3169 + unsigned int inodes;
3170 + unsigned int bytes_used_2;
3171 + unsigned int uid_start_2;
3172 + unsigned int guid_start_2;
3173 + unsigned int inode_table_start_2;
3174 + unsigned int directory_table_start_2;
3175 + unsigned int s_major:16;
3176 + unsigned int s_minor:16;
3177 + unsigned int block_size_1:16;
3178 + unsigned int block_log:16;
3179 + unsigned int flags:8;
3180 + unsigned int no_uids:8;
3181 + unsigned int no_guids:8;
3182 + unsigned int mkfs_time /* time of filesystem creation */;
3183 + squashfs_inode_t root_inode;
3184 + unsigned int block_size;
3185 + unsigned int fragments;
3186 + unsigned int fragment_table_start_2;
3187 + long long bytes_used;
3188 + long long uid_start;
3189 + long long guid_start;
3190 + long long inode_table_start;
3191 + long long directory_table_start;
3192 + long long fragment_table_start;
3194 +} __attribute__ ((packed));
3196 +struct squashfs_dir_index {
3197 + unsigned int index;
3198 + unsigned int start_block;
3199 + unsigned char size;
3200 + unsigned char name[0];
3201 +} __attribute__ ((packed));
3203 +#define SQUASHFS_BASE_INODE_HEADER \
3204 + unsigned int inode_type:4; \
3205 + unsigned int mode:12; \
3206 + unsigned int uid:8; \
3207 + unsigned int guid:8; \
3208 + unsigned int mtime; \
3209 + unsigned int inode_number;
3211 +struct squashfs_base_inode_header {
3212 + SQUASHFS_BASE_INODE_HEADER;
3213 +} __attribute__ ((packed));
3215 +struct squashfs_ipc_inode_header {
3216 + SQUASHFS_BASE_INODE_HEADER;
3217 + unsigned int nlink;
3218 +} __attribute__ ((packed));
3220 +struct squashfs_dev_inode_header {
3221 + SQUASHFS_BASE_INODE_HEADER;
3222 + unsigned int nlink;
3223 + unsigned short rdev;
3224 +} __attribute__ ((packed));
3226 +struct squashfs_symlink_inode_header {
3227 + SQUASHFS_BASE_INODE_HEADER;
3228 + unsigned int nlink;
3229 + unsigned short symlink_size;
3231 +} __attribute__ ((packed));
3233 +struct squashfs_reg_inode_header {
3234 + SQUASHFS_BASE_INODE_HEADER;
3235 + squashfs_block_t start_block;
3236 + unsigned int fragment;
3237 + unsigned int offset;
3238 + unsigned int file_size;
3239 + unsigned short block_list[0];
3240 +} __attribute__ ((packed));
3242 +struct squashfs_lreg_inode_header {
3243 + SQUASHFS_BASE_INODE_HEADER;
3244 + unsigned int nlink;
3245 + squashfs_block_t start_block;
3246 + unsigned int fragment;
3247 + unsigned int offset;
3248 + long long file_size;
3249 + unsigned short block_list[0];
3250 +} __attribute__ ((packed));
3252 +struct squashfs_dir_inode_header {
3253 + SQUASHFS_BASE_INODE_HEADER;
3254 + unsigned int nlink;
3255 + unsigned int file_size:19;
3256 + unsigned int offset:13;
3257 + unsigned int start_block;
3258 + unsigned int parent_inode;
3259 +} __attribute__ ((packed));
3261 +struct squashfs_ldir_inode_header {
3262 + SQUASHFS_BASE_INODE_HEADER;
3263 + unsigned int nlink;
3264 + unsigned int file_size:27;
3265 + unsigned int offset:13;
3266 + unsigned int start_block;
3267 + unsigned int i_count:16;
3268 + unsigned int parent_inode;
3269 + struct squashfs_dir_index index[0];
3270 +} __attribute__ ((packed));
3272 +union squashfs_inode_header {
3273 + struct squashfs_base_inode_header base;
3274 + struct squashfs_dev_inode_header dev;
3275 + struct squashfs_symlink_inode_header symlink;
3276 + struct squashfs_reg_inode_header reg;
3277 + struct squashfs_lreg_inode_header lreg;
3278 + struct squashfs_dir_inode_header dir;
3279 + struct squashfs_ldir_inode_header ldir;
3280 + struct squashfs_ipc_inode_header ipc;
3283 +struct squashfs_dir_entry {
3284 + unsigned int offset:13;
3285 + unsigned int type:3;
3286 + unsigned int size:8;
3287 + int inode_number:16;
3289 +} __attribute__ ((packed));
3291 +struct squashfs_dir_header {
3292 + unsigned int count:8;
3293 + unsigned int start_block;
3294 + unsigned int inode_number;
3295 +} __attribute__ ((packed));
3297 +struct squashfs_fragment_entry {
3298 + long long start_block;
3299 + unsigned int size;
3300 + unsigned int unused;
3301 +} __attribute__ ((packed));
3303 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3304 +extern int squashfs_uncompress_init(void);
3305 +extern int squashfs_uncompress_exit(void);
3308 + * macros to convert each packed bitfield structure from little endian to big
3309 + * endian and vice versa. These are needed when creating or using a filesystem
3310 + * on a machine with different byte ordering to the target architecture.
3314 +#define SQUASHFS_SWAP_START \
3317 + unsigned long long val;\
3318 + unsigned char *s;\
3321 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3322 + SQUASHFS_SWAP_START\
3323 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3324 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3325 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3326 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3327 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3328 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3329 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3330 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3331 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3332 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3333 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3334 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3335 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3336 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3337 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3338 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3339 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3340 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3341 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3342 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3343 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3344 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3345 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3346 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3347 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3348 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3349 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3352 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3353 + SQUASHFS_MEMSET(s, d, n);\
3354 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3355 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3356 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3357 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3358 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3359 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3361 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3362 + SQUASHFS_SWAP_START\
3363 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3366 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3367 + SQUASHFS_SWAP_START\
3368 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3369 + sizeof(struct squashfs_ipc_inode_header))\
3370 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3373 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3374 + SQUASHFS_SWAP_START\
3375 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3376 + sizeof(struct squashfs_dev_inode_header)); \
3377 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3378 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3381 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3382 + SQUASHFS_SWAP_START\
3383 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3384 + sizeof(struct squashfs_symlink_inode_header));\
3385 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3386 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3389 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3390 + SQUASHFS_SWAP_START\
3391 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3392 + sizeof(struct squashfs_reg_inode_header));\
3393 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3394 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3395 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3396 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3399 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3400 + SQUASHFS_SWAP_START\
3401 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3402 + sizeof(struct squashfs_lreg_inode_header));\
3403 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3404 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3405 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3406 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3407 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3410 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3411 + SQUASHFS_SWAP_START\
3412 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3413 + sizeof(struct squashfs_dir_inode_header));\
3414 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3415 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3416 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3417 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3418 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3421 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3422 + SQUASHFS_SWAP_START\
3423 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3424 + sizeof(struct squashfs_ldir_inode_header));\
3425 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3426 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3427 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3428 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3429 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3430 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3433 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3434 + SQUASHFS_SWAP_START\
3435 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3436 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3437 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3438 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3441 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3442 + SQUASHFS_SWAP_START\
3443 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3444 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3445 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3446 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3449 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3450 + SQUASHFS_SWAP_START\
3451 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3452 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3453 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3454 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3455 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3458 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3459 + SQUASHFS_SWAP_START\
3460 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3461 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3462 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3465 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3467 + int bit_position;\
3468 + SQUASHFS_SWAP_START\
3469 + SQUASHFS_MEMSET(s, d, n * 2);\
3470 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3472 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3475 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3477 + int bit_position;\
3478 + SQUASHFS_SWAP_START\
3479 + SQUASHFS_MEMSET(s, d, n * 4);\
3480 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3482 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3485 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3487 + int bit_position;\
3488 + SQUASHFS_SWAP_START\
3489 + SQUASHFS_MEMSET(s, d, n * 8);\
3490 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3492 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3495 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3497 + int bit_position;\
3498 + SQUASHFS_SWAP_START\
3499 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3500 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3502 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3505 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3507 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3509 +struct squashfs_base_inode_header_1 {
3510 + unsigned int inode_type:4;
3511 + unsigned int mode:12; /* protection */
3512 + unsigned int uid:4; /* index into uid table */
3513 + unsigned int guid:4; /* index into guid table */
3514 +} __attribute__ ((packed));
3516 +struct squashfs_ipc_inode_header_1 {
3517 + unsigned int inode_type:4;
3518 + unsigned int mode:12; /* protection */
3519 + unsigned int uid:4; /* index into uid table */
3520 + unsigned int guid:4; /* index into guid table */
3521 + unsigned int type:4;
3522 + unsigned int offset:4;
3523 +} __attribute__ ((packed));
3525 +struct squashfs_dev_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 + unsigned short rdev;
3531 +} __attribute__ ((packed));
3533 +struct squashfs_symlink_inode_header_1 {
3534 + unsigned int inode_type:4;
3535 + unsigned int mode:12; /* protection */
3536 + unsigned int uid:4; /* index into uid table */
3537 + unsigned int guid:4; /* index into guid table */
3538 + unsigned short symlink_size;
3540 +} __attribute__ ((packed));
3542 +struct squashfs_reg_inode_header_1 {
3543 + unsigned int inode_type:4;
3544 + unsigned int mode:12; /* protection */
3545 + unsigned int uid:4; /* index into uid table */
3546 + unsigned int guid:4; /* index into guid table */
3547 + unsigned int mtime;
3548 + unsigned int start_block;
3549 + unsigned int file_size:32;
3550 + unsigned short block_list[0];
3551 +} __attribute__ ((packed));
3553 +struct squashfs_dir_inode_header_1 {
3554 + unsigned int inode_type:4;
3555 + unsigned int mode:12; /* protection */
3556 + unsigned int uid:4; /* index into uid table */
3557 + unsigned int guid:4; /* index into guid table */
3558 + unsigned int file_size:19;
3559 + unsigned int offset:13;
3560 + unsigned int mtime;
3561 + unsigned int start_block:24;
3562 +} __attribute__ ((packed));
3564 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3565 + SQUASHFS_MEMSET(s, d, n);\
3566 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3567 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3568 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3569 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3571 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3572 + SQUASHFS_SWAP_START\
3573 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3576 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3577 + SQUASHFS_SWAP_START\
3578 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3579 + sizeof(struct squashfs_ipc_inode_header_1));\
3580 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3581 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3584 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3585 + SQUASHFS_SWAP_START\
3586 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3587 + sizeof(struct squashfs_dev_inode_header_1));\
3588 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3591 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3592 + SQUASHFS_SWAP_START\
3593 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3594 + sizeof(struct squashfs_symlink_inode_header_1));\
3595 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3598 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3599 + SQUASHFS_SWAP_START\
3600 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3601 + sizeof(struct squashfs_reg_inode_header_1));\
3602 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3603 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3604 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3607 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3608 + SQUASHFS_SWAP_START\
3609 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3610 + sizeof(struct squashfs_dir_inode_header_1));\
3611 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3612 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3613 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3614 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3619 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3621 +struct squashfs_dir_index_2 {
3622 + unsigned int index:27;
3623 + unsigned int start_block:29;
3624 + unsigned char size;
3625 + unsigned char name[0];
3626 +} __attribute__ ((packed));
3628 +struct squashfs_base_inode_header_2 {
3629 + unsigned int inode_type:4;
3630 + unsigned int mode:12; /* protection */
3631 + unsigned int uid:8; /* index into uid table */
3632 + unsigned int guid:8; /* index into guid table */
3633 +} __attribute__ ((packed));
3635 +struct squashfs_ipc_inode_header_2 {
3636 + unsigned int inode_type:4;
3637 + unsigned int mode:12; /* protection */
3638 + unsigned int uid:8; /* index into uid table */
3639 + unsigned int guid:8; /* index into guid table */
3640 +} __attribute__ ((packed));
3642 +struct squashfs_dev_inode_header_2 {
3643 + unsigned int inode_type:4;
3644 + unsigned int mode:12; /* protection */
3645 + unsigned int uid:8; /* index into uid table */
3646 + unsigned int guid:8; /* index into guid table */
3647 + unsigned short rdev;
3648 +} __attribute__ ((packed));
3650 +struct squashfs_symlink_inode_header_2 {
3651 + unsigned int inode_type:4;
3652 + unsigned int mode:12; /* protection */
3653 + unsigned int uid:8; /* index into uid table */
3654 + unsigned int guid:8; /* index into guid table */
3655 + unsigned short symlink_size;
3657 +} __attribute__ ((packed));
3659 +struct squashfs_reg_inode_header_2 {
3660 + unsigned int inode_type:4;
3661 + unsigned int mode:12; /* protection */
3662 + unsigned int uid:8; /* index into uid table */
3663 + unsigned int guid:8; /* index into guid table */
3664 + unsigned int mtime;
3665 + unsigned int start_block;
3666 + unsigned int fragment;
3667 + unsigned int offset;
3668 + unsigned int file_size:32;
3669 + unsigned short block_list[0];
3670 +} __attribute__ ((packed));
3672 +struct squashfs_dir_inode_header_2 {
3673 + unsigned int inode_type:4;
3674 + unsigned int mode:12; /* protection */
3675 + unsigned int uid:8; /* index into uid table */
3676 + unsigned int guid:8; /* index into guid table */
3677 + unsigned int file_size:19;
3678 + unsigned int offset:13;
3679 + unsigned int mtime;
3680 + unsigned int start_block:24;
3681 +} __attribute__ ((packed));
3683 +struct squashfs_ldir_inode_header_2 {
3684 + unsigned int inode_type:4;
3685 + unsigned int mode:12; /* protection */
3686 + unsigned int uid:8; /* index into uid table */
3687 + unsigned int guid:8; /* index into guid table */
3688 + unsigned int file_size:27;
3689 + unsigned int offset:13;
3690 + unsigned int mtime;
3691 + unsigned int start_block:24;
3692 + unsigned int i_count:16;
3693 + struct squashfs_dir_index_2 index[0];
3694 +} __attribute__ ((packed));
3696 +union squashfs_inode_header_2 {
3697 + struct squashfs_base_inode_header_2 base;
3698 + struct squashfs_dev_inode_header_2 dev;
3699 + struct squashfs_symlink_inode_header_2 symlink;
3700 + struct squashfs_reg_inode_header_2 reg;
3701 + struct squashfs_dir_inode_header_2 dir;
3702 + struct squashfs_ldir_inode_header_2 ldir;
3703 + struct squashfs_ipc_inode_header_2 ipc;
3706 +struct squashfs_dir_header_2 {
3707 + unsigned int count:8;
3708 + unsigned int start_block:24;
3709 +} __attribute__ ((packed));
3711 +struct squashfs_dir_entry_2 {
3712 + unsigned int offset:13;
3713 + unsigned int type:3;
3714 + unsigned int size:8;
3716 +} __attribute__ ((packed));
3718 +struct squashfs_fragment_entry_2 {
3719 + unsigned int start_block;
3720 + unsigned int size;
3721 +} __attribute__ ((packed));
3723 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3724 + SQUASHFS_MEMSET(s, d, n);\
3725 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3726 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3727 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3728 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3730 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3731 + SQUASHFS_SWAP_START\
3732 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3735 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3736 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3738 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3739 + SQUASHFS_SWAP_START\
3740 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3741 + sizeof(struct squashfs_dev_inode_header_2)); \
3742 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3745 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3746 + SQUASHFS_SWAP_START\
3747 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3748 + sizeof(struct squashfs_symlink_inode_header_2));\
3749 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3752 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3753 + SQUASHFS_SWAP_START\
3754 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3755 + sizeof(struct squashfs_reg_inode_header_2));\
3756 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3757 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3758 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3759 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3760 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3763 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3764 + SQUASHFS_SWAP_START\
3765 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3766 + sizeof(struct squashfs_dir_inode_header_2));\
3767 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3768 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3769 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3770 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3773 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3774 + SQUASHFS_SWAP_START\
3775 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3776 + sizeof(struct squashfs_ldir_inode_header_2));\
3777 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3778 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3779 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3780 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3781 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3784 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3785 + SQUASHFS_SWAP_START\
3786 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3787 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3788 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3789 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3791 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3792 + SQUASHFS_SWAP_START\
3793 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3794 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3795 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3798 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3799 + SQUASHFS_SWAP_START\
3800 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3801 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3802 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3803 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3806 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3807 + SQUASHFS_SWAP_START\
3808 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3809 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3810 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3813 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3815 +/* fragment and fragment table defines */
3816 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3818 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3819 + SQUASHFS_METADATA_SIZE)
3821 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3822 + SQUASHFS_METADATA_SIZE)
3824 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3825 + SQUASHFS_METADATA_SIZE - 1) / \
3826 + SQUASHFS_METADATA_SIZE)
3828 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3836 + * macros used to swap each structure entry, taking into account
3837 + * bitfields and different bitfield placing conventions on differing
3841 +#include <asm/byteorder.h>
3843 +#ifdef __BIG_ENDIAN
3844 + /* convert from little endian to big endian */
3845 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3848 + /* convert from big endian to little endian */
3849 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3850 + tbits, 64 - tbits - b_pos)
3853 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3856 + s = (unsigned char *)p + (pos / 8);\
3857 + d = ((unsigned char *) &val) + 7;\
3858 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3860 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3863 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3868 +++ b/include/linux/squashfs_fs_i.h
3870 +#ifndef SQUASHFS_FS_I
3871 +#define SQUASHFS_FS_I
3875 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3876 + * Phillip Lougher <phillip@lougher.org.uk>
3878 + * This program is free software; you can redistribute it and/or
3879 + * modify it under the terms of the GNU General Public License
3880 + * as published by the Free Software Foundation; either version 2,
3881 + * or (at your option) any later version.
3883 + * This program is distributed in the hope that it will be useful,
3884 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3885 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3886 + * GNU General Public License for more details.
3888 + * You should have received a copy of the GNU General Public License
3889 + * along with this program; if not, write to the Free Software
3890 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3895 +struct squashfs_inode_info {
3896 + long long start_block;
3897 + unsigned int offset;
3900 + long long fragment_start_block;
3901 + unsigned int fragment_size;
3902 + unsigned int fragment_offset;
3903 + long long block_list_start;
3906 + long long directory_index_start;
3907 + unsigned int directory_index_offset;
3908 + unsigned int directory_index_count;
3909 + unsigned int parent_inode;
3915 +++ b/include/linux/squashfs_fs_sb.h
3917 +#ifndef SQUASHFS_FS_SB
3918 +#define SQUASHFS_FS_SB
3922 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3923 + * Phillip Lougher <phillip@lougher.org.uk>
3925 + * This program is free software; you can redistribute it and/or
3926 + * modify it under the terms of the GNU General Public License
3927 + * as published by the Free Software Foundation; either version 2,
3928 + * or (at your option) any later version.
3930 + * This program is distributed in the hope that it will be useful,
3931 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3932 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3933 + * GNU General Public License for more details.
3935 + * You should have received a copy of the GNU General Public License
3936 + * along with this program; if not, write to the Free Software
3937 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3939 + * squashfs_fs_sb.h
3942 +#include <linux/squashfs_fs.h>
3944 +struct squashfs_cache {
3947 + long long next_index;
3951 +struct squashfs_fragment_cache {
3954 + unsigned int locked;
3958 +struct squashfs_sb_info {
3959 + struct squashfs_super_block sblk;
3961 + int devblksize_log2;
3963 + struct squashfs_cache *block_cache;
3964 + struct squashfs_fragment_cache *fragment;
3966 + int next_fragment;
3967 + int next_meta_index;
3968 + unsigned int *uid;
3969 + unsigned int *guid;
3970 + long long *fragment_index;
3971 + unsigned int *fragment_index_2;
3972 + unsigned int read_size;
3975 + struct semaphore read_data_mutex;
3976 + struct semaphore read_page_mutex;
3977 + struct semaphore block_cache_mutex;
3978 + struct semaphore fragment_mutex;
3979 + struct semaphore meta_index_mutex;
3980 + wait_queue_head_t waitq;
3981 + wait_queue_head_t fragment_wait_queue;
3982 + struct meta_index *meta_index;
3983 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
3985 + long long (*read_blocklist)(struct inode *inode, int \
3986 + index, int readahead_blks, char *block_list, \
3987 + unsigned short **block_p, unsigned int *bsize);
3988 + int (*read_fragment_index_table)(struct super_block *s);
3991 --- a/init/do_mounts.c
3992 +++ b/init/do_mounts.c
3994 #include <linux/minix_fs.h>
3995 #include <linux/ext2_fs.h>
3996 #include <linux/romfs_fs.h>
3997 +#include <linux/squashfs_fs.h>
3998 #include <linux/cramfs_fs.h>
4000 #define BUILD_CRAMDISK
4001 @@ -476,6 +477,7 @@ static int __init crd_load(int in_fd, in
4009 @@ -486,6 +488,7 @@ identify_ramdisk_image(int fd, int start
4010 struct minix_super_block *minixsb;
4011 struct ext2_super_block *ext2sb;
4012 struct romfs_super_block *romfsb;
4013 + struct squashfs_super_block *squashfsb;
4014 struct cramfs_super *cramfsb;
4017 @@ -497,6 +500,7 @@ identify_ramdisk_image(int fd, int start
4018 minixsb = (struct minix_super_block *) buf;
4019 ext2sb = (struct ext2_super_block *) buf;
4020 romfsb = (struct romfs_super_block *) buf;
4021 + squashfsb = (struct squashfs_super_block *) buf;
4022 cramfsb = (struct cramfs_super *) buf;
4023 memset(buf, 0xe5, size);
4025 @@ -535,6 +539,15 @@ identify_ramdisk_image(int fd, int start
4029 + /* squashfs is at block zero too */
4030 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4031 + printk(KERN_NOTICE
4032 + "RAMDISK: squashfs filesystem found at block %d\n",
4034 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4039 * Read block 1 to test for minix and ext2 superblock
4043 @@ -10,6 +10,7 @@ tristate 'CRC32 functions' CONFIG_CRC32
4044 # Do we need the compression support?
4046 if [ "$CONFIG_CRAMFS" = "y" -o \
4047 + "$CONFIG_SQUASHFS" = "y" -o \
4048 "$CONFIG_PPP_DEFLATE" = "y" -o \
4049 "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
4050 "$CONFIG_JFFS2_FS" = "y" -o \
4051 @@ -17,6 +18,7 @@ if [ "$CONFIG_CRAMFS" = "y" -o \
4052 define_tristate CONFIG_ZLIB_INFLATE y
4054 if [ "$CONFIG_CRAMFS" = "m" -o \
4055 + "$CONFIG_SQUASHFS" = "m" -o \
4056 "$CONFIG_PPP_DEFLATE" = "m" -o \
4057 "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
4058 "$CONFIG_JFFS2_FS" = "m" -o \