1 diff -urN linux-2.6.21.1.old/fs/Kconfig linux-2.6.21.1.dev/fs/Kconfig
2 --- linux-2.6.21.1.old/fs/Kconfig 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.dev/fs/Kconfig 2007-05-26 19:00:37.121351760 +0200
9 + tristate "SquashFS 3.0 - Squashed file system support"
12 + Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
13 + System). Squashfs is a highly compressed read-only filesystem for Linux.
14 + It uses zlib compression to compress both files, inodes and directories.
15 + Inodes in the system are very small and all blocks are packed to minimise
16 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
17 + SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
18 + uid/gid information, hard links and timestamps.
20 + Squashfs is intended for general read-only filesystem use, for archival
21 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
22 + systems where low overhead is needed. Further information and filesystem tools
23 + are available from http://squashfs.sourceforge.net.
25 + If you want to compile this as a module ( = code which can be
26 + inserted in and removed from the running kernel whenever you want),
27 + say M here and read <file:Documentation/modules.txt>. The module
28 + will be called squashfs. Note that the root file system (the one
29 + containing the directory /) cannot be compiled as a module.
33 +config SQUASHFS_EMBEDDED
35 + bool "Additional options for memory-constrained systems"
39 + Saying Y here allows you to specify cache sizes and how Squashfs
40 + allocates memory. This is only intended for memory constrained
45 +config SQUASHFS_FRAGMENT_CACHE_SIZE
46 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
50 + By default SquashFS caches the last 3 fragments read from
51 + the filesystem. Increasing this amount may mean SquashFS
52 + has to re-read fragments less often from disk, at the expense
53 + of extra system memory. Decreasing this amount will mean
54 + SquashFS uses less memory at the expense of extra reads from disk.
56 + Note there must be at least one cached fragment. Anything
57 + much more than three will probably not make much difference.
59 +config SQUASHFS_VMALLOC
60 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
64 + By default SquashFS uses kmalloc to obtain fragment cache memory.
65 + Kmalloc memory is the standard kernel allocator, but it can fail
66 + on memory constrained systems. Because of the way Vmalloc works,
67 + Vmalloc can succeed when kmalloc fails. Specifying this option
68 + will make SquashFS always use Vmalloc to allocate the
69 + fragment cache memory.
74 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
76 diff -urN linux-2.6.21.1.old/fs/Makefile linux-2.6.21.1.dev/fs/Makefile
77 --- linux-2.6.21.1.old/fs/Makefile 2007-04-27 23:49:26.000000000 +0200
78 +++ linux-2.6.21.1.dev/fs/Makefile 2007-05-26 19:00:37.121351760 +0200
80 obj-$(CONFIG_JBD2) += jbd2/
81 obj-$(CONFIG_EXT2_FS) += ext2/
82 obj-$(CONFIG_CRAMFS) += cramfs/
83 +obj-$(CONFIG_SQUASHFS) += squashfs/
84 obj-$(CONFIG_RAMFS) += ramfs/
85 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
86 obj-$(CONFIG_CODA_FS) += coda/
87 diff -urN linux-2.6.21.1.old/fs/squashfs/inode.c linux-2.6.21.1.dev/fs/squashfs/inode.c
88 --- linux-2.6.21.1.old/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.21.1.dev/fs/squashfs/inode.c 2007-05-26 19:00:37.123351456 +0200
92 + * Squashfs - a compressed read only filesystem for Linux
94 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
95 + * Phillip Lougher <phillip@lougher.org.uk>
97 + * This program is free software; you can redistribute it and/or
98 + * modify it under the terms of the GNU General Public License
99 + * as published by the Free Software Foundation; either version 2,
100 + * or (at your option) any later version.
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
114 +#include <linux/types.h>
115 +#include <linux/squashfs_fs.h>
116 +#include <linux/module.h>
117 +#include <linux/errno.h>
118 +#include <linux/slab.h>
119 +#include <linux/fs.h>
120 +#include <linux/smp_lock.h>
121 +#include <linux/slab.h>
122 +#include <linux/squashfs_fs_sb.h>
123 +#include <linux/squashfs_fs_i.h>
124 +#include <linux/buffer_head.h>
125 +#include <linux/vfs.h>
126 +#include <linux/init.h>
127 +#include <linux/dcache.h>
128 +#include <linux/wait.h>
129 +#include <linux/zlib.h>
130 +#include <linux/blkdev.h>
131 +#include <linux/vmalloc.h>
132 +#include <asm/uaccess.h>
133 +#include <asm/semaphore.h>
135 +#include "squashfs.h"
137 +static void squashfs_put_super(struct super_block *);
138 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
139 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
140 +static int squashfs_readpage(struct file *file, struct page *page);
141 +static int squashfs_readpage4K(struct file *file, struct page *page);
142 +static int squashfs_readdir(struct file *, void *, filldir_t);
143 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
144 +static void squashfs_destroy_inode(struct inode *inode);
145 +static int init_inodecache(void);
146 +static void destroy_inodecache(void);
147 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
148 + struct nameidata *);
149 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
150 +static long long read_blocklist(struct inode *inode, int index,
151 + int readahead_blks, char *block_list,
152 + unsigned short **block_p, unsigned int *bsize);
153 +static int squashfs_get_sb(struct file_system_type *, int,
154 + const char *, void *, struct vfsmount *);
157 +static z_stream stream;
159 +static struct file_system_type squashfs_fs_type = {
160 + .owner = THIS_MODULE,
161 + .name = "squashfs",
162 + .get_sb = squashfs_get_sb,
163 + .kill_sb = kill_block_super,
164 + .fs_flags = FS_REQUIRES_DEV
167 +static unsigned char squashfs_filetype_table[] = {
168 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
171 +static struct super_operations squashfs_ops = {
172 + .alloc_inode = squashfs_alloc_inode,
173 + .destroy_inode = squashfs_destroy_inode,
174 + .statfs = squashfs_statfs,
175 + .put_super = squashfs_put_super,
178 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
179 + .readpage = squashfs_symlink_readpage
182 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
183 + .readpage = squashfs_readpage
186 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
187 + .readpage = squashfs_readpage4K
190 +static struct file_operations squashfs_dir_ops = {
191 + .read = generic_read_dir,
192 + .readdir = squashfs_readdir
195 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
196 + .lookup = squashfs_lookup
200 +static struct buffer_head *get_block_length(struct super_block *s,
201 + int *cur_index, int *offset, int *c_byte)
203 + struct squashfs_sb_info *msblk = s->s_fs_info;
204 + unsigned short temp;
205 + struct buffer_head *bh;
207 + if (!(bh = sb_bread(s, *cur_index)))
210 + if (msblk->devblksize - *offset == 1) {
212 + ((unsigned char *) &temp)[1] = *((unsigned char *)
213 + (bh->b_data + *offset));
215 + ((unsigned char *) &temp)[0] = *((unsigned char *)
216 + (bh->b_data + *offset));
218 + if (!(bh = sb_bread(s, ++(*cur_index))))
221 + ((unsigned char *) &temp)[0] = *((unsigned char *)
224 + ((unsigned char *) &temp)[1] = *((unsigned char *)
230 + ((unsigned char *) &temp)[1] = *((unsigned char *)
231 + (bh->b_data + *offset));
232 + ((unsigned char *) &temp)[0] = *((unsigned char *)
233 + (bh->b_data + *offset + 1));
235 + ((unsigned char *) &temp)[0] = *((unsigned char *)
236 + (bh->b_data + *offset));
237 + ((unsigned char *) &temp)[1] = *((unsigned char *)
238 + (bh->b_data + *offset + 1));
244 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
245 + if (*offset == msblk->devblksize) {
247 + if (!(bh = sb_bread(s, ++(*cur_index))))
251 + if (*((unsigned char *) (bh->b_data + *offset)) !=
252 + SQUASHFS_MARKER_BYTE) {
253 + ERROR("Metadata block marker corrupt @ %x\n",
267 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
268 + long long index, unsigned int length,
269 + long long *next_index)
271 + struct squashfs_sb_info *msblk = s->s_fs_info;
272 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
273 + msblk->devblksize_log2) + 2];
274 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
275 + unsigned int cur_index = index >> msblk->devblksize_log2;
276 + int bytes, avail_bytes, b = 0, k;
278 + unsigned int compressed;
279 + unsigned int c_byte = length;
282 + bytes = msblk->devblksize - offset;
283 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
284 + c_buffer = compressed ? msblk->read_data : buffer;
285 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
287 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
288 + ? "" : "un", (unsigned int) c_byte);
290 + if (!(bh[0] = sb_getblk(s, cur_index)))
291 + goto block_release;
293 + for (b = 1; bytes < c_byte; b++) {
294 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
295 + goto block_release;
296 + bytes += msblk->devblksize;
298 + ll_rw_block(READ, b, bh);
300 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
304 + bytes = msblk->devblksize - offset;
305 + compressed = SQUASHFS_COMPRESSED(c_byte);
306 + c_buffer = compressed ? msblk->read_data : buffer;
307 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
309 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
310 + ? "" : "un", (unsigned int) c_byte);
312 + for (b = 1; bytes < c_byte; b++) {
313 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
314 + goto block_release;
315 + bytes += msblk->devblksize;
317 + ll_rw_block(READ, b - 1, bh + 1);
321 + down(&msblk->read_data_mutex);
323 + for (bytes = 0, k = 0; k < b; k++) {
324 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
325 + msblk->devblksize - offset :
327 + wait_on_buffer(bh[k]);
328 + if (!buffer_uptodate(bh[k]))
329 + goto block_release;
330 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
331 + bytes += avail_bytes;
342 + stream.next_in = c_buffer;
343 + stream.avail_in = c_byte;
344 + stream.next_out = buffer;
345 + stream.avail_out = msblk->read_size;
347 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
348 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
349 + != Z_STREAM_END) || ((zlib_err =
350 + zlib_inflateEnd(&stream)) != Z_OK)) {
351 + ERROR("zlib_fs returned unexpected result 0x%x\n",
355 + bytes = stream.total_out;
357 + up(&msblk->read_data_mutex);
361 + *next_index = index + c_byte + (length ? 0 :
362 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
371 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
376 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
377 + long long block, unsigned int offset,
378 + int length, long long *next_block,
379 + unsigned int *next_offset)
381 + struct squashfs_sb_info *msblk = s->s_fs_info;
382 + int n, i, bytes, return_length = length;
383 + long long next_index;
385 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
388 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
389 + if (msblk->block_cache[i].block == block)
392 + down(&msblk->block_cache_mutex);
394 + if (i == SQUASHFS_CACHED_BLKS) {
395 + /* read inode header block */
396 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
397 + n ; n --, i = (i + 1) %
398 + SQUASHFS_CACHED_BLKS)
399 + if (msblk->block_cache[i].block !=
406 + init_waitqueue_entry(&wait, current);
407 + add_wait_queue(&msblk->waitq, &wait);
408 + set_current_state(TASK_UNINTERRUPTIBLE);
409 + up(&msblk->block_cache_mutex);
411 + set_current_state(TASK_RUNNING);
412 + remove_wait_queue(&msblk->waitq, &wait);
415 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
417 + if (msblk->block_cache[i].block ==
418 + SQUASHFS_INVALID_BLK) {
419 + if (!(msblk->block_cache[i].data =
420 + kmalloc(SQUASHFS_METADATA_SIZE,
422 + ERROR("Failed to allocate cache"
424 + up(&msblk->block_cache_mutex);
429 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
430 + up(&msblk->block_cache_mutex);
432 + if (!(msblk->block_cache[i].length =
433 + squashfs_read_data(s,
434 + msblk->block_cache[i].data,
435 + block, 0, &next_index))) {
436 + ERROR("Unable to read cache block [%llx:%x]\n",
441 + down(&msblk->block_cache_mutex);
442 + wake_up(&msblk->waitq);
443 + msblk->block_cache[i].block = block;
444 + msblk->block_cache[i].next_index = next_index;
445 + TRACE("Read cache block [%llx:%x]\n", block, offset);
448 + if (msblk->block_cache[i].block != block) {
449 + up(&msblk->block_cache_mutex);
453 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
455 + memcpy(buffer, msblk->block_cache[i].data +
457 + if (msblk->block_cache[i].length - offset == length) {
458 + *next_block = msblk->block_cache[i].next_index;
461 + *next_block = block;
462 + *next_offset = offset + length;
464 + up(&msblk->block_cache_mutex);
468 + memcpy(buffer, msblk->block_cache[i].data +
472 + block = msblk->block_cache[i].next_index;
473 + up(&msblk->block_cache_mutex);
480 + return return_length;
486 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
487 + long long *fragment_start_block,
488 + unsigned int *fragment_size)
490 + struct squashfs_sb_info *msblk = s->s_fs_info;
491 + long long start_block =
492 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
493 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
494 + struct squashfs_fragment_entry fragment_entry;
497 + struct squashfs_fragment_entry sfragment_entry;
499 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
500 + start_block, offset,
501 + sizeof(sfragment_entry), &start_block,
504 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
506 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
507 + start_block, offset,
508 + sizeof(fragment_entry), &start_block,
512 + *fragment_start_block = fragment_entry.start_block;
513 + *fragment_size = fragment_entry.size;
522 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
523 + squashfs_fragment_cache *fragment)
525 + down(&msblk->fragment_mutex);
526 + fragment->locked --;
527 + wake_up(&msblk->fragment_wait_queue);
528 + up(&msblk->fragment_mutex);
532 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
533 + *s, long long start_block,
537 + struct squashfs_sb_info *msblk = s->s_fs_info;
540 + down(&msblk->fragment_mutex);
542 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
543 + msblk->fragment[i].block != start_block; i++);
545 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
546 + for (i = msblk->next_fragment, n =
547 + SQUASHFS_CACHED_FRAGMENTS; n &&
548 + msblk->fragment[i].locked; n--, i = (i + 1) %
549 + SQUASHFS_CACHED_FRAGMENTS);
554 + init_waitqueue_entry(&wait, current);
555 + add_wait_queue(&msblk->fragment_wait_queue,
557 + set_current_state(TASK_UNINTERRUPTIBLE);
558 + up(&msblk->fragment_mutex);
560 + set_current_state(TASK_RUNNING);
561 + remove_wait_queue(&msblk->fragment_wait_queue,
565 + msblk->next_fragment = (msblk->next_fragment + 1) %
566 + SQUASHFS_CACHED_FRAGMENTS;
568 + if (msblk->fragment[i].data == NULL)
569 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
570 + (SQUASHFS_FILE_MAX_SIZE))) {
571 + ERROR("Failed to allocate fragment "
573 + up(&msblk->fragment_mutex);
577 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
578 + msblk->fragment[i].locked = 1;
579 + up(&msblk->fragment_mutex);
581 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
582 + msblk->fragment[i].data,
583 + start_block, length, NULL))) {
584 + ERROR("Unable to read fragment cache block "
585 + "[%llx]\n", start_block);
586 + msblk->fragment[i].locked = 0;
590 + msblk->fragment[i].block = start_block;
591 + TRACE("New fragment %d, start block %lld, locked %d\n",
592 + i, msblk->fragment[i].block,
593 + msblk->fragment[i].locked);
597 + msblk->fragment[i].locked++;
598 + up(&msblk->fragment_mutex);
599 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
600 + msblk->fragment[i].block,
601 + msblk->fragment[i].locked);
605 + return &msblk->fragment[i];
612 +static struct inode *squashfs_new_inode(struct super_block *s,
613 + struct squashfs_base_inode_header *inodeb)
615 + struct squashfs_sb_info *msblk = s->s_fs_info;
616 + struct inode *i = new_inode(s);
619 + i->i_ino = inodeb->inode_number;
620 + i->i_mtime.tv_sec = inodeb->mtime;
621 + i->i_atime.tv_sec = inodeb->mtime;
622 + i->i_ctime.tv_sec = inodeb->mtime;
623 + i->i_uid = msblk->uid[inodeb->uid];
624 + i->i_mode = inodeb->mode;
626 + if (inodeb->guid == SQUASHFS_GUIDS)
627 + i->i_gid = i->i_uid;
629 + i->i_gid = msblk->guid[inodeb->guid];
636 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
639 + struct squashfs_sb_info *msblk = s->s_fs_info;
640 + struct squashfs_super_block *sblk = &msblk->sblk;
641 + long long block = SQUASHFS_INODE_BLK(inode) +
642 + sblk->inode_table_start;
643 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
644 + long long next_block;
645 + unsigned int next_offset;
646 + union squashfs_inode_header id, sid;
647 + struct squashfs_base_inode_header *inodeb = &id.base,
648 + *sinodeb = &sid.base;
650 + TRACE("Entered squashfs_iget\n");
653 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
654 + offset, sizeof(*sinodeb), &next_block,
657 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
660 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
661 + offset, sizeof(*inodeb), &next_block,
665 + switch(inodeb->inode_type) {
666 + case SQUASHFS_FILE_TYPE: {
667 + unsigned int frag_size;
668 + long long frag_blk;
669 + struct squashfs_reg_inode_header *inodep = &id.reg;
670 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
673 + if (!squashfs_get_cached_block(s, (char *)
674 + sinodep, block, offset,
675 + sizeof(*sinodep), &next_block,
678 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
680 + if (!squashfs_get_cached_block(s, (char *)
681 + inodep, block, offset,
682 + sizeof(*inodep), &next_block,
686 + frag_blk = SQUASHFS_INVALID_BLK;
687 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
688 + !get_fragment_location(s,
689 + inodep->fragment, &frag_blk, &frag_size))
692 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
696 + i->i_size = inodep->file_size;
697 + i->i_fop = &generic_ro_fops;
698 + i->i_mode |= S_IFREG;
699 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
700 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
701 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
702 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
703 + SQUASHFS_I(i)->start_block = inodep->start_block;
704 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
705 + SQUASHFS_I(i)->offset = next_offset;
706 + if (sblk->block_size > 4096)
707 + i->i_data.a_ops = &squashfs_aops;
709 + i->i_data.a_ops = &squashfs_aops_4K;
711 + TRACE("File inode %x:%x, start_block %llx, "
712 + "block_list_start %llx, offset %x\n",
713 + SQUASHFS_INODE_BLK(inode), offset,
714 + inodep->start_block, next_block,
718 + case SQUASHFS_LREG_TYPE: {
719 + unsigned int frag_size;
720 + long long frag_blk;
721 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
722 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
725 + if (!squashfs_get_cached_block(s, (char *)
726 + sinodep, block, offset,
727 + sizeof(*sinodep), &next_block,
730 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
732 + if (!squashfs_get_cached_block(s, (char *)
733 + inodep, block, offset,
734 + sizeof(*inodep), &next_block,
738 + frag_blk = SQUASHFS_INVALID_BLK;
739 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
740 + !get_fragment_location(s,
741 + inodep->fragment, &frag_blk, &frag_size))
744 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
747 + i->i_nlink = inodep->nlink;
748 + i->i_size = inodep->file_size;
749 + i->i_fop = &generic_ro_fops;
750 + i->i_mode |= S_IFREG;
751 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
752 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
753 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
754 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
755 + SQUASHFS_I(i)->start_block = inodep->start_block;
756 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
757 + SQUASHFS_I(i)->offset = next_offset;
758 + if (sblk->block_size > 4096)
759 + i->i_data.a_ops = &squashfs_aops;
761 + i->i_data.a_ops = &squashfs_aops_4K;
763 + TRACE("File inode %x:%x, start_block %llx, "
764 + "block_list_start %llx, offset %x\n",
765 + SQUASHFS_INODE_BLK(inode), offset,
766 + inodep->start_block, next_block,
770 + case SQUASHFS_DIR_TYPE: {
771 + struct squashfs_dir_inode_header *inodep = &id.dir;
772 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
775 + if (!squashfs_get_cached_block(s, (char *)
776 + sinodep, block, offset,
777 + sizeof(*sinodep), &next_block,
780 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
782 + if (!squashfs_get_cached_block(s, (char *)
783 + inodep, block, offset,
784 + sizeof(*inodep), &next_block,
788 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
791 + i->i_nlink = inodep->nlink;
792 + i->i_size = inodep->file_size;
793 + i->i_op = &squashfs_dir_inode_ops;
794 + i->i_fop = &squashfs_dir_ops;
795 + i->i_mode |= S_IFDIR;
796 + SQUASHFS_I(i)->start_block = inodep->start_block;
797 + SQUASHFS_I(i)->offset = inodep->offset;
798 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
799 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
801 + TRACE("Directory inode %x:%x, start_block %x, offset "
802 + "%x\n", SQUASHFS_INODE_BLK(inode),
803 + offset, inodep->start_block,
807 + case SQUASHFS_LDIR_TYPE: {
808 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
809 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
812 + if (!squashfs_get_cached_block(s, (char *)
813 + sinodep, block, offset,
814 + sizeof(*sinodep), &next_block,
817 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
820 + if (!squashfs_get_cached_block(s, (char *)
821 + inodep, block, offset,
822 + sizeof(*inodep), &next_block,
826 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
829 + i->i_nlink = inodep->nlink;
830 + i->i_size = inodep->file_size;
831 + i->i_op = &squashfs_dir_inode_ops;
832 + i->i_fop = &squashfs_dir_ops;
833 + i->i_mode |= S_IFDIR;
834 + SQUASHFS_I(i)->start_block = inodep->start_block;
835 + SQUASHFS_I(i)->offset = inodep->offset;
836 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
837 + SQUASHFS_I(i)->u.s2.directory_index_offset =
839 + SQUASHFS_I(i)->u.s2.directory_index_count =
841 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
843 + TRACE("Long directory inode %x:%x, start_block %x, "
845 + SQUASHFS_INODE_BLK(inode), offset,
846 + inodep->start_block, inodep->offset);
849 + case SQUASHFS_SYMLINK_TYPE: {
850 + struct squashfs_symlink_inode_header *inodep =
852 + struct squashfs_symlink_inode_header *sinodep =
856 + if (!squashfs_get_cached_block(s, (char *)
857 + sinodep, block, offset,
858 + sizeof(*sinodep), &next_block,
861 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
864 + if (!squashfs_get_cached_block(s, (char *)
865 + inodep, block, offset,
866 + sizeof(*inodep), &next_block,
870 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
873 + i->i_nlink = inodep->nlink;
874 + i->i_size = inodep->symlink_size;
875 + i->i_op = &page_symlink_inode_operations;
876 + i->i_data.a_ops = &squashfs_symlink_aops;
877 + i->i_mode |= S_IFLNK;
878 + SQUASHFS_I(i)->start_block = next_block;
879 + SQUASHFS_I(i)->offset = next_offset;
881 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
883 + SQUASHFS_INODE_BLK(inode), offset,
884 + next_block, next_offset);
887 + case SQUASHFS_BLKDEV_TYPE:
888 + case SQUASHFS_CHRDEV_TYPE: {
889 + struct squashfs_dev_inode_header *inodep = &id.dev;
890 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
893 + if (!squashfs_get_cached_block(s, (char *)
894 + sinodep, block, offset,
895 + sizeof(*sinodep), &next_block,
898 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
900 + if (!squashfs_get_cached_block(s, (char *)
901 + inodep, block, offset,
902 + sizeof(*inodep), &next_block,
906 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
909 + i->i_nlink = inodep->nlink;
910 + i->i_mode |= (inodeb->inode_type ==
911 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
913 + init_special_inode(i, i->i_mode,
914 + old_decode_dev(inodep->rdev));
916 + TRACE("Device inode %x:%x, rdev %x\n",
917 + SQUASHFS_INODE_BLK(inode), offset,
921 + case SQUASHFS_FIFO_TYPE:
922 + case SQUASHFS_SOCKET_TYPE: {
923 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
924 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
927 + if (!squashfs_get_cached_block(s, (char *)
928 + sinodep, block, offset,
929 + sizeof(*sinodep), &next_block,
932 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
934 + if (!squashfs_get_cached_block(s, (char *)
935 + inodep, block, offset,
936 + sizeof(*inodep), &next_block,
940 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
943 + i->i_nlink = inodep->nlink;
944 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
945 + ? S_IFIFO : S_IFSOCK;
946 + init_special_inode(i, i->i_mode, 0);
950 + ERROR("Unknown inode type %d in squashfs_iget!\n",
951 + inodeb->inode_type);
955 + insert_inode_hash(i);
959 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
966 +static int read_fragment_index_table(struct super_block *s)
968 + struct squashfs_sb_info *msblk = s->s_fs_info;
969 + struct squashfs_super_block *sblk = &msblk->sblk;
971 + /* Allocate fragment index table */
972 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
973 + (sblk->fragments), GFP_KERNEL))) {
974 + ERROR("Failed to allocate uid/gid table\n");
978 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
979 + !squashfs_read_data(s, (char *)
980 + msblk->fragment_index,
981 + sblk->fragment_table_start,
982 + SQUASHFS_FRAGMENT_INDEX_BYTES
983 + (sblk->fragments) |
984 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
985 + ERROR("unable to read fragment index table\n");
991 + long long fragment;
993 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
995 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
996 + &msblk->fragment_index[i], 1);
997 + msblk->fragment_index[i] = fragment;
1005 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1007 + struct squashfs_super_block *sblk = &msblk->sblk;
1009 + msblk->iget = squashfs_iget;
1010 + msblk->read_blocklist = read_blocklist;
1011 + msblk->read_fragment_index_table = read_fragment_index_table;
1013 + if (sblk->s_major == 1) {
1014 + if (!squashfs_1_0_supported(msblk)) {
1015 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1016 + "are unsupported\n");
1017 + SERROR("Please recompile with "
1018 + "Squashfs 1.0 support enabled\n");
1021 + } else if (sblk->s_major == 2) {
1022 + if (!squashfs_2_0_supported(msblk)) {
1023 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1024 + "are unsupported\n");
1025 + SERROR("Please recompile with "
1026 + "Squashfs 2.0 support enabled\n");
1029 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1031 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1032 + "filesystem\n", sblk->s_major, sblk->s_minor);
1033 + SERROR("Please update your kernel\n");
1041 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1043 + struct squashfs_sb_info *msblk;
1044 + struct squashfs_super_block *sblk;
1046 + char b[BDEVNAME_SIZE];
1047 + struct inode *root;
1049 + TRACE("Entered squashfs_read_superblock\n");
1051 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1053 + ERROR("Failed to allocate superblock\n");
1056 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1057 + msblk = s->s_fs_info;
1058 + sblk = &msblk->sblk;
1060 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1061 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1063 + init_MUTEX(&msblk->read_data_mutex);
1064 + init_MUTEX(&msblk->read_page_mutex);
1065 + init_MUTEX(&msblk->block_cache_mutex);
1066 + init_MUTEX(&msblk->fragment_mutex);
1067 + init_MUTEX(&msblk->meta_index_mutex);
1069 + init_waitqueue_head(&msblk->waitq);
1070 + init_waitqueue_head(&msblk->fragment_wait_queue);
1072 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1073 + sizeof(struct squashfs_super_block) |
1074 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1075 + SERROR("unable to read superblock\n");
1076 + goto failed_mount;
1079 + /* Check it is a SQUASHFS superblock */
1081 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1082 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1083 + struct squashfs_super_block ssblk;
1085 + WARNING("Mounting a different endian SQUASHFS "
1086 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1088 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1089 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1092 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1093 + bdevname(s->s_bdev, b));
1094 + goto failed_mount;
1098 + /* Check the MAJOR & MINOR versions */
1099 + if(!supported_squashfs_filesystem(msblk, silent))
1100 + goto failed_mount;
1102 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1103 + TRACE("Inodes are %scompressed\n",
1104 + SQUASHFS_UNCOMPRESSED_INODES
1105 + (sblk->flags) ? "un" : "");
1106 + TRACE("Data is %scompressed\n",
1107 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1109 + TRACE("Check data is %s present in the filesystem\n",
1110 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1112 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1113 + TRACE("Block size %d\n", sblk->block_size);
1114 + TRACE("Number of inodes %d\n", sblk->inodes);
1115 + if (sblk->s_major > 1)
1116 + TRACE("Number of fragments %d\n", sblk->fragments);
1117 + TRACE("Number of uids %d\n", sblk->no_uids);
1118 + TRACE("Number of gids %d\n", sblk->no_guids);
1119 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1120 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1121 + if (sblk->s_major > 1)
1122 + TRACE("sblk->fragment_table_start %llx\n",
1123 + sblk->fragment_table_start);
1124 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1126 + s->s_flags |= MS_RDONLY;
1127 + s->s_op = &squashfs_ops;
1129 + /* Init inode_table block pointer array */
1130 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1131 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1132 + ERROR("Failed to allocate block cache\n");
1133 + goto failed_mount;
1136 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1137 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1139 + msblk->next_cache = 0;
1141 + /* Allocate read_data block */
1142 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1143 + SQUASHFS_METADATA_SIZE :
1146 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1147 + ERROR("Failed to allocate read_data block\n");
1148 + goto failed_mount;
1151 + /* Allocate read_page block */
1152 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1153 + ERROR("Failed to allocate read_page block\n");
1154 + goto failed_mount;
1157 + /* Allocate uid and gid tables */
1158 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1159 + sizeof(unsigned int), GFP_KERNEL))) {
1160 + ERROR("Failed to allocate uid/gid table\n");
1161 + goto failed_mount;
1163 + msblk->guid = msblk->uid + sblk->no_uids;
1165 + if (msblk->swap) {
1166 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1168 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1169 + ((sblk->no_uids + sblk->no_guids) *
1170 + sizeof(unsigned int)) |
1171 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1172 + ERROR("unable to read uid/gid table\n");
1173 + goto failed_mount;
1176 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1177 + sblk->no_guids), (sizeof(unsigned int) * 8));
1179 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1180 + ((sblk->no_uids + sblk->no_guids) *
1181 + sizeof(unsigned int)) |
1182 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1183 + ERROR("unable to read uid/gid table\n");
1184 + goto failed_mount;
1188 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1189 + goto allocate_root;
1191 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1192 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1193 + ERROR("Failed to allocate fragment block cache\n");
1194 + goto failed_mount;
1197 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1198 + msblk->fragment[i].locked = 0;
1199 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1200 + msblk->fragment[i].data = NULL;
1203 + msblk->next_fragment = 0;
1205 + /* Allocate fragment index table */
1206 + if (msblk->read_fragment_index_table(s) == 0)
1207 + goto failed_mount;
1210 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1211 + goto failed_mount;
1213 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1214 + ERROR("Root inode create failed\n");
1216 + goto failed_mount;
1219 + TRACE("Leaving squashfs_read_super\n");
1223 + kfree(msblk->fragment_index);
1224 + kfree(msblk->fragment);
1225 + kfree(msblk->uid);
1226 + kfree(msblk->read_page);
1227 + kfree(msblk->read_data);
1228 + kfree(msblk->block_cache);
1229 + kfree(msblk->fragment_index_2);
1230 + kfree(s->s_fs_info);
1231 + s->s_fs_info = NULL;
1239 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1241 + struct squashfs_sb_info *msblk = dentry->d_inode->i_sb->s_fs_info;
1242 + struct squashfs_super_block *sblk = &msblk->sblk;
1244 + TRACE("Entered squashfs_statfs\n");
1246 + buf->f_type = SQUASHFS_MAGIC;
1247 + buf->f_bsize = sblk->block_size;
1248 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1249 + buf->f_bfree = buf->f_bavail = 0;
1250 + buf->f_files = sblk->inodes;
1252 + buf->f_namelen = SQUASHFS_NAME_LEN;
1258 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1260 + struct inode *inode = page->mapping->host;
1261 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1262 + long long block = SQUASHFS_I(inode)->start_block;
1263 + int offset = SQUASHFS_I(inode)->offset;
1264 + void *pageaddr = kmap(page);
1266 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1267 + "%llx, offset %x\n", page->index,
1268 + SQUASHFS_I(inode)->start_block,
1269 + SQUASHFS_I(inode)->offset);
1271 + for (length = 0; length < index; length += bytes) {
1272 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1273 + block, offset, PAGE_CACHE_SIZE, &block,
1275 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1281 + if (length != index) {
1282 + ERROR("(squashfs_symlink_readpage) length != index\n");
1287 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1288 + i_size_read(inode) - length;
1290 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1291 + offset, bytes, &block, &offset)))
1292 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1295 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1297 + SetPageUptodate(page);
1298 + unlock_page(page);
1304 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1306 + struct meta_index *meta = NULL;
1307 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1310 + down(&msblk->meta_index_mutex);
1312 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1314 + if(msblk->meta_index == NULL)
1315 + goto not_allocated;
1317 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1318 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1319 + msblk->meta_index[i].offset >= offset &&
1320 + msblk->meta_index[i].offset <= index &&
1321 + msblk->meta_index[i].locked == 0) {
1322 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1323 + msblk->meta_index[i].offset);
1324 + meta = &msblk->meta_index[i];
1325 + offset = meta->offset;
1332 + up(&msblk->meta_index_mutex);
1338 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1340 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1341 + struct meta_index *meta = NULL;
1344 + down(&msblk->meta_index_mutex);
1346 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1348 + if(msblk->meta_index == NULL) {
1349 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1350 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1351 + ERROR("Failed to allocate meta_index\n");
1354 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1355 + msblk->meta_index[i].inode_number = 0;
1356 + msblk->meta_index[i].locked = 0;
1358 + msblk->next_meta_index = 0;
1361 + for(i = SQUASHFS_META_NUMBER; i &&
1362 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1363 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1364 + SQUASHFS_META_NUMBER;
1367 + TRACE("empty_meta_index: failed!\n");
1371 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1372 + msblk->next_meta_index,
1373 + &msblk->meta_index[msblk->next_meta_index]);
1375 + meta = &msblk->meta_index[msblk->next_meta_index];
1376 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1377 + SQUASHFS_META_NUMBER;
1379 + meta->inode_number = inode->i_ino;
1380 + meta->offset = offset;
1381 + meta->skip = skip;
1382 + meta->entries = 0;
1386 + up(&msblk->meta_index_mutex);
1391 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1397 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1398 + long long *start_block, int *offset)
1400 + struct squashfs_sb_info *msblk = s->s_fs_info;
1401 + unsigned int *block_listp;
1404 + if (msblk->swap) {
1405 + char sblock_list[blocks << 2];
1407 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1408 + *offset, blocks << 2, start_block, offset)) {
1409 + ERROR("Unable to read block list [%llx:%x]\n",
1410 + *start_block, *offset);
1413 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1414 + ((unsigned int *)sblock_list), blocks);
1416 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1417 + *offset, blocks << 2, start_block, offset)) {
1418 + ERROR("Unable to read block list [%llx:%x]\n",
1419 + *start_block, *offset);
1423 + for (block_listp = (unsigned int *) block_list; blocks;
1424 + block_listp++, blocks --)
1425 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1436 +static inline int calculate_skip(int blocks) {
1437 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1438 + return skip >= 7 ? 7 : skip + 1;
1442 +static int get_meta_index(struct inode *inode, int index,
1443 + long long *index_block, int *index_offset,
1444 + long long *data_block, char *block_list)
1446 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1447 + struct squashfs_super_block *sblk = &msblk->sblk;
1448 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1450 + struct meta_index *meta;
1451 + struct meta_entry *meta_entry;
1452 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1453 + int cur_offset = SQUASHFS_I(inode)->offset;
1454 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1457 + index /= SQUASHFS_META_INDEXES * skip;
1459 + while ( offset < index ) {
1460 + meta = locate_meta_index(inode, index, offset + 1);
1462 + if (meta == NULL) {
1463 + if ((meta = empty_meta_index(inode, offset + 1,
1467 + offset = index < meta->offset + meta->entries ? index :
1468 + meta->offset + meta->entries - 1;
1469 + meta_entry = &meta->meta_entry[offset - meta->offset];
1470 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1471 + cur_offset = meta_entry->offset;
1472 + cur_data_block = meta_entry->data_block;
1473 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1474 + "meta->entries %d\n", offset, meta->offset,
1476 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1477 + " data_block 0x%llx\n", cur_index_block,
1478 + cur_offset, cur_data_block);
1481 + for (i = meta->offset + meta->entries; i <= index &&
1482 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1483 + int blocks = skip * SQUASHFS_META_INDEXES;
1486 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1488 + int res = read_block_index(inode->i_sb, block,
1489 + block_list, &cur_index_block,
1495 + cur_data_block += res;
1499 + meta_entry = &meta->meta_entry[i - meta->offset];
1500 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1501 + meta_entry->offset = cur_offset;
1502 + meta_entry->data_block = cur_data_block;
1507 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1508 + meta->offset, meta->entries);
1510 + release_meta_index(inode, meta);
1514 + *index_block = cur_index_block;
1515 + *index_offset = cur_offset;
1516 + *data_block = cur_data_block;
1518 + return offset * SQUASHFS_META_INDEXES * skip;
1521 + release_meta_index(inode, meta);
1526 +static long long read_blocklist(struct inode *inode, int index,
1527 + int readahead_blks, char *block_list,
1528 + unsigned short **block_p, unsigned int *bsize)
1530 + long long block_ptr;
1533 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1536 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1537 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1546 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1547 + int res = read_block_index(inode->i_sb, blocks, block_list,
1548 + &block_ptr, &offset);
1555 + if (read_block_index(inode->i_sb, 1, block_list,
1556 + &block_ptr, &offset) == -1)
1558 + *bsize = *((unsigned int *) block_list);
1567 +static int squashfs_readpage(struct file *file, struct page *page)
1569 + struct inode *inode = page->mapping->host;
1570 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1571 + struct squashfs_super_block *sblk = &msblk->sblk;
1572 + unsigned char block_list[SIZE];
1574 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1575 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1577 + struct squashfs_fragment_cache *fragment = NULL;
1578 + char *data_ptr = msblk->read_page;
1580 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1581 + int start_index = page->index & ~mask;
1582 + int end_index = start_index | mask;
1584 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1586 + SQUASHFS_I(inode)->start_block);
1588 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1589 + PAGE_CACHE_SHIFT))
1592 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1593 + || index < (i_size_read(inode) >>
1594 + sblk->block_log)) {
1595 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1596 + block_list, NULL, &bsize)) == 0)
1599 + down(&msblk->read_page_mutex);
1601 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1602 + block, bsize, NULL))) {
1603 + ERROR("Unable to read page, block %llx, size %x\n", block,
1605 + up(&msblk->read_page_mutex);
1609 + if ((fragment = get_cached_fragment(inode->i_sb,
1610 + SQUASHFS_I(inode)->
1611 + u.s1.fragment_start_block,
1612 + SQUASHFS_I(inode)->u.s1.fragment_size))
1614 + ERROR("Unable to read page, block %llx, size %x\n",
1615 + SQUASHFS_I(inode)->
1616 + u.s1.fragment_start_block,
1617 + (int) SQUASHFS_I(inode)->
1618 + u.s1.fragment_size);
1621 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1622 + (i_size_read(inode) & (sblk->block_size
1624 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1625 + data_ptr = fragment->data;
1628 + for (i = start_index; i <= end_index && byte_offset < bytes;
1629 + i++, byte_offset += PAGE_CACHE_SIZE) {
1630 + struct page *push_page;
1631 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1632 + PAGE_CACHE_SIZE : bytes - byte_offset;
1634 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1635 + bytes, i, byte_offset, available_bytes);
1637 + if (i == page->index) {
1638 + pageaddr = kmap_atomic(page, KM_USER0);
1639 + memcpy(pageaddr, data_ptr + byte_offset,
1641 + memset(pageaddr + available_bytes, 0,
1642 + PAGE_CACHE_SIZE - available_bytes);
1643 + kunmap_atomic(pageaddr, KM_USER0);
1644 + flush_dcache_page(page);
1645 + SetPageUptodate(page);
1646 + unlock_page(page);
1647 + } else if ((push_page =
1648 + grab_cache_page_nowait(page->mapping, i))) {
1649 + pageaddr = kmap_atomic(push_page, KM_USER0);
1651 + memcpy(pageaddr, data_ptr + byte_offset,
1653 + memset(pageaddr + available_bytes, 0,
1654 + PAGE_CACHE_SIZE - available_bytes);
1655 + kunmap_atomic(pageaddr, KM_USER0);
1656 + flush_dcache_page(push_page);
1657 + SetPageUptodate(push_page);
1658 + unlock_page(push_page);
1659 + page_cache_release(push_page);
1663 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1664 + || index < (i_size_read(inode) >>
1666 + up(&msblk->read_page_mutex);
1668 + release_cached_fragment(msblk, fragment);
1673 + pageaddr = kmap_atomic(page, KM_USER0);
1674 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1675 + kunmap_atomic(pageaddr, KM_USER0);
1676 + flush_dcache_page(page);
1677 + SetPageUptodate(page);
1678 + unlock_page(page);
1684 +static int squashfs_readpage4K(struct file *file, struct page *page)
1686 + struct inode *inode = page->mapping->host;
1687 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1688 + struct squashfs_super_block *sblk = &msblk->sblk;
1689 + unsigned char block_list[SIZE];
1691 + unsigned int bsize, bytes = 0;
1694 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1696 + SQUASHFS_I(inode)->start_block);
1698 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1699 + PAGE_CACHE_SHIFT)) {
1700 + pageaddr = kmap_atomic(page, KM_USER0);
1704 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1705 + || page->index < (i_size_read(inode) >>
1706 + sblk->block_log)) {
1707 + block = (msblk->read_blocklist)(inode, page->index, 1,
1708 + block_list, NULL, &bsize);
1710 + down(&msblk->read_page_mutex);
1711 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1713 + pageaddr = kmap_atomic(page, KM_USER0);
1715 + memcpy(pageaddr, msblk->read_page, bytes);
1717 + ERROR("Unable to read page, block %llx, size %x\n",
1719 + up(&msblk->read_page_mutex);
1721 + struct squashfs_fragment_cache *fragment =
1722 + get_cached_fragment(inode->i_sb,
1723 + SQUASHFS_I(inode)->
1724 + u.s1.fragment_start_block,
1725 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1726 + pageaddr = kmap_atomic(page, KM_USER0);
1728 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1729 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1730 + u.s1.fragment_offset, bytes);
1731 + release_cached_fragment(msblk, fragment);
1733 + ERROR("Unable to read page, block %llx, size %x\n",
1734 + SQUASHFS_I(inode)->
1735 + u.s1.fragment_start_block, (int)
1736 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1740 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1741 + kunmap_atomic(pageaddr, KM_USER0);
1742 + flush_dcache_page(page);
1743 + SetPageUptodate(page);
1744 + unlock_page(page);
1750 +static int get_dir_index_using_offset(struct super_block *s, long long
1751 + *next_block, unsigned int *next_offset,
1752 + long long index_start,
1753 + unsigned int index_offset, int i_count,
1756 + struct squashfs_sb_info *msblk = s->s_fs_info;
1757 + struct squashfs_super_block *sblk = &msblk->sblk;
1758 + int i, length = 0;
1759 + struct squashfs_dir_index index;
1761 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1762 + i_count, (unsigned int) f_pos);
1768 + for (i = 0; i < i_count; i++) {
1769 + if (msblk->swap) {
1770 + struct squashfs_dir_index sindex;
1771 + squashfs_get_cached_block(s, (char *) &sindex,
1772 + index_start, index_offset,
1773 + sizeof(sindex), &index_start,
1775 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1777 + squashfs_get_cached_block(s, (char *) &index,
1778 + index_start, index_offset,
1779 + sizeof(index), &index_start,
1782 + if (index.index > f_pos)
1785 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1786 + index.size + 1, &index_start,
1789 + length = index.index;
1790 + *next_block = index.start_block + sblk->directory_table_start;
1793 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1796 + return length + 3;
1800 +static int get_dir_index_using_name(struct super_block *s, long long
1801 + *next_block, unsigned int *next_offset,
1802 + long long index_start,
1803 + unsigned int index_offset, int i_count,
1804 + const char *name, int size)
1806 + struct squashfs_sb_info *msblk = s->s_fs_info;
1807 + struct squashfs_super_block *sblk = &msblk->sblk;
1808 + int i, length = 0;
1809 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1810 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1811 + char str[SQUASHFS_NAME_LEN + 1];
1813 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1815 + strncpy(str, name, size);
1818 + for (i = 0; i < i_count; i++) {
1819 + if (msblk->swap) {
1820 + struct squashfs_dir_index sindex;
1821 + squashfs_get_cached_block(s, (char *) &sindex,
1822 + index_start, index_offset,
1823 + sizeof(sindex), &index_start,
1825 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1827 + squashfs_get_cached_block(s, (char *) index,
1828 + index_start, index_offset,
1829 + sizeof(struct squashfs_dir_index),
1830 + &index_start, &index_offset);
1832 + squashfs_get_cached_block(s, index->name, index_start,
1833 + index_offset, index->size + 1,
1834 + &index_start, &index_offset);
1836 + index->name[index->size + 1] = '\0';
1838 + if (strcmp(index->name, str) > 0)
1841 + length = index->index;
1842 + *next_block = index->start_block + sblk->directory_table_start;
1845 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1846 + return length + 3;
1850 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1852 + struct inode *i = file->f_dentry->d_inode;
1853 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1854 + struct squashfs_super_block *sblk = &msblk->sblk;
1855 + long long next_block = SQUASHFS_I(i)->start_block +
1856 + sblk->directory_table_start;
1857 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1859 + struct squashfs_dir_header dirh;
1860 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1861 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1863 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1865 + while(file->f_pos < 3) {
1869 + if(file->f_pos == 0) {
1876 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1878 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1879 + (unsigned int) dirent, name, size, (int)
1880 + file->f_pos, i_ino,
1881 + squashfs_filetype_table[1]);
1883 + if (filldir(dirent, name, size,
1884 + file->f_pos, i_ino,
1885 + squashfs_filetype_table[1]) < 0) {
1886 + TRACE("Filldir returned less than 0\n");
1889 + file->f_pos += size;
1893 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1894 + SQUASHFS_I(i)->u.s2.directory_index_start,
1895 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1896 + SQUASHFS_I(i)->u.s2.directory_index_count,
1899 + while (length < i_size_read(i)) {
1900 + /* read directory header */
1901 + if (msblk->swap) {
1902 + struct squashfs_dir_header sdirh;
1904 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1905 + next_block, next_offset, sizeof(sdirh),
1906 + &next_block, &next_offset))
1909 + length += sizeof(sdirh);
1910 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1912 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1913 + next_block, next_offset, sizeof(dirh),
1914 + &next_block, &next_offset))
1917 + length += sizeof(dirh);
1920 + dir_count = dirh.count + 1;
1921 + while (dir_count--) {
1922 + if (msblk->swap) {
1923 + struct squashfs_dir_entry sdire;
1924 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1925 + &sdire, next_block, next_offset,
1926 + sizeof(sdire), &next_block,
1930 + length += sizeof(sdire);
1931 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1933 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1934 + dire, next_block, next_offset,
1935 + sizeof(*dire), &next_block,
1939 + length += sizeof(*dire);
1942 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1943 + next_block, next_offset,
1944 + dire->size + 1, &next_block,
1948 + length += dire->size + 1;
1950 + if (file->f_pos >= length)
1953 + dire->name[dire->size + 1] = '\0';
1955 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1956 + (unsigned int) dirent, dire->name,
1957 + dire->size + 1, (int) file->f_pos,
1958 + dirh.start_block, dire->offset,
1959 + dirh.inode_number + dire->inode_number,
1960 + squashfs_filetype_table[dire->type]);
1962 + if (filldir(dirent, dire->name, dire->size + 1,
1964 + dirh.inode_number + dire->inode_number,
1965 + squashfs_filetype_table[dire->type])
1967 + TRACE("Filldir returned less than 0\n");
1970 + file->f_pos = length;
1979 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1985 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
1986 + struct nameidata *nd)
1988 + const unsigned char *name = dentry->d_name.name;
1989 + int len = dentry->d_name.len;
1990 + struct inode *inode = NULL;
1991 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1992 + struct squashfs_super_block *sblk = &msblk->sblk;
1993 + long long next_block = SQUASHFS_I(i)->start_block +
1994 + sblk->directory_table_start;
1995 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1997 + struct squashfs_dir_header dirh;
1998 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1999 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
2001 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2003 + if (len > SQUASHFS_NAME_LEN)
2006 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2007 + SQUASHFS_I(i)->u.s2.directory_index_start,
2008 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2009 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2012 + while (length < i_size_read(i)) {
2013 + /* read directory header */
2014 + if (msblk->swap) {
2015 + struct squashfs_dir_header sdirh;
2016 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2017 + next_block, next_offset, sizeof(sdirh),
2018 + &next_block, &next_offset))
2021 + length += sizeof(sdirh);
2022 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2024 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2025 + next_block, next_offset, sizeof(dirh),
2026 + &next_block, &next_offset))
2029 + length += sizeof(dirh);
2032 + dir_count = dirh.count + 1;
2033 + while (dir_count--) {
2034 + if (msblk->swap) {
2035 + struct squashfs_dir_entry sdire;
2036 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2037 + &sdire, next_block,next_offset,
2038 + sizeof(sdire), &next_block,
2042 + length += sizeof(sdire);
2043 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2045 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2046 + dire, next_block,next_offset,
2047 + sizeof(*dire), &next_block,
2051 + length += sizeof(*dire);
2054 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2055 + next_block, next_offset, dire->size + 1,
2056 + &next_block, &next_offset))
2059 + length += dire->size + 1;
2061 + if (name[0] < dire->name[0])
2064 + if ((len == dire->size + 1) && !strncmp(name,
2065 + dire->name, len)) {
2066 + squashfs_inode_t ino =
2067 + SQUASHFS_MKINODE(dirh.start_block,
2070 + TRACE("calling squashfs_iget for directory "
2071 + "entry %s, inode %x:%x, %d\n", name,
2072 + dirh.start_block, dire->offset,
2073 + dirh.inode_number + dire->inode_number);
2075 + inode = (msblk->iget)(i->i_sb, ino);
2083 + d_add(dentry, inode);
2084 + return ERR_PTR(0);
2087 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2093 +static void squashfs_put_super(struct super_block *s)
2097 + if (s->s_fs_info) {
2098 + struct squashfs_sb_info *sbi = s->s_fs_info;
2099 + if (sbi->block_cache)
2100 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2101 + if (sbi->block_cache[i].block !=
2102 + SQUASHFS_INVALID_BLK)
2103 + kfree(sbi->block_cache[i].data);
2104 + if (sbi->fragment)
2105 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2106 + SQUASHFS_FREE(sbi->fragment[i].data);
2107 + kfree(sbi->fragment);
2108 + kfree(sbi->block_cache);
2109 + kfree(sbi->read_data);
2110 + kfree(sbi->read_page);
2112 + kfree(sbi->fragment_index);
2113 + kfree(sbi->fragment_index_2);
2114 + kfree(sbi->meta_index);
2115 + kfree(s->s_fs_info);
2116 + s->s_fs_info = NULL;
2121 +static int squashfs_get_sb(struct file_system_type *fs_type,
2122 + int flags, const char *dev_name, void *data,
2123 + struct vfsmount *mnt)
2125 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
2129 +static int __init init_squashfs_fs(void)
2131 + int err = init_inodecache();
2135 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2136 + "Phillip Lougher\n");
2138 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2139 + ERROR("Failed to allocate zlib workspace\n");
2140 + destroy_inodecache();
2145 + if ((err = register_filesystem(&squashfs_fs_type))) {
2146 + vfree(stream.workspace);
2147 + destroy_inodecache();
2155 +static void __exit exit_squashfs_fs(void)
2157 + vfree(stream.workspace);
2158 + unregister_filesystem(&squashfs_fs_type);
2159 + destroy_inodecache();
2163 +static struct kmem_cache * squashfs_inode_cachep;
2166 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2168 + struct squashfs_inode_info *ei;
2169 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2172 + return &ei->vfs_inode;
2176 +static void squashfs_destroy_inode(struct inode *inode)
2178 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2182 +static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
2184 + struct squashfs_inode_info *ei = foo;
2186 + inode_init_once(&ei->vfs_inode);
2190 +static int __init init_inodecache(void)
2192 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2193 + sizeof(struct squashfs_inode_info),
2194 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2196 + if (squashfs_inode_cachep == NULL)
2202 +static void destroy_inodecache(void)
2204 + kmem_cache_destroy(squashfs_inode_cachep);
2208 +module_init(init_squashfs_fs);
2209 +module_exit(exit_squashfs_fs);
2210 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2211 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2212 +MODULE_LICENSE("GPL");
2213 diff -urN linux-2.6.21.1.old/fs/squashfs/Makefile linux-2.6.21.1.dev/fs/squashfs/Makefile
2214 --- linux-2.6.21.1.old/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2215 +++ linux-2.6.21.1.dev/fs/squashfs/Makefile 2007-05-26 19:00:37.123351456 +0200
2218 +# Makefile for the linux squashfs routines.
2221 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2222 +squashfs-y += inode.o
2223 +squashfs-y += squashfs2_0.o
2224 diff -urN linux-2.6.21.1.old/fs/squashfs/squashfs2_0.c linux-2.6.21.1.dev/fs/squashfs/squashfs2_0.c
2225 --- linux-2.6.21.1.old/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2226 +++ linux-2.6.21.1.dev/fs/squashfs/squashfs2_0.c 2007-05-26 19:00:37.125351152 +0200
2229 + * Squashfs - a compressed read only filesystem for Linux
2231 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2232 + * Phillip Lougher <phillip@lougher.org.uk>
2234 + * This program is free software; you can redistribute it and/or
2235 + * modify it under the terms of the GNU General Public License
2236 + * as published by the Free Software Foundation; either version 2,
2237 + * or (at your option) any later version.
2239 + * This program is distributed in the hope that it will be useful,
2240 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2241 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2242 + * GNU General Public License for more details.
2244 + * You should have received a copy of the GNU General Public License
2245 + * along with this program; if not, write to the Free Software
2246 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2251 +#include <linux/types.h>
2252 +#include <linux/squashfs_fs.h>
2253 +#include <linux/module.h>
2254 +#include <linux/errno.h>
2255 +#include <linux/slab.h>
2256 +#include <linux/fs.h>
2257 +#include <linux/smp_lock.h>
2258 +#include <linux/slab.h>
2259 +#include <linux/squashfs_fs_sb.h>
2260 +#include <linux/squashfs_fs_i.h>
2261 +#include <linux/buffer_head.h>
2262 +#include <linux/vfs.h>
2263 +#include <linux/init.h>
2264 +#include <linux/dcache.h>
2265 +#include <linux/wait.h>
2266 +#include <linux/zlib.h>
2267 +#include <linux/blkdev.h>
2268 +#include <linux/vmalloc.h>
2269 +#include <asm/uaccess.h>
2270 +#include <asm/semaphore.h>
2272 +#include "squashfs.h"
2273 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2274 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2275 + struct nameidata *);
2277 +static struct file_operations squashfs_dir_ops_2 = {
2278 + .read = generic_read_dir,
2279 + .readdir = squashfs_readdir_2
2282 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2283 + .lookup = squashfs_lookup_2
2286 +static unsigned char squashfs_filetype_table[] = {
2287 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2290 +static int read_fragment_index_table_2(struct super_block *s)
2292 + struct squashfs_sb_info *msblk = s->s_fs_info;
2293 + struct squashfs_super_block *sblk = &msblk->sblk;
2295 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2296 + (sblk->fragments), GFP_KERNEL))) {
2297 + ERROR("Failed to allocate uid/gid table\n");
2301 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2302 + !squashfs_read_data(s, (char *)
2303 + msblk->fragment_index_2,
2304 + sblk->fragment_table_start,
2305 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2306 + (sblk->fragments) |
2307 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2308 + ERROR("unable to read fragment index table\n");
2312 + if (msblk->swap) {
2314 + unsigned int fragment;
2316 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2318 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2319 + &msblk->fragment_index_2[i], 1);
2320 + msblk->fragment_index_2[i] = fragment;
2328 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2329 + long long *fragment_start_block,
2330 + unsigned int *fragment_size)
2332 + struct squashfs_sb_info *msblk = s->s_fs_info;
2333 + long long start_block =
2334 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2335 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2336 + struct squashfs_fragment_entry_2 fragment_entry;
2338 + if (msblk->swap) {
2339 + struct squashfs_fragment_entry_2 sfragment_entry;
2341 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2342 + start_block, offset,
2343 + sizeof(sfragment_entry), &start_block,
2346 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2348 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2349 + start_block, offset,
2350 + sizeof(fragment_entry), &start_block,
2354 + *fragment_start_block = fragment_entry.start_block;
2355 + *fragment_size = fragment_entry.size;
2364 +static struct inode *squashfs_new_inode(struct super_block *s,
2365 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2367 + struct squashfs_sb_info *msblk = s->s_fs_info;
2368 + struct squashfs_super_block *sblk = &msblk->sblk;
2369 + struct inode *i = new_inode(s);
2373 + i->i_mtime.tv_sec = sblk->mkfs_time;
2374 + i->i_atime.tv_sec = sblk->mkfs_time;
2375 + i->i_ctime.tv_sec = sblk->mkfs_time;
2376 + i->i_uid = msblk->uid[inodeb->uid];
2377 + i->i_mode = inodeb->mode;
2380 + if (inodeb->guid == SQUASHFS_GUIDS)
2381 + i->i_gid = i->i_uid;
2383 + i->i_gid = msblk->guid[inodeb->guid];
2390 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2393 + struct squashfs_sb_info *msblk = s->s_fs_info;
2394 + struct squashfs_super_block *sblk = &msblk->sblk;
2395 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2396 + sblk->inode_table_start;
2397 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2398 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2399 + - sblk->inode_table_start, offset);
2400 + long long next_block;
2401 + unsigned int next_offset;
2402 + union squashfs_inode_header_2 id, sid;
2403 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2404 + *sinodeb = &sid.base;
2406 + TRACE("Entered squashfs_iget\n");
2408 + if (msblk->swap) {
2409 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2410 + offset, sizeof(*sinodeb), &next_block,
2413 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2414 + sizeof(*sinodeb));
2416 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2417 + offset, sizeof(*inodeb), &next_block,
2421 + switch(inodeb->inode_type) {
2422 + case SQUASHFS_FILE_TYPE: {
2423 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2424 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2425 + long long frag_blk;
2426 + unsigned int frag_size;
2428 + if (msblk->swap) {
2429 + if (!squashfs_get_cached_block(s, (char *)
2430 + sinodep, block, offset,
2431 + sizeof(*sinodep), &next_block,
2434 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2436 + if (!squashfs_get_cached_block(s, (char *)
2437 + inodep, block, offset,
2438 + sizeof(*inodep), &next_block,
2442 + frag_blk = SQUASHFS_INVALID_BLK;
2443 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2444 + !get_fragment_location_2(s,
2445 + inodep->fragment, &frag_blk, &frag_size))
2448 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2449 + goto failed_read1;
2451 + i->i_size = inodep->file_size;
2452 + i->i_fop = &generic_ro_fops;
2453 + i->i_mode |= S_IFREG;
2454 + i->i_mtime.tv_sec = inodep->mtime;
2455 + i->i_atime.tv_sec = inodep->mtime;
2456 + i->i_ctime.tv_sec = inodep->mtime;
2457 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2458 + i->i_blksize = PAGE_CACHE_SIZE;
2459 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2460 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2461 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2462 + SQUASHFS_I(i)->start_block = inodep->start_block;
2463 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2464 + SQUASHFS_I(i)->offset = next_offset;
2465 + if (sblk->block_size > 4096)
2466 + i->i_data.a_ops = &squashfs_aops;
2468 + i->i_data.a_ops = &squashfs_aops_4K;
2470 + TRACE("File inode %x:%x, start_block %x, "
2471 + "block_list_start %llx, offset %x\n",
2472 + SQUASHFS_INODE_BLK(inode), offset,
2473 + inodep->start_block, next_block,
2477 + case SQUASHFS_DIR_TYPE: {
2478 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2479 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2481 + if (msblk->swap) {
2482 + if (!squashfs_get_cached_block(s, (char *)
2483 + sinodep, block, offset,
2484 + sizeof(*sinodep), &next_block,
2487 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2489 + if (!squashfs_get_cached_block(s, (char *)
2490 + inodep, block, offset,
2491 + sizeof(*inodep), &next_block,
2495 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2496 + goto failed_read1;
2498 + i->i_size = inodep->file_size;
2499 + i->i_op = &squashfs_dir_inode_ops_2;
2500 + i->i_fop = &squashfs_dir_ops_2;
2501 + i->i_mode |= S_IFDIR;
2502 + i->i_mtime.tv_sec = inodep->mtime;
2503 + i->i_atime.tv_sec = inodep->mtime;
2504 + i->i_ctime.tv_sec = inodep->mtime;
2505 + SQUASHFS_I(i)->start_block = inodep->start_block;
2506 + SQUASHFS_I(i)->offset = inodep->offset;
2507 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2508 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2510 + TRACE("Directory inode %x:%x, start_block %x, offset "
2511 + "%x\n", SQUASHFS_INODE_BLK(inode),
2512 + offset, inodep->start_block,
2516 + case SQUASHFS_LDIR_TYPE: {
2517 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2518 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2520 + if (msblk->swap) {
2521 + if (!squashfs_get_cached_block(s, (char *)
2522 + sinodep, block, offset,
2523 + sizeof(*sinodep), &next_block,
2526 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2529 + if (!squashfs_get_cached_block(s, (char *)
2530 + inodep, block, offset,
2531 + sizeof(*inodep), &next_block,
2535 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2536 + goto failed_read1;
2538 + i->i_size = inodep->file_size;
2539 + i->i_op = &squashfs_dir_inode_ops_2;
2540 + i->i_fop = &squashfs_dir_ops_2;
2541 + i->i_mode |= S_IFDIR;
2542 + i->i_mtime.tv_sec = inodep->mtime;
2543 + i->i_atime.tv_sec = inodep->mtime;
2544 + i->i_ctime.tv_sec = inodep->mtime;
2545 + SQUASHFS_I(i)->start_block = inodep->start_block;
2546 + SQUASHFS_I(i)->offset = inodep->offset;
2547 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2548 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2550 + SQUASHFS_I(i)->u.s2.directory_index_count =
2552 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2554 + TRACE("Long directory inode %x:%x, start_block %x, "
2556 + SQUASHFS_INODE_BLK(inode), offset,
2557 + inodep->start_block, inodep->offset);
2560 + case SQUASHFS_SYMLINK_TYPE: {
2561 + struct squashfs_symlink_inode_header_2 *inodep =
2563 + struct squashfs_symlink_inode_header_2 *sinodep =
2566 + if (msblk->swap) {
2567 + if (!squashfs_get_cached_block(s, (char *)
2568 + sinodep, block, offset,
2569 + sizeof(*sinodep), &next_block,
2572 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2575 + if (!squashfs_get_cached_block(s, (char *)
2576 + inodep, block, offset,
2577 + sizeof(*inodep), &next_block,
2581 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2582 + goto failed_read1;
2584 + i->i_size = inodep->symlink_size;
2585 + i->i_op = &page_symlink_inode_operations;
2586 + i->i_data.a_ops = &squashfs_symlink_aops;
2587 + i->i_mode |= S_IFLNK;
2588 + SQUASHFS_I(i)->start_block = next_block;
2589 + SQUASHFS_I(i)->offset = next_offset;
2591 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2593 + SQUASHFS_INODE_BLK(inode), offset,
2594 + next_block, next_offset);
2597 + case SQUASHFS_BLKDEV_TYPE:
2598 + case SQUASHFS_CHRDEV_TYPE: {
2599 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2600 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2602 + if (msblk->swap) {
2603 + if (!squashfs_get_cached_block(s, (char *)
2604 + sinodep, block, offset,
2605 + sizeof(*sinodep), &next_block,
2608 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2610 + if (!squashfs_get_cached_block(s, (char *)
2611 + inodep, block, offset,
2612 + sizeof(*inodep), &next_block,
2616 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2617 + goto failed_read1;
2619 + i->i_mode |= (inodeb->inode_type ==
2620 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2622 + init_special_inode(i, i->i_mode,
2623 + old_decode_dev(inodep->rdev));
2625 + TRACE("Device inode %x:%x, rdev %x\n",
2626 + SQUASHFS_INODE_BLK(inode), offset,
2630 + case SQUASHFS_FIFO_TYPE:
2631 + case SQUASHFS_SOCKET_TYPE: {
2632 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2633 + goto failed_read1;
2635 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2636 + ? S_IFIFO : S_IFSOCK;
2637 + init_special_inode(i, i->i_mode, 0);
2641 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2642 + inodeb->inode_type);
2643 + goto failed_read1;
2646 + insert_inode_hash(i);
2650 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2657 +static int get_dir_index_using_offset(struct super_block *s, long long
2658 + *next_block, unsigned int *next_offset,
2659 + long long index_start,
2660 + unsigned int index_offset, int i_count,
2663 + struct squashfs_sb_info *msblk = s->s_fs_info;
2664 + struct squashfs_super_block *sblk = &msblk->sblk;
2665 + int i, length = 0;
2666 + struct squashfs_dir_index_2 index;
2668 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2669 + i_count, (unsigned int) f_pos);
2674 + for (i = 0; i < i_count; i++) {
2675 + if (msblk->swap) {
2676 + struct squashfs_dir_index_2 sindex;
2677 + squashfs_get_cached_block(s, (char *) &sindex,
2678 + index_start, index_offset,
2679 + sizeof(sindex), &index_start,
2681 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2683 + squashfs_get_cached_block(s, (char *) &index,
2684 + index_start, index_offset,
2685 + sizeof(index), &index_start,
2688 + if (index.index > f_pos)
2691 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2692 + index.size + 1, &index_start,
2695 + length = index.index;
2696 + *next_block = index.start_block + sblk->directory_table_start;
2699 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2706 +static int get_dir_index_using_name(struct super_block *s, long long
2707 + *next_block, unsigned int *next_offset,
2708 + long long index_start,
2709 + unsigned int index_offset, int i_count,
2710 + const char *name, int size)
2712 + struct squashfs_sb_info *msblk = s->s_fs_info;
2713 + struct squashfs_super_block *sblk = &msblk->sblk;
2714 + int i, length = 0;
2715 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2716 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2717 + char str[SQUASHFS_NAME_LEN + 1];
2719 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2721 + strncpy(str, name, size);
2724 + for (i = 0; i < i_count; i++) {
2725 + if (msblk->swap) {
2726 + struct squashfs_dir_index_2 sindex;
2727 + squashfs_get_cached_block(s, (char *) &sindex,
2728 + index_start, index_offset,
2729 + sizeof(sindex), &index_start,
2731 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2733 + squashfs_get_cached_block(s, (char *) index,
2734 + index_start, index_offset,
2735 + sizeof(struct squashfs_dir_index_2),
2736 + &index_start, &index_offset);
2738 + squashfs_get_cached_block(s, index->name, index_start,
2739 + index_offset, index->size + 1,
2740 + &index_start, &index_offset);
2742 + index->name[index->size + 1] = '\0';
2744 + if (strcmp(index->name, str) > 0)
2747 + length = index->index;
2748 + *next_block = index->start_block + sblk->directory_table_start;
2751 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2756 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2758 + struct inode *i = file->f_dentry->d_inode;
2759 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2760 + struct squashfs_super_block *sblk = &msblk->sblk;
2761 + long long next_block = SQUASHFS_I(i)->start_block +
2762 + sblk->directory_table_start;
2763 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2765 + struct squashfs_dir_header_2 dirh;
2766 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2767 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2769 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2771 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2772 + SQUASHFS_I(i)->u.s2.directory_index_start,
2773 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2774 + SQUASHFS_I(i)->u.s2.directory_index_count,
2777 + while (length < i_size_read(i)) {
2778 + /* read directory header */
2779 + if (msblk->swap) {
2780 + struct squashfs_dir_header_2 sdirh;
2782 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2783 + next_block, next_offset, sizeof(sdirh),
2784 + &next_block, &next_offset))
2787 + length += sizeof(sdirh);
2788 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2790 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2791 + next_block, next_offset, sizeof(dirh),
2792 + &next_block, &next_offset))
2795 + length += sizeof(dirh);
2798 + dir_count = dirh.count + 1;
2799 + while (dir_count--) {
2800 + if (msblk->swap) {
2801 + struct squashfs_dir_entry_2 sdire;
2802 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2803 + &sdire, next_block, next_offset,
2804 + sizeof(sdire), &next_block,
2808 + length += sizeof(sdire);
2809 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2811 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2812 + dire, next_block, next_offset,
2813 + sizeof(*dire), &next_block,
2817 + length += sizeof(*dire);
2820 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2821 + next_block, next_offset,
2822 + dire->size + 1, &next_block,
2826 + length += dire->size + 1;
2828 + if (file->f_pos >= length)
2831 + dire->name[dire->size + 1] = '\0';
2833 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2834 + (unsigned int) dirent, dire->name,
2835 + dire->size + 1, (int) file->f_pos,
2836 + dirh.start_block, dire->offset,
2837 + squashfs_filetype_table[dire->type]);
2839 + if (filldir(dirent, dire->name, dire->size + 1,
2840 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2841 + dirh.start_block, dire->offset),
2842 + squashfs_filetype_table[dire->type])
2844 + TRACE("Filldir returned less than 0\n");
2847 + file->f_pos = length;
2856 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2862 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2863 + struct nameidata *nd)
2865 + const unsigned char *name = dentry->d_name.name;
2866 + int len = dentry->d_name.len;
2867 + struct inode *inode = NULL;
2868 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2869 + struct squashfs_super_block *sblk = &msblk->sblk;
2870 + long long next_block = SQUASHFS_I(i)->start_block +
2871 + sblk->directory_table_start;
2872 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2874 + struct squashfs_dir_header_2 dirh;
2875 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2876 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2877 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2879 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2881 + if (len > SQUASHFS_NAME_LEN)
2884 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2885 + SQUASHFS_I(i)->u.s2.directory_index_start,
2886 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2887 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2890 + while (length < i_size_read(i)) {
2891 + /* read directory header */
2892 + if (msblk->swap) {
2893 + struct squashfs_dir_header_2 sdirh;
2894 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2895 + next_block, next_offset, sizeof(sdirh),
2896 + &next_block, &next_offset))
2899 + length += sizeof(sdirh);
2900 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2902 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2903 + next_block, next_offset, sizeof(dirh),
2904 + &next_block, &next_offset))
2907 + length += sizeof(dirh);
2910 + dir_count = dirh.count + 1;
2911 + while (dir_count--) {
2912 + if (msblk->swap) {
2913 + struct squashfs_dir_entry_2 sdire;
2914 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2915 + &sdire, next_block,next_offset,
2916 + sizeof(sdire), &next_block,
2920 + length += sizeof(sdire);
2921 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2923 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2924 + dire, next_block,next_offset,
2925 + sizeof(*dire), &next_block,
2929 + length += sizeof(*dire);
2932 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2933 + next_block, next_offset, dire->size + 1,
2934 + &next_block, &next_offset))
2937 + length += dire->size + 1;
2939 + if (sorted && name[0] < dire->name[0])
2942 + if ((len == dire->size + 1) && !strncmp(name,
2943 + dire->name, len)) {
2944 + squashfs_inode_t ino =
2945 + SQUASHFS_MKINODE(dirh.start_block,
2948 + TRACE("calling squashfs_iget for directory "
2949 + "entry %s, inode %x:%x, %lld\n", name,
2950 + dirh.start_block, dire->offset, ino);
2952 + inode = (msblk->iget)(i->i_sb, ino);
2960 + d_add(dentry, inode);
2961 + return ERR_PTR(0);
2964 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2970 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2972 + struct squashfs_super_block *sblk = &msblk->sblk;
2974 + msblk->iget = squashfs_iget_2;
2975 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2977 + sblk->bytes_used = sblk->bytes_used_2;
2978 + sblk->uid_start = sblk->uid_start_2;
2979 + sblk->guid_start = sblk->guid_start_2;
2980 + sblk->inode_table_start = sblk->inode_table_start_2;
2981 + sblk->directory_table_start = sblk->directory_table_start_2;
2982 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2986 diff -urN linux-2.6.21.1.old/fs/squashfs/squashfs.h linux-2.6.21.1.dev/fs/squashfs/squashfs.h
2987 --- linux-2.6.21.1.old/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
2988 +++ linux-2.6.21.1.dev/fs/squashfs/squashfs.h 2007-05-26 19:00:37.125351152 +0200
2991 + * Squashfs - a compressed read only filesystem for Linux
2993 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2994 + * Phillip Lougher <phillip@lougher.org.uk>
2996 + * This program is free software; you can redistribute it and/or
2997 + * modify it under the terms of the GNU General Public License
2998 + * as published by the Free Software Foundation; either version 2,
2999 + * or (at your option) any later version.
3001 + * This program is distributed in the hope that it will be useful,
3002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3004 + * GNU General Public License for more details.
3006 + * You should have received a copy of the GNU General Public License
3007 + * along with this program; if not, write to the Free Software
3008 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3013 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3014 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3017 +#ifdef SQUASHFS_TRACE
3018 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3020 +#define TRACE(s, args...) {}
3023 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3025 +#define SERROR(s, args...) do { \
3027 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3030 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3032 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3034 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3037 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3038 +#define SQSH_EXTERN
3039 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3040 + long long index, unsigned int length,
3041 + long long *next_index);
3042 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3043 + long long block, unsigned int offset,
3044 + int length, long long *next_block,
3045 + unsigned int *next_offset);
3046 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3047 + squashfs_fragment_cache *fragment);
3048 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3049 + *s, long long start_block,
3051 +extern struct address_space_operations squashfs_symlink_aops;
3052 +extern struct address_space_operations squashfs_aops;
3053 +extern struct address_space_operations squashfs_aops_4K;
3054 +extern struct inode_operations squashfs_dir_inode_ops;
3056 +#define SQSH_EXTERN static
3059 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3060 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3062 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3068 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3069 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3071 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3076 diff -urN linux-2.6.21.1.old/include/linux/squashfs_fs.h linux-2.6.21.1.dev/include/linux/squashfs_fs.h
3077 --- linux-2.6.21.1.old/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3078 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs.h 2007-05-26 19:00:37.143348416 +0200
3080 +#ifndef SQUASHFS_FS
3081 +#define SQUASHFS_FS
3086 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3087 + * Phillip Lougher <phillip@lougher.org.uk>
3089 + * This program is free software; you can redistribute it and/or
3090 + * modify it under the terms of the GNU General Public License
3091 + * as published by the Free Software Foundation; either version 2,
3092 + * or (at your option) any later version.
3094 + * This program is distributed in the hope that it will be useful,
3095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3097 + * GNU General Public License for more details.
3099 + * You should have received a copy of the GNU General Public License
3100 + * along with this program; if not, write to the Free Software
3101 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3106 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3107 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3110 +#ifdef CONFIG_SQUASHFS_VMALLOC
3111 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3112 +#define SQUASHFS_FREE(a) vfree(a)
3114 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3115 +#define SQUASHFS_FREE(a) kfree(a)
3117 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3118 +#define SQUASHFS_MAJOR 3
3119 +#define SQUASHFS_MINOR 0
3120 +#define SQUASHFS_MAGIC 0x73717368
3121 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3122 +#define SQUASHFS_START 0
3124 +/* size of metadata (inode and directory) blocks */
3125 +#define SQUASHFS_METADATA_SIZE 8192
3126 +#define SQUASHFS_METADATA_LOG 13
3128 +/* default size of data blocks */
3129 +#define SQUASHFS_FILE_SIZE 65536
3130 +#define SQUASHFS_FILE_LOG 16
3132 +#define SQUASHFS_FILE_MAX_SIZE 65536
3134 +/* Max number of uids and gids */
3135 +#define SQUASHFS_UIDS 256
3136 +#define SQUASHFS_GUIDS 255
3138 +/* Max length of filename (not 255) */
3139 +#define SQUASHFS_NAME_LEN 256
3141 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3142 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3143 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3144 +#define SQUASHFS_USED_BLK ((long long) -2)
3146 +/* Filesystem flags */
3147 +#define SQUASHFS_NOI 0
3148 +#define SQUASHFS_NOD 1
3149 +#define SQUASHFS_CHECK 2
3150 +#define SQUASHFS_NOF 3
3151 +#define SQUASHFS_NO_FRAG 4
3152 +#define SQUASHFS_ALWAYS_FRAG 5
3153 +#define SQUASHFS_DUPLICATE 6
3155 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3157 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3160 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3163 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3166 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3169 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3170 + SQUASHFS_ALWAYS_FRAG)
3172 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3173 + SQUASHFS_DUPLICATE)
3175 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3178 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3179 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3180 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3181 + (duplicate_checking << 6))
3183 +/* Max number of types and file types */
3184 +#define SQUASHFS_DIR_TYPE 1
3185 +#define SQUASHFS_FILE_TYPE 2
3186 +#define SQUASHFS_SYMLINK_TYPE 3
3187 +#define SQUASHFS_BLKDEV_TYPE 4
3188 +#define SQUASHFS_CHRDEV_TYPE 5
3189 +#define SQUASHFS_FIFO_TYPE 6
3190 +#define SQUASHFS_SOCKET_TYPE 7
3191 +#define SQUASHFS_LDIR_TYPE 8
3192 +#define SQUASHFS_LREG_TYPE 9
3194 +/* 1.0 filesystem type definitions */
3195 +#define SQUASHFS_TYPES 5
3196 +#define SQUASHFS_IPC_TYPE 0
3198 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3200 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3202 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3203 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3205 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3207 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3209 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3210 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3211 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3213 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3216 + * Inode number ops. Inodes consist of a compressed block number, and an
3217 + * uncompressed offset within that block
3219 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3221 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3223 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3226 +/* Compute 32 bit VFS inode number from squashfs inode number */
3227 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3231 +/* Translate between VFS mode and squashfs mode */
3232 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3234 +/* fragment and fragment table defines */
3235 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3237 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3238 + SQUASHFS_METADATA_SIZE)
3240 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3241 + SQUASHFS_METADATA_SIZE)
3243 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3244 + SQUASHFS_METADATA_SIZE - 1) / \
3245 + SQUASHFS_METADATA_SIZE)
3247 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3248 + sizeof(long long))
3250 +/* cached data constants for filesystem */
3251 +#define SQUASHFS_CACHED_BLKS 8
3253 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3255 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3256 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3258 +#define SQUASHFS_MARKER_BYTE 0xff
3260 +/* meta index cache */
3261 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3262 +#define SQUASHFS_META_ENTRIES 31
3263 +#define SQUASHFS_META_NUMBER 8
3264 +#define SQUASHFS_SLOTS 4
3266 +struct meta_entry {
3267 + long long data_block;
3268 + unsigned int index_block;
3269 + unsigned short offset;
3270 + unsigned short pad;
3273 +struct meta_index {
3274 + unsigned int inode_number;
3275 + unsigned int offset;
3276 + unsigned short entries;
3277 + unsigned short skip;
3278 + unsigned short locked;
3279 + unsigned short pad;
3280 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3285 + * definitions for structures on disk
3288 +typedef long long squashfs_block_t;
3289 +typedef long long squashfs_inode_t;
3291 +struct squashfs_super_block {
3292 + unsigned int s_magic;
3293 + unsigned int inodes;
3294 + unsigned int bytes_used_2;
3295 + unsigned int uid_start_2;
3296 + unsigned int guid_start_2;
3297 + unsigned int inode_table_start_2;
3298 + unsigned int directory_table_start_2;
3299 + unsigned int s_major:16;
3300 + unsigned int s_minor:16;
3301 + unsigned int block_size_1:16;
3302 + unsigned int block_log:16;
3303 + unsigned int flags:8;
3304 + unsigned int no_uids:8;
3305 + unsigned int no_guids:8;
3306 + unsigned int mkfs_time /* time of filesystem creation */;
3307 + squashfs_inode_t root_inode;
3308 + unsigned int block_size;
3309 + unsigned int fragments;
3310 + unsigned int fragment_table_start_2;
3311 + long long bytes_used;
3312 + long long uid_start;
3313 + long long guid_start;
3314 + long long inode_table_start;
3315 + long long directory_table_start;
3316 + long long fragment_table_start;
3318 +} __attribute__ ((packed));
3320 +struct squashfs_dir_index {
3321 + unsigned int index;
3322 + unsigned int start_block;
3323 + unsigned char size;
3324 + unsigned char name[0];
3325 +} __attribute__ ((packed));
3327 +#define SQUASHFS_BASE_INODE_HEADER \
3328 + unsigned int inode_type:4; \
3329 + unsigned int mode:12; \
3330 + unsigned int uid:8; \
3331 + unsigned int guid:8; \
3332 + unsigned int mtime; \
3333 + unsigned int inode_number;
3335 +struct squashfs_base_inode_header {
3336 + SQUASHFS_BASE_INODE_HEADER;
3337 +} __attribute__ ((packed));
3339 +struct squashfs_ipc_inode_header {
3340 + SQUASHFS_BASE_INODE_HEADER;
3341 + unsigned int nlink;
3342 +} __attribute__ ((packed));
3344 +struct squashfs_dev_inode_header {
3345 + SQUASHFS_BASE_INODE_HEADER;
3346 + unsigned int nlink;
3347 + unsigned short rdev;
3348 +} __attribute__ ((packed));
3350 +struct squashfs_symlink_inode_header {
3351 + SQUASHFS_BASE_INODE_HEADER;
3352 + unsigned int nlink;
3353 + unsigned short symlink_size;
3355 +} __attribute__ ((packed));
3357 +struct squashfs_reg_inode_header {
3358 + SQUASHFS_BASE_INODE_HEADER;
3359 + squashfs_block_t start_block;
3360 + unsigned int fragment;
3361 + unsigned int offset;
3362 + unsigned int file_size;
3363 + unsigned short block_list[0];
3364 +} __attribute__ ((packed));
3366 +struct squashfs_lreg_inode_header {
3367 + SQUASHFS_BASE_INODE_HEADER;
3368 + unsigned int nlink;
3369 + squashfs_block_t start_block;
3370 + unsigned int fragment;
3371 + unsigned int offset;
3372 + long long file_size;
3373 + unsigned short block_list[0];
3374 +} __attribute__ ((packed));
3376 +struct squashfs_dir_inode_header {
3377 + SQUASHFS_BASE_INODE_HEADER;
3378 + unsigned int nlink;
3379 + unsigned int file_size:19;
3380 + unsigned int offset:13;
3381 + unsigned int start_block;
3382 + unsigned int parent_inode;
3383 +} __attribute__ ((packed));
3385 +struct squashfs_ldir_inode_header {
3386 + SQUASHFS_BASE_INODE_HEADER;
3387 + unsigned int nlink;
3388 + unsigned int file_size:27;
3389 + unsigned int offset:13;
3390 + unsigned int start_block;
3391 + unsigned int i_count:16;
3392 + unsigned int parent_inode;
3393 + struct squashfs_dir_index index[0];
3394 +} __attribute__ ((packed));
3396 +union squashfs_inode_header {
3397 + struct squashfs_base_inode_header base;
3398 + struct squashfs_dev_inode_header dev;
3399 + struct squashfs_symlink_inode_header symlink;
3400 + struct squashfs_reg_inode_header reg;
3401 + struct squashfs_lreg_inode_header lreg;
3402 + struct squashfs_dir_inode_header dir;
3403 + struct squashfs_ldir_inode_header ldir;
3404 + struct squashfs_ipc_inode_header ipc;
3407 +struct squashfs_dir_entry {
3408 + unsigned int offset:13;
3409 + unsigned int type:3;
3410 + unsigned int size:8;
3411 + int inode_number:16;
3413 +} __attribute__ ((packed));
3415 +struct squashfs_dir_header {
3416 + unsigned int count:8;
3417 + unsigned int start_block;
3418 + unsigned int inode_number;
3419 +} __attribute__ ((packed));
3421 +struct squashfs_fragment_entry {
3422 + long long start_block;
3423 + unsigned int size;
3424 + unsigned int unused;
3425 +} __attribute__ ((packed));
3427 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3428 +extern int squashfs_uncompress_init(void);
3429 +extern int squashfs_uncompress_exit(void);
3432 + * macros to convert each packed bitfield structure from little endian to big
3433 + * endian and vice versa. These are needed when creating or using a filesystem
3434 + * on a machine with different byte ordering to the target architecture.
3438 +#define SQUASHFS_SWAP_START \
3441 + unsigned long long val;\
3442 + unsigned char *s;\
3445 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3446 + SQUASHFS_SWAP_START\
3447 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3448 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3449 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3450 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3451 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3452 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3453 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3454 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3455 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3456 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3457 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3458 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3459 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3460 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3461 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3462 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3463 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3464 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3465 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3466 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3467 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3468 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3469 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3470 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3471 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3472 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3473 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3476 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3477 + SQUASHFS_MEMSET(s, d, n);\
3478 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3479 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3480 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3481 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3482 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3483 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3485 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3486 + SQUASHFS_SWAP_START\
3487 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3490 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3491 + SQUASHFS_SWAP_START\
3492 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3493 + sizeof(struct squashfs_ipc_inode_header))\
3494 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3497 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3498 + SQUASHFS_SWAP_START\
3499 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3500 + sizeof(struct squashfs_dev_inode_header)); \
3501 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3502 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3505 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3506 + SQUASHFS_SWAP_START\
3507 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3508 + sizeof(struct squashfs_symlink_inode_header));\
3509 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3510 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3513 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3514 + SQUASHFS_SWAP_START\
3515 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3516 + sizeof(struct squashfs_reg_inode_header));\
3517 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3518 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3519 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3520 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3523 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3524 + SQUASHFS_SWAP_START\
3525 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3526 + sizeof(struct squashfs_lreg_inode_header));\
3527 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3528 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3529 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3530 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3531 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3534 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3535 + SQUASHFS_SWAP_START\
3536 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3537 + sizeof(struct squashfs_dir_inode_header));\
3538 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3539 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3540 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3541 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3542 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3545 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3546 + SQUASHFS_SWAP_START\
3547 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3548 + sizeof(struct squashfs_ldir_inode_header));\
3549 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3550 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3551 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3552 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3553 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3554 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3557 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3558 + SQUASHFS_SWAP_START\
3559 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3560 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3561 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3562 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3565 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3566 + SQUASHFS_SWAP_START\
3567 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3568 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3569 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3570 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3573 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3574 + SQUASHFS_SWAP_START\
3575 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3576 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3577 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3578 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3579 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3582 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3583 + SQUASHFS_SWAP_START\
3584 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3585 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3586 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3589 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3591 + int bit_position;\
3592 + SQUASHFS_SWAP_START\
3593 + SQUASHFS_MEMSET(s, d, n * 2);\
3594 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3596 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3599 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3601 + int bit_position;\
3602 + SQUASHFS_SWAP_START\
3603 + SQUASHFS_MEMSET(s, d, n * 4);\
3604 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3606 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3609 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3611 + int bit_position;\
3612 + SQUASHFS_SWAP_START\
3613 + SQUASHFS_MEMSET(s, d, n * 8);\
3614 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3616 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3619 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3621 + int bit_position;\
3622 + SQUASHFS_SWAP_START\
3623 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3624 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3626 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3629 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3631 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3633 +struct squashfs_base_inode_header_1 {
3634 + unsigned int inode_type:4;
3635 + unsigned int mode:12; /* protection */
3636 + unsigned int uid:4; /* index into uid table */
3637 + unsigned int guid:4; /* index into guid table */
3638 +} __attribute__ ((packed));
3640 +struct squashfs_ipc_inode_header_1 {
3641 + unsigned int inode_type:4;
3642 + unsigned int mode:12; /* protection */
3643 + unsigned int uid:4; /* index into uid table */
3644 + unsigned int guid:4; /* index into guid table */
3645 + unsigned int type:4;
3646 + unsigned int offset:4;
3647 +} __attribute__ ((packed));
3649 +struct squashfs_dev_inode_header_1 {
3650 + unsigned int inode_type:4;
3651 + unsigned int mode:12; /* protection */
3652 + unsigned int uid:4; /* index into uid table */
3653 + unsigned int guid:4; /* index into guid table */
3654 + unsigned short rdev;
3655 +} __attribute__ ((packed));
3657 +struct squashfs_symlink_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 + unsigned short symlink_size;
3664 +} __attribute__ ((packed));
3666 +struct squashfs_reg_inode_header_1 {
3667 + unsigned int inode_type:4;
3668 + unsigned int mode:12; /* protection */
3669 + unsigned int uid:4; /* index into uid table */
3670 + unsigned int guid:4; /* index into guid table */
3671 + unsigned int mtime;
3672 + unsigned int start_block;
3673 + unsigned int file_size:32;
3674 + unsigned short block_list[0];
3675 +} __attribute__ ((packed));
3677 +struct squashfs_dir_inode_header_1 {
3678 + unsigned int inode_type:4;
3679 + unsigned int mode:12; /* protection */
3680 + unsigned int uid:4; /* index into uid table */
3681 + unsigned int guid:4; /* index into guid table */
3682 + unsigned int file_size:19;
3683 + unsigned int offset:13;
3684 + unsigned int mtime;
3685 + unsigned int start_block:24;
3686 +} __attribute__ ((packed));
3688 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3689 + SQUASHFS_MEMSET(s, d, n);\
3690 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3691 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3692 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3693 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3695 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3696 + SQUASHFS_SWAP_START\
3697 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3700 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3701 + SQUASHFS_SWAP_START\
3702 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3703 + sizeof(struct squashfs_ipc_inode_header_1));\
3704 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3705 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3708 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3709 + SQUASHFS_SWAP_START\
3710 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3711 + sizeof(struct squashfs_dev_inode_header_1));\
3712 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3715 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3716 + SQUASHFS_SWAP_START\
3717 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3718 + sizeof(struct squashfs_symlink_inode_header_1));\
3719 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3722 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3723 + SQUASHFS_SWAP_START\
3724 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3725 + sizeof(struct squashfs_reg_inode_header_1));\
3726 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3727 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3728 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3731 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3732 + SQUASHFS_SWAP_START\
3733 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3734 + sizeof(struct squashfs_dir_inode_header_1));\
3735 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3736 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3737 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3738 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3743 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3745 +struct squashfs_dir_index_2 {
3746 + unsigned int index:27;
3747 + unsigned int start_block:29;
3748 + unsigned char size;
3749 + unsigned char name[0];
3750 +} __attribute__ ((packed));
3752 +struct squashfs_base_inode_header_2 {
3753 + unsigned int inode_type:4;
3754 + unsigned int mode:12; /* protection */
3755 + unsigned int uid:8; /* index into uid table */
3756 + unsigned int guid:8; /* index into guid table */
3757 +} __attribute__ ((packed));
3759 +struct squashfs_ipc_inode_header_2 {
3760 + unsigned int inode_type:4;
3761 + unsigned int mode:12; /* protection */
3762 + unsigned int uid:8; /* index into uid table */
3763 + unsigned int guid:8; /* index into guid table */
3764 +} __attribute__ ((packed));
3766 +struct squashfs_dev_inode_header_2 {
3767 + unsigned int inode_type:4;
3768 + unsigned int mode:12; /* protection */
3769 + unsigned int uid:8; /* index into uid table */
3770 + unsigned int guid:8; /* index into guid table */
3771 + unsigned short rdev;
3772 +} __attribute__ ((packed));
3774 +struct squashfs_symlink_inode_header_2 {
3775 + unsigned int inode_type:4;
3776 + unsigned int mode:12; /* protection */
3777 + unsigned int uid:8; /* index into uid table */
3778 + unsigned int guid:8; /* index into guid table */
3779 + unsigned short symlink_size;
3781 +} __attribute__ ((packed));
3783 +struct squashfs_reg_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 + unsigned int mtime;
3789 + unsigned int start_block;
3790 + unsigned int fragment;
3791 + unsigned int offset;
3792 + unsigned int file_size:32;
3793 + unsigned short block_list[0];
3794 +} __attribute__ ((packed));
3796 +struct squashfs_dir_inode_header_2 {
3797 + unsigned int inode_type:4;
3798 + unsigned int mode:12; /* protection */
3799 + unsigned int uid:8; /* index into uid table */
3800 + unsigned int guid:8; /* index into guid table */
3801 + unsigned int file_size:19;
3802 + unsigned int offset:13;
3803 + unsigned int mtime;
3804 + unsigned int start_block:24;
3805 +} __attribute__ ((packed));
3807 +struct squashfs_ldir_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 file_size:27;
3813 + unsigned int offset:13;
3814 + unsigned int mtime;
3815 + unsigned int start_block:24;
3816 + unsigned int i_count:16;
3817 + struct squashfs_dir_index_2 index[0];
3818 +} __attribute__ ((packed));
3820 +union squashfs_inode_header_2 {
3821 + struct squashfs_base_inode_header_2 base;
3822 + struct squashfs_dev_inode_header_2 dev;
3823 + struct squashfs_symlink_inode_header_2 symlink;
3824 + struct squashfs_reg_inode_header_2 reg;
3825 + struct squashfs_dir_inode_header_2 dir;
3826 + struct squashfs_ldir_inode_header_2 ldir;
3827 + struct squashfs_ipc_inode_header_2 ipc;
3830 +struct squashfs_dir_header_2 {
3831 + unsigned int count:8;
3832 + unsigned int start_block:24;
3833 +} __attribute__ ((packed));
3835 +struct squashfs_dir_entry_2 {
3836 + unsigned int offset:13;
3837 + unsigned int type:3;
3838 + unsigned int size:8;
3840 +} __attribute__ ((packed));
3842 +struct squashfs_fragment_entry_2 {
3843 + unsigned int start_block;
3844 + unsigned int size;
3845 +} __attribute__ ((packed));
3847 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3848 + SQUASHFS_MEMSET(s, d, n);\
3849 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3850 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3851 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3852 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3854 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3855 + SQUASHFS_SWAP_START\
3856 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3859 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3860 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3862 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3863 + SQUASHFS_SWAP_START\
3864 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3865 + sizeof(struct squashfs_dev_inode_header_2)); \
3866 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3869 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3870 + SQUASHFS_SWAP_START\
3871 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3872 + sizeof(struct squashfs_symlink_inode_header_2));\
3873 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3876 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3877 + SQUASHFS_SWAP_START\
3878 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3879 + sizeof(struct squashfs_reg_inode_header_2));\
3880 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3881 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3882 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3883 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3884 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3887 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3888 + SQUASHFS_SWAP_START\
3889 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3890 + sizeof(struct squashfs_dir_inode_header_2));\
3891 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3892 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3893 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3894 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3897 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3898 + SQUASHFS_SWAP_START\
3899 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3900 + sizeof(struct squashfs_ldir_inode_header_2));\
3901 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3902 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3903 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3904 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3905 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3908 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3909 + SQUASHFS_SWAP_START\
3910 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3911 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3912 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3913 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3915 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3916 + SQUASHFS_SWAP_START\
3917 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3918 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3919 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3922 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3923 + SQUASHFS_SWAP_START\
3924 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3925 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3926 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3927 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3930 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3931 + SQUASHFS_SWAP_START\
3932 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3933 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3934 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3937 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3939 +/* fragment and fragment table defines */
3940 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3942 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3943 + SQUASHFS_METADATA_SIZE)
3945 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3946 + SQUASHFS_METADATA_SIZE)
3948 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3949 + SQUASHFS_METADATA_SIZE - 1) / \
3950 + SQUASHFS_METADATA_SIZE)
3952 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3960 + * macros used to swap each structure entry, taking into account
3961 + * bitfields and different bitfield placing conventions on differing
3965 +#include <asm/byteorder.h>
3967 +#ifdef __BIG_ENDIAN
3968 + /* convert from little endian to big endian */
3969 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3972 + /* convert from big endian to little endian */
3973 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3974 + tbits, 64 - tbits - b_pos)
3977 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3980 + s = (unsigned char *)p + (pos / 8);\
3981 + d = ((unsigned char *) &val) + 7;\
3982 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3984 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3987 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3991 diff -urN linux-2.6.21.1.old/include/linux/squashfs_fs_i.h linux-2.6.21.1.dev/include/linux/squashfs_fs_i.h
3992 --- linux-2.6.21.1.old/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
3993 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs_i.h 2007-05-26 19:00:37.143348416 +0200
3995 +#ifndef SQUASHFS_FS_I
3996 +#define SQUASHFS_FS_I
4000 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4001 + * Phillip Lougher <phillip@lougher.org.uk>
4003 + * This program is free software; you can redistribute it and/or
4004 + * modify it under the terms of the GNU General Public License
4005 + * as published by the Free Software Foundation; either version 2,
4006 + * or (at your option) any later version.
4008 + * This program is distributed in the hope that it will be useful,
4009 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4010 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4011 + * GNU General Public License for more details.
4013 + * You should have received a copy of the GNU General Public License
4014 + * along with this program; if not, write to the Free Software
4015 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4020 +struct squashfs_inode_info {
4021 + long long start_block;
4022 + unsigned int offset;
4025 + long long fragment_start_block;
4026 + unsigned int fragment_size;
4027 + unsigned int fragment_offset;
4028 + long long block_list_start;
4031 + long long directory_index_start;
4032 + unsigned int directory_index_offset;
4033 + unsigned int directory_index_count;
4034 + unsigned int parent_inode;
4037 + struct inode vfs_inode;
4040 diff -urN linux-2.6.21.1.old/include/linux/squashfs_fs_sb.h linux-2.6.21.1.dev/include/linux/squashfs_fs_sb.h
4041 --- linux-2.6.21.1.old/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4042 +++ linux-2.6.21.1.dev/include/linux/squashfs_fs_sb.h 2007-05-26 19:00:37.144348264 +0200
4044 +#ifndef SQUASHFS_FS_SB
4045 +#define SQUASHFS_FS_SB
4049 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4050 + * Phillip Lougher <phillip@lougher.org.uk>
4052 + * This program is free software; you can redistribute it and/or
4053 + * modify it under the terms of the GNU General Public License
4054 + * as published by the Free Software Foundation; either version 2,
4055 + * or (at your option) any later version.
4057 + * This program is distributed in the hope that it will be useful,
4058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4060 + * GNU General Public License for more details.
4062 + * You should have received a copy of the GNU General Public License
4063 + * along with this program; if not, write to the Free Software
4064 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4066 + * squashfs_fs_sb.h
4069 +#include <linux/squashfs_fs.h>
4071 +struct squashfs_cache {
4074 + long long next_index;
4078 +struct squashfs_fragment_cache {
4081 + unsigned int locked;
4085 +struct squashfs_sb_info {
4086 + struct squashfs_super_block sblk;
4088 + int devblksize_log2;
4090 + struct squashfs_cache *block_cache;
4091 + struct squashfs_fragment_cache *fragment;
4093 + int next_fragment;
4094 + int next_meta_index;
4095 + unsigned int *uid;
4096 + unsigned int *guid;
4097 + long long *fragment_index;
4098 + unsigned int *fragment_index_2;
4099 + unsigned int read_size;
4102 + struct semaphore read_data_mutex;
4103 + struct semaphore read_page_mutex;
4104 + struct semaphore block_cache_mutex;
4105 + struct semaphore fragment_mutex;
4106 + struct semaphore meta_index_mutex;
4107 + wait_queue_head_t waitq;
4108 + wait_queue_head_t fragment_wait_queue;
4109 + struct meta_index *meta_index;
4110 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4112 + long long (*read_blocklist)(struct inode *inode, int \
4113 + index, int readahead_blks, char *block_list, \
4114 + unsigned short **block_p, unsigned int *bsize);
4115 + int (*read_fragment_index_table)(struct super_block *s);
4118 diff -urN linux-2.6.21.1.old/init/do_mounts_rd.c linux-2.6.21.1.dev/init/do_mounts_rd.c
4119 --- linux-2.6.21.1.old/init/do_mounts_rd.c 2007-04-27 23:49:26.000000000 +0200
4120 +++ linux-2.6.21.1.dev/init/do_mounts_rd.c 2007-05-26 19:00:37.144348264 +0200
4122 #include <linux/ext2_fs.h>
4123 #include <linux/romfs_fs.h>
4124 #include <linux/cramfs_fs.h>
4125 +#include <linux/squashfs_fs.h>
4126 #include <linux/initrd.h>
4127 #include <linux/string.h>
4130 * numbers could not be found.
4132 * We currently check for the following magic numbers:
4138 struct ext2_super_block *ext2sb;
4139 struct romfs_super_block *romfsb;
4140 struct cramfs_super *cramfsb;
4141 + struct squashfs_super_block *squashfsb;
4146 ext2sb = (struct ext2_super_block *) buf;
4147 romfsb = (struct romfs_super_block *) buf;
4148 cramfsb = (struct cramfs_super *) buf;
4149 + squashfsb = (struct squashfs_super_block *) buf;
4150 memset(buf, 0xe5, size);
4153 @@ -101,6 +105,15 @@
4157 + /* squashfs is at block zero too */
4158 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4159 + printk(KERN_NOTICE
4160 + "RAMDISK: squashfs filesystem found at block %d\n",
4162 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4167 * Read block 1 to test for minix and ext2 superblock