1 diff -x .gitignore -Nurp linux-2.6.20/fs/Kconfig linux-2.6.20-squashfs3.2-r2/fs/Kconfig
2 --- linux-2.6.20/fs/Kconfig 2006-12-25 01:13:12.000000000 +0000
3 +++ linux-2.6.20-squashfs3.2-r2/fs/Kconfig 2007-01-16 02:06:03.000000000 +0000
4 @@ -1404,6 +1404,71 @@ config CRAMFS
9 + tristate "SquashFS 3.2 - Squashed file system support"
12 + Saying Y here includes support for SquashFS 3.2 (a Compressed Read-Only File
13 + System). Squashfs is a highly compressed read-only filesystem for Linux.
14 + It uses zlib compression to compress both files, inodes and directories.
15 + Inodes in the system are very small and all blocks are packed to minimise
16 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
17 + SquashFS 3.1 supports 64 bit filesystems and files (larger than 4GB), full
18 + uid/gid information, hard links and timestamps.
20 + Squashfs is intended for general read-only filesystem use, for archival
21 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
22 + systems where low overhead is needed. Further information and filesystem tools
23 + are available from http://squashfs.sourceforge.net.
25 + If you want to compile this as a module ( = code which can be
26 + inserted in and removed from the running kernel whenever you want),
27 + say M here and read <file:Documentation/modules.txt>. The module
28 + will be called squashfs. Note that the root file system (the one
29 + containing the directory /) cannot be compiled as a module.
33 +config SQUASHFS_EMBEDDED
35 + bool "Additional options for memory-constrained systems"
39 + Saying Y here allows you to specify cache sizes and how Squashfs
40 + allocates memory. This is only intended for memory constrained
45 +config SQUASHFS_FRAGMENT_CACHE_SIZE
46 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
50 + By default SquashFS caches the last 3 fragments read from
51 + the filesystem. Increasing this amount may mean SquashFS
52 + has to re-read fragments less often from disk, at the expense
53 + of extra system memory. Decreasing this amount will mean
54 + SquashFS uses less memory at the expense of extra reads from disk.
56 + Note there must be at least one cached fragment. Anything
57 + much more than three will probably not make much difference.
59 +config SQUASHFS_VMALLOC
60 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
64 + By default SquashFS uses kmalloc to obtain fragment cache memory.
65 + Kmalloc memory is the standard kernel allocator, but it can fail
66 + on memory constrained systems. Because of the way Vmalloc works,
67 + Vmalloc can succeed when kmalloc fails. Specifying this option
68 + will make SquashFS always use Vmalloc to allocate the
69 + fragment cache memory.
74 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
76 diff -x .gitignore -Nurp linux-2.6.20/fs/Makefile linux-2.6.20-squashfs3.2-r2/fs/Makefile
77 --- linux-2.6.20/fs/Makefile 2006-12-25 01:13:12.000000000 +0000
78 +++ linux-2.6.20-squashfs3.2-r2/fs/Makefile 2007-01-16 02:06:03.000000000 +0000
79 @@ -68,6 +68,7 @@ obj-$(CONFIG_JBD) += jbd/
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 -x .gitignore -Nurp linux-2.6.20/fs/squashfs/inode.c linux-2.6.20-squashfs3.2-r2/fs/squashfs/inode.c
88 --- linux-2.6.20/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.20-squashfs3.2-r2/fs/squashfs/inode.c 2007-01-16 02:28:36.000000000 +0000
92 + * Squashfs - a compressed read only filesystem for Linux
94 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
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/squashfs_fs.h>
115 +#include <linux/module.h>
116 +#include <linux/zlib.h>
117 +#include <linux/fs.h>
118 +#include <linux/squashfs_fs_sb.h>
119 +#include <linux/squashfs_fs_i.h>
120 +#include <linux/buffer_head.h>
121 +#include <linux/vfs.h>
122 +#include <linux/vmalloc.h>
123 +#include <linux/smp_lock.h>
125 +#include "squashfs.h"
127 +static void vfs_read_inode(struct inode *i);
128 +static struct dentry *squashfs_get_parent(struct dentry *child);
129 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
130 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
131 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
132 +static long long read_blocklist(struct inode *inode, int index,
133 + int readahead_blks, char *block_list,
134 + unsigned short **block_p, unsigned int *bsize);
135 +static int squashfs_readpage(struct file *file, struct page *page);
136 +static int squashfs_readpage4K(struct file *file, struct page *page);
137 +static int squashfs_readdir(struct file *, void *, filldir_t);
138 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
139 + struct nameidata *);
140 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
141 +static void squashfs_put_super(struct super_block *);
142 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
143 + struct vfsmount *);
144 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
145 +static void squashfs_destroy_inode(struct inode *inode);
146 +static int init_inodecache(void);
147 +static void destroy_inodecache(void);
149 +static struct file_system_type squashfs_fs_type = {
150 + .owner = THIS_MODULE,
151 + .name = "squashfs",
152 + .get_sb = squashfs_get_sb,
153 + .kill_sb = kill_block_super,
154 + .fs_flags = FS_REQUIRES_DEV
157 +static const unsigned char squashfs_filetype_table[] = {
158 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
161 +static struct super_operations squashfs_super_ops = {
162 + .alloc_inode = squashfs_alloc_inode,
163 + .destroy_inode = squashfs_destroy_inode,
164 + .statfs = squashfs_statfs,
165 + .put_super = squashfs_put_super,
166 + .remount_fs = squashfs_remount
169 +static struct super_operations squashfs_export_super_ops = {
170 + .alloc_inode = squashfs_alloc_inode,
171 + .destroy_inode = squashfs_destroy_inode,
172 + .statfs = squashfs_statfs,
173 + .put_super = squashfs_put_super,
174 + .read_inode = vfs_read_inode
177 +static struct export_operations squashfs_export_ops = {
178 + .get_parent = squashfs_get_parent
181 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
182 + .readpage = squashfs_symlink_readpage
185 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
186 + .readpage = squashfs_readpage
189 +SQSH_EXTERN const struct address_space_operations squashfs_aops_4K = {
190 + .readpage = squashfs_readpage4K
193 +static const struct file_operations squashfs_dir_ops = {
194 + .read = generic_read_dir,
195 + .readdir = squashfs_readdir
198 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
199 + .lookup = squashfs_lookup
203 +static struct buffer_head *get_block_length(struct super_block *s,
204 + int *cur_index, int *offset, int *c_byte)
206 + struct squashfs_sb_info *msblk = s->s_fs_info;
207 + unsigned short temp;
208 + struct buffer_head *bh;
210 + if (!(bh = sb_bread(s, *cur_index)))
213 + if (msblk->devblksize - *offset == 1) {
215 + ((unsigned char *) &temp)[1] = *((unsigned char *)
216 + (bh->b_data + *offset));
218 + ((unsigned char *) &temp)[0] = *((unsigned char *)
219 + (bh->b_data + *offset));
221 + if (!(bh = sb_bread(s, ++(*cur_index))))
224 + ((unsigned char *) &temp)[0] = *((unsigned char *)
227 + ((unsigned char *) &temp)[1] = *((unsigned char *)
233 + ((unsigned char *) &temp)[1] = *((unsigned char *)
234 + (bh->b_data + *offset));
235 + ((unsigned char *) &temp)[0] = *((unsigned char *)
236 + (bh->b_data + *offset + 1));
238 + ((unsigned char *) &temp)[0] = *((unsigned char *)
239 + (bh->b_data + *offset));
240 + ((unsigned char *) &temp)[1] = *((unsigned char *)
241 + (bh->b_data + *offset + 1));
247 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
248 + if (*offset == msblk->devblksize) {
250 + if (!(bh = sb_bread(s, ++(*cur_index))))
254 + if (*((unsigned char *) (bh->b_data + *offset)) !=
255 + SQUASHFS_MARKER_BYTE) {
256 + ERROR("Metadata block marker corrupt @ %x\n",
270 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
271 + long long index, unsigned int length,
272 + long long *next_index, int srclength)
274 + struct squashfs_sb_info *msblk = s->s_fs_info;
275 + struct squashfs_super_block *sblk = &msblk->sblk;
276 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
277 + msblk->devblksize_log2) + 2];
278 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
279 + unsigned int cur_index = index >> msblk->devblksize_log2;
280 + int bytes, avail_bytes, b = 0, k = 0;
281 + unsigned int compressed;
282 + unsigned int c_byte = length;
285 + bytes = msblk->devblksize - offset;
286 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
287 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
289 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index, compressed
290 + ? "" : "un", (unsigned int) c_byte, srclength);
292 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
295 + if (!(bh[0] = sb_getblk(s, cur_index)))
296 + goto block_release;
298 + for (b = 1; bytes < c_byte; b++) {
299 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
300 + goto block_release;
301 + bytes += msblk->devblksize;
303 + ll_rw_block(READ, b, bh);
305 + if (index < 0 || (index + 2) > sblk->bytes_used)
308 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
312 + bytes = msblk->devblksize - offset;
313 + compressed = SQUASHFS_COMPRESSED(c_byte);
314 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
316 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
317 + ? "" : "un", (unsigned int) c_byte);
319 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
322 + for (b = 1; bytes < c_byte; b++) {
323 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
324 + goto block_release;
325 + bytes += msblk->devblksize;
327 + ll_rw_block(READ, b - 1, bh + 1);
337 + mutex_lock(&msblk->read_data_mutex);
339 + msblk->stream.next_out = buffer;
340 + msblk->stream.avail_out = srclength;
342 + for (bytes = 0; k < b; k++) {
343 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
344 + msblk->devblksize - offset :
346 + wait_on_buffer(bh[k]);
347 + if (!buffer_uptodate(bh[k]))
348 + goto release_mutex;
350 + msblk->stream.next_in = bh[k]->b_data + offset;
351 + msblk->stream.avail_in = avail_bytes;
354 + zlib_err = zlib_inflateInit(&msblk->stream);
355 + if (zlib_err != Z_OK) {
356 + ERROR("zlib_inflateInit returned unexpected result 0x%x, srclength %d\n",
357 + zlib_err, srclength);
358 + goto release_mutex;
361 + if (avail_bytes == 0) {
368 + zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
369 + if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
370 + ERROR("zlib_inflate returned unexpected result 0x%x, srclength %d, avail_in %d, avail_out %d\n",
371 + zlib_err, srclength, msblk->stream.avail_in, msblk->stream.avail_out);
372 + goto release_mutex;
375 + bytes += avail_bytes;
380 + if (zlib_err != Z_STREAM_END)
381 + goto release_mutex;
383 + zlib_err = zlib_inflateEnd(&msblk->stream);
384 + if (zlib_err != Z_OK) {
385 + ERROR("zlib_inflateEnd returned unexpected result 0x%x, srclength %d\n",
386 + zlib_err, srclength);
387 + goto release_mutex;
389 + bytes = msblk->stream.total_out;
390 + mutex_unlock(&msblk->read_data_mutex);
394 + for(i = 0; i < b; i++) {
395 + wait_on_buffer(bh[i]);
396 + if(!buffer_uptodate(bh[i]))
397 + goto block_release;
400 + for (bytes = 0; k < b; k++) {
401 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
402 + msblk->devblksize - offset :
404 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
405 + bytes += avail_bytes;
412 + *next_index = index + c_byte + (length ? 0 :
413 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
418 + mutex_unlock(&msblk->read_data_mutex);
425 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
430 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
431 + long long block, unsigned int offset,
432 + int length, long long *next_block,
433 + unsigned int *next_offset)
435 + struct squashfs_sb_info *msblk = s->s_fs_info;
436 + int n, i, bytes, return_length = length;
437 + long long next_index;
439 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
442 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
443 + if (msblk->block_cache[i].block == block)
446 + mutex_lock(&msblk->block_cache_mutex);
448 + if (i == SQUASHFS_CACHED_BLKS) {
449 + /* read inode header block */
450 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
451 + n ; n --, i = (i + 1) %
452 + SQUASHFS_CACHED_BLKS)
453 + if (msblk->block_cache[i].block !=
460 + init_waitqueue_entry(&wait, current);
461 + add_wait_queue(&msblk->waitq, &wait);
462 + set_current_state(TASK_UNINTERRUPTIBLE);
463 + mutex_unlock(&msblk->block_cache_mutex);
465 + set_current_state(TASK_RUNNING);
466 + remove_wait_queue(&msblk->waitq, &wait);
469 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
471 + if (msblk->block_cache[i].block ==
472 + SQUASHFS_INVALID_BLK) {
473 + if (!(msblk->block_cache[i].data =
474 + kmalloc(SQUASHFS_METADATA_SIZE,
476 + ERROR("Failed to allocate cache"
478 + mutex_unlock(&msblk->block_cache_mutex);
483 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
484 + mutex_unlock(&msblk->block_cache_mutex);
486 + msblk->block_cache[i].length = squashfs_read_data(s,
487 + msblk->block_cache[i].data, block, 0, &next_index, SQUASHFS_METADATA_SIZE);
488 + if (msblk->block_cache[i].length == 0) {
489 + ERROR("Unable to read cache block [%llx:%x]\n",
491 + mutex_lock(&msblk->block_cache_mutex);
492 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
493 + kfree(msblk->block_cache[i].data);
494 + wake_up(&msblk->waitq);
495 + mutex_unlock(&msblk->block_cache_mutex);
499 + mutex_lock(&msblk->block_cache_mutex);
500 + wake_up(&msblk->waitq);
501 + msblk->block_cache[i].block = block;
502 + msblk->block_cache[i].next_index = next_index;
503 + TRACE("Read cache block [%llx:%x]\n", block, offset);
506 + if (msblk->block_cache[i].block != block) {
507 + mutex_unlock(&msblk->block_cache_mutex);
511 + bytes = msblk->block_cache[i].length - offset;
514 + mutex_unlock(&msblk->block_cache_mutex);
516 + } else if (bytes >= length) {
518 + memcpy(buffer, msblk->block_cache[i].data +
520 + if (msblk->block_cache[i].length - offset == length) {
521 + *next_block = msblk->block_cache[i].next_index;
524 + *next_block = block;
525 + *next_offset = offset + length;
527 + mutex_unlock(&msblk->block_cache_mutex);
531 + memcpy(buffer, msblk->block_cache[i].data +
535 + block = msblk->block_cache[i].next_index;
536 + mutex_unlock(&msblk->block_cache_mutex);
543 + return return_length;
549 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
550 + long long *fragment_start_block,
551 + unsigned int *fragment_size)
553 + struct squashfs_sb_info *msblk = s->s_fs_info;
554 + long long start_block =
555 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
556 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
557 + struct squashfs_fragment_entry fragment_entry;
560 + struct squashfs_fragment_entry sfragment_entry;
562 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
563 + start_block, offset,
564 + sizeof(sfragment_entry), &start_block,
567 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
569 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
570 + start_block, offset,
571 + sizeof(fragment_entry), &start_block,
575 + *fragment_start_block = fragment_entry.start_block;
576 + *fragment_size = fragment_entry.size;
585 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
586 + squashfs_fragment_cache *fragment)
588 + mutex_lock(&msblk->fragment_mutex);
589 + fragment->locked --;
590 + wake_up(&msblk->fragment_wait_queue);
591 + mutex_unlock(&msblk->fragment_mutex);
595 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
596 + *s, long long start_block,
600 + struct squashfs_sb_info *msblk = s->s_fs_info;
601 + struct squashfs_super_block *sblk = &msblk->sblk;
604 + mutex_lock(&msblk->fragment_mutex);
606 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
607 + msblk->fragment[i].block != start_block; i++);
609 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
610 + for (i = msblk->next_fragment, n =
611 + SQUASHFS_CACHED_FRAGMENTS; n &&
612 + msblk->fragment[i].locked; n--, i = (i + 1) %
613 + SQUASHFS_CACHED_FRAGMENTS);
618 + init_waitqueue_entry(&wait, current);
619 + add_wait_queue(&msblk->fragment_wait_queue,
621 + set_current_state(TASK_UNINTERRUPTIBLE);
622 + mutex_unlock(&msblk->fragment_mutex);
624 + set_current_state(TASK_RUNNING);
625 + remove_wait_queue(&msblk->fragment_wait_queue,
629 + msblk->next_fragment = (msblk->next_fragment + 1) %
630 + SQUASHFS_CACHED_FRAGMENTS;
632 + if (msblk->fragment[i].data == NULL)
633 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
634 + (SQUASHFS_FILE_MAX_SIZE))) {
635 + ERROR("Failed to allocate fragment "
637 + mutex_unlock(&msblk->fragment_mutex);
641 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
642 + msblk->fragment[i].locked = 1;
643 + mutex_unlock(&msblk->fragment_mutex);
645 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
646 + msblk->fragment[i].data,
647 + start_block, length, NULL, sblk->block_size))) {
648 + ERROR("Unable to read fragment cache block "
649 + "[%llx]\n", start_block);
650 + msblk->fragment[i].locked = 0;
655 + mutex_lock(&msblk->fragment_mutex);
656 + msblk->fragment[i].block = start_block;
657 + TRACE("New fragment %d, start block %lld, locked %d\n",
658 + i, msblk->fragment[i].block,
659 + msblk->fragment[i].locked);
660 + mutex_unlock(&msblk->fragment_mutex);
664 + msblk->fragment[i].locked++;
665 + mutex_unlock(&msblk->fragment_mutex);
666 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
667 + msblk->fragment[i].block,
668 + msblk->fragment[i].locked);
672 + return &msblk->fragment[i];
679 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
680 + struct squashfs_base_inode_header *inodeb)
682 + i->i_ino = inodeb->inode_number;
683 + i->i_mtime.tv_sec = inodeb->mtime;
684 + i->i_atime.tv_sec = inodeb->mtime;
685 + i->i_ctime.tv_sec = inodeb->mtime;
686 + i->i_uid = msblk->uid[inodeb->uid];
687 + i->i_mode = inodeb->mode;
689 + if (inodeb->guid == SQUASHFS_GUIDS)
690 + i->i_gid = i->i_uid;
692 + i->i_gid = msblk->guid[inodeb->guid];
696 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
698 + struct squashfs_sb_info *msblk = s->s_fs_info;
699 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
700 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
701 + squashfs_inode_t inode;
703 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
706 + squashfs_inode_t sinode;
708 + if (!squashfs_get_cached_block(s, (char *) &sinode, start, offset,
709 + sizeof(sinode), &start, &offset))
711 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
712 + } else if (!squashfs_get_cached_block(s, (char *) &inode, start, offset,
713 + sizeof(inode), &start, &offset))
716 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
721 + return SQUASHFS_INVALID_BLK;
725 +static void vfs_read_inode(struct inode *i)
727 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
728 + squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);
730 + TRACE("Entered vfs_read_inode\n");
732 + if(inode != SQUASHFS_INVALID_BLK)
733 + (msblk->read_inode)(i, inode);
737 +static struct dentry *squashfs_get_parent(struct dentry *child)
739 + struct inode *i = child->d_inode;
740 + struct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
743 + TRACE("Entered squashfs_get_parent\n");
745 + if(parent == NULL) {
746 + rv = ERR_PTR(-EACCES);
750 + rv = d_alloc_anon(parent);
752 + rv = ERR_PTR(-ENOMEM);
759 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number)
761 + struct squashfs_sb_info *msblk = s->s_fs_info;
762 + struct inode *i = iget_locked(s, inode_number);
764 + TRACE("Entered squashfs_iget\n");
766 + if(i && (i->i_state & I_NEW)) {
767 + (msblk->read_inode)(i, inode);
768 + unlock_new_inode(i);
775 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
777 + struct super_block *s = i->i_sb;
778 + struct squashfs_sb_info *msblk = s->s_fs_info;
779 + struct squashfs_super_block *sblk = &msblk->sblk;
780 + long long block = SQUASHFS_INODE_BLK(inode) +
781 + sblk->inode_table_start;
782 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
783 + long long next_block;
784 + unsigned int next_offset;
785 + union squashfs_inode_header id, sid;
786 + struct squashfs_base_inode_header *inodeb = &id.base,
787 + *sinodeb = &sid.base;
789 + TRACE("Entered squashfs_read_inode\n");
792 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
793 + offset, sizeof(*sinodeb), &next_block,
796 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
799 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
800 + offset, sizeof(*inodeb), &next_block,
804 + squashfs_new_inode(msblk, i, inodeb);
806 + switch(inodeb->inode_type) {
807 + case SQUASHFS_FILE_TYPE: {
808 + unsigned int frag_size;
809 + long long frag_blk;
810 + struct squashfs_reg_inode_header *inodep = &id.reg;
811 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
814 + if (!squashfs_get_cached_block(s, (char *)
815 + sinodep, block, offset,
816 + sizeof(*sinodep), &next_block,
819 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
821 + if (!squashfs_get_cached_block(s, (char *)
822 + inodep, block, offset,
823 + sizeof(*inodep), &next_block,
827 + frag_blk = SQUASHFS_INVALID_BLK;
828 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
829 + !get_fragment_location(s,
830 + inodep->fragment, &frag_blk, &frag_size))
834 + i->i_size = inodep->file_size;
835 + i->i_fop = &generic_ro_fops;
836 + i->i_mode |= S_IFREG;
837 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
838 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
839 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
840 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
841 + SQUASHFS_I(i)->start_block = inodep->start_block;
842 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
843 + SQUASHFS_I(i)->offset = next_offset;
844 + if (sblk->block_size > 4096)
845 + i->i_data.a_ops = &squashfs_aops;
847 + i->i_data.a_ops = &squashfs_aops_4K;
849 + TRACE("File inode %x:%x, start_block %llx, "
850 + "block_list_start %llx, offset %x\n",
851 + SQUASHFS_INODE_BLK(inode), offset,
852 + inodep->start_block, next_block,
856 + case SQUASHFS_LREG_TYPE: {
857 + unsigned int frag_size;
858 + long long frag_blk;
859 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
860 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
863 + if (!squashfs_get_cached_block(s, (char *)
864 + sinodep, block, offset,
865 + sizeof(*sinodep), &next_block,
868 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
870 + if (!squashfs_get_cached_block(s, (char *)
871 + inodep, block, offset,
872 + sizeof(*inodep), &next_block,
876 + frag_blk = SQUASHFS_INVALID_BLK;
877 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
878 + !get_fragment_location(s,
879 + inodep->fragment, &frag_blk, &frag_size))
882 + i->i_nlink = inodep->nlink;
883 + i->i_size = inodep->file_size;
884 + i->i_fop = &generic_ro_fops;
885 + i->i_mode |= S_IFREG;
886 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
887 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
888 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
889 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
890 + SQUASHFS_I(i)->start_block = inodep->start_block;
891 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
892 + SQUASHFS_I(i)->offset = next_offset;
893 + if (sblk->block_size > 4096)
894 + i->i_data.a_ops = &squashfs_aops;
896 + i->i_data.a_ops = &squashfs_aops_4K;
898 + TRACE("File inode %x:%x, start_block %llx, "
899 + "block_list_start %llx, offset %x\n",
900 + SQUASHFS_INODE_BLK(inode), offset,
901 + inodep->start_block, next_block,
905 + case SQUASHFS_DIR_TYPE: {
906 + struct squashfs_dir_inode_header *inodep = &id.dir;
907 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
910 + if (!squashfs_get_cached_block(s, (char *)
911 + sinodep, block, offset,
912 + sizeof(*sinodep), &next_block,
915 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
917 + if (!squashfs_get_cached_block(s, (char *)
918 + inodep, block, offset,
919 + sizeof(*inodep), &next_block,
923 + i->i_nlink = inodep->nlink;
924 + i->i_size = inodep->file_size;
925 + i->i_op = &squashfs_dir_inode_ops;
926 + i->i_fop = &squashfs_dir_ops;
927 + i->i_mode |= S_IFDIR;
928 + SQUASHFS_I(i)->start_block = inodep->start_block;
929 + SQUASHFS_I(i)->offset = inodep->offset;
930 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
931 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
933 + TRACE("Directory inode %x:%x, start_block %x, offset "
934 + "%x\n", SQUASHFS_INODE_BLK(inode),
935 + offset, inodep->start_block,
939 + case SQUASHFS_LDIR_TYPE: {
940 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
941 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
944 + if (!squashfs_get_cached_block(s, (char *)
945 + sinodep, block, offset,
946 + sizeof(*sinodep), &next_block,
949 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
952 + if (!squashfs_get_cached_block(s, (char *)
953 + inodep, block, offset,
954 + sizeof(*inodep), &next_block,
958 + i->i_nlink = inodep->nlink;
959 + i->i_size = inodep->file_size;
960 + i->i_op = &squashfs_dir_inode_ops;
961 + i->i_fop = &squashfs_dir_ops;
962 + i->i_mode |= S_IFDIR;
963 + SQUASHFS_I(i)->start_block = inodep->start_block;
964 + SQUASHFS_I(i)->offset = inodep->offset;
965 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
966 + SQUASHFS_I(i)->u.s2.directory_index_offset =
968 + SQUASHFS_I(i)->u.s2.directory_index_count =
970 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
972 + TRACE("Long directory inode %x:%x, start_block %x, "
974 + SQUASHFS_INODE_BLK(inode), offset,
975 + inodep->start_block, inodep->offset);
978 + case SQUASHFS_SYMLINK_TYPE: {
979 + struct squashfs_symlink_inode_header *inodep =
981 + struct squashfs_symlink_inode_header *sinodep =
985 + if (!squashfs_get_cached_block(s, (char *)
986 + sinodep, block, offset,
987 + sizeof(*sinodep), &next_block,
990 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
993 + if (!squashfs_get_cached_block(s, (char *)
994 + inodep, block, offset,
995 + sizeof(*inodep), &next_block,
999 + i->i_nlink = inodep->nlink;
1000 + i->i_size = inodep->symlink_size;
1001 + i->i_op = &page_symlink_inode_operations;
1002 + i->i_data.a_ops = &squashfs_symlink_aops;
1003 + i->i_mode |= S_IFLNK;
1004 + SQUASHFS_I(i)->start_block = next_block;
1005 + SQUASHFS_I(i)->offset = next_offset;
1007 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
1009 + SQUASHFS_INODE_BLK(inode), offset,
1010 + next_block, next_offset);
1013 + case SQUASHFS_BLKDEV_TYPE:
1014 + case SQUASHFS_CHRDEV_TYPE: {
1015 + struct squashfs_dev_inode_header *inodep = &id.dev;
1016 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
1018 + if (msblk->swap) {
1019 + if (!squashfs_get_cached_block(s, (char *)
1020 + sinodep, block, offset,
1021 + sizeof(*sinodep), &next_block,
1024 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
1026 + if (!squashfs_get_cached_block(s, (char *)
1027 + inodep, block, offset,
1028 + sizeof(*inodep), &next_block,
1032 + i->i_nlink = inodep->nlink;
1033 + i->i_mode |= (inodeb->inode_type ==
1034 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
1036 + init_special_inode(i, i->i_mode,
1037 + old_decode_dev(inodep->rdev));
1039 + TRACE("Device inode %x:%x, rdev %x\n",
1040 + SQUASHFS_INODE_BLK(inode), offset,
1044 + case SQUASHFS_FIFO_TYPE:
1045 + case SQUASHFS_SOCKET_TYPE: {
1046 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
1047 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
1049 + if (msblk->swap) {
1050 + if (!squashfs_get_cached_block(s, (char *)
1051 + sinodep, block, offset,
1052 + sizeof(*sinodep), &next_block,
1055 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
1057 + if (!squashfs_get_cached_block(s, (char *)
1058 + inodep, block, offset,
1059 + sizeof(*inodep), &next_block,
1063 + i->i_nlink = inodep->nlink;
1064 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
1065 + ? S_IFIFO : S_IFSOCK;
1066 + init_special_inode(i, i->i_mode, 0);
1070 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1071 + inodeb->inode_type);
1072 + goto failed_read1;
1078 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1081 + make_bad_inode(i);
1086 +static int read_inode_lookup_table(struct super_block *s)
1088 + struct squashfs_sb_info *msblk = s->s_fs_info;
1089 + struct squashfs_super_block *sblk = &msblk->sblk;
1090 + unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1092 + TRACE("In read_inode_lookup_table, length %d\n", length);
1094 + /* Allocate inode lookup table */
1095 + if (!(msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL))) {
1096 + ERROR("Failed to allocate inode lookup table\n");
1100 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1101 + sblk->lookup_table_start, length |
1102 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1103 + ERROR("unable to read inode lookup table\n");
1107 + if (msblk->swap) {
1111 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1112 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1113 + &msblk->inode_lookup_table[i], 1);
1114 + msblk->inode_lookup_table[i] = block;
1122 +static int read_fragment_index_table(struct super_block *s)
1124 + struct squashfs_sb_info *msblk = s->s_fs_info;
1125 + struct squashfs_super_block *sblk = &msblk->sblk;
1126 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1131 + /* Allocate fragment index table */
1132 + if (!(msblk->fragment_index = kmalloc(length, GFP_KERNEL))) {
1133 + ERROR("Failed to allocate fragment index table\n");
1137 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1138 + sblk->fragment_table_start, length |
1139 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1140 + ERROR("unable to read fragment index table\n");
1144 + if (msblk->swap) {
1146 + long long fragment;
1148 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1149 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1150 + &msblk->fragment_index[i], 1);
1151 + msblk->fragment_index[i] = fragment;
1159 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1161 + struct squashfs_super_block *sblk = &msblk->sblk;
1163 + msblk->read_inode = squashfs_read_inode;
1164 + msblk->read_blocklist = read_blocklist;
1165 + msblk->read_fragment_index_table = read_fragment_index_table;
1167 + if (sblk->s_major == 1) {
1168 + if (!squashfs_1_0_supported(msblk)) {
1169 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1170 + "are unsupported\n");
1171 + SERROR("Please recompile with "
1172 + "Squashfs 1.0 support enabled\n");
1175 + } else if (sblk->s_major == 2) {
1176 + if (!squashfs_2_0_supported(msblk)) {
1177 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1178 + "are unsupported\n");
1179 + SERROR("Please recompile with "
1180 + "Squashfs 2.0 support enabled\n");
1183 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1185 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1186 + "filesystem\n", sblk->s_major, sblk->s_minor);
1187 + SERROR("Please update your kernel\n");
1195 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1197 + struct squashfs_sb_info *msblk;
1198 + struct squashfs_super_block *sblk;
1200 + char b[BDEVNAME_SIZE];
1201 + struct inode *root;
1203 + TRACE("Entered squashfs_read_superblock\n");
1205 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1207 + ERROR("Failed to allocate superblock\n");
1210 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1211 + msblk = s->s_fs_info;
1212 + if (!(msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
1213 + ERROR("Failed to allocate zlib workspace\n");
1216 + sblk = &msblk->sblk;
1218 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1219 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1221 + mutex_init(&msblk->read_data_mutex);
1222 + mutex_init(&msblk->read_page_mutex);
1223 + mutex_init(&msblk->block_cache_mutex);
1224 + mutex_init(&msblk->fragment_mutex);
1225 + mutex_init(&msblk->meta_index_mutex);
1227 + init_waitqueue_head(&msblk->waitq);
1228 + init_waitqueue_head(&msblk->fragment_wait_queue);
1230 + sblk->bytes_used = sizeof(struct squashfs_super_block);
1231 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1232 + sizeof(struct squashfs_super_block) |
1233 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1234 + SERROR("unable to read superblock\n");
1235 + goto failed_mount;
1238 + /* Check it is a SQUASHFS superblock */
1240 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1241 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1242 + struct squashfs_super_block ssblk;
1244 + WARNING("Mounting a different endian SQUASHFS "
1245 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1247 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1248 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1251 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1252 + bdevname(s->s_bdev, b));
1253 + goto failed_mount;
1257 + /* Check the MAJOR & MINOR versions */
1258 + if(!supported_squashfs_filesystem(msblk, silent))
1259 + goto failed_mount;
1261 + /* Check the filesystem does not extend beyond the end of the
1263 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1264 + goto failed_mount;
1266 + /* Check the root inode for sanity */
1267 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1268 + goto failed_mount;
1270 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1271 + TRACE("Inodes are %scompressed\n",
1272 + SQUASHFS_UNCOMPRESSED_INODES
1273 + (sblk->flags) ? "un" : "");
1274 + TRACE("Data is %scompressed\n",
1275 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1277 + TRACE("Check data is %s present in the filesystem\n",
1278 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1280 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1281 + TRACE("Block size %d\n", sblk->block_size);
1282 + TRACE("Number of inodes %d\n", sblk->inodes);
1283 + if (sblk->s_major > 1)
1284 + TRACE("Number of fragments %d\n", sblk->fragments);
1285 + TRACE("Number of uids %d\n", sblk->no_uids);
1286 + TRACE("Number of gids %d\n", sblk->no_guids);
1287 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1288 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1289 + if (sblk->s_major > 1)
1290 + TRACE("sblk->fragment_table_start %llx\n",
1291 + sblk->fragment_table_start);
1292 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1294 + s->s_flags |= MS_RDONLY;
1295 + s->s_op = &squashfs_super_ops;
1297 + /* Init inode_table block pointer array */
1298 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1299 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1300 + ERROR("Failed to allocate block cache\n");
1301 + goto failed_mount;
1304 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1305 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1307 + msblk->next_cache = 0;
1309 + /* Allocate read_page block */
1310 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1311 + ERROR("Failed to allocate read_page block\n");
1312 + goto failed_mount;
1315 + /* Allocate uid and gid tables */
1316 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1317 + sizeof(unsigned int), GFP_KERNEL))) {
1318 + ERROR("Failed to allocate uid/gid table\n");
1319 + goto failed_mount;
1321 + msblk->guid = msblk->uid + sblk->no_uids;
1323 + if (msblk->swap) {
1324 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1326 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1327 + ((sblk->no_uids + sblk->no_guids) *
1328 + sizeof(unsigned int)) |
1329 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1330 + ERROR("unable to read uid/gid table\n");
1331 + goto failed_mount;
1334 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1335 + sblk->no_guids), (sizeof(unsigned int) * 8));
1337 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1338 + ((sblk->no_uids + sblk->no_guids) *
1339 + sizeof(unsigned int)) |
1340 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1341 + ERROR("unable to read uid/gid table\n");
1342 + goto failed_mount;
1346 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1347 + goto allocate_root;
1349 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1350 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1351 + ERROR("Failed to allocate fragment block cache\n");
1352 + goto failed_mount;
1355 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1356 + msblk->fragment[i].locked = 0;
1357 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1358 + msblk->fragment[i].data = NULL;
1361 + msblk->next_fragment = 0;
1363 + /* Allocate and read fragment index table */
1364 + if (msblk->read_fragment_index_table(s) == 0)
1365 + goto failed_mount;
1367 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1368 + goto allocate_root;
1370 + /* Allocate and read inode lookup table */
1371 + if (read_inode_lookup_table(s) == 0)
1372 + goto failed_mount;
1374 + s->s_op = &squashfs_export_super_ops;
1375 + s->s_export_op = &squashfs_export_ops;
1378 + root = new_inode(s);
1379 + if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1380 + goto failed_mount;
1381 + insert_inode_hash(root);
1383 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1384 + ERROR("Root inode create failed\n");
1386 + goto failed_mount;
1389 + TRACE("Leaving squashfs_read_super\n");
1393 + kfree(msblk->inode_lookup_table);
1394 + kfree(msblk->fragment_index);
1395 + kfree(msblk->fragment);
1396 + kfree(msblk->uid);
1397 + kfree(msblk->read_page);
1398 + kfree(msblk->block_cache);
1399 + kfree(msblk->fragment_index_2);
1400 + vfree(msblk->stream.workspace);
1401 + kfree(s->s_fs_info);
1402 + s->s_fs_info = NULL;
1410 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1412 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1413 + struct squashfs_super_block *sblk = &msblk->sblk;
1415 + TRACE("Entered squashfs_statfs\n");
1417 + buf->f_type = SQUASHFS_MAGIC;
1418 + buf->f_bsize = sblk->block_size;
1419 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1420 + buf->f_bfree = buf->f_bavail = 0;
1421 + buf->f_files = sblk->inodes;
1423 + buf->f_namelen = SQUASHFS_NAME_LEN;
1429 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1431 + struct inode *inode = page->mapping->host;
1432 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1433 + long long block = SQUASHFS_I(inode)->start_block;
1434 + int offset = SQUASHFS_I(inode)->offset;
1435 + void *pageaddr = kmap(page);
1437 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1438 + "%llx, offset %x\n", page->index,
1439 + SQUASHFS_I(inode)->start_block,
1440 + SQUASHFS_I(inode)->offset);
1442 + for (length = 0; length < index; length += bytes) {
1443 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1444 + block, offset, PAGE_CACHE_SIZE, &block,
1446 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1452 + if (length != index) {
1453 + ERROR("(squashfs_symlink_readpage) length != index\n");
1458 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1459 + i_size_read(inode) - length;
1461 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1462 + offset, bytes, &block, &offset)))
1463 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1466 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1468 + flush_dcache_page(page);
1469 + SetPageUptodate(page);
1470 + unlock_page(page);
1476 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1478 + struct meta_index *meta = NULL;
1479 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1482 + mutex_lock(&msblk->meta_index_mutex);
1484 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1486 + if(msblk->meta_index == NULL)
1487 + goto not_allocated;
1489 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1490 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1491 + msblk->meta_index[i].offset >= offset &&
1492 + msblk->meta_index[i].offset <= index &&
1493 + msblk->meta_index[i].locked == 0) {
1494 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1495 + msblk->meta_index[i].offset);
1496 + meta = &msblk->meta_index[i];
1497 + offset = meta->offset;
1504 + mutex_unlock(&msblk->meta_index_mutex);
1510 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1512 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1513 + struct meta_index *meta = NULL;
1516 + mutex_lock(&msblk->meta_index_mutex);
1518 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1520 + if(msblk->meta_index == NULL) {
1521 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1522 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1523 + ERROR("Failed to allocate meta_index\n");
1526 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1527 + msblk->meta_index[i].inode_number = 0;
1528 + msblk->meta_index[i].locked = 0;
1530 + msblk->next_meta_index = 0;
1533 + for(i = SQUASHFS_META_NUMBER; i &&
1534 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1535 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1536 + SQUASHFS_META_NUMBER;
1539 + TRACE("empty_meta_index: failed!\n");
1543 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1544 + msblk->next_meta_index,
1545 + &msblk->meta_index[msblk->next_meta_index]);
1547 + meta = &msblk->meta_index[msblk->next_meta_index];
1548 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1549 + SQUASHFS_META_NUMBER;
1551 + meta->inode_number = inode->i_ino;
1552 + meta->offset = offset;
1553 + meta->skip = skip;
1554 + meta->entries = 0;
1558 + mutex_unlock(&msblk->meta_index_mutex);
1563 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1570 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1571 + long long *start_block, int *offset)
1573 + struct squashfs_sb_info *msblk = s->s_fs_info;
1574 + unsigned int *block_listp;
1577 + if (msblk->swap) {
1578 + char sblock_list[blocks << 2];
1580 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1581 + *offset, blocks << 2, start_block, offset)) {
1582 + ERROR("Unable to read block list [%llx:%x]\n",
1583 + *start_block, *offset);
1586 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1587 + ((unsigned int *)sblock_list), blocks);
1589 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1590 + *offset, blocks << 2, start_block, offset)) {
1591 + ERROR("Unable to read block list [%llx:%x]\n",
1592 + *start_block, *offset);
1596 + for (block_listp = (unsigned int *) block_list; blocks;
1597 + block_listp++, blocks --)
1598 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1609 +static inline int calculate_skip(int blocks) {
1610 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1611 + return skip >= 7 ? 7 : skip + 1;
1615 +static int get_meta_index(struct inode *inode, int index,
1616 + long long *index_block, int *index_offset,
1617 + long long *data_block, char *block_list)
1619 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1620 + struct squashfs_super_block *sblk = &msblk->sblk;
1621 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1623 + struct meta_index *meta;
1624 + struct meta_entry *meta_entry;
1625 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1626 + int cur_offset = SQUASHFS_I(inode)->offset;
1627 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1630 + index /= SQUASHFS_META_INDEXES * skip;
1632 + while ( offset < index ) {
1633 + meta = locate_meta_index(inode, index, offset + 1);
1635 + if (meta == NULL) {
1636 + if ((meta = empty_meta_index(inode, offset + 1,
1640 + if(meta->entries == 0)
1642 + offset = index < meta->offset + meta->entries ? index :
1643 + meta->offset + meta->entries - 1;
1644 + meta_entry = &meta->meta_entry[offset - meta->offset];
1645 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1646 + cur_offset = meta_entry->offset;
1647 + cur_data_block = meta_entry->data_block;
1648 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1649 + "meta->entries %d\n", offset, meta->offset,
1651 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1652 + " data_block 0x%llx\n", cur_index_block,
1653 + cur_offset, cur_data_block);
1656 + for (i = meta->offset + meta->entries; i <= index &&
1657 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1658 + int blocks = skip * SQUASHFS_META_INDEXES;
1661 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1663 + int res = read_block_index(inode->i_sb, block,
1664 + block_list, &cur_index_block,
1670 + cur_data_block += res;
1674 + meta_entry = &meta->meta_entry[i - meta->offset];
1675 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1676 + meta_entry->offset = cur_offset;
1677 + meta_entry->data_block = cur_data_block;
1682 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1683 + meta->offset, meta->entries);
1685 + release_meta_index(inode, meta);
1689 + *index_block = cur_index_block;
1690 + *index_offset = cur_offset;
1691 + *data_block = cur_data_block;
1693 + return offset * SQUASHFS_META_INDEXES * skip;
1696 + release_meta_index(inode, meta);
1701 +static long long read_blocklist(struct inode *inode, int index,
1702 + int readahead_blks, char *block_list,
1703 + unsigned short **block_p, unsigned int *bsize)
1705 + long long block_ptr;
1708 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1711 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1712 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1721 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1722 + int res = read_block_index(inode->i_sb, blocks, block_list,
1723 + &block_ptr, &offset);
1730 + if (read_block_index(inode->i_sb, 1, block_list,
1731 + &block_ptr, &offset) == -1)
1733 + *bsize = *((unsigned int *) block_list);
1742 +static int squashfs_readpage(struct file *file, struct page *page)
1744 + struct inode *inode = page->mapping->host;
1745 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1746 + struct squashfs_super_block *sblk = &msblk->sblk;
1747 + unsigned char *block_list;
1749 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1750 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1752 + struct squashfs_fragment_cache *fragment = NULL;
1753 + char *data_ptr = msblk->read_page;
1755 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1756 + int start_index = page->index & ~mask;
1757 + int end_index = start_index | mask;
1759 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1761 + SQUASHFS_I(inode)->start_block);
1763 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1764 + ERROR("Failed to allocate block_list\n");
1768 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1769 + PAGE_CACHE_SHIFT))
1772 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1773 + || index < (i_size_read(inode) >>
1774 + sblk->block_log)) {
1775 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1776 + block_list, NULL, &bsize)) == 0)
1779 + mutex_lock(&msblk->read_page_mutex);
1781 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1782 + block, bsize, NULL, sblk->block_size))) {
1783 + ERROR("Unable to read page, block %llx, size %x\n", block,
1785 + mutex_unlock(&msblk->read_page_mutex);
1789 + if ((fragment = get_cached_fragment(inode->i_sb,
1790 + SQUASHFS_I(inode)->
1791 + u.s1.fragment_start_block,
1792 + SQUASHFS_I(inode)->u.s1.fragment_size))
1794 + ERROR("Unable to read page, block %llx, size %x\n",
1795 + SQUASHFS_I(inode)->
1796 + u.s1.fragment_start_block,
1797 + (int) SQUASHFS_I(inode)->
1798 + u.s1.fragment_size);
1801 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1802 + (i_size_read(inode) & (sblk->block_size
1804 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1805 + data_ptr = fragment->data;
1808 + for (i = start_index; i <= end_index && byte_offset < bytes;
1809 + i++, byte_offset += PAGE_CACHE_SIZE) {
1810 + struct page *push_page;
1811 + int avail = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1812 + PAGE_CACHE_SIZE : bytes - byte_offset;
1814 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1815 + bytes, i, byte_offset, avail);
1817 + push_page = (i == page->index) ? page :
1818 + grab_cache_page_nowait(page->mapping, i);
1823 + if (PageUptodate(push_page))
1826 + pageaddr = kmap_atomic(push_page, KM_USER0);
1827 + memcpy(pageaddr, data_ptr + byte_offset, avail);
1828 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1829 + kunmap_atomic(pageaddr, KM_USER0);
1830 + flush_dcache_page(push_page);
1831 + SetPageUptodate(push_page);
1833 + unlock_page(push_page);
1834 + if(i != page->index)
1835 + page_cache_release(push_page);
1838 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1839 + || index < (i_size_read(inode) >>
1841 + mutex_unlock(&msblk->read_page_mutex);
1843 + release_cached_fragment(msblk, fragment);
1845 + kfree(block_list);
1849 + pageaddr = kmap_atomic(page, KM_USER0);
1850 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1851 + kunmap_atomic(pageaddr, KM_USER0);
1852 + flush_dcache_page(page);
1853 + SetPageUptodate(page);
1854 + unlock_page(page);
1856 + kfree(block_list);
1861 +static int squashfs_readpage4K(struct file *file, struct page *page)
1863 + struct inode *inode = page->mapping->host;
1864 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1865 + struct squashfs_super_block *sblk = &msblk->sblk;
1866 + unsigned char *block_list;
1868 + unsigned int bsize, bytes = 0;
1871 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1873 + SQUASHFS_I(inode)->start_block);
1875 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1876 + PAGE_CACHE_SHIFT)) {
1877 + block_list = NULL;
1881 + if (!(block_list = kmalloc(SIZE, GFP_KERNEL))) {
1882 + ERROR("Failed to allocate block_list\n");
1886 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1887 + || page->index < (i_size_read(inode) >>
1888 + sblk->block_log)) {
1889 + block = (msblk->read_blocklist)(inode, page->index, 1,
1890 + block_list, NULL, &bsize);
1894 + mutex_lock(&msblk->read_page_mutex);
1895 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1896 + bsize, NULL, sblk->block_size);
1898 + pageaddr = kmap_atomic(page, KM_USER0);
1899 + memcpy(pageaddr, msblk->read_page, bytes);
1900 + kunmap_atomic(pageaddr, KM_USER0);
1902 + ERROR("Unable to read page, block %llx, size %x\n",
1904 + mutex_unlock(&msblk->read_page_mutex);
1906 + struct squashfs_fragment_cache *fragment =
1907 + get_cached_fragment(inode->i_sb,
1908 + SQUASHFS_I(inode)->
1909 + u.s1.fragment_start_block,
1910 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1912 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1913 + pageaddr = kmap_atomic(page, KM_USER0);
1914 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1915 + u.s1.fragment_offset, bytes);
1916 + kunmap_atomic(pageaddr, KM_USER0);
1917 + release_cached_fragment(msblk, fragment);
1919 + ERROR("Unable to read page, block %llx, size %x\n",
1920 + SQUASHFS_I(inode)->
1921 + u.s1.fragment_start_block, (int)
1922 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1926 + pageaddr = kmap_atomic(page, KM_USER0);
1927 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1928 + kunmap_atomic(pageaddr, KM_USER0);
1929 + flush_dcache_page(page);
1930 + SetPageUptodate(page);
1931 + unlock_page(page);
1933 + kfree(block_list);
1938 +static int get_dir_index_using_offset(struct super_block *s, long long
1939 + *next_block, unsigned int *next_offset,
1940 + long long index_start,
1941 + unsigned int index_offset, int i_count,
1944 + struct squashfs_sb_info *msblk = s->s_fs_info;
1945 + struct squashfs_super_block *sblk = &msblk->sblk;
1946 + int i, length = 0;
1947 + struct squashfs_dir_index index;
1949 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1950 + i_count, (unsigned int) f_pos);
1956 + for (i = 0; i < i_count; i++) {
1957 + if (msblk->swap) {
1958 + struct squashfs_dir_index sindex;
1959 + squashfs_get_cached_block(s, (char *) &sindex,
1960 + index_start, index_offset,
1961 + sizeof(sindex), &index_start,
1963 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1965 + squashfs_get_cached_block(s, (char *) &index,
1966 + index_start, index_offset,
1967 + sizeof(index), &index_start,
1970 + if (index.index > f_pos)
1973 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1974 + index.size + 1, &index_start,
1977 + length = index.index;
1978 + *next_block = index.start_block + sblk->directory_table_start;
1981 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1984 + return length + 3;
1988 +static int get_dir_index_using_name(struct super_block *s, long long
1989 + *next_block, unsigned int *next_offset,
1990 + long long index_start,
1991 + unsigned int index_offset, int i_count,
1992 + const char *name, int size)
1994 + struct squashfs_sb_info *msblk = s->s_fs_info;
1995 + struct squashfs_super_block *sblk = &msblk->sblk;
1996 + int i, length = 0;
1997 + struct squashfs_dir_index *index;
2000 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2002 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2003 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2004 + ERROR("Failed to allocate squashfs_dir_index\n");
2008 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
2009 + strncpy(str, name, size);
2012 + for (i = 0; i < i_count; i++) {
2013 + if (msblk->swap) {
2014 + struct squashfs_dir_index sindex;
2015 + squashfs_get_cached_block(s, (char *) &sindex,
2016 + index_start, index_offset,
2017 + sizeof(sindex), &index_start,
2019 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
2021 + squashfs_get_cached_block(s, (char *) index,
2022 + index_start, index_offset,
2023 + sizeof(struct squashfs_dir_index),
2024 + &index_start, &index_offset);
2026 + squashfs_get_cached_block(s, index->name, index_start,
2027 + index_offset, index->size + 1,
2028 + &index_start, &index_offset);
2030 + index->name[index->size + 1] = '\0';
2032 + if (strcmp(index->name, str) > 0)
2035 + length = index->index;
2036 + *next_block = index->start_block + sblk->directory_table_start;
2039 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2042 + return length + 3;
2046 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
2048 + struct inode *i = file->f_dentry->d_inode;
2049 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2050 + struct squashfs_super_block *sblk = &msblk->sblk;
2051 + long long next_block = SQUASHFS_I(i)->start_block +
2052 + sblk->directory_table_start;
2053 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2055 + struct squashfs_dir_header dirh;
2056 + struct squashfs_dir_entry *dire;
2058 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
2060 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2061 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2062 + ERROR("Failed to allocate squashfs_dir_entry\n");
2066 + while(file->f_pos < 3) {
2070 + if(file->f_pos == 0) {
2077 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
2079 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
2080 + (unsigned int) dirent, name, size, (int)
2081 + file->f_pos, i_ino,
2082 + squashfs_filetype_table[1]);
2084 + if (filldir(dirent, name, size,
2085 + file->f_pos, i_ino,
2086 + squashfs_filetype_table[1]) < 0) {
2087 + TRACE("Filldir returned less than 0\n");
2090 + file->f_pos += size;
2093 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2094 + SQUASHFS_I(i)->u.s2.directory_index_start,
2095 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2096 + SQUASHFS_I(i)->u.s2.directory_index_count,
2099 + while (length < i_size_read(i)) {
2100 + /* read directory header */
2101 + if (msblk->swap) {
2102 + struct squashfs_dir_header sdirh;
2104 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2105 + next_block, next_offset, sizeof(sdirh),
2106 + &next_block, &next_offset))
2109 + length += sizeof(sdirh);
2110 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2112 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2113 + next_block, next_offset, sizeof(dirh),
2114 + &next_block, &next_offset))
2117 + length += sizeof(dirh);
2120 + dir_count = dirh.count + 1;
2121 + while (dir_count--) {
2122 + if (msblk->swap) {
2123 + struct squashfs_dir_entry sdire;
2124 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2125 + &sdire, next_block, next_offset,
2126 + sizeof(sdire), &next_block,
2130 + length += sizeof(sdire);
2131 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2133 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2134 + dire, next_block, next_offset,
2135 + sizeof(*dire), &next_block,
2139 + length += sizeof(*dire);
2142 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2143 + next_block, next_offset,
2144 + dire->size + 1, &next_block,
2148 + length += dire->size + 1;
2150 + if (file->f_pos >= length)
2153 + dire->name[dire->size + 1] = '\0';
2155 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2156 + (unsigned int) dirent, dire->name,
2157 + dire->size + 1, (int) file->f_pos,
2158 + dirh.start_block, dire->offset,
2159 + dirh.inode_number + dire->inode_number,
2160 + squashfs_filetype_table[dire->type]);
2162 + if (filldir(dirent, dire->name, dire->size + 1,
2164 + dirh.inode_number + dire->inode_number,
2165 + squashfs_filetype_table[dire->type])
2167 + TRACE("Filldir returned less than 0\n");
2170 + file->f_pos = length;
2179 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2186 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2187 + struct nameidata *nd)
2189 + const unsigned char *name = dentry->d_name.name;
2190 + int len = dentry->d_name.len;
2191 + struct inode *inode = NULL;
2192 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2193 + struct squashfs_super_block *sblk = &msblk->sblk;
2194 + long long next_block = SQUASHFS_I(i)->start_block +
2195 + sblk->directory_table_start;
2196 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2198 + struct squashfs_dir_header dirh;
2199 + struct squashfs_dir_entry *dire;
2201 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2203 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2204 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2205 + ERROR("Failed to allocate squashfs_dir_entry\n");
2209 + if (len > SQUASHFS_NAME_LEN)
2212 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2213 + SQUASHFS_I(i)->u.s2.directory_index_start,
2214 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2215 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2218 + while (length < i_size_read(i)) {
2219 + /* read directory header */
2220 + if (msblk->swap) {
2221 + struct squashfs_dir_header sdirh;
2222 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2223 + next_block, next_offset, sizeof(sdirh),
2224 + &next_block, &next_offset))
2227 + length += sizeof(sdirh);
2228 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2230 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2231 + next_block, next_offset, sizeof(dirh),
2232 + &next_block, &next_offset))
2235 + length += sizeof(dirh);
2238 + dir_count = dirh.count + 1;
2239 + while (dir_count--) {
2240 + if (msblk->swap) {
2241 + struct squashfs_dir_entry sdire;
2242 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2243 + &sdire, next_block,next_offset,
2244 + sizeof(sdire), &next_block,
2248 + length += sizeof(sdire);
2249 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2251 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2252 + dire, next_block,next_offset,
2253 + sizeof(*dire), &next_block,
2257 + length += sizeof(*dire);
2260 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2261 + next_block, next_offset, dire->size + 1,
2262 + &next_block, &next_offset))
2265 + length += dire->size + 1;
2267 + if (name[0] < dire->name[0])
2270 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2271 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2274 + TRACE("calling squashfs_iget for directory "
2275 + "entry %s, inode %x:%x, %d\n", name,
2276 + dirh.start_block, dire->offset,
2277 + dirh.inode_number + dire->inode_number);
2279 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2289 + return d_splice_alias(inode, dentry);
2290 + d_add(dentry, inode);
2291 + return ERR_PTR(0);
2294 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2300 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
2302 + *flags |= MS_RDONLY;
2307 +static void squashfs_put_super(struct super_block *s)
2311 + if (s->s_fs_info) {
2312 + struct squashfs_sb_info *sbi = s->s_fs_info;
2313 + if (sbi->block_cache)
2314 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2315 + if (sbi->block_cache[i].block !=
2316 + SQUASHFS_INVALID_BLK)
2317 + kfree(sbi->block_cache[i].data);
2318 + if (sbi->fragment)
2319 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2320 + SQUASHFS_FREE(sbi->fragment[i].data);
2321 + kfree(sbi->fragment);
2322 + kfree(sbi->block_cache);
2323 + kfree(sbi->read_page);
2325 + kfree(sbi->fragment_index);
2326 + kfree(sbi->fragment_index_2);
2327 + kfree(sbi->meta_index);
2328 + vfree(sbi->stream.workspace);
2329 + kfree(s->s_fs_info);
2330 + s->s_fs_info = NULL;
2335 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2336 + const char *dev_name, void *data,
2337 + struct vfsmount *mnt)
2339 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2344 +static int __init init_squashfs_fs(void)
2346 + int err = init_inodecache();
2350 + printk(KERN_INFO "squashfs: version 3.2-r2 (2007/01/15) "
2351 + "Phillip Lougher\n");
2353 + if ((err = register_filesystem(&squashfs_fs_type)))
2354 + destroy_inodecache();
2361 +static void __exit exit_squashfs_fs(void)
2363 + unregister_filesystem(&squashfs_fs_type);
2364 + destroy_inodecache();
2368 +static struct kmem_cache * squashfs_inode_cachep;
2371 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2373 + struct squashfs_inode_info *ei;
2374 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2377 + return &ei->vfs_inode;
2381 +static void squashfs_destroy_inode(struct inode *inode)
2383 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2387 +static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
2389 + struct squashfs_inode_info *ei = foo;
2391 + inode_init_once(&ei->vfs_inode);
2395 +static int __init init_inodecache(void)
2397 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2398 + sizeof(struct squashfs_inode_info),
2399 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2401 + if (squashfs_inode_cachep == NULL)
2407 +static void destroy_inodecache(void)
2409 + kmem_cache_destroy(squashfs_inode_cachep);
2413 +module_init(init_squashfs_fs);
2414 +module_exit(exit_squashfs_fs);
2415 +MODULE_DESCRIPTION("squashfs 3.2-r2, a compressed read-only filesystem");
2416 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2417 +MODULE_LICENSE("GPL");
2418 diff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/Makefile linux-2.6.20-squashfs3.2-r2/fs/squashfs/Makefile
2419 --- linux-2.6.20/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2420 +++ linux-2.6.20-squashfs3.2-r2/fs/squashfs/Makefile 2007-01-12 00:06:09.000000000 +0000
2423 +# Makefile for the linux squashfs routines.
2426 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2427 +squashfs-y += inode.o
2428 +squashfs-y += squashfs2_0.o
2429 diff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs2_0.c linux-2.6.20-squashfs3.2-r2/fs/squashfs/squashfs2_0.c
2430 --- linux-2.6.20/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2431 +++ linux-2.6.20-squashfs3.2-r2/fs/squashfs/squashfs2_0.c 2007-01-12 02:27:20.000000000 +0000
2434 + * Squashfs - a compressed read only filesystem for Linux
2436 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
2437 + * Phillip Lougher <phillip@lougher.org.uk>
2439 + * This program is free software; you can redistribute it and/or
2440 + * modify it under the terms of the GNU General Public License
2441 + * as published by the Free Software Foundation; either version 2,
2442 + * or (at your option) any later version.
2444 + * This program is distributed in the hope that it will be useful,
2445 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2446 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2447 + * GNU General Public License for more details.
2449 + * You should have received a copy of the GNU General Public License
2450 + * along with this program; if not, write to the Free Software
2451 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2456 +#include <linux/squashfs_fs.h>
2457 +#include <linux/module.h>
2458 +#include <linux/zlib.h>
2459 +#include <linux/fs.h>
2460 +#include <linux/squashfs_fs_sb.h>
2461 +#include <linux/squashfs_fs_i.h>
2463 +#include "squashfs.h"
2464 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2465 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2466 + struct nameidata *);
2468 +static struct file_operations squashfs_dir_ops_2 = {
2469 + .read = generic_read_dir,
2470 + .readdir = squashfs_readdir_2
2473 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2474 + .lookup = squashfs_lookup_2
2477 +static unsigned char squashfs_filetype_table[] = {
2478 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2481 +static int read_fragment_index_table_2(struct super_block *s)
2483 + struct squashfs_sb_info *msblk = s->s_fs_info;
2484 + struct squashfs_super_block *sblk = &msblk->sblk;
2486 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2487 + (sblk->fragments), GFP_KERNEL))) {
2488 + ERROR("Failed to allocate uid/gid table\n");
2492 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2493 + !squashfs_read_data(s, (char *)
2494 + msblk->fragment_index_2,
2495 + sblk->fragment_table_start,
2496 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2497 + (sblk->fragments) |
2498 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2499 + ERROR("unable to read fragment index table\n");
2503 + if (msblk->swap) {
2505 + unsigned int fragment;
2507 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2509 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2510 + &msblk->fragment_index_2[i], 1);
2511 + msblk->fragment_index_2[i] = fragment;
2519 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2520 + long long *fragment_start_block,
2521 + unsigned int *fragment_size)
2523 + struct squashfs_sb_info *msblk = s->s_fs_info;
2524 + long long start_block =
2525 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2526 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2527 + struct squashfs_fragment_entry_2 fragment_entry;
2529 + if (msblk->swap) {
2530 + struct squashfs_fragment_entry_2 sfragment_entry;
2532 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2533 + start_block, offset,
2534 + sizeof(sfragment_entry), &start_block,
2537 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2539 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2540 + start_block, offset,
2541 + sizeof(fragment_entry), &start_block,
2545 + *fragment_start_block = fragment_entry.start_block;
2546 + *fragment_size = fragment_entry.size;
2555 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2556 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2558 + struct squashfs_super_block *sblk = &msblk->sblk;
2561 + i->i_mtime.tv_sec = sblk->mkfs_time;
2562 + i->i_atime.tv_sec = sblk->mkfs_time;
2563 + i->i_ctime.tv_sec = sblk->mkfs_time;
2564 + i->i_uid = msblk->uid[inodeb->uid];
2565 + i->i_mode = inodeb->mode;
2568 + if (inodeb->guid == SQUASHFS_GUIDS)
2569 + i->i_gid = i->i_uid;
2571 + i->i_gid = msblk->guid[inodeb->guid];
2575 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2577 + struct super_block *s = i->i_sb;
2578 + struct squashfs_sb_info *msblk = s->s_fs_info;
2579 + struct squashfs_super_block *sblk = &msblk->sblk;
2580 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2581 + sblk->inode_table_start;
2582 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2583 + unsigned int ino = i->i_ino;
2584 + long long next_block;
2585 + unsigned int next_offset;
2586 + union squashfs_inode_header_2 id, sid;
2587 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2588 + *sinodeb = &sid.base;
2590 + TRACE("Entered squashfs_iget\n");
2592 + if (msblk->swap) {
2593 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2594 + offset, sizeof(*sinodeb), &next_block,
2597 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2598 + sizeof(*sinodeb));
2600 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2601 + offset, sizeof(*inodeb), &next_block,
2605 + squashfs_new_inode(msblk, i, inodeb, ino);
2607 + switch(inodeb->inode_type) {
2608 + case SQUASHFS_FILE_TYPE: {
2609 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2610 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2611 + long long frag_blk;
2612 + unsigned int frag_size = 0;
2614 + if (msblk->swap) {
2615 + if (!squashfs_get_cached_block(s, (char *)
2616 + sinodep, block, offset,
2617 + sizeof(*sinodep), &next_block,
2620 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2622 + if (!squashfs_get_cached_block(s, (char *)
2623 + inodep, block, offset,
2624 + sizeof(*inodep), &next_block,
2628 + frag_blk = SQUASHFS_INVALID_BLK;
2629 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2630 + !get_fragment_location_2(s,
2631 + inodep->fragment, &frag_blk, &frag_size))
2634 + i->i_size = inodep->file_size;
2635 + i->i_fop = &generic_ro_fops;
2636 + i->i_mode |= S_IFREG;
2637 + i->i_mtime.tv_sec = inodep->mtime;
2638 + i->i_atime.tv_sec = inodep->mtime;
2639 + i->i_ctime.tv_sec = inodep->mtime;
2640 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2641 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2642 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2643 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2644 + SQUASHFS_I(i)->start_block = inodep->start_block;
2645 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2646 + SQUASHFS_I(i)->offset = next_offset;
2647 + if (sblk->block_size > 4096)
2648 + i->i_data.a_ops = &squashfs_aops;
2650 + i->i_data.a_ops = &squashfs_aops_4K;
2652 + TRACE("File inode %x:%x, start_block %x, "
2653 + "block_list_start %llx, offset %x\n",
2654 + SQUASHFS_INODE_BLK(inode), offset,
2655 + inodep->start_block, next_block,
2659 + case SQUASHFS_DIR_TYPE: {
2660 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2661 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2663 + if (msblk->swap) {
2664 + if (!squashfs_get_cached_block(s, (char *)
2665 + sinodep, block, offset,
2666 + sizeof(*sinodep), &next_block,
2669 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2671 + if (!squashfs_get_cached_block(s, (char *)
2672 + inodep, block, offset,
2673 + sizeof(*inodep), &next_block,
2677 + i->i_size = inodep->file_size;
2678 + i->i_op = &squashfs_dir_inode_ops_2;
2679 + i->i_fop = &squashfs_dir_ops_2;
2680 + i->i_mode |= S_IFDIR;
2681 + i->i_mtime.tv_sec = inodep->mtime;
2682 + i->i_atime.tv_sec = inodep->mtime;
2683 + i->i_ctime.tv_sec = inodep->mtime;
2684 + SQUASHFS_I(i)->start_block = inodep->start_block;
2685 + SQUASHFS_I(i)->offset = inodep->offset;
2686 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2687 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2689 + TRACE("Directory inode %x:%x, start_block %x, offset "
2690 + "%x\n", SQUASHFS_INODE_BLK(inode),
2691 + offset, inodep->start_block,
2695 + case SQUASHFS_LDIR_TYPE: {
2696 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2697 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2699 + if (msblk->swap) {
2700 + if (!squashfs_get_cached_block(s, (char *)
2701 + sinodep, block, offset,
2702 + sizeof(*sinodep), &next_block,
2705 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2708 + if (!squashfs_get_cached_block(s, (char *)
2709 + inodep, block, offset,
2710 + sizeof(*inodep), &next_block,
2714 + i->i_size = inodep->file_size;
2715 + i->i_op = &squashfs_dir_inode_ops_2;
2716 + i->i_fop = &squashfs_dir_ops_2;
2717 + i->i_mode |= S_IFDIR;
2718 + i->i_mtime.tv_sec = inodep->mtime;
2719 + i->i_atime.tv_sec = inodep->mtime;
2720 + i->i_ctime.tv_sec = inodep->mtime;
2721 + SQUASHFS_I(i)->start_block = inodep->start_block;
2722 + SQUASHFS_I(i)->offset = inodep->offset;
2723 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2724 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2726 + SQUASHFS_I(i)->u.s2.directory_index_count =
2728 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2730 + TRACE("Long directory inode %x:%x, start_block %x, "
2732 + SQUASHFS_INODE_BLK(inode), offset,
2733 + inodep->start_block, inodep->offset);
2736 + case SQUASHFS_SYMLINK_TYPE: {
2737 + struct squashfs_symlink_inode_header_2 *inodep =
2739 + struct squashfs_symlink_inode_header_2 *sinodep =
2742 + if (msblk->swap) {
2743 + if (!squashfs_get_cached_block(s, (char *)
2744 + sinodep, block, offset,
2745 + sizeof(*sinodep), &next_block,
2748 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2751 + if (!squashfs_get_cached_block(s, (char *)
2752 + inodep, block, offset,
2753 + sizeof(*inodep), &next_block,
2757 + i->i_size = inodep->symlink_size;
2758 + i->i_op = &page_symlink_inode_operations;
2759 + i->i_data.a_ops = &squashfs_symlink_aops;
2760 + i->i_mode |= S_IFLNK;
2761 + SQUASHFS_I(i)->start_block = next_block;
2762 + SQUASHFS_I(i)->offset = next_offset;
2764 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2766 + SQUASHFS_INODE_BLK(inode), offset,
2767 + next_block, next_offset);
2770 + case SQUASHFS_BLKDEV_TYPE:
2771 + case SQUASHFS_CHRDEV_TYPE: {
2772 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2773 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2775 + if (msblk->swap) {
2776 + if (!squashfs_get_cached_block(s, (char *)
2777 + sinodep, block, offset,
2778 + sizeof(*sinodep), &next_block,
2781 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2783 + if (!squashfs_get_cached_block(s, (char *)
2784 + inodep, block, offset,
2785 + sizeof(*inodep), &next_block,
2789 + i->i_mode |= (inodeb->inode_type ==
2790 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2792 + init_special_inode(i, i->i_mode,
2793 + old_decode_dev(inodep->rdev));
2795 + TRACE("Device inode %x:%x, rdev %x\n",
2796 + SQUASHFS_INODE_BLK(inode), offset,
2800 + case SQUASHFS_FIFO_TYPE:
2801 + case SQUASHFS_SOCKET_TYPE: {
2803 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2804 + ? S_IFIFO : S_IFSOCK;
2805 + init_special_inode(i, i->i_mode, 0);
2809 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2810 + inodeb->inode_type);
2811 + goto failed_read1;
2817 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2824 +static int get_dir_index_using_offset(struct super_block *s, long long
2825 + *next_block, unsigned int *next_offset,
2826 + long long index_start,
2827 + unsigned int index_offset, int i_count,
2830 + struct squashfs_sb_info *msblk = s->s_fs_info;
2831 + struct squashfs_super_block *sblk = &msblk->sblk;
2832 + int i, length = 0;
2833 + struct squashfs_dir_index_2 index;
2835 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2836 + i_count, (unsigned int) f_pos);
2841 + for (i = 0; i < i_count; i++) {
2842 + if (msblk->swap) {
2843 + struct squashfs_dir_index_2 sindex;
2844 + squashfs_get_cached_block(s, (char *) &sindex,
2845 + index_start, index_offset,
2846 + sizeof(sindex), &index_start,
2848 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2850 + squashfs_get_cached_block(s, (char *) &index,
2851 + index_start, index_offset,
2852 + sizeof(index), &index_start,
2855 + if (index.index > f_pos)
2858 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2859 + index.size + 1, &index_start,
2862 + length = index.index;
2863 + *next_block = index.start_block + sblk->directory_table_start;
2866 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2873 +static int get_dir_index_using_name(struct super_block *s, long long
2874 + *next_block, unsigned int *next_offset,
2875 + long long index_start,
2876 + unsigned int index_offset, int i_count,
2877 + const char *name, int size)
2879 + struct squashfs_sb_info *msblk = s->s_fs_info;
2880 + struct squashfs_super_block *sblk = &msblk->sblk;
2881 + int i, length = 0;
2882 + struct squashfs_dir_index_2 *index;
2885 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2887 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2888 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2889 + ERROR("Failed to allocate squashfs_dir_index\n");
2893 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2894 + strncpy(str, name, size);
2897 + for (i = 0; i < i_count; i++) {
2898 + if (msblk->swap) {
2899 + struct squashfs_dir_index_2 sindex;
2900 + squashfs_get_cached_block(s, (char *) &sindex,
2901 + index_start, index_offset,
2902 + sizeof(sindex), &index_start,
2904 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2906 + squashfs_get_cached_block(s, (char *) index,
2907 + index_start, index_offset,
2908 + sizeof(struct squashfs_dir_index_2),
2909 + &index_start, &index_offset);
2911 + squashfs_get_cached_block(s, index->name, index_start,
2912 + index_offset, index->size + 1,
2913 + &index_start, &index_offset);
2915 + index->name[index->size + 1] = '\0';
2917 + if (strcmp(index->name, str) > 0)
2920 + length = index->index;
2921 + *next_block = index->start_block + sblk->directory_table_start;
2924 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2931 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2933 + struct inode *i = file->f_dentry->d_inode;
2934 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2935 + struct squashfs_super_block *sblk = &msblk->sblk;
2936 + long long next_block = SQUASHFS_I(i)->start_block +
2937 + sblk->directory_table_start;
2938 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2940 + struct squashfs_dir_header_2 dirh;
2941 + struct squashfs_dir_entry_2 *dire;
2943 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2945 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2946 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2947 + ERROR("Failed to allocate squashfs_dir_entry\n");
2951 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2952 + SQUASHFS_I(i)->u.s2.directory_index_start,
2953 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2954 + SQUASHFS_I(i)->u.s2.directory_index_count,
2957 + while (length < i_size_read(i)) {
2958 + /* read directory header */
2959 + if (msblk->swap) {
2960 + struct squashfs_dir_header_2 sdirh;
2962 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2963 + next_block, next_offset, sizeof(sdirh),
2964 + &next_block, &next_offset))
2967 + length += sizeof(sdirh);
2968 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2970 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2971 + next_block, next_offset, sizeof(dirh),
2972 + &next_block, &next_offset))
2975 + length += sizeof(dirh);
2978 + dir_count = dirh.count + 1;
2979 + while (dir_count--) {
2980 + if (msblk->swap) {
2981 + struct squashfs_dir_entry_2 sdire;
2982 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2983 + &sdire, next_block, next_offset,
2984 + sizeof(sdire), &next_block,
2988 + length += sizeof(sdire);
2989 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2991 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2992 + dire, next_block, next_offset,
2993 + sizeof(*dire), &next_block,
2997 + length += sizeof(*dire);
3000 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
3001 + next_block, next_offset,
3002 + dire->size + 1, &next_block,
3006 + length += dire->size + 1;
3008 + if (file->f_pos >= length)
3011 + dire->name[dire->size + 1] = '\0';
3013 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
3014 + (unsigned int) dirent, dire->name,
3015 + dire->size + 1, (int) file->f_pos,
3016 + dirh.start_block, dire->offset,
3017 + squashfs_filetype_table[dire->type]);
3019 + if (filldir(dirent, dire->name, dire->size + 1,
3020 + file->f_pos, SQUASHFS_MK_VFS_INODE(
3021 + dirh.start_block, dire->offset),
3022 + squashfs_filetype_table[dire->type])
3024 + TRACE("Filldir returned less than 0\n");
3027 + file->f_pos = length;
3036 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3043 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
3044 + struct nameidata *nd)
3046 + const unsigned char *name = dentry->d_name.name;
3047 + int len = dentry->d_name.len;
3048 + struct inode *inode = NULL;
3049 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
3050 + struct squashfs_super_block *sblk = &msblk->sblk;
3051 + long long next_block = SQUASHFS_I(i)->start_block +
3052 + sblk->directory_table_start;
3053 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
3055 + struct squashfs_dir_header_2 dirh;
3056 + struct squashfs_dir_entry_2 *dire;
3057 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
3059 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
3061 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
3062 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
3063 + ERROR("Failed to allocate squashfs_dir_entry\n");
3067 + if (len > SQUASHFS_NAME_LEN)
3070 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
3071 + SQUASHFS_I(i)->u.s2.directory_index_start,
3072 + SQUASHFS_I(i)->u.s2.directory_index_offset,
3073 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
3076 + while (length < i_size_read(i)) {
3077 + /* read directory header */
3078 + if (msblk->swap) {
3079 + struct squashfs_dir_header_2 sdirh;
3080 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
3081 + next_block, next_offset, sizeof(sdirh),
3082 + &next_block, &next_offset))
3085 + length += sizeof(sdirh);
3086 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
3088 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
3089 + next_block, next_offset, sizeof(dirh),
3090 + &next_block, &next_offset))
3093 + length += sizeof(dirh);
3096 + dir_count = dirh.count + 1;
3097 + while (dir_count--) {
3098 + if (msblk->swap) {
3099 + struct squashfs_dir_entry_2 sdire;
3100 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3101 + &sdire, next_block,next_offset,
3102 + sizeof(sdire), &next_block,
3106 + length += sizeof(sdire);
3107 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
3109 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3110 + dire, next_block,next_offset,
3111 + sizeof(*dire), &next_block,
3115 + length += sizeof(*dire);
3118 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
3119 + next_block, next_offset, dire->size + 1,
3120 + &next_block, &next_offset))
3123 + length += dire->size + 1;
3125 + if (sorted && name[0] < dire->name[0])
3128 + if ((len == dire->size + 1) && !strncmp(name,
3129 + dire->name, len)) {
3130 + squashfs_inode_t ino =
3131 + SQUASHFS_MKINODE(dirh.start_block,
3133 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
3136 + TRACE("calling squashfs_iget for directory "
3137 + "entry %s, inode %x:%x, %lld\n", name,
3138 + dirh.start_block, dire->offset, ino);
3140 + inode = squashfs_iget(i->i_sb, ino, inode_number);
3149 + d_add(dentry, inode);
3150 + return ERR_PTR(0);
3153 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3159 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3161 + struct squashfs_super_block *sblk = &msblk->sblk;
3163 + msblk->read_inode = squashfs_read_inode_2;
3164 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3166 + sblk->bytes_used = sblk->bytes_used_2;
3167 + sblk->uid_start = sblk->uid_start_2;
3168 + sblk->guid_start = sblk->guid_start_2;
3169 + sblk->inode_table_start = sblk->inode_table_start_2;
3170 + sblk->directory_table_start = sblk->directory_table_start_2;
3171 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3175 diff -x .gitignore -Nurp linux-2.6.20/fs/squashfs/squashfs.h linux-2.6.20-squashfs3.2-r2/fs/squashfs/squashfs.h
3176 --- linux-2.6.20/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3177 +++ linux-2.6.20-squashfs3.2-r2/fs/squashfs/squashfs.h 2007-01-12 01:42:11.000000000 +0000
3180 + * Squashfs - a compressed read only filesystem for Linux
3182 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3183 + * Phillip Lougher <phillip@lougher.org.uk>
3185 + * This program is free software; you can redistribute it and/or
3186 + * modify it under the terms of the GNU General Public License
3187 + * as published by the Free Software Foundation; either version 2,
3188 + * or (at your option) any later version.
3190 + * This program is distributed in the hope that it will be useful,
3191 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3192 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3193 + * GNU General Public License for more details.
3195 + * You should have received a copy of the GNU General Public License
3196 + * along with this program; if not, write to the Free Software
3197 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3202 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3203 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3206 +#ifdef SQUASHFS_TRACE
3207 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3209 +#define TRACE(s, args...) {}
3212 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3214 +#define SERROR(s, args...) do { \
3216 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3219 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3221 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3223 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3226 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3227 +#define SQSH_EXTERN
3228 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3229 + long long index, unsigned int length,
3230 + long long *next_index, int srclength);
3231 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3232 + long long block, unsigned int offset,
3233 + int length, long long *next_block,
3234 + unsigned int *next_offset);
3235 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3236 + squashfs_fragment_cache *fragment);
3237 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3238 + *s, long long start_block,
3240 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
3241 +extern const struct address_space_operations squashfs_symlink_aops;
3242 +extern const struct address_space_operations squashfs_aops;
3243 +extern const struct address_space_operations squashfs_aops_4K;
3244 +extern struct inode_operations squashfs_dir_inode_ops;
3246 +#define SQSH_EXTERN static
3249 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3250 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3252 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3258 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3259 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3261 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3266 diff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs.h linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs.h
3267 --- linux-2.6.20/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3268 +++ linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs.h 2007-01-12 00:06:09.000000000 +0000
3270 +#ifndef SQUASHFS_FS
3271 +#define SQUASHFS_FS
3276 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3277 + * Phillip Lougher <phillip@lougher.org.uk>
3279 + * This program is free software; you can redistribute it and/or
3280 + * modify it under the terms of the GNU General Public License
3281 + * as published by the Free Software Foundation; either version 2,
3282 + * or (at your option) any later version.
3284 + * This program is distributed in the hope that it will be useful,
3285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3287 + * GNU General Public License for more details.
3289 + * You should have received a copy of the GNU General Public License
3290 + * along with this program; if not, write to the Free Software
3291 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3296 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3297 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3300 +#ifdef CONFIG_SQUASHFS_VMALLOC
3301 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3302 +#define SQUASHFS_FREE(a) vfree(a)
3304 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3305 +#define SQUASHFS_FREE(a) kfree(a)
3307 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3308 +#define SQUASHFS_MAJOR 3
3309 +#define SQUASHFS_MINOR 0
3310 +#define SQUASHFS_MAGIC 0x73717368
3311 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3312 +#define SQUASHFS_START 0
3314 +/* size of metadata (inode and directory) blocks */
3315 +#define SQUASHFS_METADATA_SIZE 8192
3316 +#define SQUASHFS_METADATA_LOG 13
3318 +/* default size of data blocks */
3319 +#define SQUASHFS_FILE_SIZE 65536
3320 +#define SQUASHFS_FILE_LOG 16
3322 +#define SQUASHFS_FILE_MAX_SIZE 65536
3324 +/* Max number of uids and gids */
3325 +#define SQUASHFS_UIDS 256
3326 +#define SQUASHFS_GUIDS 255
3328 +/* Max length of filename (not 255) */
3329 +#define SQUASHFS_NAME_LEN 256
3331 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3332 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3333 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3334 +#define SQUASHFS_USED_BLK ((long long) -2)
3336 +/* Filesystem flags */
3337 +#define SQUASHFS_NOI 0
3338 +#define SQUASHFS_NOD 1
3339 +#define SQUASHFS_CHECK 2
3340 +#define SQUASHFS_NOF 3
3341 +#define SQUASHFS_NO_FRAG 4
3342 +#define SQUASHFS_ALWAYS_FRAG 5
3343 +#define SQUASHFS_DUPLICATE 6
3344 +#define SQUASHFS_EXPORT 7
3346 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3348 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3351 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3354 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3357 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3360 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3361 + SQUASHFS_ALWAYS_FRAG)
3363 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3364 + SQUASHFS_DUPLICATE)
3366 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3369 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3372 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3373 + duplicate_checking, exortable) (noi | (nod << 1) | (check_data << 2) \
3374 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3375 + (duplicate_checking << 6) | (exportable << 7))
3377 +/* Max number of types and file types */
3378 +#define SQUASHFS_DIR_TYPE 1
3379 +#define SQUASHFS_FILE_TYPE 2
3380 +#define SQUASHFS_SYMLINK_TYPE 3
3381 +#define SQUASHFS_BLKDEV_TYPE 4
3382 +#define SQUASHFS_CHRDEV_TYPE 5
3383 +#define SQUASHFS_FIFO_TYPE 6
3384 +#define SQUASHFS_SOCKET_TYPE 7
3385 +#define SQUASHFS_LDIR_TYPE 8
3386 +#define SQUASHFS_LREG_TYPE 9
3388 +/* 1.0 filesystem type definitions */
3389 +#define SQUASHFS_TYPES 5
3390 +#define SQUASHFS_IPC_TYPE 0
3392 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3394 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3396 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3397 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3399 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3401 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3403 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3404 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3405 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3407 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3410 + * Inode number ops. Inodes consist of a compressed block number, and an
3411 + * uncompressed offset within that block
3413 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3415 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3417 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3420 +/* Compute 32 bit VFS inode number from squashfs inode number */
3421 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3425 +/* Translate between VFS mode and squashfs mode */
3426 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3428 +/* fragment and fragment table defines */
3429 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3431 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3432 + SQUASHFS_METADATA_SIZE)
3434 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3435 + SQUASHFS_METADATA_SIZE)
3437 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3438 + SQUASHFS_METADATA_SIZE - 1) / \
3439 + SQUASHFS_METADATA_SIZE)
3441 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3442 + sizeof(long long))
3444 +/* inode lookup table defines */
3445 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3447 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3448 + SQUASHFS_METADATA_SIZE)
3450 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3451 + SQUASHFS_METADATA_SIZE)
3453 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3454 + SQUASHFS_METADATA_SIZE - 1) / \
3455 + SQUASHFS_METADATA_SIZE)
3457 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3458 + sizeof(long long))
3460 +/* cached data constants for filesystem */
3461 +#define SQUASHFS_CACHED_BLKS 8
3463 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3465 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3466 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3468 +#define SQUASHFS_MARKER_BYTE 0xff
3470 +/* meta index cache */
3471 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3472 +#define SQUASHFS_META_ENTRIES 31
3473 +#define SQUASHFS_META_NUMBER 8
3474 +#define SQUASHFS_SLOTS 4
3476 +struct meta_entry {
3477 + long long data_block;
3478 + unsigned int index_block;
3479 + unsigned short offset;
3480 + unsigned short pad;
3483 +struct meta_index {
3484 + unsigned int inode_number;
3485 + unsigned int offset;
3486 + unsigned short entries;
3487 + unsigned short skip;
3488 + unsigned short locked;
3489 + unsigned short pad;
3490 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3495 + * definitions for structures on disk
3498 +typedef long long squashfs_block_t;
3499 +typedef long long squashfs_inode_t;
3501 +struct squashfs_super_block {
3502 + unsigned int s_magic;
3503 + unsigned int inodes;
3504 + unsigned int bytes_used_2;
3505 + unsigned int uid_start_2;
3506 + unsigned int guid_start_2;
3507 + unsigned int inode_table_start_2;
3508 + unsigned int directory_table_start_2;
3509 + unsigned int s_major:16;
3510 + unsigned int s_minor:16;
3511 + unsigned int block_size_1:16;
3512 + unsigned int block_log:16;
3513 + unsigned int flags:8;
3514 + unsigned int no_uids:8;
3515 + unsigned int no_guids:8;
3516 + unsigned int mkfs_time /* time of filesystem creation */;
3517 + squashfs_inode_t root_inode;
3518 + unsigned int block_size;
3519 + unsigned int fragments;
3520 + unsigned int fragment_table_start_2;
3521 + long long bytes_used;
3522 + long long uid_start;
3523 + long long guid_start;
3524 + long long inode_table_start;
3525 + long long directory_table_start;
3526 + long long fragment_table_start;
3527 + long long lookup_table_start;
3528 +} __attribute__ ((packed));
3530 +struct squashfs_dir_index {
3531 + unsigned int index;
3532 + unsigned int start_block;
3533 + unsigned char size;
3534 + unsigned char name[0];
3535 +} __attribute__ ((packed));
3537 +#define SQUASHFS_BASE_INODE_HEADER \
3538 + unsigned int inode_type:4; \
3539 + unsigned int mode:12; \
3540 + unsigned int uid:8; \
3541 + unsigned int guid:8; \
3542 + unsigned int mtime; \
3543 + unsigned int inode_number;
3545 +struct squashfs_base_inode_header {
3546 + SQUASHFS_BASE_INODE_HEADER;
3547 +} __attribute__ ((packed));
3549 +struct squashfs_ipc_inode_header {
3550 + SQUASHFS_BASE_INODE_HEADER;
3551 + unsigned int nlink;
3552 +} __attribute__ ((packed));
3554 +struct squashfs_dev_inode_header {
3555 + SQUASHFS_BASE_INODE_HEADER;
3556 + unsigned int nlink;
3557 + unsigned short rdev;
3558 +} __attribute__ ((packed));
3560 +struct squashfs_symlink_inode_header {
3561 + SQUASHFS_BASE_INODE_HEADER;
3562 + unsigned int nlink;
3563 + unsigned short symlink_size;
3565 +} __attribute__ ((packed));
3567 +struct squashfs_reg_inode_header {
3568 + SQUASHFS_BASE_INODE_HEADER;
3569 + squashfs_block_t start_block;
3570 + unsigned int fragment;
3571 + unsigned int offset;
3572 + unsigned int file_size;
3573 + unsigned short block_list[0];
3574 +} __attribute__ ((packed));
3576 +struct squashfs_lreg_inode_header {
3577 + SQUASHFS_BASE_INODE_HEADER;
3578 + unsigned int nlink;
3579 + squashfs_block_t start_block;
3580 + unsigned int fragment;
3581 + unsigned int offset;
3582 + long long file_size;
3583 + unsigned short block_list[0];
3584 +} __attribute__ ((packed));
3586 +struct squashfs_dir_inode_header {
3587 + SQUASHFS_BASE_INODE_HEADER;
3588 + unsigned int nlink;
3589 + unsigned int file_size:19;
3590 + unsigned int offset:13;
3591 + unsigned int start_block;
3592 + unsigned int parent_inode;
3593 +} __attribute__ ((packed));
3595 +struct squashfs_ldir_inode_header {
3596 + SQUASHFS_BASE_INODE_HEADER;
3597 + unsigned int nlink;
3598 + unsigned int file_size:27;
3599 + unsigned int offset:13;
3600 + unsigned int start_block;
3601 + unsigned int i_count:16;
3602 + unsigned int parent_inode;
3603 + struct squashfs_dir_index index[0];
3604 +} __attribute__ ((packed));
3606 +union squashfs_inode_header {
3607 + struct squashfs_base_inode_header base;
3608 + struct squashfs_dev_inode_header dev;
3609 + struct squashfs_symlink_inode_header symlink;
3610 + struct squashfs_reg_inode_header reg;
3611 + struct squashfs_lreg_inode_header lreg;
3612 + struct squashfs_dir_inode_header dir;
3613 + struct squashfs_ldir_inode_header ldir;
3614 + struct squashfs_ipc_inode_header ipc;
3617 +struct squashfs_dir_entry {
3618 + unsigned int offset:13;
3619 + unsigned int type:3;
3620 + unsigned int size:8;
3621 + int inode_number:16;
3623 +} __attribute__ ((packed));
3625 +struct squashfs_dir_header {
3626 + unsigned int count:8;
3627 + unsigned int start_block;
3628 + unsigned int inode_number;
3629 +} __attribute__ ((packed));
3631 +struct squashfs_fragment_entry {
3632 + long long start_block;
3633 + unsigned int size;
3634 + unsigned int pending;
3635 +} __attribute__ ((packed));
3637 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3638 +extern int squashfs_uncompress_init(void);
3639 +extern int squashfs_uncompress_exit(void);
3642 + * macros to convert each packed bitfield structure from little endian to big
3643 + * endian and vice versa. These are needed when creating or using a filesystem
3644 + * on a machine with different byte ordering to the target architecture.
3648 +#define SQUASHFS_SWAP_START \
3651 + unsigned long long val;\
3652 + unsigned char *s;\
3655 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3656 + SQUASHFS_SWAP_START\
3657 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3658 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3659 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3660 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3661 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3662 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3663 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3664 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3665 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3666 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3667 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3668 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3669 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3670 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3671 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3672 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3673 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3674 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3675 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3676 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3677 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3678 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3679 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3680 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3681 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3682 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3683 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3686 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3687 + SQUASHFS_MEMSET(s, d, n);\
3688 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3689 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3690 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3691 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3692 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3693 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3695 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3696 + SQUASHFS_SWAP_START\
3697 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3700 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3701 + SQUASHFS_SWAP_START\
3702 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3703 + sizeof(struct squashfs_ipc_inode_header))\
3704 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3707 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3708 + SQUASHFS_SWAP_START\
3709 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3710 + sizeof(struct squashfs_dev_inode_header)); \
3711 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3712 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3715 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3716 + SQUASHFS_SWAP_START\
3717 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3718 + sizeof(struct squashfs_symlink_inode_header));\
3719 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3720 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3723 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3724 + SQUASHFS_SWAP_START\
3725 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3726 + sizeof(struct squashfs_reg_inode_header));\
3727 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3728 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3729 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3730 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3733 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3734 + SQUASHFS_SWAP_START\
3735 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3736 + sizeof(struct squashfs_lreg_inode_header));\
3737 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3738 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3739 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3740 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3741 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3744 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3745 + SQUASHFS_SWAP_START\
3746 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3747 + sizeof(struct squashfs_dir_inode_header));\
3748 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3749 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3750 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3751 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3752 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3755 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3756 + SQUASHFS_SWAP_START\
3757 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3758 + sizeof(struct squashfs_ldir_inode_header));\
3759 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3760 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3761 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3762 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3763 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3764 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3767 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3768 + SQUASHFS_SWAP_START\
3769 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3770 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3771 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3772 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3775 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3776 + SQUASHFS_SWAP_START\
3777 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3778 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3779 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3780 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3783 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3784 + SQUASHFS_SWAP_START\
3785 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3786 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3787 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3788 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3789 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3792 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3793 + SQUASHFS_SWAP_START\
3794 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3795 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3796 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3799 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3801 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3803 + int bit_position;\
3804 + SQUASHFS_SWAP_START\
3805 + SQUASHFS_MEMSET(s, d, n * 2);\
3806 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3808 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3811 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3813 + int bit_position;\
3814 + SQUASHFS_SWAP_START\
3815 + SQUASHFS_MEMSET(s, d, n * 4);\
3816 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3818 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3821 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3823 + int bit_position;\
3824 + SQUASHFS_SWAP_START\
3825 + SQUASHFS_MEMSET(s, d, n * 8);\
3826 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3828 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3831 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3833 + int bit_position;\
3834 + SQUASHFS_SWAP_START\
3835 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3836 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3838 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3841 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3842 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3844 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3846 +struct squashfs_base_inode_header_1 {
3847 + unsigned int inode_type:4;
3848 + unsigned int mode:12; /* protection */
3849 + unsigned int uid:4; /* index into uid table */
3850 + unsigned int guid:4; /* index into guid table */
3851 +} __attribute__ ((packed));
3853 +struct squashfs_ipc_inode_header_1 {
3854 + unsigned int inode_type:4;
3855 + unsigned int mode:12; /* protection */
3856 + unsigned int uid:4; /* index into uid table */
3857 + unsigned int guid:4; /* index into guid table */
3858 + unsigned int type:4;
3859 + unsigned int offset:4;
3860 +} __attribute__ ((packed));
3862 +struct squashfs_dev_inode_header_1 {
3863 + unsigned int inode_type:4;
3864 + unsigned int mode:12; /* protection */
3865 + unsigned int uid:4; /* index into uid table */
3866 + unsigned int guid:4; /* index into guid table */
3867 + unsigned short rdev;
3868 +} __attribute__ ((packed));
3870 +struct squashfs_symlink_inode_header_1 {
3871 + unsigned int inode_type:4;
3872 + unsigned int mode:12; /* protection */
3873 + unsigned int uid:4; /* index into uid table */
3874 + unsigned int guid:4; /* index into guid table */
3875 + unsigned short symlink_size;
3877 +} __attribute__ ((packed));
3879 +struct squashfs_reg_inode_header_1 {
3880 + unsigned int inode_type:4;
3881 + unsigned int mode:12; /* protection */
3882 + unsigned int uid:4; /* index into uid table */
3883 + unsigned int guid:4; /* index into guid table */
3884 + unsigned int mtime;
3885 + unsigned int start_block;
3886 + unsigned int file_size:32;
3887 + unsigned short block_list[0];
3888 +} __attribute__ ((packed));
3890 +struct squashfs_dir_inode_header_1 {
3891 + unsigned int inode_type:4;
3892 + unsigned int mode:12; /* protection */
3893 + unsigned int uid:4; /* index into uid table */
3894 + unsigned int guid:4; /* index into guid table */
3895 + unsigned int file_size:19;
3896 + unsigned int offset:13;
3897 + unsigned int mtime;
3898 + unsigned int start_block:24;
3899 +} __attribute__ ((packed));
3901 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3902 + SQUASHFS_MEMSET(s, d, n);\
3903 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3904 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3905 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3906 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3908 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3909 + SQUASHFS_SWAP_START\
3910 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3913 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3914 + SQUASHFS_SWAP_START\
3915 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3916 + sizeof(struct squashfs_ipc_inode_header_1));\
3917 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3918 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3921 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3922 + SQUASHFS_SWAP_START\
3923 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3924 + sizeof(struct squashfs_dev_inode_header_1));\
3925 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3928 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3929 + SQUASHFS_SWAP_START\
3930 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3931 + sizeof(struct squashfs_symlink_inode_header_1));\
3932 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3935 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3936 + SQUASHFS_SWAP_START\
3937 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3938 + sizeof(struct squashfs_reg_inode_header_1));\
3939 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3940 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3941 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3944 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3945 + SQUASHFS_SWAP_START\
3946 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3947 + sizeof(struct squashfs_dir_inode_header_1));\
3948 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3949 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3950 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3951 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3956 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3958 +struct squashfs_dir_index_2 {
3959 + unsigned int index:27;
3960 + unsigned int start_block:29;
3961 + unsigned char size;
3962 + unsigned char name[0];
3963 +} __attribute__ ((packed));
3965 +struct squashfs_base_inode_header_2 {
3966 + unsigned int inode_type:4;
3967 + unsigned int mode:12; /* protection */
3968 + unsigned int uid:8; /* index into uid table */
3969 + unsigned int guid:8; /* index into guid table */
3970 +} __attribute__ ((packed));
3972 +struct squashfs_ipc_inode_header_2 {
3973 + unsigned int inode_type:4;
3974 + unsigned int mode:12; /* protection */
3975 + unsigned int uid:8; /* index into uid table */
3976 + unsigned int guid:8; /* index into guid table */
3977 +} __attribute__ ((packed));
3979 +struct squashfs_dev_inode_header_2 {
3980 + unsigned int inode_type:4;
3981 + unsigned int mode:12; /* protection */
3982 + unsigned int uid:8; /* index into uid table */
3983 + unsigned int guid:8; /* index into guid table */
3984 + unsigned short rdev;
3985 +} __attribute__ ((packed));
3987 +struct squashfs_symlink_inode_header_2 {
3988 + unsigned int inode_type:4;
3989 + unsigned int mode:12; /* protection */
3990 + unsigned int uid:8; /* index into uid table */
3991 + unsigned int guid:8; /* index into guid table */
3992 + unsigned short symlink_size;
3994 +} __attribute__ ((packed));
3996 +struct squashfs_reg_inode_header_2 {
3997 + unsigned int inode_type:4;
3998 + unsigned int mode:12; /* protection */
3999 + unsigned int uid:8; /* index into uid table */
4000 + unsigned int guid:8; /* index into guid table */
4001 + unsigned int mtime;
4002 + unsigned int start_block;
4003 + unsigned int fragment;
4004 + unsigned int offset;
4005 + unsigned int file_size:32;
4006 + unsigned short block_list[0];
4007 +} __attribute__ ((packed));
4009 +struct squashfs_dir_inode_header_2 {
4010 + unsigned int inode_type:4;
4011 + unsigned int mode:12; /* protection */
4012 + unsigned int uid:8; /* index into uid table */
4013 + unsigned int guid:8; /* index into guid table */
4014 + unsigned int file_size:19;
4015 + unsigned int offset:13;
4016 + unsigned int mtime;
4017 + unsigned int start_block:24;
4018 +} __attribute__ ((packed));
4020 +struct squashfs_ldir_inode_header_2 {
4021 + unsigned int inode_type:4;
4022 + unsigned int mode:12; /* protection */
4023 + unsigned int uid:8; /* index into uid table */
4024 + unsigned int guid:8; /* index into guid table */
4025 + unsigned int file_size:27;
4026 + unsigned int offset:13;
4027 + unsigned int mtime;
4028 + unsigned int start_block:24;
4029 + unsigned int i_count:16;
4030 + struct squashfs_dir_index_2 index[0];
4031 +} __attribute__ ((packed));
4033 +union squashfs_inode_header_2 {
4034 + struct squashfs_base_inode_header_2 base;
4035 + struct squashfs_dev_inode_header_2 dev;
4036 + struct squashfs_symlink_inode_header_2 symlink;
4037 + struct squashfs_reg_inode_header_2 reg;
4038 + struct squashfs_dir_inode_header_2 dir;
4039 + struct squashfs_ldir_inode_header_2 ldir;
4040 + struct squashfs_ipc_inode_header_2 ipc;
4043 +struct squashfs_dir_header_2 {
4044 + unsigned int count:8;
4045 + unsigned int start_block:24;
4046 +} __attribute__ ((packed));
4048 +struct squashfs_dir_entry_2 {
4049 + unsigned int offset:13;
4050 + unsigned int type:3;
4051 + unsigned int size:8;
4053 +} __attribute__ ((packed));
4055 +struct squashfs_fragment_entry_2 {
4056 + unsigned int start_block;
4057 + unsigned int size;
4058 +} __attribute__ ((packed));
4060 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
4061 + SQUASHFS_MEMSET(s, d, n);\
4062 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
4063 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
4064 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
4065 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
4067 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
4068 + SQUASHFS_SWAP_START\
4069 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
4072 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
4073 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
4075 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
4076 + SQUASHFS_SWAP_START\
4077 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
4078 + sizeof(struct squashfs_dev_inode_header_2)); \
4079 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
4082 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
4083 + SQUASHFS_SWAP_START\
4084 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
4085 + sizeof(struct squashfs_symlink_inode_header_2));\
4086 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
4089 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
4090 + SQUASHFS_SWAP_START\
4091 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
4092 + sizeof(struct squashfs_reg_inode_header_2));\
4093 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
4094 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
4095 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
4096 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
4097 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
4100 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
4101 + SQUASHFS_SWAP_START\
4102 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
4103 + sizeof(struct squashfs_dir_inode_header_2));\
4104 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
4105 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
4106 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
4107 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
4110 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
4111 + SQUASHFS_SWAP_START\
4112 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
4113 + sizeof(struct squashfs_ldir_inode_header_2));\
4114 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
4115 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
4116 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
4117 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
4118 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
4121 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
4122 + SQUASHFS_SWAP_START\
4123 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
4124 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
4125 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
4126 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
4128 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
4129 + SQUASHFS_SWAP_START\
4130 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
4131 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
4132 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
4135 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
4136 + SQUASHFS_SWAP_START\
4137 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
4138 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
4139 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
4140 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
4143 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
4144 + SQUASHFS_SWAP_START\
4145 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
4146 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
4147 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
4150 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
4152 +/* fragment and fragment table defines */
4153 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
4155 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
4156 + SQUASHFS_METADATA_SIZE)
4158 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4159 + SQUASHFS_METADATA_SIZE)
4161 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4162 + SQUASHFS_METADATA_SIZE - 1) / \
4163 + SQUASHFS_METADATA_SIZE)
4165 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4173 + * macros used to swap each structure entry, taking into account
4174 + * bitfields and different bitfield placing conventions on differing
4178 +#include <asm/byteorder.h>
4180 +#ifdef __BIG_ENDIAN
4181 + /* convert from little endian to big endian */
4182 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4185 + /* convert from big endian to little endian */
4186 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4187 + tbits, 64 - tbits - b_pos)
4190 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4193 + s = (unsigned char *)p + (pos / 8);\
4194 + d = ((unsigned char *) &val) + 7;\
4195 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4197 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4200 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4204 diff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_i.h linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs_i.h
4205 --- linux-2.6.20/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4206 +++ linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs_i.h 2007-01-12 00:06:09.000000000 +0000
4208 +#ifndef SQUASHFS_FS_I
4209 +#define SQUASHFS_FS_I
4213 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4214 + * Phillip Lougher <phillip@lougher.org.uk>
4216 + * This program is free software; you can redistribute it and/or
4217 + * modify it under the terms of the GNU General Public License
4218 + * as published by the Free Software Foundation; either version 2,
4219 + * or (at your option) any later version.
4221 + * This program is distributed in the hope that it will be useful,
4222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4224 + * GNU General Public License for more details.
4226 + * You should have received a copy of the GNU General Public License
4227 + * along with this program; if not, write to the Free Software
4228 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4233 +struct squashfs_inode_info {
4234 + long long start_block;
4235 + unsigned int offset;
4238 + long long fragment_start_block;
4239 + unsigned int fragment_size;
4240 + unsigned int fragment_offset;
4241 + long long block_list_start;
4244 + long long directory_index_start;
4245 + unsigned int directory_index_offset;
4246 + unsigned int directory_index_count;
4247 + unsigned int parent_inode;
4250 + struct inode vfs_inode;
4253 diff -x .gitignore -Nurp linux-2.6.20/include/linux/squashfs_fs_sb.h linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs_sb.h
4254 --- linux-2.6.20/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4255 +++ linux-2.6.20-squashfs3.2-r2/include/linux/squashfs_fs_sb.h 2007-01-12 01:23:47.000000000 +0000
4257 +#ifndef SQUASHFS_FS_SB
4258 +#define SQUASHFS_FS_SB
4262 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4263 + * Phillip Lougher <phillip@lougher.org.uk>
4265 + * This program is free software; you can redistribute it and/or
4266 + * modify it under the terms of the GNU General Public License
4267 + * as published by the Free Software Foundation; either version 2,
4268 + * or (at your option) any later version.
4270 + * This program is distributed in the hope that it will be useful,
4271 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4272 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4273 + * GNU General Public License for more details.
4275 + * You should have received a copy of the GNU General Public License
4276 + * along with this program; if not, write to the Free Software
4277 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4279 + * squashfs_fs_sb.h
4282 +#include <linux/squashfs_fs.h>
4284 +struct squashfs_cache {
4287 + long long next_index;
4291 +struct squashfs_fragment_cache {
4294 + unsigned int locked;
4298 +struct squashfs_sb_info {
4299 + struct squashfs_super_block sblk;
4301 + int devblksize_log2;
4303 + struct squashfs_cache *block_cache;
4304 + struct squashfs_fragment_cache *fragment;
4306 + int next_fragment;
4307 + int next_meta_index;
4308 + unsigned int *uid;
4309 + unsigned int *guid;
4310 + long long *fragment_index;
4311 + unsigned int *fragment_index_2;
4313 + struct mutex read_data_mutex;
4314 + struct mutex read_page_mutex;
4315 + struct mutex block_cache_mutex;
4316 + struct mutex fragment_mutex;
4317 + struct mutex meta_index_mutex;
4318 + wait_queue_head_t waitq;
4319 + wait_queue_head_t fragment_wait_queue;
4320 + struct meta_index *meta_index;
4322 + long long *inode_lookup_table;
4323 + int (*read_inode)(struct inode *i, squashfs_inode_t \
4325 + long long (*read_blocklist)(struct inode *inode, int \
4326 + index, int readahead_blks, char *block_list, \
4327 + unsigned short **block_p, unsigned int *bsize);
4328 + int (*read_fragment_index_table)(struct super_block *s);
4331 diff -x .gitignore -Nurp linux-2.6.20/init/do_mounts_rd.c linux-2.6.20-squashfs3.2-r2/init/do_mounts_rd.c
4332 --- linux-2.6.20/init/do_mounts_rd.c 2006-11-29 21:57:37.000000000 +0000
4333 +++ linux-2.6.20-squashfs3.2-r2/init/do_mounts_rd.c 2007-01-16 02:06:03.000000000 +0000
4335 #include <linux/ext2_fs.h>
4336 #include <linux/romfs_fs.h>
4337 #include <linux/cramfs_fs.h>
4338 +#include <linux/squashfs_fs.h>
4339 #include <linux/initrd.h>
4340 #include <linux/string.h>
4342 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4343 * numbers could not be found.
4345 * We currently check for the following magic numbers:
4350 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4351 struct ext2_super_block *ext2sb;
4352 struct romfs_super_block *romfsb;
4353 struct cramfs_super *cramfsb;
4354 + struct squashfs_super_block *squashfsb;
4358 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4359 ext2sb = (struct ext2_super_block *) buf;
4360 romfsb = (struct romfs_super_block *) buf;
4361 cramfsb = (struct cramfs_super *) buf;
4362 + squashfsb = (struct squashfs_super_block *) buf;
4363 memset(buf, 0xe5, size);
4366 @@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4370 + /* squashfs is at block zero too */
4371 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4372 + printk(KERN_NOTICE
4373 + "RAMDISK: squashfs filesystem found at block %d\n",
4375 + if (squashfsb->s_major < 3)
4376 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4378 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4383 * Read block 1 to test for minix and ext2 superblock