1 diff -x .gitignore -Nurp linux-2.6.24/fs/Kconfig linux-2.6.24-squashfs3.3/fs/Kconfig
2 --- linux-2.6.24/fs/Kconfig 2007-10-25 17:41:45.000000000 +0100
3 +++ linux-2.6.24-squashfs3.3/fs/Kconfig 2007-11-01 05:06:25.000000000 +0000
4 @@ -1396,6 +1396,56 @@ config CRAMFS
9 + tristate "SquashFS 3.3 - Squashed file system support"
12 + Saying Y here includes support for SquashFS 3.3 (a Compressed
13 + Read-Only File System). Squashfs is a highly compressed read-only
14 + filesystem for Linux. It uses zlib compression to compress both
15 + files, inodes and directories. Inodes in the system are very small
16 + and all blocks are packed to minimise data overhead. Block sizes
17 + greater than 4K are supported up to a maximum of 1 Mbytes (default
18 + block size 128K). SquashFS 3.3 supports 64 bit filesystems and files
19 + (larger than 4GB), full uid/gid information, hard links and timestamps.
21 + Squashfs is intended for general read-only filesystem use, for
22 + archival use (i.e. in cases where a .tar.gz file may be used), and in
23 + embedded systems where low overhead is needed. Further information
24 + and filesystem tools are available from http://squashfs.sourceforge.net.
26 + If you want to compile this as a module ( = code which can be
27 + inserted in and removed from the running kernel whenever you want),
28 + say M here and read <file:Documentation/modules.txt>. The module
29 + will be called squashfs. Note that the root file system (the one
30 + containing the directory /) cannot be compiled as a module.
34 +config SQUASHFS_EMBEDDED
36 + bool "Additional option for memory-constrained systems"
40 + Saying Y here allows you to specify cache size.
44 +config SQUASHFS_FRAGMENT_CACHE_SIZE
45 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
49 + By default SquashFS caches the last 3 fragments read from
50 + the filesystem. Increasing this amount may mean SquashFS
51 + has to re-read fragments less often from disk, at the expense
52 + of extra system memory. Decreasing this amount will mean
53 + SquashFS uses less memory at the expense of extra reads from disk.
55 + Note there must be at least one cached fragment. Anything
56 + much more than three will probably not make much difference.
59 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
61 diff -x .gitignore -Nurp linux-2.6.24/fs/Makefile linux-2.6.24-squashfs3.3/fs/Makefile
62 --- linux-2.6.24/fs/Makefile 2007-10-25 17:41:45.000000000 +0100
63 +++ linux-2.6.24-squashfs3.3/fs/Makefile 2007-11-01 05:08:09.000000000 +0000
64 @@ -72,6 +72,7 @@ obj-$(CONFIG_JBD) += jbd/
65 obj-$(CONFIG_JBD2) += jbd2/
66 obj-$(CONFIG_EXT2_FS) += ext2/
67 obj-$(CONFIG_CRAMFS) += cramfs/
68 +obj-$(CONFIG_SQUASHFS) += squashfs/
70 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
71 obj-$(CONFIG_CODA_FS) += coda/
72 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/inode.c linux-2.6.24-squashfs3.3/fs/squashfs/inode.c
73 --- linux-2.6.24/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
74 +++ linux-2.6.24-squashfs3.3/fs/squashfs/inode.c 2007-11-01 05:05:00.000000000 +0000
77 + * Squashfs - a compressed read only filesystem for Linux
79 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
80 + * Phillip Lougher <phillip@lougher.demon.co.uk>
82 + * This program is free software; you can redistribute it and/or
83 + * modify it under the terms of the GNU General Public License
84 + * as published by the Free Software Foundation; either version 2,
85 + * or (at your option) any later version.
87 + * This program is distributed in the hope that it will be useful,
88 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
89 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 + * GNU General Public License for more details.
92 + * You should have received a copy of the GNU General Public License
93 + * along with this program; if not, write to the Free Software
94 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
99 +#include <linux/squashfs_fs.h>
100 +#include <linux/module.h>
101 +#include <linux/zlib.h>
102 +#include <linux/fs.h>
103 +#include <linux/squashfs_fs_sb.h>
104 +#include <linux/squashfs_fs_i.h>
105 +#include <linux/buffer_head.h>
106 +#include <linux/vfs.h>
107 +#include <linux/vmalloc.h>
108 +#include <linux/smp_lock.h>
109 +#include <linux/exportfs.h>
111 +#include "squashfs.h"
113 +int squashfs_cached_blks;
115 +static struct dentry *squashfs_get_parent(struct dentry *child);
116 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
117 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
118 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
119 +static long long read_blocklist(struct inode *inode, int index,
120 + int readahead_blks, char *block_list,
121 + unsigned short **block_p, unsigned int *bsize);
122 +static int squashfs_readpage(struct file *file, struct page *page);
123 +static int squashfs_readdir(struct file *, void *, filldir_t);
124 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
125 + struct nameidata *);
126 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
127 +static void squashfs_put_super(struct super_block *);
128 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
129 + struct vfsmount *);
130 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
131 +static void squashfs_destroy_inode(struct inode *inode);
132 +static int init_inodecache(void);
133 +static void destroy_inodecache(void);
135 +static struct file_system_type squashfs_fs_type = {
136 + .owner = THIS_MODULE,
137 + .name = "squashfs",
138 + .get_sb = squashfs_get_sb,
139 + .kill_sb = kill_block_super,
140 + .fs_flags = FS_REQUIRES_DEV
143 +static const unsigned char squashfs_filetype_table[] = {
144 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
147 +static struct super_operations squashfs_super_ops = {
148 + .alloc_inode = squashfs_alloc_inode,
149 + .destroy_inode = squashfs_destroy_inode,
150 + .statfs = squashfs_statfs,
151 + .put_super = squashfs_put_super,
152 + .remount_fs = squashfs_remount
155 +static struct super_operations squashfs_export_super_ops = {
156 + .alloc_inode = squashfs_alloc_inode,
157 + .destroy_inode = squashfs_destroy_inode,
158 + .statfs = squashfs_statfs,
159 + .put_super = squashfs_put_super,
162 +static struct export_operations squashfs_export_ops = {
163 + .get_parent = squashfs_get_parent
166 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
167 + .readpage = squashfs_symlink_readpage
170 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
171 + .readpage = squashfs_readpage
174 +static const struct file_operations squashfs_dir_ops = {
175 + .read = generic_read_dir,
176 + .readdir = squashfs_readdir
179 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
180 + .lookup = squashfs_lookup
184 +static struct buffer_head *get_block_length(struct super_block *s,
185 + int *cur_index, int *offset, int *c_byte)
187 + struct squashfs_sb_info *msblk = s->s_fs_info;
188 + unsigned short temp;
189 + struct buffer_head *bh;
191 + if (!(bh = sb_bread(s, *cur_index)))
194 + if (msblk->devblksize - *offset == 1) {
196 + ((unsigned char *) &temp)[1] = *((unsigned char *)
197 + (bh->b_data + *offset));
199 + ((unsigned char *) &temp)[0] = *((unsigned char *)
200 + (bh->b_data + *offset));
202 + if (!(bh = sb_bread(s, ++(*cur_index))))
205 + ((unsigned char *) &temp)[0] = *((unsigned char *)
208 + ((unsigned char *) &temp)[1] = *((unsigned char *)
214 + ((unsigned char *) &temp)[1] = *((unsigned char *)
215 + (bh->b_data + *offset));
216 + ((unsigned char *) &temp)[0] = *((unsigned char *)
217 + (bh->b_data + *offset + 1));
219 + ((unsigned char *) &temp)[0] = *((unsigned char *)
220 + (bh->b_data + *offset));
221 + ((unsigned char *) &temp)[1] = *((unsigned char *)
222 + (bh->b_data + *offset + 1));
228 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
229 + if (*offset == msblk->devblksize) {
231 + if (!(bh = sb_bread(s, ++(*cur_index))))
235 + if (*((unsigned char *) (bh->b_data + *offset)) !=
236 + SQUASHFS_MARKER_BYTE) {
237 + ERROR("Metadata block marker corrupt @ %x\n",
251 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
252 + long long index, unsigned int length,
253 + long long *next_index, int srclength)
255 + struct squashfs_sb_info *msblk = s->s_fs_info;
256 + struct squashfs_super_block *sblk = &msblk->sblk;
257 + struct buffer_head **bh;
258 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
259 + unsigned int cur_index = index >> msblk->devblksize_log2;
260 + int bytes, avail_bytes, b = 0, k = 0;
261 + unsigned int compressed;
262 + unsigned int c_byte = length;
264 + bh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *
265 + sizeof(struct buffer_head *), GFP_KERNEL);
270 + bytes = msblk->devblksize - offset;
271 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
272 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
274 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index,
275 + compressed ? "" : "un", (unsigned int) c_byte, srclength);
277 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
280 + bh[0] = sb_getblk(s, cur_index);
282 + goto block_release;
284 + for (b = 1; bytes < c_byte; b++) {
285 + bh[b] = sb_getblk(s, ++cur_index);
287 + goto block_release;
288 + bytes += msblk->devblksize;
290 + ll_rw_block(READ, b, bh);
292 + if (index < 0 || (index + 2) > sblk->bytes_used)
295 + bh[0] = get_block_length(s, &cur_index, &offset, &c_byte);
299 + bytes = msblk->devblksize - offset;
300 + compressed = SQUASHFS_COMPRESSED(c_byte);
301 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
303 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
304 + ? "" : "un", (unsigned int) c_byte);
306 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
309 + for (b = 1; bytes < c_byte; b++) {
310 + bh[b] = sb_getblk(s, ++cur_index);
312 + goto block_release;
313 + bytes += msblk->devblksize;
315 + ll_rw_block(READ, b - 1, bh + 1);
325 + mutex_lock(&msblk->read_data_mutex);
327 + msblk->stream.next_out = buffer;
328 + msblk->stream.avail_out = srclength;
330 + for (bytes = 0; k < b; k++) {
331 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
333 + wait_on_buffer(bh[k]);
334 + if (!buffer_uptodate(bh[k]))
335 + goto release_mutex;
337 + msblk->stream.next_in = bh[k]->b_data + offset;
338 + msblk->stream.avail_in = avail_bytes;
341 + zlib_err = zlib_inflateInit(&msblk->stream);
342 + if (zlib_err != Z_OK) {
343 + ERROR("zlib_inflateInit returned unexpected result 0x%x,"
344 + " srclength %d\n", zlib_err, srclength);
345 + goto release_mutex;
348 + if (avail_bytes == 0) {
355 + zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
356 + if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
357 + ERROR("zlib_inflate returned unexpected result 0x%x,"
358 + " srclength %d, avail_in %d, avail_out %d\n", zlib_err,
359 + srclength, msblk->stream.avail_in, msblk->stream.avail_out);
360 + goto release_mutex;
363 + bytes += avail_bytes;
368 + if (zlib_err != Z_STREAM_END)
369 + goto release_mutex;
371 + zlib_err = zlib_inflateEnd(&msblk->stream);
372 + if (zlib_err != Z_OK) {
373 + ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
374 + " srclength %d\n", zlib_err, srclength);
375 + goto release_mutex;
377 + bytes = msblk->stream.total_out;
378 + mutex_unlock(&msblk->read_data_mutex);
382 + for(i = 0; i < b; i++) {
383 + wait_on_buffer(bh[i]);
384 + if (!buffer_uptodate(bh[i]))
385 + goto block_release;
388 + for (bytes = 0; k < b; k++) {
389 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
391 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
392 + bytes += avail_bytes;
399 + *next_index = index + c_byte + (length ? 0 :
400 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));
406 + mutex_unlock(&msblk->read_data_mutex);
413 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
419 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,
420 + long long block, unsigned int offset,
421 + int length, long long *next_block,
422 + unsigned int *next_offset)
424 + struct squashfs_sb_info *msblk = s->s_fs_info;
425 + int n, i, bytes, return_length = length;
426 + long long next_index;
428 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
431 + for (i = 0; i < squashfs_cached_blks; i++)
432 + if (msblk->block_cache[i].block == block)
435 + mutex_lock(&msblk->block_cache_mutex);
437 + if (i == squashfs_cached_blks) {
438 + /* read inode header block */
439 + if (msblk->unused_cache_blks == 0) {
440 + mutex_unlock(&msblk->block_cache_mutex);
441 + wait_event(msblk->waitq, msblk->unused_cache_blks);
445 + i = msblk->next_cache;
446 + for (n = 0; n < squashfs_cached_blks; n++) {
447 + if (msblk->block_cache[i].block != SQUASHFS_USED_BLK)
449 + i = (i + 1) % squashfs_cached_blks;
452 + msblk->next_cache = (i + 1) % squashfs_cached_blks;
454 + if (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
455 + msblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);
456 + if (msblk->block_cache[i].data == NULL) {
457 + ERROR("Failed to allocate cache block\n");
458 + mutex_unlock(&msblk->block_cache_mutex);
463 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
464 + msblk->unused_cache_blks --;
465 + mutex_unlock(&msblk->block_cache_mutex);
467 + msblk->block_cache[i].length = squashfs_read_data(s,
468 + msblk->block_cache[i].data, block, 0, &next_index,
469 + SQUASHFS_METADATA_SIZE);
471 + if (msblk->block_cache[i].length == 0) {
472 + ERROR("Unable to read cache block [%llx:%x]\n", block, offset);
473 + mutex_lock(&msblk->block_cache_mutex);
474 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
475 + msblk->unused_cache_blks ++;
477 + vfree(msblk->block_cache[i].data);
478 + wake_up(&msblk->waitq);
479 + mutex_unlock(&msblk->block_cache_mutex);
483 + mutex_lock(&msblk->block_cache_mutex);
484 + msblk->block_cache[i].block = block;
485 + msblk->block_cache[i].next_index = next_index;
486 + msblk->unused_cache_blks ++;
488 + wake_up(&msblk->waitq);
489 + TRACE("Read cache block [%llx:%x]\n", block, offset);
492 + if (msblk->block_cache[i].block != block) {
493 + mutex_unlock(&msblk->block_cache_mutex);
497 + bytes = msblk->block_cache[i].length - offset;
500 + mutex_unlock(&msblk->block_cache_mutex);
502 + } else if (bytes >= length) {
504 + memcpy(buffer, msblk->block_cache[i].data + offset, length);
505 + if (msblk->block_cache[i].length - offset == length) {
506 + *next_block = msblk->block_cache[i].next_index;
509 + *next_block = block;
510 + *next_offset = offset + length;
512 + mutex_unlock(&msblk->block_cache_mutex);
516 + memcpy(buffer, msblk->block_cache[i].data + offset, bytes);
517 + buffer = (char *) buffer + bytes;
519 + block = msblk->block_cache[i].next_index;
520 + mutex_unlock(&msblk->block_cache_mutex);
527 + return return_length;
533 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
534 + long long *fragment_start_block,
535 + unsigned int *fragment_size)
537 + struct squashfs_sb_info *msblk = s->s_fs_info;
538 + long long start_block =
539 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
540 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
541 + struct squashfs_fragment_entry fragment_entry;
544 + struct squashfs_fragment_entry sfragment_entry;
546 + if (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,
547 + sizeof(sfragment_entry), &start_block, &offset))
549 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
551 + if (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,
552 + sizeof(fragment_entry), &start_block, &offset))
555 + *fragment_start_block = fragment_entry.start_block;
556 + *fragment_size = fragment_entry.size;
565 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,
566 + struct squashfs_fragment_cache *fragment)
568 + mutex_lock(&msblk->fragment_mutex);
569 + fragment->locked --;
570 + if (fragment->locked == 0) {
571 + msblk->unused_frag_blks ++;
573 + wake_up(&msblk->fragment_wait_queue);
575 + mutex_unlock(&msblk->fragment_mutex);
580 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,
581 + long long start_block, int length)
584 + struct squashfs_sb_info *msblk = s->s_fs_info;
585 + struct squashfs_super_block *sblk = &msblk->sblk;
588 + mutex_lock(&msblk->fragment_mutex);
590 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
591 + msblk->fragment[i].block != start_block; i++);
593 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
594 + if (msblk->unused_frag_blks == 0) {
595 + mutex_unlock(&msblk->fragment_mutex);
596 + wait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);
600 + i = msblk->next_fragment;
601 + for (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {
602 + if (msblk->fragment[i].locked == 0)
604 + i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;
607 + msblk->next_fragment = (msblk->next_fragment + 1) %
608 + SQUASHFS_CACHED_FRAGMENTS;
610 + if (msblk->fragment[i].data == NULL) {
611 + msblk->fragment[i].data = vmalloc(sblk->block_size);
612 + if (msblk->fragment[i].data == NULL) {
613 + ERROR("Failed to allocate fragment cache block\n");
614 + mutex_unlock(&msblk->fragment_mutex);
619 + msblk->unused_frag_blks --;
620 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
621 + msblk->fragment[i].locked = 1;
622 + mutex_unlock(&msblk->fragment_mutex);
624 + msblk->fragment[i].length = squashfs_read_data(s,
625 + msblk->fragment[i].data, start_block, length, NULL,
628 + if (msblk->fragment[i].length == 0) {
629 + ERROR("Unable to read fragment cache block [%llx]\n", start_block);
630 + msblk->fragment[i].locked = 0;
631 + msblk->unused_frag_blks ++;
633 + wake_up(&msblk->fragment_wait_queue);
637 + mutex_lock(&msblk->fragment_mutex);
638 + msblk->fragment[i].block = start_block;
639 + TRACE("New fragment %d, start block %lld, locked %d\n",
640 + i, msblk->fragment[i].block, msblk->fragment[i].locked);
641 + mutex_unlock(&msblk->fragment_mutex);
645 + if (msblk->fragment[i].locked == 0)
646 + msblk->unused_frag_blks --;
647 + msblk->fragment[i].locked++;
648 + mutex_unlock(&msblk->fragment_mutex);
649 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
650 + msblk->fragment[i].block, msblk->fragment[i].locked);
654 + return &msblk->fragment[i];
661 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
662 + struct squashfs_base_inode_header *inodeb)
664 + i->i_ino = inodeb->inode_number;
665 + i->i_mtime.tv_sec = inodeb->mtime;
666 + i->i_atime.tv_sec = inodeb->mtime;
667 + i->i_ctime.tv_sec = inodeb->mtime;
668 + i->i_uid = msblk->uid[inodeb->uid];
669 + i->i_mode = inodeb->mode;
672 + if (inodeb->guid == SQUASHFS_GUIDS)
673 + i->i_gid = i->i_uid;
675 + i->i_gid = msblk->guid[inodeb->guid];
679 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
681 + struct squashfs_sb_info *msblk = s->s_fs_info;
682 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
683 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
684 + squashfs_inode_t inode;
686 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
689 + squashfs_inode_t sinode;
691 + if (!squashfs_get_cached_block(s, &sinode, start, offset,
692 + sizeof(sinode), &start, &offset))
694 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
695 + } else if (!squashfs_get_cached_block(s, &inode, start, offset,
696 + sizeof(inode), &start, &offset))
699 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
704 + return SQUASHFS_INVALID_BLK;
707 +static struct dentry *squashfs_get_parent(struct dentry *child)
709 + struct inode *i = child->d_inode;
710 + unsigned long ino = SQUASHFS_I(i)->u.s2.parent_inode;
711 + squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, ino);
712 + struct inode *parent;
715 + TRACE("Entered squashfs_get_parent\n");
717 + if (inode == SQUASHFS_INVALID_BLK)
718 + return ERR_PTR(-EINVAL);
720 + parent = squashfs_iget(i->i_sb, inode, ino);
721 + if (IS_ERR(parent)) {
722 + rv = ERR_PTR(-EACCES);
726 + rv = d_alloc_anon(parent);
728 + rv = ERR_PTR(-ENOMEM);
735 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,
736 + squashfs_inode_t inode, unsigned int inode_number)
738 + struct squashfs_sb_info *msblk = s->s_fs_info;
739 + struct inode *i = iget_locked(s, inode_number);
741 + TRACE("Entered squashfs_iget\n");
743 + return ERR_PTR(-ENOMEM);
745 + if (i->i_state & I_NEW) {
746 + (msblk->read_inode)(i, inode);
747 + unlock_new_inode(i);
754 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
756 + struct super_block *s = i->i_sb;
757 + struct squashfs_sb_info *msblk = s->s_fs_info;
758 + struct squashfs_super_block *sblk = &msblk->sblk;
759 + long long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;
760 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
761 + long long next_block;
762 + unsigned int next_offset;
763 + union squashfs_inode_header id, sid;
764 + struct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;
766 + TRACE("Entered squashfs_read_inode\n");
769 + if (!squashfs_get_cached_block(s, sinodeb, block, offset,
770 + sizeof(*sinodeb), &next_block, &next_offset))
772 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));
774 + if (!squashfs_get_cached_block(s, inodeb, block, offset,
775 + sizeof(*inodeb), &next_block, &next_offset))
778 + squashfs_new_inode(msblk, i, inodeb);
780 + switch(inodeb->inode_type) {
781 + case SQUASHFS_FILE_TYPE: {
782 + unsigned int frag_size;
783 + long long frag_blk;
784 + struct squashfs_reg_inode_header *inodep = &id.reg;
785 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
788 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
789 + sizeof(*sinodep), &next_block, &next_offset))
791 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
793 + if (!squashfs_get_cached_block(s, inodep, block, offset,
794 + sizeof(*inodep), &next_block, &next_offset))
797 + frag_blk = SQUASHFS_INVALID_BLK;
799 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
800 + if(!get_fragment_location(s, inodep->fragment, &frag_blk,
805 + i->i_size = inodep->file_size;
806 + i->i_fop = &generic_ro_fops;
807 + i->i_mode |= S_IFREG;
808 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
809 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
810 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
811 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
812 + SQUASHFS_I(i)->start_block = inodep->start_block;
813 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
814 + SQUASHFS_I(i)->offset = next_offset;
815 + i->i_data.a_ops = &squashfs_aops;
817 + TRACE("File inode %x:%x, start_block %llx, "
818 + "block_list_start %llx, offset %x\n",
819 + SQUASHFS_INODE_BLK(inode), offset,
820 + inodep->start_block, next_block,
824 + case SQUASHFS_LREG_TYPE: {
825 + unsigned int frag_size;
826 + long long frag_blk;
827 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
828 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
831 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
832 + sizeof(*sinodep), &next_block, &next_offset))
834 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
836 + if (!squashfs_get_cached_block(s, inodep, block, offset,
837 + sizeof(*inodep), &next_block, &next_offset))
840 + frag_blk = SQUASHFS_INVALID_BLK;
842 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
843 + if (!get_fragment_location(s, inodep->fragment, &frag_blk,
847 + i->i_nlink = inodep->nlink;
848 + i->i_size = inodep->file_size;
849 + i->i_fop = &generic_ro_fops;
850 + i->i_mode |= S_IFREG;
851 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
852 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
853 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
854 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
855 + SQUASHFS_I(i)->start_block = inodep->start_block;
856 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
857 + SQUASHFS_I(i)->offset = next_offset;
858 + i->i_data.a_ops = &squashfs_aops;
860 + TRACE("File inode %x:%x, start_block %llx, "
861 + "block_list_start %llx, offset %x\n",
862 + SQUASHFS_INODE_BLK(inode), offset,
863 + inodep->start_block, next_block,
867 + case SQUASHFS_DIR_TYPE: {
868 + struct squashfs_dir_inode_header *inodep = &id.dir;
869 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
872 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
873 + sizeof(*sinodep), &next_block, &next_offset))
875 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
877 + if (!squashfs_get_cached_block(s, inodep, block, offset,
878 + sizeof(*inodep), &next_block, &next_offset))
881 + i->i_nlink = inodep->nlink;
882 + i->i_size = inodep->file_size;
883 + i->i_op = &squashfs_dir_inode_ops;
884 + i->i_fop = &squashfs_dir_ops;
885 + i->i_mode |= S_IFDIR;
886 + SQUASHFS_I(i)->start_block = inodep->start_block;
887 + SQUASHFS_I(i)->offset = inodep->offset;
888 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
889 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
891 + TRACE("Directory inode %x:%x, start_block %x, offset "
892 + "%x\n", SQUASHFS_INODE_BLK(inode),
893 + offset, inodep->start_block,
897 + case SQUASHFS_LDIR_TYPE: {
898 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
899 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
902 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
903 + sizeof(*sinodep), &next_block, &next_offset))
905 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);
907 + if (!squashfs_get_cached_block(s, inodep, block, offset,
908 + sizeof(*inodep), &next_block, &next_offset))
911 + i->i_nlink = inodep->nlink;
912 + i->i_size = inodep->file_size;
913 + i->i_op = &squashfs_dir_inode_ops;
914 + i->i_fop = &squashfs_dir_ops;
915 + i->i_mode |= S_IFDIR;
916 + SQUASHFS_I(i)->start_block = inodep->start_block;
917 + SQUASHFS_I(i)->offset = inodep->offset;
918 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
919 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
920 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;
921 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
923 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n",
924 + SQUASHFS_INODE_BLK(inode), offset,
925 + inodep->start_block, inodep->offset);
928 + case SQUASHFS_SYMLINK_TYPE: {
929 + struct squashfs_symlink_inode_header *inodep = &id.symlink;
930 + struct squashfs_symlink_inode_header *sinodep = &sid.symlink;
933 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
934 + sizeof(*sinodep), &next_block, &next_offset))
936 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);
938 + if (!squashfs_get_cached_block(s, inodep, block, offset,
939 + sizeof(*inodep), &next_block, &next_offset))
942 + i->i_nlink = inodep->nlink;
943 + i->i_size = inodep->symlink_size;
944 + i->i_op = &page_symlink_inode_operations;
945 + i->i_data.a_ops = &squashfs_symlink_aops;
946 + i->i_mode |= S_IFLNK;
947 + SQUASHFS_I(i)->start_block = next_block;
948 + SQUASHFS_I(i)->offset = next_offset;
950 + TRACE("Symbolic link inode %x:%x, start_block %llx, offset %x\n",
951 + SQUASHFS_INODE_BLK(inode), offset,
952 + next_block, next_offset);
955 + case SQUASHFS_BLKDEV_TYPE:
956 + case SQUASHFS_CHRDEV_TYPE: {
957 + struct squashfs_dev_inode_header *inodep = &id.dev;
958 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
961 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
962 + sizeof(*sinodep), &next_block, &next_offset))
964 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
966 + if (!squashfs_get_cached_block(s, inodep, block, offset,
967 + sizeof(*inodep), &next_block, &next_offset))
970 + i->i_nlink = inodep->nlink;
971 + i->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?
973 + init_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));
975 + TRACE("Device inode %x:%x, rdev %x\n",
976 + SQUASHFS_INODE_BLK(inode), offset, inodep->rdev);
979 + case SQUASHFS_FIFO_TYPE:
980 + case SQUASHFS_SOCKET_TYPE: {
981 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
982 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
985 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
986 + sizeof(*sinodep), &next_block, &next_offset))
988 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
990 + if (!squashfs_get_cached_block(s, inodep, block, offset,
991 + sizeof(*inodep), &next_block, &next_offset))
994 + i->i_nlink = inodep->nlink;
995 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
996 + ? S_IFIFO : S_IFSOCK;
997 + init_special_inode(i, i->i_mode, 0);
1001 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1002 + inodeb->inode_type);
1003 + goto failed_read1;
1009 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1012 + make_bad_inode(i);
1017 +static int read_inode_lookup_table(struct super_block *s)
1019 + struct squashfs_sb_info *msblk = s->s_fs_info;
1020 + struct squashfs_super_block *sblk = &msblk->sblk;
1021 + unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1023 + TRACE("In read_inode_lookup_table, length %d\n", length);
1025 + /* Allocate inode lookup table */
1026 + msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);
1027 + if (msblk->inode_lookup_table == NULL) {
1028 + ERROR("Failed to allocate inode lookup table\n");
1032 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1033 + sblk->lookup_table_start, length |
1034 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1035 + ERROR("unable to read inode lookup table\n");
1039 + if (msblk->swap) {
1043 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1045 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1046 + &msblk->inode_lookup_table[i], 1);
1047 + msblk->inode_lookup_table[i] = block;
1055 +static int read_fragment_index_table(struct super_block *s)
1057 + struct squashfs_sb_info *msblk = s->s_fs_info;
1058 + struct squashfs_super_block *sblk = &msblk->sblk;
1059 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1064 + /* Allocate fragment index table */
1065 + msblk->fragment_index = kmalloc(length, GFP_KERNEL);
1066 + if (msblk->fragment_index == NULL) {
1067 + ERROR("Failed to allocate fragment index table\n");
1071 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1072 + sblk->fragment_table_start, length |
1073 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1074 + ERROR("unable to read fragment index table\n");
1078 + if (msblk->swap) {
1080 + long long fragment;
1082 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1084 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1085 + &msblk->fragment_index[i], 1);
1086 + msblk->fragment_index[i] = fragment;
1094 +static int readahead_metadata(struct super_block *s)
1096 + struct squashfs_sb_info *msblk = s->s_fs_info;
1099 + squashfs_cached_blks = SQUASHFS_CACHED_BLKS;
1101 + /* Init inode_table block pointer array */
1102 + msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1103 + squashfs_cached_blks, GFP_KERNEL);
1104 + if (msblk->block_cache == NULL) {
1105 + ERROR("Failed to allocate block cache\n");
1109 + for (i = 0; i < squashfs_cached_blks; i++)
1110 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1112 + msblk->next_cache = 0;
1113 + msblk->unused_cache_blks = squashfs_cached_blks;
1122 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1124 + struct squashfs_super_block *sblk = &msblk->sblk;
1126 + msblk->read_inode = squashfs_read_inode;
1127 + msblk->read_blocklist = read_blocklist;
1128 + msblk->read_fragment_index_table = read_fragment_index_table;
1130 + if (sblk->s_major == 1) {
1131 + if (!squashfs_1_0_supported(msblk)) {
1132 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1133 + "are unsupported\n");
1134 + SERROR("Please recompile with Squashfs 1.0 support enabled\n");
1137 + } else if (sblk->s_major == 2) {
1138 + if (!squashfs_2_0_supported(msblk)) {
1139 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1140 + "are unsupported\n");
1141 + SERROR("Please recompile with Squashfs 2.0 support enabled\n");
1144 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1146 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1147 + "filesystem\n", sblk->s_major, sblk->s_minor);
1148 + SERROR("Please update your kernel\n");
1156 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1158 + struct squashfs_sb_info *msblk;
1159 + struct squashfs_super_block *sblk;
1161 + char b[BDEVNAME_SIZE];
1162 + struct inode *root;
1164 + TRACE("Entered squashfs_fill_superblock\n");
1166 + s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1167 + if (s->s_fs_info == NULL) {
1168 + ERROR("Failed to allocate superblock\n");
1171 + msblk = s->s_fs_info;
1173 + msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1174 + if (msblk->stream.workspace == NULL) {
1175 + ERROR("Failed to allocate zlib workspace\n");
1178 + sblk = &msblk->sblk;
1180 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1181 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1183 + mutex_init(&msblk->read_data_mutex);
1184 + mutex_init(&msblk->read_page_mutex);
1185 + mutex_init(&msblk->block_cache_mutex);
1186 + mutex_init(&msblk->fragment_mutex);
1187 + mutex_init(&msblk->meta_index_mutex);
1189 + init_waitqueue_head(&msblk->waitq);
1190 + init_waitqueue_head(&msblk->fragment_wait_queue);
1192 + /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1193 + * beyond filesystem end. As we're using squashfs_read_data to read sblk here,
1194 + * first set sblk->bytes_used to a useful value */
1195 + sblk->bytes_used = sizeof(struct squashfs_super_block);
1196 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1197 + sizeof(struct squashfs_super_block) |
1198 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1199 + SERROR("unable to read superblock\n");
1200 + goto failed_mount;
1203 + /* Check it is a SQUASHFS superblock */
1204 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1205 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1206 + struct squashfs_super_block ssblk;
1208 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1209 + bdevname(s->s_bdev, b));
1211 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1212 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1215 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1216 + bdevname(s->s_bdev, b));
1217 + goto failed_mount;
1221 + /* Check the MAJOR & MINOR versions */
1222 + if(!supported_squashfs_filesystem(msblk, silent))
1223 + goto failed_mount;
1225 + /* Check the filesystem does not extend beyond the end of the
1227 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1228 + goto failed_mount;
1230 + /* Check the root inode for sanity */
1231 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1232 + goto failed_mount;
1234 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1235 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)
1237 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1239 + TRACE("Check data is %spresent in the filesystem\n",
1240 + SQUASHFS_CHECK_DATA(sblk->flags) ? "" : "not ");
1241 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1242 + TRACE("Block size %d\n", sblk->block_size);
1243 + TRACE("Number of inodes %d\n", sblk->inodes);
1244 + if (sblk->s_major > 1)
1245 + TRACE("Number of fragments %d\n", sblk->fragments);
1246 + TRACE("Number of uids %d\n", sblk->no_uids);
1247 + TRACE("Number of gids %d\n", sblk->no_guids);
1248 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1249 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1250 + if (sblk->s_major > 1)
1251 + TRACE("sblk->fragment_table_start %llx\n", sblk->fragment_table_start);
1252 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1254 + s->s_maxbytes = MAX_LFS_FILESIZE;
1255 + s->s_flags |= MS_RDONLY;
1256 + s->s_op = &squashfs_super_ops;
1258 + if (readahead_metadata(s) == 0)
1259 + goto failed_mount;
1261 + /* Allocate read_page block */
1262 + msblk->read_page = vmalloc(sblk->block_size);
1263 + if (msblk->read_page == NULL) {
1264 + ERROR("Failed to allocate read_page block\n");
1265 + goto failed_mount;
1268 + /* Allocate uid and gid tables */
1269 + msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1270 + sizeof(unsigned int), GFP_KERNEL);
1271 + if (msblk->uid == NULL) {
1272 + ERROR("Failed to allocate uid/gid table\n");
1273 + goto failed_mount;
1275 + msblk->guid = msblk->uid + sblk->no_uids;
1277 + if (msblk->swap) {
1278 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1280 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1281 + ((sblk->no_uids + sblk->no_guids) *
1282 + sizeof(unsigned int)) |
1283 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1284 + ERROR("unable to read uid/gid table\n");
1285 + goto failed_mount;
1288 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1289 + sblk->no_guids), (sizeof(unsigned int) * 8));
1291 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1292 + ((sblk->no_uids + sblk->no_guids) *
1293 + sizeof(unsigned int)) |
1294 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1295 + ERROR("unable to read uid/gid table\n");
1296 + goto failed_mount;
1300 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1301 + goto allocate_root;
1303 + msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *
1304 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);
1305 + if (msblk->fragment == NULL) {
1306 + ERROR("Failed to allocate fragment block cache\n");
1307 + goto failed_mount;
1310 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1311 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1314 + msblk->next_fragment = 0;
1315 + msblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;
1317 + /* Allocate and read fragment index table */
1318 + if (msblk->read_fragment_index_table(s) == 0)
1319 + goto failed_mount;
1321 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1322 + goto allocate_root;
1324 + /* Allocate and read inode lookup table */
1325 + if (read_inode_lookup_table(s) == 0)
1326 + goto failed_mount;
1328 + s->s_op = &squashfs_export_super_ops;
1329 + s->s_export_op = &squashfs_export_ops;
1332 + root = new_inode(s);
1333 + if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1334 + goto failed_mount;
1335 + insert_inode_hash(root);
1337 + s->s_root = d_alloc_root(root);
1338 + if (s->s_root == NULL) {
1339 + ERROR("Root inode create failed\n");
1341 + goto failed_mount;
1344 + TRACE("Leaving squashfs_fill_super\n");
1348 + kfree(msblk->inode_lookup_table);
1349 + kfree(msblk->fragment_index);
1350 + kfree(msblk->fragment);
1351 + kfree(msblk->uid);
1352 + vfree(msblk->read_page);
1353 + kfree(msblk->block_cache);
1354 + kfree(msblk->fragment_index_2);
1355 + vfree(msblk->stream.workspace);
1356 + kfree(s->s_fs_info);
1357 + s->s_fs_info = NULL;
1365 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1367 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1368 + struct squashfs_super_block *sblk = &msblk->sblk;
1370 + TRACE("Entered squashfs_statfs\n");
1372 + buf->f_type = SQUASHFS_MAGIC;
1373 + buf->f_bsize = sblk->block_size;
1374 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1375 + buf->f_bfree = buf->f_bavail = 0;
1376 + buf->f_files = sblk->inodes;
1378 + buf->f_namelen = SQUASHFS_NAME_LEN;
1384 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1386 + struct inode *inode = page->mapping->host;
1387 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;
1388 + long long block = SQUASHFS_I(inode)->start_block;
1389 + int offset = SQUASHFS_I(inode)->offset;
1390 + void *pageaddr = kmap(page);
1392 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1393 + "%llx, offset %x\n", page->index,
1394 + SQUASHFS_I(inode)->start_block,
1395 + SQUASHFS_I(inode)->offset);
1397 + for (length = 0; length < index; length += bytes) {
1398 + bytes = squashfs_get_cached_block(inode->i_sb, NULL, block,
1399 + offset, PAGE_CACHE_SIZE, &block, &offset);
1401 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1406 + if (length != index) {
1407 + ERROR("(squashfs_symlink_readpage) length != index\n");
1412 + avail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);
1414 + bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,
1415 + avail_bytes, &block, &offset);
1417 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1420 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1422 + flush_dcache_page(page);
1423 + SetPageUptodate(page);
1424 + unlock_page(page);
1430 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1432 + struct meta_index *meta = NULL;
1433 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1436 + mutex_lock(&msblk->meta_index_mutex);
1438 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1440 + if (msblk->meta_index == NULL)
1441 + goto not_allocated;
1443 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++) {
1444 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1445 + msblk->meta_index[i].offset >= offset &&
1446 + msblk->meta_index[i].offset <= index &&
1447 + msblk->meta_index[i].locked == 0) {
1448 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1449 + msblk->meta_index[i].offset);
1450 + meta = &msblk->meta_index[i];
1451 + offset = meta->offset;
1459 + mutex_unlock(&msblk->meta_index_mutex);
1465 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1467 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1468 + struct meta_index *meta = NULL;
1471 + mutex_lock(&msblk->meta_index_mutex);
1473 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1475 + if (msblk->meta_index == NULL) {
1476 + msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1477 + SQUASHFS_META_NUMBER, GFP_KERNEL);
1478 + if (msblk->meta_index == NULL) {
1479 + ERROR("Failed to allocate meta_index\n");
1482 + for (i = 0; i < SQUASHFS_META_NUMBER; i++) {
1483 + msblk->meta_index[i].inode_number = 0;
1484 + msblk->meta_index[i].locked = 0;
1486 + msblk->next_meta_index = 0;
1489 + for (i = SQUASHFS_META_NUMBER; i &&
1490 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1491 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1492 + SQUASHFS_META_NUMBER;
1495 + TRACE("empty_meta_index: failed!\n");
1499 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1500 + msblk->next_meta_index,
1501 + &msblk->meta_index[msblk->next_meta_index]);
1503 + meta = &msblk->meta_index[msblk->next_meta_index];
1504 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1505 + SQUASHFS_META_NUMBER;
1507 + meta->inode_number = inode->i_ino;
1508 + meta->offset = offset;
1509 + meta->skip = skip;
1510 + meta->entries = 0;
1514 + mutex_unlock(&msblk->meta_index_mutex);
1519 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1526 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1527 + long long *start_block, int *offset)
1529 + struct squashfs_sb_info *msblk = s->s_fs_info;
1530 + unsigned int *block_listp;
1533 + if (msblk->swap) {
1534 + char sblock_list[blocks << 2];
1536 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1537 + *offset, blocks << 2, start_block, offset)) {
1538 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1541 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1542 + ((unsigned int *)sblock_list), blocks);
1544 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1545 + *offset, blocks << 2, start_block, offset)) {
1546 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1551 + for (block_listp = (unsigned int *) block_list; blocks;
1552 + block_listp++, blocks --)
1553 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1564 +static inline int calculate_skip(int blocks) {
1565 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1566 + return skip >= 7 ? 7 : skip + 1;
1570 +static int get_meta_index(struct inode *inode, int index,
1571 + long long *index_block, int *index_offset,
1572 + long long *data_block, char *block_list)
1574 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1575 + struct squashfs_super_block *sblk = &msblk->sblk;
1576 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1578 + struct meta_index *meta;
1579 + struct meta_entry *meta_entry;
1580 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1581 + int cur_offset = SQUASHFS_I(inode)->offset;
1582 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1585 + index /= SQUASHFS_META_INDEXES * skip;
1587 + while (offset < index) {
1588 + meta = locate_meta_index(inode, index, offset + 1);
1590 + if (meta == NULL) {
1591 + meta = empty_meta_index(inode, offset + 1, skip);
1595 + if(meta->entries == 0)
1598 + offset = index < meta->offset + meta->entries ? index :
1599 + meta->offset + meta->entries - 1;
1601 + meta_entry = &meta->meta_entry[offset - meta->offset];
1602 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1603 + cur_offset = meta_entry->offset;
1604 + cur_data_block = meta_entry->data_block;
1605 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1606 + "meta->entries %d\n", offset, meta->offset, meta->entries);
1607 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1608 + " data_block 0x%llx\n", cur_index_block,
1609 + cur_offset, cur_data_block);
1612 + for (i = meta->offset + meta->entries; i <= index &&
1613 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1614 + int blocks = skip * SQUASHFS_META_INDEXES;
1617 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;
1618 + int res = read_block_index(inode->i_sb, block, block_list,
1619 + &cur_index_block, &cur_offset);
1624 + cur_data_block += res;
1628 + meta_entry = &meta->meta_entry[i - meta->offset];
1629 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1630 + meta_entry->offset = cur_offset;
1631 + meta_entry->data_block = cur_data_block;
1636 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1637 + meta->offset, meta->entries);
1639 + release_meta_index(inode, meta);
1643 + *index_block = cur_index_block;
1644 + *index_offset = cur_offset;
1645 + *data_block = cur_data_block;
1647 + return offset * SQUASHFS_META_INDEXES * skip;
1650 + release_meta_index(inode, meta);
1655 +static long long read_blocklist(struct inode *inode, int index,
1656 + int readahead_blks, char *block_list,
1657 + unsigned short **block_p, unsigned int *bsize)
1659 + long long block_ptr;
1662 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1665 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1666 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset, block);
1674 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1675 + int res = read_block_index(inode->i_sb, blocks, block_list,
1676 + &block_ptr, &offset);
1683 + if (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)
1685 + *bsize = *((unsigned int *) block_list);
1694 +static int squashfs_readpage(struct file *file, struct page *page)
1696 + struct inode *inode = page->mapping->host;
1697 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1698 + struct squashfs_super_block *sblk = &msblk->sblk;
1699 + unsigned char *block_list = NULL;
1701 + unsigned int bsize, i;
1703 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1705 + struct squashfs_fragment_cache *fragment = NULL;
1706 + char *data_ptr = msblk->read_page;
1708 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1709 + int start_index = page->index & ~mask;
1710 + int end_index = start_index | mask;
1711 + int file_end = i_size_read(inode) >> sblk->block_log;
1714 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1715 + page->index, SQUASHFS_I(inode)->start_block);
1717 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1718 + PAGE_CACHE_SHIFT))
1721 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1722 + || index < file_end) {
1723 + block_list = kmalloc(SIZE, GFP_KERNEL);
1724 + if (block_list == NULL) {
1725 + ERROR("Failed to allocate block_list\n");
1729 + block = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);
1733 + if (bsize == 0) { /* hole */
1734 + bytes = index == file_end ?
1735 + (i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;
1738 + mutex_lock(&msblk->read_page_mutex);
1740 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1741 + bsize, NULL, sblk->block_size);
1744 + ERROR("Unable to read page, block %llx, size %x\n", block, bsize);
1745 + mutex_unlock(&msblk->read_page_mutex);
1750 + fragment = get_cached_fragment(inode->i_sb,
1751 + SQUASHFS_I(inode)-> u.s1.fragment_start_block,
1752 + SQUASHFS_I(inode)->u.s1.fragment_size);
1754 + if (fragment == NULL) {
1755 + ERROR("Unable to read page, block %llx, size %x\n",
1756 + SQUASHFS_I(inode)->u.s1.fragment_start_block,
1757 + (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1760 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1761 + data_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;
1764 + for (i = start_index; i <= end_index && bytes > 0; i++,
1765 + bytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {
1766 + struct page *push_page;
1767 + int avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);
1769 + TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
1771 + push_page = (i == page->index) ? page :
1772 + grab_cache_page_nowait(page->mapping, i);
1777 + if (PageUptodate(push_page))
1780 + pageaddr = kmap_atomic(push_page, KM_USER0);
1781 + memcpy(pageaddr, data_ptr, avail);
1782 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1783 + kunmap_atomic(pageaddr, KM_USER0);
1784 + flush_dcache_page(push_page);
1785 + SetPageUptodate(push_page);
1787 + unlock_page(push_page);
1788 + if(i != page->index)
1789 + page_cache_release(push_page);
1792 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1793 + || index < file_end) {
1795 + mutex_unlock(&msblk->read_page_mutex);
1796 + kfree(block_list);
1798 + release_cached_fragment(msblk, fragment);
1803 + SetPageError(page);
1805 + pageaddr = kmap_atomic(page, KM_USER0);
1806 + memset(pageaddr, 0, PAGE_CACHE_SIZE);
1807 + kunmap_atomic(pageaddr, KM_USER0);
1808 + flush_dcache_page(page);
1809 + if (!PageError(page))
1810 + SetPageUptodate(page);
1811 + unlock_page(page);
1813 + kfree(block_list);
1818 +static int get_dir_index_using_offset(struct super_block *s,
1819 + long long *next_block, unsigned int *next_offset,
1820 + long long index_start, unsigned int index_offset, int i_count,
1823 + struct squashfs_sb_info *msblk = s->s_fs_info;
1824 + struct squashfs_super_block *sblk = &msblk->sblk;
1825 + int i, length = 0;
1826 + struct squashfs_dir_index index;
1828 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1829 + i_count, (unsigned int) f_pos);
1835 + for (i = 0; i < i_count; i++) {
1836 + if (msblk->swap) {
1837 + struct squashfs_dir_index sindex;
1838 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1839 + sizeof(sindex), &index_start, &index_offset);
1840 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1842 + squashfs_get_cached_block(s, &index, index_start, index_offset,
1843 + sizeof(index), &index_start, &index_offset);
1845 + if (index.index > f_pos)
1848 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1849 + index.size + 1, &index_start, &index_offset);
1851 + length = index.index;
1852 + *next_block = index.start_block + sblk->directory_table_start;
1855 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1858 + return length + 3;
1862 +static int get_dir_index_using_name(struct super_block *s,
1863 + long long *next_block, unsigned int *next_offset,
1864 + long long index_start, unsigned int index_offset, int i_count,
1865 + const char *name, int size)
1867 + struct squashfs_sb_info *msblk = s->s_fs_info;
1868 + struct squashfs_super_block *sblk = &msblk->sblk;
1869 + int i, length = 0;
1870 + struct squashfs_dir_index *index;
1873 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1875 + str = kmalloc(sizeof(struct squashfs_dir_index) +
1876 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);
1877 + if (str == NULL) {
1878 + ERROR("Failed to allocate squashfs_dir_index\n");
1882 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1883 + strncpy(str, name, size);
1886 + for (i = 0; i < i_count; i++) {
1887 + if (msblk->swap) {
1888 + struct squashfs_dir_index sindex;
1889 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1890 + sizeof(sindex), &index_start, &index_offset);
1891 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1893 + squashfs_get_cached_block(s, index, index_start, index_offset,
1894 + sizeof(struct squashfs_dir_index), &index_start, &index_offset);
1896 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1897 + index->size + 1, &index_start, &index_offset);
1899 + index->name[index->size + 1] = '\0';
1901 + if (strcmp(index->name, str) > 0)
1904 + length = index->index;
1905 + *next_block = index->start_block + sblk->directory_table_start;
1908 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1912 + return length + 3;
1916 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1918 + struct inode *i = file->f_dentry->d_inode;
1919 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1920 + struct squashfs_super_block *sblk = &msblk->sblk;
1921 + long long next_block = SQUASHFS_I(i)->start_block +
1922 + sblk->directory_table_start;
1923 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
1924 + struct squashfs_dir_header dirh;
1925 + struct squashfs_dir_entry *dire;
1927 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1929 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1930 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
1931 + if (dire == NULL) {
1932 + ERROR("Failed to allocate squashfs_dir_entry\n");
1936 + while(file->f_pos < 3) {
1940 + if(file->f_pos == 0) {
1947 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1949 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1950 + (unsigned int) dirent, name, size, (int)
1951 + file->f_pos, i_ino, squashfs_filetype_table[1]);
1953 + if (filldir(dirent, name, size, file->f_pos, i_ino,
1954 + squashfs_filetype_table[1]) < 0) {
1955 + TRACE("Filldir returned less than 0\n");
1958 + file->f_pos += size;
1961 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1962 + SQUASHFS_I(i)->u.s2.directory_index_start,
1963 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1964 + SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1966 + while (length < i_size_read(i)) {
1967 + /* read directory header */
1968 + if (msblk->swap) {
1969 + struct squashfs_dir_header sdirh;
1971 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
1972 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1975 + length += sizeof(sdirh);
1976 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1978 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
1979 + next_offset, sizeof(dirh), &next_block, &next_offset))
1982 + length += sizeof(dirh);
1985 + dir_count = dirh.count + 1;
1986 + while (dir_count--) {
1987 + if (msblk->swap) {
1988 + struct squashfs_dir_entry sdire;
1989 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
1990 + next_offset, sizeof(sdire), &next_block, &next_offset))
1993 + length += sizeof(sdire);
1994 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1996 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
1997 + next_offset, sizeof(*dire), &next_block, &next_offset))
2000 + length += sizeof(*dire);
2003 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2004 + next_offset, dire->size + 1, &next_block, &next_offset))
2007 + length += dire->size + 1;
2009 + if (file->f_pos >= length)
2012 + dire->name[dire->size + 1] = '\0';
2014 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2015 + (unsigned int) dirent, dire->name, dire->size + 1,
2016 + (int) file->f_pos, dirh.start_block, dire->offset,
2017 + dirh.inode_number + dire->inode_number,
2018 + squashfs_filetype_table[dire->type]);
2020 + if (filldir(dirent, dire->name, dire->size + 1, file->f_pos,
2021 + dirh.inode_number + dire->inode_number,
2022 + squashfs_filetype_table[dire->type]) < 0) {
2023 + TRACE("Filldir returned less than 0\n");
2026 + file->f_pos = length;
2035 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2042 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2043 + struct nameidata *nd)
2045 + const unsigned char *name = dentry->d_name.name;
2046 + int len = dentry->d_name.len;
2047 + struct inode *inode = NULL;
2048 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2049 + struct squashfs_super_block *sblk = &msblk->sblk;
2050 + long long next_block = SQUASHFS_I(i)->start_block +
2051 + sblk->directory_table_start;
2052 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
2053 + struct squashfs_dir_header dirh;
2054 + struct squashfs_dir_entry *dire;
2056 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2058 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2059 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
2060 + if (dire == NULL) {
2061 + ERROR("Failed to allocate squashfs_dir_entry\n");
2065 + if (len > SQUASHFS_NAME_LEN)
2068 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2069 + SQUASHFS_I(i)->u.s2.directory_index_start,
2070 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2071 + SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
2073 + while (length < i_size_read(i)) {
2074 + /* read directory header */
2075 + if (msblk->swap) {
2076 + struct squashfs_dir_header sdirh;
2077 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
2078 + next_offset, sizeof(sdirh), &next_block, &next_offset))
2081 + length += sizeof(sdirh);
2082 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2084 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2085 + next_offset, sizeof(dirh), &next_block, &next_offset))
2088 + length += sizeof(dirh);
2091 + dir_count = dirh.count + 1;
2092 + while (dir_count--) {
2093 + if (msblk->swap) {
2094 + struct squashfs_dir_entry sdire;
2095 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2096 + next_offset, sizeof(sdire), &next_block, &next_offset))
2099 + length += sizeof(sdire);
2100 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2102 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2103 + next_offset, sizeof(*dire), &next_block, &next_offset))
2106 + length += sizeof(*dire);
2109 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2110 + next_offset, dire->size + 1, &next_block, &next_offset))
2113 + length += dire->size + 1;
2115 + if (name[0] < dire->name[0])
2118 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2119 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2122 + TRACE("calling squashfs_iget for directory entry %s, inode"
2123 + " %x:%x, %d\n", name, dirh.start_block, dire->offset,
2124 + dirh.inode_number + dire->inode_number);
2126 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2136 + return d_splice_alias(inode, dentry);
2137 + d_add(dentry, inode);
2138 + return ERR_PTR(0);
2141 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2147 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
2149 + *flags |= MS_RDONLY;
2154 +static void squashfs_put_super(struct super_block *s)
2158 + if (s->s_fs_info) {
2159 + struct squashfs_sb_info *sbi = s->s_fs_info;
2160 + if (sbi->block_cache)
2161 + for (i = 0; i < squashfs_cached_blks; i++)
2162 + if (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)
2163 + vfree(sbi->block_cache[i].data);
2164 + if (sbi->fragment)
2165 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2166 + vfree(sbi->fragment[i].data);
2167 + kfree(sbi->fragment);
2168 + kfree(sbi->block_cache);
2169 + vfree(sbi->read_page);
2171 + kfree(sbi->fragment_index);
2172 + kfree(sbi->fragment_index_2);
2173 + kfree(sbi->meta_index);
2174 + vfree(sbi->stream.workspace);
2175 + kfree(s->s_fs_info);
2176 + s->s_fs_info = NULL;
2181 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2182 + const char *dev_name, void *data, struct vfsmount *mnt)
2184 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2189 +static int __init init_squashfs_fs(void)
2191 + int err = init_inodecache();
2195 + printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) "
2196 + "Phillip Lougher\n");
2198 + err = register_filesystem(&squashfs_fs_type);
2200 + destroy_inodecache();
2207 +static void __exit exit_squashfs_fs(void)
2209 + unregister_filesystem(&squashfs_fs_type);
2210 + destroy_inodecache();
2214 +static struct kmem_cache * squashfs_inode_cachep;
2217 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2219 + struct squashfs_inode_info *ei;
2220 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2221 + return ei ? &ei->vfs_inode : NULL;
2225 +static void squashfs_destroy_inode(struct inode *inode)
2227 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2231 +static void init_once(struct kmem_cache *cachep, void *foo)
2233 + struct squashfs_inode_info *ei = foo;
2235 + inode_init_once(&ei->vfs_inode);
2239 +static int __init init_inodecache(void)
2241 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2242 + sizeof(struct squashfs_inode_info), 0,
2243 + SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);
2244 + if (squashfs_inode_cachep == NULL)
2250 +static void destroy_inodecache(void)
2252 + kmem_cache_destroy(squashfs_inode_cachep);
2256 +module_init(init_squashfs_fs);
2257 +module_exit(exit_squashfs_fs);
2258 +MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem");
2259 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2260 +MODULE_LICENSE("GPL");
2261 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/Makefile linux-2.6.24-squashfs3.3/fs/squashfs/Makefile
2262 --- linux-2.6.24/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2263 +++ linux-2.6.24-squashfs3.3/fs/squashfs/Makefile 2005-11-20 14:31:00.000000000 +0000
2266 +# Makefile for the linux squashfs routines.
2269 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2270 +squashfs-y += inode.o
2271 +squashfs-y += squashfs2_0.o
2272 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs2_0.c linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c
2273 --- linux-2.6.24/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2274 +++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c 2007-10-25 00:43:59.000000000 +0100
2277 + * Squashfs - a compressed read only filesystem for Linux
2279 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
2280 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2282 + * This program is free software; you can redistribute it and/or
2283 + * modify it under the terms of the GNU General Public License
2284 + * as published by the Free Software Foundation; either version 2,
2285 + * or (at your option) any later version.
2287 + * This program is distributed in the hope that it will be useful,
2288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2290 + * GNU General Public License for more details.
2292 + * You should have received a copy of the GNU General Public License
2293 + * along with this program; if not, write to the Free Software
2294 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2299 +#include <linux/squashfs_fs.h>
2300 +#include <linux/module.h>
2301 +#include <linux/zlib.h>
2302 +#include <linux/fs.h>
2303 +#include <linux/squashfs_fs_sb.h>
2304 +#include <linux/squashfs_fs_i.h>
2306 +#include "squashfs.h"
2307 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2308 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2309 + struct nameidata *);
2311 +static struct file_operations squashfs_dir_ops_2 = {
2312 + .read = generic_read_dir,
2313 + .readdir = squashfs_readdir_2
2316 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2317 + .lookup = squashfs_lookup_2
2320 +static unsigned char squashfs_filetype_table[] = {
2321 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2324 +static int read_fragment_index_table_2(struct super_block *s)
2326 + struct squashfs_sb_info *msblk = s->s_fs_info;
2327 + struct squashfs_super_block *sblk = &msblk->sblk;
2329 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2330 + (sblk->fragments), GFP_KERNEL))) {
2331 + ERROR("Failed to allocate uid/gid table\n");
2335 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2336 + !squashfs_read_data(s, (char *)
2337 + msblk->fragment_index_2,
2338 + sblk->fragment_table_start,
2339 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2340 + (sblk->fragments) |
2341 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2342 + ERROR("unable to read fragment index table\n");
2346 + if (msblk->swap) {
2348 + unsigned int fragment;
2350 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2352 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2353 + &msblk->fragment_index_2[i], 1);
2354 + msblk->fragment_index_2[i] = fragment;
2362 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2363 + long long *fragment_start_block,
2364 + unsigned int *fragment_size)
2366 + struct squashfs_sb_info *msblk = s->s_fs_info;
2367 + long long start_block =
2368 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2369 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2370 + struct squashfs_fragment_entry_2 fragment_entry;
2372 + if (msblk->swap) {
2373 + struct squashfs_fragment_entry_2 sfragment_entry;
2375 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2376 + start_block, offset,
2377 + sizeof(sfragment_entry), &start_block,
2380 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2382 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2383 + start_block, offset,
2384 + sizeof(fragment_entry), &start_block,
2388 + *fragment_start_block = fragment_entry.start_block;
2389 + *fragment_size = fragment_entry.size;
2398 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2399 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2401 + struct squashfs_super_block *sblk = &msblk->sblk;
2404 + i->i_mtime.tv_sec = sblk->mkfs_time;
2405 + i->i_atime.tv_sec = sblk->mkfs_time;
2406 + i->i_ctime.tv_sec = sblk->mkfs_time;
2407 + i->i_uid = msblk->uid[inodeb->uid];
2408 + i->i_mode = inodeb->mode;
2411 + if (inodeb->guid == SQUASHFS_GUIDS)
2412 + i->i_gid = i->i_uid;
2414 + i->i_gid = msblk->guid[inodeb->guid];
2418 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2420 + struct super_block *s = i->i_sb;
2421 + struct squashfs_sb_info *msblk = s->s_fs_info;
2422 + struct squashfs_super_block *sblk = &msblk->sblk;
2423 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2424 + sblk->inode_table_start;
2425 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2426 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block -
2427 + sblk->inode_table_start, offset);
2428 + long long next_block;
2429 + unsigned int next_offset;
2430 + union squashfs_inode_header_2 id, sid;
2431 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2432 + *sinodeb = &sid.base;
2434 + TRACE("Entered squashfs_read_inode_2\n");
2436 + if (msblk->swap) {
2437 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2438 + offset, sizeof(*sinodeb), &next_block,
2441 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2442 + sizeof(*sinodeb));
2444 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2445 + offset, sizeof(*inodeb), &next_block,
2449 + squashfs_new_inode(msblk, i, inodeb, ino);
2451 + switch(inodeb->inode_type) {
2452 + case SQUASHFS_FILE_TYPE: {
2453 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2454 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2455 + long long frag_blk;
2456 + unsigned int frag_size = 0;
2458 + if (msblk->swap) {
2459 + if (!squashfs_get_cached_block(s, (char *)
2460 + sinodep, block, offset,
2461 + sizeof(*sinodep), &next_block,
2464 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2466 + if (!squashfs_get_cached_block(s, (char *)
2467 + inodep, block, offset,
2468 + sizeof(*inodep), &next_block,
2472 + frag_blk = SQUASHFS_INVALID_BLK;
2473 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2474 + !get_fragment_location_2(s,
2475 + inodep->fragment, &frag_blk, &frag_size))
2478 + i->i_size = inodep->file_size;
2479 + i->i_fop = &generic_ro_fops;
2480 + i->i_mode |= S_IFREG;
2481 + i->i_mtime.tv_sec = inodep->mtime;
2482 + i->i_atime.tv_sec = inodep->mtime;
2483 + i->i_ctime.tv_sec = inodep->mtime;
2484 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2485 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2486 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2487 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2488 + SQUASHFS_I(i)->start_block = inodep->start_block;
2489 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2490 + SQUASHFS_I(i)->offset = next_offset;
2491 + i->i_data.a_ops = &squashfs_aops;
2493 + TRACE("File inode %x:%x, start_block %x, "
2494 + "block_list_start %llx, offset %x\n",
2495 + SQUASHFS_INODE_BLK(inode), offset,
2496 + inodep->start_block, next_block,
2500 + case SQUASHFS_DIR_TYPE: {
2501 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2502 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2504 + if (msblk->swap) {
2505 + if (!squashfs_get_cached_block(s, (char *)
2506 + sinodep, block, offset,
2507 + sizeof(*sinodep), &next_block,
2510 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2512 + if (!squashfs_get_cached_block(s, (char *)
2513 + inodep, block, offset,
2514 + sizeof(*inodep), &next_block,
2518 + i->i_size = inodep->file_size;
2519 + i->i_op = &squashfs_dir_inode_ops_2;
2520 + i->i_fop = &squashfs_dir_ops_2;
2521 + i->i_mode |= S_IFDIR;
2522 + i->i_mtime.tv_sec = inodep->mtime;
2523 + i->i_atime.tv_sec = inodep->mtime;
2524 + i->i_ctime.tv_sec = inodep->mtime;
2525 + SQUASHFS_I(i)->start_block = inodep->start_block;
2526 + SQUASHFS_I(i)->offset = inodep->offset;
2527 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2528 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2530 + TRACE("Directory inode %x:%x, start_block %x, offset "
2531 + "%x\n", SQUASHFS_INODE_BLK(inode),
2532 + offset, inodep->start_block,
2536 + case SQUASHFS_LDIR_TYPE: {
2537 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2538 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2540 + if (msblk->swap) {
2541 + if (!squashfs_get_cached_block(s, (char *)
2542 + sinodep, block, offset,
2543 + sizeof(*sinodep), &next_block,
2546 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2549 + if (!squashfs_get_cached_block(s, (char *)
2550 + inodep, block, offset,
2551 + sizeof(*inodep), &next_block,
2555 + i->i_size = inodep->file_size;
2556 + i->i_op = &squashfs_dir_inode_ops_2;
2557 + i->i_fop = &squashfs_dir_ops_2;
2558 + i->i_mode |= S_IFDIR;
2559 + i->i_mtime.tv_sec = inodep->mtime;
2560 + i->i_atime.tv_sec = inodep->mtime;
2561 + i->i_ctime.tv_sec = inodep->mtime;
2562 + SQUASHFS_I(i)->start_block = inodep->start_block;
2563 + SQUASHFS_I(i)->offset = inodep->offset;
2564 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2565 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2567 + SQUASHFS_I(i)->u.s2.directory_index_count =
2569 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2571 + TRACE("Long directory inode %x:%x, start_block %x, "
2573 + SQUASHFS_INODE_BLK(inode), offset,
2574 + inodep->start_block, inodep->offset);
2577 + case SQUASHFS_SYMLINK_TYPE: {
2578 + struct squashfs_symlink_inode_header_2 *inodep =
2580 + struct squashfs_symlink_inode_header_2 *sinodep =
2583 + if (msblk->swap) {
2584 + if (!squashfs_get_cached_block(s, (char *)
2585 + sinodep, block, offset,
2586 + sizeof(*sinodep), &next_block,
2589 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2592 + if (!squashfs_get_cached_block(s, (char *)
2593 + inodep, block, offset,
2594 + sizeof(*inodep), &next_block,
2598 + i->i_size = inodep->symlink_size;
2599 + i->i_op = &page_symlink_inode_operations;
2600 + i->i_data.a_ops = &squashfs_symlink_aops;
2601 + i->i_mode |= S_IFLNK;
2602 + SQUASHFS_I(i)->start_block = next_block;
2603 + SQUASHFS_I(i)->offset = next_offset;
2605 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2607 + SQUASHFS_INODE_BLK(inode), offset,
2608 + next_block, next_offset);
2611 + case SQUASHFS_BLKDEV_TYPE:
2612 + case SQUASHFS_CHRDEV_TYPE: {
2613 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2614 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2616 + if (msblk->swap) {
2617 + if (!squashfs_get_cached_block(s, (char *)
2618 + sinodep, block, offset,
2619 + sizeof(*sinodep), &next_block,
2622 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2624 + if (!squashfs_get_cached_block(s, (char *)
2625 + inodep, block, offset,
2626 + sizeof(*inodep), &next_block,
2630 + i->i_mode |= (inodeb->inode_type ==
2631 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2633 + init_special_inode(i, i->i_mode,
2634 + old_decode_dev(inodep->rdev));
2636 + TRACE("Device inode %x:%x, rdev %x\n",
2637 + SQUASHFS_INODE_BLK(inode), offset,
2641 + case SQUASHFS_FIFO_TYPE:
2642 + case SQUASHFS_SOCKET_TYPE: {
2644 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2645 + ? S_IFIFO : S_IFSOCK;
2646 + init_special_inode(i, i->i_mode, 0);
2650 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2651 + inodeb->inode_type);
2652 + goto failed_read1;
2658 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2665 +static int get_dir_index_using_offset(struct super_block *s, long long
2666 + *next_block, unsigned int *next_offset,
2667 + long long index_start,
2668 + unsigned int index_offset, int i_count,
2671 + struct squashfs_sb_info *msblk = s->s_fs_info;
2672 + struct squashfs_super_block *sblk = &msblk->sblk;
2673 + int i, length = 0;
2674 + struct squashfs_dir_index_2 index;
2676 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2677 + i_count, (unsigned int) f_pos);
2682 + for (i = 0; i < i_count; i++) {
2683 + if (msblk->swap) {
2684 + struct squashfs_dir_index_2 sindex;
2685 + squashfs_get_cached_block(s, (char *) &sindex,
2686 + index_start, index_offset,
2687 + sizeof(sindex), &index_start,
2689 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2691 + squashfs_get_cached_block(s, (char *) &index,
2692 + index_start, index_offset,
2693 + sizeof(index), &index_start,
2696 + if (index.index > f_pos)
2699 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2700 + index.size + 1, &index_start,
2703 + length = index.index;
2704 + *next_block = index.start_block + sblk->directory_table_start;
2707 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2714 +static int get_dir_index_using_name(struct super_block *s, long long
2715 + *next_block, unsigned int *next_offset,
2716 + long long index_start,
2717 + unsigned int index_offset, int i_count,
2718 + const char *name, int size)
2720 + struct squashfs_sb_info *msblk = s->s_fs_info;
2721 + struct squashfs_super_block *sblk = &msblk->sblk;
2722 + int i, length = 0;
2723 + struct squashfs_dir_index_2 *index;
2726 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2728 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2729 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2730 + ERROR("Failed to allocate squashfs_dir_index\n");
2734 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2735 + strncpy(str, name, size);
2738 + for (i = 0; i < i_count; i++) {
2739 + if (msblk->swap) {
2740 + struct squashfs_dir_index_2 sindex;
2741 + squashfs_get_cached_block(s, (char *) &sindex,
2742 + index_start, index_offset,
2743 + sizeof(sindex), &index_start,
2745 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2747 + squashfs_get_cached_block(s, (char *) index,
2748 + index_start, index_offset,
2749 + sizeof(struct squashfs_dir_index_2),
2750 + &index_start, &index_offset);
2752 + squashfs_get_cached_block(s, index->name, index_start,
2753 + index_offset, index->size + 1,
2754 + &index_start, &index_offset);
2756 + index->name[index->size + 1] = '\0';
2758 + if (strcmp(index->name, str) > 0)
2761 + length = index->index;
2762 + *next_block = index->start_block + sblk->directory_table_start;
2765 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2772 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2774 + struct inode *i = file->f_dentry->d_inode;
2775 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2776 + struct squashfs_super_block *sblk = &msblk->sblk;
2777 + long long next_block = SQUASHFS_I(i)->start_block +
2778 + sblk->directory_table_start;
2779 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2781 + struct squashfs_dir_header_2 dirh;
2782 + struct squashfs_dir_entry_2 *dire;
2784 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2786 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2787 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2788 + ERROR("Failed to allocate squashfs_dir_entry\n");
2792 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2793 + SQUASHFS_I(i)->u.s2.directory_index_start,
2794 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2795 + SQUASHFS_I(i)->u.s2.directory_index_count,
2798 + while (length < i_size_read(i)) {
2799 + /* read directory header */
2800 + if (msblk->swap) {
2801 + struct squashfs_dir_header_2 sdirh;
2803 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2804 + next_block, next_offset, sizeof(sdirh),
2805 + &next_block, &next_offset))
2808 + length += sizeof(sdirh);
2809 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2811 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2812 + next_block, next_offset, sizeof(dirh),
2813 + &next_block, &next_offset))
2816 + length += sizeof(dirh);
2819 + dir_count = dirh.count + 1;
2820 + while (dir_count--) {
2821 + if (msblk->swap) {
2822 + struct squashfs_dir_entry_2 sdire;
2823 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2824 + &sdire, next_block, next_offset,
2825 + sizeof(sdire), &next_block,
2829 + length += sizeof(sdire);
2830 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2832 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2833 + dire, next_block, next_offset,
2834 + sizeof(*dire), &next_block,
2838 + length += sizeof(*dire);
2841 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2842 + next_block, next_offset,
2843 + dire->size + 1, &next_block,
2847 + length += dire->size + 1;
2849 + if (file->f_pos >= length)
2852 + dire->name[dire->size + 1] = '\0';
2854 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2855 + (unsigned int) dirent, dire->name,
2856 + dire->size + 1, (int) file->f_pos,
2857 + dirh.start_block, dire->offset,
2858 + squashfs_filetype_table[dire->type]);
2860 + if (filldir(dirent, dire->name, dire->size + 1,
2861 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2862 + dirh.start_block, dire->offset),
2863 + squashfs_filetype_table[dire->type])
2865 + TRACE("Filldir returned less than 0\n");
2868 + file->f_pos = length;
2877 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2884 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2885 + struct nameidata *nd)
2887 + const unsigned char *name = dentry->d_name.name;
2888 + int len = dentry->d_name.len;
2889 + struct inode *inode = NULL;
2890 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2891 + struct squashfs_super_block *sblk = &msblk->sblk;
2892 + long long next_block = SQUASHFS_I(i)->start_block +
2893 + sblk->directory_table_start;
2894 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2896 + struct squashfs_dir_header_2 dirh;
2897 + struct squashfs_dir_entry_2 *dire;
2898 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2900 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2902 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2903 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2904 + ERROR("Failed to allocate squashfs_dir_entry\n");
2908 + if (len > SQUASHFS_NAME_LEN)
2911 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2912 + SQUASHFS_I(i)->u.s2.directory_index_start,
2913 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2914 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2917 + while (length < i_size_read(i)) {
2918 + /* read directory header */
2919 + if (msblk->swap) {
2920 + struct squashfs_dir_header_2 sdirh;
2921 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2922 + next_block, next_offset, sizeof(sdirh),
2923 + &next_block, &next_offset))
2926 + length += sizeof(sdirh);
2927 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2929 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2930 + next_block, next_offset, sizeof(dirh),
2931 + &next_block, &next_offset))
2934 + length += sizeof(dirh);
2937 + dir_count = dirh.count + 1;
2938 + while (dir_count--) {
2939 + if (msblk->swap) {
2940 + struct squashfs_dir_entry_2 sdire;
2941 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2942 + &sdire, next_block,next_offset,
2943 + sizeof(sdire), &next_block,
2947 + length += sizeof(sdire);
2948 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2950 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2951 + dire, next_block,next_offset,
2952 + sizeof(*dire), &next_block,
2956 + length += sizeof(*dire);
2959 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2960 + next_block, next_offset, dire->size + 1,
2961 + &next_block, &next_offset))
2964 + length += dire->size + 1;
2966 + if (sorted && name[0] < dire->name[0])
2969 + if ((len == dire->size + 1) && !strncmp(name,
2970 + dire->name, len)) {
2971 + squashfs_inode_t ino =
2972 + SQUASHFS_MKINODE(dirh.start_block,
2974 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
2977 + TRACE("calling squashfs_iget for directory "
2978 + "entry %s, inode %x:%x, %lld\n", name,
2979 + dirh.start_block, dire->offset, ino);
2981 + inode = squashfs_iget(i->i_sb, ino, inode_number);
2990 + d_add(dentry, inode);
2991 + return ERR_PTR(0);
2994 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3000 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3002 + struct squashfs_super_block *sblk = &msblk->sblk;
3004 + msblk->read_inode = squashfs_read_inode_2;
3005 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3007 + sblk->bytes_used = sblk->bytes_used_2;
3008 + sblk->uid_start = sblk->uid_start_2;
3009 + sblk->guid_start = sblk->guid_start_2;
3010 + sblk->inode_table_start = sblk->inode_table_start_2;
3011 + sblk->directory_table_start = sblk->directory_table_start_2;
3012 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3016 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs.h linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h
3017 --- linux-2.6.24/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3018 +++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h 2007-08-19 04:23:16.000000000 +0100
3021 + * Squashfs - a compressed read only filesystem for Linux
3023 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3024 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3026 + * This program is free software; you can redistribute it and/or
3027 + * modify it under the terms of the GNU General Public License
3028 + * as published by the Free Software Foundation; either version 2,
3029 + * or (at your option) any later version.
3031 + * This program is distributed in the hope that it will be useful,
3032 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3033 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3034 + * GNU General Public License for more details.
3036 + * You should have received a copy of the GNU General Public License
3037 + * along with this program; if not, write to the Free Software
3038 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3043 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3044 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3047 +#ifdef SQUASHFS_TRACE
3048 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3050 +#define TRACE(s, args...) {}
3053 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3055 +#define SERROR(s, args...) do { \
3057 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3060 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3062 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3064 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3067 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3068 +#define SQSH_EXTERN
3069 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3070 + long long index, unsigned int length,
3071 + long long *next_index, int srclength);
3072 +extern int squashfs_get_cached_block(struct super_block *s, void *buffer,
3073 + long long block, unsigned int offset,
3074 + int length, long long *next_block,
3075 + unsigned int *next_offset);
3076 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3077 + squashfs_fragment_cache *fragment);
3078 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3079 + *s, long long start_block,
3081 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
3082 +extern const struct address_space_operations squashfs_symlink_aops;
3083 +extern const struct address_space_operations squashfs_aops;
3084 +extern struct inode_operations squashfs_dir_inode_ops;
3086 +#define SQSH_EXTERN static
3089 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3090 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3092 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3098 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3099 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3101 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3106 diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h
3107 --- linux-2.6.24/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3108 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h 2007-11-01 03:50:57.000000000 +0000
3110 +#ifndef SQUASHFS_FS
3111 +#define SQUASHFS_FS
3116 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3117 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3119 + * This program is free software; you can redistribute it and/or
3120 + * modify it under the terms of the GNU General Public License
3121 + * as published by the Free Software Foundation; either version 2,
3122 + * or (at your option) any later version.
3124 + * This program is distributed in the hope that it will be useful,
3125 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3126 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3127 + * GNU General Public License for more details.
3129 + * You should have received a copy of the GNU General Public License
3130 + * along with this program; if not, write to the Free Software
3131 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3136 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3137 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3140 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3141 +#define SQUASHFS_MAJOR 3
3142 +#define SQUASHFS_MINOR 1
3143 +#define SQUASHFS_MAGIC 0x73717368
3144 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3145 +#define SQUASHFS_START 0
3147 +/* size of metadata (inode and directory) blocks */
3148 +#define SQUASHFS_METADATA_SIZE 8192
3149 +#define SQUASHFS_METADATA_LOG 13
3151 +/* default size of data blocks */
3152 +#define SQUASHFS_FILE_SIZE 131072
3153 +#define SQUASHFS_FILE_LOG 17
3155 +#define SQUASHFS_FILE_MAX_SIZE 1048576
3157 +/* Max number of uids and gids */
3158 +#define SQUASHFS_UIDS 256
3159 +#define SQUASHFS_GUIDS 255
3161 +/* Max length of filename (not 255) */
3162 +#define SQUASHFS_NAME_LEN 256
3164 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3165 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3166 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3167 +#define SQUASHFS_USED_BLK ((long long) -2)
3169 +/* Filesystem flags */
3170 +#define SQUASHFS_NOI 0
3171 +#define SQUASHFS_NOD 1
3172 +#define SQUASHFS_CHECK 2
3173 +#define SQUASHFS_NOF 3
3174 +#define SQUASHFS_NO_FRAG 4
3175 +#define SQUASHFS_ALWAYS_FRAG 5
3176 +#define SQUASHFS_DUPLICATE 6
3177 +#define SQUASHFS_EXPORT 7
3179 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3181 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3184 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3187 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3190 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3193 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3194 + SQUASHFS_ALWAYS_FRAG)
3196 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3197 + SQUASHFS_DUPLICATE)
3199 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3202 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3205 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3206 + duplicate_checking, exortable) (noi | (nod << 1) | (check_data << 2) \
3207 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3208 + (duplicate_checking << 6) | (exportable << 7))
3210 +/* Max number of types and file types */
3211 +#define SQUASHFS_DIR_TYPE 1
3212 +#define SQUASHFS_FILE_TYPE 2
3213 +#define SQUASHFS_SYMLINK_TYPE 3
3214 +#define SQUASHFS_BLKDEV_TYPE 4
3215 +#define SQUASHFS_CHRDEV_TYPE 5
3216 +#define SQUASHFS_FIFO_TYPE 6
3217 +#define SQUASHFS_SOCKET_TYPE 7
3218 +#define SQUASHFS_LDIR_TYPE 8
3219 +#define SQUASHFS_LREG_TYPE 9
3221 +/* 1.0 filesystem type definitions */
3222 +#define SQUASHFS_TYPES 5
3223 +#define SQUASHFS_IPC_TYPE 0
3225 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3227 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3229 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3230 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3232 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3234 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3236 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
3237 + ~SQUASHFS_COMPRESSED_BIT_BLOCK)
3239 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3242 + * Inode number ops. Inodes consist of a compressed block number, and an
3243 + * uncompressed offset within that block
3245 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3247 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3249 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3252 +/* Compute 32 bit VFS inode number from squashfs inode number */
3253 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3257 +/* Translate between VFS mode and squashfs mode */
3258 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3260 +/* fragment and fragment table defines */
3261 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3263 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3264 + SQUASHFS_METADATA_SIZE)
3266 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3267 + SQUASHFS_METADATA_SIZE)
3269 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3270 + SQUASHFS_METADATA_SIZE - 1) / \
3271 + SQUASHFS_METADATA_SIZE)
3273 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3274 + sizeof(long long))
3276 +/* inode lookup table defines */
3277 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3279 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3280 + SQUASHFS_METADATA_SIZE)
3282 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3283 + SQUASHFS_METADATA_SIZE)
3285 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3286 + SQUASHFS_METADATA_SIZE - 1) / \
3287 + SQUASHFS_METADATA_SIZE)
3289 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3290 + sizeof(long long))
3292 +/* cached data constants for filesystem */
3293 +#define SQUASHFS_CACHED_BLKS 8
3295 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3297 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3298 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3300 +#define SQUASHFS_MARKER_BYTE 0xff
3302 +/* meta index cache */
3303 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3304 +#define SQUASHFS_META_ENTRIES 31
3305 +#define SQUASHFS_META_NUMBER 8
3306 +#define SQUASHFS_SLOTS 4
3308 +struct meta_entry {
3309 + long long data_block;
3310 + unsigned int index_block;
3311 + unsigned short offset;
3312 + unsigned short pad;
3315 +struct meta_index {
3316 + unsigned int inode_number;
3317 + unsigned int offset;
3318 + unsigned short entries;
3319 + unsigned short skip;
3320 + unsigned short locked;
3321 + unsigned short pad;
3322 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3327 + * definitions for structures on disk
3330 +typedef long long squashfs_block_t;
3331 +typedef long long squashfs_inode_t;
3333 +struct squashfs_super_block {
3334 + unsigned int s_magic;
3335 + unsigned int inodes;
3336 + unsigned int bytes_used_2;
3337 + unsigned int uid_start_2;
3338 + unsigned int guid_start_2;
3339 + unsigned int inode_table_start_2;
3340 + unsigned int directory_table_start_2;
3341 + unsigned int s_major:16;
3342 + unsigned int s_minor:16;
3343 + unsigned int block_size_1:16;
3344 + unsigned int block_log:16;
3345 + unsigned int flags:8;
3346 + unsigned int no_uids:8;
3347 + unsigned int no_guids:8;
3348 + unsigned int mkfs_time /* time of filesystem creation */;
3349 + squashfs_inode_t root_inode;
3350 + unsigned int block_size;
3351 + unsigned int fragments;
3352 + unsigned int fragment_table_start_2;
3353 + long long bytes_used;
3354 + long long uid_start;
3355 + long long guid_start;
3356 + long long inode_table_start;
3357 + long long directory_table_start;
3358 + long long fragment_table_start;
3359 + long long lookup_table_start;
3360 +} __attribute__ ((packed));
3362 +struct squashfs_dir_index {
3363 + unsigned int index;
3364 + unsigned int start_block;
3365 + unsigned char size;
3366 + unsigned char name[0];
3367 +} __attribute__ ((packed));
3369 +#define SQUASHFS_BASE_INODE_HEADER \
3370 + unsigned int inode_type:4; \
3371 + unsigned int mode:12; \
3372 + unsigned int uid:8; \
3373 + unsigned int guid:8; \
3374 + unsigned int mtime; \
3375 + unsigned int inode_number;
3377 +struct squashfs_base_inode_header {
3378 + SQUASHFS_BASE_INODE_HEADER;
3379 +} __attribute__ ((packed));
3381 +struct squashfs_ipc_inode_header {
3382 + SQUASHFS_BASE_INODE_HEADER;
3383 + unsigned int nlink;
3384 +} __attribute__ ((packed));
3386 +struct squashfs_dev_inode_header {
3387 + SQUASHFS_BASE_INODE_HEADER;
3388 + unsigned int nlink;
3389 + unsigned short rdev;
3390 +} __attribute__ ((packed));
3392 +struct squashfs_symlink_inode_header {
3393 + SQUASHFS_BASE_INODE_HEADER;
3394 + unsigned int nlink;
3395 + unsigned short symlink_size;
3397 +} __attribute__ ((packed));
3399 +struct squashfs_reg_inode_header {
3400 + SQUASHFS_BASE_INODE_HEADER;
3401 + squashfs_block_t start_block;
3402 + unsigned int fragment;
3403 + unsigned int offset;
3404 + unsigned int file_size;
3405 + unsigned short block_list[0];
3406 +} __attribute__ ((packed));
3408 +struct squashfs_lreg_inode_header {
3409 + SQUASHFS_BASE_INODE_HEADER;
3410 + unsigned int nlink;
3411 + squashfs_block_t start_block;
3412 + unsigned int fragment;
3413 + unsigned int offset;
3414 + long long file_size;
3415 + unsigned short block_list[0];
3416 +} __attribute__ ((packed));
3418 +struct squashfs_dir_inode_header {
3419 + SQUASHFS_BASE_INODE_HEADER;
3420 + unsigned int nlink;
3421 + unsigned int file_size:19;
3422 + unsigned int offset:13;
3423 + unsigned int start_block;
3424 + unsigned int parent_inode;
3425 +} __attribute__ ((packed));
3427 +struct squashfs_ldir_inode_header {
3428 + SQUASHFS_BASE_INODE_HEADER;
3429 + unsigned int nlink;
3430 + unsigned int file_size:27;
3431 + unsigned int offset:13;
3432 + unsigned int start_block;
3433 + unsigned int i_count:16;
3434 + unsigned int parent_inode;
3435 + struct squashfs_dir_index index[0];
3436 +} __attribute__ ((packed));
3438 +union squashfs_inode_header {
3439 + struct squashfs_base_inode_header base;
3440 + struct squashfs_dev_inode_header dev;
3441 + struct squashfs_symlink_inode_header symlink;
3442 + struct squashfs_reg_inode_header reg;
3443 + struct squashfs_lreg_inode_header lreg;
3444 + struct squashfs_dir_inode_header dir;
3445 + struct squashfs_ldir_inode_header ldir;
3446 + struct squashfs_ipc_inode_header ipc;
3449 +struct squashfs_dir_entry {
3450 + unsigned int offset:13;
3451 + unsigned int type:3;
3452 + unsigned int size:8;
3453 + int inode_number:16;
3455 +} __attribute__ ((packed));
3457 +struct squashfs_dir_header {
3458 + unsigned int count:8;
3459 + unsigned int start_block;
3460 + unsigned int inode_number;
3461 +} __attribute__ ((packed));
3463 +struct squashfs_fragment_entry {
3464 + long long start_block;
3465 + unsigned int size;
3466 + unsigned int pending;
3467 +} __attribute__ ((packed));
3469 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3470 +extern int squashfs_uncompress_init(void);
3471 +extern int squashfs_uncompress_exit(void);
3474 + * macros to convert each packed bitfield structure from little endian to big
3475 + * endian and vice versa. These are needed when creating or using a filesystem
3476 + * on a machine with different byte ordering to the target architecture.
3480 +#define SQUASHFS_SWAP_START \
3483 + unsigned long long val;\
3484 + unsigned char *s;\
3487 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3488 + SQUASHFS_SWAP_START\
3489 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3490 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3491 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3492 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3493 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3494 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3495 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3496 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3497 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3498 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3499 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3500 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3501 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3502 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3503 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3504 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3505 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3506 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3507 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3508 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3509 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3510 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3511 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3512 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3513 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3514 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3515 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3518 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3519 + SQUASHFS_MEMSET(s, d, n);\
3520 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3521 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3522 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3523 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3524 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3525 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3527 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3528 + SQUASHFS_SWAP_START\
3529 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3532 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3533 + SQUASHFS_SWAP_START\
3534 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3535 + sizeof(struct squashfs_ipc_inode_header))\
3536 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3539 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3540 + SQUASHFS_SWAP_START\
3541 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3542 + sizeof(struct squashfs_dev_inode_header)); \
3543 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3544 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3547 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3548 + SQUASHFS_SWAP_START\
3549 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 + sizeof(struct squashfs_symlink_inode_header));\
3551 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3555 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3556 + SQUASHFS_SWAP_START\
3557 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3558 + sizeof(struct squashfs_reg_inode_header));\
3559 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3560 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3561 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3562 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3565 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3566 + SQUASHFS_SWAP_START\
3567 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3568 + sizeof(struct squashfs_lreg_inode_header));\
3569 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3570 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3571 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3572 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3573 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3576 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3577 + SQUASHFS_SWAP_START\
3578 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3579 + sizeof(struct squashfs_dir_inode_header));\
3580 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3581 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3582 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3583 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3584 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3587 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3588 + SQUASHFS_SWAP_START\
3589 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3590 + sizeof(struct squashfs_ldir_inode_header));\
3591 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3592 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3593 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3594 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3595 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3596 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3599 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3600 + SQUASHFS_SWAP_START\
3601 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3602 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3603 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3604 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3607 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3608 + SQUASHFS_SWAP_START\
3609 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3610 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3611 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3612 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3615 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3616 + SQUASHFS_SWAP_START\
3617 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3618 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3619 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3620 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3621 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3624 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3625 + SQUASHFS_SWAP_START\
3626 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3627 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3628 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3631 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3633 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3635 + int bit_position;\
3636 + SQUASHFS_SWAP_START\
3637 + SQUASHFS_MEMSET(s, d, n * 2);\
3638 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3640 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3643 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3645 + int bit_position;\
3646 + SQUASHFS_SWAP_START\
3647 + SQUASHFS_MEMSET(s, d, n * 4);\
3648 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3650 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3653 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3655 + int bit_position;\
3656 + SQUASHFS_SWAP_START\
3657 + SQUASHFS_MEMSET(s, d, n * 8);\
3658 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3660 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3663 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3665 + int bit_position;\
3666 + SQUASHFS_SWAP_START\
3667 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3668 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3670 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3673 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3674 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3676 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3678 +struct squashfs_base_inode_header_1 {
3679 + unsigned int inode_type:4;
3680 + unsigned int mode:12; /* protection */
3681 + unsigned int uid:4; /* index into uid table */
3682 + unsigned int guid:4; /* index into guid table */
3683 +} __attribute__ ((packed));
3685 +struct squashfs_ipc_inode_header_1 {
3686 + unsigned int inode_type:4;
3687 + unsigned int mode:12; /* protection */
3688 + unsigned int uid:4; /* index into uid table */
3689 + unsigned int guid:4; /* index into guid table */
3690 + unsigned int type:4;
3691 + unsigned int offset:4;
3692 +} __attribute__ ((packed));
3694 +struct squashfs_dev_inode_header_1 {
3695 + unsigned int inode_type:4;
3696 + unsigned int mode:12; /* protection */
3697 + unsigned int uid:4; /* index into uid table */
3698 + unsigned int guid:4; /* index into guid table */
3699 + unsigned short rdev;
3700 +} __attribute__ ((packed));
3702 +struct squashfs_symlink_inode_header_1 {
3703 + unsigned int inode_type:4;
3704 + unsigned int mode:12; /* protection */
3705 + unsigned int uid:4; /* index into uid table */
3706 + unsigned int guid:4; /* index into guid table */
3707 + unsigned short symlink_size;
3709 +} __attribute__ ((packed));
3711 +struct squashfs_reg_inode_header_1 {
3712 + unsigned int inode_type:4;
3713 + unsigned int mode:12; /* protection */
3714 + unsigned int uid:4; /* index into uid table */
3715 + unsigned int guid:4; /* index into guid table */
3716 + unsigned int mtime;
3717 + unsigned int start_block;
3718 + unsigned int file_size:32;
3719 + unsigned short block_list[0];
3720 +} __attribute__ ((packed));
3722 +struct squashfs_dir_inode_header_1 {
3723 + unsigned int inode_type:4;
3724 + unsigned int mode:12; /* protection */
3725 + unsigned int uid:4; /* index into uid table */
3726 + unsigned int guid:4; /* index into guid table */
3727 + unsigned int file_size:19;
3728 + unsigned int offset:13;
3729 + unsigned int mtime;
3730 + unsigned int start_block:24;
3731 +} __attribute__ ((packed));
3733 +union squashfs_inode_header_1 {
3734 + struct squashfs_base_inode_header_1 base;
3735 + struct squashfs_dev_inode_header_1 dev;
3736 + struct squashfs_symlink_inode_header_1 symlink;
3737 + struct squashfs_reg_inode_header_1 reg;
3738 + struct squashfs_dir_inode_header_1 dir;
3739 + struct squashfs_ipc_inode_header_1 ipc;
3742 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3743 + SQUASHFS_MEMSET(s, d, n);\
3744 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3745 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3746 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3747 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3749 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3750 + SQUASHFS_SWAP_START\
3751 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3754 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3755 + SQUASHFS_SWAP_START\
3756 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3757 + sizeof(struct squashfs_ipc_inode_header_1));\
3758 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3759 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3762 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3763 + SQUASHFS_SWAP_START\
3764 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3765 + sizeof(struct squashfs_dev_inode_header_1));\
3766 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3769 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3770 + SQUASHFS_SWAP_START\
3771 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3772 + sizeof(struct squashfs_symlink_inode_header_1));\
3773 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3776 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3777 + SQUASHFS_SWAP_START\
3778 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3779 + sizeof(struct squashfs_reg_inode_header_1));\
3780 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3781 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3782 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3785 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3786 + SQUASHFS_SWAP_START\
3787 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3788 + sizeof(struct squashfs_dir_inode_header_1));\
3789 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3790 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3791 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3792 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3797 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3799 +struct squashfs_dir_index_2 {
3800 + unsigned int index:27;
3801 + unsigned int start_block:29;
3802 + unsigned char size;
3803 + unsigned char name[0];
3804 +} __attribute__ ((packed));
3806 +struct squashfs_base_inode_header_2 {
3807 + unsigned int inode_type:4;
3808 + unsigned int mode:12; /* protection */
3809 + unsigned int uid:8; /* index into uid table */
3810 + unsigned int guid:8; /* index into guid table */
3811 +} __attribute__ ((packed));
3813 +struct squashfs_ipc_inode_header_2 {
3814 + unsigned int inode_type:4;
3815 + unsigned int mode:12; /* protection */
3816 + unsigned int uid:8; /* index into uid table */
3817 + unsigned int guid:8; /* index into guid table */
3818 +} __attribute__ ((packed));
3820 +struct squashfs_dev_inode_header_2 {
3821 + unsigned int inode_type:4;
3822 + unsigned int mode:12; /* protection */
3823 + unsigned int uid:8; /* index into uid table */
3824 + unsigned int guid:8; /* index into guid table */
3825 + unsigned short rdev;
3826 +} __attribute__ ((packed));
3828 +struct squashfs_symlink_inode_header_2 {
3829 + unsigned int inode_type:4;
3830 + unsigned int mode:12; /* protection */
3831 + unsigned int uid:8; /* index into uid table */
3832 + unsigned int guid:8; /* index into guid table */
3833 + unsigned short symlink_size;
3835 +} __attribute__ ((packed));
3837 +struct squashfs_reg_inode_header_2 {
3838 + unsigned int inode_type:4;
3839 + unsigned int mode:12; /* protection */
3840 + unsigned int uid:8; /* index into uid table */
3841 + unsigned int guid:8; /* index into guid table */
3842 + unsigned int mtime;
3843 + unsigned int start_block;
3844 + unsigned int fragment;
3845 + unsigned int offset;
3846 + unsigned int file_size:32;
3847 + unsigned short block_list[0];
3848 +} __attribute__ ((packed));
3850 +struct squashfs_dir_inode_header_2 {
3851 + unsigned int inode_type:4;
3852 + unsigned int mode:12; /* protection */
3853 + unsigned int uid:8; /* index into uid table */
3854 + unsigned int guid:8; /* index into guid table */
3855 + unsigned int file_size:19;
3856 + unsigned int offset:13;
3857 + unsigned int mtime;
3858 + unsigned int start_block:24;
3859 +} __attribute__ ((packed));
3861 +struct squashfs_ldir_inode_header_2 {
3862 + unsigned int inode_type:4;
3863 + unsigned int mode:12; /* protection */
3864 + unsigned int uid:8; /* index into uid table */
3865 + unsigned int guid:8; /* index into guid table */
3866 + unsigned int file_size:27;
3867 + unsigned int offset:13;
3868 + unsigned int mtime;
3869 + unsigned int start_block:24;
3870 + unsigned int i_count:16;
3871 + struct squashfs_dir_index_2 index[0];
3872 +} __attribute__ ((packed));
3874 +union squashfs_inode_header_2 {
3875 + struct squashfs_base_inode_header_2 base;
3876 + struct squashfs_dev_inode_header_2 dev;
3877 + struct squashfs_symlink_inode_header_2 symlink;
3878 + struct squashfs_reg_inode_header_2 reg;
3879 + struct squashfs_dir_inode_header_2 dir;
3880 + struct squashfs_ldir_inode_header_2 ldir;
3881 + struct squashfs_ipc_inode_header_2 ipc;
3884 +struct squashfs_dir_header_2 {
3885 + unsigned int count:8;
3886 + unsigned int start_block:24;
3887 +} __attribute__ ((packed));
3889 +struct squashfs_dir_entry_2 {
3890 + unsigned int offset:13;
3891 + unsigned int type:3;
3892 + unsigned int size:8;
3894 +} __attribute__ ((packed));
3896 +struct squashfs_fragment_entry_2 {
3897 + unsigned int start_block;
3898 + unsigned int size;
3899 +} __attribute__ ((packed));
3901 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(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, 8);\
3906 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3908 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3909 + SQUASHFS_SWAP_START\
3910 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3913 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3914 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3916 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3917 + SQUASHFS_SWAP_START\
3918 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3919 + sizeof(struct squashfs_dev_inode_header_2)); \
3920 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3923 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3924 + SQUASHFS_SWAP_START\
3925 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3926 + sizeof(struct squashfs_symlink_inode_header_2));\
3927 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3930 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3931 + SQUASHFS_SWAP_START\
3932 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3933 + sizeof(struct squashfs_reg_inode_header_2));\
3934 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3935 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3936 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3937 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3938 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3941 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3942 + SQUASHFS_SWAP_START\
3943 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3944 + sizeof(struct squashfs_dir_inode_header_2));\
3945 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3946 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3947 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3948 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3951 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3952 + SQUASHFS_SWAP_START\
3953 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3954 + sizeof(struct squashfs_ldir_inode_header_2));\
3955 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3956 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3957 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3958 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3959 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3962 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3963 + SQUASHFS_SWAP_START\
3964 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3965 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3966 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3967 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3969 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3970 + SQUASHFS_SWAP_START\
3971 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3972 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3973 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3976 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3977 + SQUASHFS_SWAP_START\
3978 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3979 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3980 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3981 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3984 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3985 + SQUASHFS_SWAP_START\
3986 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3987 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3988 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3991 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3993 +/* fragment and fragment table defines */
3994 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3996 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3997 + SQUASHFS_METADATA_SIZE)
3999 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4000 + SQUASHFS_METADATA_SIZE)
4002 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4003 + SQUASHFS_METADATA_SIZE - 1) / \
4004 + SQUASHFS_METADATA_SIZE)
4006 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4014 + * macros used to swap each structure entry, taking into account
4015 + * bitfields and different bitfield placing conventions on differing
4019 +#include <asm/byteorder.h>
4021 +#ifdef __BIG_ENDIAN
4022 + /* convert from little endian to big endian */
4023 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4026 + /* convert from big endian to little endian */
4027 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4028 + tbits, 64 - tbits - b_pos)
4031 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4034 + s = (unsigned char *)p + (pos / 8);\
4035 + d = ((unsigned char *) &val) + 7;\
4036 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4038 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4041 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4045 diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_i.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h
4046 --- linux-2.6.24/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4047 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h 2007-08-19 04:24:08.000000000 +0100
4049 +#ifndef SQUASHFS_FS_I
4050 +#define SQUASHFS_FS_I
4054 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4055 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4057 + * This program is free software; you can redistribute it and/or
4058 + * modify it under the terms of the GNU General Public License
4059 + * as published by the Free Software Foundation; either version 2,
4060 + * or (at your option) any later version.
4062 + * This program is distributed in the hope that it will be useful,
4063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4065 + * GNU General Public License for more details.
4067 + * You should have received a copy of the GNU General Public License
4068 + * along with this program; if not, write to the Free Software
4069 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4074 +struct squashfs_inode_info {
4075 + long long start_block;
4076 + unsigned int offset;
4079 + long long fragment_start_block;
4080 + unsigned int fragment_size;
4081 + unsigned int fragment_offset;
4082 + long long block_list_start;
4085 + long long directory_index_start;
4086 + unsigned int directory_index_offset;
4087 + unsigned int directory_index_count;
4088 + unsigned int parent_inode;
4091 + struct inode vfs_inode;
4094 diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs_sb.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h
4095 --- linux-2.6.24/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4096 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h 2007-08-19 04:24:26.000000000 +0100
4098 +#ifndef SQUASHFS_FS_SB
4099 +#define SQUASHFS_FS_SB
4103 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4104 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4106 + * This program is free software; you can redistribute it and/or
4107 + * modify it under the terms of the GNU General Public License
4108 + * as published by the Free Software Foundation; either version 2,
4109 + * or (at your option) any later version.
4111 + * This program is distributed in the hope that it will be useful,
4112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4114 + * GNU General Public License for more details.
4116 + * You should have received a copy of the GNU General Public License
4117 + * along with this program; if not, write to the Free Software
4118 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4120 + * squashfs_fs_sb.h
4123 +#include <linux/squashfs_fs.h>
4125 +struct squashfs_cache {
4128 + long long next_index;
4132 +struct squashfs_fragment_cache {
4135 + unsigned int locked;
4139 +struct squashfs_sb_info {
4140 + struct squashfs_super_block sblk;
4142 + int devblksize_log2;
4144 + struct squashfs_cache *block_cache;
4145 + struct squashfs_fragment_cache *fragment;
4147 + int next_fragment;
4148 + int next_meta_index;
4149 + unsigned int *uid;
4150 + unsigned int *guid;
4151 + long long *fragment_index;
4152 + unsigned int *fragment_index_2;
4154 + struct mutex read_data_mutex;
4155 + struct mutex read_page_mutex;
4156 + struct mutex block_cache_mutex;
4157 + struct mutex fragment_mutex;
4158 + struct mutex meta_index_mutex;
4159 + wait_queue_head_t waitq;
4160 + wait_queue_head_t fragment_wait_queue;
4161 + struct meta_index *meta_index;
4163 + long long *inode_lookup_table;
4164 + int unused_cache_blks;
4165 + int unused_frag_blks;
4166 + int (*read_inode)(struct inode *i, squashfs_inode_t \
4168 + long long (*read_blocklist)(struct inode *inode, int \
4169 + index, int readahead_blks, char *block_list, \
4170 + unsigned short **block_p, unsigned int *bsize);
4171 + int (*read_fragment_index_table)(struct super_block *s);
4174 diff -x .gitignore -Nurp linux-2.6.24/init/do_mounts_rd.c linux-2.6.24-squashfs3.3/init/do_mounts_rd.c
4175 --- linux-2.6.24/init/do_mounts_rd.c 2007-10-25 17:41:49.000000000 +0100
4176 +++ linux-2.6.24-squashfs3.3/init/do_mounts_rd.c 2007-11-01 05:06:25.000000000 +0000
4178 #include <linux/ext2_fs.h>
4179 #include <linux/romfs_fs.h>
4180 #include <linux/cramfs_fs.h>
4181 +#include <linux/squashfs_fs.h>
4182 #include <linux/initrd.h>
4183 #include <linux/string.h>
4185 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4186 * numbers could not be found.
4188 * We currently check for the following magic numbers:
4193 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4194 struct ext2_super_block *ext2sb;
4195 struct romfs_super_block *romfsb;
4196 struct cramfs_super *cramfsb;
4197 + struct squashfs_super_block *squashfsb;
4201 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4202 ext2sb = (struct ext2_super_block *) buf;
4203 romfsb = (struct romfs_super_block *) buf;
4204 cramfsb = (struct cramfs_super *) buf;
4205 + squashfsb = (struct squashfs_super_block *) buf;
4206 memset(buf, 0xe5, size);
4209 @@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4213 + /* squashfs is at block zero too */
4214 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4215 + printk(KERN_NOTICE
4216 + "RAMDISK: squashfs filesystem found at block %d\n",
4218 + if (squashfsb->s_major < 3)
4219 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4221 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4226 * Read block 1 to test for minix and ext2 superblock