1 diff --new-file -urp linux-2.6.18/fs/Kconfig linux-2.6.18-squashfs3.1/fs/Kconfig
2 --- linux-2.6.18/fs/Kconfig 2006-08-11 00:03:11.000000000 +0100
3 +++ linux-2.6.18-squashfs3.1/fs/Kconfig 2006-08-21 00:13:12.000000000 +0100
4 @@ -1249,6 +1249,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.18/fs/Makefile linux-2.6.18-squashfs3.1/fs/Makefile
77 --- linux-2.6.18/fs/Makefile 2006-08-11 00:03:12.000000000 +0100
78 +++ linux-2.6.18-squashfs3.1/fs/Makefile 2006-08-21 00:13:12.000000000 +0100
79 @@ -57,6 +57,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.18/fs/squashfs/inode.c linux-2.6.18-squashfs3.1/fs/squashfs/inode.c
88 --- linux-2.6.18/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.18-squashfs3.1/fs/squashfs/inode.c 2006-08-21 00:15:29.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 dentry *, 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 int squashfs_get_sb(struct file_system_type *, int, const char *, void *,
154 + struct vfsmount *);
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 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
698 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
699 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
700 + SQUASHFS_I(i)->start_block = inodep->start_block;
701 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
702 + SQUASHFS_I(i)->offset = next_offset;
703 + if (sblk->block_size > 4096)
704 + i->i_data.a_ops = &squashfs_aops;
706 + i->i_data.a_ops = &squashfs_aops_4K;
708 + TRACE("File inode %x:%x, start_block %llx, "
709 + "block_list_start %llx, offset %x\n",
710 + SQUASHFS_INODE_BLK(inode), offset,
711 + inodep->start_block, next_block,
715 + case SQUASHFS_LREG_TYPE: {
716 + unsigned int frag_size;
717 + long long frag_blk;
718 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
719 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
722 + if (!squashfs_get_cached_block(s, (char *)
723 + sinodep, block, offset,
724 + sizeof(*sinodep), &next_block,
727 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
729 + if (!squashfs_get_cached_block(s, (char *)
730 + inodep, block, offset,
731 + sizeof(*inodep), &next_block,
735 + frag_blk = SQUASHFS_INVALID_BLK;
736 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
737 + !get_fragment_location(s,
738 + inodep->fragment, &frag_blk, &frag_size))
741 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
744 + i->i_nlink = inodep->nlink;
745 + i->i_size = inodep->file_size;
746 + i->i_fop = &generic_ro_fops;
747 + i->i_mode |= S_IFREG;
748 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
749 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
750 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
751 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
752 + SQUASHFS_I(i)->start_block = inodep->start_block;
753 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
754 + SQUASHFS_I(i)->offset = next_offset;
755 + if (sblk->block_size > 4096)
756 + i->i_data.a_ops = &squashfs_aops;
758 + i->i_data.a_ops = &squashfs_aops_4K;
760 + TRACE("File inode %x:%x, start_block %llx, "
761 + "block_list_start %llx, offset %x\n",
762 + SQUASHFS_INODE_BLK(inode), offset,
763 + inodep->start_block, next_block,
767 + case SQUASHFS_DIR_TYPE: {
768 + struct squashfs_dir_inode_header *inodep = &id.dir;
769 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
772 + if (!squashfs_get_cached_block(s, (char *)
773 + sinodep, block, offset,
774 + sizeof(*sinodep), &next_block,
777 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
779 + if (!squashfs_get_cached_block(s, (char *)
780 + inodep, block, offset,
781 + sizeof(*inodep), &next_block,
785 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
788 + i->i_nlink = inodep->nlink;
789 + i->i_size = inodep->file_size;
790 + i->i_op = &squashfs_dir_inode_ops;
791 + i->i_fop = &squashfs_dir_ops;
792 + i->i_mode |= S_IFDIR;
793 + SQUASHFS_I(i)->start_block = inodep->start_block;
794 + SQUASHFS_I(i)->offset = inodep->offset;
795 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
796 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
798 + TRACE("Directory inode %x:%x, start_block %x, offset "
799 + "%x\n", SQUASHFS_INODE_BLK(inode),
800 + offset, inodep->start_block,
804 + case SQUASHFS_LDIR_TYPE: {
805 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
806 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
809 + if (!squashfs_get_cached_block(s, (char *)
810 + sinodep, block, offset,
811 + sizeof(*sinodep), &next_block,
814 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
817 + if (!squashfs_get_cached_block(s, (char *)
818 + inodep, block, offset,
819 + sizeof(*inodep), &next_block,
823 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
826 + i->i_nlink = inodep->nlink;
827 + i->i_size = inodep->file_size;
828 + i->i_op = &squashfs_dir_inode_ops;
829 + i->i_fop = &squashfs_dir_ops;
830 + i->i_mode |= S_IFDIR;
831 + SQUASHFS_I(i)->start_block = inodep->start_block;
832 + SQUASHFS_I(i)->offset = inodep->offset;
833 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
834 + SQUASHFS_I(i)->u.s2.directory_index_offset =
836 + SQUASHFS_I(i)->u.s2.directory_index_count =
838 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
840 + TRACE("Long directory inode %x:%x, start_block %x, "
842 + SQUASHFS_INODE_BLK(inode), offset,
843 + inodep->start_block, inodep->offset);
846 + case SQUASHFS_SYMLINK_TYPE: {
847 + struct squashfs_symlink_inode_header *inodep =
849 + struct squashfs_symlink_inode_header *sinodep =
853 + if (!squashfs_get_cached_block(s, (char *)
854 + sinodep, block, offset,
855 + sizeof(*sinodep), &next_block,
858 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
861 + if (!squashfs_get_cached_block(s, (char *)
862 + inodep, block, offset,
863 + sizeof(*inodep), &next_block,
867 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
870 + i->i_nlink = inodep->nlink;
871 + i->i_size = inodep->symlink_size;
872 + i->i_op = &page_symlink_inode_operations;
873 + i->i_data.a_ops = &squashfs_symlink_aops;
874 + i->i_mode |= S_IFLNK;
875 + SQUASHFS_I(i)->start_block = next_block;
876 + SQUASHFS_I(i)->offset = next_offset;
878 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
880 + SQUASHFS_INODE_BLK(inode), offset,
881 + next_block, next_offset);
884 + case SQUASHFS_BLKDEV_TYPE:
885 + case SQUASHFS_CHRDEV_TYPE: {
886 + struct squashfs_dev_inode_header *inodep = &id.dev;
887 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
890 + if (!squashfs_get_cached_block(s, (char *)
891 + sinodep, block, offset,
892 + sizeof(*sinodep), &next_block,
895 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
897 + if (!squashfs_get_cached_block(s, (char *)
898 + inodep, block, offset,
899 + sizeof(*inodep), &next_block,
903 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
906 + i->i_nlink = inodep->nlink;
907 + i->i_mode |= (inodeb->inode_type ==
908 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
910 + init_special_inode(i, i->i_mode,
911 + old_decode_dev(inodep->rdev));
913 + TRACE("Device inode %x:%x, rdev %x\n",
914 + SQUASHFS_INODE_BLK(inode), offset,
918 + case SQUASHFS_FIFO_TYPE:
919 + case SQUASHFS_SOCKET_TYPE: {
920 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
921 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
924 + if (!squashfs_get_cached_block(s, (char *)
925 + sinodep, block, offset,
926 + sizeof(*sinodep), &next_block,
929 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
931 + if (!squashfs_get_cached_block(s, (char *)
932 + inodep, block, offset,
933 + sizeof(*inodep), &next_block,
937 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
940 + i->i_nlink = inodep->nlink;
941 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
942 + ? S_IFIFO : S_IFSOCK;
943 + init_special_inode(i, i->i_mode, 0);
947 + ERROR("Unknown inode type %d in squashfs_iget!\n",
948 + inodeb->inode_type);
952 + insert_inode_hash(i);
956 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
963 +static int read_fragment_index_table(struct super_block *s)
965 + struct squashfs_sb_info *msblk = s->s_fs_info;
966 + struct squashfs_super_block *sblk = &msblk->sblk;
968 + /* Allocate fragment index table */
969 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
970 + (sblk->fragments), GFP_KERNEL))) {
971 + ERROR("Failed to allocate uid/gid table\n");
975 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
976 + !squashfs_read_data(s, (char *)
977 + msblk->fragment_index,
978 + sblk->fragment_table_start,
979 + SQUASHFS_FRAGMENT_INDEX_BYTES
980 + (sblk->fragments) |
981 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
982 + ERROR("unable to read fragment index table\n");
988 + long long fragment;
990 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
992 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
993 + &msblk->fragment_index[i], 1);
994 + msblk->fragment_index[i] = fragment;
1002 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1004 + struct squashfs_super_block *sblk = &msblk->sblk;
1006 + msblk->iget = squashfs_iget;
1007 + msblk->read_blocklist = read_blocklist;
1008 + msblk->read_fragment_index_table = read_fragment_index_table;
1010 + if (sblk->s_major == 1) {
1011 + if (!squashfs_1_0_supported(msblk)) {
1012 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1013 + "are unsupported\n");
1014 + SERROR("Please recompile with "
1015 + "Squashfs 1.0 support enabled\n");
1018 + } else if (sblk->s_major == 2) {
1019 + if (!squashfs_2_0_supported(msblk)) {
1020 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1021 + "are unsupported\n");
1022 + SERROR("Please recompile with "
1023 + "Squashfs 2.0 support enabled\n");
1026 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1028 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1029 + "filesystem\n", sblk->s_major, sblk->s_minor);
1030 + SERROR("Please update your kernel\n");
1038 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1040 + struct squashfs_sb_info *msblk;
1041 + struct squashfs_super_block *sblk;
1043 + char b[BDEVNAME_SIZE];
1044 + struct inode *root;
1046 + TRACE("Entered squashfs_read_superblock\n");
1048 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1050 + ERROR("Failed to allocate superblock\n");
1053 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1054 + msblk = s->s_fs_info;
1055 + if (!(msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
1056 + ERROR("Failed to allocate zlib workspace\n");
1059 + sblk = &msblk->sblk;
1061 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1062 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1064 + init_MUTEX(&msblk->read_data_mutex);
1065 + init_MUTEX(&msblk->read_page_mutex);
1066 + init_MUTEX(&msblk->block_cache_mutex);
1067 + init_MUTEX(&msblk->fragment_mutex);
1068 + init_MUTEX(&msblk->meta_index_mutex);
1070 + init_waitqueue_head(&msblk->waitq);
1071 + init_waitqueue_head(&msblk->fragment_wait_queue);
1073 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1074 + sizeof(struct squashfs_super_block) |
1075 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1076 + SERROR("unable to read superblock\n");
1077 + goto failed_mount;
1080 + /* Check it is a SQUASHFS superblock */
1082 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1083 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1084 + struct squashfs_super_block ssblk;
1086 + WARNING("Mounting a different endian SQUASHFS "
1087 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1089 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1090 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1093 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1094 + bdevname(s->s_bdev, b));
1095 + goto failed_mount;
1099 + /* Check the MAJOR & MINOR versions */
1100 + if(!supported_squashfs_filesystem(msblk, silent))
1101 + goto failed_mount;
1103 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1104 + TRACE("Inodes are %scompressed\n",
1105 + SQUASHFS_UNCOMPRESSED_INODES
1106 + (sblk->flags) ? "un" : "");
1107 + TRACE("Data is %scompressed\n",
1108 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1110 + TRACE("Check data is %s present in the filesystem\n",
1111 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1113 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1114 + TRACE("Block size %d\n", sblk->block_size);
1115 + TRACE("Number of inodes %d\n", sblk->inodes);
1116 + if (sblk->s_major > 1)
1117 + TRACE("Number of fragments %d\n", sblk->fragments);
1118 + TRACE("Number of uids %d\n", sblk->no_uids);
1119 + TRACE("Number of gids %d\n", sblk->no_guids);
1120 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1121 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1122 + if (sblk->s_major > 1)
1123 + TRACE("sblk->fragment_table_start %llx\n",
1124 + sblk->fragment_table_start);
1125 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1127 + s->s_flags |= MS_RDONLY;
1128 + s->s_op = &squashfs_ops;
1130 + /* Init inode_table block pointer array */
1131 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1132 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1133 + ERROR("Failed to allocate block cache\n");
1134 + goto failed_mount;
1137 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1138 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1140 + msblk->next_cache = 0;
1142 + /* Allocate read_data block */
1143 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1144 + SQUASHFS_METADATA_SIZE :
1147 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1148 + ERROR("Failed to allocate read_data block\n");
1149 + goto failed_mount;
1152 + /* Allocate read_page block */
1153 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1154 + ERROR("Failed to allocate read_page block\n");
1155 + goto failed_mount;
1158 + /* Allocate uid and gid tables */
1159 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1160 + sizeof(unsigned int), GFP_KERNEL))) {
1161 + ERROR("Failed to allocate uid/gid table\n");
1162 + goto failed_mount;
1164 + msblk->guid = msblk->uid + sblk->no_uids;
1166 + if (msblk->swap) {
1167 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1169 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1170 + ((sblk->no_uids + sblk->no_guids) *
1171 + sizeof(unsigned int)) |
1172 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1173 + ERROR("unable to read uid/gid table\n");
1174 + goto failed_mount;
1177 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1178 + sblk->no_guids), (sizeof(unsigned int) * 8));
1180 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1181 + ((sblk->no_uids + sblk->no_guids) *
1182 + sizeof(unsigned int)) |
1183 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1184 + ERROR("unable to read uid/gid table\n");
1185 + goto failed_mount;
1189 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1190 + goto allocate_root;
1192 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1193 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1194 + ERROR("Failed to allocate fragment block cache\n");
1195 + goto failed_mount;
1198 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1199 + msblk->fragment[i].locked = 0;
1200 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1201 + msblk->fragment[i].data = NULL;
1204 + msblk->next_fragment = 0;
1206 + /* Allocate fragment index table */
1207 + if (msblk->read_fragment_index_table(s) == 0)
1208 + goto failed_mount;
1211 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1212 + goto failed_mount;
1214 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1215 + ERROR("Root inode create failed\n");
1217 + goto failed_mount;
1220 + TRACE("Leaving squashfs_read_super\n");
1224 + kfree(msblk->fragment_index);
1225 + kfree(msblk->fragment);
1226 + kfree(msblk->uid);
1227 + kfree(msblk->read_page);
1228 + kfree(msblk->read_data);
1229 + kfree(msblk->block_cache);
1230 + kfree(msblk->fragment_index_2);
1231 + vfree(msblk->stream.workspace);
1232 + kfree(s->s_fs_info);
1233 + s->s_fs_info = NULL;
1241 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1243 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1244 + struct squashfs_super_block *sblk = &msblk->sblk;
1246 + TRACE("Entered squashfs_statfs\n");
1248 + buf->f_type = SQUASHFS_MAGIC;
1249 + buf->f_bsize = sblk->block_size;
1250 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1251 + buf->f_bfree = buf->f_bavail = 0;
1252 + buf->f_files = sblk->inodes;
1254 + buf->f_namelen = SQUASHFS_NAME_LEN;
1260 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1262 + struct inode *inode = page->mapping->host;
1263 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1264 + long long block = SQUASHFS_I(inode)->start_block;
1265 + int offset = SQUASHFS_I(inode)->offset;
1266 + void *pageaddr = kmap(page);
1268 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1269 + "%llx, offset %x\n", page->index,
1270 + SQUASHFS_I(inode)->start_block,
1271 + SQUASHFS_I(inode)->offset);
1273 + for (length = 0; length < index; length += bytes) {
1274 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1275 + block, offset, PAGE_CACHE_SIZE, &block,
1277 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1283 + if (length != index) {
1284 + ERROR("(squashfs_symlink_readpage) length != index\n");
1289 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1290 + i_size_read(inode) - length;
1292 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1293 + offset, bytes, &block, &offset)))
1294 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1297 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1299 + SetPageUptodate(page);
1300 + unlock_page(page);
1306 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1308 + struct meta_index *meta = NULL;
1309 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1312 + down(&msblk->meta_index_mutex);
1314 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1316 + if(msblk->meta_index == NULL)
1317 + goto not_allocated;
1319 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1320 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1321 + msblk->meta_index[i].offset >= offset &&
1322 + msblk->meta_index[i].offset <= index &&
1323 + msblk->meta_index[i].locked == 0) {
1324 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1325 + msblk->meta_index[i].offset);
1326 + meta = &msblk->meta_index[i];
1327 + offset = meta->offset;
1334 + up(&msblk->meta_index_mutex);
1340 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1342 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1343 + struct meta_index *meta = NULL;
1346 + down(&msblk->meta_index_mutex);
1348 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1350 + if(msblk->meta_index == NULL) {
1351 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1352 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1353 + ERROR("Failed to allocate meta_index\n");
1356 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1357 + msblk->meta_index[i].inode_number = 0;
1358 + msblk->meta_index[i].locked = 0;
1360 + msblk->next_meta_index = 0;
1363 + for(i = SQUASHFS_META_NUMBER; i &&
1364 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1365 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1366 + SQUASHFS_META_NUMBER;
1369 + TRACE("empty_meta_index: failed!\n");
1373 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1374 + msblk->next_meta_index,
1375 + &msblk->meta_index[msblk->next_meta_index]);
1377 + meta = &msblk->meta_index[msblk->next_meta_index];
1378 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1379 + SQUASHFS_META_NUMBER;
1381 + meta->inode_number = inode->i_ino;
1382 + meta->offset = offset;
1383 + meta->skip = skip;
1384 + meta->entries = 0;
1388 + up(&msblk->meta_index_mutex);
1393 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1399 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1400 + long long *start_block, int *offset)
1402 + struct squashfs_sb_info *msblk = s->s_fs_info;
1403 + unsigned int *block_listp;
1406 + if (msblk->swap) {
1407 + char sblock_list[blocks << 2];
1409 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1410 + *offset, blocks << 2, start_block, offset)) {
1411 + ERROR("Unable to read block list [%llx:%x]\n",
1412 + *start_block, *offset);
1415 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1416 + ((unsigned int *)sblock_list), blocks);
1418 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1419 + *offset, blocks << 2, start_block, offset)) {
1420 + ERROR("Unable to read block list [%llx:%x]\n",
1421 + *start_block, *offset);
1425 + for (block_listp = (unsigned int *) block_list; blocks;
1426 + block_listp++, blocks --)
1427 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1438 +static inline int calculate_skip(int blocks) {
1439 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1440 + return skip >= 7 ? 7 : skip + 1;
1444 +static int get_meta_index(struct inode *inode, int index,
1445 + long long *index_block, int *index_offset,
1446 + long long *data_block, char *block_list)
1448 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1449 + struct squashfs_super_block *sblk = &msblk->sblk;
1450 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1452 + struct meta_index *meta;
1453 + struct meta_entry *meta_entry;
1454 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1455 + int cur_offset = SQUASHFS_I(inode)->offset;
1456 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1459 + index /= SQUASHFS_META_INDEXES * skip;
1461 + while ( offset < index ) {
1462 + meta = locate_meta_index(inode, index, offset + 1);
1464 + if (meta == NULL) {
1465 + if ((meta = empty_meta_index(inode, offset + 1,
1469 + offset = index < meta->offset + meta->entries ? index :
1470 + meta->offset + meta->entries - 1;
1471 + meta_entry = &meta->meta_entry[offset - meta->offset];
1472 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1473 + cur_offset = meta_entry->offset;
1474 + cur_data_block = meta_entry->data_block;
1475 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1476 + "meta->entries %d\n", offset, meta->offset,
1478 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1479 + " data_block 0x%llx\n", cur_index_block,
1480 + cur_offset, cur_data_block);
1483 + for (i = meta->offset + meta->entries; i <= index &&
1484 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1485 + int blocks = skip * SQUASHFS_META_INDEXES;
1488 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1490 + int res = read_block_index(inode->i_sb, block,
1491 + block_list, &cur_index_block,
1497 + cur_data_block += res;
1501 + meta_entry = &meta->meta_entry[i - meta->offset];
1502 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1503 + meta_entry->offset = cur_offset;
1504 + meta_entry->data_block = cur_data_block;
1509 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1510 + meta->offset, meta->entries);
1512 + release_meta_index(inode, meta);
1516 + *index_block = cur_index_block;
1517 + *index_offset = cur_offset;
1518 + *data_block = cur_data_block;
1520 + return offset * SQUASHFS_META_INDEXES * skip;
1523 + release_meta_index(inode, meta);
1528 +static long long read_blocklist(struct inode *inode, int index,
1529 + int readahead_blks, char *block_list,
1530 + unsigned short **block_p, unsigned int *bsize)
1532 + long long block_ptr;
1535 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1538 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1539 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1548 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1549 + int res = read_block_index(inode->i_sb, blocks, block_list,
1550 + &block_ptr, &offset);
1557 + if (read_block_index(inode->i_sb, 1, block_list,
1558 + &block_ptr, &offset) == -1)
1560 + *bsize = *((unsigned int *) block_list);
1569 +static int squashfs_readpage(struct file *file, struct page *page)
1571 + struct inode *inode = page->mapping->host;
1572 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1573 + struct squashfs_super_block *sblk = &msblk->sblk;
1574 + unsigned char *block_list;
1576 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1577 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1579 + struct squashfs_fragment_cache *fragment = NULL;
1580 + char *data_ptr = msblk->read_page;
1582 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1583 + int start_index = page->index & ~mask;
1584 + int end_index = start_index | mask;
1586 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1588 + SQUASHFS_I(inode)->start_block);
1590 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1591 + ERROR("Failed to allocate block_list\n");
1595 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1596 + PAGE_CACHE_SHIFT))
1599 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1600 + || index < (i_size_read(inode) >>
1601 + sblk->block_log)) {
1602 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1603 + block_list, NULL, &bsize)) == 0)
1606 + down(&msblk->read_page_mutex);
1608 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1609 + block, bsize, NULL))) {
1610 + ERROR("Unable to read page, block %llx, size %x\n", block,
1612 + up(&msblk->read_page_mutex);
1616 + if ((fragment = get_cached_fragment(inode->i_sb,
1617 + SQUASHFS_I(inode)->
1618 + u.s1.fragment_start_block,
1619 + SQUASHFS_I(inode)->u.s1.fragment_size))
1621 + ERROR("Unable to read page, block %llx, size %x\n",
1622 + SQUASHFS_I(inode)->
1623 + u.s1.fragment_start_block,
1624 + (int) SQUASHFS_I(inode)->
1625 + u.s1.fragment_size);
1628 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1629 + (i_size_read(inode) & (sblk->block_size
1631 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1632 + data_ptr = fragment->data;
1635 + for (i = start_index; i <= end_index && byte_offset < bytes;
1636 + i++, byte_offset += PAGE_CACHE_SIZE) {
1637 + struct page *push_page;
1638 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1639 + PAGE_CACHE_SIZE : bytes - byte_offset;
1641 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1642 + bytes, i, byte_offset, available_bytes);
1644 + if (i == page->index) {
1645 + pageaddr = kmap_atomic(page, KM_USER0);
1646 + memcpy(pageaddr, data_ptr + byte_offset,
1648 + memset(pageaddr + available_bytes, 0,
1649 + PAGE_CACHE_SIZE - available_bytes);
1650 + kunmap_atomic(pageaddr, KM_USER0);
1651 + flush_dcache_page(page);
1652 + SetPageUptodate(page);
1653 + unlock_page(page);
1654 + } else if ((push_page =
1655 + grab_cache_page_nowait(page->mapping, i))) {
1656 + pageaddr = kmap_atomic(push_page, KM_USER0);
1658 + memcpy(pageaddr, data_ptr + byte_offset,
1660 + memset(pageaddr + available_bytes, 0,
1661 + PAGE_CACHE_SIZE - available_bytes);
1662 + kunmap_atomic(pageaddr, KM_USER0);
1663 + flush_dcache_page(push_page);
1664 + SetPageUptodate(push_page);
1665 + unlock_page(push_page);
1666 + page_cache_release(push_page);
1670 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1671 + || index < (i_size_read(inode) >>
1673 + up(&msblk->read_page_mutex);
1675 + release_cached_fragment(msblk, fragment);
1677 + kfree(block_list);
1681 + pageaddr = kmap_atomic(page, KM_USER0);
1682 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1683 + kunmap_atomic(pageaddr, KM_USER0);
1684 + flush_dcache_page(page);
1685 + SetPageUptodate(page);
1686 + unlock_page(page);
1688 + kfree(block_list);
1693 +static int squashfs_readpage4K(struct file *file, struct page *page)
1695 + struct inode *inode = page->mapping->host;
1696 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1697 + struct squashfs_super_block *sblk = &msblk->sblk;
1698 + unsigned char *block_list;
1700 + unsigned int bsize, bytes = 0;
1703 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1705 + SQUASHFS_I(inode)->start_block);
1707 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1708 + PAGE_CACHE_SHIFT)) {
1709 + pageaddr = kmap_atomic(page, KM_USER0);
1710 + block_list = NULL;
1714 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1715 + ERROR("Failed to allocate block_list\n");
1716 + pageaddr = kmap_atomic(page, KM_USER0);
1717 + block_list = NULL;
1721 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1722 + || page->index < (i_size_read(inode) >>
1723 + sblk->block_log)) {
1724 + block = (msblk->read_blocklist)(inode, page->index, 1,
1725 + block_list, NULL, &bsize);
1727 + down(&msblk->read_page_mutex);
1728 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1730 + pageaddr = kmap_atomic(page, KM_USER0);
1732 + memcpy(pageaddr, msblk->read_page, bytes);
1734 + ERROR("Unable to read page, block %llx, size %x\n",
1736 + up(&msblk->read_page_mutex);
1738 + struct squashfs_fragment_cache *fragment =
1739 + get_cached_fragment(inode->i_sb,
1740 + SQUASHFS_I(inode)->
1741 + u.s1.fragment_start_block,
1742 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1743 + pageaddr = kmap_atomic(page, KM_USER0);
1745 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1746 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1747 + u.s1.fragment_offset, bytes);
1748 + release_cached_fragment(msblk, fragment);
1750 + ERROR("Unable to read page, block %llx, size %x\n",
1751 + SQUASHFS_I(inode)->
1752 + u.s1.fragment_start_block, (int)
1753 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1757 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1758 + kunmap_atomic(pageaddr, KM_USER0);
1759 + flush_dcache_page(page);
1760 + SetPageUptodate(page);
1761 + unlock_page(page);
1763 + kfree(block_list);
1768 +static int get_dir_index_using_offset(struct super_block *s, long long
1769 + *next_block, unsigned int *next_offset,
1770 + long long index_start,
1771 + unsigned int index_offset, int i_count,
1774 + struct squashfs_sb_info *msblk = s->s_fs_info;
1775 + struct squashfs_super_block *sblk = &msblk->sblk;
1776 + int i, length = 0;
1777 + struct squashfs_dir_index index;
1779 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1780 + i_count, (unsigned int) f_pos);
1786 + for (i = 0; i < i_count; i++) {
1787 + if (msblk->swap) {
1788 + struct squashfs_dir_index sindex;
1789 + squashfs_get_cached_block(s, (char *) &sindex,
1790 + index_start, index_offset,
1791 + sizeof(sindex), &index_start,
1793 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1795 + squashfs_get_cached_block(s, (char *) &index,
1796 + index_start, index_offset,
1797 + sizeof(index), &index_start,
1800 + if (index.index > f_pos)
1803 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1804 + index.size + 1, &index_start,
1807 + length = index.index;
1808 + *next_block = index.start_block + sblk->directory_table_start;
1811 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1814 + return length + 3;
1818 +static int get_dir_index_using_name(struct super_block *s, long long
1819 + *next_block, unsigned int *next_offset,
1820 + long long index_start,
1821 + unsigned int index_offset, int i_count,
1822 + const char *name, int size)
1824 + struct squashfs_sb_info *msblk = s->s_fs_info;
1825 + struct squashfs_super_block *sblk = &msblk->sblk;
1826 + int i, length = 0;
1827 + struct squashfs_dir_index *index;
1830 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1832 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
1833 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
1834 + ERROR("Failed to allocate squashfs_dir_index\n");
1838 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1839 + strncpy(str, name, size);
1842 + for (i = 0; i < i_count; i++) {
1843 + if (msblk->swap) {
1844 + struct squashfs_dir_index sindex;
1845 + squashfs_get_cached_block(s, (char *) &sindex,
1846 + index_start, index_offset,
1847 + sizeof(sindex), &index_start,
1849 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1851 + squashfs_get_cached_block(s, (char *) index,
1852 + index_start, index_offset,
1853 + sizeof(struct squashfs_dir_index),
1854 + &index_start, &index_offset);
1856 + squashfs_get_cached_block(s, index->name, index_start,
1857 + index_offset, index->size + 1,
1858 + &index_start, &index_offset);
1860 + index->name[index->size + 1] = '\0';
1862 + if (strcmp(index->name, str) > 0)
1865 + length = index->index;
1866 + *next_block = index->start_block + sblk->directory_table_start;
1869 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1872 + return length + 3;
1876 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1878 + struct inode *i = file->f_dentry->d_inode;
1879 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1880 + struct squashfs_super_block *sblk = &msblk->sblk;
1881 + long long next_block = SQUASHFS_I(i)->start_block +
1882 + sblk->directory_table_start;
1883 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1885 + struct squashfs_dir_header dirh;
1886 + struct squashfs_dir_entry *dire;
1888 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1890 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1891 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
1892 + ERROR("Failed to allocate squashfs_dir_entry\n");
1896 + while(file->f_pos < 3) {
1900 + if(file->f_pos == 0) {
1907 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1909 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1910 + (unsigned int) dirent, name, size, (int)
1911 + file->f_pos, i_ino,
1912 + squashfs_filetype_table[1]);
1914 + if (filldir(dirent, name, size,
1915 + file->f_pos, i_ino,
1916 + squashfs_filetype_table[1]) < 0) {
1917 + TRACE("Filldir returned less than 0\n");
1920 + file->f_pos += size;
1923 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1924 + SQUASHFS_I(i)->u.s2.directory_index_start,
1925 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1926 + SQUASHFS_I(i)->u.s2.directory_index_count,
1929 + while (length < i_size_read(i)) {
1930 + /* read directory header */
1931 + if (msblk->swap) {
1932 + struct squashfs_dir_header sdirh;
1934 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1935 + next_block, next_offset, sizeof(sdirh),
1936 + &next_block, &next_offset))
1939 + length += sizeof(sdirh);
1940 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1942 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1943 + next_block, next_offset, sizeof(dirh),
1944 + &next_block, &next_offset))
1947 + length += sizeof(dirh);
1950 + dir_count = dirh.count + 1;
1951 + while (dir_count--) {
1952 + if (msblk->swap) {
1953 + struct squashfs_dir_entry sdire;
1954 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1955 + &sdire, next_block, next_offset,
1956 + sizeof(sdire), &next_block,
1960 + length += sizeof(sdire);
1961 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1963 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1964 + dire, next_block, next_offset,
1965 + sizeof(*dire), &next_block,
1969 + length += sizeof(*dire);
1972 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1973 + next_block, next_offset,
1974 + dire->size + 1, &next_block,
1978 + length += dire->size + 1;
1980 + if (file->f_pos >= length)
1983 + dire->name[dire->size + 1] = '\0';
1985 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1986 + (unsigned int) dirent, dire->name,
1987 + dire->size + 1, (int) file->f_pos,
1988 + dirh.start_block, dire->offset,
1989 + dirh.inode_number + dire->inode_number,
1990 + squashfs_filetype_table[dire->type]);
1992 + if (filldir(dirent, dire->name, dire->size + 1,
1994 + dirh.inode_number + dire->inode_number,
1995 + squashfs_filetype_table[dire->type])
1997 + TRACE("Filldir returned less than 0\n");
2000 + file->f_pos = length;
2009 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2015 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2016 + struct nameidata *nd)
2018 + const unsigned char *name = dentry->d_name.name;
2019 + int len = dentry->d_name.len;
2020 + struct inode *inode = NULL;
2021 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2022 + struct squashfs_super_block *sblk = &msblk->sblk;
2023 + long long next_block = SQUASHFS_I(i)->start_block +
2024 + sblk->directory_table_start;
2025 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2027 + struct squashfs_dir_header dirh;
2028 + struct squashfs_dir_entry *dire;
2030 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2032 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2033 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2034 + ERROR("Failed to allocate squashfs_dir_entry\n");
2038 + if (len > SQUASHFS_NAME_LEN)
2041 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2042 + SQUASHFS_I(i)->u.s2.directory_index_start,
2043 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2044 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2047 + while (length < i_size_read(i)) {
2048 + /* read directory header */
2049 + if (msblk->swap) {
2050 + struct squashfs_dir_header sdirh;
2051 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2052 + next_block, next_offset, sizeof(sdirh),
2053 + &next_block, &next_offset))
2056 + length += sizeof(sdirh);
2057 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2059 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2060 + next_block, next_offset, sizeof(dirh),
2061 + &next_block, &next_offset))
2064 + length += sizeof(dirh);
2067 + dir_count = dirh.count + 1;
2068 + while (dir_count--) {
2069 + if (msblk->swap) {
2070 + struct squashfs_dir_entry sdire;
2071 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2072 + &sdire, next_block,next_offset,
2073 + sizeof(sdire), &next_block,
2077 + length += sizeof(sdire);
2078 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2080 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2081 + dire, next_block,next_offset,
2082 + sizeof(*dire), &next_block,
2086 + length += sizeof(*dire);
2089 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2090 + next_block, next_offset, dire->size + 1,
2091 + &next_block, &next_offset))
2094 + length += dire->size + 1;
2096 + if (name[0] < dire->name[0])
2099 + if ((len == dire->size + 1) && !strncmp(name,
2100 + dire->name, len)) {
2101 + squashfs_inode_t ino =
2102 + SQUASHFS_MKINODE(dirh.start_block,
2105 + TRACE("calling squashfs_iget for directory "
2106 + "entry %s, inode %x:%x, %d\n", name,
2107 + dirh.start_block, dire->offset,
2108 + dirh.inode_number + dire->inode_number);
2110 + inode = (msblk->iget)(i->i_sb, ino);
2119 + d_add(dentry, inode);
2120 + return ERR_PTR(0);
2123 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2129 +static void squashfs_put_super(struct super_block *s)
2133 + if (s->s_fs_info) {
2134 + struct squashfs_sb_info *sbi = s->s_fs_info;
2135 + if (sbi->block_cache)
2136 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2137 + if (sbi->block_cache[i].block !=
2138 + SQUASHFS_INVALID_BLK)
2139 + kfree(sbi->block_cache[i].data);
2140 + if (sbi->fragment)
2141 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2142 + SQUASHFS_FREE(sbi->fragment[i].data);
2143 + kfree(sbi->fragment);
2144 + kfree(sbi->block_cache);
2145 + kfree(sbi->read_data);
2146 + kfree(sbi->read_page);
2148 + kfree(sbi->fragment_index);
2149 + kfree(sbi->fragment_index_2);
2150 + kfree(sbi->meta_index);
2151 + vfree(sbi->stream.workspace);
2152 + kfree(s->s_fs_info);
2153 + s->s_fs_info = NULL;
2158 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2159 + const char *dev_name, void *data,
2160 + struct vfsmount *mnt)
2162 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2167 +static int __init init_squashfs_fs(void)
2169 + int err = init_inodecache();
2173 + printk(KERN_INFO "squashfs: version 3.1 (2006/08/19) "
2174 + "Phillip Lougher\n");
2176 + if ((err = register_filesystem(&squashfs_fs_type)))
2177 + destroy_inodecache();
2184 +static void __exit exit_squashfs_fs(void)
2186 + unregister_filesystem(&squashfs_fs_type);
2187 + destroy_inodecache();
2191 +static kmem_cache_t * squashfs_inode_cachep;
2194 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2196 + struct squashfs_inode_info *ei;
2197 + ei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
2200 + return &ei->vfs_inode;
2204 +static void squashfs_destroy_inode(struct inode *inode)
2206 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2210 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2212 + struct squashfs_inode_info *ei = foo;
2214 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2215 + SLAB_CTOR_CONSTRUCTOR)
2216 + inode_init_once(&ei->vfs_inode);
2220 +static int __init init_inodecache(void)
2222 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2223 + sizeof(struct squashfs_inode_info),
2224 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2226 + if (squashfs_inode_cachep == NULL)
2232 +static void destroy_inodecache(void)
2234 + kmem_cache_destroy(squashfs_inode_cachep);
2238 +module_init(init_squashfs_fs);
2239 +module_exit(exit_squashfs_fs);
2240 +MODULE_DESCRIPTION("squashfs 3.1, a compressed read-only filesystem");
2241 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2242 +MODULE_LICENSE("GPL");
2243 diff --new-file -urp linux-2.6.18/fs/squashfs/Makefile linux-2.6.18-squashfs3.1/fs/squashfs/Makefile
2244 --- linux-2.6.18/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2245 +++ linux-2.6.18-squashfs3.1/fs/squashfs/Makefile 2006-08-21 00:13:12.000000000 +0100
2248 +# Makefile for the linux squashfs routines.
2251 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2252 +squashfs-y += inode.o
2253 +squashfs-y += squashfs2_0.o
2254 diff --new-file -urp linux-2.6.18/fs/squashfs/squashfs2_0.c linux-2.6.18-squashfs3.1/fs/squashfs/squashfs2_0.c
2255 --- linux-2.6.18/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2256 +++ linux-2.6.18-squashfs3.1/fs/squashfs/squashfs2_0.c 2006-08-21 00:14:55.000000000 +0100
2259 + * Squashfs - a compressed read only filesystem for Linux
2261 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2262 + * Phillip Lougher <phillip@lougher.org.uk>
2264 + * This program is free software; you can redistribute it and/or
2265 + * modify it under the terms of the GNU General Public License
2266 + * as published by the Free Software Foundation; either version 2,
2267 + * or (at your option) any later version.
2269 + * This program is distributed in the hope that it will be useful,
2270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2272 + * GNU General Public License for more details.
2274 + * You should have received a copy of the GNU General Public License
2275 + * along with this program; if not, write to the Free Software
2276 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2281 +#include <linux/types.h>
2282 +#include <linux/squashfs_fs.h>
2283 +#include <linux/module.h>
2284 +#include <linux/errno.h>
2285 +#include <linux/slab.h>
2286 +#include <linux/zlib.h>
2287 +#include <linux/fs.h>
2288 +#include <linux/smp_lock.h>
2289 +#include <linux/slab.h>
2290 +#include <linux/squashfs_fs_sb.h>
2291 +#include <linux/squashfs_fs_i.h>
2292 +#include <linux/buffer_head.h>
2293 +#include <linux/vfs.h>
2294 +#include <linux/init.h>
2295 +#include <linux/dcache.h>
2296 +#include <linux/wait.h>
2297 +#include <linux/zlib.h>
2298 +#include <linux/blkdev.h>
2299 +#include <linux/vmalloc.h>
2300 +#include <asm/uaccess.h>
2301 +#include <asm/semaphore.h>
2303 +#include "squashfs.h"
2304 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2305 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2306 + struct nameidata *);
2308 +static struct file_operations squashfs_dir_ops_2 = {
2309 + .read = generic_read_dir,
2310 + .readdir = squashfs_readdir_2
2313 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2314 + .lookup = squashfs_lookup_2
2317 +static unsigned char squashfs_filetype_table[] = {
2318 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2321 +static int read_fragment_index_table_2(struct super_block *s)
2323 + struct squashfs_sb_info *msblk = s->s_fs_info;
2324 + struct squashfs_super_block *sblk = &msblk->sblk;
2326 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2327 + (sblk->fragments), GFP_KERNEL))) {
2328 + ERROR("Failed to allocate uid/gid table\n");
2332 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2333 + !squashfs_read_data(s, (char *)
2334 + msblk->fragment_index_2,
2335 + sblk->fragment_table_start,
2336 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2337 + (sblk->fragments) |
2338 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2339 + ERROR("unable to read fragment index table\n");
2343 + if (msblk->swap) {
2345 + unsigned int fragment;
2347 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2349 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2350 + &msblk->fragment_index_2[i], 1);
2351 + msblk->fragment_index_2[i] = fragment;
2359 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2360 + long long *fragment_start_block,
2361 + unsigned int *fragment_size)
2363 + struct squashfs_sb_info *msblk = s->s_fs_info;
2364 + long long start_block =
2365 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2366 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2367 + struct squashfs_fragment_entry_2 fragment_entry;
2369 + if (msblk->swap) {
2370 + struct squashfs_fragment_entry_2 sfragment_entry;
2372 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2373 + start_block, offset,
2374 + sizeof(sfragment_entry), &start_block,
2377 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2379 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2380 + start_block, offset,
2381 + sizeof(fragment_entry), &start_block,
2385 + *fragment_start_block = fragment_entry.start_block;
2386 + *fragment_size = fragment_entry.size;
2395 +static struct inode *squashfs_new_inode(struct super_block *s,
2396 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2398 + struct squashfs_sb_info *msblk = s->s_fs_info;
2399 + struct squashfs_super_block *sblk = &msblk->sblk;
2400 + struct inode *i = new_inode(s);
2404 + i->i_mtime.tv_sec = sblk->mkfs_time;
2405 + i->i_atime.tv_sec = sblk->mkfs_time;
2406 + i->i_ctime.tv_sec = sblk->mkfs_time;
2407 + i->i_uid = msblk->uid[inodeb->uid];
2408 + i->i_mode = inodeb->mode;
2411 + if (inodeb->guid == SQUASHFS_GUIDS)
2412 + i->i_gid = i->i_uid;
2414 + i->i_gid = msblk->guid[inodeb->guid];
2421 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2424 + struct squashfs_sb_info *msblk = s->s_fs_info;
2425 + struct squashfs_super_block *sblk = &msblk->sblk;
2426 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2427 + sblk->inode_table_start;
2428 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2429 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2430 + - sblk->inode_table_start, offset);
2431 + long long next_block;
2432 + unsigned int next_offset;
2433 + union squashfs_inode_header_2 id, sid;
2434 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2435 + *sinodeb = &sid.base;
2437 + TRACE("Entered squashfs_iget\n");
2439 + if (msblk->swap) {
2440 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2441 + offset, sizeof(*sinodeb), &next_block,
2444 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2445 + sizeof(*sinodeb));
2447 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2448 + offset, sizeof(*inodeb), &next_block,
2452 + switch(inodeb->inode_type) {
2453 + case SQUASHFS_FILE_TYPE: {
2454 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2455 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2456 + long long frag_blk;
2457 + unsigned int frag_size;
2459 + if (msblk->swap) {
2460 + if (!squashfs_get_cached_block(s, (char *)
2461 + sinodep, block, offset,
2462 + sizeof(*sinodep), &next_block,
2465 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2467 + if (!squashfs_get_cached_block(s, (char *)
2468 + inodep, block, offset,
2469 + sizeof(*inodep), &next_block,
2473 + frag_blk = SQUASHFS_INVALID_BLK;
2474 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2475 + !get_fragment_location_2(s,
2476 + inodep->fragment, &frag_blk, &frag_size))
2479 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2480 + goto failed_read1;
2482 + i->i_size = inodep->file_size;
2483 + i->i_fop = &generic_ro_fops;
2484 + i->i_mode |= S_IFREG;
2485 + i->i_mtime.tv_sec = inodep->mtime;
2486 + i->i_atime.tv_sec = inodep->mtime;
2487 + i->i_ctime.tv_sec = inodep->mtime;
2488 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2489 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2490 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2491 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2492 + SQUASHFS_I(i)->start_block = inodep->start_block;
2493 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2494 + SQUASHFS_I(i)->offset = next_offset;
2495 + if (sblk->block_size > 4096)
2496 + i->i_data.a_ops = &squashfs_aops;
2498 + i->i_data.a_ops = &squashfs_aops_4K;
2500 + TRACE("File inode %x:%x, start_block %x, "
2501 + "block_list_start %llx, offset %x\n",
2502 + SQUASHFS_INODE_BLK(inode), offset,
2503 + inodep->start_block, next_block,
2507 + case SQUASHFS_DIR_TYPE: {
2508 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2509 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2511 + if (msblk->swap) {
2512 + if (!squashfs_get_cached_block(s, (char *)
2513 + sinodep, block, offset,
2514 + sizeof(*sinodep), &next_block,
2517 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2519 + if (!squashfs_get_cached_block(s, (char *)
2520 + inodep, block, offset,
2521 + sizeof(*inodep), &next_block,
2525 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2526 + goto failed_read1;
2528 + i->i_size = inodep->file_size;
2529 + i->i_op = &squashfs_dir_inode_ops_2;
2530 + i->i_fop = &squashfs_dir_ops_2;
2531 + i->i_mode |= S_IFDIR;
2532 + i->i_mtime.tv_sec = inodep->mtime;
2533 + i->i_atime.tv_sec = inodep->mtime;
2534 + i->i_ctime.tv_sec = inodep->mtime;
2535 + SQUASHFS_I(i)->start_block = inodep->start_block;
2536 + SQUASHFS_I(i)->offset = inodep->offset;
2537 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2538 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2540 + TRACE("Directory inode %x:%x, start_block %x, offset "
2541 + "%x\n", SQUASHFS_INODE_BLK(inode),
2542 + offset, inodep->start_block,
2546 + case SQUASHFS_LDIR_TYPE: {
2547 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2548 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2550 + if (msblk->swap) {
2551 + if (!squashfs_get_cached_block(s, (char *)
2552 + sinodep, block, offset,
2553 + sizeof(*sinodep), &next_block,
2556 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2559 + if (!squashfs_get_cached_block(s, (char *)
2560 + inodep, block, offset,
2561 + sizeof(*inodep), &next_block,
2565 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2566 + goto failed_read1;
2568 + i->i_size = inodep->file_size;
2569 + i->i_op = &squashfs_dir_inode_ops_2;
2570 + i->i_fop = &squashfs_dir_ops_2;
2571 + i->i_mode |= S_IFDIR;
2572 + i->i_mtime.tv_sec = inodep->mtime;
2573 + i->i_atime.tv_sec = inodep->mtime;
2574 + i->i_ctime.tv_sec = inodep->mtime;
2575 + SQUASHFS_I(i)->start_block = inodep->start_block;
2576 + SQUASHFS_I(i)->offset = inodep->offset;
2577 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2578 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2580 + SQUASHFS_I(i)->u.s2.directory_index_count =
2582 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2584 + TRACE("Long directory inode %x:%x, start_block %x, "
2586 + SQUASHFS_INODE_BLK(inode), offset,
2587 + inodep->start_block, inodep->offset);
2590 + case SQUASHFS_SYMLINK_TYPE: {
2591 + struct squashfs_symlink_inode_header_2 *inodep =
2593 + struct squashfs_symlink_inode_header_2 *sinodep =
2596 + if (msblk->swap) {
2597 + if (!squashfs_get_cached_block(s, (char *)
2598 + sinodep, block, offset,
2599 + sizeof(*sinodep), &next_block,
2602 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + inodep, block, offset,
2607 + sizeof(*inodep), &next_block,
2611 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2612 + goto failed_read1;
2614 + i->i_size = inodep->symlink_size;
2615 + i->i_op = &page_symlink_inode_operations;
2616 + i->i_data.a_ops = &squashfs_symlink_aops;
2617 + i->i_mode |= S_IFLNK;
2618 + SQUASHFS_I(i)->start_block = next_block;
2619 + SQUASHFS_I(i)->offset = next_offset;
2621 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2623 + SQUASHFS_INODE_BLK(inode), offset,
2624 + next_block, next_offset);
2627 + case SQUASHFS_BLKDEV_TYPE:
2628 + case SQUASHFS_CHRDEV_TYPE: {
2629 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2630 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2632 + if (msblk->swap) {
2633 + if (!squashfs_get_cached_block(s, (char *)
2634 + sinodep, block, offset,
2635 + sizeof(*sinodep), &next_block,
2638 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2640 + if (!squashfs_get_cached_block(s, (char *)
2641 + inodep, block, offset,
2642 + sizeof(*inodep), &next_block,
2646 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2647 + goto failed_read1;
2649 + i->i_mode |= (inodeb->inode_type ==
2650 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2652 + init_special_inode(i, i->i_mode,
2653 + old_decode_dev(inodep->rdev));
2655 + TRACE("Device inode %x:%x, rdev %x\n",
2656 + SQUASHFS_INODE_BLK(inode), offset,
2660 + case SQUASHFS_FIFO_TYPE:
2661 + case SQUASHFS_SOCKET_TYPE: {
2662 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2663 + goto failed_read1;
2665 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2666 + ? S_IFIFO : S_IFSOCK;
2667 + init_special_inode(i, i->i_mode, 0);
2671 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2672 + inodeb->inode_type);
2673 + goto failed_read1;
2676 + insert_inode_hash(i);
2680 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2687 +static int get_dir_index_using_offset(struct super_block *s, long long
2688 + *next_block, unsigned int *next_offset,
2689 + long long index_start,
2690 + unsigned int index_offset, int i_count,
2693 + struct squashfs_sb_info *msblk = s->s_fs_info;
2694 + struct squashfs_super_block *sblk = &msblk->sblk;
2695 + int i, length = 0;
2696 + struct squashfs_dir_index_2 index;
2698 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2699 + i_count, (unsigned int) f_pos);
2704 + for (i = 0; i < i_count; i++) {
2705 + if (msblk->swap) {
2706 + struct squashfs_dir_index_2 sindex;
2707 + squashfs_get_cached_block(s, (char *) &sindex,
2708 + index_start, index_offset,
2709 + sizeof(sindex), &index_start,
2711 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2713 + squashfs_get_cached_block(s, (char *) &index,
2714 + index_start, index_offset,
2715 + sizeof(index), &index_start,
2718 + if (index.index > f_pos)
2721 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2722 + index.size + 1, &index_start,
2725 + length = index.index;
2726 + *next_block = index.start_block + sblk->directory_table_start;
2729 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2736 +static int get_dir_index_using_name(struct super_block *s, long long
2737 + *next_block, unsigned int *next_offset,
2738 + long long index_start,
2739 + unsigned int index_offset, int i_count,
2740 + const char *name, int size)
2742 + struct squashfs_sb_info *msblk = s->s_fs_info;
2743 + struct squashfs_super_block *sblk = &msblk->sblk;
2744 + int i, length = 0;
2745 + struct squashfs_dir_index_2 *index;
2748 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2750 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2751 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2752 + ERROR("Failed to allocate squashfs_dir_index\n");
2756 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2757 + strncpy(str, name, size);
2760 + for (i = 0; i < i_count; i++) {
2761 + if (msblk->swap) {
2762 + struct squashfs_dir_index_2 sindex;
2763 + squashfs_get_cached_block(s, (char *) &sindex,
2764 + index_start, index_offset,
2765 + sizeof(sindex), &index_start,
2767 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2769 + squashfs_get_cached_block(s, (char *) index,
2770 + index_start, index_offset,
2771 + sizeof(struct squashfs_dir_index_2),
2772 + &index_start, &index_offset);
2774 + squashfs_get_cached_block(s, index->name, index_start,
2775 + index_offset, index->size + 1,
2776 + &index_start, &index_offset);
2778 + index->name[index->size + 1] = '\0';
2780 + if (strcmp(index->name, str) > 0)
2783 + length = index->index;
2784 + *next_block = index->start_block + sblk->directory_table_start;
2787 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2794 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2796 + struct inode *i = file->f_dentry->d_inode;
2797 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2798 + struct squashfs_super_block *sblk = &msblk->sblk;
2799 + long long next_block = SQUASHFS_I(i)->start_block +
2800 + sblk->directory_table_start;
2801 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2803 + struct squashfs_dir_header_2 dirh;
2804 + struct squashfs_dir_entry_2 *dire;
2806 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2808 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2809 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2810 + ERROR("Failed to allocate squashfs_dir_entry\n");
2814 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2815 + SQUASHFS_I(i)->u.s2.directory_index_start,
2816 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2817 + SQUASHFS_I(i)->u.s2.directory_index_count,
2820 + while (length < i_size_read(i)) {
2821 + /* read directory header */
2822 + if (msblk->swap) {
2823 + struct squashfs_dir_header_2 sdirh;
2825 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2826 + next_block, next_offset, sizeof(sdirh),
2827 + &next_block, &next_offset))
2830 + length += sizeof(sdirh);
2831 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2833 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2834 + next_block, next_offset, sizeof(dirh),
2835 + &next_block, &next_offset))
2838 + length += sizeof(dirh);
2841 + dir_count = dirh.count + 1;
2842 + while (dir_count--) {
2843 + if (msblk->swap) {
2844 + struct squashfs_dir_entry_2 sdire;
2845 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2846 + &sdire, next_block, next_offset,
2847 + sizeof(sdire), &next_block,
2851 + length += sizeof(sdire);
2852 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2854 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2855 + dire, next_block, next_offset,
2856 + sizeof(*dire), &next_block,
2860 + length += sizeof(*dire);
2863 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2864 + next_block, next_offset,
2865 + dire->size + 1, &next_block,
2869 + length += dire->size + 1;
2871 + if (file->f_pos >= length)
2874 + dire->name[dire->size + 1] = '\0';
2876 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2877 + (unsigned int) dirent, dire->name,
2878 + dire->size + 1, (int) file->f_pos,
2879 + dirh.start_block, dire->offset,
2880 + squashfs_filetype_table[dire->type]);
2882 + if (filldir(dirent, dire->name, dire->size + 1,
2883 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2884 + dirh.start_block, dire->offset),
2885 + squashfs_filetype_table[dire->type])
2887 + TRACE("Filldir returned less than 0\n");
2890 + file->f_pos = length;
2899 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2906 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2907 + struct nameidata *nd)
2909 + const unsigned char *name = dentry->d_name.name;
2910 + int len = dentry->d_name.len;
2911 + struct inode *inode = NULL;
2912 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2913 + struct squashfs_super_block *sblk = &msblk->sblk;
2914 + long long next_block = SQUASHFS_I(i)->start_block +
2915 + sblk->directory_table_start;
2916 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2918 + struct squashfs_dir_header_2 dirh;
2919 + struct squashfs_dir_entry_2 *dire;
2920 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2922 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2924 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2925 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2926 + ERROR("Failed to allocate squashfs_dir_entry\n");
2930 + if (len > SQUASHFS_NAME_LEN)
2933 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2934 + SQUASHFS_I(i)->u.s2.directory_index_start,
2935 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2936 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2939 + while (length < i_size_read(i)) {
2940 + /* read directory header */
2941 + if (msblk->swap) {
2942 + struct squashfs_dir_header_2 sdirh;
2943 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2944 + next_block, next_offset, sizeof(sdirh),
2945 + &next_block, &next_offset))
2948 + length += sizeof(sdirh);
2949 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2951 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2952 + next_block, next_offset, sizeof(dirh),
2953 + &next_block, &next_offset))
2956 + length += sizeof(dirh);
2959 + dir_count = dirh.count + 1;
2960 + while (dir_count--) {
2961 + if (msblk->swap) {
2962 + struct squashfs_dir_entry_2 sdire;
2963 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2964 + &sdire, next_block,next_offset,
2965 + sizeof(sdire), &next_block,
2969 + length += sizeof(sdire);
2970 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2972 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2973 + dire, next_block,next_offset,
2974 + sizeof(*dire), &next_block,
2978 + length += sizeof(*dire);
2981 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2982 + next_block, next_offset, dire->size + 1,
2983 + &next_block, &next_offset))
2986 + length += dire->size + 1;
2988 + if (sorted && name[0] < dire->name[0])
2991 + if ((len == dire->size + 1) && !strncmp(name,
2992 + dire->name, len)) {
2993 + squashfs_inode_t ino =
2994 + SQUASHFS_MKINODE(dirh.start_block,
2997 + TRACE("calling squashfs_iget for directory "
2998 + "entry %s, inode %x:%x, %lld\n", name,
2999 + dirh.start_block, dire->offset, ino);
3001 + inode = (msblk->iget)(i->i_sb, ino);
3010 + d_add(dentry, inode);
3011 + return ERR_PTR(0);
3014 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3020 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3022 + struct squashfs_super_block *sblk = &msblk->sblk;
3024 + msblk->iget = squashfs_iget_2;
3025 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3027 + sblk->bytes_used = sblk->bytes_used_2;
3028 + sblk->uid_start = sblk->uid_start_2;
3029 + sblk->guid_start = sblk->guid_start_2;
3030 + sblk->inode_table_start = sblk->inode_table_start_2;
3031 + sblk->directory_table_start = sblk->directory_table_start_2;
3032 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3036 diff --new-file -urp linux-2.6.18/fs/squashfs/squashfs.h linux-2.6.18-squashfs3.1/fs/squashfs/squashfs.h
3037 --- linux-2.6.18/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3038 +++ linux-2.6.18-squashfs3.1/fs/squashfs/squashfs.h 2006-08-21 00:13:12.000000000 +0100
3041 + * Squashfs - a compressed read only filesystem for Linux
3043 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3044 + * Phillip Lougher <phillip@lougher.org.uk>
3046 + * This program is free software; you can redistribute it and/or
3047 + * modify it under the terms of the GNU General Public License
3048 + * as published by the Free Software Foundation; either version 2,
3049 + * or (at your option) any later version.
3051 + * This program is distributed in the hope that it will be useful,
3052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3054 + * GNU General Public License for more details.
3056 + * You should have received a copy of the GNU General Public License
3057 + * along with this program; if not, write to the Free Software
3058 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3063 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3064 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3067 +#ifdef SQUASHFS_TRACE
3068 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3070 +#define TRACE(s, args...) {}
3073 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3075 +#define SERROR(s, args...) do { \
3077 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3080 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3082 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3084 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3087 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3088 +#define SQSH_EXTERN
3089 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3090 + long long index, unsigned int length,
3091 + long long *next_index);
3092 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3093 + long long block, unsigned int offset,
3094 + int length, long long *next_block,
3095 + unsigned int *next_offset);
3096 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3097 + squashfs_fragment_cache *fragment);
3098 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3099 + *s, long long start_block,
3101 +extern struct address_space_operations squashfs_symlink_aops;
3102 +extern struct address_space_operations squashfs_aops;
3103 +extern struct address_space_operations squashfs_aops_4K;
3104 +extern struct inode_operations squashfs_dir_inode_ops;
3106 +#define SQSH_EXTERN static
3109 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3110 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3112 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3118 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3119 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3121 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3126 diff --new-file -urp linux-2.6.18/include/linux/squashfs_fs.h linux-2.6.18-squashfs3.1/include/linux/squashfs_fs.h
3127 --- linux-2.6.18/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3128 +++ linux-2.6.18-squashfs3.1/include/linux/squashfs_fs.h 2006-08-21 00:13:19.000000000 +0100
3130 +#ifndef SQUASHFS_FS
3131 +#define SQUASHFS_FS
3136 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3137 + * Phillip Lougher <phillip@lougher.org.uk>
3139 + * This program is free software; you can redistribute it and/or
3140 + * modify it under the terms of the GNU General Public License
3141 + * as published by the Free Software Foundation; either version 2,
3142 + * or (at your option) any later version.
3144 + * This program is distributed in the hope that it will be useful,
3145 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3146 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3147 + * GNU General Public License for more details.
3149 + * You should have received a copy of the GNU General Public License
3150 + * along with this program; if not, write to the Free Software
3151 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3156 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3157 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3160 +#ifdef CONFIG_SQUASHFS_VMALLOC
3161 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3162 +#define SQUASHFS_FREE(a) vfree(a)
3164 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3165 +#define SQUASHFS_FREE(a) kfree(a)
3167 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3168 +#define SQUASHFS_MAJOR 3
3169 +#define SQUASHFS_MINOR 0
3170 +#define SQUASHFS_MAGIC 0x73717368
3171 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3172 +#define SQUASHFS_START 0
3174 +/* size of metadata (inode and directory) blocks */
3175 +#define SQUASHFS_METADATA_SIZE 8192
3176 +#define SQUASHFS_METADATA_LOG 13
3178 +/* default size of data blocks */
3179 +#define SQUASHFS_FILE_SIZE 65536
3180 +#define SQUASHFS_FILE_LOG 16
3182 +#define SQUASHFS_FILE_MAX_SIZE 65536
3184 +/* Max number of uids and gids */
3185 +#define SQUASHFS_UIDS 256
3186 +#define SQUASHFS_GUIDS 255
3188 +/* Max length of filename (not 255) */
3189 +#define SQUASHFS_NAME_LEN 256
3191 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3192 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3193 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3194 +#define SQUASHFS_USED_BLK ((long long) -2)
3196 +/* Filesystem flags */
3197 +#define SQUASHFS_NOI 0
3198 +#define SQUASHFS_NOD 1
3199 +#define SQUASHFS_CHECK 2
3200 +#define SQUASHFS_NOF 3
3201 +#define SQUASHFS_NO_FRAG 4
3202 +#define SQUASHFS_ALWAYS_FRAG 5
3203 +#define SQUASHFS_DUPLICATE 6
3205 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3207 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3210 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3213 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3216 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3219 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3220 + SQUASHFS_ALWAYS_FRAG)
3222 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3223 + SQUASHFS_DUPLICATE)
3225 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3228 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3229 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3230 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3231 + (duplicate_checking << 6))
3233 +/* Max number of types and file types */
3234 +#define SQUASHFS_DIR_TYPE 1
3235 +#define SQUASHFS_FILE_TYPE 2
3236 +#define SQUASHFS_SYMLINK_TYPE 3
3237 +#define SQUASHFS_BLKDEV_TYPE 4
3238 +#define SQUASHFS_CHRDEV_TYPE 5
3239 +#define SQUASHFS_FIFO_TYPE 6
3240 +#define SQUASHFS_SOCKET_TYPE 7
3241 +#define SQUASHFS_LDIR_TYPE 8
3242 +#define SQUASHFS_LREG_TYPE 9
3244 +/* 1.0 filesystem type definitions */
3245 +#define SQUASHFS_TYPES 5
3246 +#define SQUASHFS_IPC_TYPE 0
3248 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3250 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3252 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3253 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3255 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3257 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3259 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3260 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3261 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3263 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3266 + * Inode number ops. Inodes consist of a compressed block number, and an
3267 + * uncompressed offset within that block
3269 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3271 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3273 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3276 +/* Compute 32 bit VFS inode number from squashfs inode number */
3277 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3281 +/* Translate between VFS mode and squashfs mode */
3282 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3284 +/* fragment and fragment table defines */
3285 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3287 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3288 + SQUASHFS_METADATA_SIZE)
3290 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3291 + SQUASHFS_METADATA_SIZE)
3293 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3294 + SQUASHFS_METADATA_SIZE - 1) / \
3295 + SQUASHFS_METADATA_SIZE)
3297 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3298 + sizeof(long long))
3300 +/* cached data constants for filesystem */
3301 +#define SQUASHFS_CACHED_BLKS 8
3303 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3305 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3306 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3308 +#define SQUASHFS_MARKER_BYTE 0xff
3310 +/* meta index cache */
3311 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3312 +#define SQUASHFS_META_ENTRIES 31
3313 +#define SQUASHFS_META_NUMBER 8
3314 +#define SQUASHFS_SLOTS 4
3316 +struct meta_entry {
3317 + long long data_block;
3318 + unsigned int index_block;
3319 + unsigned short offset;
3320 + unsigned short pad;
3323 +struct meta_index {
3324 + unsigned int inode_number;
3325 + unsigned int offset;
3326 + unsigned short entries;
3327 + unsigned short skip;
3328 + unsigned short locked;
3329 + unsigned short pad;
3330 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3335 + * definitions for structures on disk
3338 +typedef long long squashfs_block_t;
3339 +typedef long long squashfs_inode_t;
3341 +struct squashfs_super_block {
3342 + unsigned int s_magic;
3343 + unsigned int inodes;
3344 + unsigned int bytes_used_2;
3345 + unsigned int uid_start_2;
3346 + unsigned int guid_start_2;
3347 + unsigned int inode_table_start_2;
3348 + unsigned int directory_table_start_2;
3349 + unsigned int s_major:16;
3350 + unsigned int s_minor:16;
3351 + unsigned int block_size_1:16;
3352 + unsigned int block_log:16;
3353 + unsigned int flags:8;
3354 + unsigned int no_uids:8;
3355 + unsigned int no_guids:8;
3356 + unsigned int mkfs_time /* time of filesystem creation */;
3357 + squashfs_inode_t root_inode;
3358 + unsigned int block_size;
3359 + unsigned int fragments;
3360 + unsigned int fragment_table_start_2;
3361 + long long bytes_used;
3362 + long long uid_start;
3363 + long long guid_start;
3364 + long long inode_table_start;
3365 + long long directory_table_start;
3366 + long long fragment_table_start;
3368 +} __attribute__ ((packed));
3370 +struct squashfs_dir_index {
3371 + unsigned int index;
3372 + unsigned int start_block;
3373 + unsigned char size;
3374 + unsigned char name[0];
3375 +} __attribute__ ((packed));
3377 +#define SQUASHFS_BASE_INODE_HEADER \
3378 + unsigned int inode_type:4; \
3379 + unsigned int mode:12; \
3380 + unsigned int uid:8; \
3381 + unsigned int guid:8; \
3382 + unsigned int mtime; \
3383 + unsigned int inode_number;
3385 +struct squashfs_base_inode_header {
3386 + SQUASHFS_BASE_INODE_HEADER;
3387 +} __attribute__ ((packed));
3389 +struct squashfs_ipc_inode_header {
3390 + SQUASHFS_BASE_INODE_HEADER;
3391 + unsigned int nlink;
3392 +} __attribute__ ((packed));
3394 +struct squashfs_dev_inode_header {
3395 + SQUASHFS_BASE_INODE_HEADER;
3396 + unsigned int nlink;
3397 + unsigned short rdev;
3398 +} __attribute__ ((packed));
3400 +struct squashfs_symlink_inode_header {
3401 + SQUASHFS_BASE_INODE_HEADER;
3402 + unsigned int nlink;
3403 + unsigned short symlink_size;
3405 +} __attribute__ ((packed));
3407 +struct squashfs_reg_inode_header {
3408 + SQUASHFS_BASE_INODE_HEADER;
3409 + squashfs_block_t start_block;
3410 + unsigned int fragment;
3411 + unsigned int offset;
3412 + unsigned int file_size;
3413 + unsigned short block_list[0];
3414 +} __attribute__ ((packed));
3416 +struct squashfs_lreg_inode_header {
3417 + SQUASHFS_BASE_INODE_HEADER;
3418 + unsigned int nlink;
3419 + squashfs_block_t start_block;
3420 + unsigned int fragment;
3421 + unsigned int offset;
3422 + long long file_size;
3423 + unsigned short block_list[0];
3424 +} __attribute__ ((packed));
3426 +struct squashfs_dir_inode_header {
3427 + SQUASHFS_BASE_INODE_HEADER;
3428 + unsigned int nlink;
3429 + unsigned int file_size:19;
3430 + unsigned int offset:13;
3431 + unsigned int start_block;
3432 + unsigned int parent_inode;
3433 +} __attribute__ ((packed));
3435 +struct squashfs_ldir_inode_header {
3436 + SQUASHFS_BASE_INODE_HEADER;
3437 + unsigned int nlink;
3438 + unsigned int file_size:27;
3439 + unsigned int offset:13;
3440 + unsigned int start_block;
3441 + unsigned int i_count:16;
3442 + unsigned int parent_inode;
3443 + struct squashfs_dir_index index[0];
3444 +} __attribute__ ((packed));
3446 +union squashfs_inode_header {
3447 + struct squashfs_base_inode_header base;
3448 + struct squashfs_dev_inode_header dev;
3449 + struct squashfs_symlink_inode_header symlink;
3450 + struct squashfs_reg_inode_header reg;
3451 + struct squashfs_lreg_inode_header lreg;
3452 + struct squashfs_dir_inode_header dir;
3453 + struct squashfs_ldir_inode_header ldir;
3454 + struct squashfs_ipc_inode_header ipc;
3457 +struct squashfs_dir_entry {
3458 + unsigned int offset:13;
3459 + unsigned int type:3;
3460 + unsigned int size:8;
3461 + int inode_number:16;
3463 +} __attribute__ ((packed));
3465 +struct squashfs_dir_header {
3466 + unsigned int count:8;
3467 + unsigned int start_block;
3468 + unsigned int inode_number;
3469 +} __attribute__ ((packed));
3471 +struct squashfs_fragment_entry {
3472 + long long start_block;
3473 + unsigned int size;
3474 + unsigned int unused;
3475 +} __attribute__ ((packed));
3477 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3478 +extern int squashfs_uncompress_init(void);
3479 +extern int squashfs_uncompress_exit(void);
3482 + * macros to convert each packed bitfield structure from little endian to big
3483 + * endian and vice versa. These are needed when creating or using a filesystem
3484 + * on a machine with different byte ordering to the target architecture.
3488 +#define SQUASHFS_SWAP_START \
3491 + unsigned long long val;\
3492 + unsigned char *s;\
3495 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3496 + SQUASHFS_SWAP_START\
3497 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3498 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3499 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3500 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3501 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3502 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3503 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3504 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3505 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3506 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3507 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3508 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3509 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3510 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3511 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3512 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3513 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3514 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3515 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3516 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3517 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3518 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3519 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3520 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3521 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3522 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3523 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3526 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3527 + SQUASHFS_MEMSET(s, d, n);\
3528 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3529 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3530 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3531 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3532 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3533 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3535 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3536 + SQUASHFS_SWAP_START\
3537 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3540 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3541 + SQUASHFS_SWAP_START\
3542 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3543 + sizeof(struct squashfs_ipc_inode_header))\
3544 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3547 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3548 + SQUASHFS_SWAP_START\
3549 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 + sizeof(struct squashfs_dev_inode_header)); \
3551 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3555 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3556 + SQUASHFS_SWAP_START\
3557 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3558 + sizeof(struct squashfs_symlink_inode_header));\
3559 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3560 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3563 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3564 + SQUASHFS_SWAP_START\
3565 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3566 + sizeof(struct squashfs_reg_inode_header));\
3567 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3568 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3569 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3570 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3573 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3574 + SQUASHFS_SWAP_START\
3575 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3576 + sizeof(struct squashfs_lreg_inode_header));\
3577 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3578 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3579 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3580 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3581 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3584 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3585 + SQUASHFS_SWAP_START\
3586 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3587 + sizeof(struct squashfs_dir_inode_header));\
3588 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3589 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3590 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3591 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3592 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3595 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3596 + SQUASHFS_SWAP_START\
3597 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3598 + sizeof(struct squashfs_ldir_inode_header));\
3599 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3600 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3601 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3602 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3603 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3604 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3607 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3608 + SQUASHFS_SWAP_START\
3609 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3610 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3611 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3612 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3615 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3616 + SQUASHFS_SWAP_START\
3617 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3618 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3619 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3620 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3623 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3624 + SQUASHFS_SWAP_START\
3625 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3626 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3627 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3628 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3629 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3632 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3633 + SQUASHFS_SWAP_START\
3634 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3635 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3636 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3639 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3641 + int bit_position;\
3642 + SQUASHFS_SWAP_START\
3643 + SQUASHFS_MEMSET(s, d, n * 2);\
3644 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3646 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3649 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3651 + int bit_position;\
3652 + SQUASHFS_SWAP_START\
3653 + SQUASHFS_MEMSET(s, d, n * 4);\
3654 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3656 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3659 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3661 + int bit_position;\
3662 + SQUASHFS_SWAP_START\
3663 + SQUASHFS_MEMSET(s, d, n * 8);\
3664 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3666 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3669 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3671 + int bit_position;\
3672 + SQUASHFS_SWAP_START\
3673 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3674 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3676 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3679 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3681 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3683 +struct squashfs_base_inode_header_1 {
3684 + unsigned int inode_type:4;
3685 + unsigned int mode:12; /* protection */
3686 + unsigned int uid:4; /* index into uid table */
3687 + unsigned int guid:4; /* index into guid table */
3688 +} __attribute__ ((packed));
3690 +struct squashfs_ipc_inode_header_1 {
3691 + unsigned int inode_type:4;
3692 + unsigned int mode:12; /* protection */
3693 + unsigned int uid:4; /* index into uid table */
3694 + unsigned int guid:4; /* index into guid table */
3695 + unsigned int type:4;
3696 + unsigned int offset:4;
3697 +} __attribute__ ((packed));
3699 +struct squashfs_dev_inode_header_1 {
3700 + unsigned int inode_type:4;
3701 + unsigned int mode:12; /* protection */
3702 + unsigned int uid:4; /* index into uid table */
3703 + unsigned int guid:4; /* index into guid table */
3704 + unsigned short rdev;
3705 +} __attribute__ ((packed));
3707 +struct squashfs_symlink_inode_header_1 {
3708 + unsigned int inode_type:4;
3709 + unsigned int mode:12; /* protection */
3710 + unsigned int uid:4; /* index into uid table */
3711 + unsigned int guid:4; /* index into guid table */
3712 + unsigned short symlink_size;
3714 +} __attribute__ ((packed));
3716 +struct squashfs_reg_inode_header_1 {
3717 + unsigned int inode_type:4;
3718 + unsigned int mode:12; /* protection */
3719 + unsigned int uid:4; /* index into uid table */
3720 + unsigned int guid:4; /* index into guid table */
3721 + unsigned int mtime;
3722 + unsigned int start_block;
3723 + unsigned int file_size:32;
3724 + unsigned short block_list[0];
3725 +} __attribute__ ((packed));
3727 +struct squashfs_dir_inode_header_1 {
3728 + unsigned int inode_type:4;
3729 + unsigned int mode:12; /* protection */
3730 + unsigned int uid:4; /* index into uid table */
3731 + unsigned int guid:4; /* index into guid table */
3732 + unsigned int file_size:19;
3733 + unsigned int offset:13;
3734 + unsigned int mtime;
3735 + unsigned int start_block:24;
3736 +} __attribute__ ((packed));
3738 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3739 + SQUASHFS_MEMSET(s, d, n);\
3740 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3741 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3742 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3743 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3745 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3746 + SQUASHFS_SWAP_START\
3747 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3750 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3751 + SQUASHFS_SWAP_START\
3752 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3753 + sizeof(struct squashfs_ipc_inode_header_1));\
3754 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3755 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3758 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3759 + SQUASHFS_SWAP_START\
3760 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3761 + sizeof(struct squashfs_dev_inode_header_1));\
3762 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3765 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3766 + SQUASHFS_SWAP_START\
3767 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3768 + sizeof(struct squashfs_symlink_inode_header_1));\
3769 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3772 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3773 + SQUASHFS_SWAP_START\
3774 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3775 + sizeof(struct squashfs_reg_inode_header_1));\
3776 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3777 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3778 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3781 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3782 + SQUASHFS_SWAP_START\
3783 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3784 + sizeof(struct squashfs_dir_inode_header_1));\
3785 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3786 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3787 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3788 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3793 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3795 +struct squashfs_dir_index_2 {
3796 + unsigned int index:27;
3797 + unsigned int start_block:29;
3798 + unsigned char size;
3799 + unsigned char name[0];
3800 +} __attribute__ ((packed));
3802 +struct squashfs_base_inode_header_2 {
3803 + unsigned int inode_type:4;
3804 + unsigned int mode:12; /* protection */
3805 + unsigned int uid:8; /* index into uid table */
3806 + unsigned int guid:8; /* index into guid table */
3807 +} __attribute__ ((packed));
3809 +struct squashfs_ipc_inode_header_2 {
3810 + unsigned int inode_type:4;
3811 + unsigned int mode:12; /* protection */
3812 + unsigned int uid:8; /* index into uid table */
3813 + unsigned int guid:8; /* index into guid table */
3814 +} __attribute__ ((packed));
3816 +struct squashfs_dev_inode_header_2 {
3817 + unsigned int inode_type:4;
3818 + unsigned int mode:12; /* protection */
3819 + unsigned int uid:8; /* index into uid table */
3820 + unsigned int guid:8; /* index into guid table */
3821 + unsigned short rdev;
3822 +} __attribute__ ((packed));
3824 +struct squashfs_symlink_inode_header_2 {
3825 + unsigned int inode_type:4;
3826 + unsigned int mode:12; /* protection */
3827 + unsigned int uid:8; /* index into uid table */
3828 + unsigned int guid:8; /* index into guid table */
3829 + unsigned short symlink_size;
3831 +} __attribute__ ((packed));
3833 +struct squashfs_reg_inode_header_2 {
3834 + unsigned int inode_type:4;
3835 + unsigned int mode:12; /* protection */
3836 + unsigned int uid:8; /* index into uid table */
3837 + unsigned int guid:8; /* index into guid table */
3838 + unsigned int mtime;
3839 + unsigned int start_block;
3840 + unsigned int fragment;
3841 + unsigned int offset;
3842 + unsigned int file_size:32;
3843 + unsigned short block_list[0];
3844 +} __attribute__ ((packed));
3846 +struct squashfs_dir_inode_header_2 {
3847 + unsigned int inode_type:4;
3848 + unsigned int mode:12; /* protection */
3849 + unsigned int uid:8; /* index into uid table */
3850 + unsigned int guid:8; /* index into guid table */
3851 + unsigned int file_size:19;
3852 + unsigned int offset:13;
3853 + unsigned int mtime;
3854 + unsigned int start_block:24;
3855 +} __attribute__ ((packed));
3857 +struct squashfs_ldir_inode_header_2 {
3858 + unsigned int inode_type:4;
3859 + unsigned int mode:12; /* protection */
3860 + unsigned int uid:8; /* index into uid table */
3861 + unsigned int guid:8; /* index into guid table */
3862 + unsigned int file_size:27;
3863 + unsigned int offset:13;
3864 + unsigned int mtime;
3865 + unsigned int start_block:24;
3866 + unsigned int i_count:16;
3867 + struct squashfs_dir_index_2 index[0];
3868 +} __attribute__ ((packed));
3870 +union squashfs_inode_header_2 {
3871 + struct squashfs_base_inode_header_2 base;
3872 + struct squashfs_dev_inode_header_2 dev;
3873 + struct squashfs_symlink_inode_header_2 symlink;
3874 + struct squashfs_reg_inode_header_2 reg;
3875 + struct squashfs_dir_inode_header_2 dir;
3876 + struct squashfs_ldir_inode_header_2 ldir;
3877 + struct squashfs_ipc_inode_header_2 ipc;
3880 +struct squashfs_dir_header_2 {
3881 + unsigned int count:8;
3882 + unsigned int start_block:24;
3883 +} __attribute__ ((packed));
3885 +struct squashfs_dir_entry_2 {
3886 + unsigned int offset:13;
3887 + unsigned int type:3;
3888 + unsigned int size:8;
3890 +} __attribute__ ((packed));
3892 +struct squashfs_fragment_entry_2 {
3893 + unsigned int start_block;
3894 + unsigned int size;
3895 +} __attribute__ ((packed));
3897 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3898 + SQUASHFS_MEMSET(s, d, n);\
3899 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3900 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3901 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3902 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3904 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3905 + SQUASHFS_SWAP_START\
3906 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3909 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3910 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3912 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3913 + SQUASHFS_SWAP_START\
3914 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3915 + sizeof(struct squashfs_dev_inode_header_2)); \
3916 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3919 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3920 + SQUASHFS_SWAP_START\
3921 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3922 + sizeof(struct squashfs_symlink_inode_header_2));\
3923 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3926 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3927 + SQUASHFS_SWAP_START\
3928 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3929 + sizeof(struct squashfs_reg_inode_header_2));\
3930 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3931 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3932 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3933 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3934 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3937 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3938 + SQUASHFS_SWAP_START\
3939 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3940 + sizeof(struct squashfs_dir_inode_header_2));\
3941 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3942 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3943 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3944 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3947 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3948 + SQUASHFS_SWAP_START\
3949 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3950 + sizeof(struct squashfs_ldir_inode_header_2));\
3951 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3952 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3953 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3954 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3955 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3958 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3959 + SQUASHFS_SWAP_START\
3960 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3961 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3962 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3963 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3965 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3966 + SQUASHFS_SWAP_START\
3967 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3968 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3969 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3972 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3973 + SQUASHFS_SWAP_START\
3974 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3975 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3976 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3977 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3980 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3981 + SQUASHFS_SWAP_START\
3982 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3983 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3984 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3987 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3989 +/* fragment and fragment table defines */
3990 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3992 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3993 + SQUASHFS_METADATA_SIZE)
3995 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3996 + SQUASHFS_METADATA_SIZE)
3998 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3999 + SQUASHFS_METADATA_SIZE - 1) / \
4000 + SQUASHFS_METADATA_SIZE)
4002 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4010 + * macros used to swap each structure entry, taking into account
4011 + * bitfields and different bitfield placing conventions on differing
4015 +#include <asm/byteorder.h>
4017 +#ifdef __BIG_ENDIAN
4018 + /* convert from little endian to big endian */
4019 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4022 + /* convert from big endian to little endian */
4023 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4024 + tbits, 64 - tbits - b_pos)
4027 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4030 + s = (unsigned char *)p + (pos / 8);\
4031 + d = ((unsigned char *) &val) + 7;\
4032 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4034 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4037 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4041 diff --new-file -urp linux-2.6.18/include/linux/squashfs_fs_i.h linux-2.6.18-squashfs3.1/include/linux/squashfs_fs_i.h
4042 --- linux-2.6.18/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4043 +++ linux-2.6.18-squashfs3.1/include/linux/squashfs_fs_i.h 2006-08-21 00:13:19.000000000 +0100
4045 +#ifndef SQUASHFS_FS_I
4046 +#define SQUASHFS_FS_I
4050 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4051 + * Phillip Lougher <phillip@lougher.org.uk>
4053 + * This program is free software; you can redistribute it and/or
4054 + * modify it under the terms of the GNU General Public License
4055 + * as published by the Free Software Foundation; either version 2,
4056 + * or (at your option) any later version.
4058 + * This program is distributed in the hope that it will be useful,
4059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4061 + * GNU General Public License for more details.
4063 + * You should have received a copy of the GNU General Public License
4064 + * along with this program; if not, write to the Free Software
4065 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4070 +struct squashfs_inode_info {
4071 + long long start_block;
4072 + unsigned int offset;
4075 + long long fragment_start_block;
4076 + unsigned int fragment_size;
4077 + unsigned int fragment_offset;
4078 + long long block_list_start;
4081 + long long directory_index_start;
4082 + unsigned int directory_index_offset;
4083 + unsigned int directory_index_count;
4084 + unsigned int parent_inode;
4087 + struct inode vfs_inode;
4090 diff --new-file -urp linux-2.6.18/include/linux/squashfs_fs_sb.h linux-2.6.18-squashfs3.1/include/linux/squashfs_fs_sb.h
4091 --- linux-2.6.18/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4092 +++ linux-2.6.18-squashfs3.1/include/linux/squashfs_fs_sb.h 2006-08-21 00:16:48.000000000 +0100
4094 +#ifndef SQUASHFS_FS_SB
4095 +#define SQUASHFS_FS_SB
4099 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4100 + * Phillip Lougher <phillip@lougher.org.uk>
4102 + * This program is free software; you can redistribute it and/or
4103 + * modify it under the terms of the GNU General Public License
4104 + * as published by the Free Software Foundation; either version 2,
4105 + * or (at your option) any later version.
4107 + * This program is distributed in the hope that it will be useful,
4108 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4109 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4110 + * GNU General Public License for more details.
4112 + * You should have received a copy of the GNU General Public License
4113 + * along with this program; if not, write to the Free Software
4114 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4116 + * squashfs_fs_sb.h
4119 +#include <linux/squashfs_fs.h>
4121 +struct squashfs_cache {
4124 + long long next_index;
4128 +struct squashfs_fragment_cache {
4131 + unsigned int locked;
4135 +struct squashfs_sb_info {
4136 + struct squashfs_super_block sblk;
4138 + int devblksize_log2;
4140 + struct squashfs_cache *block_cache;
4141 + struct squashfs_fragment_cache *fragment;
4143 + int next_fragment;
4144 + int next_meta_index;
4145 + unsigned int *uid;
4146 + unsigned int *guid;
4147 + long long *fragment_index;
4148 + unsigned int *fragment_index_2;
4149 + unsigned int read_size;
4152 + struct semaphore read_data_mutex;
4153 + struct semaphore read_page_mutex;
4154 + struct semaphore block_cache_mutex;
4155 + struct semaphore fragment_mutex;
4156 + struct semaphore meta_index_mutex;
4157 + wait_queue_head_t waitq;
4158 + wait_queue_head_t fragment_wait_queue;
4159 + struct meta_index *meta_index;
4161 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t
4163 + long long (*read_blocklist)(struct inode *inode, int
4164 + index, int readahead_blks, char *block_list,
4165 + unsigned short **block_p, unsigned int *bsize);
4166 + int (*read_fragment_index_table)(struct super_block *s);
4169 diff --new-file -urp linux-2.6.18/init/do_mounts_rd.c linux-2.6.18-squashfs3.1/init/do_mounts_rd.c
4170 --- linux-2.6.18/init/do_mounts_rd.c 2006-08-11 00:03:15.000000000 +0100
4171 +++ linux-2.6.18-squashfs3.1/init/do_mounts_rd.c 2006-08-21 00:13:19.000000000 +0100
4173 #include <linux/ext2_fs.h>
4174 #include <linux/romfs_fs.h>
4175 #include <linux/cramfs_fs.h>
4176 +#include <linux/squashfs_fs.h>
4177 #include <linux/initrd.h>
4178 #include <linux/string.h>
4180 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4181 * numbers could not be found.
4183 * We currently check for the following magic numbers:
4188 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4189 struct ext2_super_block *ext2sb;
4190 struct romfs_super_block *romfsb;
4191 struct cramfs_super *cramfsb;
4192 + struct squashfs_super_block *squashfsb;
4196 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4197 ext2sb = (struct ext2_super_block *) buf;
4198 romfsb = (struct romfs_super_block *) buf;
4199 cramfsb = (struct cramfs_super *) buf;
4200 + squashfsb = (struct squashfs_super_block *) buf;
4201 memset(buf, 0xe5, size);
4204 @@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4208 + /* squashfs is at block zero too */
4209 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4210 + printk(KERN_NOTICE
4211 + "RAMDISK: squashfs filesystem found at block %d\n",
4213 + if (squashfsb->s_major < 3)
4214 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4216 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4221 * Read block 1 to test for minix and ext2 superblock