3 fs/squashfs/Makefile | 7
4 fs/squashfs/inode.c | 2127 +++++++++++++++++++++++++++++++++++++++++
5 fs/squashfs/squashfs.h | 86 +
6 fs/squashfs/squashfs2_0.c | 758 ++++++++++++++
7 include/linux/squashfs_fs.h | 911 +++++++++++++++++
8 include/linux/squashfs_fs_i.h | 45
9 include/linux/squashfs_fs_sb.h | 74 +
10 init/do_mounts_rd.c | 13
11 10 files changed, 4087 insertions(+)
13 Index: linux-2.6.18/fs/Kconfig
14 ===================================================================
15 --- linux-2.6.18.orig/fs/Kconfig 2006-09-20 04:42:06.000000000 +0100
16 +++ linux-2.6.18/fs/Kconfig 2006-09-20 15:45:15.000000000 +0100
17 @@ -1249,6 +1249,71 @@ config CRAMFS
22 + tristate "SquashFS 3.0 - Squashed file system support"
25 + Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
26 + System). Squashfs is a highly compressed read-only filesystem for Linux.
27 + It uses zlib compression to compress both files, inodes and directories.
28 + Inodes in the system are very small and all blocks are packed to minimise
29 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
30 + SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
31 + uid/gid information, hard links and timestamps.
33 + Squashfs is intended for general read-only filesystem use, for archival
34 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
35 + systems where low overhead is needed. Further information and filesystem tools
36 + are available from http://squashfs.sourceforge.net.
38 + If you want to compile this as a module ( = code which can be
39 + inserted in and removed from the running kernel whenever you want),
40 + say M here and read <file:Documentation/modules.txt>. The module
41 + will be called squashfs. Note that the root file system (the one
42 + containing the directory /) cannot be compiled as a module.
46 +config SQUASHFS_EMBEDDED
48 + bool "Additional options for memory-constrained systems"
52 + Saying Y here allows you to specify cache sizes and how Squashfs
53 + allocates memory. This is only intended for memory constrained
58 +config SQUASHFS_FRAGMENT_CACHE_SIZE
59 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
63 + By default SquashFS caches the last 3 fragments read from
64 + the filesystem. Increasing this amount may mean SquashFS
65 + has to re-read fragments less often from disk, at the expense
66 + of extra system memory. Decreasing this amount will mean
67 + SquashFS uses less memory at the expense of extra reads from disk.
69 + Note there must be at least one cached fragment. Anything
70 + much more than three will probably not make much difference.
72 +config SQUASHFS_VMALLOC
73 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
77 + By default SquashFS uses kmalloc to obtain fragment cache memory.
78 + Kmalloc memory is the standard kernel allocator, but it can fail
79 + on memory constrained systems. Because of the way Vmalloc works,
80 + Vmalloc can succeed when kmalloc fails. Specifying this option
81 + will make SquashFS always use Vmalloc to allocate the
82 + fragment cache memory.
87 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
89 Index: linux-2.6.18/fs/Makefile
90 ===================================================================
91 --- linux-2.6.18.orig/fs/Makefile 2006-09-20 04:42:06.000000000 +0100
92 +++ linux-2.6.18/fs/Makefile 2006-09-20 15:45:15.000000000 +0100
93 @@ -57,6 +57,7 @@ obj-$(CONFIG_EXT3_FS) += ext3/ # Before
94 obj-$(CONFIG_JBD) += jbd/
95 obj-$(CONFIG_EXT2_FS) += ext2/
96 obj-$(CONFIG_CRAMFS) += cramfs/
97 +obj-$(CONFIG_SQUASHFS) += squashfs/
98 obj-$(CONFIG_RAMFS) += ramfs/
99 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
100 obj-$(CONFIG_CODA_FS) += coda/
101 Index: linux-2.6.18/fs/squashfs/inode.c
102 ===================================================================
103 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
104 +++ linux-2.6.18/fs/squashfs/inode.c 2006-09-20 16:15:58.000000000 +0100
107 + * Squashfs - a compressed read only filesystem for Linux
109 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
110 + * Phillip Lougher <phillip@lougher.org.uk>
112 + * This program is free software; you can redistribute it and/or
113 + * modify it under the terms of the GNU General Public License
114 + * as published by the Free Software Foundation; either version 2,
115 + * or (at your option) any later version.
117 + * This program is distributed in the hope that it will be useful,
118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 + * GNU General Public License for more details.
122 + * You should have received a copy of the GNU General Public License
123 + * along with this program; if not, write to the Free Software
124 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
129 +#include <linux/types.h>
130 +#include <linux/squashfs_fs.h>
131 +#include <linux/module.h>
132 +#include <linux/errno.h>
133 +#include <linux/slab.h>
134 +#include <linux/fs.h>
135 +#include <linux/smp_lock.h>
136 +#include <linux/slab.h>
137 +#include <linux/squashfs_fs_sb.h>
138 +#include <linux/squashfs_fs_i.h>
139 +#include <linux/buffer_head.h>
140 +#include <linux/vfs.h>
141 +#include <linux/init.h>
142 +#include <linux/dcache.h>
143 +#include <linux/wait.h>
144 +#include <linux/zlib.h>
145 +#include <linux/blkdev.h>
146 +#include <linux/vmalloc.h>
147 +#include <asm/uaccess.h>
148 +#include <asm/semaphore.h>
150 +#include "squashfs.h"
152 +static void squashfs_put_super(struct super_block *);
153 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
154 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
155 +static int squashfs_readpage(struct file *file, struct page *page);
156 +static int squashfs_readpage4K(struct file *file, struct page *page);
157 +static int squashfs_readdir(struct file *, void *, filldir_t);
158 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
159 +static void squashfs_destroy_inode(struct inode *inode);
160 +static int init_inodecache(void);
161 +static void destroy_inodecache(void);
162 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
163 + struct nameidata *);
164 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
165 +static long long read_blocklist(struct inode *inode, int index,
166 + int readahead_blks, char *block_list,
167 + unsigned short **block_p, unsigned int *bsize);
168 +static struct super_block *squashfs_get_sb(struct file_system_type *, int,
169 + const char *, void *, struct vfsmount *);
172 +static z_stream stream;
174 +static struct file_system_type squashfs_fs_type = {
175 + .owner = THIS_MODULE,
176 + .name = "squashfs",
177 + .get_sb = squashfs_get_sb,
178 + .kill_sb = kill_block_super,
179 + .fs_flags = FS_REQUIRES_DEV
182 +static unsigned char squashfs_filetype_table[] = {
183 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
186 +static struct super_operations squashfs_ops = {
187 + .alloc_inode = squashfs_alloc_inode,
188 + .destroy_inode = squashfs_destroy_inode,
189 + .statfs = squashfs_statfs,
190 + .put_super = squashfs_put_super,
193 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
194 + .readpage = squashfs_symlink_readpage
197 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
198 + .readpage = squashfs_readpage
201 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
202 + .readpage = squashfs_readpage4K
205 +static struct file_operations squashfs_dir_ops = {
206 + .read = generic_read_dir,
207 + .readdir = squashfs_readdir
210 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
211 + .lookup = squashfs_lookup
215 +static struct buffer_head *get_block_length(struct super_block *s,
216 + int *cur_index, int *offset, int *c_byte)
218 + struct squashfs_sb_info *msblk = s->s_fs_info;
219 + unsigned short temp;
220 + struct buffer_head *bh;
222 + if (!(bh = sb_bread(s, *cur_index)))
225 + if (msblk->devblksize - *offset == 1) {
227 + ((unsigned char *) &temp)[1] = *((unsigned char *)
228 + (bh->b_data + *offset));
230 + ((unsigned char *) &temp)[0] = *((unsigned char *)
231 + (bh->b_data + *offset));
233 + if (!(bh = sb_bread(s, ++(*cur_index))))
236 + ((unsigned char *) &temp)[0] = *((unsigned char *)
239 + ((unsigned char *) &temp)[1] = *((unsigned char *)
245 + ((unsigned char *) &temp)[1] = *((unsigned char *)
246 + (bh->b_data + *offset));
247 + ((unsigned char *) &temp)[0] = *((unsigned char *)
248 + (bh->b_data + *offset + 1));
250 + ((unsigned char *) &temp)[0] = *((unsigned char *)
251 + (bh->b_data + *offset));
252 + ((unsigned char *) &temp)[1] = *((unsigned char *)
253 + (bh->b_data + *offset + 1));
259 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
260 + if (*offset == msblk->devblksize) {
262 + if (!(bh = sb_bread(s, ++(*cur_index))))
266 + if (*((unsigned char *) (bh->b_data + *offset)) !=
267 + SQUASHFS_MARKER_BYTE) {
268 + ERROR("Metadata block marker corrupt @ %x\n",
282 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
283 + long long index, unsigned int length,
284 + long long *next_index)
286 + struct squashfs_sb_info *msblk = s->s_fs_info;
287 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
288 + msblk->devblksize_log2) + 2];
289 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
290 + unsigned int cur_index = index >> msblk->devblksize_log2;
291 + int bytes, avail_bytes, b = 0, k;
293 + unsigned int compressed;
294 + unsigned int c_byte = length;
297 + bytes = msblk->devblksize - offset;
298 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
299 + c_buffer = compressed ? msblk->read_data : buffer;
300 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
302 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
303 + ? "" : "un", (unsigned int) c_byte);
305 + if (!(bh[0] = sb_getblk(s, cur_index)))
306 + goto block_release;
308 + for (b = 1; bytes < c_byte; b++) {
309 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
310 + goto block_release;
311 + bytes += msblk->devblksize;
313 + ll_rw_block(READ, b, bh);
315 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
319 + bytes = msblk->devblksize - offset;
320 + compressed = SQUASHFS_COMPRESSED(c_byte);
321 + c_buffer = compressed ? msblk->read_data : buffer;
322 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
324 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
325 + ? "" : "un", (unsigned int) c_byte);
327 + for (b = 1; bytes < c_byte; b++) {
328 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
329 + goto block_release;
330 + bytes += msblk->devblksize;
332 + ll_rw_block(READ, b - 1, bh + 1);
336 + down(&msblk->read_data_mutex);
338 + for (bytes = 0, k = 0; k < b; k++) {
339 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
340 + msblk->devblksize - offset :
342 + wait_on_buffer(bh[k]);
343 + if (!buffer_uptodate(bh[k]))
344 + goto block_release;
345 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
346 + bytes += avail_bytes;
357 + stream.next_in = c_buffer;
358 + stream.avail_in = c_byte;
359 + stream.next_out = buffer;
360 + stream.avail_out = msblk->read_size;
362 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
363 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
364 + != Z_STREAM_END) || ((zlib_err =
365 + zlib_inflateEnd(&stream)) != Z_OK)) {
366 + ERROR("zlib_fs returned unexpected result 0x%x\n",
370 + bytes = stream.total_out;
372 + up(&msblk->read_data_mutex);
376 + *next_index = index + c_byte + (length ? 0 :
377 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
386 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
391 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
392 + long long block, unsigned int offset,
393 + int length, long long *next_block,
394 + unsigned int *next_offset)
396 + struct squashfs_sb_info *msblk = s->s_fs_info;
397 + int n, i, bytes, return_length = length;
398 + long long next_index;
400 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
403 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
404 + if (msblk->block_cache[i].block == block)
407 + down(&msblk->block_cache_mutex);
409 + if (i == SQUASHFS_CACHED_BLKS) {
410 + /* read inode header block */
411 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
412 + n ; n --, i = (i + 1) %
413 + SQUASHFS_CACHED_BLKS)
414 + if (msblk->block_cache[i].block !=
421 + init_waitqueue_entry(&wait, current);
422 + add_wait_queue(&msblk->waitq, &wait);
423 + set_current_state(TASK_UNINTERRUPTIBLE);
424 + up(&msblk->block_cache_mutex);
426 + set_current_state(TASK_RUNNING);
427 + remove_wait_queue(&msblk->waitq, &wait);
430 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
432 + if (msblk->block_cache[i].block ==
433 + SQUASHFS_INVALID_BLK) {
434 + if (!(msblk->block_cache[i].data =
435 + kmalloc(SQUASHFS_METADATA_SIZE,
437 + ERROR("Failed to allocate cache"
439 + up(&msblk->block_cache_mutex);
444 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
445 + up(&msblk->block_cache_mutex);
447 + if (!(msblk->block_cache[i].length =
448 + squashfs_read_data(s,
449 + msblk->block_cache[i].data,
450 + block, 0, &next_index))) {
451 + ERROR("Unable to read cache block [%llx:%x]\n",
456 + down(&msblk->block_cache_mutex);
457 + wake_up(&msblk->waitq);
458 + msblk->block_cache[i].block = block;
459 + msblk->block_cache[i].next_index = next_index;
460 + TRACE("Read cache block [%llx:%x]\n", block, offset);
463 + if (msblk->block_cache[i].block != block) {
464 + up(&msblk->block_cache_mutex);
468 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
470 + memcpy(buffer, msblk->block_cache[i].data +
472 + if (msblk->block_cache[i].length - offset == length) {
473 + *next_block = msblk->block_cache[i].next_index;
476 + *next_block = block;
477 + *next_offset = offset + length;
479 + up(&msblk->block_cache_mutex);
483 + memcpy(buffer, msblk->block_cache[i].data +
487 + block = msblk->block_cache[i].next_index;
488 + up(&msblk->block_cache_mutex);
495 + return return_length;
501 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
502 + long long *fragment_start_block,
503 + unsigned int *fragment_size)
505 + struct squashfs_sb_info *msblk = s->s_fs_info;
506 + long long start_block =
507 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
508 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
509 + struct squashfs_fragment_entry fragment_entry;
512 + struct squashfs_fragment_entry sfragment_entry;
514 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
515 + start_block, offset,
516 + sizeof(sfragment_entry), &start_block,
519 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
521 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
522 + start_block, offset,
523 + sizeof(fragment_entry), &start_block,
527 + *fragment_start_block = fragment_entry.start_block;
528 + *fragment_size = fragment_entry.size;
537 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
538 + squashfs_fragment_cache *fragment)
540 + down(&msblk->fragment_mutex);
541 + fragment->locked --;
542 + wake_up(&msblk->fragment_wait_queue);
543 + up(&msblk->fragment_mutex);
547 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
548 + *s, long long start_block,
552 + struct squashfs_sb_info *msblk = s->s_fs_info;
555 + down(&msblk->fragment_mutex);
557 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
558 + msblk->fragment[i].block != start_block; i++);
560 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
561 + nf = (msblk->next_fragment + 1) %
562 + SQUASHFS_CACHED_FRAGMENTS;
563 + for (i = msblk->next_fragment, n =
564 + SQUASHFS_CACHED_FRAGMENTS; n &&
565 + msblk->fragment[i].locked; n--, i = (i + 1) %
566 + SQUASHFS_CACHED_FRAGMENTS);
571 + init_waitqueue_entry(&wait, current);
572 + add_wait_queue(&msblk->fragment_wait_queue,
574 + set_current_state(TASK_UNINTERRUPTIBLE);
575 + up(&msblk->fragment_mutex);
577 + set_current_state(TASK_RUNNING);
578 + remove_wait_queue(&msblk->fragment_wait_queue,
582 + msblk->next_fragment = nf;
584 + if (msblk->fragment[i].data == NULL)
585 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
586 + (SQUASHFS_FILE_MAX_SIZE))) {
587 + ERROR("Failed to allocate fragment "
589 + up(&msblk->fragment_mutex);
593 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
594 + msblk->fragment[i].locked = 1;
595 + up(&msblk->fragment_mutex);
597 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
598 + msblk->fragment[i].data,
599 + start_block, length, NULL))) {
600 + ERROR("Unable to read fragment cache block "
601 + "[%llx]\n", start_block);
602 + msblk->fragment[i].locked = 0;
606 + msblk->fragment[i].block = start_block;
607 + TRACE("New fragment %d, start block %lld, locked %d\n",
608 + i, msblk->fragment[i].block,
609 + msblk->fragment[i].locked);
613 + msblk->fragment[i].locked++;
614 + up(&msblk->fragment_mutex);
615 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
616 + msblk->fragment[i].block,
617 + msblk->fragment[i].locked);
621 + return &msblk->fragment[i];
628 +static struct inode *squashfs_new_inode(struct super_block *s,
629 + struct squashfs_base_inode_header *inodeb)
631 + struct squashfs_sb_info *msblk = s->s_fs_info;
632 + struct inode *i = new_inode(s);
635 + i->i_ino = inodeb->inode_number;
636 + i->i_mtime.tv_sec = inodeb->mtime;
637 + i->i_atime.tv_sec = inodeb->mtime;
638 + i->i_ctime.tv_sec = inodeb->mtime;
639 + i->i_uid = msblk->uid[inodeb->uid];
640 + i->i_mode = inodeb->mode;
642 + if (inodeb->guid == SQUASHFS_GUIDS)
643 + i->i_gid = i->i_uid;
645 + i->i_gid = msblk->guid[inodeb->guid];
652 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
655 + struct squashfs_sb_info *msblk = s->s_fs_info;
656 + struct squashfs_super_block *sblk = &msblk->sblk;
657 + long long block = SQUASHFS_INODE_BLK(inode) +
658 + sblk->inode_table_start;
659 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
660 + long long next_block;
661 + unsigned int next_offset;
662 + union squashfs_inode_header id, sid;
663 + struct squashfs_base_inode_header *inodeb = &id.base,
664 + *sinodeb = &sid.base;
666 + TRACE("Entered squashfs_iget\n");
669 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
670 + offset, sizeof(*sinodeb), &next_block,
673 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
676 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
677 + offset, sizeof(*inodeb), &next_block,
681 + switch(inodeb->inode_type) {
682 + case SQUASHFS_FILE_TYPE: {
683 + unsigned int frag_size;
684 + long long frag_blk;
685 + struct squashfs_reg_inode_header *inodep = &id.reg;
686 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
689 + if (!squashfs_get_cached_block(s, (char *)
690 + sinodep, block, offset,
691 + sizeof(*sinodep), &next_block,
694 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
696 + if (!squashfs_get_cached_block(s, (char *)
697 + inodep, block, offset,
698 + sizeof(*inodep), &next_block,
702 + frag_blk = SQUASHFS_INVALID_BLK;
703 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
704 + !get_fragment_location(s,
705 + inodep->fragment, &frag_blk, &frag_size))
708 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
712 + i->i_size = inodep->file_size;
713 + i->i_fop = &generic_ro_fops;
714 + i->i_mode |= S_IFREG;
715 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
716 + i->i_blksize = PAGE_CACHE_SIZE;
717 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
718 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
719 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
720 + SQUASHFS_I(i)->start_block = inodep->start_block;
721 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
722 + SQUASHFS_I(i)->offset = next_offset;
723 + if (sblk->block_size > 4096)
724 + i->i_data.a_ops = &squashfs_aops;
726 + i->i_data.a_ops = &squashfs_aops_4K;
728 + TRACE("File inode %x:%x, start_block %llx, "
729 + "block_list_start %llx, offset %x\n",
730 + SQUASHFS_INODE_BLK(inode), offset,
731 + inodep->start_block, next_block,
735 + case SQUASHFS_LREG_TYPE: {
736 + unsigned int frag_size;
737 + long long frag_blk;
738 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
739 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
742 + if (!squashfs_get_cached_block(s, (char *)
743 + sinodep, block, offset,
744 + sizeof(*sinodep), &next_block,
747 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
749 + if (!squashfs_get_cached_block(s, (char *)
750 + inodep, block, offset,
751 + sizeof(*inodep), &next_block,
755 + frag_blk = SQUASHFS_INVALID_BLK;
756 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
757 + !get_fragment_location(s,
758 + inodep->fragment, &frag_blk, &frag_size))
761 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
764 + i->i_nlink = inodep->nlink;
765 + i->i_size = inodep->file_size;
766 + i->i_fop = &generic_ro_fops;
767 + i->i_mode |= S_IFREG;
768 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
769 + i->i_blksize = PAGE_CACHE_SIZE;
770 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
771 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
772 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
773 + SQUASHFS_I(i)->start_block = inodep->start_block;
774 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
775 + SQUASHFS_I(i)->offset = next_offset;
776 + if (sblk->block_size > 4096)
777 + i->i_data.a_ops = &squashfs_aops;
779 + i->i_data.a_ops = &squashfs_aops_4K;
781 + TRACE("File inode %x:%x, start_block %llx, "
782 + "block_list_start %llx, offset %x\n",
783 + SQUASHFS_INODE_BLK(inode), offset,
784 + inodep->start_block, next_block,
788 + case SQUASHFS_DIR_TYPE: {
789 + struct squashfs_dir_inode_header *inodep = &id.dir;
790 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
793 + if (!squashfs_get_cached_block(s, (char *)
794 + sinodep, block, offset,
795 + sizeof(*sinodep), &next_block,
798 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
800 + if (!squashfs_get_cached_block(s, (char *)
801 + inodep, block, offset,
802 + sizeof(*inodep), &next_block,
806 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
809 + i->i_nlink = inodep->nlink;
810 + i->i_size = inodep->file_size;
811 + i->i_op = &squashfs_dir_inode_ops;
812 + i->i_fop = &squashfs_dir_ops;
813 + i->i_mode |= S_IFDIR;
814 + SQUASHFS_I(i)->start_block = inodep->start_block;
815 + SQUASHFS_I(i)->offset = inodep->offset;
816 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
817 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
819 + TRACE("Directory inode %x:%x, start_block %x, offset "
820 + "%x\n", SQUASHFS_INODE_BLK(inode),
821 + offset, inodep->start_block,
825 + case SQUASHFS_LDIR_TYPE: {
826 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
827 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
830 + if (!squashfs_get_cached_block(s, (char *)
831 + sinodep, block, offset,
832 + sizeof(*sinodep), &next_block,
835 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
838 + if (!squashfs_get_cached_block(s, (char *)
839 + inodep, block, offset,
840 + sizeof(*inodep), &next_block,
844 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
847 + i->i_nlink = inodep->nlink;
848 + i->i_size = inodep->file_size;
849 + i->i_op = &squashfs_dir_inode_ops;
850 + i->i_fop = &squashfs_dir_ops;
851 + i->i_mode |= S_IFDIR;
852 + SQUASHFS_I(i)->start_block = inodep->start_block;
853 + SQUASHFS_I(i)->offset = inodep->offset;
854 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
855 + SQUASHFS_I(i)->u.s2.directory_index_offset =
857 + SQUASHFS_I(i)->u.s2.directory_index_count =
859 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
861 + TRACE("Long directory inode %x:%x, start_block %x, "
863 + SQUASHFS_INODE_BLK(inode), offset,
864 + inodep->start_block, inodep->offset);
867 + case SQUASHFS_SYMLINK_TYPE: {
868 + struct squashfs_symlink_inode_header *inodep =
870 + struct squashfs_symlink_inode_header *sinodep =
874 + if (!squashfs_get_cached_block(s, (char *)
875 + sinodep, block, offset,
876 + sizeof(*sinodep), &next_block,
879 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
882 + if (!squashfs_get_cached_block(s, (char *)
883 + inodep, block, offset,
884 + sizeof(*inodep), &next_block,
888 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
891 + i->i_nlink = inodep->nlink;
892 + i->i_size = inodep->symlink_size;
893 + i->i_op = &page_symlink_inode_operations;
894 + i->i_data.a_ops = &squashfs_symlink_aops;
895 + i->i_mode |= S_IFLNK;
896 + SQUASHFS_I(i)->start_block = next_block;
897 + SQUASHFS_I(i)->offset = next_offset;
899 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
901 + SQUASHFS_INODE_BLK(inode), offset,
902 + next_block, next_offset);
905 + case SQUASHFS_BLKDEV_TYPE:
906 + case SQUASHFS_CHRDEV_TYPE: {
907 + struct squashfs_dev_inode_header *inodep = &id.dev;
908 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
911 + if (!squashfs_get_cached_block(s, (char *)
912 + sinodep, block, offset,
913 + sizeof(*sinodep), &next_block,
916 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
918 + if (!squashfs_get_cached_block(s, (char *)
919 + inodep, block, offset,
920 + sizeof(*inodep), &next_block,
924 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
927 + i->i_nlink = inodep->nlink;
928 + i->i_mode |= (inodeb->inode_type ==
929 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
931 + init_special_inode(i, i->i_mode,
932 + old_decode_dev(inodep->rdev));
934 + TRACE("Device inode %x:%x, rdev %x\n",
935 + SQUASHFS_INODE_BLK(inode), offset,
939 + case SQUASHFS_FIFO_TYPE:
940 + case SQUASHFS_SOCKET_TYPE: {
941 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
942 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
945 + if (!squashfs_get_cached_block(s, (char *)
946 + sinodep, block, offset,
947 + sizeof(*sinodep), &next_block,
950 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
952 + if (!squashfs_get_cached_block(s, (char *)
953 + inodep, block, offset,
954 + sizeof(*inodep), &next_block,
958 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
961 + i->i_nlink = inodep->nlink;
962 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
963 + ? S_IFIFO : S_IFSOCK;
964 + init_special_inode(i, i->i_mode, 0);
968 + ERROR("Unknown inode type %d in squashfs_iget!\n",
969 + inodeb->inode_type);
973 + insert_inode_hash(i);
977 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
984 +static int read_fragment_index_table(struct super_block *s)
986 + struct squashfs_sb_info *msblk = s->s_fs_info;
987 + struct squashfs_super_block *sblk = &msblk->sblk;
989 + /* Allocate fragment index table */
990 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
991 + (sblk->fragments), GFP_KERNEL))) {
992 + ERROR("Failed to allocate uid/gid table\n");
996 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
997 + !squashfs_read_data(s, (char *)
998 + msblk->fragment_index,
999 + sblk->fragment_table_start,
1000 + SQUASHFS_FRAGMENT_INDEX_BYTES
1001 + (sblk->fragments) |
1002 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1003 + ERROR("unable to read fragment index table\n");
1007 + if (msblk->swap) {
1009 + long long fragment;
1011 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
1013 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1014 + &msblk->fragment_index[i], 1);
1015 + msblk->fragment_index[i] = fragment;
1023 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1025 + struct squashfs_super_block *sblk = &msblk->sblk;
1027 + msblk->iget = squashfs_iget;
1028 + msblk->read_blocklist = read_blocklist;
1029 + msblk->read_fragment_index_table = read_fragment_index_table;
1031 + if (sblk->s_major == 1) {
1032 + if (!squashfs_1_0_supported(msblk)) {
1033 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1034 + "are unsupported\n");
1035 + SERROR("Please recompile with "
1036 + "Squashfs 1.0 support enabled\n");
1039 + } else if (sblk->s_major == 2) {
1040 + if (!squashfs_2_0_supported(msblk)) {
1041 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1042 + "are unsupported\n");
1043 + SERROR("Please recompile with "
1044 + "Squashfs 2.0 support enabled\n");
1047 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1049 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1050 + "filesystem\n", sblk->s_major, sblk->s_minor);
1051 + SERROR("Please update your kernel\n");
1059 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1061 + struct squashfs_sb_info *msblk;
1062 + struct squashfs_super_block *sblk;
1064 + char b[BDEVNAME_SIZE];
1065 + struct inode *root;
1067 + TRACE("Entered squashfs_read_superblock\n");
1069 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1071 + ERROR("Failed to allocate superblock\n");
1074 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1075 + msblk = s->s_fs_info;
1076 + sblk = &msblk->sblk;
1078 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1079 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1081 + init_MUTEX(&msblk->read_data_mutex);
1082 + init_MUTEX(&msblk->read_page_mutex);
1083 + init_MUTEX(&msblk->block_cache_mutex);
1084 + init_MUTEX(&msblk->fragment_mutex);
1085 + init_MUTEX(&msblk->meta_index_mutex);
1087 + init_waitqueue_head(&msblk->waitq);
1088 + init_waitqueue_head(&msblk->fragment_wait_queue);
1090 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1091 + sizeof(struct squashfs_super_block) |
1092 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1093 + SERROR("unable to read superblock\n");
1094 + goto failed_mount;
1097 + /* Check it is a SQUASHFS superblock */
1099 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1100 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1101 + struct squashfs_super_block ssblk;
1103 + WARNING("Mounting a different endian SQUASHFS "
1104 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1106 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1107 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1110 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1111 + bdevname(s->s_bdev, b));
1112 + goto failed_mount;
1116 + /* Check the MAJOR & MINOR versions */
1117 + if(!supported_squashfs_filesystem(msblk, silent))
1118 + goto failed_mount;
1120 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1121 + TRACE("Inodes are %scompressed\n",
1122 + SQUASHFS_UNCOMPRESSED_INODES
1123 + (sblk->flags) ? "un" : "");
1124 + TRACE("Data is %scompressed\n",
1125 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1127 + TRACE("Check data is %s present in the filesystem\n",
1128 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1130 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1131 + TRACE("Block size %d\n", sblk->block_size);
1132 + TRACE("Number of inodes %d\n", sblk->inodes);
1133 + if (sblk->s_major > 1)
1134 + TRACE("Number of fragments %d\n", sblk->fragments);
1135 + TRACE("Number of uids %d\n", sblk->no_uids);
1136 + TRACE("Number of gids %d\n", sblk->no_guids);
1137 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1138 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1139 + if (sblk->s_major > 1)
1140 + TRACE("sblk->fragment_table_start %llx\n",
1141 + sblk->fragment_table_start);
1142 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1144 + s->s_flags |= MS_RDONLY;
1145 + s->s_op = &squashfs_ops;
1147 + /* Init inode_table block pointer array */
1148 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1149 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1150 + ERROR("Failed to allocate block cache\n");
1151 + goto failed_mount;
1154 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1155 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1157 + msblk->next_cache = 0;
1159 + /* Allocate read_data block */
1160 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1161 + SQUASHFS_METADATA_SIZE :
1164 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1165 + ERROR("Failed to allocate read_data block\n");
1166 + goto failed_mount;
1169 + /* Allocate read_page block */
1170 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1171 + ERROR("Failed to allocate read_page block\n");
1172 + goto failed_mount;
1175 + /* Allocate uid and gid tables */
1176 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1177 + sizeof(unsigned int), GFP_KERNEL))) {
1178 + ERROR("Failed to allocate uid/gid table\n");
1179 + goto failed_mount;
1181 + msblk->guid = msblk->uid + sblk->no_uids;
1183 + if (msblk->swap) {
1184 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1186 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1187 + ((sblk->no_uids + sblk->no_guids) *
1188 + sizeof(unsigned int)) |
1189 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1190 + ERROR("unable to read uid/gid table\n");
1191 + goto failed_mount;
1194 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1195 + sblk->no_guids), (sizeof(unsigned int) * 8));
1197 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1198 + ((sblk->no_uids + sblk->no_guids) *
1199 + sizeof(unsigned int)) |
1200 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1201 + ERROR("unable to read uid/gid table\n");
1202 + goto failed_mount;
1206 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1207 + goto allocate_root;
1209 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1210 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1211 + ERROR("Failed to allocate fragment block cache\n");
1212 + goto failed_mount;
1215 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1216 + msblk->fragment[i].locked = 0;
1217 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1218 + msblk->fragment[i].data = NULL;
1221 + msblk->next_fragment = 0;
1223 + /* Allocate fragment index table */
1224 + if (msblk->read_fragment_index_table(s) == 0)
1225 + goto failed_mount;
1228 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1229 + goto failed_mount;
1231 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1232 + ERROR("Root inode create failed\n");
1234 + goto failed_mount;
1237 + TRACE("Leaving squashfs_read_super\n");
1241 + kfree(msblk->fragment_index);
1242 + kfree(msblk->fragment);
1243 + kfree(msblk->uid);
1244 + kfree(msblk->read_page);
1245 + kfree(msblk->read_data);
1246 + kfree(msblk->block_cache);
1247 + kfree(msblk->fragment_index_2);
1248 + kfree(s->s_fs_info);
1249 + s->s_fs_info = NULL;
1257 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1259 + struct squashfs_sb_info *msblk = s->s_fs_info;
1260 + struct squashfs_super_block *sblk = &msblk->sblk;
1262 + TRACE("Entered squashfs_statfs\n");
1264 + buf->f_type = SQUASHFS_MAGIC;
1265 + buf->f_bsize = sblk->block_size;
1266 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1267 + buf->f_bfree = buf->f_bavail = 0;
1268 + buf->f_files = sblk->inodes;
1270 + buf->f_namelen = SQUASHFS_NAME_LEN;
1276 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1278 + struct inode *inode = page->mapping->host;
1279 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1280 + long long block = SQUASHFS_I(inode)->start_block;
1281 + int offset = SQUASHFS_I(inode)->offset;
1282 + void *pageaddr = kmap(page);
1284 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1285 + "%llx, offset %x\n", page->index,
1286 + SQUASHFS_I(inode)->start_block,
1287 + SQUASHFS_I(inode)->offset);
1289 + for (length = 0; length < index; length += bytes) {
1290 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1291 + block, offset, PAGE_CACHE_SIZE, &block,
1293 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1299 + if (length != index) {
1300 + ERROR("(squashfs_symlink_readpage) length != index\n");
1305 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1306 + i_size_read(inode) - length;
1308 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1309 + offset, bytes, &block, &offset)))
1310 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1313 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1315 + SetPageUptodate(page);
1316 + unlock_page(page);
1322 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1324 + struct meta_index *meta = NULL;
1325 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1328 + down(&msblk->meta_index_mutex);
1330 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1332 + if(msblk->meta_index == NULL)
1333 + goto not_allocated;
1335 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1336 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1337 + msblk->meta_index[i].offset >= offset &&
1338 + msblk->meta_index[i].offset <= index &&
1339 + msblk->meta_index[i].locked == 0) {
1340 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1341 + msblk->meta_index[i].offset);
1342 + meta = &msblk->meta_index[i];
1343 + offset = meta->offset;
1350 + up(&msblk->meta_index_mutex);
1356 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1358 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1359 + struct meta_index *meta = NULL;
1362 + down(&msblk->meta_index_mutex);
1364 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1366 + if(msblk->meta_index == NULL) {
1367 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1368 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1369 + ERROR("Failed to allocate meta_index\n");
1372 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1373 + msblk->meta_index[i].inode_number = 0;
1374 + msblk->meta_index[i].locked = 0;
1376 + msblk->next_meta_index = 0;
1379 + for(i = SQUASHFS_META_NUMBER; i &&
1380 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1381 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1382 + SQUASHFS_META_NUMBER;
1385 + TRACE("empty_meta_index: failed!\n");
1389 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1390 + msblk->next_meta_index,
1391 + &msblk->meta_index[msblk->next_meta_index]);
1393 + meta = &msblk->meta_index[msblk->next_meta_index];
1394 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1395 + SQUASHFS_META_NUMBER;
1397 + meta->inode_number = inode->i_ino;
1398 + meta->offset = offset;
1399 + meta->skip = skip;
1400 + meta->entries = 0;
1404 + up(&msblk->meta_index_mutex);
1409 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1415 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1416 + long long *start_block, int *offset)
1418 + struct squashfs_sb_info *msblk = s->s_fs_info;
1419 + unsigned int *block_listp;
1422 + if (msblk->swap) {
1423 + char sblock_list[blocks << 2];
1425 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1426 + *offset, blocks << 2, start_block, offset)) {
1427 + ERROR("Unable to read block list [%llx:%x]\n",
1428 + *start_block, *offset);
1431 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1432 + ((unsigned int *)sblock_list), blocks);
1434 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1435 + *offset, blocks << 2, start_block, offset)) {
1436 + ERROR("Unable to read block list [%llx:%x]\n",
1437 + *start_block, *offset);
1441 + for (block_listp = (unsigned int *) block_list; blocks;
1442 + block_listp++, blocks --)
1443 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1454 +static inline int calculate_skip(int blocks) {
1455 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1456 + return skip >= 7 ? 7 : skip + 1;
1460 +static int get_meta_index(struct inode *inode, int index,
1461 + long long *index_block, int *index_offset,
1462 + long long *data_block, char *block_list)
1464 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1465 + struct squashfs_super_block *sblk = &msblk->sblk;
1466 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1468 + struct meta_index *meta;
1469 + struct meta_entry *meta_entry;
1470 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1471 + int cur_offset = SQUASHFS_I(inode)->offset;
1472 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1475 + index /= SQUASHFS_META_INDEXES * skip;
1477 + while ( offset < index ) {
1478 + meta = locate_meta_index(inode, index, offset + 1);
1480 + if (meta == NULL) {
1481 + if ((meta = empty_meta_index(inode, offset + 1,
1485 + offset = index < meta->offset + meta->entries ? index :
1486 + meta->offset + meta->entries - 1;
1487 + meta_entry = &meta->meta_entry[offset - meta->offset];
1488 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1489 + cur_offset = meta_entry->offset;
1490 + cur_data_block = meta_entry->data_block;
1491 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1492 + "meta->entries %d\n", offset, meta->offset,
1494 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1495 + " data_block 0x%llx\n", cur_index_block,
1496 + cur_offset, cur_data_block);
1499 + for (i = meta->offset + meta->entries; i <= index &&
1500 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1501 + int blocks = skip * SQUASHFS_META_INDEXES;
1504 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1506 + int res = read_block_index(inode->i_sb, block,
1507 + block_list, &cur_index_block,
1513 + cur_data_block += res;
1517 + meta_entry = &meta->meta_entry[i - meta->offset];
1518 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1519 + meta_entry->offset = cur_offset;
1520 + meta_entry->data_block = cur_data_block;
1525 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1526 + meta->offset, meta->entries);
1528 + release_meta_index(inode, meta);
1532 + *index_block = cur_index_block;
1533 + *index_offset = cur_offset;
1534 + *data_block = cur_data_block;
1536 + return offset * SQUASHFS_META_INDEXES * skip;
1539 + release_meta_index(inode, meta);
1544 +static long long read_blocklist(struct inode *inode, int index,
1545 + int readahead_blks, char *block_list,
1546 + unsigned short **block_p, unsigned int *bsize)
1548 + long long block_ptr;
1551 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1554 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1555 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1564 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1565 + int res = read_block_index(inode->i_sb, blocks, block_list,
1566 + &block_ptr, &offset);
1573 + if (read_block_index(inode->i_sb, 1, block_list,
1574 + &block_ptr, &offset) == -1)
1576 + *bsize = *((unsigned int *) block_list);
1585 +static int squashfs_readpage(struct file *file, struct page *page)
1587 + struct inode *inode = page->mapping->host;
1588 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1589 + struct squashfs_super_block *sblk = &msblk->sblk;
1590 + unsigned char block_list[SIZE];
1592 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1593 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1595 + struct squashfs_fragment_cache *fragment = NULL;
1596 + char *data_ptr = msblk->read_page;
1598 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1599 + int start_index = page->index & ~mask;
1600 + int end_index = start_index | mask;
1602 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1604 + SQUASHFS_I(inode)->start_block);
1606 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1607 + PAGE_CACHE_SHIFT))
1610 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1611 + || index < (i_size_read(inode) >>
1612 + sblk->block_log)) {
1613 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1614 + block_list, NULL, &bsize)) == 0)
1617 + down(&msblk->read_page_mutex);
1619 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1620 + block, bsize, NULL))) {
1621 + ERROR("Unable to read page, block %llx, size %x\n", block,
1623 + up(&msblk->read_page_mutex);
1627 + if ((fragment = get_cached_fragment(inode->i_sb,
1628 + SQUASHFS_I(inode)->
1629 + u.s1.fragment_start_block,
1630 + SQUASHFS_I(inode)->u.s1.fragment_size))
1632 + ERROR("Unable to read page, block %llx, size %x\n",
1633 + SQUASHFS_I(inode)->
1634 + u.s1.fragment_start_block,
1635 + (int) SQUASHFS_I(inode)->
1636 + u.s1.fragment_size);
1639 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1640 + (i_size_read(inode) & (sblk->block_size
1642 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1643 + data_ptr = fragment->data;
1646 + for (i = start_index; i <= end_index && byte_offset < bytes;
1647 + i++, byte_offset += PAGE_CACHE_SIZE) {
1648 + struct page *push_page;
1649 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1650 + PAGE_CACHE_SIZE : bytes - byte_offset;
1652 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1653 + bytes, i, byte_offset, available_bytes);
1655 + if (i == page->index) {
1656 + pageaddr = kmap_atomic(page, KM_USER0);
1657 + memcpy(pageaddr, data_ptr + byte_offset,
1659 + memset(pageaddr + available_bytes, 0,
1660 + PAGE_CACHE_SIZE - available_bytes);
1661 + kunmap_atomic(pageaddr, KM_USER0);
1662 + flush_dcache_page(page);
1663 + SetPageUptodate(page);
1664 + unlock_page(page);
1665 + } else if ((push_page =
1666 + grab_cache_page_nowait(page->mapping, i))) {
1667 + pageaddr = kmap_atomic(push_page, KM_USER0);
1669 + memcpy(pageaddr, data_ptr + byte_offset,
1671 + memset(pageaddr + available_bytes, 0,
1672 + PAGE_CACHE_SIZE - available_bytes);
1673 + kunmap_atomic(pageaddr, KM_USER0);
1674 + flush_dcache_page(push_page);
1675 + SetPageUptodate(push_page);
1676 + unlock_page(push_page);
1677 + page_cache_release(push_page);
1681 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1682 + || index < (i_size_read(inode) >>
1684 + up(&msblk->read_page_mutex);
1686 + release_cached_fragment(msblk, fragment);
1691 + pageaddr = kmap_atomic(page, KM_USER0);
1692 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1693 + kunmap_atomic(pageaddr, KM_USER0);
1694 + flush_dcache_page(page);
1695 + SetPageUptodate(page);
1696 + unlock_page(page);
1702 +static int squashfs_readpage4K(struct file *file, struct page *page)
1704 + struct inode *inode = page->mapping->host;
1705 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1706 + struct squashfs_super_block *sblk = &msblk->sblk;
1707 + unsigned char block_list[SIZE];
1709 + unsigned int bsize, bytes = 0;
1712 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1714 + SQUASHFS_I(inode)->start_block);
1716 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1717 + PAGE_CACHE_SHIFT)) {
1718 + pageaddr = kmap_atomic(page, KM_USER0);
1722 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1723 + || page->index < (i_size_read(inode) >>
1724 + sblk->block_log)) {
1725 + block = (msblk->read_blocklist)(inode, page->index, 1,
1726 + block_list, NULL, &bsize);
1728 + down(&msblk->read_page_mutex);
1729 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1731 + pageaddr = kmap_atomic(page, KM_USER0);
1733 + memcpy(pageaddr, msblk->read_page, bytes);
1735 + ERROR("Unable to read page, block %llx, size %x\n",
1737 + up(&msblk->read_page_mutex);
1739 + struct squashfs_fragment_cache *fragment =
1740 + get_cached_fragment(inode->i_sb,
1741 + SQUASHFS_I(inode)->
1742 + u.s1.fragment_start_block,
1743 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1744 + pageaddr = kmap_atomic(page, KM_USER0);
1746 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1747 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1748 + u.s1.fragment_offset, bytes);
1749 + release_cached_fragment(msblk, fragment);
1751 + ERROR("Unable to read page, block %llx, size %x\n",
1752 + SQUASHFS_I(inode)->
1753 + u.s1.fragment_start_block, (int)
1754 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1758 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1759 + kunmap_atomic(pageaddr, KM_USER0);
1760 + flush_dcache_page(page);
1761 + SetPageUptodate(page);
1762 + unlock_page(page);
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 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1828 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1829 + char str[SQUASHFS_NAME_LEN + 1];
1831 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1833 + strncpy(str, name, size);
1836 + for (i = 0; i < i_count; i++) {
1837 + if (msblk->swap) {
1838 + struct squashfs_dir_index sindex;
1839 + squashfs_get_cached_block(s, (char *) &sindex,
1840 + index_start, index_offset,
1841 + sizeof(sindex), &index_start,
1843 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1845 + squashfs_get_cached_block(s, (char *) index,
1846 + index_start, index_offset,
1847 + sizeof(struct squashfs_dir_index),
1848 + &index_start, &index_offset);
1850 + squashfs_get_cached_block(s, index->name, index_start,
1851 + index_offset, index->size + 1,
1852 + &index_start, &index_offset);
1854 + index->name[index->size + 1] = '\0';
1856 + if (strcmp(index->name, str) > 0)
1859 + length = index->index;
1860 + *next_block = index->start_block + sblk->directory_table_start;
1863 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1864 + return length + 3;
1868 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1870 + struct inode *i = file->f_dentry->d_inode;
1871 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1872 + struct squashfs_super_block *sblk = &msblk->sblk;
1873 + long long next_block = SQUASHFS_I(i)->start_block +
1874 + sblk->directory_table_start;
1875 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1877 + struct squashfs_dir_header dirh;
1878 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1879 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1881 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1883 + while(file->f_pos < 3) {
1887 + if(file->f_pos == 0) {
1894 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1896 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1897 + (unsigned int) dirent, name, size, (int)
1898 + file->f_pos, i_ino,
1899 + squashfs_filetype_table[1]);
1901 + if (filldir(dirent, name, size,
1902 + file->f_pos, i_ino,
1903 + squashfs_filetype_table[1]) < 0) {
1904 + TRACE("Filldir returned less than 0\n");
1907 + file->f_pos += size;
1911 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1912 + SQUASHFS_I(i)->u.s2.directory_index_start,
1913 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1914 + SQUASHFS_I(i)->u.s2.directory_index_count,
1917 + while (length < i_size_read(i)) {
1918 + /* read directory header */
1919 + if (msblk->swap) {
1920 + struct squashfs_dir_header sdirh;
1922 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1923 + next_block, next_offset, sizeof(sdirh),
1924 + &next_block, &next_offset))
1927 + length += sizeof(sdirh);
1928 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1930 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1931 + next_block, next_offset, sizeof(dirh),
1932 + &next_block, &next_offset))
1935 + length += sizeof(dirh);
1938 + dir_count = dirh.count + 1;
1939 + while (dir_count--) {
1940 + if (msblk->swap) {
1941 + struct squashfs_dir_entry sdire;
1942 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1943 + &sdire, next_block, next_offset,
1944 + sizeof(sdire), &next_block,
1948 + length += sizeof(sdire);
1949 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1951 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1952 + dire, next_block, next_offset,
1953 + sizeof(*dire), &next_block,
1957 + length += sizeof(*dire);
1960 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1961 + next_block, next_offset,
1962 + dire->size + 1, &next_block,
1966 + length += dire->size + 1;
1968 + if (file->f_pos >= length)
1971 + dire->name[dire->size + 1] = '\0';
1973 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1974 + (unsigned int) dirent, dire->name,
1975 + dire->size + 1, (int) file->f_pos,
1976 + dirh.start_block, dire->offset,
1977 + dirh.inode_number + dire->inode_number,
1978 + squashfs_filetype_table[dire->type]);
1980 + if (filldir(dirent, dire->name, dire->size + 1,
1982 + dirh.inode_number + dire->inode_number,
1983 + squashfs_filetype_table[dire->type])
1985 + TRACE("Filldir returned less than 0\n");
1988 + file->f_pos = length;
1997 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2003 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2004 + struct nameidata *nd)
2006 + const unsigned char *name = dentry->d_name.name;
2007 + int len = dentry->d_name.len;
2008 + struct inode *inode = NULL;
2009 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2010 + struct squashfs_super_block *sblk = &msblk->sblk;
2011 + long long next_block = SQUASHFS_I(i)->start_block +
2012 + sblk->directory_table_start;
2013 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2015 + struct squashfs_dir_header dirh;
2016 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
2017 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
2019 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2021 + if (len > SQUASHFS_NAME_LEN)
2024 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2025 + SQUASHFS_I(i)->u.s2.directory_index_start,
2026 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2027 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2030 + while (length < i_size_read(i)) {
2031 + /* read directory header */
2032 + if (msblk->swap) {
2033 + struct squashfs_dir_header sdirh;
2034 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2035 + next_block, next_offset, sizeof(sdirh),
2036 + &next_block, &next_offset))
2039 + length += sizeof(sdirh);
2040 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2042 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2043 + next_block, next_offset, sizeof(dirh),
2044 + &next_block, &next_offset))
2047 + length += sizeof(dirh);
2050 + dir_count = dirh.count + 1;
2051 + while (dir_count--) {
2052 + if (msblk->swap) {
2053 + struct squashfs_dir_entry sdire;
2054 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2055 + &sdire, next_block,next_offset,
2056 + sizeof(sdire), &next_block,
2060 + length += sizeof(sdire);
2061 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2063 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2064 + dire, next_block,next_offset,
2065 + sizeof(*dire), &next_block,
2069 + length += sizeof(*dire);
2072 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2073 + next_block, next_offset, dire->size + 1,
2074 + &next_block, &next_offset))
2077 + length += dire->size + 1;
2079 + if (name[0] < dire->name[0])
2082 + if ((len == dire->size + 1) && !strncmp(name,
2083 + dire->name, len)) {
2084 + squashfs_inode_t ino =
2085 + SQUASHFS_MKINODE(dirh.start_block,
2088 + TRACE("calling squashfs_iget for directory "
2089 + "entry %s, inode %x:%x, %d\n", name,
2090 + dirh.start_block, dire->offset,
2091 + dirh.inode_number + dire->inode_number);
2093 + inode = (msblk->iget)(i->i_sb, ino);
2101 + d_add(dentry, inode);
2102 + return ERR_PTR(0);
2105 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2111 +static void squashfs_put_super(struct super_block *s)
2115 + if (s->s_fs_info) {
2116 + struct squashfs_sb_info *sbi = s->s_fs_info;
2117 + if (sbi->block_cache)
2118 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2119 + if (sbi->block_cache[i].block !=
2120 + SQUASHFS_INVALID_BLK)
2121 + kfree(sbi->block_cache[i].data);
2122 + if (sbi->fragment)
2123 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2124 + SQUASHFS_FREE(sbi->fragment[i].data);
2125 + kfree(sbi->fragment);
2126 + kfree(sbi->block_cache);
2127 + kfree(sbi->read_data);
2128 + kfree(sbi->read_page);
2130 + kfree(sbi->fragment_index);
2131 + kfree(sbi->fragment_index_2);
2132 + kfree(sbi->meta_index);
2133 + kfree(s->s_fs_info);
2134 + s->s_fs_info = NULL;
2139 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type,
2140 + int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2142 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
2146 +static int __init init_squashfs_fs(void)
2148 + int err = init_inodecache();
2152 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2153 + "Phillip Lougher\n");
2155 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2156 + ERROR("Failed to allocate zlib workspace\n");
2157 + destroy_inodecache();
2162 + if ((err = register_filesystem(&squashfs_fs_type))) {
2163 + vfree(stream.workspace);
2164 + destroy_inodecache();
2172 +static void __exit exit_squashfs_fs(void)
2174 + vfree(stream.workspace);
2175 + unregister_filesystem(&squashfs_fs_type);
2176 + destroy_inodecache();
2180 +static kmem_cache_t * squashfs_inode_cachep;
2183 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2185 + struct squashfs_inode_info *ei;
2186 + ei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
2189 + return &ei->vfs_inode;
2193 +static void squashfs_destroy_inode(struct inode *inode)
2195 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2199 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2201 + struct squashfs_inode_info *ei = foo;
2203 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2204 + SLAB_CTOR_CONSTRUCTOR)
2205 + inode_init_once(&ei->vfs_inode);
2209 +static int __init init_inodecache(void)
2211 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2212 + sizeof(struct squashfs_inode_info),
2213 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2215 + if (squashfs_inode_cachep == NULL)
2221 +static void destroy_inodecache(void)
2223 + if (kmem_cache_destroy(squashfs_inode_cachep))
2224 + printk(KERN_INFO "squashfs_inode_cache: not all structures "
2229 +module_init(init_squashfs_fs);
2230 +module_exit(exit_squashfs_fs);
2231 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2232 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2233 Index: linux-2.6.18/fs/squashfs/Makefile
2234 ===================================================================
2235 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2236 +++ linux-2.6.18/fs/squashfs/Makefile 2006-09-20 15:45:15.000000000 +0100
2239 +# Makefile for the linux squashfs routines.
2242 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2243 +squashfs-y += inode.o
2244 +squashfs-y += squashfs2_0.o
2245 Index: linux-2.6.18/fs/squashfs/squashfs2_0.c
2246 ===================================================================
2247 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2248 +++ linux-2.6.18/fs/squashfs/squashfs2_0.c 2006-09-20 15:45:15.000000000 +0100
2251 + * Squashfs - a compressed read only filesystem for Linux
2253 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2254 + * Phillip Lougher <phillip@lougher.org.uk>
2256 + * This program is free software; you can redistribute it and/or
2257 + * modify it under the terms of the GNU General Public License
2258 + * as published by the Free Software Foundation; either version 2,
2259 + * or (at your option) any later version.
2261 + * This program is distributed in the hope that it will be useful,
2262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2264 + * GNU General Public License for more details.
2266 + * You should have received a copy of the GNU General Public License
2267 + * along with this program; if not, write to the Free Software
2268 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2273 +#include <linux/types.h>
2274 +#include <linux/squashfs_fs.h>
2275 +#include <linux/module.h>
2276 +#include <linux/errno.h>
2277 +#include <linux/slab.h>
2278 +#include <linux/fs.h>
2279 +#include <linux/smp_lock.h>
2280 +#include <linux/slab.h>
2281 +#include <linux/squashfs_fs_sb.h>
2282 +#include <linux/squashfs_fs_i.h>
2283 +#include <linux/buffer_head.h>
2284 +#include <linux/vfs.h>
2285 +#include <linux/init.h>
2286 +#include <linux/dcache.h>
2287 +#include <linux/wait.h>
2288 +#include <linux/zlib.h>
2289 +#include <linux/blkdev.h>
2290 +#include <linux/vmalloc.h>
2291 +#include <asm/uaccess.h>
2292 +#include <asm/semaphore.h>
2294 +#include "squashfs.h"
2295 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2296 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2297 + struct nameidata *);
2299 +static struct file_operations squashfs_dir_ops_2 = {
2300 + .read = generic_read_dir,
2301 + .readdir = squashfs_readdir_2
2304 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2305 + .lookup = squashfs_lookup_2
2308 +static unsigned char squashfs_filetype_table[] = {
2309 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2312 +static int read_fragment_index_table_2(struct super_block *s)
2314 + struct squashfs_sb_info *msblk = s->s_fs_info;
2315 + struct squashfs_super_block *sblk = &msblk->sblk;
2317 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2318 + (sblk->fragments), GFP_KERNEL))) {
2319 + ERROR("Failed to allocate uid/gid table\n");
2323 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2324 + !squashfs_read_data(s, (char *)
2325 + msblk->fragment_index_2,
2326 + sblk->fragment_table_start,
2327 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2328 + (sblk->fragments) |
2329 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2330 + ERROR("unable to read fragment index table\n");
2334 + if (msblk->swap) {
2336 + unsigned int fragment;
2338 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2340 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2341 + &msblk->fragment_index_2[i], 1);
2342 + msblk->fragment_index_2[i] = fragment;
2350 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2351 + long long *fragment_start_block,
2352 + unsigned int *fragment_size)
2354 + struct squashfs_sb_info *msblk = s->s_fs_info;
2355 + long long start_block =
2356 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2357 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2358 + struct squashfs_fragment_entry_2 fragment_entry;
2360 + if (msblk->swap) {
2361 + struct squashfs_fragment_entry_2 sfragment_entry;
2363 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2364 + start_block, offset,
2365 + sizeof(sfragment_entry), &start_block,
2368 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2370 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2371 + start_block, offset,
2372 + sizeof(fragment_entry), &start_block,
2376 + *fragment_start_block = fragment_entry.start_block;
2377 + *fragment_size = fragment_entry.size;
2386 +static struct inode *squashfs_new_inode(struct super_block *s,
2387 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2389 + struct squashfs_sb_info *msblk = s->s_fs_info;
2390 + struct squashfs_super_block *sblk = &msblk->sblk;
2391 + struct inode *i = new_inode(s);
2395 + i->i_mtime.tv_sec = sblk->mkfs_time;
2396 + i->i_atime.tv_sec = sblk->mkfs_time;
2397 + i->i_ctime.tv_sec = sblk->mkfs_time;
2398 + i->i_uid = msblk->uid[inodeb->uid];
2399 + i->i_mode = inodeb->mode;
2402 + if (inodeb->guid == SQUASHFS_GUIDS)
2403 + i->i_gid = i->i_uid;
2405 + i->i_gid = msblk->guid[inodeb->guid];
2412 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2415 + struct squashfs_sb_info *msblk = s->s_fs_info;
2416 + struct squashfs_super_block *sblk = &msblk->sblk;
2417 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2418 + sblk->inode_table_start;
2419 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2420 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2421 + - sblk->inode_table_start, offset);
2422 + long long next_block;
2423 + unsigned int next_offset;
2424 + union squashfs_inode_header_2 id, sid;
2425 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2426 + *sinodeb = &sid.base;
2428 + TRACE("Entered squashfs_iget\n");
2430 + if (msblk->swap) {
2431 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2432 + offset, sizeof(*sinodeb), &next_block,
2435 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2436 + sizeof(*sinodeb));
2438 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2439 + offset, sizeof(*inodeb), &next_block,
2443 + switch(inodeb->inode_type) {
2444 + case SQUASHFS_FILE_TYPE: {
2445 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2446 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2447 + long long frag_blk;
2448 + unsigned int frag_size;
2450 + if (msblk->swap) {
2451 + if (!squashfs_get_cached_block(s, (char *)
2452 + sinodep, block, offset,
2453 + sizeof(*sinodep), &next_block,
2456 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2458 + if (!squashfs_get_cached_block(s, (char *)
2459 + inodep, block, offset,
2460 + sizeof(*inodep), &next_block,
2464 + frag_blk = SQUASHFS_INVALID_BLK;
2465 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2466 + !get_fragment_location_2(s,
2467 + inodep->fragment, &frag_blk, &frag_size))
2470 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2471 + goto failed_read1;
2473 + i->i_size = inodep->file_size;
2474 + i->i_fop = &generic_ro_fops;
2475 + i->i_mode |= S_IFREG;
2476 + i->i_mtime.tv_sec = inodep->mtime;
2477 + i->i_atime.tv_sec = inodep->mtime;
2478 + i->i_ctime.tv_sec = inodep->mtime;
2479 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2480 + i->i_blksize = PAGE_CACHE_SIZE;
2481 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2482 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2483 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2484 + SQUASHFS_I(i)->start_block = inodep->start_block;
2485 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2486 + SQUASHFS_I(i)->offset = next_offset;
2487 + if (sblk->block_size > 4096)
2488 + i->i_data.a_ops = &squashfs_aops;
2490 + i->i_data.a_ops = &squashfs_aops_4K;
2492 + TRACE("File inode %x:%x, start_block %x, "
2493 + "block_list_start %llx, offset %x\n",
2494 + SQUASHFS_INODE_BLK(inode), offset,
2495 + inodep->start_block, next_block,
2499 + case SQUASHFS_DIR_TYPE: {
2500 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2501 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2503 + if (msblk->swap) {
2504 + if (!squashfs_get_cached_block(s, (char *)
2505 + sinodep, block, offset,
2506 + sizeof(*sinodep), &next_block,
2509 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2511 + if (!squashfs_get_cached_block(s, (char *)
2512 + inodep, block, offset,
2513 + sizeof(*inodep), &next_block,
2517 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2518 + goto failed_read1;
2520 + i->i_size = inodep->file_size;
2521 + i->i_op = &squashfs_dir_inode_ops_2;
2522 + i->i_fop = &squashfs_dir_ops_2;
2523 + i->i_mode |= S_IFDIR;
2524 + i->i_mtime.tv_sec = inodep->mtime;
2525 + i->i_atime.tv_sec = inodep->mtime;
2526 + i->i_ctime.tv_sec = inodep->mtime;
2527 + SQUASHFS_I(i)->start_block = inodep->start_block;
2528 + SQUASHFS_I(i)->offset = inodep->offset;
2529 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2530 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2532 + TRACE("Directory inode %x:%x, start_block %x, offset "
2533 + "%x\n", SQUASHFS_INODE_BLK(inode),
2534 + offset, inodep->start_block,
2538 + case SQUASHFS_LDIR_TYPE: {
2539 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2540 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2542 + if (msblk->swap) {
2543 + if (!squashfs_get_cached_block(s, (char *)
2544 + sinodep, block, offset,
2545 + sizeof(*sinodep), &next_block,
2548 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2551 + if (!squashfs_get_cached_block(s, (char *)
2552 + inodep, block, offset,
2553 + sizeof(*inodep), &next_block,
2557 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2558 + goto failed_read1;
2560 + i->i_size = inodep->file_size;
2561 + i->i_op = &squashfs_dir_inode_ops_2;
2562 + i->i_fop = &squashfs_dir_ops_2;
2563 + i->i_mode |= S_IFDIR;
2564 + i->i_mtime.tv_sec = inodep->mtime;
2565 + i->i_atime.tv_sec = inodep->mtime;
2566 + i->i_ctime.tv_sec = inodep->mtime;
2567 + SQUASHFS_I(i)->start_block = inodep->start_block;
2568 + SQUASHFS_I(i)->offset = inodep->offset;
2569 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2570 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2572 + SQUASHFS_I(i)->u.s2.directory_index_count =
2574 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2576 + TRACE("Long directory inode %x:%x, start_block %x, "
2578 + SQUASHFS_INODE_BLK(inode), offset,
2579 + inodep->start_block, inodep->offset);
2582 + case SQUASHFS_SYMLINK_TYPE: {
2583 + struct squashfs_symlink_inode_header_2 *inodep =
2585 + struct squashfs_symlink_inode_header_2 *sinodep =
2588 + if (msblk->swap) {
2589 + if (!squashfs_get_cached_block(s, (char *)
2590 + sinodep, block, offset,
2591 + sizeof(*sinodep), &next_block,
2594 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2597 + if (!squashfs_get_cached_block(s, (char *)
2598 + inodep, block, offset,
2599 + sizeof(*inodep), &next_block,
2603 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2604 + goto failed_read1;
2606 + i->i_size = inodep->symlink_size;
2607 + i->i_op = &page_symlink_inode_operations;
2608 + i->i_data.a_ops = &squashfs_symlink_aops;
2609 + i->i_mode |= S_IFLNK;
2610 + SQUASHFS_I(i)->start_block = next_block;
2611 + SQUASHFS_I(i)->offset = next_offset;
2613 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2615 + SQUASHFS_INODE_BLK(inode), offset,
2616 + next_block, next_offset);
2619 + case SQUASHFS_BLKDEV_TYPE:
2620 + case SQUASHFS_CHRDEV_TYPE: {
2621 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2622 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2624 + if (msblk->swap) {
2625 + if (!squashfs_get_cached_block(s, (char *)
2626 + sinodep, block, offset,
2627 + sizeof(*sinodep), &next_block,
2630 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2632 + if (!squashfs_get_cached_block(s, (char *)
2633 + inodep, block, offset,
2634 + sizeof(*inodep), &next_block,
2638 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2639 + goto failed_read1;
2641 + i->i_mode |= (inodeb->inode_type ==
2642 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2644 + init_special_inode(i, i->i_mode,
2645 + old_decode_dev(inodep->rdev));
2647 + TRACE("Device inode %x:%x, rdev %x\n",
2648 + SQUASHFS_INODE_BLK(inode), offset,
2652 + case SQUASHFS_FIFO_TYPE:
2653 + case SQUASHFS_SOCKET_TYPE: {
2654 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2655 + goto failed_read1;
2657 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2658 + ? S_IFIFO : S_IFSOCK;
2659 + init_special_inode(i, i->i_mode, 0);
2663 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2664 + inodeb->inode_type);
2665 + goto failed_read1;
2668 + insert_inode_hash(i);
2672 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2679 +static int get_dir_index_using_offset(struct super_block *s, long long
2680 + *next_block, unsigned int *next_offset,
2681 + long long index_start,
2682 + unsigned int index_offset, int i_count,
2685 + struct squashfs_sb_info *msblk = s->s_fs_info;
2686 + struct squashfs_super_block *sblk = &msblk->sblk;
2687 + int i, length = 0;
2688 + struct squashfs_dir_index_2 index;
2690 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2691 + i_count, (unsigned int) f_pos);
2696 + for (i = 0; i < i_count; i++) {
2697 + if (msblk->swap) {
2698 + struct squashfs_dir_index_2 sindex;
2699 + squashfs_get_cached_block(s, (char *) &sindex,
2700 + index_start, index_offset,
2701 + sizeof(sindex), &index_start,
2703 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2705 + squashfs_get_cached_block(s, (char *) &index,
2706 + index_start, index_offset,
2707 + sizeof(index), &index_start,
2710 + if (index.index > f_pos)
2713 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2714 + index.size + 1, &index_start,
2717 + length = index.index;
2718 + *next_block = index.start_block + sblk->directory_table_start;
2721 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2728 +static int get_dir_index_using_name(struct super_block *s, long long
2729 + *next_block, unsigned int *next_offset,
2730 + long long index_start,
2731 + unsigned int index_offset, int i_count,
2732 + const char *name, int size)
2734 + struct squashfs_sb_info *msblk = s->s_fs_info;
2735 + struct squashfs_super_block *sblk = &msblk->sblk;
2736 + int i, length = 0;
2737 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2738 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2739 + char str[SQUASHFS_NAME_LEN + 1];
2741 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2743 + strncpy(str, name, size);
2746 + for (i = 0; i < i_count; i++) {
2747 + if (msblk->swap) {
2748 + struct squashfs_dir_index_2 sindex;
2749 + squashfs_get_cached_block(s, (char *) &sindex,
2750 + index_start, index_offset,
2751 + sizeof(sindex), &index_start,
2753 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2755 + squashfs_get_cached_block(s, (char *) index,
2756 + index_start, index_offset,
2757 + sizeof(struct squashfs_dir_index_2),
2758 + &index_start, &index_offset);
2760 + squashfs_get_cached_block(s, index->name, index_start,
2761 + index_offset, index->size + 1,
2762 + &index_start, &index_offset);
2764 + index->name[index->size + 1] = '\0';
2766 + if (strcmp(index->name, str) > 0)
2769 + length = index->index;
2770 + *next_block = index->start_block + sblk->directory_table_start;
2773 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2778 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2780 + struct inode *i = file->f_dentry->d_inode;
2781 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2782 + struct squashfs_super_block *sblk = &msblk->sblk;
2783 + long long next_block = SQUASHFS_I(i)->start_block +
2784 + sblk->directory_table_start;
2785 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2787 + struct squashfs_dir_header_2 dirh;
2788 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2789 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2791 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2793 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2794 + SQUASHFS_I(i)->u.s2.directory_index_start,
2795 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2796 + SQUASHFS_I(i)->u.s2.directory_index_count,
2799 + while (length < i_size_read(i)) {
2800 + /* read directory header */
2801 + if (msblk->swap) {
2802 + struct squashfs_dir_header_2 sdirh;
2804 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2805 + next_block, next_offset, sizeof(sdirh),
2806 + &next_block, &next_offset))
2809 + length += sizeof(sdirh);
2810 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2812 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2813 + next_block, next_offset, sizeof(dirh),
2814 + &next_block, &next_offset))
2817 + length += sizeof(dirh);
2820 + dir_count = dirh.count + 1;
2821 + while (dir_count--) {
2822 + if (msblk->swap) {
2823 + struct squashfs_dir_entry_2 sdire;
2824 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2825 + &sdire, next_block, next_offset,
2826 + sizeof(sdire), &next_block,
2830 + length += sizeof(sdire);
2831 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2833 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2834 + dire, next_block, next_offset,
2835 + sizeof(*dire), &next_block,
2839 + length += sizeof(*dire);
2842 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2843 + next_block, next_offset,
2844 + dire->size + 1, &next_block,
2848 + length += dire->size + 1;
2850 + if (file->f_pos >= length)
2853 + dire->name[dire->size + 1] = '\0';
2855 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2856 + (unsigned int) dirent, dire->name,
2857 + dire->size + 1, (int) file->f_pos,
2858 + dirh.start_block, dire->offset,
2859 + squashfs_filetype_table[dire->type]);
2861 + if (filldir(dirent, dire->name, dire->size + 1,
2862 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2863 + dirh.start_block, dire->offset),
2864 + squashfs_filetype_table[dire->type])
2866 + TRACE("Filldir returned less than 0\n");
2869 + file->f_pos = length;
2878 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2884 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2885 + struct nameidata *nd)
2887 + const unsigned char *name = dentry->d_name.name;
2888 + int len = dentry->d_name.len;
2889 + struct inode *inode = NULL;
2890 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2891 + struct squashfs_super_block *sblk = &msblk->sblk;
2892 + long long next_block = SQUASHFS_I(i)->start_block +
2893 + sblk->directory_table_start;
2894 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2896 + struct squashfs_dir_header_2 dirh;
2897 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2898 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2899 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2901 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2903 + if (len > SQUASHFS_NAME_LEN)
2906 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2907 + SQUASHFS_I(i)->u.s2.directory_index_start,
2908 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2909 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2912 + while (length < i_size_read(i)) {
2913 + /* read directory header */
2914 + if (msblk->swap) {
2915 + struct squashfs_dir_header_2 sdirh;
2916 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2917 + next_block, next_offset, sizeof(sdirh),
2918 + &next_block, &next_offset))
2921 + length += sizeof(sdirh);
2922 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2924 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2925 + next_block, next_offset, sizeof(dirh),
2926 + &next_block, &next_offset))
2929 + length += sizeof(dirh);
2932 + dir_count = dirh.count + 1;
2933 + while (dir_count--) {
2934 + if (msblk->swap) {
2935 + struct squashfs_dir_entry_2 sdire;
2936 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2937 + &sdire, next_block,next_offset,
2938 + sizeof(sdire), &next_block,
2942 + length += sizeof(sdire);
2943 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2945 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2946 + dire, next_block,next_offset,
2947 + sizeof(*dire), &next_block,
2951 + length += sizeof(*dire);
2954 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2955 + next_block, next_offset, dire->size + 1,
2956 + &next_block, &next_offset))
2959 + length += dire->size + 1;
2961 + if (sorted && name[0] < dire->name[0])
2964 + if ((len == dire->size + 1) && !strncmp(name,
2965 + dire->name, len)) {
2966 + squashfs_inode_t ino =
2967 + SQUASHFS_MKINODE(dirh.start_block,
2970 + TRACE("calling squashfs_iget for directory "
2971 + "entry %s, inode %x:%x, %lld\n", name,
2972 + dirh.start_block, dire->offset, ino);
2974 + inode = (msblk->iget)(i->i_sb, ino);
2982 + d_add(dentry, inode);
2983 + return ERR_PTR(0);
2986 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2992 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2994 + struct squashfs_super_block *sblk = &msblk->sblk;
2996 + msblk->iget = squashfs_iget_2;
2997 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2999 + sblk->bytes_used = sblk->bytes_used_2;
3000 + sblk->uid_start = sblk->uid_start_2;
3001 + sblk->guid_start = sblk->guid_start_2;
3002 + sblk->inode_table_start = sblk->inode_table_start_2;
3003 + sblk->directory_table_start = sblk->directory_table_start_2;
3004 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3008 Index: linux-2.6.18/fs/squashfs/squashfs.h
3009 ===================================================================
3010 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3011 +++ linux-2.6.18/fs/squashfs/squashfs.h 2006-09-20 15:45:15.000000000 +0100
3014 + * Squashfs - a compressed read only filesystem for Linux
3016 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3017 + * Phillip Lougher <phillip@lougher.org.uk>
3019 + * This program is free software; you can redistribute it and/or
3020 + * modify it under the terms of the GNU General Public License
3021 + * as published by the Free Software Foundation; either version 2,
3022 + * or (at your option) any later version.
3024 + * This program is distributed in the hope that it will be useful,
3025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3027 + * GNU General Public License for more details.
3029 + * You should have received a copy of the GNU General Public License
3030 + * along with this program; if not, write to the Free Software
3031 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3036 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3037 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3040 +#ifdef SQUASHFS_TRACE
3041 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3043 +#define TRACE(s, args...) {}
3046 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3048 +#define SERROR(s, args...) do { \
3050 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3053 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3055 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3057 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3060 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3061 +#define SQSH_EXTERN
3062 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3063 + long long index, unsigned int length,
3064 + long long *next_index);
3065 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3066 + long long block, unsigned int offset,
3067 + int length, long long *next_block,
3068 + unsigned int *next_offset);
3069 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3070 + squashfs_fragment_cache *fragment);
3071 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3072 + *s, long long start_block,
3074 +extern struct address_space_operations squashfs_symlink_aops;
3075 +extern struct address_space_operations squashfs_aops;
3076 +extern struct address_space_operations squashfs_aops_4K;
3077 +extern struct inode_operations squashfs_dir_inode_ops;
3079 +#define SQSH_EXTERN static
3082 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3083 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3085 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3091 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3092 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3094 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3099 Index: linux-2.6.18/include/linux/squashfs_fs.h
3100 ===================================================================
3101 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3102 +++ linux-2.6.18/include/linux/squashfs_fs.h 2006-09-20 15:45:15.000000000 +0100
3104 +#ifndef SQUASHFS_FS
3105 +#define SQUASHFS_FS
3110 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3111 + * Phillip Lougher <phillip@lougher.org.uk>
3113 + * This program is free software; you can redistribute it and/or
3114 + * modify it under the terms of the GNU General Public License
3115 + * as published by the Free Software Foundation; either version 2,
3116 + * or (at your option) any later version.
3118 + * This program is distributed in the hope that it will be useful,
3119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3121 + * GNU General Public License for more details.
3123 + * You should have received a copy of the GNU General Public License
3124 + * along with this program; if not, write to the Free Software
3125 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3130 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3131 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3134 +#ifdef CONFIG_SQUASHFS_VMALLOC
3135 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3136 +#define SQUASHFS_FREE(a) vfree(a)
3138 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3139 +#define SQUASHFS_FREE(a) kfree(a)
3141 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3142 +#define SQUASHFS_MAJOR 3
3143 +#define SQUASHFS_MINOR 0
3144 +#define SQUASHFS_MAGIC 0x73717368
3145 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3146 +#define SQUASHFS_START 0
3148 +/* size of metadata (inode and directory) blocks */
3149 +#define SQUASHFS_METADATA_SIZE 8192
3150 +#define SQUASHFS_METADATA_LOG 13
3152 +/* default size of data blocks */
3153 +#define SQUASHFS_FILE_SIZE 65536
3154 +#define SQUASHFS_FILE_LOG 16
3156 +#define SQUASHFS_FILE_MAX_SIZE 65536
3158 +/* Max number of uids and gids */
3159 +#define SQUASHFS_UIDS 256
3160 +#define SQUASHFS_GUIDS 255
3162 +/* Max length of filename (not 255) */
3163 +#define SQUASHFS_NAME_LEN 256
3165 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3166 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3167 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3168 +#define SQUASHFS_USED_BLK ((long long) -2)
3170 +/* Filesystem flags */
3171 +#define SQUASHFS_NOI 0
3172 +#define SQUASHFS_NOD 1
3173 +#define SQUASHFS_CHECK 2
3174 +#define SQUASHFS_NOF 3
3175 +#define SQUASHFS_NO_FRAG 4
3176 +#define SQUASHFS_ALWAYS_FRAG 5
3177 +#define SQUASHFS_DUPLICATE 6
3179 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3181 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3184 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3187 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3190 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3193 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3194 + SQUASHFS_ALWAYS_FRAG)
3196 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3197 + SQUASHFS_DUPLICATE)
3199 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3202 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3203 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3204 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3205 + (duplicate_checking << 6))
3207 +/* Max number of types and file types */
3208 +#define SQUASHFS_DIR_TYPE 1
3209 +#define SQUASHFS_FILE_TYPE 2
3210 +#define SQUASHFS_SYMLINK_TYPE 3
3211 +#define SQUASHFS_BLKDEV_TYPE 4
3212 +#define SQUASHFS_CHRDEV_TYPE 5
3213 +#define SQUASHFS_FIFO_TYPE 6
3214 +#define SQUASHFS_SOCKET_TYPE 7
3215 +#define SQUASHFS_LDIR_TYPE 8
3216 +#define SQUASHFS_LREG_TYPE 9
3218 +/* 1.0 filesystem type definitions */
3219 +#define SQUASHFS_TYPES 5
3220 +#define SQUASHFS_IPC_TYPE 0
3222 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3224 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3226 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3227 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3229 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3231 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3233 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3234 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3235 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3237 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3240 + * Inode number ops. Inodes consist of a compressed block number, and an
3241 + * uncompressed offset within that block
3243 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3245 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3247 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3250 +/* Compute 32 bit VFS inode number from squashfs inode number */
3251 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3255 +/* Translate between VFS mode and squashfs mode */
3256 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3258 +/* fragment and fragment table defines */
3259 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3261 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3262 + SQUASHFS_METADATA_SIZE)
3264 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3265 + SQUASHFS_METADATA_SIZE)
3267 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3268 + SQUASHFS_METADATA_SIZE - 1) / \
3269 + SQUASHFS_METADATA_SIZE)
3271 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3272 + sizeof(long long))
3274 +/* cached data constants for filesystem */
3275 +#define SQUASHFS_CACHED_BLKS 8
3277 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3279 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3280 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3282 +#define SQUASHFS_MARKER_BYTE 0xff
3284 +/* meta index cache */
3285 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3286 +#define SQUASHFS_META_ENTRIES 31
3287 +#define SQUASHFS_META_NUMBER 8
3288 +#define SQUASHFS_SLOTS 4
3290 +struct meta_entry {
3291 + long long data_block;
3292 + unsigned int index_block;
3293 + unsigned short offset;
3294 + unsigned short pad;
3297 +struct meta_index {
3298 + unsigned int inode_number;
3299 + unsigned int offset;
3300 + unsigned short entries;
3301 + unsigned short skip;
3302 + unsigned short locked;
3303 + unsigned short pad;
3304 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3309 + * definitions for structures on disk
3312 +typedef long long squashfs_block_t;
3313 +typedef long long squashfs_inode_t;
3315 +struct squashfs_super_block {
3316 + unsigned int s_magic;
3317 + unsigned int inodes;
3318 + unsigned int bytes_used_2;
3319 + unsigned int uid_start_2;
3320 + unsigned int guid_start_2;
3321 + unsigned int inode_table_start_2;
3322 + unsigned int directory_table_start_2;
3323 + unsigned int s_major:16;
3324 + unsigned int s_minor:16;
3325 + unsigned int block_size_1:16;
3326 + unsigned int block_log:16;
3327 + unsigned int flags:8;
3328 + unsigned int no_uids:8;
3329 + unsigned int no_guids:8;
3330 + unsigned int mkfs_time /* time of filesystem creation */;
3331 + squashfs_inode_t root_inode;
3332 + unsigned int block_size;
3333 + unsigned int fragments;
3334 + unsigned int fragment_table_start_2;
3335 + long long bytes_used;
3336 + long long uid_start;
3337 + long long guid_start;
3338 + long long inode_table_start;
3339 + long long directory_table_start;
3340 + long long fragment_table_start;
3342 +} __attribute__ ((packed));
3344 +struct squashfs_dir_index {
3345 + unsigned int index;
3346 + unsigned int start_block;
3347 + unsigned char size;
3348 + unsigned char name[0];
3349 +} __attribute__ ((packed));
3351 +#define SQUASHFS_BASE_INODE_HEADER \
3352 + unsigned int inode_type:4; \
3353 + unsigned int mode:12; \
3354 + unsigned int uid:8; \
3355 + unsigned int guid:8; \
3356 + unsigned int mtime; \
3357 + unsigned int inode_number;
3359 +struct squashfs_base_inode_header {
3360 + SQUASHFS_BASE_INODE_HEADER;
3361 +} __attribute__ ((packed));
3363 +struct squashfs_ipc_inode_header {
3364 + SQUASHFS_BASE_INODE_HEADER;
3365 + unsigned int nlink;
3366 +} __attribute__ ((packed));
3368 +struct squashfs_dev_inode_header {
3369 + SQUASHFS_BASE_INODE_HEADER;
3370 + unsigned int nlink;
3371 + unsigned short rdev;
3372 +} __attribute__ ((packed));
3374 +struct squashfs_symlink_inode_header {
3375 + SQUASHFS_BASE_INODE_HEADER;
3376 + unsigned int nlink;
3377 + unsigned short symlink_size;
3379 +} __attribute__ ((packed));
3381 +struct squashfs_reg_inode_header {
3382 + SQUASHFS_BASE_INODE_HEADER;
3383 + squashfs_block_t start_block;
3384 + unsigned int fragment;
3385 + unsigned int offset;
3386 + unsigned int file_size;
3387 + unsigned short block_list[0];
3388 +} __attribute__ ((packed));
3390 +struct squashfs_lreg_inode_header {
3391 + SQUASHFS_BASE_INODE_HEADER;
3392 + unsigned int nlink;
3393 + squashfs_block_t start_block;
3394 + unsigned int fragment;
3395 + unsigned int offset;
3396 + long long file_size;
3397 + unsigned short block_list[0];
3398 +} __attribute__ ((packed));
3400 +struct squashfs_dir_inode_header {
3401 + SQUASHFS_BASE_INODE_HEADER;
3402 + unsigned int nlink;
3403 + unsigned int file_size:19;
3404 + unsigned int offset:13;
3405 + unsigned int start_block;
3406 + unsigned int parent_inode;
3407 +} __attribute__ ((packed));
3409 +struct squashfs_ldir_inode_header {
3410 + SQUASHFS_BASE_INODE_HEADER;
3411 + unsigned int nlink;
3412 + unsigned int file_size:27;
3413 + unsigned int offset:13;
3414 + unsigned int start_block;
3415 + unsigned int i_count:16;
3416 + unsigned int parent_inode;
3417 + struct squashfs_dir_index index[0];
3418 +} __attribute__ ((packed));
3420 +union squashfs_inode_header {
3421 + struct squashfs_base_inode_header base;
3422 + struct squashfs_dev_inode_header dev;
3423 + struct squashfs_symlink_inode_header symlink;
3424 + struct squashfs_reg_inode_header reg;
3425 + struct squashfs_lreg_inode_header lreg;
3426 + struct squashfs_dir_inode_header dir;
3427 + struct squashfs_ldir_inode_header ldir;
3428 + struct squashfs_ipc_inode_header ipc;
3431 +struct squashfs_dir_entry {
3432 + unsigned int offset:13;
3433 + unsigned int type:3;
3434 + unsigned int size:8;
3435 + int inode_number:16;
3437 +} __attribute__ ((packed));
3439 +struct squashfs_dir_header {
3440 + unsigned int count:8;
3441 + unsigned int start_block;
3442 + unsigned int inode_number;
3443 +} __attribute__ ((packed));
3445 +struct squashfs_fragment_entry {
3446 + long long start_block;
3447 + unsigned int size;
3448 + unsigned int unused;
3449 +} __attribute__ ((packed));
3451 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3452 +extern int squashfs_uncompress_init(void);
3453 +extern int squashfs_uncompress_exit(void);
3456 + * macros to convert each packed bitfield structure from little endian to big
3457 + * endian and vice versa. These are needed when creating or using a filesystem
3458 + * on a machine with different byte ordering to the target architecture.
3462 +#define SQUASHFS_SWAP_START \
3465 + unsigned long long val;\
3466 + unsigned char *s;\
3469 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3470 + SQUASHFS_SWAP_START\
3471 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3472 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3473 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3474 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3475 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3476 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3477 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3478 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3479 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3480 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3481 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3482 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3483 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3484 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3485 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3486 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3487 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3488 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3489 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3490 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3491 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3492 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3493 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3494 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3495 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3496 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3497 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3500 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3501 + SQUASHFS_MEMSET(s, d, n);\
3502 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3503 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3504 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3505 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3506 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3507 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3509 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3510 + SQUASHFS_SWAP_START\
3511 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3514 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3515 + SQUASHFS_SWAP_START\
3516 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3517 + sizeof(struct squashfs_ipc_inode_header))\
3518 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3521 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3522 + SQUASHFS_SWAP_START\
3523 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3524 + sizeof(struct squashfs_dev_inode_header)); \
3525 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3526 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3529 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3530 + SQUASHFS_SWAP_START\
3531 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3532 + sizeof(struct squashfs_symlink_inode_header));\
3533 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3534 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3537 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3538 + SQUASHFS_SWAP_START\
3539 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3540 + sizeof(struct squashfs_reg_inode_header));\
3541 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3542 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3543 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3544 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3547 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3548 + SQUASHFS_SWAP_START\
3549 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 + sizeof(struct squashfs_lreg_inode_header));\
3551 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3553 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3554 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3555 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3558 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3559 + SQUASHFS_SWAP_START\
3560 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3561 + sizeof(struct squashfs_dir_inode_header));\
3562 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3563 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3564 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3565 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3566 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3569 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3570 + SQUASHFS_SWAP_START\
3571 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3572 + sizeof(struct squashfs_ldir_inode_header));\
3573 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3574 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3575 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3576 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3577 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3578 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3581 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3582 + SQUASHFS_SWAP_START\
3583 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3584 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3585 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3586 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3589 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3590 + SQUASHFS_SWAP_START\
3591 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3592 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3593 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3594 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3597 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3598 + SQUASHFS_SWAP_START\
3599 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3600 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3601 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3602 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3603 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3606 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3609 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3610 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3613 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3615 + int bit_position;\
3616 + SQUASHFS_SWAP_START\
3617 + SQUASHFS_MEMSET(s, d, n * 2);\
3618 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3620 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3623 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3625 + int bit_position;\
3626 + SQUASHFS_SWAP_START\
3627 + SQUASHFS_MEMSET(s, d, n * 4);\
3628 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3630 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3633 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3635 + int bit_position;\
3636 + SQUASHFS_SWAP_START\
3637 + SQUASHFS_MEMSET(s, d, n * 8);\
3638 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3640 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3643 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3645 + int bit_position;\
3646 + SQUASHFS_SWAP_START\
3647 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3648 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3650 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3653 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3655 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3657 +struct squashfs_base_inode_header_1 {
3658 + unsigned int inode_type:4;
3659 + unsigned int mode:12; /* protection */
3660 + unsigned int uid:4; /* index into uid table */
3661 + unsigned int guid:4; /* index into guid table */
3662 +} __attribute__ ((packed));
3664 +struct squashfs_ipc_inode_header_1 {
3665 + unsigned int inode_type:4;
3666 + unsigned int mode:12; /* protection */
3667 + unsigned int uid:4; /* index into uid table */
3668 + unsigned int guid:4; /* index into guid table */
3669 + unsigned int type:4;
3670 + unsigned int offset:4;
3671 +} __attribute__ ((packed));
3673 +struct squashfs_dev_inode_header_1 {
3674 + unsigned int inode_type:4;
3675 + unsigned int mode:12; /* protection */
3676 + unsigned int uid:4; /* index into uid table */
3677 + unsigned int guid:4; /* index into guid table */
3678 + unsigned short rdev;
3679 +} __attribute__ ((packed));
3681 +struct squashfs_symlink_inode_header_1 {
3682 + unsigned int inode_type:4;
3683 + unsigned int mode:12; /* protection */
3684 + unsigned int uid:4; /* index into uid table */
3685 + unsigned int guid:4; /* index into guid table */
3686 + unsigned short symlink_size;
3688 +} __attribute__ ((packed));
3690 +struct squashfs_reg_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 mtime;
3696 + unsigned int start_block;
3697 + unsigned int file_size:32;
3698 + unsigned short block_list[0];
3699 +} __attribute__ ((packed));
3701 +struct squashfs_dir_inode_header_1 {
3702 + unsigned int inode_type:4;
3703 + unsigned int mode:12; /* protection */
3704 + unsigned int uid:4; /* index into uid table */
3705 + unsigned int guid:4; /* index into guid table */
3706 + unsigned int file_size:19;
3707 + unsigned int offset:13;
3708 + unsigned int mtime;
3709 + unsigned int start_block:24;
3710 +} __attribute__ ((packed));
3712 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3713 + SQUASHFS_MEMSET(s, d, n);\
3714 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3715 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3716 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3717 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3719 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3720 + SQUASHFS_SWAP_START\
3721 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3724 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3725 + SQUASHFS_SWAP_START\
3726 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3727 + sizeof(struct squashfs_ipc_inode_header_1));\
3728 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3729 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3732 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3733 + SQUASHFS_SWAP_START\
3734 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3735 + sizeof(struct squashfs_dev_inode_header_1));\
3736 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3739 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3740 + SQUASHFS_SWAP_START\
3741 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3742 + sizeof(struct squashfs_symlink_inode_header_1));\
3743 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3746 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3747 + SQUASHFS_SWAP_START\
3748 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3749 + sizeof(struct squashfs_reg_inode_header_1));\
3750 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3751 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3752 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3755 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3756 + SQUASHFS_SWAP_START\
3757 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3758 + sizeof(struct squashfs_dir_inode_header_1));\
3759 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3760 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3761 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3762 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3767 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3769 +struct squashfs_dir_index_2 {
3770 + unsigned int index:27;
3771 + unsigned int start_block:29;
3772 + unsigned char size;
3773 + unsigned char name[0];
3774 +} __attribute__ ((packed));
3776 +struct squashfs_base_inode_header_2 {
3777 + unsigned int inode_type:4;
3778 + unsigned int mode:12; /* protection */
3779 + unsigned int uid:8; /* index into uid table */
3780 + unsigned int guid:8; /* index into guid table */
3781 +} __attribute__ ((packed));
3783 +struct squashfs_ipc_inode_header_2 {
3784 + unsigned int inode_type:4;
3785 + unsigned int mode:12; /* protection */
3786 + unsigned int uid:8; /* index into uid table */
3787 + unsigned int guid:8; /* index into guid table */
3788 +} __attribute__ ((packed));
3790 +struct squashfs_dev_inode_header_2 {
3791 + unsigned int inode_type:4;
3792 + unsigned int mode:12; /* protection */
3793 + unsigned int uid:8; /* index into uid table */
3794 + unsigned int guid:8; /* index into guid table */
3795 + unsigned short rdev;
3796 +} __attribute__ ((packed));
3798 +struct squashfs_symlink_inode_header_2 {
3799 + unsigned int inode_type:4;
3800 + unsigned int mode:12; /* protection */
3801 + unsigned int uid:8; /* index into uid table */
3802 + unsigned int guid:8; /* index into guid table */
3803 + unsigned short symlink_size;
3805 +} __attribute__ ((packed));
3807 +struct squashfs_reg_inode_header_2 {
3808 + unsigned int inode_type:4;
3809 + unsigned int mode:12; /* protection */
3810 + unsigned int uid:8; /* index into uid table */
3811 + unsigned int guid:8; /* index into guid table */
3812 + unsigned int mtime;
3813 + unsigned int start_block;
3814 + unsigned int fragment;
3815 + unsigned int offset;
3816 + unsigned int file_size:32;
3817 + unsigned short block_list[0];
3818 +} __attribute__ ((packed));
3820 +struct squashfs_dir_inode_header_2 {
3821 + unsigned int inode_type:4;
3822 + unsigned int mode:12; /* protection */
3823 + unsigned int uid:8; /* index into uid table */
3824 + unsigned int guid:8; /* index into guid table */
3825 + unsigned int file_size:19;
3826 + unsigned int offset:13;
3827 + unsigned int mtime;
3828 + unsigned int start_block:24;
3829 +} __attribute__ ((packed));
3831 +struct squashfs_ldir_inode_header_2 {
3832 + unsigned int inode_type:4;
3833 + unsigned int mode:12; /* protection */
3834 + unsigned int uid:8; /* index into uid table */
3835 + unsigned int guid:8; /* index into guid table */
3836 + unsigned int file_size:27;
3837 + unsigned int offset:13;
3838 + unsigned int mtime;
3839 + unsigned int start_block:24;
3840 + unsigned int i_count:16;
3841 + struct squashfs_dir_index_2 index[0];
3842 +} __attribute__ ((packed));
3844 +union squashfs_inode_header_2 {
3845 + struct squashfs_base_inode_header_2 base;
3846 + struct squashfs_dev_inode_header_2 dev;
3847 + struct squashfs_symlink_inode_header_2 symlink;
3848 + struct squashfs_reg_inode_header_2 reg;
3849 + struct squashfs_dir_inode_header_2 dir;
3850 + struct squashfs_ldir_inode_header_2 ldir;
3851 + struct squashfs_ipc_inode_header_2 ipc;
3854 +struct squashfs_dir_header_2 {
3855 + unsigned int count:8;
3856 + unsigned int start_block:24;
3857 +} __attribute__ ((packed));
3859 +struct squashfs_dir_entry_2 {
3860 + unsigned int offset:13;
3861 + unsigned int type:3;
3862 + unsigned int size:8;
3864 +} __attribute__ ((packed));
3866 +struct squashfs_fragment_entry_2 {
3867 + unsigned int start_block;
3868 + unsigned int size;
3869 +} __attribute__ ((packed));
3871 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3872 + SQUASHFS_MEMSET(s, d, n);\
3873 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3874 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3875 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3876 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3878 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3879 + SQUASHFS_SWAP_START\
3880 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3883 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3884 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3886 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3887 + SQUASHFS_SWAP_START\
3888 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3889 + sizeof(struct squashfs_dev_inode_header_2)); \
3890 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3893 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3894 + SQUASHFS_SWAP_START\
3895 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3896 + sizeof(struct squashfs_symlink_inode_header_2));\
3897 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3900 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3901 + SQUASHFS_SWAP_START\
3902 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3903 + sizeof(struct squashfs_reg_inode_header_2));\
3904 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3905 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3906 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3907 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3908 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3911 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3912 + SQUASHFS_SWAP_START\
3913 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3914 + sizeof(struct squashfs_dir_inode_header_2));\
3915 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3916 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3917 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3918 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3921 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3922 + SQUASHFS_SWAP_START\
3923 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3924 + sizeof(struct squashfs_ldir_inode_header_2));\
3925 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3926 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3927 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3928 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3929 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3932 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3933 + SQUASHFS_SWAP_START\
3934 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3935 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3936 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3937 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3939 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3940 + SQUASHFS_SWAP_START\
3941 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3942 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3943 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3946 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3947 + SQUASHFS_SWAP_START\
3948 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3949 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3950 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3951 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3954 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3955 + SQUASHFS_SWAP_START\
3956 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3957 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3958 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3961 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3963 +/* fragment and fragment table defines */
3964 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3966 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3967 + SQUASHFS_METADATA_SIZE)
3969 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3970 + SQUASHFS_METADATA_SIZE)
3972 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3973 + SQUASHFS_METADATA_SIZE - 1) / \
3974 + SQUASHFS_METADATA_SIZE)
3976 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3984 + * macros used to swap each structure entry, taking into account
3985 + * bitfields and different bitfield placing conventions on differing
3989 +#include <asm/byteorder.h>
3991 +#ifdef __BIG_ENDIAN
3992 + /* convert from little endian to big endian */
3993 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3996 + /* convert from big endian to little endian */
3997 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3998 + tbits, 64 - tbits - b_pos)
4001 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4004 + s = (unsigned char *)p + (pos / 8);\
4005 + d = ((unsigned char *) &val) + 7;\
4006 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4008 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4011 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4015 Index: linux-2.6.18/include/linux/squashfs_fs_i.h
4016 ===================================================================
4017 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4018 +++ linux-2.6.18/include/linux/squashfs_fs_i.h 2006-09-20 15:45:15.000000000 +0100
4020 +#ifndef SQUASHFS_FS_I
4021 +#define SQUASHFS_FS_I
4025 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4026 + * Phillip Lougher <phillip@lougher.org.uk>
4028 + * This program is free software; you can redistribute it and/or
4029 + * modify it under the terms of the GNU General Public License
4030 + * as published by the Free Software Foundation; either version 2,
4031 + * or (at your option) any later version.
4033 + * This program is distributed in the hope that it will be useful,
4034 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4035 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4036 + * GNU General Public License for more details.
4038 + * You should have received a copy of the GNU General Public License
4039 + * along with this program; if not, write to the Free Software
4040 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4045 +struct squashfs_inode_info {
4046 + long long start_block;
4047 + unsigned int offset;
4050 + long long fragment_start_block;
4051 + unsigned int fragment_size;
4052 + unsigned int fragment_offset;
4053 + long long block_list_start;
4056 + long long directory_index_start;
4057 + unsigned int directory_index_offset;
4058 + unsigned int directory_index_count;
4059 + unsigned int parent_inode;
4062 + struct inode vfs_inode;
4065 Index: linux-2.6.18/include/linux/squashfs_fs_sb.h
4066 ===================================================================
4067 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4068 +++ linux-2.6.18/include/linux/squashfs_fs_sb.h 2006-09-20 15:45:15.000000000 +0100
4070 +#ifndef SQUASHFS_FS_SB
4071 +#define SQUASHFS_FS_SB
4075 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4076 + * Phillip Lougher <phillip@lougher.org.uk>
4078 + * This program is free software; you can redistribute it and/or
4079 + * modify it under the terms of the GNU General Public License
4080 + * as published by the Free Software Foundation; either version 2,
4081 + * or (at your option) any later version.
4083 + * This program is distributed in the hope that it will be useful,
4084 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4086 + * GNU General Public License for more details.
4088 + * You should have received a copy of the GNU General Public License
4089 + * along with this program; if not, write to the Free Software
4090 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4092 + * squashfs_fs_sb.h
4095 +#include <linux/squashfs_fs.h>
4097 +struct squashfs_cache {
4100 + long long next_index;
4104 +struct squashfs_fragment_cache {
4107 + unsigned int locked;
4111 +struct squashfs_sb_info {
4112 + struct squashfs_super_block sblk;
4114 + int devblksize_log2;
4116 + struct squashfs_cache *block_cache;
4117 + struct squashfs_fragment_cache *fragment;
4119 + int next_fragment;
4120 + int next_meta_index;
4121 + unsigned int *uid;
4122 + unsigned int *guid;
4123 + long long *fragment_index;
4124 + unsigned int *fragment_index_2;
4125 + unsigned int read_size;
4128 + struct semaphore read_data_mutex;
4129 + struct semaphore read_page_mutex;
4130 + struct semaphore block_cache_mutex;
4131 + struct semaphore fragment_mutex;
4132 + struct semaphore meta_index_mutex;
4133 + wait_queue_head_t waitq;
4134 + wait_queue_head_t fragment_wait_queue;
4135 + struct meta_index *meta_index;
4136 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4138 + long long (*read_blocklist)(struct inode *inode, int \
4139 + index, int readahead_blks, char *block_list, \
4140 + unsigned short **block_p, unsigned int *bsize);
4141 + int (*read_fragment_index_table)(struct super_block *s);
4144 Index: linux-2.6.18/init/do_mounts_rd.c
4145 ===================================================================
4146 --- linux-2.6.18.orig/init/do_mounts_rd.c 2006-09-20 04:42:06.000000000 +0100
4147 +++ linux-2.6.18/init/do_mounts_rd.c 2006-09-20 15:45:15.000000000 +0100
4149 #include <linux/ext2_fs.h>
4150 #include <linux/romfs_fs.h>
4151 #include <linux/cramfs_fs.h>
4152 +#include <linux/squashfs_fs.h>
4153 #include <linux/initrd.h>
4154 #include <linux/string.h>
4156 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4157 * numbers could not be found.
4159 * We currently check for the following magic numbers:
4164 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4165 struct ext2_super_block *ext2sb;
4166 struct romfs_super_block *romfsb;
4167 struct cramfs_super *cramfsb;
4168 + struct squashfs_super_block *squashfsb;
4172 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4173 ext2sb = (struct ext2_super_block *) buf;
4174 romfsb = (struct romfs_super_block *) buf;
4175 cramfsb = (struct cramfs_super *) buf;
4176 + squashfsb = (struct squashfs_super_block *) buf;
4177 memset(buf, 0xe5, size);
4180 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
4184 + /* squashfs is at block zero too */
4185 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4186 + printk(KERN_NOTICE
4187 + "RAMDISK: squashfs filesystem found at block %d\n",
4189 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4194 * Read block 1 to test for minix and ext2 superblock