1 diff --new-file -urp linux-2.6.16/fs/Kconfig linux-2.6.16-squashfs3.1/fs/Kconfig
2 --- linux-2.6.16/fs/Kconfig 2006-03-20 05:53:29.000000000 +0000
3 +++ linux-2.6.16-squashfs3.1/fs/Kconfig 2006-08-20 01:15:02.000000000 +0100
4 @@ -1193,6 +1193,71 @@ config CRAMFS
9 + tristate "SquashFS 3.1 - Squashed file system support"
12 + Saying Y here includes support for SquashFS 3.1 (a Compressed Read-Only File
13 + System). Squashfs is a highly compressed read-only filesystem for Linux.
14 + It uses zlib compression to compress both files, inodes and directories.
15 + Inodes in the system are very small and all blocks are packed to minimise
16 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
17 + SquashFS 3.1 supports 64 bit filesystems and files (larger than 4GB), full
18 + uid/gid information, hard links and timestamps.
20 + Squashfs is intended for general read-only filesystem use, for archival
21 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
22 + systems where low overhead is needed. Further information and filesystem tools
23 + are available from http://squashfs.sourceforge.net.
25 + If you want to compile this as a module ( = code which can be
26 + inserted in and removed from the running kernel whenever you want),
27 + say M here and read <file:Documentation/modules.txt>. The module
28 + will be called squashfs. Note that the root file system (the one
29 + containing the directory /) cannot be compiled as a module.
33 +config SQUASHFS_EMBEDDED
35 + bool "Additional options for memory-constrained systems"
39 + Saying Y here allows you to specify cache sizes and how Squashfs
40 + allocates memory. This is only intended for memory constrained
45 +config SQUASHFS_FRAGMENT_CACHE_SIZE
46 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
50 + By default SquashFS caches the last 3 fragments read from
51 + the filesystem. Increasing this amount may mean SquashFS
52 + has to re-read fragments less often from disk, at the expense
53 + of extra system memory. Decreasing this amount will mean
54 + SquashFS uses less memory at the expense of extra reads from disk.
56 + Note there must be at least one cached fragment. Anything
57 + much more than three will probably not make much difference.
59 +config SQUASHFS_VMALLOC
60 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
64 + By default SquashFS uses kmalloc to obtain fragment cache memory.
65 + Kmalloc memory is the standard kernel allocator, but it can fail
66 + on memory constrained systems. Because of the way Vmalloc works,
67 + Vmalloc can succeed when kmalloc fails. Specifying this option
68 + will make SquashFS always use Vmalloc to allocate the
69 + fragment cache memory.
74 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
76 diff --new-file -urp linux-2.6.16/fs/Makefile linux-2.6.16-squashfs3.1/fs/Makefile
77 --- linux-2.6.16/fs/Makefile 2006-03-20 05:53:29.000000000 +0000
78 +++ linux-2.6.16-squashfs3.1/fs/Makefile 2006-08-11 09:32:48.000000000 +0100
79 @@ -55,6 +55,7 @@ obj-$(CONFIG_EXT3_FS) += ext3/ # Before
80 obj-$(CONFIG_JBD) += jbd/
81 obj-$(CONFIG_EXT2_FS) += ext2/
82 obj-$(CONFIG_CRAMFS) += cramfs/
83 +obj-$(CONFIG_SQUASHFS) += squashfs/
84 obj-$(CONFIG_RAMFS) += ramfs/
85 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
86 obj-$(CONFIG_CODA_FS) += coda/
87 diff --new-file -urp linux-2.6.16/fs/squashfs/inode.c linux-2.6.16-squashfs3.1/fs/squashfs/inode.c
88 --- linux-2.6.16/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.16-squashfs3.1/fs/squashfs/inode.c 2006-08-20 01:15:02.000000000 +0100
92 + * Squashfs - a compressed read only filesystem for Linux
94 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
95 + * Phillip Lougher <phillip@lougher.org.uk>
97 + * This program is free software; you can redistribute it and/or
98 + * modify it under the terms of the GNU General Public License
99 + * as published by the Free Software Foundation; either version 2,
100 + * or (at your option) any later version.
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
114 +#include <linux/types.h>
115 +#include <linux/squashfs_fs.h>
116 +#include <linux/module.h>
117 +#include <linux/errno.h>
118 +#include <linux/slab.h>
119 +#include <linux/zlib.h>
120 +#include <linux/fs.h>
121 +#include <linux/smp_lock.h>
122 +#include <linux/slab.h>
123 +#include <linux/squashfs_fs_sb.h>
124 +#include <linux/squashfs_fs_i.h>
125 +#include <linux/buffer_head.h>
126 +#include <linux/vfs.h>
127 +#include <linux/init.h>
128 +#include <linux/dcache.h>
129 +#include <linux/wait.h>
130 +#include <linux/blkdev.h>
131 +#include <linux/vmalloc.h>
132 +#include <asm/uaccess.h>
133 +#include <asm/semaphore.h>
135 +#include "squashfs.h"
137 +static void squashfs_put_super(struct super_block *);
138 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
139 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
140 +static int squashfs_readpage(struct file *file, struct page *page);
141 +static int squashfs_readpage4K(struct file *file, struct page *page);
142 +static int squashfs_readdir(struct file *, void *, filldir_t);
143 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
144 +static void squashfs_destroy_inode(struct inode *inode);
145 +static int init_inodecache(void);
146 +static void destroy_inodecache(void);
147 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
148 + struct nameidata *);
149 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
150 +static long long read_blocklist(struct inode *inode, int index,
151 + int readahead_blks, char *block_list,
152 + unsigned short **block_p, unsigned int *bsize);
153 +static struct super_block *squashfs_get_sb(struct file_system_type *, int,
154 + const char *, void *);
156 +static struct file_system_type squashfs_fs_type = {
157 + .owner = THIS_MODULE,
158 + .name = "squashfs",
159 + .get_sb = squashfs_get_sb,
160 + .kill_sb = kill_block_super,
161 + .fs_flags = FS_REQUIRES_DEV
164 +static unsigned char squashfs_filetype_table[] = {
165 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
168 +static struct super_operations squashfs_ops = {
169 + .alloc_inode = squashfs_alloc_inode,
170 + .destroy_inode = squashfs_destroy_inode,
171 + .statfs = squashfs_statfs,
172 + .put_super = squashfs_put_super,
175 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
176 + .readpage = squashfs_symlink_readpage
179 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
180 + .readpage = squashfs_readpage
183 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
184 + .readpage = squashfs_readpage4K
187 +static struct file_operations squashfs_dir_ops = {
188 + .read = generic_read_dir,
189 + .readdir = squashfs_readdir
192 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
193 + .lookup = squashfs_lookup
197 +static struct buffer_head *get_block_length(struct super_block *s,
198 + int *cur_index, int *offset, int *c_byte)
200 + struct squashfs_sb_info *msblk = s->s_fs_info;
201 + unsigned short temp;
202 + struct buffer_head *bh;
204 + if (!(bh = sb_bread(s, *cur_index)))
207 + if (msblk->devblksize - *offset == 1) {
209 + ((unsigned char *) &temp)[1] = *((unsigned char *)
210 + (bh->b_data + *offset));
212 + ((unsigned char *) &temp)[0] = *((unsigned char *)
213 + (bh->b_data + *offset));
215 + if (!(bh = sb_bread(s, ++(*cur_index))))
218 + ((unsigned char *) &temp)[0] = *((unsigned char *)
221 + ((unsigned char *) &temp)[1] = *((unsigned char *)
227 + ((unsigned char *) &temp)[1] = *((unsigned char *)
228 + (bh->b_data + *offset));
229 + ((unsigned char *) &temp)[0] = *((unsigned char *)
230 + (bh->b_data + *offset + 1));
232 + ((unsigned char *) &temp)[0] = *((unsigned char *)
233 + (bh->b_data + *offset));
234 + ((unsigned char *) &temp)[1] = *((unsigned char *)
235 + (bh->b_data + *offset + 1));
241 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
242 + if (*offset == msblk->devblksize) {
244 + if (!(bh = sb_bread(s, ++(*cur_index))))
248 + if (*((unsigned char *) (bh->b_data + *offset)) !=
249 + SQUASHFS_MARKER_BYTE) {
250 + ERROR("Metadata block marker corrupt @ %x\n",
264 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
265 + long long index, unsigned int length,
266 + long long *next_index)
268 + struct squashfs_sb_info *msblk = s->s_fs_info;
269 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
270 + msblk->devblksize_log2) + 2];
271 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
272 + unsigned int cur_index = index >> msblk->devblksize_log2;
273 + int bytes, avail_bytes, b = 0, k;
275 + unsigned int compressed;
276 + unsigned int c_byte = length;
279 + bytes = msblk->devblksize - offset;
280 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
281 + c_buffer = compressed ? msblk->read_data : buffer;
282 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
284 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
285 + ? "" : "un", (unsigned int) c_byte);
287 + if (!(bh[0] = sb_getblk(s, cur_index)))
288 + goto block_release;
290 + for (b = 1; bytes < c_byte; b++) {
291 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
292 + goto block_release;
293 + bytes += msblk->devblksize;
295 + ll_rw_block(READ, b, bh);
297 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
301 + bytes = msblk->devblksize - offset;
302 + compressed = SQUASHFS_COMPRESSED(c_byte);
303 + c_buffer = compressed ? msblk->read_data : buffer;
304 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
306 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
307 + ? "" : "un", (unsigned int) c_byte);
309 + for (b = 1; bytes < c_byte; b++) {
310 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
311 + goto block_release;
312 + bytes += msblk->devblksize;
314 + ll_rw_block(READ, b - 1, bh + 1);
318 + down(&msblk->read_data_mutex);
320 + for (bytes = 0, k = 0; k < b; k++) {
321 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
322 + msblk->devblksize - offset :
324 + wait_on_buffer(bh[k]);
325 + if (!buffer_uptodate(bh[k]))
326 + goto block_release;
327 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
328 + bytes += avail_bytes;
339 + msblk->stream.next_in = c_buffer;
340 + msblk->stream.avail_in = c_byte;
341 + msblk->stream.next_out = buffer;
342 + msblk->stream.avail_out = msblk->read_size;
344 + if (((zlib_err = zlib_inflateInit(&msblk->stream)) != Z_OK) ||
345 + ((zlib_err = zlib_inflate(&msblk->stream, Z_FINISH))
346 + != Z_STREAM_END) || ((zlib_err =
347 + zlib_inflateEnd(&msblk->stream)) != Z_OK)) {
348 + ERROR("zlib_fs returned unexpected result 0x%x\n",
352 + bytes = msblk->stream.total_out;
354 + up(&msblk->read_data_mutex);
358 + *next_index = index + c_byte + (length ? 0 :
359 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
368 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
373 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
374 + long long block, unsigned int offset,
375 + int length, long long *next_block,
376 + unsigned int *next_offset)
378 + struct squashfs_sb_info *msblk = s->s_fs_info;
379 + int n, i, bytes, return_length = length;
380 + long long next_index;
382 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
385 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
386 + if (msblk->block_cache[i].block == block)
389 + down(&msblk->block_cache_mutex);
391 + if (i == SQUASHFS_CACHED_BLKS) {
392 + /* read inode header block */
393 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
394 + n ; n --, i = (i + 1) %
395 + SQUASHFS_CACHED_BLKS)
396 + if (msblk->block_cache[i].block !=
403 + init_waitqueue_entry(&wait, current);
404 + add_wait_queue(&msblk->waitq, &wait);
405 + set_current_state(TASK_UNINTERRUPTIBLE);
406 + up(&msblk->block_cache_mutex);
408 + set_current_state(TASK_RUNNING);
409 + remove_wait_queue(&msblk->waitq, &wait);
412 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
414 + if (msblk->block_cache[i].block ==
415 + SQUASHFS_INVALID_BLK) {
416 + if (!(msblk->block_cache[i].data =
417 + kmalloc(SQUASHFS_METADATA_SIZE,
419 + ERROR("Failed to allocate cache"
421 + up(&msblk->block_cache_mutex);
426 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
427 + up(&msblk->block_cache_mutex);
429 + if (!(msblk->block_cache[i].length =
430 + squashfs_read_data(s,
431 + msblk->block_cache[i].data,
432 + block, 0, &next_index))) {
433 + ERROR("Unable to read cache block [%llx:%x]\n",
438 + down(&msblk->block_cache_mutex);
439 + wake_up(&msblk->waitq);
440 + msblk->block_cache[i].block = block;
441 + msblk->block_cache[i].next_index = next_index;
442 + TRACE("Read cache block [%llx:%x]\n", block, offset);
445 + if (msblk->block_cache[i].block != block) {
446 + up(&msblk->block_cache_mutex);
450 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
452 + memcpy(buffer, msblk->block_cache[i].data +
454 + if (msblk->block_cache[i].length - offset == length) {
455 + *next_block = msblk->block_cache[i].next_index;
458 + *next_block = block;
459 + *next_offset = offset + length;
461 + up(&msblk->block_cache_mutex);
465 + memcpy(buffer, msblk->block_cache[i].data +
469 + block = msblk->block_cache[i].next_index;
470 + up(&msblk->block_cache_mutex);
477 + return return_length;
483 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
484 + long long *fragment_start_block,
485 + unsigned int *fragment_size)
487 + struct squashfs_sb_info *msblk = s->s_fs_info;
488 + long long start_block =
489 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
490 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
491 + struct squashfs_fragment_entry fragment_entry;
494 + struct squashfs_fragment_entry sfragment_entry;
496 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
497 + start_block, offset,
498 + sizeof(sfragment_entry), &start_block,
501 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
503 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
504 + start_block, offset,
505 + sizeof(fragment_entry), &start_block,
509 + *fragment_start_block = fragment_entry.start_block;
510 + *fragment_size = fragment_entry.size;
519 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
520 + squashfs_fragment_cache *fragment)
522 + down(&msblk->fragment_mutex);
523 + fragment->locked --;
524 + wake_up(&msblk->fragment_wait_queue);
525 + up(&msblk->fragment_mutex);
529 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
530 + *s, long long start_block,
534 + struct squashfs_sb_info *msblk = s->s_fs_info;
537 + down(&msblk->fragment_mutex);
539 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
540 + msblk->fragment[i].block != start_block; i++);
542 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
543 + for (i = msblk->next_fragment, n =
544 + SQUASHFS_CACHED_FRAGMENTS; n &&
545 + msblk->fragment[i].locked; n--, i = (i + 1) %
546 + SQUASHFS_CACHED_FRAGMENTS);
551 + init_waitqueue_entry(&wait, current);
552 + add_wait_queue(&msblk->fragment_wait_queue,
554 + set_current_state(TASK_UNINTERRUPTIBLE);
555 + up(&msblk->fragment_mutex);
557 + set_current_state(TASK_RUNNING);
558 + remove_wait_queue(&msblk->fragment_wait_queue,
562 + msblk->next_fragment = (msblk->next_fragment + 1) %
563 + SQUASHFS_CACHED_FRAGMENTS;
565 + if (msblk->fragment[i].data == NULL)
566 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
567 + (SQUASHFS_FILE_MAX_SIZE))) {
568 + ERROR("Failed to allocate fragment "
570 + up(&msblk->fragment_mutex);
574 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
575 + msblk->fragment[i].locked = 1;
576 + up(&msblk->fragment_mutex);
578 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
579 + msblk->fragment[i].data,
580 + start_block, length, NULL))) {
581 + ERROR("Unable to read fragment cache block "
582 + "[%llx]\n", start_block);
583 + msblk->fragment[i].locked = 0;
587 + msblk->fragment[i].block = start_block;
588 + TRACE("New fragment %d, start block %lld, locked %d\n",
589 + i, msblk->fragment[i].block,
590 + msblk->fragment[i].locked);
594 + msblk->fragment[i].locked++;
595 + up(&msblk->fragment_mutex);
596 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
597 + msblk->fragment[i].block,
598 + msblk->fragment[i].locked);
602 + return &msblk->fragment[i];
609 +static struct inode *squashfs_new_inode(struct super_block *s,
610 + struct squashfs_base_inode_header *inodeb)
612 + struct squashfs_sb_info *msblk = s->s_fs_info;
613 + struct inode *i = new_inode(s);
616 + i->i_ino = inodeb->inode_number;
617 + i->i_mtime.tv_sec = inodeb->mtime;
618 + i->i_atime.tv_sec = inodeb->mtime;
619 + i->i_ctime.tv_sec = inodeb->mtime;
620 + i->i_uid = msblk->uid[inodeb->uid];
621 + i->i_mode = inodeb->mode;
623 + if (inodeb->guid == SQUASHFS_GUIDS)
624 + i->i_gid = i->i_uid;
626 + i->i_gid = msblk->guid[inodeb->guid];
633 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
636 + struct squashfs_sb_info *msblk = s->s_fs_info;
637 + struct squashfs_super_block *sblk = &msblk->sblk;
638 + long long block = SQUASHFS_INODE_BLK(inode) +
639 + sblk->inode_table_start;
640 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
641 + long long next_block;
642 + unsigned int next_offset;
643 + union squashfs_inode_header id, sid;
644 + struct squashfs_base_inode_header *inodeb = &id.base,
645 + *sinodeb = &sid.base;
647 + TRACE("Entered squashfs_iget\n");
650 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
651 + offset, sizeof(*sinodeb), &next_block,
654 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
657 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
658 + offset, sizeof(*inodeb), &next_block,
662 + switch(inodeb->inode_type) {
663 + case SQUASHFS_FILE_TYPE: {
664 + unsigned int frag_size;
665 + long long frag_blk;
666 + struct squashfs_reg_inode_header *inodep = &id.reg;
667 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
670 + if (!squashfs_get_cached_block(s, (char *)
671 + sinodep, block, offset,
672 + sizeof(*sinodep), &next_block,
675 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
677 + if (!squashfs_get_cached_block(s, (char *)
678 + inodep, block, offset,
679 + sizeof(*inodep), &next_block,
683 + frag_blk = SQUASHFS_INVALID_BLK;
684 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
685 + !get_fragment_location(s,
686 + inodep->fragment, &frag_blk, &frag_size))
689 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
693 + i->i_size = inodep->file_size;
694 + i->i_fop = &generic_ro_fops;
695 + i->i_mode |= S_IFREG;
696 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
697 + i->i_blksize = PAGE_CACHE_SIZE;
698 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
699 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
700 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
701 + SQUASHFS_I(i)->start_block = inodep->start_block;
702 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
703 + SQUASHFS_I(i)->offset = next_offset;
704 + if (sblk->block_size > 4096)
705 + i->i_data.a_ops = &squashfs_aops;
707 + i->i_data.a_ops = &squashfs_aops_4K;
709 + TRACE("File inode %x:%x, start_block %llx, "
710 + "block_list_start %llx, offset %x\n",
711 + SQUASHFS_INODE_BLK(inode), offset,
712 + inodep->start_block, next_block,
716 + case SQUASHFS_LREG_TYPE: {
717 + unsigned int frag_size;
718 + long long frag_blk;
719 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
720 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
723 + if (!squashfs_get_cached_block(s, (char *)
724 + sinodep, block, offset,
725 + sizeof(*sinodep), &next_block,
728 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
730 + if (!squashfs_get_cached_block(s, (char *)
731 + inodep, block, offset,
732 + sizeof(*inodep), &next_block,
736 + frag_blk = SQUASHFS_INVALID_BLK;
737 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
738 + !get_fragment_location(s,
739 + inodep->fragment, &frag_blk, &frag_size))
742 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
745 + i->i_nlink = inodep->nlink;
746 + i->i_size = inodep->file_size;
747 + i->i_fop = &generic_ro_fops;
748 + i->i_mode |= S_IFREG;
749 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
750 + i->i_blksize = PAGE_CACHE_SIZE;
751 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
752 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
753 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
754 + SQUASHFS_I(i)->start_block = inodep->start_block;
755 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
756 + SQUASHFS_I(i)->offset = next_offset;
757 + if (sblk->block_size > 4096)
758 + i->i_data.a_ops = &squashfs_aops;
760 + i->i_data.a_ops = &squashfs_aops_4K;
762 + TRACE("File inode %x:%x, start_block %llx, "
763 + "block_list_start %llx, offset %x\n",
764 + SQUASHFS_INODE_BLK(inode), offset,
765 + inodep->start_block, next_block,
769 + case SQUASHFS_DIR_TYPE: {
770 + struct squashfs_dir_inode_header *inodep = &id.dir;
771 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
774 + if (!squashfs_get_cached_block(s, (char *)
775 + sinodep, block, offset,
776 + sizeof(*sinodep), &next_block,
779 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
781 + if (!squashfs_get_cached_block(s, (char *)
782 + inodep, block, offset,
783 + sizeof(*inodep), &next_block,
787 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
790 + i->i_nlink = inodep->nlink;
791 + i->i_size = inodep->file_size;
792 + i->i_op = &squashfs_dir_inode_ops;
793 + i->i_fop = &squashfs_dir_ops;
794 + i->i_mode |= S_IFDIR;
795 + SQUASHFS_I(i)->start_block = inodep->start_block;
796 + SQUASHFS_I(i)->offset = inodep->offset;
797 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
798 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
800 + TRACE("Directory inode %x:%x, start_block %x, offset "
801 + "%x\n", SQUASHFS_INODE_BLK(inode),
802 + offset, inodep->start_block,
806 + case SQUASHFS_LDIR_TYPE: {
807 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
808 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
811 + if (!squashfs_get_cached_block(s, (char *)
812 + sinodep, block, offset,
813 + sizeof(*sinodep), &next_block,
816 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
819 + if (!squashfs_get_cached_block(s, (char *)
820 + inodep, block, offset,
821 + sizeof(*inodep), &next_block,
825 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
828 + i->i_nlink = inodep->nlink;
829 + i->i_size = inodep->file_size;
830 + i->i_op = &squashfs_dir_inode_ops;
831 + i->i_fop = &squashfs_dir_ops;
832 + i->i_mode |= S_IFDIR;
833 + SQUASHFS_I(i)->start_block = inodep->start_block;
834 + SQUASHFS_I(i)->offset = inodep->offset;
835 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
836 + SQUASHFS_I(i)->u.s2.directory_index_offset =
838 + SQUASHFS_I(i)->u.s2.directory_index_count =
840 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
842 + TRACE("Long directory inode %x:%x, start_block %x, "
844 + SQUASHFS_INODE_BLK(inode), offset,
845 + inodep->start_block, inodep->offset);
848 + case SQUASHFS_SYMLINK_TYPE: {
849 + struct squashfs_symlink_inode_header *inodep =
851 + struct squashfs_symlink_inode_header *sinodep =
855 + if (!squashfs_get_cached_block(s, (char *)
856 + sinodep, block, offset,
857 + sizeof(*sinodep), &next_block,
860 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
863 + if (!squashfs_get_cached_block(s, (char *)
864 + inodep, block, offset,
865 + sizeof(*inodep), &next_block,
869 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
872 + i->i_nlink = inodep->nlink;
873 + i->i_size = inodep->symlink_size;
874 + i->i_op = &page_symlink_inode_operations;
875 + i->i_data.a_ops = &squashfs_symlink_aops;
876 + i->i_mode |= S_IFLNK;
877 + SQUASHFS_I(i)->start_block = next_block;
878 + SQUASHFS_I(i)->offset = next_offset;
880 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
882 + SQUASHFS_INODE_BLK(inode), offset,
883 + next_block, next_offset);
886 + case SQUASHFS_BLKDEV_TYPE:
887 + case SQUASHFS_CHRDEV_TYPE: {
888 + struct squashfs_dev_inode_header *inodep = &id.dev;
889 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
892 + if (!squashfs_get_cached_block(s, (char *)
893 + sinodep, block, offset,
894 + sizeof(*sinodep), &next_block,
897 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
899 + if (!squashfs_get_cached_block(s, (char *)
900 + inodep, block, offset,
901 + sizeof(*inodep), &next_block,
905 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
908 + i->i_nlink = inodep->nlink;
909 + i->i_mode |= (inodeb->inode_type ==
910 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
912 + init_special_inode(i, i->i_mode,
913 + old_decode_dev(inodep->rdev));
915 + TRACE("Device inode %x:%x, rdev %x\n",
916 + SQUASHFS_INODE_BLK(inode), offset,
920 + case SQUASHFS_FIFO_TYPE:
921 + case SQUASHFS_SOCKET_TYPE: {
922 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
923 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
926 + if (!squashfs_get_cached_block(s, (char *)
927 + sinodep, block, offset,
928 + sizeof(*sinodep), &next_block,
931 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
933 + if (!squashfs_get_cached_block(s, (char *)
934 + inodep, block, offset,
935 + sizeof(*inodep), &next_block,
939 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
942 + i->i_nlink = inodep->nlink;
943 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
944 + ? S_IFIFO : S_IFSOCK;
945 + init_special_inode(i, i->i_mode, 0);
949 + ERROR("Unknown inode type %d in squashfs_iget!\n",
950 + inodeb->inode_type);
954 + insert_inode_hash(i);
958 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
965 +static int read_fragment_index_table(struct super_block *s)
967 + struct squashfs_sb_info *msblk = s->s_fs_info;
968 + struct squashfs_super_block *sblk = &msblk->sblk;
970 + /* Allocate fragment index table */
971 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
972 + (sblk->fragments), GFP_KERNEL))) {
973 + ERROR("Failed to allocate uid/gid table\n");
977 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
978 + !squashfs_read_data(s, (char *)
979 + msblk->fragment_index,
980 + sblk->fragment_table_start,
981 + SQUASHFS_FRAGMENT_INDEX_BYTES
982 + (sblk->fragments) |
983 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
984 + ERROR("unable to read fragment index table\n");
990 + long long fragment;
992 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
994 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
995 + &msblk->fragment_index[i], 1);
996 + msblk->fragment_index[i] = fragment;
1004 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1006 + struct squashfs_super_block *sblk = &msblk->sblk;
1008 + msblk->iget = squashfs_iget;
1009 + msblk->read_blocklist = read_blocklist;
1010 + msblk->read_fragment_index_table = read_fragment_index_table;
1012 + if (sblk->s_major == 1) {
1013 + if (!squashfs_1_0_supported(msblk)) {
1014 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1015 + "are unsupported\n");
1016 + SERROR("Please recompile with "
1017 + "Squashfs 1.0 support enabled\n");
1020 + } else if (sblk->s_major == 2) {
1021 + if (!squashfs_2_0_supported(msblk)) {
1022 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1023 + "are unsupported\n");
1024 + SERROR("Please recompile with "
1025 + "Squashfs 2.0 support enabled\n");
1028 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1030 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1031 + "filesystem\n", sblk->s_major, sblk->s_minor);
1032 + SERROR("Please update your kernel\n");
1040 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1042 + struct squashfs_sb_info *msblk;
1043 + struct squashfs_super_block *sblk;
1045 + char b[BDEVNAME_SIZE];
1046 + struct inode *root;
1048 + TRACE("Entered squashfs_read_superblock\n");
1050 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1052 + ERROR("Failed to allocate superblock\n");
1055 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1056 + msblk = s->s_fs_info;
1057 + if (!(msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
1058 + ERROR("Failed to allocate zlib workspace\n");
1061 + sblk = &msblk->sblk;
1063 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1064 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1066 + init_MUTEX(&msblk->read_data_mutex);
1067 + init_MUTEX(&msblk->read_page_mutex);
1068 + init_MUTEX(&msblk->block_cache_mutex);
1069 + init_MUTEX(&msblk->fragment_mutex);
1070 + init_MUTEX(&msblk->meta_index_mutex);
1072 + init_waitqueue_head(&msblk->waitq);
1073 + init_waitqueue_head(&msblk->fragment_wait_queue);
1075 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1076 + sizeof(struct squashfs_super_block) |
1077 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1078 + SERROR("unable to read superblock\n");
1079 + goto failed_mount;
1082 + /* Check it is a SQUASHFS superblock */
1084 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1085 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1086 + struct squashfs_super_block ssblk;
1088 + WARNING("Mounting a different endian SQUASHFS "
1089 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1091 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1092 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1095 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1096 + bdevname(s->s_bdev, b));
1097 + goto failed_mount;
1101 + /* Check the MAJOR & MINOR versions */
1102 + if(!supported_squashfs_filesystem(msblk, silent))
1103 + goto failed_mount;
1105 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1106 + TRACE("Inodes are %scompressed\n",
1107 + SQUASHFS_UNCOMPRESSED_INODES
1108 + (sblk->flags) ? "un" : "");
1109 + TRACE("Data is %scompressed\n",
1110 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1112 + TRACE("Check data is %s present in the filesystem\n",
1113 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1115 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1116 + TRACE("Block size %d\n", sblk->block_size);
1117 + TRACE("Number of inodes %d\n", sblk->inodes);
1118 + if (sblk->s_major > 1)
1119 + TRACE("Number of fragments %d\n", sblk->fragments);
1120 + TRACE("Number of uids %d\n", sblk->no_uids);
1121 + TRACE("Number of gids %d\n", sblk->no_guids);
1122 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1123 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1124 + if (sblk->s_major > 1)
1125 + TRACE("sblk->fragment_table_start %llx\n",
1126 + sblk->fragment_table_start);
1127 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1129 + s->s_flags |= MS_RDONLY;
1130 + s->s_op = &squashfs_ops;
1132 + /* Init inode_table block pointer array */
1133 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1134 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1135 + ERROR("Failed to allocate block cache\n");
1136 + goto failed_mount;
1139 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1140 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1142 + msblk->next_cache = 0;
1144 + /* Allocate read_data block */
1145 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1146 + SQUASHFS_METADATA_SIZE :
1149 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1150 + ERROR("Failed to allocate read_data block\n");
1151 + goto failed_mount;
1154 + /* Allocate read_page block */
1155 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1156 + ERROR("Failed to allocate read_page block\n");
1157 + goto failed_mount;
1160 + /* Allocate uid and gid tables */
1161 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1162 + sizeof(unsigned int), GFP_KERNEL))) {
1163 + ERROR("Failed to allocate uid/gid table\n");
1164 + goto failed_mount;
1166 + msblk->guid = msblk->uid + sblk->no_uids;
1168 + if (msblk->swap) {
1169 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1171 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1172 + ((sblk->no_uids + sblk->no_guids) *
1173 + sizeof(unsigned int)) |
1174 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1175 + ERROR("unable to read uid/gid table\n");
1176 + goto failed_mount;
1179 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1180 + sblk->no_guids), (sizeof(unsigned int) * 8));
1182 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1183 + ((sblk->no_uids + sblk->no_guids) *
1184 + sizeof(unsigned int)) |
1185 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1186 + ERROR("unable to read uid/gid table\n");
1187 + goto failed_mount;
1191 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1192 + goto allocate_root;
1194 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1195 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1196 + ERROR("Failed to allocate fragment block cache\n");
1197 + goto failed_mount;
1200 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1201 + msblk->fragment[i].locked = 0;
1202 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1203 + msblk->fragment[i].data = NULL;
1206 + msblk->next_fragment = 0;
1208 + /* Allocate fragment index table */
1209 + if (msblk->read_fragment_index_table(s) == 0)
1210 + goto failed_mount;
1213 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1214 + goto failed_mount;
1216 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1217 + ERROR("Root inode create failed\n");
1219 + goto failed_mount;
1222 + TRACE("Leaving squashfs_read_super\n");
1226 + kfree(msblk->fragment_index);
1227 + kfree(msblk->fragment);
1228 + kfree(msblk->uid);
1229 + kfree(msblk->read_page);
1230 + kfree(msblk->read_data);
1231 + kfree(msblk->block_cache);
1232 + kfree(msblk->fragment_index_2);
1233 + vfree(msblk->stream.workspace);
1234 + kfree(s->s_fs_info);
1235 + s->s_fs_info = NULL;
1243 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1245 + struct squashfs_sb_info *msblk = s->s_fs_info;
1246 + struct squashfs_super_block *sblk = &msblk->sblk;
1248 + TRACE("Entered squashfs_statfs\n");
1250 + buf->f_type = SQUASHFS_MAGIC;
1251 + buf->f_bsize = sblk->block_size;
1252 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1253 + buf->f_bfree = buf->f_bavail = 0;
1254 + buf->f_files = sblk->inodes;
1256 + buf->f_namelen = SQUASHFS_NAME_LEN;
1262 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1264 + struct inode *inode = page->mapping->host;
1265 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1266 + long long block = SQUASHFS_I(inode)->start_block;
1267 + int offset = SQUASHFS_I(inode)->offset;
1268 + void *pageaddr = kmap(page);
1270 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1271 + "%llx, offset %x\n", page->index,
1272 + SQUASHFS_I(inode)->start_block,
1273 + SQUASHFS_I(inode)->offset);
1275 + for (length = 0; length < index; length += bytes) {
1276 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1277 + block, offset, PAGE_CACHE_SIZE, &block,
1279 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1285 + if (length != index) {
1286 + ERROR("(squashfs_symlink_readpage) length != index\n");
1291 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1292 + i_size_read(inode) - length;
1294 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1295 + offset, bytes, &block, &offset)))
1296 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1299 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1301 + SetPageUptodate(page);
1302 + unlock_page(page);
1308 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1310 + struct meta_index *meta = NULL;
1311 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1314 + down(&msblk->meta_index_mutex);
1316 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1318 + if(msblk->meta_index == NULL)
1319 + goto not_allocated;
1321 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1322 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1323 + msblk->meta_index[i].offset >= offset &&
1324 + msblk->meta_index[i].offset <= index &&
1325 + msblk->meta_index[i].locked == 0) {
1326 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1327 + msblk->meta_index[i].offset);
1328 + meta = &msblk->meta_index[i];
1329 + offset = meta->offset;
1336 + up(&msblk->meta_index_mutex);
1342 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1344 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1345 + struct meta_index *meta = NULL;
1348 + down(&msblk->meta_index_mutex);
1350 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1352 + if(msblk->meta_index == NULL) {
1353 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1354 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1355 + ERROR("Failed to allocate meta_index\n");
1358 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1359 + msblk->meta_index[i].inode_number = 0;
1360 + msblk->meta_index[i].locked = 0;
1362 + msblk->next_meta_index = 0;
1365 + for(i = SQUASHFS_META_NUMBER; i &&
1366 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1367 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1368 + SQUASHFS_META_NUMBER;
1371 + TRACE("empty_meta_index: failed!\n");
1375 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1376 + msblk->next_meta_index,
1377 + &msblk->meta_index[msblk->next_meta_index]);
1379 + meta = &msblk->meta_index[msblk->next_meta_index];
1380 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1381 + SQUASHFS_META_NUMBER;
1383 + meta->inode_number = inode->i_ino;
1384 + meta->offset = offset;
1385 + meta->skip = skip;
1386 + meta->entries = 0;
1390 + up(&msblk->meta_index_mutex);
1395 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1401 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1402 + long long *start_block, int *offset)
1404 + struct squashfs_sb_info *msblk = s->s_fs_info;
1405 + unsigned int *block_listp;
1408 + if (msblk->swap) {
1409 + char sblock_list[blocks << 2];
1411 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1412 + *offset, blocks << 2, start_block, offset)) {
1413 + ERROR("Unable to read block list [%llx:%x]\n",
1414 + *start_block, *offset);
1417 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1418 + ((unsigned int *)sblock_list), blocks);
1420 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1421 + *offset, blocks << 2, start_block, offset)) {
1422 + ERROR("Unable to read block list [%llx:%x]\n",
1423 + *start_block, *offset);
1427 + for (block_listp = (unsigned int *) block_list; blocks;
1428 + block_listp++, blocks --)
1429 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1440 +static inline int calculate_skip(int blocks) {
1441 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1442 + return skip >= 7 ? 7 : skip + 1;
1446 +static int get_meta_index(struct inode *inode, int index,
1447 + long long *index_block, int *index_offset,
1448 + long long *data_block, char *block_list)
1450 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1451 + struct squashfs_super_block *sblk = &msblk->sblk;
1452 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1454 + struct meta_index *meta;
1455 + struct meta_entry *meta_entry;
1456 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1457 + int cur_offset = SQUASHFS_I(inode)->offset;
1458 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1461 + index /= SQUASHFS_META_INDEXES * skip;
1463 + while ( offset < index ) {
1464 + meta = locate_meta_index(inode, index, offset + 1);
1466 + if (meta == NULL) {
1467 + if ((meta = empty_meta_index(inode, offset + 1,
1471 + offset = index < meta->offset + meta->entries ? index :
1472 + meta->offset + meta->entries - 1;
1473 + meta_entry = &meta->meta_entry[offset - meta->offset];
1474 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1475 + cur_offset = meta_entry->offset;
1476 + cur_data_block = meta_entry->data_block;
1477 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1478 + "meta->entries %d\n", offset, meta->offset,
1480 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1481 + " data_block 0x%llx\n", cur_index_block,
1482 + cur_offset, cur_data_block);
1485 + for (i = meta->offset + meta->entries; i <= index &&
1486 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1487 + int blocks = skip * SQUASHFS_META_INDEXES;
1490 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1492 + int res = read_block_index(inode->i_sb, block,
1493 + block_list, &cur_index_block,
1499 + cur_data_block += res;
1503 + meta_entry = &meta->meta_entry[i - meta->offset];
1504 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1505 + meta_entry->offset = cur_offset;
1506 + meta_entry->data_block = cur_data_block;
1511 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1512 + meta->offset, meta->entries);
1514 + release_meta_index(inode, meta);
1518 + *index_block = cur_index_block;
1519 + *index_offset = cur_offset;
1520 + *data_block = cur_data_block;
1522 + return offset * SQUASHFS_META_INDEXES * skip;
1525 + release_meta_index(inode, meta);
1530 +static long long read_blocklist(struct inode *inode, int index,
1531 + int readahead_blks, char *block_list,
1532 + unsigned short **block_p, unsigned int *bsize)
1534 + long long block_ptr;
1537 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1540 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1541 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1550 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1551 + int res = read_block_index(inode->i_sb, blocks, block_list,
1552 + &block_ptr, &offset);
1559 + if (read_block_index(inode->i_sb, 1, block_list,
1560 + &block_ptr, &offset) == -1)
1562 + *bsize = *((unsigned int *) block_list);
1571 +static int squashfs_readpage(struct file *file, struct page *page)
1573 + struct inode *inode = page->mapping->host;
1574 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1575 + struct squashfs_super_block *sblk = &msblk->sblk;
1576 + unsigned char *block_list;
1578 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1579 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1581 + struct squashfs_fragment_cache *fragment = NULL;
1582 + char *data_ptr = msblk->read_page;
1584 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1585 + int start_index = page->index & ~mask;
1586 + int end_index = start_index | mask;
1588 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1590 + SQUASHFS_I(inode)->start_block);
1592 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1593 + ERROR("Failed to allocate block_list\n");
1597 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1598 + PAGE_CACHE_SHIFT))
1601 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1602 + || index < (i_size_read(inode) >>
1603 + sblk->block_log)) {
1604 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1605 + block_list, NULL, &bsize)) == 0)
1608 + down(&msblk->read_page_mutex);
1610 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1611 + block, bsize, NULL))) {
1612 + ERROR("Unable to read page, block %llx, size %x\n", block,
1614 + up(&msblk->read_page_mutex);
1618 + if ((fragment = get_cached_fragment(inode->i_sb,
1619 + SQUASHFS_I(inode)->
1620 + u.s1.fragment_start_block,
1621 + SQUASHFS_I(inode)->u.s1.fragment_size))
1623 + ERROR("Unable to read page, block %llx, size %x\n",
1624 + SQUASHFS_I(inode)->
1625 + u.s1.fragment_start_block,
1626 + (int) SQUASHFS_I(inode)->
1627 + u.s1.fragment_size);
1630 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1631 + (i_size_read(inode) & (sblk->block_size
1633 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1634 + data_ptr = fragment->data;
1637 + for (i = start_index; i <= end_index && byte_offset < bytes;
1638 + i++, byte_offset += PAGE_CACHE_SIZE) {
1639 + struct page *push_page;
1640 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1641 + PAGE_CACHE_SIZE : bytes - byte_offset;
1643 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1644 + bytes, i, byte_offset, available_bytes);
1646 + if (i == page->index) {
1647 + pageaddr = kmap_atomic(page, KM_USER0);
1648 + memcpy(pageaddr, data_ptr + byte_offset,
1650 + memset(pageaddr + available_bytes, 0,
1651 + PAGE_CACHE_SIZE - available_bytes);
1652 + kunmap_atomic(pageaddr, KM_USER0);
1653 + flush_dcache_page(page);
1654 + SetPageUptodate(page);
1655 + unlock_page(page);
1656 + } else if ((push_page =
1657 + grab_cache_page_nowait(page->mapping, i))) {
1658 + pageaddr = kmap_atomic(push_page, KM_USER0);
1660 + memcpy(pageaddr, data_ptr + byte_offset,
1662 + memset(pageaddr + available_bytes, 0,
1663 + PAGE_CACHE_SIZE - available_bytes);
1664 + kunmap_atomic(pageaddr, KM_USER0);
1665 + flush_dcache_page(push_page);
1666 + SetPageUptodate(push_page);
1667 + unlock_page(push_page);
1668 + page_cache_release(push_page);
1672 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1673 + || index < (i_size_read(inode) >>
1675 + up(&msblk->read_page_mutex);
1677 + release_cached_fragment(msblk, fragment);
1679 + kfree(block_list);
1683 + pageaddr = kmap_atomic(page, KM_USER0);
1684 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1685 + kunmap_atomic(pageaddr, KM_USER0);
1686 + flush_dcache_page(page);
1687 + SetPageUptodate(page);
1688 + unlock_page(page);
1690 + kfree(block_list);
1695 +static int squashfs_readpage4K(struct file *file, struct page *page)
1697 + struct inode *inode = page->mapping->host;
1698 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1699 + struct squashfs_super_block *sblk = &msblk->sblk;
1700 + unsigned char *block_list;
1702 + unsigned int bsize, bytes = 0;
1705 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1707 + SQUASHFS_I(inode)->start_block);
1709 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1710 + PAGE_CACHE_SHIFT)) {
1711 + pageaddr = kmap_atomic(page, KM_USER0);
1712 + block_list = NULL;
1716 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1717 + ERROR("Failed to allocate block_list\n");
1718 + pageaddr = kmap_atomic(page, KM_USER0);
1719 + block_list = NULL;
1723 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1724 + || page->index < (i_size_read(inode) >>
1725 + sblk->block_log)) {
1726 + block = (msblk->read_blocklist)(inode, page->index, 1,
1727 + block_list, NULL, &bsize);
1729 + down(&msblk->read_page_mutex);
1730 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1732 + pageaddr = kmap_atomic(page, KM_USER0);
1734 + memcpy(pageaddr, msblk->read_page, bytes);
1736 + ERROR("Unable to read page, block %llx, size %x\n",
1738 + up(&msblk->read_page_mutex);
1740 + struct squashfs_fragment_cache *fragment =
1741 + get_cached_fragment(inode->i_sb,
1742 + SQUASHFS_I(inode)->
1743 + u.s1.fragment_start_block,
1744 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1745 + pageaddr = kmap_atomic(page, KM_USER0);
1747 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1748 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1749 + u.s1.fragment_offset, bytes);
1750 + release_cached_fragment(msblk, fragment);
1752 + ERROR("Unable to read page, block %llx, size %x\n",
1753 + SQUASHFS_I(inode)->
1754 + u.s1.fragment_start_block, (int)
1755 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1759 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1760 + kunmap_atomic(pageaddr, KM_USER0);
1761 + flush_dcache_page(page);
1762 + SetPageUptodate(page);
1763 + unlock_page(page);
1765 + kfree(block_list);
1770 +static int get_dir_index_using_offset(struct super_block *s, long long
1771 + *next_block, unsigned int *next_offset,
1772 + long long index_start,
1773 + unsigned int index_offset, int i_count,
1776 + struct squashfs_sb_info *msblk = s->s_fs_info;
1777 + struct squashfs_super_block *sblk = &msblk->sblk;
1778 + int i, length = 0;
1779 + struct squashfs_dir_index index;
1781 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1782 + i_count, (unsigned int) f_pos);
1788 + for (i = 0; i < i_count; i++) {
1789 + if (msblk->swap) {
1790 + struct squashfs_dir_index sindex;
1791 + squashfs_get_cached_block(s, (char *) &sindex,
1792 + index_start, index_offset,
1793 + sizeof(sindex), &index_start,
1795 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1797 + squashfs_get_cached_block(s, (char *) &index,
1798 + index_start, index_offset,
1799 + sizeof(index), &index_start,
1802 + if (index.index > f_pos)
1805 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1806 + index.size + 1, &index_start,
1809 + length = index.index;
1810 + *next_block = index.start_block + sblk->directory_table_start;
1813 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1816 + return length + 3;
1820 +static int get_dir_index_using_name(struct super_block *s, long long
1821 + *next_block, unsigned int *next_offset,
1822 + long long index_start,
1823 + unsigned int index_offset, int i_count,
1824 + const char *name, int size)
1826 + struct squashfs_sb_info *msblk = s->s_fs_info;
1827 + struct squashfs_super_block *sblk = &msblk->sblk;
1828 + int i, length = 0;
1829 + struct squashfs_dir_index *index;
1832 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1834 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
1835 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
1836 + ERROR("Failed to allocate squashfs_dir_index\n");
1840 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1841 + strncpy(str, name, size);
1844 + for (i = 0; i < i_count; i++) {
1845 + if (msblk->swap) {
1846 + struct squashfs_dir_index sindex;
1847 + squashfs_get_cached_block(s, (char *) &sindex,
1848 + index_start, index_offset,
1849 + sizeof(sindex), &index_start,
1851 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1853 + squashfs_get_cached_block(s, (char *) index,
1854 + index_start, index_offset,
1855 + sizeof(struct squashfs_dir_index),
1856 + &index_start, &index_offset);
1858 + squashfs_get_cached_block(s, index->name, index_start,
1859 + index_offset, index->size + 1,
1860 + &index_start, &index_offset);
1862 + index->name[index->size + 1] = '\0';
1864 + if (strcmp(index->name, str) > 0)
1867 + length = index->index;
1868 + *next_block = index->start_block + sblk->directory_table_start;
1871 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1874 + return length + 3;
1878 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1880 + struct inode *i = file->f_dentry->d_inode;
1881 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1882 + struct squashfs_super_block *sblk = &msblk->sblk;
1883 + long long next_block = SQUASHFS_I(i)->start_block +
1884 + sblk->directory_table_start;
1885 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1887 + struct squashfs_dir_header dirh;
1888 + struct squashfs_dir_entry *dire;
1890 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1892 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1893 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
1894 + ERROR("Failed to allocate squashfs_dir_entry\n");
1898 + while(file->f_pos < 3) {
1902 + if(file->f_pos == 0) {
1909 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1911 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1912 + (unsigned int) dirent, name, size, (int)
1913 + file->f_pos, i_ino,
1914 + squashfs_filetype_table[1]);
1916 + if (filldir(dirent, name, size,
1917 + file->f_pos, i_ino,
1918 + squashfs_filetype_table[1]) < 0) {
1919 + TRACE("Filldir returned less than 0\n");
1922 + file->f_pos += size;
1925 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1926 + SQUASHFS_I(i)->u.s2.directory_index_start,
1927 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1928 + SQUASHFS_I(i)->u.s2.directory_index_count,
1931 + while (length < i_size_read(i)) {
1932 + /* read directory header */
1933 + if (msblk->swap) {
1934 + struct squashfs_dir_header sdirh;
1936 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1937 + next_block, next_offset, sizeof(sdirh),
1938 + &next_block, &next_offset))
1941 + length += sizeof(sdirh);
1942 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1944 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1945 + next_block, next_offset, sizeof(dirh),
1946 + &next_block, &next_offset))
1949 + length += sizeof(dirh);
1952 + dir_count = dirh.count + 1;
1953 + while (dir_count--) {
1954 + if (msblk->swap) {
1955 + struct squashfs_dir_entry sdire;
1956 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1957 + &sdire, next_block, next_offset,
1958 + sizeof(sdire), &next_block,
1962 + length += sizeof(sdire);
1963 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1965 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1966 + dire, next_block, next_offset,
1967 + sizeof(*dire), &next_block,
1971 + length += sizeof(*dire);
1974 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1975 + next_block, next_offset,
1976 + dire->size + 1, &next_block,
1980 + length += dire->size + 1;
1982 + if (file->f_pos >= length)
1985 + dire->name[dire->size + 1] = '\0';
1987 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1988 + (unsigned int) dirent, dire->name,
1989 + dire->size + 1, (int) file->f_pos,
1990 + dirh.start_block, dire->offset,
1991 + dirh.inode_number + dire->inode_number,
1992 + squashfs_filetype_table[dire->type]);
1994 + if (filldir(dirent, dire->name, dire->size + 1,
1996 + dirh.inode_number + dire->inode_number,
1997 + squashfs_filetype_table[dire->type])
1999 + TRACE("Filldir returned less than 0\n");
2002 + file->f_pos = length;
2011 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2018 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2019 + struct nameidata *nd)
2021 + const unsigned char *name = dentry->d_name.name;
2022 + int len = dentry->d_name.len;
2023 + struct inode *inode = NULL;
2024 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2025 + struct squashfs_super_block *sblk = &msblk->sblk;
2026 + long long next_block = SQUASHFS_I(i)->start_block +
2027 + sblk->directory_table_start;
2028 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2030 + struct squashfs_dir_header dirh;
2031 + struct squashfs_dir_entry *dire;
2033 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2035 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2036 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2037 + ERROR("Failed to allocate squashfs_dir_entry\n");
2041 + if (len > SQUASHFS_NAME_LEN)
2044 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2045 + SQUASHFS_I(i)->u.s2.directory_index_start,
2046 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2047 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2050 + while (length < i_size_read(i)) {
2051 + /* read directory header */
2052 + if (msblk->swap) {
2053 + struct squashfs_dir_header sdirh;
2054 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2055 + next_block, next_offset, sizeof(sdirh),
2056 + &next_block, &next_offset))
2059 + length += sizeof(sdirh);
2060 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2062 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2063 + next_block, next_offset, sizeof(dirh),
2064 + &next_block, &next_offset))
2067 + length += sizeof(dirh);
2070 + dir_count = dirh.count + 1;
2071 + while (dir_count--) {
2072 + if (msblk->swap) {
2073 + struct squashfs_dir_entry sdire;
2074 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2075 + &sdire, next_block,next_offset,
2076 + sizeof(sdire), &next_block,
2080 + length += sizeof(sdire);
2081 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2083 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2084 + dire, next_block,next_offset,
2085 + sizeof(*dire), &next_block,
2089 + length += sizeof(*dire);
2092 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2093 + next_block, next_offset, dire->size + 1,
2094 + &next_block, &next_offset))
2097 + length += dire->size + 1;
2099 + if (name[0] < dire->name[0])
2102 + if ((len == dire->size + 1) && !strncmp(name,
2103 + dire->name, len)) {
2104 + squashfs_inode_t ino =
2105 + SQUASHFS_MKINODE(dirh.start_block,
2108 + TRACE("calling squashfs_iget for directory "
2109 + "entry %s, inode %x:%x, %d\n", name,
2110 + dirh.start_block, dire->offset,
2111 + dirh.inode_number + dire->inode_number);
2113 + inode = (msblk->iget)(i->i_sb, ino);
2122 + d_add(dentry, inode);
2123 + return ERR_PTR(0);
2126 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2132 +static void squashfs_put_super(struct super_block *s)
2136 + if (s->s_fs_info) {
2137 + struct squashfs_sb_info *sbi = s->s_fs_info;
2138 + if (sbi->block_cache)
2139 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2140 + if (sbi->block_cache[i].block !=
2141 + SQUASHFS_INVALID_BLK)
2142 + kfree(sbi->block_cache[i].data);
2143 + if (sbi->fragment)
2144 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2145 + SQUASHFS_FREE(sbi->fragment[i].data);
2146 + kfree(sbi->fragment);
2147 + kfree(sbi->block_cache);
2148 + kfree(sbi->read_data);
2149 + kfree(sbi->read_page);
2151 + kfree(sbi->fragment_index);
2152 + kfree(sbi->fragment_index_2);
2153 + kfree(sbi->meta_index);
2154 + vfree(sbi->stream.workspace);
2155 + kfree(s->s_fs_info);
2156 + s->s_fs_info = NULL;
2161 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type,
2162 + int flags, const char *dev_name, void *data)
2164 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
2168 +static int __init init_squashfs_fs(void)
2170 + int err = init_inodecache();
2174 + printk(KERN_INFO "squashfs: version 3.1 (2006/08/19) "
2175 + "Phillip Lougher\n");
2177 + if ((err = register_filesystem(&squashfs_fs_type)))
2178 + destroy_inodecache();
2185 +static void __exit exit_squashfs_fs(void)
2187 + unregister_filesystem(&squashfs_fs_type);
2188 + destroy_inodecache();
2192 +static kmem_cache_t * squashfs_inode_cachep;
2195 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2197 + struct squashfs_inode_info *ei;
2198 + ei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
2201 + return &ei->vfs_inode;
2205 +static void squashfs_destroy_inode(struct inode *inode)
2207 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2211 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2213 + struct squashfs_inode_info *ei = foo;
2215 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2216 + SLAB_CTOR_CONSTRUCTOR)
2217 + inode_init_once(&ei->vfs_inode);
2221 +static int __init init_inodecache(void)
2223 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2224 + sizeof(struct squashfs_inode_info),
2225 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2227 + if (squashfs_inode_cachep == NULL)
2233 +static void destroy_inodecache(void)
2235 + if (kmem_cache_destroy(squashfs_inode_cachep))
2236 + printk(KERN_INFO "squashfs_inode_cache: not all structures "
2241 +module_init(init_squashfs_fs);
2242 +module_exit(exit_squashfs_fs);
2243 +MODULE_DESCRIPTION("squashfs 3.1, a compressed read-only filesystem");
2244 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2245 +MODULE_LICENSE("GPL");
2246 diff --new-file -urp linux-2.6.16/fs/squashfs/Makefile linux-2.6.16-squashfs3.1/fs/squashfs/Makefile
2247 --- linux-2.6.16/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2248 +++ linux-2.6.16-squashfs3.1/fs/squashfs/Makefile 2006-08-11 09:32:48.000000000 +0100
2251 +# Makefile for the linux squashfs routines.
2254 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2255 +squashfs-y += inode.o
2256 +squashfs-y += squashfs2_0.o
2257 diff --new-file -urp linux-2.6.16/fs/squashfs/squashfs2_0.c linux-2.6.16-squashfs3.1/fs/squashfs/squashfs2_0.c
2258 --- linux-2.6.16/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2259 +++ linux-2.6.16-squashfs3.1/fs/squashfs/squashfs2_0.c 2006-08-20 01:15:02.000000000 +0100
2262 + * Squashfs - a compressed read only filesystem for Linux
2264 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2265 + * Phillip Lougher <phillip@lougher.org.uk>
2267 + * This program is free software; you can redistribute it and/or
2268 + * modify it under the terms of the GNU General Public License
2269 + * as published by the Free Software Foundation; either version 2,
2270 + * or (at your option) any later version.
2272 + * This program is distributed in the hope that it will be useful,
2273 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2274 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2275 + * GNU General Public License for more details.
2277 + * You should have received a copy of the GNU General Public License
2278 + * along with this program; if not, write to the Free Software
2279 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2284 +#include <linux/types.h>
2285 +#include <linux/squashfs_fs.h>
2286 +#include <linux/module.h>
2287 +#include <linux/errno.h>
2288 +#include <linux/slab.h>
2289 +#include <linux/zlib.h>
2290 +#include <linux/fs.h>
2291 +#include <linux/smp_lock.h>
2292 +#include <linux/slab.h>
2293 +#include <linux/squashfs_fs_sb.h>
2294 +#include <linux/squashfs_fs_i.h>
2295 +#include <linux/buffer_head.h>
2296 +#include <linux/vfs.h>
2297 +#include <linux/init.h>
2298 +#include <linux/dcache.h>
2299 +#include <linux/wait.h>
2300 +#include <linux/zlib.h>
2301 +#include <linux/blkdev.h>
2302 +#include <linux/vmalloc.h>
2303 +#include <asm/uaccess.h>
2304 +#include <asm/semaphore.h>
2306 +#include "squashfs.h"
2307 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2308 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2309 + struct nameidata *);
2311 +static struct file_operations squashfs_dir_ops_2 = {
2312 + .read = generic_read_dir,
2313 + .readdir = squashfs_readdir_2
2316 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2317 + .lookup = squashfs_lookup_2
2320 +static unsigned char squashfs_filetype_table[] = {
2321 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2324 +static int read_fragment_index_table_2(struct super_block *s)
2326 + struct squashfs_sb_info *msblk = s->s_fs_info;
2327 + struct squashfs_super_block *sblk = &msblk->sblk;
2329 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2330 + (sblk->fragments), GFP_KERNEL))) {
2331 + ERROR("Failed to allocate uid/gid table\n");
2335 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2336 + !squashfs_read_data(s, (char *)
2337 + msblk->fragment_index_2,
2338 + sblk->fragment_table_start,
2339 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2340 + (sblk->fragments) |
2341 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2342 + ERROR("unable to read fragment index table\n");
2346 + if (msblk->swap) {
2348 + unsigned int fragment;
2350 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2352 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2353 + &msblk->fragment_index_2[i], 1);
2354 + msblk->fragment_index_2[i] = fragment;
2362 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2363 + long long *fragment_start_block,
2364 + unsigned int *fragment_size)
2366 + struct squashfs_sb_info *msblk = s->s_fs_info;
2367 + long long start_block =
2368 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2369 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2370 + struct squashfs_fragment_entry_2 fragment_entry;
2372 + if (msblk->swap) {
2373 + struct squashfs_fragment_entry_2 sfragment_entry;
2375 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2376 + start_block, offset,
2377 + sizeof(sfragment_entry), &start_block,
2380 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2382 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2383 + start_block, offset,
2384 + sizeof(fragment_entry), &start_block,
2388 + *fragment_start_block = fragment_entry.start_block;
2389 + *fragment_size = fragment_entry.size;
2398 +static struct inode *squashfs_new_inode(struct super_block *s,
2399 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2401 + struct squashfs_sb_info *msblk = s->s_fs_info;
2402 + struct squashfs_super_block *sblk = &msblk->sblk;
2403 + struct inode *i = new_inode(s);
2407 + i->i_mtime.tv_sec = sblk->mkfs_time;
2408 + i->i_atime.tv_sec = sblk->mkfs_time;
2409 + i->i_ctime.tv_sec = sblk->mkfs_time;
2410 + i->i_uid = msblk->uid[inodeb->uid];
2411 + i->i_mode = inodeb->mode;
2414 + if (inodeb->guid == SQUASHFS_GUIDS)
2415 + i->i_gid = i->i_uid;
2417 + i->i_gid = msblk->guid[inodeb->guid];
2424 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2427 + struct squashfs_sb_info *msblk = s->s_fs_info;
2428 + struct squashfs_super_block *sblk = &msblk->sblk;
2429 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2430 + sblk->inode_table_start;
2431 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2432 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2433 + - sblk->inode_table_start, offset);
2434 + long long next_block;
2435 + unsigned int next_offset;
2436 + union squashfs_inode_header_2 id, sid;
2437 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2438 + *sinodeb = &sid.base;
2440 + TRACE("Entered squashfs_iget\n");
2442 + if (msblk->swap) {
2443 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2444 + offset, sizeof(*sinodeb), &next_block,
2447 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2448 + sizeof(*sinodeb));
2450 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2451 + offset, sizeof(*inodeb), &next_block,
2455 + switch(inodeb->inode_type) {
2456 + case SQUASHFS_FILE_TYPE: {
2457 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2458 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2459 + long long frag_blk;
2460 + unsigned int frag_size;
2462 + if (msblk->swap) {
2463 + if (!squashfs_get_cached_block(s, (char *)
2464 + sinodep, block, offset,
2465 + sizeof(*sinodep), &next_block,
2468 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2470 + if (!squashfs_get_cached_block(s, (char *)
2471 + inodep, block, offset,
2472 + sizeof(*inodep), &next_block,
2476 + frag_blk = SQUASHFS_INVALID_BLK;
2477 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2478 + !get_fragment_location_2(s,
2479 + inodep->fragment, &frag_blk, &frag_size))
2482 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2483 + goto failed_read1;
2485 + i->i_size = inodep->file_size;
2486 + i->i_fop = &generic_ro_fops;
2487 + i->i_mode |= S_IFREG;
2488 + i->i_mtime.tv_sec = inodep->mtime;
2489 + i->i_atime.tv_sec = inodep->mtime;
2490 + i->i_ctime.tv_sec = inodep->mtime;
2491 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2492 + i->i_blksize = PAGE_CACHE_SIZE;
2493 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2494 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2495 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2496 + SQUASHFS_I(i)->start_block = inodep->start_block;
2497 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2498 + SQUASHFS_I(i)->offset = next_offset;
2499 + if (sblk->block_size > 4096)
2500 + i->i_data.a_ops = &squashfs_aops;
2502 + i->i_data.a_ops = &squashfs_aops_4K;
2504 + TRACE("File inode %x:%x, start_block %x, "
2505 + "block_list_start %llx, offset %x\n",
2506 + SQUASHFS_INODE_BLK(inode), offset,
2507 + inodep->start_block, next_block,
2511 + case SQUASHFS_DIR_TYPE: {
2512 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2513 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2515 + if (msblk->swap) {
2516 + if (!squashfs_get_cached_block(s, (char *)
2517 + sinodep, block, offset,
2518 + sizeof(*sinodep), &next_block,
2521 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2523 + if (!squashfs_get_cached_block(s, (char *)
2524 + inodep, block, offset,
2525 + sizeof(*inodep), &next_block,
2529 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2530 + goto failed_read1;
2532 + i->i_size = inodep->file_size;
2533 + i->i_op = &squashfs_dir_inode_ops_2;
2534 + i->i_fop = &squashfs_dir_ops_2;
2535 + i->i_mode |= S_IFDIR;
2536 + i->i_mtime.tv_sec = inodep->mtime;
2537 + i->i_atime.tv_sec = inodep->mtime;
2538 + i->i_ctime.tv_sec = inodep->mtime;
2539 + SQUASHFS_I(i)->start_block = inodep->start_block;
2540 + SQUASHFS_I(i)->offset = inodep->offset;
2541 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2542 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2544 + TRACE("Directory inode %x:%x, start_block %x, offset "
2545 + "%x\n", SQUASHFS_INODE_BLK(inode),
2546 + offset, inodep->start_block,
2550 + case SQUASHFS_LDIR_TYPE: {
2551 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2552 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2554 + if (msblk->swap) {
2555 + if (!squashfs_get_cached_block(s, (char *)
2556 + sinodep, block, offset,
2557 + sizeof(*sinodep), &next_block,
2560 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2563 + if (!squashfs_get_cached_block(s, (char *)
2564 + inodep, block, offset,
2565 + sizeof(*inodep), &next_block,
2569 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2570 + goto failed_read1;
2572 + i->i_size = inodep->file_size;
2573 + i->i_op = &squashfs_dir_inode_ops_2;
2574 + i->i_fop = &squashfs_dir_ops_2;
2575 + i->i_mode |= S_IFDIR;
2576 + i->i_mtime.tv_sec = inodep->mtime;
2577 + i->i_atime.tv_sec = inodep->mtime;
2578 + i->i_ctime.tv_sec = inodep->mtime;
2579 + SQUASHFS_I(i)->start_block = inodep->start_block;
2580 + SQUASHFS_I(i)->offset = inodep->offset;
2581 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2582 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2584 + SQUASHFS_I(i)->u.s2.directory_index_count =
2586 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2588 + TRACE("Long directory inode %x:%x, start_block %x, "
2590 + SQUASHFS_INODE_BLK(inode), offset,
2591 + inodep->start_block, inodep->offset);
2594 + case SQUASHFS_SYMLINK_TYPE: {
2595 + struct squashfs_symlink_inode_header_2 *inodep =
2597 + struct squashfs_symlink_inode_header_2 *sinodep =
2600 + if (msblk->swap) {
2601 + if (!squashfs_get_cached_block(s, (char *)
2602 + sinodep, block, offset,
2603 + sizeof(*sinodep), &next_block,
2606 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2609 + if (!squashfs_get_cached_block(s, (char *)
2610 + inodep, block, offset,
2611 + sizeof(*inodep), &next_block,
2615 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2616 + goto failed_read1;
2618 + i->i_size = inodep->symlink_size;
2619 + i->i_op = &page_symlink_inode_operations;
2620 + i->i_data.a_ops = &squashfs_symlink_aops;
2621 + i->i_mode |= S_IFLNK;
2622 + SQUASHFS_I(i)->start_block = next_block;
2623 + SQUASHFS_I(i)->offset = next_offset;
2625 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2627 + SQUASHFS_INODE_BLK(inode), offset,
2628 + next_block, next_offset);
2631 + case SQUASHFS_BLKDEV_TYPE:
2632 + case SQUASHFS_CHRDEV_TYPE: {
2633 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2634 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2636 + if (msblk->swap) {
2637 + if (!squashfs_get_cached_block(s, (char *)
2638 + sinodep, block, offset,
2639 + sizeof(*sinodep), &next_block,
2642 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2644 + if (!squashfs_get_cached_block(s, (char *)
2645 + inodep, block, offset,
2646 + sizeof(*inodep), &next_block,
2650 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2651 + goto failed_read1;
2653 + i->i_mode |= (inodeb->inode_type ==
2654 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2656 + init_special_inode(i, i->i_mode,
2657 + old_decode_dev(inodep->rdev));
2659 + TRACE("Device inode %x:%x, rdev %x\n",
2660 + SQUASHFS_INODE_BLK(inode), offset,
2664 + case SQUASHFS_FIFO_TYPE:
2665 + case SQUASHFS_SOCKET_TYPE: {
2666 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2667 + goto failed_read1;
2669 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2670 + ? S_IFIFO : S_IFSOCK;
2671 + init_special_inode(i, i->i_mode, 0);
2675 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2676 + inodeb->inode_type);
2677 + goto failed_read1;
2680 + insert_inode_hash(i);
2684 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2691 +static int get_dir_index_using_offset(struct super_block *s, long long
2692 + *next_block, unsigned int *next_offset,
2693 + long long index_start,
2694 + unsigned int index_offset, int i_count,
2697 + struct squashfs_sb_info *msblk = s->s_fs_info;
2698 + struct squashfs_super_block *sblk = &msblk->sblk;
2699 + int i, length = 0;
2700 + struct squashfs_dir_index_2 index;
2702 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2703 + i_count, (unsigned int) f_pos);
2708 + for (i = 0; i < i_count; i++) {
2709 + if (msblk->swap) {
2710 + struct squashfs_dir_index_2 sindex;
2711 + squashfs_get_cached_block(s, (char *) &sindex,
2712 + index_start, index_offset,
2713 + sizeof(sindex), &index_start,
2715 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2717 + squashfs_get_cached_block(s, (char *) &index,
2718 + index_start, index_offset,
2719 + sizeof(index), &index_start,
2722 + if (index.index > f_pos)
2725 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2726 + index.size + 1, &index_start,
2729 + length = index.index;
2730 + *next_block = index.start_block + sblk->directory_table_start;
2733 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2740 +static int get_dir_index_using_name(struct super_block *s, long long
2741 + *next_block, unsigned int *next_offset,
2742 + long long index_start,
2743 + unsigned int index_offset, int i_count,
2744 + const char *name, int size)
2746 + struct squashfs_sb_info *msblk = s->s_fs_info;
2747 + struct squashfs_super_block *sblk = &msblk->sblk;
2748 + int i, length = 0;
2749 + struct squashfs_dir_index_2 *index;
2752 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2754 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2755 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2756 + ERROR("Failed to allocate squashfs_dir_index\n");
2760 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2761 + strncpy(str, name, size);
2764 + for (i = 0; i < i_count; i++) {
2765 + if (msblk->swap) {
2766 + struct squashfs_dir_index_2 sindex;
2767 + squashfs_get_cached_block(s, (char *) &sindex,
2768 + index_start, index_offset,
2769 + sizeof(sindex), &index_start,
2771 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2773 + squashfs_get_cached_block(s, (char *) index,
2774 + index_start, index_offset,
2775 + sizeof(struct squashfs_dir_index_2),
2776 + &index_start, &index_offset);
2778 + squashfs_get_cached_block(s, index->name, index_start,
2779 + index_offset, index->size + 1,
2780 + &index_start, &index_offset);
2782 + index->name[index->size + 1] = '\0';
2784 + if (strcmp(index->name, str) > 0)
2787 + length = index->index;
2788 + *next_block = index->start_block + sblk->directory_table_start;
2791 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2798 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2800 + struct inode *i = file->f_dentry->d_inode;
2801 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2802 + struct squashfs_super_block *sblk = &msblk->sblk;
2803 + long long next_block = SQUASHFS_I(i)->start_block +
2804 + sblk->directory_table_start;
2805 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2807 + struct squashfs_dir_header_2 dirh;
2808 + struct squashfs_dir_entry_2 *dire;
2810 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2812 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2813 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2814 + ERROR("Failed to allocate squashfs_dir_entry\n");
2818 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2819 + SQUASHFS_I(i)->u.s2.directory_index_start,
2820 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2821 + SQUASHFS_I(i)->u.s2.directory_index_count,
2824 + while (length < i_size_read(i)) {
2825 + /* read directory header */
2826 + if (msblk->swap) {
2827 + struct squashfs_dir_header_2 sdirh;
2829 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2830 + next_block, next_offset, sizeof(sdirh),
2831 + &next_block, &next_offset))
2834 + length += sizeof(sdirh);
2835 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2837 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2838 + next_block, next_offset, sizeof(dirh),
2839 + &next_block, &next_offset))
2842 + length += sizeof(dirh);
2845 + dir_count = dirh.count + 1;
2846 + while (dir_count--) {
2847 + if (msblk->swap) {
2848 + struct squashfs_dir_entry_2 sdire;
2849 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2850 + &sdire, next_block, next_offset,
2851 + sizeof(sdire), &next_block,
2855 + length += sizeof(sdire);
2856 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2858 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2859 + dire, next_block, next_offset,
2860 + sizeof(*dire), &next_block,
2864 + length += sizeof(*dire);
2867 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2868 + next_block, next_offset,
2869 + dire->size + 1, &next_block,
2873 + length += dire->size + 1;
2875 + if (file->f_pos >= length)
2878 + dire->name[dire->size + 1] = '\0';
2880 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2881 + (unsigned int) dirent, dire->name,
2882 + dire->size + 1, (int) file->f_pos,
2883 + dirh.start_block, dire->offset,
2884 + squashfs_filetype_table[dire->type]);
2886 + if (filldir(dirent, dire->name, dire->size + 1,
2887 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2888 + dirh.start_block, dire->offset),
2889 + squashfs_filetype_table[dire->type])
2891 + TRACE("Filldir returned less than 0\n");
2894 + file->f_pos = length;
2903 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2910 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2911 + struct nameidata *nd)
2913 + const unsigned char *name = dentry->d_name.name;
2914 + int len = dentry->d_name.len;
2915 + struct inode *inode = NULL;
2916 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2917 + struct squashfs_super_block *sblk = &msblk->sblk;
2918 + long long next_block = SQUASHFS_I(i)->start_block +
2919 + sblk->directory_table_start;
2920 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2922 + struct squashfs_dir_header_2 dirh;
2923 + struct squashfs_dir_entry_2 *dire;
2924 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2926 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2928 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2929 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2930 + ERROR("Failed to allocate squashfs_dir_entry\n");
2934 + if (len > SQUASHFS_NAME_LEN)
2937 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2938 + SQUASHFS_I(i)->u.s2.directory_index_start,
2939 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2940 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2943 + while (length < i_size_read(i)) {
2944 + /* read directory header */
2945 + if (msblk->swap) {
2946 + struct squashfs_dir_header_2 sdirh;
2947 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2948 + next_block, next_offset, sizeof(sdirh),
2949 + &next_block, &next_offset))
2952 + length += sizeof(sdirh);
2953 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2955 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2956 + next_block, next_offset, sizeof(dirh),
2957 + &next_block, &next_offset))
2960 + length += sizeof(dirh);
2963 + dir_count = dirh.count + 1;
2964 + while (dir_count--) {
2965 + if (msblk->swap) {
2966 + struct squashfs_dir_entry_2 sdire;
2967 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2968 + &sdire, next_block,next_offset,
2969 + sizeof(sdire), &next_block,
2973 + length += sizeof(sdire);
2974 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2976 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2977 + dire, next_block,next_offset,
2978 + sizeof(*dire), &next_block,
2982 + length += sizeof(*dire);
2985 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2986 + next_block, next_offset, dire->size + 1,
2987 + &next_block, &next_offset))
2990 + length += dire->size + 1;
2992 + if (sorted && name[0] < dire->name[0])
2995 + if ((len == dire->size + 1) && !strncmp(name,
2996 + dire->name, len)) {
2997 + squashfs_inode_t ino =
2998 + SQUASHFS_MKINODE(dirh.start_block,
3001 + TRACE("calling squashfs_iget for directory "
3002 + "entry %s, inode %x:%x, %lld\n", name,
3003 + dirh.start_block, dire->offset, ino);
3005 + inode = (msblk->iget)(i->i_sb, ino);
3014 + d_add(dentry, inode);
3015 + return ERR_PTR(0);
3018 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3024 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3026 + struct squashfs_super_block *sblk = &msblk->sblk;
3028 + msblk->iget = squashfs_iget_2;
3029 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3031 + sblk->bytes_used = sblk->bytes_used_2;
3032 + sblk->uid_start = sblk->uid_start_2;
3033 + sblk->guid_start = sblk->guid_start_2;
3034 + sblk->inode_table_start = sblk->inode_table_start_2;
3035 + sblk->directory_table_start = sblk->directory_table_start_2;
3036 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3040 diff --new-file -urp linux-2.6.16/fs/squashfs/squashfs.h linux-2.6.16-squashfs3.1/fs/squashfs/squashfs.h
3041 --- linux-2.6.16/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3042 +++ linux-2.6.16-squashfs3.1/fs/squashfs/squashfs.h 2006-08-11 09:32:48.000000000 +0100
3045 + * Squashfs - a compressed read only filesystem for Linux
3047 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3048 + * Phillip Lougher <phillip@lougher.org.uk>
3050 + * This program is free software; you can redistribute it and/or
3051 + * modify it under the terms of the GNU General Public License
3052 + * as published by the Free Software Foundation; either version 2,
3053 + * or (at your option) any later version.
3055 + * This program is distributed in the hope that it will be useful,
3056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3058 + * GNU General Public License for more details.
3060 + * You should have received a copy of the GNU General Public License
3061 + * along with this program; if not, write to the Free Software
3062 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3067 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3068 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3071 +#ifdef SQUASHFS_TRACE
3072 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3074 +#define TRACE(s, args...) {}
3077 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3079 +#define SERROR(s, args...) do { \
3081 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3084 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3086 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3088 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3091 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3092 +#define SQSH_EXTERN
3093 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3094 + long long index, unsigned int length,
3095 + long long *next_index);
3096 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3097 + long long block, unsigned int offset,
3098 + int length, long long *next_block,
3099 + unsigned int *next_offset);
3100 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3101 + squashfs_fragment_cache *fragment);
3102 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3103 + *s, long long start_block,
3105 +extern struct address_space_operations squashfs_symlink_aops;
3106 +extern struct address_space_operations squashfs_aops;
3107 +extern struct address_space_operations squashfs_aops_4K;
3108 +extern struct inode_operations squashfs_dir_inode_ops;
3110 +#define SQSH_EXTERN static
3113 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3114 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3116 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3122 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3123 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3125 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3130 diff --new-file -urp linux-2.6.16/include/linux/squashfs_fs.h linux-2.6.16-squashfs3.1/include/linux/squashfs_fs.h
3131 --- linux-2.6.16/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3132 +++ linux-2.6.16-squashfs3.1/include/linux/squashfs_fs.h 2006-08-11 09:32:48.000000000 +0100
3134 +#ifndef SQUASHFS_FS
3135 +#define SQUASHFS_FS
3140 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3141 + * Phillip Lougher <phillip@lougher.org.uk>
3143 + * This program is free software; you can redistribute it and/or
3144 + * modify it under the terms of the GNU General Public License
3145 + * as published by the Free Software Foundation; either version 2,
3146 + * or (at your option) any later version.
3148 + * This program is distributed in the hope that it will be useful,
3149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3151 + * GNU General Public License for more details.
3153 + * You should have received a copy of the GNU General Public License
3154 + * along with this program; if not, write to the Free Software
3155 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3160 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3161 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3164 +#ifdef CONFIG_SQUASHFS_VMALLOC
3165 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3166 +#define SQUASHFS_FREE(a) vfree(a)
3168 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3169 +#define SQUASHFS_FREE(a) kfree(a)
3171 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3172 +#define SQUASHFS_MAJOR 3
3173 +#define SQUASHFS_MINOR 0
3174 +#define SQUASHFS_MAGIC 0x73717368
3175 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3176 +#define SQUASHFS_START 0
3178 +/* size of metadata (inode and directory) blocks */
3179 +#define SQUASHFS_METADATA_SIZE 8192
3180 +#define SQUASHFS_METADATA_LOG 13
3182 +/* default size of data blocks */
3183 +#define SQUASHFS_FILE_SIZE 65536
3184 +#define SQUASHFS_FILE_LOG 16
3186 +#define SQUASHFS_FILE_MAX_SIZE 65536
3188 +/* Max number of uids and gids */
3189 +#define SQUASHFS_UIDS 256
3190 +#define SQUASHFS_GUIDS 255
3192 +/* Max length of filename (not 255) */
3193 +#define SQUASHFS_NAME_LEN 256
3195 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3196 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3197 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3198 +#define SQUASHFS_USED_BLK ((long long) -2)
3200 +/* Filesystem flags */
3201 +#define SQUASHFS_NOI 0
3202 +#define SQUASHFS_NOD 1
3203 +#define SQUASHFS_CHECK 2
3204 +#define SQUASHFS_NOF 3
3205 +#define SQUASHFS_NO_FRAG 4
3206 +#define SQUASHFS_ALWAYS_FRAG 5
3207 +#define SQUASHFS_DUPLICATE 6
3209 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3211 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3214 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3217 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3220 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3223 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3224 + SQUASHFS_ALWAYS_FRAG)
3226 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3227 + SQUASHFS_DUPLICATE)
3229 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3232 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3233 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3234 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3235 + (duplicate_checking << 6))
3237 +/* Max number of types and file types */
3238 +#define SQUASHFS_DIR_TYPE 1
3239 +#define SQUASHFS_FILE_TYPE 2
3240 +#define SQUASHFS_SYMLINK_TYPE 3
3241 +#define SQUASHFS_BLKDEV_TYPE 4
3242 +#define SQUASHFS_CHRDEV_TYPE 5
3243 +#define SQUASHFS_FIFO_TYPE 6
3244 +#define SQUASHFS_SOCKET_TYPE 7
3245 +#define SQUASHFS_LDIR_TYPE 8
3246 +#define SQUASHFS_LREG_TYPE 9
3248 +/* 1.0 filesystem type definitions */
3249 +#define SQUASHFS_TYPES 5
3250 +#define SQUASHFS_IPC_TYPE 0
3252 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3254 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3256 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3257 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3259 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3261 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3263 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3264 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3265 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3267 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3270 + * Inode number ops. Inodes consist of a compressed block number, and an
3271 + * uncompressed offset within that block
3273 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3275 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3277 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3280 +/* Compute 32 bit VFS inode number from squashfs inode number */
3281 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3285 +/* Translate between VFS mode and squashfs mode */
3286 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3288 +/* fragment and fragment table defines */
3289 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3291 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3292 + SQUASHFS_METADATA_SIZE)
3294 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3295 + SQUASHFS_METADATA_SIZE)
3297 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3298 + SQUASHFS_METADATA_SIZE - 1) / \
3299 + SQUASHFS_METADATA_SIZE)
3301 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3302 + sizeof(long long))
3304 +/* cached data constants for filesystem */
3305 +#define SQUASHFS_CACHED_BLKS 8
3307 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3309 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3310 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3312 +#define SQUASHFS_MARKER_BYTE 0xff
3314 +/* meta index cache */
3315 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3316 +#define SQUASHFS_META_ENTRIES 31
3317 +#define SQUASHFS_META_NUMBER 8
3318 +#define SQUASHFS_SLOTS 4
3320 +struct meta_entry {
3321 + long long data_block;
3322 + unsigned int index_block;
3323 + unsigned short offset;
3324 + unsigned short pad;
3327 +struct meta_index {
3328 + unsigned int inode_number;
3329 + unsigned int offset;
3330 + unsigned short entries;
3331 + unsigned short skip;
3332 + unsigned short locked;
3333 + unsigned short pad;
3334 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3339 + * definitions for structures on disk
3342 +typedef long long squashfs_block_t;
3343 +typedef long long squashfs_inode_t;
3345 +struct squashfs_super_block {
3346 + unsigned int s_magic;
3347 + unsigned int inodes;
3348 + unsigned int bytes_used_2;
3349 + unsigned int uid_start_2;
3350 + unsigned int guid_start_2;
3351 + unsigned int inode_table_start_2;
3352 + unsigned int directory_table_start_2;
3353 + unsigned int s_major:16;
3354 + unsigned int s_minor:16;
3355 + unsigned int block_size_1:16;
3356 + unsigned int block_log:16;
3357 + unsigned int flags:8;
3358 + unsigned int no_uids:8;
3359 + unsigned int no_guids:8;
3360 + unsigned int mkfs_time /* time of filesystem creation */;
3361 + squashfs_inode_t root_inode;
3362 + unsigned int block_size;
3363 + unsigned int fragments;
3364 + unsigned int fragment_table_start_2;
3365 + long long bytes_used;
3366 + long long uid_start;
3367 + long long guid_start;
3368 + long long inode_table_start;
3369 + long long directory_table_start;
3370 + long long fragment_table_start;
3372 +} __attribute__ ((packed));
3374 +struct squashfs_dir_index {
3375 + unsigned int index;
3376 + unsigned int start_block;
3377 + unsigned char size;
3378 + unsigned char name[0];
3379 +} __attribute__ ((packed));
3381 +#define SQUASHFS_BASE_INODE_HEADER \
3382 + unsigned int inode_type:4; \
3383 + unsigned int mode:12; \
3384 + unsigned int uid:8; \
3385 + unsigned int guid:8; \
3386 + unsigned int mtime; \
3387 + unsigned int inode_number;
3389 +struct squashfs_base_inode_header {
3390 + SQUASHFS_BASE_INODE_HEADER;
3391 +} __attribute__ ((packed));
3393 +struct squashfs_ipc_inode_header {
3394 + SQUASHFS_BASE_INODE_HEADER;
3395 + unsigned int nlink;
3396 +} __attribute__ ((packed));
3398 +struct squashfs_dev_inode_header {
3399 + SQUASHFS_BASE_INODE_HEADER;
3400 + unsigned int nlink;
3401 + unsigned short rdev;
3402 +} __attribute__ ((packed));
3404 +struct squashfs_symlink_inode_header {
3405 + SQUASHFS_BASE_INODE_HEADER;
3406 + unsigned int nlink;
3407 + unsigned short symlink_size;
3409 +} __attribute__ ((packed));
3411 +struct squashfs_reg_inode_header {
3412 + SQUASHFS_BASE_INODE_HEADER;
3413 + squashfs_block_t start_block;
3414 + unsigned int fragment;
3415 + unsigned int offset;
3416 + unsigned int file_size;
3417 + unsigned short block_list[0];
3418 +} __attribute__ ((packed));
3420 +struct squashfs_lreg_inode_header {
3421 + SQUASHFS_BASE_INODE_HEADER;
3422 + unsigned int nlink;
3423 + squashfs_block_t start_block;
3424 + unsigned int fragment;
3425 + unsigned int offset;
3426 + long long file_size;
3427 + unsigned short block_list[0];
3428 +} __attribute__ ((packed));
3430 +struct squashfs_dir_inode_header {
3431 + SQUASHFS_BASE_INODE_HEADER;
3432 + unsigned int nlink;
3433 + unsigned int file_size:19;
3434 + unsigned int offset:13;
3435 + unsigned int start_block;
3436 + unsigned int parent_inode;
3437 +} __attribute__ ((packed));
3439 +struct squashfs_ldir_inode_header {
3440 + SQUASHFS_BASE_INODE_HEADER;
3441 + unsigned int nlink;
3442 + unsigned int file_size:27;
3443 + unsigned int offset:13;
3444 + unsigned int start_block;
3445 + unsigned int i_count:16;
3446 + unsigned int parent_inode;
3447 + struct squashfs_dir_index index[0];
3448 +} __attribute__ ((packed));
3450 +union squashfs_inode_header {
3451 + struct squashfs_base_inode_header base;
3452 + struct squashfs_dev_inode_header dev;
3453 + struct squashfs_symlink_inode_header symlink;
3454 + struct squashfs_reg_inode_header reg;
3455 + struct squashfs_lreg_inode_header lreg;
3456 + struct squashfs_dir_inode_header dir;
3457 + struct squashfs_ldir_inode_header ldir;
3458 + struct squashfs_ipc_inode_header ipc;
3461 +struct squashfs_dir_entry {
3462 + unsigned int offset:13;
3463 + unsigned int type:3;
3464 + unsigned int size:8;
3465 + int inode_number:16;
3467 +} __attribute__ ((packed));
3469 +struct squashfs_dir_header {
3470 + unsigned int count:8;
3471 + unsigned int start_block;
3472 + unsigned int inode_number;
3473 +} __attribute__ ((packed));
3475 +struct squashfs_fragment_entry {
3476 + long long start_block;
3477 + unsigned int size;
3478 + unsigned int unused;
3479 +} __attribute__ ((packed));
3481 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3482 +extern int squashfs_uncompress_init(void);
3483 +extern int squashfs_uncompress_exit(void);
3486 + * macros to convert each packed bitfield structure from little endian to big
3487 + * endian and vice versa. These are needed when creating or using a filesystem
3488 + * on a machine with different byte ordering to the target architecture.
3492 +#define SQUASHFS_SWAP_START \
3495 + unsigned long long val;\
3496 + unsigned char *s;\
3499 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3500 + SQUASHFS_SWAP_START\
3501 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3502 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3503 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3504 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3505 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3506 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3507 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3508 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3509 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3510 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3511 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3512 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3513 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3514 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3515 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3516 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3517 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3518 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3519 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3520 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3521 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3522 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3523 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3524 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3525 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3526 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3527 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3530 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3531 + SQUASHFS_MEMSET(s, d, n);\
3532 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3533 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3534 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3535 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3536 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3537 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3539 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3540 + SQUASHFS_SWAP_START\
3541 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3544 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3545 + SQUASHFS_SWAP_START\
3546 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3547 + sizeof(struct squashfs_ipc_inode_header))\
3548 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3551 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3552 + SQUASHFS_SWAP_START\
3553 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3554 + sizeof(struct squashfs_dev_inode_header)); \
3555 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3556 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3559 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3560 + SQUASHFS_SWAP_START\
3561 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3562 + sizeof(struct squashfs_symlink_inode_header));\
3563 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3564 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3567 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3568 + SQUASHFS_SWAP_START\
3569 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3570 + sizeof(struct squashfs_reg_inode_header));\
3571 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3572 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3573 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3574 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3577 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3578 + SQUASHFS_SWAP_START\
3579 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3580 + sizeof(struct squashfs_lreg_inode_header));\
3581 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3582 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3583 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3584 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3585 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3588 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3589 + SQUASHFS_SWAP_START\
3590 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3591 + sizeof(struct squashfs_dir_inode_header));\
3592 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3593 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3594 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3595 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3596 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3599 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3600 + SQUASHFS_SWAP_START\
3601 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3602 + sizeof(struct squashfs_ldir_inode_header));\
3603 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3604 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3605 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3606 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3607 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3608 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3611 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3612 + SQUASHFS_SWAP_START\
3613 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3614 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3615 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3616 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3619 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3620 + SQUASHFS_SWAP_START\
3621 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3622 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3623 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3624 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3627 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3628 + SQUASHFS_SWAP_START\
3629 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3630 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3631 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3632 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3633 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3636 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3637 + SQUASHFS_SWAP_START\
3638 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3639 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3640 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3643 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3645 + int bit_position;\
3646 + SQUASHFS_SWAP_START\
3647 + SQUASHFS_MEMSET(s, d, n * 2);\
3648 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3650 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3653 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3655 + int bit_position;\
3656 + SQUASHFS_SWAP_START\
3657 + SQUASHFS_MEMSET(s, d, n * 4);\
3658 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3660 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3663 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3665 + int bit_position;\
3666 + SQUASHFS_SWAP_START\
3667 + SQUASHFS_MEMSET(s, d, n * 8);\
3668 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3670 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3673 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3675 + int bit_position;\
3676 + SQUASHFS_SWAP_START\
3677 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3678 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3680 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3683 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3685 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3687 +struct squashfs_base_inode_header_1 {
3688 + unsigned int inode_type:4;
3689 + unsigned int mode:12; /* protection */
3690 + unsigned int uid:4; /* index into uid table */
3691 + unsigned int guid:4; /* index into guid table */
3692 +} __attribute__ ((packed));
3694 +struct squashfs_ipc_inode_header_1 {
3695 + unsigned int inode_type:4;
3696 + unsigned int mode:12; /* protection */
3697 + unsigned int uid:4; /* index into uid table */
3698 + unsigned int guid:4; /* index into guid table */
3699 + unsigned int type:4;
3700 + unsigned int offset:4;
3701 +} __attribute__ ((packed));
3703 +struct squashfs_dev_inode_header_1 {
3704 + unsigned int inode_type:4;
3705 + unsigned int mode:12; /* protection */
3706 + unsigned int uid:4; /* index into uid table */
3707 + unsigned int guid:4; /* index into guid table */
3708 + unsigned short rdev;
3709 +} __attribute__ ((packed));
3711 +struct squashfs_symlink_inode_header_1 {
3712 + unsigned int inode_type:4;
3713 + unsigned int mode:12; /* protection */
3714 + unsigned int uid:4; /* index into uid table */
3715 + unsigned int guid:4; /* index into guid table */
3716 + unsigned short symlink_size;
3718 +} __attribute__ ((packed));
3720 +struct squashfs_reg_inode_header_1 {
3721 + unsigned int inode_type:4;
3722 + unsigned int mode:12; /* protection */
3723 + unsigned int uid:4; /* index into uid table */
3724 + unsigned int guid:4; /* index into guid table */
3725 + unsigned int mtime;
3726 + unsigned int start_block;
3727 + unsigned int file_size:32;
3728 + unsigned short block_list[0];
3729 +} __attribute__ ((packed));
3731 +struct squashfs_dir_inode_header_1 {
3732 + unsigned int inode_type:4;
3733 + unsigned int mode:12; /* protection */
3734 + unsigned int uid:4; /* index into uid table */
3735 + unsigned int guid:4; /* index into guid table */
3736 + unsigned int file_size:19;
3737 + unsigned int offset:13;
3738 + unsigned int mtime;
3739 + unsigned int start_block:24;
3740 +} __attribute__ ((packed));
3742 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3743 + SQUASHFS_MEMSET(s, d, n);\
3744 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3745 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3746 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3747 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3749 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3750 + SQUASHFS_SWAP_START\
3751 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3754 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3755 + SQUASHFS_SWAP_START\
3756 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3757 + sizeof(struct squashfs_ipc_inode_header_1));\
3758 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3759 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3762 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3763 + SQUASHFS_SWAP_START\
3764 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3765 + sizeof(struct squashfs_dev_inode_header_1));\
3766 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3769 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3770 + SQUASHFS_SWAP_START\
3771 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3772 + sizeof(struct squashfs_symlink_inode_header_1));\
3773 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3776 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3777 + SQUASHFS_SWAP_START\
3778 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3779 + sizeof(struct squashfs_reg_inode_header_1));\
3780 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3781 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3782 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3785 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3786 + SQUASHFS_SWAP_START\
3787 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3788 + sizeof(struct squashfs_dir_inode_header_1));\
3789 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3790 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3791 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3792 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3797 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3799 +struct squashfs_dir_index_2 {
3800 + unsigned int index:27;
3801 + unsigned int start_block:29;
3802 + unsigned char size;
3803 + unsigned char name[0];
3804 +} __attribute__ ((packed));
3806 +struct squashfs_base_inode_header_2 {
3807 + unsigned int inode_type:4;
3808 + unsigned int mode:12; /* protection */
3809 + unsigned int uid:8; /* index into uid table */
3810 + unsigned int guid:8; /* index into guid table */
3811 +} __attribute__ ((packed));
3813 +struct squashfs_ipc_inode_header_2 {
3814 + unsigned int inode_type:4;
3815 + unsigned int mode:12; /* protection */
3816 + unsigned int uid:8; /* index into uid table */
3817 + unsigned int guid:8; /* index into guid table */
3818 +} __attribute__ ((packed));
3820 +struct squashfs_dev_inode_header_2 {
3821 + unsigned int inode_type:4;
3822 + unsigned int mode:12; /* protection */
3823 + unsigned int uid:8; /* index into uid table */
3824 + unsigned int guid:8; /* index into guid table */
3825 + unsigned short rdev;
3826 +} __attribute__ ((packed));
3828 +struct squashfs_symlink_inode_header_2 {
3829 + unsigned int inode_type:4;
3830 + unsigned int mode:12; /* protection */
3831 + unsigned int uid:8; /* index into uid table */
3832 + unsigned int guid:8; /* index into guid table */
3833 + unsigned short symlink_size;
3835 +} __attribute__ ((packed));
3837 +struct squashfs_reg_inode_header_2 {
3838 + unsigned int inode_type:4;
3839 + unsigned int mode:12; /* protection */
3840 + unsigned int uid:8; /* index into uid table */
3841 + unsigned int guid:8; /* index into guid table */
3842 + unsigned int mtime;
3843 + unsigned int start_block;
3844 + unsigned int fragment;
3845 + unsigned int offset;
3846 + unsigned int file_size:32;
3847 + unsigned short block_list[0];
3848 +} __attribute__ ((packed));
3850 +struct squashfs_dir_inode_header_2 {
3851 + unsigned int inode_type:4;
3852 + unsigned int mode:12; /* protection */
3853 + unsigned int uid:8; /* index into uid table */
3854 + unsigned int guid:8; /* index into guid table */
3855 + unsigned int file_size:19;
3856 + unsigned int offset:13;
3857 + unsigned int mtime;
3858 + unsigned int start_block:24;
3859 +} __attribute__ ((packed));
3861 +struct squashfs_ldir_inode_header_2 {
3862 + unsigned int inode_type:4;
3863 + unsigned int mode:12; /* protection */
3864 + unsigned int uid:8; /* index into uid table */
3865 + unsigned int guid:8; /* index into guid table */
3866 + unsigned int file_size:27;
3867 + unsigned int offset:13;
3868 + unsigned int mtime;
3869 + unsigned int start_block:24;
3870 + unsigned int i_count:16;
3871 + struct squashfs_dir_index_2 index[0];
3872 +} __attribute__ ((packed));
3874 +union squashfs_inode_header_2 {
3875 + struct squashfs_base_inode_header_2 base;
3876 + struct squashfs_dev_inode_header_2 dev;
3877 + struct squashfs_symlink_inode_header_2 symlink;
3878 + struct squashfs_reg_inode_header_2 reg;
3879 + struct squashfs_dir_inode_header_2 dir;
3880 + struct squashfs_ldir_inode_header_2 ldir;
3881 + struct squashfs_ipc_inode_header_2 ipc;
3884 +struct squashfs_dir_header_2 {
3885 + unsigned int count:8;
3886 + unsigned int start_block:24;
3887 +} __attribute__ ((packed));
3889 +struct squashfs_dir_entry_2 {
3890 + unsigned int offset:13;
3891 + unsigned int type:3;
3892 + unsigned int size:8;
3894 +} __attribute__ ((packed));
3896 +struct squashfs_fragment_entry_2 {
3897 + unsigned int start_block;
3898 + unsigned int size;
3899 +} __attribute__ ((packed));
3901 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3902 + SQUASHFS_MEMSET(s, d, n);\
3903 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3904 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3905 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3906 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3908 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3909 + SQUASHFS_SWAP_START\
3910 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3913 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3914 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3916 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3917 + SQUASHFS_SWAP_START\
3918 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3919 + sizeof(struct squashfs_dev_inode_header_2)); \
3920 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3923 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3924 + SQUASHFS_SWAP_START\
3925 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3926 + sizeof(struct squashfs_symlink_inode_header_2));\
3927 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3930 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3931 + SQUASHFS_SWAP_START\
3932 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3933 + sizeof(struct squashfs_reg_inode_header_2));\
3934 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3935 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3936 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3937 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3938 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3941 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3942 + SQUASHFS_SWAP_START\
3943 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3944 + sizeof(struct squashfs_dir_inode_header_2));\
3945 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3946 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3947 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3948 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3951 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3952 + SQUASHFS_SWAP_START\
3953 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3954 + sizeof(struct squashfs_ldir_inode_header_2));\
3955 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3956 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3957 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3958 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3959 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3962 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3963 + SQUASHFS_SWAP_START\
3964 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3965 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3966 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3967 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3969 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3970 + SQUASHFS_SWAP_START\
3971 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3972 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3973 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3976 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3977 + SQUASHFS_SWAP_START\
3978 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3979 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3980 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3981 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3984 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3985 + SQUASHFS_SWAP_START\
3986 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3987 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3988 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3991 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3993 +/* fragment and fragment table defines */
3994 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3996 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3997 + SQUASHFS_METADATA_SIZE)
3999 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4000 + SQUASHFS_METADATA_SIZE)
4002 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4003 + SQUASHFS_METADATA_SIZE - 1) / \
4004 + SQUASHFS_METADATA_SIZE)
4006 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4014 + * macros used to swap each structure entry, taking into account
4015 + * bitfields and different bitfield placing conventions on differing
4019 +#include <asm/byteorder.h>
4021 +#ifdef __BIG_ENDIAN
4022 + /* convert from little endian to big endian */
4023 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4026 + /* convert from big endian to little endian */
4027 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4028 + tbits, 64 - tbits - b_pos)
4031 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4034 + s = (unsigned char *)p + (pos / 8);\
4035 + d = ((unsigned char *) &val) + 7;\
4036 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4038 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4041 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4045 diff --new-file -urp linux-2.6.16/include/linux/squashfs_fs_i.h linux-2.6.16-squashfs3.1/include/linux/squashfs_fs_i.h
4046 --- linux-2.6.16/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4047 +++ linux-2.6.16-squashfs3.1/include/linux/squashfs_fs_i.h 2006-08-11 09:32:48.000000000 +0100
4049 +#ifndef SQUASHFS_FS_I
4050 +#define SQUASHFS_FS_I
4054 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4055 + * Phillip Lougher <phillip@lougher.org.uk>
4057 + * This program is free software; you can redistribute it and/or
4058 + * modify it under the terms of the GNU General Public License
4059 + * as published by the Free Software Foundation; either version 2,
4060 + * or (at your option) any later version.
4062 + * This program is distributed in the hope that it will be useful,
4063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4065 + * GNU General Public License for more details.
4067 + * You should have received a copy of the GNU General Public License
4068 + * along with this program; if not, write to the Free Software
4069 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4074 +struct squashfs_inode_info {
4075 + long long start_block;
4076 + unsigned int offset;
4079 + long long fragment_start_block;
4080 + unsigned int fragment_size;
4081 + unsigned int fragment_offset;
4082 + long long block_list_start;
4085 + long long directory_index_start;
4086 + unsigned int directory_index_offset;
4087 + unsigned int directory_index_count;
4088 + unsigned int parent_inode;
4091 + struct inode vfs_inode;
4094 diff --new-file -urp linux-2.6.16/include/linux/squashfs_fs_sb.h linux-2.6.16-squashfs3.1/include/linux/squashfs_fs_sb.h
4095 --- linux-2.6.16/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4096 +++ linux-2.6.16-squashfs3.1/include/linux/squashfs_fs_sb.h 2006-08-20 01:15:02.000000000 +0100
4098 +#ifndef SQUASHFS_FS_SB
4099 +#define SQUASHFS_FS_SB
4103 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4104 + * Phillip Lougher <phillip@lougher.org.uk>
4106 + * This program is free software; you can redistribute it and/or
4107 + * modify it under the terms of the GNU General Public License
4108 + * as published by the Free Software Foundation; either version 2,
4109 + * or (at your option) any later version.
4111 + * This program is distributed in the hope that it will be useful,
4112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4114 + * GNU General Public License for more details.
4116 + * You should have received a copy of the GNU General Public License
4117 + * along with this program; if not, write to the Free Software
4118 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4120 + * squashfs_fs_sb.h
4123 +#include <linux/squashfs_fs.h>
4125 +struct squashfs_cache {
4128 + long long next_index;
4132 +struct squashfs_fragment_cache {
4135 + unsigned int locked;
4139 +struct squashfs_sb_info {
4140 + struct squashfs_super_block sblk;
4142 + int devblksize_log2;
4144 + struct squashfs_cache *block_cache;
4145 + struct squashfs_fragment_cache *fragment;
4147 + int next_fragment;
4148 + int next_meta_index;
4149 + unsigned int *uid;
4150 + unsigned int *guid;
4151 + long long *fragment_index;
4152 + unsigned int *fragment_index_2;
4153 + unsigned int read_size;
4156 + struct semaphore read_data_mutex;
4157 + struct semaphore read_page_mutex;
4158 + struct semaphore block_cache_mutex;
4159 + struct semaphore fragment_mutex;
4160 + struct semaphore meta_index_mutex;
4161 + wait_queue_head_t waitq;
4162 + wait_queue_head_t fragment_wait_queue;
4163 + struct meta_index *meta_index;
4165 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t
4167 + long long (*read_blocklist)(struct inode *inode, int
4168 + index, int readahead_blks, char *block_list,
4169 + unsigned short **block_p, unsigned int *bsize);
4170 + int (*read_fragment_index_table)(struct super_block *s);
4173 diff --new-file -urp linux-2.6.16/init/do_mounts_rd.c linux-2.6.16-squashfs3.1/init/do_mounts_rd.c
4174 --- linux-2.6.16/init/do_mounts_rd.c 2006-03-20 05:53:29.000000000 +0000
4175 +++ linux-2.6.16-squashfs3.1/init/do_mounts_rd.c 2006-08-20 01:15:02.000000000 +0100
4177 #include <linux/ext2_fs.h>
4178 #include <linux/romfs_fs.h>
4179 #include <linux/cramfs_fs.h>
4180 +#include <linux/squashfs_fs.h>
4181 #include <linux/initrd.h>
4182 #include <linux/string.h>
4184 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4185 * numbers could not be found.
4187 * We currently check for the following magic numbers:
4192 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4193 struct ext2_super_block *ext2sb;
4194 struct romfs_super_block *romfsb;
4195 struct cramfs_super *cramfsb;
4196 + struct squashfs_super_block *squashfsb;
4200 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4201 ext2sb = (struct ext2_super_block *) buf;
4202 romfsb = (struct romfs_super_block *) buf;
4203 cramfsb = (struct cramfs_super *) buf;
4204 + squashfsb = (struct squashfs_super_block *) buf;
4205 memset(buf, 0xe5, size);
4208 @@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4212 + /* squashfs is at block zero too */
4213 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4214 + printk(KERN_NOTICE
4215 + "RAMDISK: squashfs filesystem found at block %d\n",
4217 + if (squashfsb->s_major < 3)
4218 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4220 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4225 * Read block 1 to test for minix and ext2 superblock