1 diff -urN linux-2.6.19.old/fs/Kconfig linux-2.6.19.dev/fs/Kconfig
2 --- linux-2.6.19.old/fs/Kconfig 2006-12-14 03:13:16.000000000 +0100
3 +++ linux-2.6.19.dev/fs/Kconfig 2006-12-14 03:13:16.000000000 +0100
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.19.old/fs/Makefile linux-2.6.19.dev/fs/Makefile
77 --- linux-2.6.19.old/fs/Makefile 2006-12-14 03:13:16.000000000 +0100
78 +++ linux-2.6.19.dev/fs/Makefile 2006-12-14 03:13:16.000000000 +0100
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.19.old/fs/squashfs/inode.c linux-2.6.19.dev/fs/squashfs/inode.c
88 --- linux-2.6.19.old/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.19.dev/fs/squashfs/inode.c 2006-12-14 03:13:16.000000000 +0100
92 + * Squashfs - a compressed read only filesystem for Linux
94 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
95 + * Phillip Lougher <phillip@lougher.org.uk>
97 + * This program is free software; you can redistribute it and/or
98 + * modify it under the terms of the GNU General Public License
99 + * as published by the Free Software Foundation; either version 2,
100 + * or (at your option) any later version.
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
114 +#include <linux/types.h>
115 +#include <linux/squashfs_fs.h>
116 +#include <linux/module.h>
117 +#include <linux/errno.h>
118 +#include <linux/slab.h>
119 +#include <linux/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 kmem_cache_t * 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, SLAB_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, kmem_cache_t * cachep, unsigned long flags)
2184 + struct squashfs_inode_info *ei = foo;
2186 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2187 + SLAB_CTOR_CONSTRUCTOR)
2188 + inode_init_once(&ei->vfs_inode);
2192 +static int __init init_inodecache(void)
2194 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2195 + sizeof(struct squashfs_inode_info),
2196 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2198 + if (squashfs_inode_cachep == NULL)
2204 +static void destroy_inodecache(void)
2206 + kmem_cache_destroy(squashfs_inode_cachep);
2210 +module_init(init_squashfs_fs);
2211 +module_exit(exit_squashfs_fs);
2212 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2213 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2214 +MODULE_LICENSE("GPL");
2215 diff -urN linux-2.6.19.old/fs/squashfs/Makefile linux-2.6.19.dev/fs/squashfs/Makefile
2216 --- linux-2.6.19.old/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2217 +++ linux-2.6.19.dev/fs/squashfs/Makefile 2006-12-14 03:13:16.000000000 +0100
2220 +# Makefile for the linux squashfs routines.
2223 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2224 +squashfs-y += inode.o
2225 +squashfs-y += squashfs2_0.o
2226 diff -urN linux-2.6.19.old/fs/squashfs/squashfs2_0.c linux-2.6.19.dev/fs/squashfs/squashfs2_0.c
2227 --- linux-2.6.19.old/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2228 +++ linux-2.6.19.dev/fs/squashfs/squashfs2_0.c 2006-12-14 03:13:16.000000000 +0100
2231 + * Squashfs - a compressed read only filesystem for Linux
2233 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2234 + * Phillip Lougher <phillip@lougher.org.uk>
2236 + * This program is free software; you can redistribute it and/or
2237 + * modify it under the terms of the GNU General Public License
2238 + * as published by the Free Software Foundation; either version 2,
2239 + * or (at your option) any later version.
2241 + * This program is distributed in the hope that it will be useful,
2242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2244 + * GNU General Public License for more details.
2246 + * You should have received a copy of the GNU General Public License
2247 + * along with this program; if not, write to the Free Software
2248 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2253 +#include <linux/types.h>
2254 +#include <linux/squashfs_fs.h>
2255 +#include <linux/module.h>
2256 +#include <linux/errno.h>
2257 +#include <linux/slab.h>
2258 +#include <linux/fs.h>
2259 +#include <linux/smp_lock.h>
2260 +#include <linux/slab.h>
2261 +#include <linux/squashfs_fs_sb.h>
2262 +#include <linux/squashfs_fs_i.h>
2263 +#include <linux/buffer_head.h>
2264 +#include <linux/vfs.h>
2265 +#include <linux/init.h>
2266 +#include <linux/dcache.h>
2267 +#include <linux/wait.h>
2268 +#include <linux/zlib.h>
2269 +#include <linux/blkdev.h>
2270 +#include <linux/vmalloc.h>
2271 +#include <asm/uaccess.h>
2272 +#include <asm/semaphore.h>
2274 +#include "squashfs.h"
2275 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2276 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2277 + struct nameidata *);
2279 +static struct file_operations squashfs_dir_ops_2 = {
2280 + .read = generic_read_dir,
2281 + .readdir = squashfs_readdir_2
2284 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2285 + .lookup = squashfs_lookup_2
2288 +static unsigned char squashfs_filetype_table[] = {
2289 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2292 +static int read_fragment_index_table_2(struct super_block *s)
2294 + struct squashfs_sb_info *msblk = s->s_fs_info;
2295 + struct squashfs_super_block *sblk = &msblk->sblk;
2297 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2298 + (sblk->fragments), GFP_KERNEL))) {
2299 + ERROR("Failed to allocate uid/gid table\n");
2303 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2304 + !squashfs_read_data(s, (char *)
2305 + msblk->fragment_index_2,
2306 + sblk->fragment_table_start,
2307 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2308 + (sblk->fragments) |
2309 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2310 + ERROR("unable to read fragment index table\n");
2314 + if (msblk->swap) {
2316 + unsigned int fragment;
2318 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2320 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2321 + &msblk->fragment_index_2[i], 1);
2322 + msblk->fragment_index_2[i] = fragment;
2330 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2331 + long long *fragment_start_block,
2332 + unsigned int *fragment_size)
2334 + struct squashfs_sb_info *msblk = s->s_fs_info;
2335 + long long start_block =
2336 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2337 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2338 + struct squashfs_fragment_entry_2 fragment_entry;
2340 + if (msblk->swap) {
2341 + struct squashfs_fragment_entry_2 sfragment_entry;
2343 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2344 + start_block, offset,
2345 + sizeof(sfragment_entry), &start_block,
2348 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2350 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2351 + start_block, offset,
2352 + sizeof(fragment_entry), &start_block,
2356 + *fragment_start_block = fragment_entry.start_block;
2357 + *fragment_size = fragment_entry.size;
2366 +static struct inode *squashfs_new_inode(struct super_block *s,
2367 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2369 + struct squashfs_sb_info *msblk = s->s_fs_info;
2370 + struct squashfs_super_block *sblk = &msblk->sblk;
2371 + struct inode *i = new_inode(s);
2375 + i->i_mtime.tv_sec = sblk->mkfs_time;
2376 + i->i_atime.tv_sec = sblk->mkfs_time;
2377 + i->i_ctime.tv_sec = sblk->mkfs_time;
2378 + i->i_uid = msblk->uid[inodeb->uid];
2379 + i->i_mode = inodeb->mode;
2382 + if (inodeb->guid == SQUASHFS_GUIDS)
2383 + i->i_gid = i->i_uid;
2385 + i->i_gid = msblk->guid[inodeb->guid];
2392 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2395 + struct squashfs_sb_info *msblk = s->s_fs_info;
2396 + struct squashfs_super_block *sblk = &msblk->sblk;
2397 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2398 + sblk->inode_table_start;
2399 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2400 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2401 + - sblk->inode_table_start, offset);
2402 + long long next_block;
2403 + unsigned int next_offset;
2404 + union squashfs_inode_header_2 id, sid;
2405 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2406 + *sinodeb = &sid.base;
2408 + TRACE("Entered squashfs_iget\n");
2410 + if (msblk->swap) {
2411 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2412 + offset, sizeof(*sinodeb), &next_block,
2415 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2416 + sizeof(*sinodeb));
2418 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2419 + offset, sizeof(*inodeb), &next_block,
2423 + switch(inodeb->inode_type) {
2424 + case SQUASHFS_FILE_TYPE: {
2425 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2426 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2427 + long long frag_blk;
2428 + unsigned int frag_size;
2430 + if (msblk->swap) {
2431 + if (!squashfs_get_cached_block(s, (char *)
2432 + sinodep, block, offset,
2433 + sizeof(*sinodep), &next_block,
2436 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2438 + if (!squashfs_get_cached_block(s, (char *)
2439 + inodep, block, offset,
2440 + sizeof(*inodep), &next_block,
2444 + frag_blk = SQUASHFS_INVALID_BLK;
2445 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2446 + !get_fragment_location_2(s,
2447 + inodep->fragment, &frag_blk, &frag_size))
2450 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2451 + goto failed_read1;
2453 + i->i_size = inodep->file_size;
2454 + i->i_fop = &generic_ro_fops;
2455 + i->i_mode |= S_IFREG;
2456 + i->i_mtime.tv_sec = inodep->mtime;
2457 + i->i_atime.tv_sec = inodep->mtime;
2458 + i->i_ctime.tv_sec = inodep->mtime;
2459 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2460 + i->i_blksize = PAGE_CACHE_SIZE;
2461 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2462 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2463 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2464 + SQUASHFS_I(i)->start_block = inodep->start_block;
2465 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2466 + SQUASHFS_I(i)->offset = next_offset;
2467 + if (sblk->block_size > 4096)
2468 + i->i_data.a_ops = &squashfs_aops;
2470 + i->i_data.a_ops = &squashfs_aops_4K;
2472 + TRACE("File inode %x:%x, start_block %x, "
2473 + "block_list_start %llx, offset %x\n",
2474 + SQUASHFS_INODE_BLK(inode), offset,
2475 + inodep->start_block, next_block,
2479 + case SQUASHFS_DIR_TYPE: {
2480 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2481 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2483 + if (msblk->swap) {
2484 + if (!squashfs_get_cached_block(s, (char *)
2485 + sinodep, block, offset,
2486 + sizeof(*sinodep), &next_block,
2489 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2491 + if (!squashfs_get_cached_block(s, (char *)
2492 + inodep, block, offset,
2493 + sizeof(*inodep), &next_block,
2497 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2498 + goto failed_read1;
2500 + i->i_size = inodep->file_size;
2501 + i->i_op = &squashfs_dir_inode_ops_2;
2502 + i->i_fop = &squashfs_dir_ops_2;
2503 + i->i_mode |= S_IFDIR;
2504 + i->i_mtime.tv_sec = inodep->mtime;
2505 + i->i_atime.tv_sec = inodep->mtime;
2506 + i->i_ctime.tv_sec = inodep->mtime;
2507 + SQUASHFS_I(i)->start_block = inodep->start_block;
2508 + SQUASHFS_I(i)->offset = inodep->offset;
2509 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2510 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2512 + TRACE("Directory inode %x:%x, start_block %x, offset "
2513 + "%x\n", SQUASHFS_INODE_BLK(inode),
2514 + offset, inodep->start_block,
2518 + case SQUASHFS_LDIR_TYPE: {
2519 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2520 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2522 + if (msblk->swap) {
2523 + if (!squashfs_get_cached_block(s, (char *)
2524 + sinodep, block, offset,
2525 + sizeof(*sinodep), &next_block,
2528 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2531 + if (!squashfs_get_cached_block(s, (char *)
2532 + inodep, block, offset,
2533 + sizeof(*inodep), &next_block,
2537 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2538 + goto failed_read1;
2540 + i->i_size = inodep->file_size;
2541 + i->i_op = &squashfs_dir_inode_ops_2;
2542 + i->i_fop = &squashfs_dir_ops_2;
2543 + i->i_mode |= S_IFDIR;
2544 + i->i_mtime.tv_sec = inodep->mtime;
2545 + i->i_atime.tv_sec = inodep->mtime;
2546 + i->i_ctime.tv_sec = inodep->mtime;
2547 + SQUASHFS_I(i)->start_block = inodep->start_block;
2548 + SQUASHFS_I(i)->offset = inodep->offset;
2549 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2550 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2552 + SQUASHFS_I(i)->u.s2.directory_index_count =
2554 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2556 + TRACE("Long directory inode %x:%x, start_block %x, "
2558 + SQUASHFS_INODE_BLK(inode), offset,
2559 + inodep->start_block, inodep->offset);
2562 + case SQUASHFS_SYMLINK_TYPE: {
2563 + struct squashfs_symlink_inode_header_2 *inodep =
2565 + struct squashfs_symlink_inode_header_2 *sinodep =
2568 + if (msblk->swap) {
2569 + if (!squashfs_get_cached_block(s, (char *)
2570 + sinodep, block, offset,
2571 + sizeof(*sinodep), &next_block,
2574 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2577 + if (!squashfs_get_cached_block(s, (char *)
2578 + inodep, block, offset,
2579 + sizeof(*inodep), &next_block,
2583 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2584 + goto failed_read1;
2586 + i->i_size = inodep->symlink_size;
2587 + i->i_op = &page_symlink_inode_operations;
2588 + i->i_data.a_ops = &squashfs_symlink_aops;
2589 + i->i_mode |= S_IFLNK;
2590 + SQUASHFS_I(i)->start_block = next_block;
2591 + SQUASHFS_I(i)->offset = next_offset;
2593 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2595 + SQUASHFS_INODE_BLK(inode), offset,
2596 + next_block, next_offset);
2599 + case SQUASHFS_BLKDEV_TYPE:
2600 + case SQUASHFS_CHRDEV_TYPE: {
2601 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2602 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2604 + if (msblk->swap) {
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + sinodep, block, offset,
2607 + sizeof(*sinodep), &next_block,
2610 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2612 + if (!squashfs_get_cached_block(s, (char *)
2613 + inodep, block, offset,
2614 + sizeof(*inodep), &next_block,
2618 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2619 + goto failed_read1;
2621 + i->i_mode |= (inodeb->inode_type ==
2622 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2624 + init_special_inode(i, i->i_mode,
2625 + old_decode_dev(inodep->rdev));
2627 + TRACE("Device inode %x:%x, rdev %x\n",
2628 + SQUASHFS_INODE_BLK(inode), offset,
2632 + case SQUASHFS_FIFO_TYPE:
2633 + case SQUASHFS_SOCKET_TYPE: {
2634 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2635 + goto failed_read1;
2637 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2638 + ? S_IFIFO : S_IFSOCK;
2639 + init_special_inode(i, i->i_mode, 0);
2643 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2644 + inodeb->inode_type);
2645 + goto failed_read1;
2648 + insert_inode_hash(i);
2652 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2659 +static int get_dir_index_using_offset(struct super_block *s, long long
2660 + *next_block, unsigned int *next_offset,
2661 + long long index_start,
2662 + unsigned int index_offset, int i_count,
2665 + struct squashfs_sb_info *msblk = s->s_fs_info;
2666 + struct squashfs_super_block *sblk = &msblk->sblk;
2667 + int i, length = 0;
2668 + struct squashfs_dir_index_2 index;
2670 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2671 + i_count, (unsigned int) f_pos);
2676 + for (i = 0; i < i_count; i++) {
2677 + if (msblk->swap) {
2678 + struct squashfs_dir_index_2 sindex;
2679 + squashfs_get_cached_block(s, (char *) &sindex,
2680 + index_start, index_offset,
2681 + sizeof(sindex), &index_start,
2683 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2685 + squashfs_get_cached_block(s, (char *) &index,
2686 + index_start, index_offset,
2687 + sizeof(index), &index_start,
2690 + if (index.index > f_pos)
2693 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2694 + index.size + 1, &index_start,
2697 + length = index.index;
2698 + *next_block = index.start_block + sblk->directory_table_start;
2701 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2708 +static int get_dir_index_using_name(struct super_block *s, long long
2709 + *next_block, unsigned int *next_offset,
2710 + long long index_start,
2711 + unsigned int index_offset, int i_count,
2712 + const char *name, int size)
2714 + struct squashfs_sb_info *msblk = s->s_fs_info;
2715 + struct squashfs_super_block *sblk = &msblk->sblk;
2716 + int i, length = 0;
2717 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2718 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2719 + char str[SQUASHFS_NAME_LEN + 1];
2721 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2723 + strncpy(str, name, size);
2726 + for (i = 0; i < i_count; i++) {
2727 + if (msblk->swap) {
2728 + struct squashfs_dir_index_2 sindex;
2729 + squashfs_get_cached_block(s, (char *) &sindex,
2730 + index_start, index_offset,
2731 + sizeof(sindex), &index_start,
2733 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2735 + squashfs_get_cached_block(s, (char *) index,
2736 + index_start, index_offset,
2737 + sizeof(struct squashfs_dir_index_2),
2738 + &index_start, &index_offset);
2740 + squashfs_get_cached_block(s, index->name, index_start,
2741 + index_offset, index->size + 1,
2742 + &index_start, &index_offset);
2744 + index->name[index->size + 1] = '\0';
2746 + if (strcmp(index->name, str) > 0)
2749 + length = index->index;
2750 + *next_block = index->start_block + sblk->directory_table_start;
2753 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2758 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2760 + struct inode *i = file->f_dentry->d_inode;
2761 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2762 + struct squashfs_super_block *sblk = &msblk->sblk;
2763 + long long next_block = SQUASHFS_I(i)->start_block +
2764 + sblk->directory_table_start;
2765 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2767 + struct squashfs_dir_header_2 dirh;
2768 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2769 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2771 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2773 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2774 + SQUASHFS_I(i)->u.s2.directory_index_start,
2775 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2776 + SQUASHFS_I(i)->u.s2.directory_index_count,
2779 + while (length < i_size_read(i)) {
2780 + /* read directory header */
2781 + if (msblk->swap) {
2782 + struct squashfs_dir_header_2 sdirh;
2784 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2785 + next_block, next_offset, sizeof(sdirh),
2786 + &next_block, &next_offset))
2789 + length += sizeof(sdirh);
2790 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2792 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2793 + next_block, next_offset, sizeof(dirh),
2794 + &next_block, &next_offset))
2797 + length += sizeof(dirh);
2800 + dir_count = dirh.count + 1;
2801 + while (dir_count--) {
2802 + if (msblk->swap) {
2803 + struct squashfs_dir_entry_2 sdire;
2804 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2805 + &sdire, next_block, next_offset,
2806 + sizeof(sdire), &next_block,
2810 + length += sizeof(sdire);
2811 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2813 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2814 + dire, next_block, next_offset,
2815 + sizeof(*dire), &next_block,
2819 + length += sizeof(*dire);
2822 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2823 + next_block, next_offset,
2824 + dire->size + 1, &next_block,
2828 + length += dire->size + 1;
2830 + if (file->f_pos >= length)
2833 + dire->name[dire->size + 1] = '\0';
2835 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2836 + (unsigned int) dirent, dire->name,
2837 + dire->size + 1, (int) file->f_pos,
2838 + dirh.start_block, dire->offset,
2839 + squashfs_filetype_table[dire->type]);
2841 + if (filldir(dirent, dire->name, dire->size + 1,
2842 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2843 + dirh.start_block, dire->offset),
2844 + squashfs_filetype_table[dire->type])
2846 + TRACE("Filldir returned less than 0\n");
2849 + file->f_pos = length;
2858 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2864 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2865 + struct nameidata *nd)
2867 + const unsigned char *name = dentry->d_name.name;
2868 + int len = dentry->d_name.len;
2869 + struct inode *inode = NULL;
2870 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2871 + struct squashfs_super_block *sblk = &msblk->sblk;
2872 + long long next_block = SQUASHFS_I(i)->start_block +
2873 + sblk->directory_table_start;
2874 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2876 + struct squashfs_dir_header_2 dirh;
2877 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2878 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2879 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2881 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2883 + if (len > SQUASHFS_NAME_LEN)
2886 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2887 + SQUASHFS_I(i)->u.s2.directory_index_start,
2888 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2889 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2892 + while (length < i_size_read(i)) {
2893 + /* read directory header */
2894 + if (msblk->swap) {
2895 + struct squashfs_dir_header_2 sdirh;
2896 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2897 + next_block, next_offset, sizeof(sdirh),
2898 + &next_block, &next_offset))
2901 + length += sizeof(sdirh);
2902 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2904 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2905 + next_block, next_offset, sizeof(dirh),
2906 + &next_block, &next_offset))
2909 + length += sizeof(dirh);
2912 + dir_count = dirh.count + 1;
2913 + while (dir_count--) {
2914 + if (msblk->swap) {
2915 + struct squashfs_dir_entry_2 sdire;
2916 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2917 + &sdire, next_block,next_offset,
2918 + sizeof(sdire), &next_block,
2922 + length += sizeof(sdire);
2923 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2925 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2926 + dire, next_block,next_offset,
2927 + sizeof(*dire), &next_block,
2931 + length += sizeof(*dire);
2934 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2935 + next_block, next_offset, dire->size + 1,
2936 + &next_block, &next_offset))
2939 + length += dire->size + 1;
2941 + if (sorted && name[0] < dire->name[0])
2944 + if ((len == dire->size + 1) && !strncmp(name,
2945 + dire->name, len)) {
2946 + squashfs_inode_t ino =
2947 + SQUASHFS_MKINODE(dirh.start_block,
2950 + TRACE("calling squashfs_iget for directory "
2951 + "entry %s, inode %x:%x, %lld\n", name,
2952 + dirh.start_block, dire->offset, ino);
2954 + inode = (msblk->iget)(i->i_sb, ino);
2962 + d_add(dentry, inode);
2963 + return ERR_PTR(0);
2966 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2972 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2974 + struct squashfs_super_block *sblk = &msblk->sblk;
2976 + msblk->iget = squashfs_iget_2;
2977 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2979 + sblk->bytes_used = sblk->bytes_used_2;
2980 + sblk->uid_start = sblk->uid_start_2;
2981 + sblk->guid_start = sblk->guid_start_2;
2982 + sblk->inode_table_start = sblk->inode_table_start_2;
2983 + sblk->directory_table_start = sblk->directory_table_start_2;
2984 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2988 diff -urN linux-2.6.19.old/fs/squashfs/squashfs.h linux-2.6.19.dev/fs/squashfs/squashfs.h
2989 --- linux-2.6.19.old/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
2990 +++ linux-2.6.19.dev/fs/squashfs/squashfs.h 2006-12-14 03:13:16.000000000 +0100
2993 + * Squashfs - a compressed read only filesystem for Linux
2995 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2996 + * Phillip Lougher <phillip@lougher.org.uk>
2998 + * This program is free software; you can redistribute it and/or
2999 + * modify it under the terms of the GNU General Public License
3000 + * as published by the Free Software Foundation; either version 2,
3001 + * or (at your option) any later version.
3003 + * This program is distributed in the hope that it will be useful,
3004 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3005 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3006 + * GNU General Public License for more details.
3008 + * You should have received a copy of the GNU General Public License
3009 + * along with this program; if not, write to the Free Software
3010 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3015 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3016 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3019 +#ifdef SQUASHFS_TRACE
3020 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3022 +#define TRACE(s, args...) {}
3025 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3027 +#define SERROR(s, args...) do { \
3029 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3032 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3034 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3036 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3039 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3040 +#define SQSH_EXTERN
3041 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3042 + long long index, unsigned int length,
3043 + long long *next_index);
3044 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3045 + long long block, unsigned int offset,
3046 + int length, long long *next_block,
3047 + unsigned int *next_offset);
3048 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3049 + squashfs_fragment_cache *fragment);
3050 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3051 + *s, long long start_block,
3053 +extern struct address_space_operations squashfs_symlink_aops;
3054 +extern struct address_space_operations squashfs_aops;
3055 +extern struct address_space_operations squashfs_aops_4K;
3056 +extern struct inode_operations squashfs_dir_inode_ops;
3058 +#define SQSH_EXTERN static
3061 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3062 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3064 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3070 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3071 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3073 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3078 diff -urN linux-2.6.19.old/include/linux/squashfs_fs.h linux-2.6.19.dev/include/linux/squashfs_fs.h
3079 --- linux-2.6.19.old/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3080 +++ linux-2.6.19.dev/include/linux/squashfs_fs.h 2006-12-14 03:13:16.000000000 +0100
3082 +#ifndef SQUASHFS_FS
3083 +#define SQUASHFS_FS
3088 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3089 + * Phillip Lougher <phillip@lougher.org.uk>
3091 + * This program is free software; you can redistribute it and/or
3092 + * modify it under the terms of the GNU General Public License
3093 + * as published by the Free Software Foundation; either version 2,
3094 + * or (at your option) any later version.
3096 + * This program is distributed in the hope that it will be useful,
3097 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3098 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3099 + * GNU General Public License for more details.
3101 + * You should have received a copy of the GNU General Public License
3102 + * along with this program; if not, write to the Free Software
3103 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3108 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3109 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3112 +#ifdef CONFIG_SQUASHFS_VMALLOC
3113 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3114 +#define SQUASHFS_FREE(a) vfree(a)
3116 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3117 +#define SQUASHFS_FREE(a) kfree(a)
3119 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3120 +#define SQUASHFS_MAJOR 3
3121 +#define SQUASHFS_MINOR 0
3122 +#define SQUASHFS_MAGIC 0x73717368
3123 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3124 +#define SQUASHFS_START 0
3126 +/* size of metadata (inode and directory) blocks */
3127 +#define SQUASHFS_METADATA_SIZE 8192
3128 +#define SQUASHFS_METADATA_LOG 13
3130 +/* default size of data blocks */
3131 +#define SQUASHFS_FILE_SIZE 65536
3132 +#define SQUASHFS_FILE_LOG 16
3134 +#define SQUASHFS_FILE_MAX_SIZE 65536
3136 +/* Max number of uids and gids */
3137 +#define SQUASHFS_UIDS 256
3138 +#define SQUASHFS_GUIDS 255
3140 +/* Max length of filename (not 255) */
3141 +#define SQUASHFS_NAME_LEN 256
3143 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3144 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3145 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3146 +#define SQUASHFS_USED_BLK ((long long) -2)
3148 +/* Filesystem flags */
3149 +#define SQUASHFS_NOI 0
3150 +#define SQUASHFS_NOD 1
3151 +#define SQUASHFS_CHECK 2
3152 +#define SQUASHFS_NOF 3
3153 +#define SQUASHFS_NO_FRAG 4
3154 +#define SQUASHFS_ALWAYS_FRAG 5
3155 +#define SQUASHFS_DUPLICATE 6
3157 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3159 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3162 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3165 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3168 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3171 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3172 + SQUASHFS_ALWAYS_FRAG)
3174 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3175 + SQUASHFS_DUPLICATE)
3177 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3180 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3181 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3182 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3183 + (duplicate_checking << 6))
3185 +/* Max number of types and file types */
3186 +#define SQUASHFS_DIR_TYPE 1
3187 +#define SQUASHFS_FILE_TYPE 2
3188 +#define SQUASHFS_SYMLINK_TYPE 3
3189 +#define SQUASHFS_BLKDEV_TYPE 4
3190 +#define SQUASHFS_CHRDEV_TYPE 5
3191 +#define SQUASHFS_FIFO_TYPE 6
3192 +#define SQUASHFS_SOCKET_TYPE 7
3193 +#define SQUASHFS_LDIR_TYPE 8
3194 +#define SQUASHFS_LREG_TYPE 9
3196 +/* 1.0 filesystem type definitions */
3197 +#define SQUASHFS_TYPES 5
3198 +#define SQUASHFS_IPC_TYPE 0
3200 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3202 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3204 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3205 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3207 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3209 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3211 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3212 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3213 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3215 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3218 + * Inode number ops. Inodes consist of a compressed block number, and an
3219 + * uncompressed offset within that block
3221 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3223 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3225 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3228 +/* Compute 32 bit VFS inode number from squashfs inode number */
3229 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3233 +/* Translate between VFS mode and squashfs mode */
3234 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3236 +/* fragment and fragment table defines */
3237 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3239 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3240 + SQUASHFS_METADATA_SIZE)
3242 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3243 + SQUASHFS_METADATA_SIZE)
3245 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3246 + SQUASHFS_METADATA_SIZE - 1) / \
3247 + SQUASHFS_METADATA_SIZE)
3249 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3250 + sizeof(long long))
3252 +/* cached data constants for filesystem */
3253 +#define SQUASHFS_CACHED_BLKS 8
3255 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3257 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3258 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3260 +#define SQUASHFS_MARKER_BYTE 0xff
3262 +/* meta index cache */
3263 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3264 +#define SQUASHFS_META_ENTRIES 31
3265 +#define SQUASHFS_META_NUMBER 8
3266 +#define SQUASHFS_SLOTS 4
3268 +struct meta_entry {
3269 + long long data_block;
3270 + unsigned int index_block;
3271 + unsigned short offset;
3272 + unsigned short pad;
3275 +struct meta_index {
3276 + unsigned int inode_number;
3277 + unsigned int offset;
3278 + unsigned short entries;
3279 + unsigned short skip;
3280 + unsigned short locked;
3281 + unsigned short pad;
3282 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3287 + * definitions for structures on disk
3290 +typedef long long squashfs_block_t;
3291 +typedef long long squashfs_inode_t;
3293 +struct squashfs_super_block {
3294 + unsigned int s_magic;
3295 + unsigned int inodes;
3296 + unsigned int bytes_used_2;
3297 + unsigned int uid_start_2;
3298 + unsigned int guid_start_2;
3299 + unsigned int inode_table_start_2;
3300 + unsigned int directory_table_start_2;
3301 + unsigned int s_major:16;
3302 + unsigned int s_minor:16;
3303 + unsigned int block_size_1:16;
3304 + unsigned int block_log:16;
3305 + unsigned int flags:8;
3306 + unsigned int no_uids:8;
3307 + unsigned int no_guids:8;
3308 + unsigned int mkfs_time /* time of filesystem creation */;
3309 + squashfs_inode_t root_inode;
3310 + unsigned int block_size;
3311 + unsigned int fragments;
3312 + unsigned int fragment_table_start_2;
3313 + long long bytes_used;
3314 + long long uid_start;
3315 + long long guid_start;
3316 + long long inode_table_start;
3317 + long long directory_table_start;
3318 + long long fragment_table_start;
3320 +} __attribute__ ((packed));
3322 +struct squashfs_dir_index {
3323 + unsigned int index;
3324 + unsigned int start_block;
3325 + unsigned char size;
3326 + unsigned char name[0];
3327 +} __attribute__ ((packed));
3329 +#define SQUASHFS_BASE_INODE_HEADER \
3330 + unsigned int inode_type:4; \
3331 + unsigned int mode:12; \
3332 + unsigned int uid:8; \
3333 + unsigned int guid:8; \
3334 + unsigned int mtime; \
3335 + unsigned int inode_number;
3337 +struct squashfs_base_inode_header {
3338 + SQUASHFS_BASE_INODE_HEADER;
3339 +} __attribute__ ((packed));
3341 +struct squashfs_ipc_inode_header {
3342 + SQUASHFS_BASE_INODE_HEADER;
3343 + unsigned int nlink;
3344 +} __attribute__ ((packed));
3346 +struct squashfs_dev_inode_header {
3347 + SQUASHFS_BASE_INODE_HEADER;
3348 + unsigned int nlink;
3349 + unsigned short rdev;
3350 +} __attribute__ ((packed));
3352 +struct squashfs_symlink_inode_header {
3353 + SQUASHFS_BASE_INODE_HEADER;
3354 + unsigned int nlink;
3355 + unsigned short symlink_size;
3357 +} __attribute__ ((packed));
3359 +struct squashfs_reg_inode_header {
3360 + SQUASHFS_BASE_INODE_HEADER;
3361 + squashfs_block_t start_block;
3362 + unsigned int fragment;
3363 + unsigned int offset;
3364 + unsigned int file_size;
3365 + unsigned short block_list[0];
3366 +} __attribute__ ((packed));
3368 +struct squashfs_lreg_inode_header {
3369 + SQUASHFS_BASE_INODE_HEADER;
3370 + unsigned int nlink;
3371 + squashfs_block_t start_block;
3372 + unsigned int fragment;
3373 + unsigned int offset;
3374 + long long file_size;
3375 + unsigned short block_list[0];
3376 +} __attribute__ ((packed));
3378 +struct squashfs_dir_inode_header {
3379 + SQUASHFS_BASE_INODE_HEADER;
3380 + unsigned int nlink;
3381 + unsigned int file_size:19;
3382 + unsigned int offset:13;
3383 + unsigned int start_block;
3384 + unsigned int parent_inode;
3385 +} __attribute__ ((packed));
3387 +struct squashfs_ldir_inode_header {
3388 + SQUASHFS_BASE_INODE_HEADER;
3389 + unsigned int nlink;
3390 + unsigned int file_size:27;
3391 + unsigned int offset:13;
3392 + unsigned int start_block;
3393 + unsigned int i_count:16;
3394 + unsigned int parent_inode;
3395 + struct squashfs_dir_index index[0];
3396 +} __attribute__ ((packed));
3398 +union squashfs_inode_header {
3399 + struct squashfs_base_inode_header base;
3400 + struct squashfs_dev_inode_header dev;
3401 + struct squashfs_symlink_inode_header symlink;
3402 + struct squashfs_reg_inode_header reg;
3403 + struct squashfs_lreg_inode_header lreg;
3404 + struct squashfs_dir_inode_header dir;
3405 + struct squashfs_ldir_inode_header ldir;
3406 + struct squashfs_ipc_inode_header ipc;
3409 +struct squashfs_dir_entry {
3410 + unsigned int offset:13;
3411 + unsigned int type:3;
3412 + unsigned int size:8;
3413 + int inode_number:16;
3415 +} __attribute__ ((packed));
3417 +struct squashfs_dir_header {
3418 + unsigned int count:8;
3419 + unsigned int start_block;
3420 + unsigned int inode_number;
3421 +} __attribute__ ((packed));
3423 +struct squashfs_fragment_entry {
3424 + long long start_block;
3425 + unsigned int size;
3426 + unsigned int unused;
3427 +} __attribute__ ((packed));
3429 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3430 +extern int squashfs_uncompress_init(void);
3431 +extern int squashfs_uncompress_exit(void);
3434 + * macros to convert each packed bitfield structure from little endian to big
3435 + * endian and vice versa. These are needed when creating or using a filesystem
3436 + * on a machine with different byte ordering to the target architecture.
3440 +#define SQUASHFS_SWAP_START \
3443 + unsigned long long val;\
3444 + unsigned char *s;\
3447 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3448 + SQUASHFS_SWAP_START\
3449 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3450 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3451 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3452 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3453 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3454 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3455 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3456 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3457 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3458 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3459 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3460 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3461 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3462 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3463 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3464 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3465 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3466 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3467 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3468 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3469 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3470 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3471 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3472 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3473 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3474 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3475 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3478 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3479 + SQUASHFS_MEMSET(s, d, n);\
3480 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3481 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3482 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3483 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3484 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3485 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3487 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3488 + SQUASHFS_SWAP_START\
3489 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3492 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3493 + SQUASHFS_SWAP_START\
3494 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3495 + sizeof(struct squashfs_ipc_inode_header))\
3496 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3499 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3500 + SQUASHFS_SWAP_START\
3501 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3502 + sizeof(struct squashfs_dev_inode_header)); \
3503 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3504 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3507 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3508 + SQUASHFS_SWAP_START\
3509 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3510 + sizeof(struct squashfs_symlink_inode_header));\
3511 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3512 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3515 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3516 + SQUASHFS_SWAP_START\
3517 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3518 + sizeof(struct squashfs_reg_inode_header));\
3519 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3520 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3521 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3522 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3525 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3526 + SQUASHFS_SWAP_START\
3527 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3528 + sizeof(struct squashfs_lreg_inode_header));\
3529 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3530 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3531 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3532 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3533 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3536 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3537 + SQUASHFS_SWAP_START\
3538 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3539 + sizeof(struct squashfs_dir_inode_header));\
3540 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3541 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3542 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3543 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3544 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3547 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3548 + SQUASHFS_SWAP_START\
3549 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 + sizeof(struct squashfs_ldir_inode_header));\
3551 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3553 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3554 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3555 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3556 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3559 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3560 + SQUASHFS_SWAP_START\
3561 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3562 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3563 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3564 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3567 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3568 + SQUASHFS_SWAP_START\
3569 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3570 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3571 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3572 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3575 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3576 + SQUASHFS_SWAP_START\
3577 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3578 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3579 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3580 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3581 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3584 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3585 + SQUASHFS_SWAP_START\
3586 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3587 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3588 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3591 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3593 + int bit_position;\
3594 + SQUASHFS_SWAP_START\
3595 + SQUASHFS_MEMSET(s, d, n * 2);\
3596 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3598 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3601 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3603 + int bit_position;\
3604 + SQUASHFS_SWAP_START\
3605 + SQUASHFS_MEMSET(s, d, n * 4);\
3606 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3608 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3611 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3613 + int bit_position;\
3614 + SQUASHFS_SWAP_START\
3615 + SQUASHFS_MEMSET(s, d, n * 8);\
3616 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3618 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3621 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3623 + int bit_position;\
3624 + SQUASHFS_SWAP_START\
3625 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3626 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3628 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3631 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3633 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3635 +struct squashfs_base_inode_header_1 {
3636 + unsigned int inode_type:4;
3637 + unsigned int mode:12; /* protection */
3638 + unsigned int uid:4; /* index into uid table */
3639 + unsigned int guid:4; /* index into guid table */
3640 +} __attribute__ ((packed));
3642 +struct squashfs_ipc_inode_header_1 {
3643 + unsigned int inode_type:4;
3644 + unsigned int mode:12; /* protection */
3645 + unsigned int uid:4; /* index into uid table */
3646 + unsigned int guid:4; /* index into guid table */
3647 + unsigned int type:4;
3648 + unsigned int offset:4;
3649 +} __attribute__ ((packed));
3651 +struct squashfs_dev_inode_header_1 {
3652 + unsigned int inode_type:4;
3653 + unsigned int mode:12; /* protection */
3654 + unsigned int uid:4; /* index into uid table */
3655 + unsigned int guid:4; /* index into guid table */
3656 + unsigned short rdev;
3657 +} __attribute__ ((packed));
3659 +struct squashfs_symlink_inode_header_1 {
3660 + unsigned int inode_type:4;
3661 + unsigned int mode:12; /* protection */
3662 + unsigned int uid:4; /* index into uid table */
3663 + unsigned int guid:4; /* index into guid table */
3664 + unsigned short symlink_size;
3666 +} __attribute__ ((packed));
3668 +struct squashfs_reg_inode_header_1 {
3669 + unsigned int inode_type:4;
3670 + unsigned int mode:12; /* protection */
3671 + unsigned int uid:4; /* index into uid table */
3672 + unsigned int guid:4; /* index into guid table */
3673 + unsigned int mtime;
3674 + unsigned int start_block;
3675 + unsigned int file_size:32;
3676 + unsigned short block_list[0];
3677 +} __attribute__ ((packed));
3679 +struct squashfs_dir_inode_header_1 {
3680 + unsigned int inode_type:4;
3681 + unsigned int mode:12; /* protection */
3682 + unsigned int uid:4; /* index into uid table */
3683 + unsigned int guid:4; /* index into guid table */
3684 + unsigned int file_size:19;
3685 + unsigned int offset:13;
3686 + unsigned int mtime;
3687 + unsigned int start_block:24;
3688 +} __attribute__ ((packed));
3690 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3691 + SQUASHFS_MEMSET(s, d, n);\
3692 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3693 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3694 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3695 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3697 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3698 + SQUASHFS_SWAP_START\
3699 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3702 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3703 + SQUASHFS_SWAP_START\
3704 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3705 + sizeof(struct squashfs_ipc_inode_header_1));\
3706 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3707 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3710 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3711 + SQUASHFS_SWAP_START\
3712 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3713 + sizeof(struct squashfs_dev_inode_header_1));\
3714 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3717 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3718 + SQUASHFS_SWAP_START\
3719 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3720 + sizeof(struct squashfs_symlink_inode_header_1));\
3721 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3724 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3725 + SQUASHFS_SWAP_START\
3726 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3727 + sizeof(struct squashfs_reg_inode_header_1));\
3728 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3729 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3730 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3733 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3734 + SQUASHFS_SWAP_START\
3735 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3736 + sizeof(struct squashfs_dir_inode_header_1));\
3737 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3738 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3739 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3740 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3745 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3747 +struct squashfs_dir_index_2 {
3748 + unsigned int index:27;
3749 + unsigned int start_block:29;
3750 + unsigned char size;
3751 + unsigned char name[0];
3752 +} __attribute__ ((packed));
3754 +struct squashfs_base_inode_header_2 {
3755 + unsigned int inode_type:4;
3756 + unsigned int mode:12; /* protection */
3757 + unsigned int uid:8; /* index into uid table */
3758 + unsigned int guid:8; /* index into guid table */
3759 +} __attribute__ ((packed));
3761 +struct squashfs_ipc_inode_header_2 {
3762 + unsigned int inode_type:4;
3763 + unsigned int mode:12; /* protection */
3764 + unsigned int uid:8; /* index into uid table */
3765 + unsigned int guid:8; /* index into guid table */
3766 +} __attribute__ ((packed));
3768 +struct squashfs_dev_inode_header_2 {
3769 + unsigned int inode_type:4;
3770 + unsigned int mode:12; /* protection */
3771 + unsigned int uid:8; /* index into uid table */
3772 + unsigned int guid:8; /* index into guid table */
3773 + unsigned short rdev;
3774 +} __attribute__ ((packed));
3776 +struct squashfs_symlink_inode_header_2 {
3777 + unsigned int inode_type:4;
3778 + unsigned int mode:12; /* protection */
3779 + unsigned int uid:8; /* index into uid table */
3780 + unsigned int guid:8; /* index into guid table */
3781 + unsigned short symlink_size;
3783 +} __attribute__ ((packed));
3785 +struct squashfs_reg_inode_header_2 {
3786 + unsigned int inode_type:4;
3787 + unsigned int mode:12; /* protection */
3788 + unsigned int uid:8; /* index into uid table */
3789 + unsigned int guid:8; /* index into guid table */
3790 + unsigned int mtime;
3791 + unsigned int start_block;
3792 + unsigned int fragment;
3793 + unsigned int offset;
3794 + unsigned int file_size:32;
3795 + unsigned short block_list[0];
3796 +} __attribute__ ((packed));
3798 +struct squashfs_dir_inode_header_2 {
3799 + unsigned int inode_type:4;
3800 + unsigned int mode:12; /* protection */
3801 + unsigned int uid:8; /* index into uid table */
3802 + unsigned int guid:8; /* index into guid table */
3803 + unsigned int file_size:19;
3804 + unsigned int offset:13;
3805 + unsigned int mtime;
3806 + unsigned int start_block:24;
3807 +} __attribute__ ((packed));
3809 +struct squashfs_ldir_inode_header_2 {
3810 + unsigned int inode_type:4;
3811 + unsigned int mode:12; /* protection */
3812 + unsigned int uid:8; /* index into uid table */
3813 + unsigned int guid:8; /* index into guid table */
3814 + unsigned int file_size:27;
3815 + unsigned int offset:13;
3816 + unsigned int mtime;
3817 + unsigned int start_block:24;
3818 + unsigned int i_count:16;
3819 + struct squashfs_dir_index_2 index[0];
3820 +} __attribute__ ((packed));
3822 +union squashfs_inode_header_2 {
3823 + struct squashfs_base_inode_header_2 base;
3824 + struct squashfs_dev_inode_header_2 dev;
3825 + struct squashfs_symlink_inode_header_2 symlink;
3826 + struct squashfs_reg_inode_header_2 reg;
3827 + struct squashfs_dir_inode_header_2 dir;
3828 + struct squashfs_ldir_inode_header_2 ldir;
3829 + struct squashfs_ipc_inode_header_2 ipc;
3832 +struct squashfs_dir_header_2 {
3833 + unsigned int count:8;
3834 + unsigned int start_block:24;
3835 +} __attribute__ ((packed));
3837 +struct squashfs_dir_entry_2 {
3838 + unsigned int offset:13;
3839 + unsigned int type:3;
3840 + unsigned int size:8;
3842 +} __attribute__ ((packed));
3844 +struct squashfs_fragment_entry_2 {
3845 + unsigned int start_block;
3846 + unsigned int size;
3847 +} __attribute__ ((packed));
3849 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3850 + SQUASHFS_MEMSET(s, d, n);\
3851 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3852 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3853 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3854 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3856 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3857 + SQUASHFS_SWAP_START\
3858 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3861 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3862 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3864 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3865 + SQUASHFS_SWAP_START\
3866 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3867 + sizeof(struct squashfs_dev_inode_header_2)); \
3868 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3871 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3872 + SQUASHFS_SWAP_START\
3873 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3874 + sizeof(struct squashfs_symlink_inode_header_2));\
3875 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3878 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3879 + SQUASHFS_SWAP_START\
3880 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3881 + sizeof(struct squashfs_reg_inode_header_2));\
3882 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3883 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3884 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3885 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3886 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3889 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3890 + SQUASHFS_SWAP_START\
3891 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3892 + sizeof(struct squashfs_dir_inode_header_2));\
3893 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3894 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3895 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3896 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3899 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3900 + SQUASHFS_SWAP_START\
3901 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3902 + sizeof(struct squashfs_ldir_inode_header_2));\
3903 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3904 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3905 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3906 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3907 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3910 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3911 + SQUASHFS_SWAP_START\
3912 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3913 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3914 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3915 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3917 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3918 + SQUASHFS_SWAP_START\
3919 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3920 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3921 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3924 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3925 + SQUASHFS_SWAP_START\
3926 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3927 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3928 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3929 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3932 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3933 + SQUASHFS_SWAP_START\
3934 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3935 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3936 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3939 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3941 +/* fragment and fragment table defines */
3942 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3944 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3945 + SQUASHFS_METADATA_SIZE)
3947 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3948 + SQUASHFS_METADATA_SIZE)
3950 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3951 + SQUASHFS_METADATA_SIZE - 1) / \
3952 + SQUASHFS_METADATA_SIZE)
3954 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3962 + * macros used to swap each structure entry, taking into account
3963 + * bitfields and different bitfield placing conventions on differing
3967 +#include <asm/byteorder.h>
3969 +#ifdef __BIG_ENDIAN
3970 + /* convert from little endian to big endian */
3971 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3974 + /* convert from big endian to little endian */
3975 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3976 + tbits, 64 - tbits - b_pos)
3979 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3982 + s = (unsigned char *)p + (pos / 8);\
3983 + d = ((unsigned char *) &val) + 7;\
3984 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3986 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3989 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3993 diff -urN linux-2.6.19.old/include/linux/squashfs_fs_i.h linux-2.6.19.dev/include/linux/squashfs_fs_i.h
3994 --- linux-2.6.19.old/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
3995 +++ linux-2.6.19.dev/include/linux/squashfs_fs_i.h 2006-12-14 03:13:16.000000000 +0100
3997 +#ifndef SQUASHFS_FS_I
3998 +#define SQUASHFS_FS_I
4002 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4003 + * Phillip Lougher <phillip@lougher.org.uk>
4005 + * This program is free software; you can redistribute it and/or
4006 + * modify it under the terms of the GNU General Public License
4007 + * as published by the Free Software Foundation; either version 2,
4008 + * or (at your option) any later version.
4010 + * This program is distributed in the hope that it will be useful,
4011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4013 + * GNU General Public License for more details.
4015 + * You should have received a copy of the GNU General Public License
4016 + * along with this program; if not, write to the Free Software
4017 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4022 +struct squashfs_inode_info {
4023 + long long start_block;
4024 + unsigned int offset;
4027 + long long fragment_start_block;
4028 + unsigned int fragment_size;
4029 + unsigned int fragment_offset;
4030 + long long block_list_start;
4033 + long long directory_index_start;
4034 + unsigned int directory_index_offset;
4035 + unsigned int directory_index_count;
4036 + unsigned int parent_inode;
4039 + struct inode vfs_inode;
4042 diff -urN linux-2.6.19.old/include/linux/squashfs_fs_sb.h linux-2.6.19.dev/include/linux/squashfs_fs_sb.h
4043 --- linux-2.6.19.old/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4044 +++ linux-2.6.19.dev/include/linux/squashfs_fs_sb.h 2006-12-14 03:13:16.000000000 +0100
4046 +#ifndef SQUASHFS_FS_SB
4047 +#define SQUASHFS_FS_SB
4051 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4052 + * Phillip Lougher <phillip@lougher.org.uk>
4054 + * This program is free software; you can redistribute it and/or
4055 + * modify it under the terms of the GNU General Public License
4056 + * as published by the Free Software Foundation; either version 2,
4057 + * or (at your option) any later version.
4059 + * This program is distributed in the hope that it will be useful,
4060 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4061 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4062 + * GNU General Public License for more details.
4064 + * You should have received a copy of the GNU General Public License
4065 + * along with this program; if not, write to the Free Software
4066 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4068 + * squashfs_fs_sb.h
4071 +#include <linux/squashfs_fs.h>
4073 +struct squashfs_cache {
4076 + long long next_index;
4080 +struct squashfs_fragment_cache {
4083 + unsigned int locked;
4087 +struct squashfs_sb_info {
4088 + struct squashfs_super_block sblk;
4090 + int devblksize_log2;
4092 + struct squashfs_cache *block_cache;
4093 + struct squashfs_fragment_cache *fragment;
4095 + int next_fragment;
4096 + int next_meta_index;
4097 + unsigned int *uid;
4098 + unsigned int *guid;
4099 + long long *fragment_index;
4100 + unsigned int *fragment_index_2;
4101 + unsigned int read_size;
4104 + struct semaphore read_data_mutex;
4105 + struct semaphore read_page_mutex;
4106 + struct semaphore block_cache_mutex;
4107 + struct semaphore fragment_mutex;
4108 + struct semaphore meta_index_mutex;
4109 + wait_queue_head_t waitq;
4110 + wait_queue_head_t fragment_wait_queue;
4111 + struct meta_index *meta_index;
4112 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4114 + long long (*read_blocklist)(struct inode *inode, int \
4115 + index, int readahead_blks, char *block_list, \
4116 + unsigned short **block_p, unsigned int *bsize);
4117 + int (*read_fragment_index_table)(struct super_block *s);
4120 diff -urN linux-2.6.19.old/init/do_mounts_rd.c linux-2.6.19.dev/init/do_mounts_rd.c
4121 --- linux-2.6.19.old/init/do_mounts_rd.c 2006-11-29 22:57:37.000000000 +0100
4122 +++ linux-2.6.19.dev/init/do_mounts_rd.c 2006-12-14 03:13:16.000000000 +0100
4124 #include <linux/ext2_fs.h>
4125 #include <linux/romfs_fs.h>
4126 #include <linux/cramfs_fs.h>
4127 +#include <linux/squashfs_fs.h>
4128 #include <linux/initrd.h>
4129 #include <linux/string.h>
4132 * numbers could not be found.
4134 * We currently check for the following magic numbers:
4140 struct ext2_super_block *ext2sb;
4141 struct romfs_super_block *romfsb;
4142 struct cramfs_super *cramfsb;
4143 + struct squashfs_super_block *squashfsb;
4148 ext2sb = (struct ext2_super_block *) buf;
4149 romfsb = (struct romfs_super_block *) buf;
4150 cramfsb = (struct cramfs_super *) buf;
4151 + squashfsb = (struct squashfs_super_block *) buf;
4152 memset(buf, 0xe5, size);
4155 @@ -101,6 +105,15 @@
4159 + /* squashfs is at block zero too */
4160 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4161 + printk(KERN_NOTICE
4162 + "RAMDISK: squashfs filesystem found at block %d\n",
4164 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4169 * Read block 1 to test for minix and ext2 superblock