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 void vfs_read_inode(struct inode *i);
116 +static struct dentry *squashfs_get_parent(struct dentry *child);
117 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
118 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
119 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
120 +static long long read_blocklist(struct inode *inode, int index,
121 + int readahead_blks, char *block_list,
122 + unsigned short **block_p, unsigned int *bsize);
123 +static int squashfs_readpage(struct file *file, struct page *page);
124 +static int squashfs_readdir(struct file *, void *, filldir_t);
125 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
126 + struct nameidata *);
127 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
128 +static void squashfs_put_super(struct super_block *);
129 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
130 + struct vfsmount *);
131 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
132 +static void squashfs_destroy_inode(struct inode *inode);
133 +static int init_inodecache(void);
134 +static void destroy_inodecache(void);
136 +static struct file_system_type squashfs_fs_type = {
137 + .owner = THIS_MODULE,
138 + .name = "squashfs",
139 + .get_sb = squashfs_get_sb,
140 + .kill_sb = kill_block_super,
141 + .fs_flags = FS_REQUIRES_DEV
144 +static const unsigned char squashfs_filetype_table[] = {
145 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
148 +static struct super_operations squashfs_super_ops = {
149 + .alloc_inode = squashfs_alloc_inode,
150 + .destroy_inode = squashfs_destroy_inode,
151 + .statfs = squashfs_statfs,
152 + .put_super = squashfs_put_super,
153 + .remount_fs = squashfs_remount
156 +static struct super_operations squashfs_export_super_ops = {
157 + .alloc_inode = squashfs_alloc_inode,
158 + .destroy_inode = squashfs_destroy_inode,
159 + .statfs = squashfs_statfs,
160 + .put_super = squashfs_put_super,
161 + .read_inode = vfs_read_inode
164 +static struct export_operations squashfs_export_ops = {
165 + .get_parent = squashfs_get_parent
168 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
169 + .readpage = squashfs_symlink_readpage
172 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
173 + .readpage = squashfs_readpage
176 +static const struct file_operations squashfs_dir_ops = {
177 + .read = generic_read_dir,
178 + .readdir = squashfs_readdir
181 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
182 + .lookup = squashfs_lookup
186 +static struct buffer_head *get_block_length(struct super_block *s,
187 + int *cur_index, int *offset, int *c_byte)
189 + struct squashfs_sb_info *msblk = s->s_fs_info;
190 + unsigned short temp;
191 + struct buffer_head *bh;
193 + if (!(bh = sb_bread(s, *cur_index)))
196 + if (msblk->devblksize - *offset == 1) {
198 + ((unsigned char *) &temp)[1] = *((unsigned char *)
199 + (bh->b_data + *offset));
201 + ((unsigned char *) &temp)[0] = *((unsigned char *)
202 + (bh->b_data + *offset));
204 + if (!(bh = sb_bread(s, ++(*cur_index))))
207 + ((unsigned char *) &temp)[0] = *((unsigned char *)
210 + ((unsigned char *) &temp)[1] = *((unsigned char *)
216 + ((unsigned char *) &temp)[1] = *((unsigned char *)
217 + (bh->b_data + *offset));
218 + ((unsigned char *) &temp)[0] = *((unsigned char *)
219 + (bh->b_data + *offset + 1));
221 + ((unsigned char *) &temp)[0] = *((unsigned char *)
222 + (bh->b_data + *offset));
223 + ((unsigned char *) &temp)[1] = *((unsigned char *)
224 + (bh->b_data + *offset + 1));
230 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
231 + if (*offset == msblk->devblksize) {
233 + if (!(bh = sb_bread(s, ++(*cur_index))))
237 + if (*((unsigned char *) (bh->b_data + *offset)) !=
238 + SQUASHFS_MARKER_BYTE) {
239 + ERROR("Metadata block marker corrupt @ %x\n",
253 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
254 + long long index, unsigned int length,
255 + long long *next_index, int srclength)
257 + struct squashfs_sb_info *msblk = s->s_fs_info;
258 + struct squashfs_super_block *sblk = &msblk->sblk;
259 + struct buffer_head **bh;
260 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
261 + unsigned int cur_index = index >> msblk->devblksize_log2;
262 + int bytes, avail_bytes, b = 0, k = 0;
263 + unsigned int compressed;
264 + unsigned int c_byte = length;
266 + bh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *
267 + sizeof(struct buffer_head *), GFP_KERNEL);
272 + bytes = msblk->devblksize - offset;
273 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
274 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
276 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index,
277 + compressed ? "" : "un", (unsigned int) c_byte, srclength);
279 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
282 + bh[0] = sb_getblk(s, cur_index);
284 + goto block_release;
286 + for (b = 1; bytes < c_byte; b++) {
287 + bh[b] = sb_getblk(s, ++cur_index);
289 + goto block_release;
290 + bytes += msblk->devblksize;
292 + ll_rw_block(READ, b, bh);
294 + if (index < 0 || (index + 2) > sblk->bytes_used)
297 + bh[0] = get_block_length(s, &cur_index, &offset, &c_byte);
301 + bytes = msblk->devblksize - offset;
302 + compressed = SQUASHFS_COMPRESSED(c_byte);
303 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
305 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
306 + ? "" : "un", (unsigned int) c_byte);
308 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
311 + for (b = 1; bytes < c_byte; b++) {
312 + bh[b] = sb_getblk(s, ++cur_index);
314 + goto block_release;
315 + bytes += msblk->devblksize;
317 + ll_rw_block(READ, b - 1, bh + 1);
327 + mutex_lock(&msblk->read_data_mutex);
329 + msblk->stream.next_out = buffer;
330 + msblk->stream.avail_out = srclength;
332 + for (bytes = 0; k < b; k++) {
333 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
335 + wait_on_buffer(bh[k]);
336 + if (!buffer_uptodate(bh[k]))
337 + goto release_mutex;
339 + msblk->stream.next_in = bh[k]->b_data + offset;
340 + msblk->stream.avail_in = avail_bytes;
343 + zlib_err = zlib_inflateInit(&msblk->stream);
344 + if (zlib_err != Z_OK) {
345 + ERROR("zlib_inflateInit returned unexpected result 0x%x,"
346 + " srclength %d\n", zlib_err, srclength);
347 + goto release_mutex;
350 + if (avail_bytes == 0) {
357 + zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
358 + if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
359 + ERROR("zlib_inflate returned unexpected result 0x%x,"
360 + " srclength %d, avail_in %d, avail_out %d\n", zlib_err,
361 + srclength, msblk->stream.avail_in, msblk->stream.avail_out);
362 + goto release_mutex;
365 + bytes += avail_bytes;
370 + if (zlib_err != Z_STREAM_END)
371 + goto release_mutex;
373 + zlib_err = zlib_inflateEnd(&msblk->stream);
374 + if (zlib_err != Z_OK) {
375 + ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
376 + " srclength %d\n", zlib_err, srclength);
377 + goto release_mutex;
379 + bytes = msblk->stream.total_out;
380 + mutex_unlock(&msblk->read_data_mutex);
384 + for(i = 0; i < b; i++) {
385 + wait_on_buffer(bh[i]);
386 + if (!buffer_uptodate(bh[i]))
387 + goto block_release;
390 + for (bytes = 0; k < b; k++) {
391 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
393 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
394 + bytes += avail_bytes;
401 + *next_index = index + c_byte + (length ? 0 :
402 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));
408 + mutex_unlock(&msblk->read_data_mutex);
415 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
421 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,
422 + long long block, unsigned int offset,
423 + int length, long long *next_block,
424 + unsigned int *next_offset)
426 + struct squashfs_sb_info *msblk = s->s_fs_info;
427 + int n, i, bytes, return_length = length;
428 + long long next_index;
430 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
433 + for (i = 0; i < squashfs_cached_blks; i++)
434 + if (msblk->block_cache[i].block == block)
437 + mutex_lock(&msblk->block_cache_mutex);
439 + if (i == squashfs_cached_blks) {
440 + /* read inode header block */
441 + if (msblk->unused_cache_blks == 0) {
442 + mutex_unlock(&msblk->block_cache_mutex);
443 + wait_event(msblk->waitq, msblk->unused_cache_blks);
447 + i = msblk->next_cache;
448 + for (n = 0; n < squashfs_cached_blks; n++) {
449 + if (msblk->block_cache[i].block != SQUASHFS_USED_BLK)
451 + i = (i + 1) % squashfs_cached_blks;
454 + msblk->next_cache = (i + 1) % squashfs_cached_blks;
456 + if (msblk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
457 + msblk->block_cache[i].data = vmalloc(SQUASHFS_METADATA_SIZE);
458 + if (msblk->block_cache[i].data == NULL) {
459 + ERROR("Failed to allocate cache block\n");
460 + mutex_unlock(&msblk->block_cache_mutex);
465 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
466 + msblk->unused_cache_blks --;
467 + mutex_unlock(&msblk->block_cache_mutex);
469 + msblk->block_cache[i].length = squashfs_read_data(s,
470 + msblk->block_cache[i].data, block, 0, &next_index,
471 + SQUASHFS_METADATA_SIZE);
473 + if (msblk->block_cache[i].length == 0) {
474 + ERROR("Unable to read cache block [%llx:%x]\n", block, offset);
475 + mutex_lock(&msblk->block_cache_mutex);
476 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
477 + msblk->unused_cache_blks ++;
479 + vfree(msblk->block_cache[i].data);
480 + wake_up(&msblk->waitq);
481 + mutex_unlock(&msblk->block_cache_mutex);
485 + mutex_lock(&msblk->block_cache_mutex);
486 + msblk->block_cache[i].block = block;
487 + msblk->block_cache[i].next_index = next_index;
488 + msblk->unused_cache_blks ++;
490 + wake_up(&msblk->waitq);
491 + TRACE("Read cache block [%llx:%x]\n", block, offset);
494 + if (msblk->block_cache[i].block != block) {
495 + mutex_unlock(&msblk->block_cache_mutex);
499 + bytes = msblk->block_cache[i].length - offset;
502 + mutex_unlock(&msblk->block_cache_mutex);
504 + } else if (bytes >= length) {
506 + memcpy(buffer, msblk->block_cache[i].data + offset, length);
507 + if (msblk->block_cache[i].length - offset == length) {
508 + *next_block = msblk->block_cache[i].next_index;
511 + *next_block = block;
512 + *next_offset = offset + length;
514 + mutex_unlock(&msblk->block_cache_mutex);
518 + memcpy(buffer, msblk->block_cache[i].data + offset, bytes);
519 + buffer = (char *) buffer + bytes;
521 + block = msblk->block_cache[i].next_index;
522 + mutex_unlock(&msblk->block_cache_mutex);
529 + return return_length;
535 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
536 + long long *fragment_start_block,
537 + unsigned int *fragment_size)
539 + struct squashfs_sb_info *msblk = s->s_fs_info;
540 + long long start_block =
541 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
542 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
543 + struct squashfs_fragment_entry fragment_entry;
546 + struct squashfs_fragment_entry sfragment_entry;
548 + if (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,
549 + sizeof(sfragment_entry), &start_block, &offset))
551 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
553 + if (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,
554 + sizeof(fragment_entry), &start_block, &offset))
557 + *fragment_start_block = fragment_entry.start_block;
558 + *fragment_size = fragment_entry.size;
567 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,
568 + struct squashfs_fragment_cache *fragment)
570 + mutex_lock(&msblk->fragment_mutex);
571 + fragment->locked --;
572 + if (fragment->locked == 0) {
573 + msblk->unused_frag_blks ++;
575 + wake_up(&msblk->fragment_wait_queue);
577 + mutex_unlock(&msblk->fragment_mutex);
582 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s,
583 + long long start_block, int length)
586 + struct squashfs_sb_info *msblk = s->s_fs_info;
587 + struct squashfs_super_block *sblk = &msblk->sblk;
590 + mutex_lock(&msblk->fragment_mutex);
592 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
593 + msblk->fragment[i].block != start_block; i++);
595 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
596 + if (msblk->unused_frag_blks == 0) {
597 + mutex_unlock(&msblk->fragment_mutex);
598 + wait_event(msblk->fragment_wait_queue, msblk->unused_frag_blks);
602 + i = msblk->next_fragment;
603 + for (n = 0; n < SQUASHFS_CACHED_FRAGMENTS; n++) {
604 + if (msblk->fragment[i].locked == 0)
606 + i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS;
609 + msblk->next_fragment = (msblk->next_fragment + 1) %
610 + SQUASHFS_CACHED_FRAGMENTS;
612 + if (msblk->fragment[i].data == NULL) {
613 + msblk->fragment[i].data = vmalloc(sblk->block_size);
614 + if (msblk->fragment[i].data == NULL) {
615 + ERROR("Failed to allocate fragment cache block\n");
616 + mutex_unlock(&msblk->fragment_mutex);
621 + msblk->unused_frag_blks --;
622 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
623 + msblk->fragment[i].locked = 1;
624 + mutex_unlock(&msblk->fragment_mutex);
626 + msblk->fragment[i].length = squashfs_read_data(s,
627 + msblk->fragment[i].data, start_block, length, NULL,
630 + if (msblk->fragment[i].length == 0) {
631 + ERROR("Unable to read fragment cache block [%llx]\n", start_block);
632 + msblk->fragment[i].locked = 0;
633 + msblk->unused_frag_blks ++;
635 + wake_up(&msblk->fragment_wait_queue);
639 + mutex_lock(&msblk->fragment_mutex);
640 + msblk->fragment[i].block = start_block;
641 + TRACE("New fragment %d, start block %lld, locked %d\n",
642 + i, msblk->fragment[i].block, msblk->fragment[i].locked);
643 + mutex_unlock(&msblk->fragment_mutex);
647 + if (msblk->fragment[i].locked == 0)
648 + msblk->unused_frag_blks --;
649 + msblk->fragment[i].locked++;
650 + mutex_unlock(&msblk->fragment_mutex);
651 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
652 + msblk->fragment[i].block, msblk->fragment[i].locked);
656 + return &msblk->fragment[i];
663 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
664 + struct squashfs_base_inode_header *inodeb)
666 + i->i_ino = inodeb->inode_number;
667 + i->i_mtime.tv_sec = inodeb->mtime;
668 + i->i_atime.tv_sec = inodeb->mtime;
669 + i->i_ctime.tv_sec = inodeb->mtime;
670 + i->i_uid = msblk->uid[inodeb->uid];
671 + i->i_mode = inodeb->mode;
674 + if (inodeb->guid == SQUASHFS_GUIDS)
675 + i->i_gid = i->i_uid;
677 + i->i_gid = msblk->guid[inodeb->guid];
681 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
683 + struct squashfs_sb_info *msblk = s->s_fs_info;
684 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
685 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
686 + squashfs_inode_t inode;
688 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
691 + squashfs_inode_t sinode;
693 + if (!squashfs_get_cached_block(s, &sinode, start, offset,
694 + sizeof(sinode), &start, &offset))
696 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
697 + } else if (!squashfs_get_cached_block(s, &inode, start, offset,
698 + sizeof(inode), &start, &offset))
701 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
706 + return SQUASHFS_INVALID_BLK;
710 +static void vfs_read_inode(struct inode *i)
712 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
713 + squashfs_inode_t inode = squashfs_inode_lookup(i->i_sb, i->i_ino);
715 + TRACE("Entered vfs_read_inode\n");
717 + if(inode != SQUASHFS_INVALID_BLK)
718 + (msblk->read_inode)(i, inode);
722 +static struct dentry *squashfs_get_parent(struct dentry *child)
724 + struct inode *i = child->d_inode;
725 + struct inode *parent = iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
728 + TRACE("Entered squashfs_get_parent\n");
730 + if(parent == NULL) {
731 + rv = ERR_PTR(-EACCES);
735 + rv = d_alloc_anon(parent);
737 + rv = ERR_PTR(-ENOMEM);
744 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,
745 + squashfs_inode_t inode, unsigned int inode_number)
747 + struct squashfs_sb_info *msblk = s->s_fs_info;
748 + struct inode *i = iget_locked(s, inode_number);
750 + TRACE("Entered squashfs_iget\n");
752 + if(i && (i->i_state & I_NEW)) {
753 + (msblk->read_inode)(i, inode);
754 + unlock_new_inode(i);
761 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
763 + struct super_block *s = i->i_sb;
764 + struct squashfs_sb_info *msblk = s->s_fs_info;
765 + struct squashfs_super_block *sblk = &msblk->sblk;
766 + long long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;
767 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
768 + long long next_block;
769 + unsigned int next_offset;
770 + union squashfs_inode_header id, sid;
771 + struct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;
773 + TRACE("Entered squashfs_read_inode\n");
776 + if (!squashfs_get_cached_block(s, sinodeb, block, offset,
777 + sizeof(*sinodeb), &next_block, &next_offset))
779 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));
781 + if (!squashfs_get_cached_block(s, inodeb, block, offset,
782 + sizeof(*inodeb), &next_block, &next_offset))
785 + squashfs_new_inode(msblk, i, inodeb);
787 + switch(inodeb->inode_type) {
788 + case SQUASHFS_FILE_TYPE: {
789 + unsigned int frag_size;
790 + long long frag_blk;
791 + struct squashfs_reg_inode_header *inodep = &id.reg;
792 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
795 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
796 + sizeof(*sinodep), &next_block, &next_offset))
798 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
800 + if (!squashfs_get_cached_block(s, inodep, block, offset,
801 + sizeof(*inodep), &next_block, &next_offset))
804 + frag_blk = SQUASHFS_INVALID_BLK;
806 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
807 + if(!get_fragment_location(s, inodep->fragment, &frag_blk,
812 + i->i_size = inodep->file_size;
813 + i->i_fop = &generic_ro_fops;
814 + i->i_mode |= S_IFREG;
815 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
816 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
817 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
818 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
819 + SQUASHFS_I(i)->start_block = inodep->start_block;
820 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
821 + SQUASHFS_I(i)->offset = next_offset;
822 + i->i_data.a_ops = &squashfs_aops;
824 + TRACE("File inode %x:%x, start_block %llx, "
825 + "block_list_start %llx, offset %x\n",
826 + SQUASHFS_INODE_BLK(inode), offset,
827 + inodep->start_block, next_block,
831 + case SQUASHFS_LREG_TYPE: {
832 + unsigned int frag_size;
833 + long long frag_blk;
834 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
835 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
838 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
839 + sizeof(*sinodep), &next_block, &next_offset))
841 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
843 + if (!squashfs_get_cached_block(s, inodep, block, offset,
844 + sizeof(*inodep), &next_block, &next_offset))
847 + frag_blk = SQUASHFS_INVALID_BLK;
849 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
850 + if (!get_fragment_location(s, inodep->fragment, &frag_blk,
854 + i->i_nlink = inodep->nlink;
855 + i->i_size = inodep->file_size;
856 + i->i_fop = &generic_ro_fops;
857 + i->i_mode |= S_IFREG;
858 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
859 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
860 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
861 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
862 + SQUASHFS_I(i)->start_block = inodep->start_block;
863 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
864 + SQUASHFS_I(i)->offset = next_offset;
865 + i->i_data.a_ops = &squashfs_aops;
867 + TRACE("File inode %x:%x, start_block %llx, "
868 + "block_list_start %llx, offset %x\n",
869 + SQUASHFS_INODE_BLK(inode), offset,
870 + inodep->start_block, next_block,
874 + case SQUASHFS_DIR_TYPE: {
875 + struct squashfs_dir_inode_header *inodep = &id.dir;
876 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
879 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
880 + sizeof(*sinodep), &next_block, &next_offset))
882 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
884 + if (!squashfs_get_cached_block(s, inodep, block, offset,
885 + sizeof(*inodep), &next_block, &next_offset))
888 + i->i_nlink = inodep->nlink;
889 + i->i_size = inodep->file_size;
890 + i->i_op = &squashfs_dir_inode_ops;
891 + i->i_fop = &squashfs_dir_ops;
892 + i->i_mode |= S_IFDIR;
893 + SQUASHFS_I(i)->start_block = inodep->start_block;
894 + SQUASHFS_I(i)->offset = inodep->offset;
895 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
896 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
898 + TRACE("Directory inode %x:%x, start_block %x, offset "
899 + "%x\n", SQUASHFS_INODE_BLK(inode),
900 + offset, inodep->start_block,
904 + case SQUASHFS_LDIR_TYPE: {
905 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
906 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
909 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
910 + sizeof(*sinodep), &next_block, &next_offset))
912 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);
914 + if (!squashfs_get_cached_block(s, inodep, block, offset,
915 + sizeof(*inodep), &next_block, &next_offset))
918 + i->i_nlink = inodep->nlink;
919 + i->i_size = inodep->file_size;
920 + i->i_op = &squashfs_dir_inode_ops;
921 + i->i_fop = &squashfs_dir_ops;
922 + i->i_mode |= S_IFDIR;
923 + SQUASHFS_I(i)->start_block = inodep->start_block;
924 + SQUASHFS_I(i)->offset = inodep->offset;
925 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
926 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
927 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;
928 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
930 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n",
931 + SQUASHFS_INODE_BLK(inode), offset,
932 + inodep->start_block, inodep->offset);
935 + case SQUASHFS_SYMLINK_TYPE: {
936 + struct squashfs_symlink_inode_header *inodep = &id.symlink;
937 + struct squashfs_symlink_inode_header *sinodep = &sid.symlink;
940 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
941 + sizeof(*sinodep), &next_block, &next_offset))
943 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);
945 + if (!squashfs_get_cached_block(s, inodep, block, offset,
946 + sizeof(*inodep), &next_block, &next_offset))
949 + i->i_nlink = inodep->nlink;
950 + i->i_size = inodep->symlink_size;
951 + i->i_op = &page_symlink_inode_operations;
952 + i->i_data.a_ops = &squashfs_symlink_aops;
953 + i->i_mode |= S_IFLNK;
954 + SQUASHFS_I(i)->start_block = next_block;
955 + SQUASHFS_I(i)->offset = next_offset;
957 + TRACE("Symbolic link inode %x:%x, start_block %llx, offset %x\n",
958 + SQUASHFS_INODE_BLK(inode), offset,
959 + next_block, next_offset);
962 + case SQUASHFS_BLKDEV_TYPE:
963 + case SQUASHFS_CHRDEV_TYPE: {
964 + struct squashfs_dev_inode_header *inodep = &id.dev;
965 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
968 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
969 + sizeof(*sinodep), &next_block, &next_offset))
971 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
973 + if (!squashfs_get_cached_block(s, inodep, block, offset,
974 + sizeof(*inodep), &next_block, &next_offset))
977 + i->i_nlink = inodep->nlink;
978 + i->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?
980 + init_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));
982 + TRACE("Device inode %x:%x, rdev %x\n",
983 + SQUASHFS_INODE_BLK(inode), offset, inodep->rdev);
986 + case SQUASHFS_FIFO_TYPE:
987 + case SQUASHFS_SOCKET_TYPE: {
988 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
989 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
992 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
993 + sizeof(*sinodep), &next_block, &next_offset))
995 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
997 + if (!squashfs_get_cached_block(s, inodep, block, offset,
998 + sizeof(*inodep), &next_block, &next_offset))
1001 + i->i_nlink = inodep->nlink;
1002 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
1003 + ? S_IFIFO : S_IFSOCK;
1004 + init_special_inode(i, i->i_mode, 0);
1008 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1009 + inodeb->inode_type);
1010 + goto failed_read1;
1016 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1019 + make_bad_inode(i);
1024 +static int read_inode_lookup_table(struct super_block *s)
1026 + struct squashfs_sb_info *msblk = s->s_fs_info;
1027 + struct squashfs_super_block *sblk = &msblk->sblk;
1028 + unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1030 + TRACE("In read_inode_lookup_table, length %d\n", length);
1032 + /* Allocate inode lookup table */
1033 + msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);
1034 + if (msblk->inode_lookup_table == NULL) {
1035 + ERROR("Failed to allocate inode lookup table\n");
1039 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1040 + sblk->lookup_table_start, length |
1041 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1042 + ERROR("unable to read inode lookup table\n");
1046 + if (msblk->swap) {
1050 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1052 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1053 + &msblk->inode_lookup_table[i], 1);
1054 + msblk->inode_lookup_table[i] = block;
1062 +static int read_fragment_index_table(struct super_block *s)
1064 + struct squashfs_sb_info *msblk = s->s_fs_info;
1065 + struct squashfs_super_block *sblk = &msblk->sblk;
1066 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1071 + /* Allocate fragment index table */
1072 + msblk->fragment_index = kmalloc(length, GFP_KERNEL);
1073 + if (msblk->fragment_index == NULL) {
1074 + ERROR("Failed to allocate fragment index table\n");
1078 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1079 + sblk->fragment_table_start, length |
1080 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1081 + ERROR("unable to read fragment index table\n");
1085 + if (msblk->swap) {
1087 + long long fragment;
1089 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1091 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1092 + &msblk->fragment_index[i], 1);
1093 + msblk->fragment_index[i] = fragment;
1101 +static int readahead_metadata(struct super_block *s)
1103 + struct squashfs_sb_info *msblk = s->s_fs_info;
1106 + squashfs_cached_blks = SQUASHFS_CACHED_BLKS;
1108 + /* Init inode_table block pointer array */
1109 + msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1110 + squashfs_cached_blks, GFP_KERNEL);
1111 + if (msblk->block_cache == NULL) {
1112 + ERROR("Failed to allocate block cache\n");
1116 + for (i = 0; i < squashfs_cached_blks; i++)
1117 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1119 + msblk->next_cache = 0;
1120 + msblk->unused_cache_blks = squashfs_cached_blks;
1129 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1131 + struct squashfs_super_block *sblk = &msblk->sblk;
1133 + msblk->read_inode = squashfs_read_inode;
1134 + msblk->read_blocklist = read_blocklist;
1135 + msblk->read_fragment_index_table = read_fragment_index_table;
1137 + if (sblk->s_major == 1) {
1138 + if (!squashfs_1_0_supported(msblk)) {
1139 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1140 + "are unsupported\n");
1141 + SERROR("Please recompile with Squashfs 1.0 support enabled\n");
1144 + } else if (sblk->s_major == 2) {
1145 + if (!squashfs_2_0_supported(msblk)) {
1146 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1147 + "are unsupported\n");
1148 + SERROR("Please recompile with Squashfs 2.0 support enabled\n");
1151 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1153 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1154 + "filesystem\n", sblk->s_major, sblk->s_minor);
1155 + SERROR("Please update your kernel\n");
1163 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1165 + struct squashfs_sb_info *msblk;
1166 + struct squashfs_super_block *sblk;
1168 + char b[BDEVNAME_SIZE];
1169 + struct inode *root;
1171 + TRACE("Entered squashfs_fill_superblock\n");
1173 + s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1174 + if (s->s_fs_info == NULL) {
1175 + ERROR("Failed to allocate superblock\n");
1178 + msblk = s->s_fs_info;
1180 + msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1181 + if (msblk->stream.workspace == NULL) {
1182 + ERROR("Failed to allocate zlib workspace\n");
1185 + sblk = &msblk->sblk;
1187 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1188 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1190 + mutex_init(&msblk->read_data_mutex);
1191 + mutex_init(&msblk->read_page_mutex);
1192 + mutex_init(&msblk->block_cache_mutex);
1193 + mutex_init(&msblk->fragment_mutex);
1194 + mutex_init(&msblk->meta_index_mutex);
1196 + init_waitqueue_head(&msblk->waitq);
1197 + init_waitqueue_head(&msblk->fragment_wait_queue);
1199 + /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1200 + * beyond filesystem end. As we're using squashfs_read_data to read sblk here,
1201 + * first set sblk->bytes_used to a useful value */
1202 + sblk->bytes_used = sizeof(struct squashfs_super_block);
1203 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1204 + sizeof(struct squashfs_super_block) |
1205 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1206 + SERROR("unable to read superblock\n");
1207 + goto failed_mount;
1210 + /* Check it is a SQUASHFS superblock */
1211 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1212 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1213 + struct squashfs_super_block ssblk;
1215 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1216 + bdevname(s->s_bdev, b));
1218 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1219 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1222 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1223 + bdevname(s->s_bdev, b));
1224 + goto failed_mount;
1228 + /* Check the MAJOR & MINOR versions */
1229 + if(!supported_squashfs_filesystem(msblk, silent))
1230 + goto failed_mount;
1232 + /* Check the filesystem does not extend beyond the end of the
1234 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1235 + goto failed_mount;
1237 + /* Check the root inode for sanity */
1238 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1239 + goto failed_mount;
1241 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1242 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)
1244 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1246 + TRACE("Check data is %spresent in the filesystem\n",
1247 + SQUASHFS_CHECK_DATA(sblk->flags) ? "" : "not ");
1248 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1249 + TRACE("Block size %d\n", sblk->block_size);
1250 + TRACE("Number of inodes %d\n", sblk->inodes);
1251 + if (sblk->s_major > 1)
1252 + TRACE("Number of fragments %d\n", sblk->fragments);
1253 + TRACE("Number of uids %d\n", sblk->no_uids);
1254 + TRACE("Number of gids %d\n", sblk->no_guids);
1255 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1256 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1257 + if (sblk->s_major > 1)
1258 + TRACE("sblk->fragment_table_start %llx\n", sblk->fragment_table_start);
1259 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1261 + s->s_maxbytes = MAX_LFS_FILESIZE;
1262 + s->s_flags |= MS_RDONLY;
1263 + s->s_op = &squashfs_super_ops;
1265 + if (readahead_metadata(s) == 0)
1266 + goto failed_mount;
1268 + /* Allocate read_page block */
1269 + msblk->read_page = vmalloc(sblk->block_size);
1270 + if (msblk->read_page == NULL) {
1271 + ERROR("Failed to allocate read_page block\n");
1272 + goto failed_mount;
1275 + /* Allocate uid and gid tables */
1276 + msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1277 + sizeof(unsigned int), GFP_KERNEL);
1278 + if (msblk->uid == NULL) {
1279 + ERROR("Failed to allocate uid/gid table\n");
1280 + goto failed_mount;
1282 + msblk->guid = msblk->uid + sblk->no_uids;
1284 + if (msblk->swap) {
1285 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1287 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1288 + ((sblk->no_uids + sblk->no_guids) *
1289 + sizeof(unsigned int)) |
1290 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1291 + ERROR("unable to read uid/gid table\n");
1292 + goto failed_mount;
1295 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1296 + sblk->no_guids), (sizeof(unsigned int) * 8));
1298 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1299 + ((sblk->no_uids + sblk->no_guids) *
1300 + sizeof(unsigned int)) |
1301 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1302 + ERROR("unable to read uid/gid table\n");
1303 + goto failed_mount;
1307 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1308 + goto allocate_root;
1310 + msblk->fragment = kzalloc(sizeof(struct squashfs_fragment_cache) *
1311 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL);
1312 + if (msblk->fragment == NULL) {
1313 + ERROR("Failed to allocate fragment block cache\n");
1314 + goto failed_mount;
1317 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1318 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1321 + msblk->next_fragment = 0;
1322 + msblk->unused_frag_blks = SQUASHFS_CACHED_FRAGMENTS;
1324 + /* Allocate and read fragment index table */
1325 + if (msblk->read_fragment_index_table(s) == 0)
1326 + goto failed_mount;
1328 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1329 + goto allocate_root;
1331 + /* Allocate and read inode lookup table */
1332 + if (read_inode_lookup_table(s) == 0)
1333 + goto failed_mount;
1335 + s->s_op = &squashfs_export_super_ops;
1336 + s->s_export_op = &squashfs_export_ops;
1339 + root = new_inode(s);
1340 + if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1341 + goto failed_mount;
1342 + insert_inode_hash(root);
1344 + s->s_root = d_alloc_root(root);
1345 + if (s->s_root == NULL) {
1346 + ERROR("Root inode create failed\n");
1348 + goto failed_mount;
1351 + TRACE("Leaving squashfs_fill_super\n");
1355 + kfree(msblk->inode_lookup_table);
1356 + kfree(msblk->fragment_index);
1357 + kfree(msblk->fragment);
1358 + kfree(msblk->uid);
1359 + vfree(msblk->read_page);
1360 + kfree(msblk->block_cache);
1361 + kfree(msblk->fragment_index_2);
1362 + vfree(msblk->stream.workspace);
1363 + kfree(s->s_fs_info);
1364 + s->s_fs_info = NULL;
1372 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1374 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1375 + struct squashfs_super_block *sblk = &msblk->sblk;
1377 + TRACE("Entered squashfs_statfs\n");
1379 + buf->f_type = SQUASHFS_MAGIC;
1380 + buf->f_bsize = sblk->block_size;
1381 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1382 + buf->f_bfree = buf->f_bavail = 0;
1383 + buf->f_files = sblk->inodes;
1385 + buf->f_namelen = SQUASHFS_NAME_LEN;
1391 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1393 + struct inode *inode = page->mapping->host;
1394 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;
1395 + long long block = SQUASHFS_I(inode)->start_block;
1396 + int offset = SQUASHFS_I(inode)->offset;
1397 + void *pageaddr = kmap(page);
1399 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1400 + "%llx, offset %x\n", page->index,
1401 + SQUASHFS_I(inode)->start_block,
1402 + SQUASHFS_I(inode)->offset);
1404 + for (length = 0; length < index; length += bytes) {
1405 + bytes = squashfs_get_cached_block(inode->i_sb, NULL, block,
1406 + offset, PAGE_CACHE_SIZE, &block, &offset);
1408 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1413 + if (length != index) {
1414 + ERROR("(squashfs_symlink_readpage) length != index\n");
1419 + avail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);
1421 + bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,
1422 + avail_bytes, &block, &offset);
1424 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1427 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1429 + flush_dcache_page(page);
1430 + SetPageUptodate(page);
1431 + unlock_page(page);
1437 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1439 + struct meta_index *meta = NULL;
1440 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1443 + mutex_lock(&msblk->meta_index_mutex);
1445 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1447 + if (msblk->meta_index == NULL)
1448 + goto not_allocated;
1450 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++) {
1451 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1452 + msblk->meta_index[i].offset >= offset &&
1453 + msblk->meta_index[i].offset <= index &&
1454 + msblk->meta_index[i].locked == 0) {
1455 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1456 + msblk->meta_index[i].offset);
1457 + meta = &msblk->meta_index[i];
1458 + offset = meta->offset;
1466 + mutex_unlock(&msblk->meta_index_mutex);
1472 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1474 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1475 + struct meta_index *meta = NULL;
1478 + mutex_lock(&msblk->meta_index_mutex);
1480 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1482 + if (msblk->meta_index == NULL) {
1483 + msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1484 + SQUASHFS_META_NUMBER, GFP_KERNEL);
1485 + if (msblk->meta_index == NULL) {
1486 + ERROR("Failed to allocate meta_index\n");
1489 + for (i = 0; i < SQUASHFS_META_NUMBER; i++) {
1490 + msblk->meta_index[i].inode_number = 0;
1491 + msblk->meta_index[i].locked = 0;
1493 + msblk->next_meta_index = 0;
1496 + for (i = SQUASHFS_META_NUMBER; i &&
1497 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1498 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1499 + SQUASHFS_META_NUMBER;
1502 + TRACE("empty_meta_index: failed!\n");
1506 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1507 + msblk->next_meta_index,
1508 + &msblk->meta_index[msblk->next_meta_index]);
1510 + meta = &msblk->meta_index[msblk->next_meta_index];
1511 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1512 + SQUASHFS_META_NUMBER;
1514 + meta->inode_number = inode->i_ino;
1515 + meta->offset = offset;
1516 + meta->skip = skip;
1517 + meta->entries = 0;
1521 + mutex_unlock(&msblk->meta_index_mutex);
1526 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1533 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1534 + long long *start_block, int *offset)
1536 + struct squashfs_sb_info *msblk = s->s_fs_info;
1537 + unsigned int *block_listp;
1540 + if (msblk->swap) {
1541 + char sblock_list[blocks << 2];
1543 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1544 + *offset, blocks << 2, start_block, offset)) {
1545 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1548 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1549 + ((unsigned int *)sblock_list), blocks);
1551 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1552 + *offset, blocks << 2, start_block, offset)) {
1553 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1558 + for (block_listp = (unsigned int *) block_list; blocks;
1559 + block_listp++, blocks --)
1560 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1571 +static inline int calculate_skip(int blocks) {
1572 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1573 + return skip >= 7 ? 7 : skip + 1;
1577 +static int get_meta_index(struct inode *inode, int index,
1578 + long long *index_block, int *index_offset,
1579 + long long *data_block, char *block_list)
1581 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1582 + struct squashfs_super_block *sblk = &msblk->sblk;
1583 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1585 + struct meta_index *meta;
1586 + struct meta_entry *meta_entry;
1587 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1588 + int cur_offset = SQUASHFS_I(inode)->offset;
1589 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1592 + index /= SQUASHFS_META_INDEXES * skip;
1594 + while (offset < index) {
1595 + meta = locate_meta_index(inode, index, offset + 1);
1597 + if (meta == NULL) {
1598 + meta = empty_meta_index(inode, offset + 1, skip);
1602 + if(meta->entries == 0)
1605 + offset = index < meta->offset + meta->entries ? index :
1606 + meta->offset + meta->entries - 1;
1608 + meta_entry = &meta->meta_entry[offset - meta->offset];
1609 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1610 + cur_offset = meta_entry->offset;
1611 + cur_data_block = meta_entry->data_block;
1612 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1613 + "meta->entries %d\n", offset, meta->offset, meta->entries);
1614 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1615 + " data_block 0x%llx\n", cur_index_block,
1616 + cur_offset, cur_data_block);
1619 + for (i = meta->offset + meta->entries; i <= index &&
1620 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1621 + int blocks = skip * SQUASHFS_META_INDEXES;
1624 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;
1625 + int res = read_block_index(inode->i_sb, block, block_list,
1626 + &cur_index_block, &cur_offset);
1631 + cur_data_block += res;
1635 + meta_entry = &meta->meta_entry[i - meta->offset];
1636 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1637 + meta_entry->offset = cur_offset;
1638 + meta_entry->data_block = cur_data_block;
1643 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1644 + meta->offset, meta->entries);
1646 + release_meta_index(inode, meta);
1650 + *index_block = cur_index_block;
1651 + *index_offset = cur_offset;
1652 + *data_block = cur_data_block;
1654 + return offset * SQUASHFS_META_INDEXES * skip;
1657 + release_meta_index(inode, meta);
1662 +static long long read_blocklist(struct inode *inode, int index,
1663 + int readahead_blks, char *block_list,
1664 + unsigned short **block_p, unsigned int *bsize)
1666 + long long block_ptr;
1669 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1672 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1673 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset, block);
1681 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1682 + int res = read_block_index(inode->i_sb, blocks, block_list,
1683 + &block_ptr, &offset);
1690 + if (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)
1692 + *bsize = *((unsigned int *) block_list);
1701 +static int squashfs_readpage(struct file *file, struct page *page)
1703 + struct inode *inode = page->mapping->host;
1704 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1705 + struct squashfs_super_block *sblk = &msblk->sblk;
1706 + unsigned char *block_list = NULL;
1708 + unsigned int bsize, i;
1710 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1712 + struct squashfs_fragment_cache *fragment = NULL;
1713 + char *data_ptr = msblk->read_page;
1715 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1716 + int start_index = page->index & ~mask;
1717 + int end_index = start_index | mask;
1718 + int file_end = i_size_read(inode) >> sblk->block_log;
1721 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1722 + page->index, SQUASHFS_I(inode)->start_block);
1724 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1725 + PAGE_CACHE_SHIFT))
1728 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1729 + || index < file_end) {
1730 + block_list = kmalloc(SIZE, GFP_KERNEL);
1731 + if (block_list == NULL) {
1732 + ERROR("Failed to allocate block_list\n");
1736 + block = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);
1740 + if (bsize == 0) { /* hole */
1741 + bytes = index == file_end ?
1742 + (i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;
1745 + mutex_lock(&msblk->read_page_mutex);
1747 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1748 + bsize, NULL, sblk->block_size);
1751 + ERROR("Unable to read page, block %llx, size %x\n", block, bsize);
1752 + mutex_unlock(&msblk->read_page_mutex);
1757 + fragment = get_cached_fragment(inode->i_sb,
1758 + SQUASHFS_I(inode)-> u.s1.fragment_start_block,
1759 + SQUASHFS_I(inode)->u.s1.fragment_size);
1761 + if (fragment == NULL) {
1762 + ERROR("Unable to read page, block %llx, size %x\n",
1763 + SQUASHFS_I(inode)->u.s1.fragment_start_block,
1764 + (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1767 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1768 + data_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;
1771 + for (i = start_index; i <= end_index && bytes > 0; i++,
1772 + bytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {
1773 + struct page *push_page;
1774 + int avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);
1776 + TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
1778 + push_page = (i == page->index) ? page :
1779 + grab_cache_page_nowait(page->mapping, i);
1784 + if (PageUptodate(push_page))
1787 + pageaddr = kmap_atomic(push_page, KM_USER0);
1788 + memcpy(pageaddr, data_ptr, avail);
1789 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1790 + kunmap_atomic(pageaddr, KM_USER0);
1791 + flush_dcache_page(push_page);
1792 + SetPageUptodate(push_page);
1794 + unlock_page(push_page);
1795 + if(i != page->index)
1796 + page_cache_release(push_page);
1799 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1800 + || index < file_end) {
1802 + mutex_unlock(&msblk->read_page_mutex);
1803 + kfree(block_list);
1805 + release_cached_fragment(msblk, fragment);
1810 + SetPageError(page);
1812 + pageaddr = kmap_atomic(page, KM_USER0);
1813 + memset(pageaddr, 0, PAGE_CACHE_SIZE);
1814 + kunmap_atomic(pageaddr, KM_USER0);
1815 + flush_dcache_page(page);
1816 + if (!PageError(page))
1817 + SetPageUptodate(page);
1818 + unlock_page(page);
1820 + kfree(block_list);
1825 +static int get_dir_index_using_offset(struct super_block *s,
1826 + long long *next_block, unsigned int *next_offset,
1827 + long long index_start, unsigned int index_offset, int i_count,
1830 + struct squashfs_sb_info *msblk = s->s_fs_info;
1831 + struct squashfs_super_block *sblk = &msblk->sblk;
1832 + int i, length = 0;
1833 + struct squashfs_dir_index index;
1835 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1836 + i_count, (unsigned int) f_pos);
1842 + for (i = 0; i < i_count; i++) {
1843 + if (msblk->swap) {
1844 + struct squashfs_dir_index sindex;
1845 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1846 + sizeof(sindex), &index_start, &index_offset);
1847 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1849 + squashfs_get_cached_block(s, &index, index_start, index_offset,
1850 + sizeof(index), &index_start, &index_offset);
1852 + if (index.index > f_pos)
1855 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1856 + index.size + 1, &index_start, &index_offset);
1858 + length = index.index;
1859 + *next_block = index.start_block + sblk->directory_table_start;
1862 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1865 + return length + 3;
1869 +static int get_dir_index_using_name(struct super_block *s,
1870 + long long *next_block, unsigned int *next_offset,
1871 + long long index_start, unsigned int index_offset, int i_count,
1872 + const char *name, int size)
1874 + struct squashfs_sb_info *msblk = s->s_fs_info;
1875 + struct squashfs_super_block *sblk = &msblk->sblk;
1876 + int i, length = 0;
1877 + struct squashfs_dir_index *index;
1880 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1882 + str = kmalloc(sizeof(struct squashfs_dir_index) +
1883 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);
1884 + if (str == NULL) {
1885 + ERROR("Failed to allocate squashfs_dir_index\n");
1889 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1890 + strncpy(str, name, size);
1893 + for (i = 0; i < i_count; i++) {
1894 + if (msblk->swap) {
1895 + struct squashfs_dir_index sindex;
1896 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1897 + sizeof(sindex), &index_start, &index_offset);
1898 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1900 + squashfs_get_cached_block(s, index, index_start, index_offset,
1901 + sizeof(struct squashfs_dir_index), &index_start, &index_offset);
1903 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1904 + index->size + 1, &index_start, &index_offset);
1906 + index->name[index->size + 1] = '\0';
1908 + if (strcmp(index->name, str) > 0)
1911 + length = index->index;
1912 + *next_block = index->start_block + sblk->directory_table_start;
1915 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1919 + return length + 3;
1923 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1925 + struct inode *i = file->f_dentry->d_inode;
1926 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1927 + struct squashfs_super_block *sblk = &msblk->sblk;
1928 + long long next_block = SQUASHFS_I(i)->start_block +
1929 + sblk->directory_table_start;
1930 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
1931 + struct squashfs_dir_header dirh;
1932 + struct squashfs_dir_entry *dire;
1934 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1936 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1937 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
1938 + if (dire == NULL) {
1939 + ERROR("Failed to allocate squashfs_dir_entry\n");
1943 + while(file->f_pos < 3) {
1947 + if(file->f_pos == 0) {
1954 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1956 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1957 + (unsigned int) dirent, name, size, (int)
1958 + file->f_pos, i_ino, squashfs_filetype_table[1]);
1960 + if (filldir(dirent, name, size, file->f_pos, i_ino,
1961 + squashfs_filetype_table[1]) < 0) {
1962 + TRACE("Filldir returned less than 0\n");
1965 + file->f_pos += size;
1968 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1969 + SQUASHFS_I(i)->u.s2.directory_index_start,
1970 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1971 + SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1973 + while (length < i_size_read(i)) {
1974 + /* read directory header */
1975 + if (msblk->swap) {
1976 + struct squashfs_dir_header sdirh;
1978 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
1979 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1982 + length += sizeof(sdirh);
1983 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1985 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
1986 + next_offset, sizeof(dirh), &next_block, &next_offset))
1989 + length += sizeof(dirh);
1992 + dir_count = dirh.count + 1;
1993 + while (dir_count--) {
1994 + if (msblk->swap) {
1995 + struct squashfs_dir_entry sdire;
1996 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
1997 + next_offset, sizeof(sdire), &next_block, &next_offset))
2000 + length += sizeof(sdire);
2001 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2003 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2004 + next_offset, sizeof(*dire), &next_block, &next_offset))
2007 + length += sizeof(*dire);
2010 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2011 + next_offset, dire->size + 1, &next_block, &next_offset))
2014 + length += dire->size + 1;
2016 + if (file->f_pos >= length)
2019 + dire->name[dire->size + 1] = '\0';
2021 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2022 + (unsigned int) dirent, dire->name, dire->size + 1,
2023 + (int) file->f_pos, dirh.start_block, dire->offset,
2024 + dirh.inode_number + dire->inode_number,
2025 + squashfs_filetype_table[dire->type]);
2027 + if (filldir(dirent, dire->name, dire->size + 1, file->f_pos,
2028 + dirh.inode_number + dire->inode_number,
2029 + squashfs_filetype_table[dire->type]) < 0) {
2030 + TRACE("Filldir returned less than 0\n");
2033 + file->f_pos = length;
2042 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2049 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2050 + struct nameidata *nd)
2052 + const unsigned char *name = dentry->d_name.name;
2053 + int len = dentry->d_name.len;
2054 + struct inode *inode = NULL;
2055 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2056 + struct squashfs_super_block *sblk = &msblk->sblk;
2057 + long long next_block = SQUASHFS_I(i)->start_block +
2058 + sblk->directory_table_start;
2059 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
2060 + struct squashfs_dir_header dirh;
2061 + struct squashfs_dir_entry *dire;
2063 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2065 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2066 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
2067 + if (dire == NULL) {
2068 + ERROR("Failed to allocate squashfs_dir_entry\n");
2072 + if (len > SQUASHFS_NAME_LEN)
2075 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2076 + SQUASHFS_I(i)->u.s2.directory_index_start,
2077 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2078 + SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
2080 + while (length < i_size_read(i)) {
2081 + /* read directory header */
2082 + if (msblk->swap) {
2083 + struct squashfs_dir_header sdirh;
2084 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
2085 + next_offset, sizeof(sdirh), &next_block, &next_offset))
2088 + length += sizeof(sdirh);
2089 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2091 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2092 + next_offset, sizeof(dirh), &next_block, &next_offset))
2095 + length += sizeof(dirh);
2098 + dir_count = dirh.count + 1;
2099 + while (dir_count--) {
2100 + if (msblk->swap) {
2101 + struct squashfs_dir_entry sdire;
2102 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2103 + next_offset, sizeof(sdire), &next_block, &next_offset))
2106 + length += sizeof(sdire);
2107 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2109 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2110 + next_offset, sizeof(*dire), &next_block, &next_offset))
2113 + length += sizeof(*dire);
2116 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2117 + next_offset, dire->size + 1, &next_block, &next_offset))
2120 + length += dire->size + 1;
2122 + if (name[0] < dire->name[0])
2125 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2126 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2129 + TRACE("calling squashfs_iget for directory entry %s, inode"
2130 + " %x:%x, %d\n", name, dirh.start_block, dire->offset,
2131 + dirh.inode_number + dire->inode_number);
2133 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2143 + return d_splice_alias(inode, dentry);
2144 + d_add(dentry, inode);
2145 + return ERR_PTR(0);
2148 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2154 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
2156 + *flags |= MS_RDONLY;
2161 +static void squashfs_put_super(struct super_block *s)
2165 + if (s->s_fs_info) {
2166 + struct squashfs_sb_info *sbi = s->s_fs_info;
2167 + if (sbi->block_cache)
2168 + for (i = 0; i < squashfs_cached_blks; i++)
2169 + if (sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)
2170 + vfree(sbi->block_cache[i].data);
2171 + if (sbi->fragment)
2172 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2173 + vfree(sbi->fragment[i].data);
2174 + kfree(sbi->fragment);
2175 + kfree(sbi->block_cache);
2176 + vfree(sbi->read_page);
2178 + kfree(sbi->fragment_index);
2179 + kfree(sbi->fragment_index_2);
2180 + kfree(sbi->meta_index);
2181 + vfree(sbi->stream.workspace);
2182 + kfree(s->s_fs_info);
2183 + s->s_fs_info = NULL;
2188 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2189 + const char *dev_name, void *data, struct vfsmount *mnt)
2191 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2196 +static int __init init_squashfs_fs(void)
2198 + int err = init_inodecache();
2202 + printk(KERN_INFO "squashfs: version 3.3 (2007/10/31) "
2203 + "Phillip Lougher\n");
2205 + err = register_filesystem(&squashfs_fs_type);
2207 + destroy_inodecache();
2214 +static void __exit exit_squashfs_fs(void)
2216 + unregister_filesystem(&squashfs_fs_type);
2217 + destroy_inodecache();
2221 +static struct kmem_cache * squashfs_inode_cachep;
2224 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2226 + struct squashfs_inode_info *ei;
2227 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2228 + return ei ? &ei->vfs_inode : NULL;
2232 +static void squashfs_destroy_inode(struct inode *inode)
2234 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2238 +static void init_once(struct kmem_cache *cachep, void *foo)
2240 + struct squashfs_inode_info *ei = foo;
2242 + inode_init_once(&ei->vfs_inode);
2246 +static int __init init_inodecache(void)
2248 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2249 + sizeof(struct squashfs_inode_info), 0,
2250 + SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);
2251 + if (squashfs_inode_cachep == NULL)
2257 +static void destroy_inodecache(void)
2259 + kmem_cache_destroy(squashfs_inode_cachep);
2263 +module_init(init_squashfs_fs);
2264 +module_exit(exit_squashfs_fs);
2265 +MODULE_DESCRIPTION("squashfs 3.2-r2-CVS, a compressed read-only filesystem");
2266 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2267 +MODULE_LICENSE("GPL");
2268 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/Makefile linux-2.6.24-squashfs3.3/fs/squashfs/Makefile
2269 --- linux-2.6.24/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
2270 +++ linux-2.6.24-squashfs3.3/fs/squashfs/Makefile 2005-11-20 14:31:00.000000000 +0000
2273 +# Makefile for the linux squashfs routines.
2276 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2277 +squashfs-y += inode.o
2278 +squashfs-y += squashfs2_0.o
2279 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs2_0.c linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c
2280 --- linux-2.6.24/fs/squashfs/squashfs2_0.c 1970-01-01 01:00:00.000000000 +0100
2281 +++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs2_0.c 2007-10-25 00:43:59.000000000 +0100
2284 + * Squashfs - a compressed read only filesystem for Linux
2286 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
2287 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2289 + * This program is free software; you can redistribute it and/or
2290 + * modify it under the terms of the GNU General Public License
2291 + * as published by the Free Software Foundation; either version 2,
2292 + * or (at your option) any later version.
2294 + * This program is distributed in the hope that it will be useful,
2295 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2296 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2297 + * GNU General Public License for more details.
2299 + * You should have received a copy of the GNU General Public License
2300 + * along with this program; if not, write to the Free Software
2301 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2306 +#include <linux/squashfs_fs.h>
2307 +#include <linux/module.h>
2308 +#include <linux/zlib.h>
2309 +#include <linux/fs.h>
2310 +#include <linux/squashfs_fs_sb.h>
2311 +#include <linux/squashfs_fs_i.h>
2313 +#include "squashfs.h"
2314 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2315 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2316 + struct nameidata *);
2318 +static struct file_operations squashfs_dir_ops_2 = {
2319 + .read = generic_read_dir,
2320 + .readdir = squashfs_readdir_2
2323 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2324 + .lookup = squashfs_lookup_2
2327 +static unsigned char squashfs_filetype_table[] = {
2328 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2331 +static int read_fragment_index_table_2(struct super_block *s)
2333 + struct squashfs_sb_info *msblk = s->s_fs_info;
2334 + struct squashfs_super_block *sblk = &msblk->sblk;
2336 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2337 + (sblk->fragments), GFP_KERNEL))) {
2338 + ERROR("Failed to allocate uid/gid table\n");
2342 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2343 + !squashfs_read_data(s, (char *)
2344 + msblk->fragment_index_2,
2345 + sblk->fragment_table_start,
2346 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2347 + (sblk->fragments) |
2348 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2349 + ERROR("unable to read fragment index table\n");
2353 + if (msblk->swap) {
2355 + unsigned int fragment;
2357 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2359 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2360 + &msblk->fragment_index_2[i], 1);
2361 + msblk->fragment_index_2[i] = fragment;
2369 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2370 + long long *fragment_start_block,
2371 + unsigned int *fragment_size)
2373 + struct squashfs_sb_info *msblk = s->s_fs_info;
2374 + long long start_block =
2375 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2376 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2377 + struct squashfs_fragment_entry_2 fragment_entry;
2379 + if (msblk->swap) {
2380 + struct squashfs_fragment_entry_2 sfragment_entry;
2382 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2383 + start_block, offset,
2384 + sizeof(sfragment_entry), &start_block,
2387 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2389 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2390 + start_block, offset,
2391 + sizeof(fragment_entry), &start_block,
2395 + *fragment_start_block = fragment_entry.start_block;
2396 + *fragment_size = fragment_entry.size;
2405 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2406 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2408 + struct squashfs_super_block *sblk = &msblk->sblk;
2411 + i->i_mtime.tv_sec = sblk->mkfs_time;
2412 + i->i_atime.tv_sec = sblk->mkfs_time;
2413 + i->i_ctime.tv_sec = sblk->mkfs_time;
2414 + i->i_uid = msblk->uid[inodeb->uid];
2415 + i->i_mode = inodeb->mode;
2418 + if (inodeb->guid == SQUASHFS_GUIDS)
2419 + i->i_gid = i->i_uid;
2421 + i->i_gid = msblk->guid[inodeb->guid];
2425 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2427 + struct super_block *s = i->i_sb;
2428 + struct squashfs_sb_info *msblk = s->s_fs_info;
2429 + struct squashfs_super_block *sblk = &msblk->sblk;
2430 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2431 + sblk->inode_table_start;
2432 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2433 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block -
2434 + sblk->inode_table_start, offset);
2435 + long long next_block;
2436 + unsigned int next_offset;
2437 + union squashfs_inode_header_2 id, sid;
2438 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2439 + *sinodeb = &sid.base;
2441 + TRACE("Entered squashfs_read_inode_2\n");
2443 + if (msblk->swap) {
2444 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2445 + offset, sizeof(*sinodeb), &next_block,
2448 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2449 + sizeof(*sinodeb));
2451 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2452 + offset, sizeof(*inodeb), &next_block,
2456 + squashfs_new_inode(msblk, i, inodeb, ino);
2458 + switch(inodeb->inode_type) {
2459 + case SQUASHFS_FILE_TYPE: {
2460 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2461 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2462 + long long frag_blk;
2463 + unsigned int frag_size = 0;
2465 + if (msblk->swap) {
2466 + if (!squashfs_get_cached_block(s, (char *)
2467 + sinodep, block, offset,
2468 + sizeof(*sinodep), &next_block,
2471 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2473 + if (!squashfs_get_cached_block(s, (char *)
2474 + inodep, block, offset,
2475 + sizeof(*inodep), &next_block,
2479 + frag_blk = SQUASHFS_INVALID_BLK;
2480 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2481 + !get_fragment_location_2(s,
2482 + inodep->fragment, &frag_blk, &frag_size))
2485 + i->i_size = inodep->file_size;
2486 + i->i_fop = &generic_ro_fops;
2487 + i->i_mode |= S_IFREG;
2488 + i->i_mtime.tv_sec = inodep->mtime;
2489 + i->i_atime.tv_sec = inodep->mtime;
2490 + i->i_ctime.tv_sec = inodep->mtime;
2491 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2492 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2493 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2494 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2495 + SQUASHFS_I(i)->start_block = inodep->start_block;
2496 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2497 + SQUASHFS_I(i)->offset = next_offset;
2498 + i->i_data.a_ops = &squashfs_aops;
2500 + TRACE("File inode %x:%x, start_block %x, "
2501 + "block_list_start %llx, offset %x\n",
2502 + SQUASHFS_INODE_BLK(inode), offset,
2503 + inodep->start_block, next_block,
2507 + case SQUASHFS_DIR_TYPE: {
2508 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2509 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2511 + if (msblk->swap) {
2512 + if (!squashfs_get_cached_block(s, (char *)
2513 + sinodep, block, offset,
2514 + sizeof(*sinodep), &next_block,
2517 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2519 + if (!squashfs_get_cached_block(s, (char *)
2520 + inodep, block, offset,
2521 + sizeof(*inodep), &next_block,
2525 + i->i_size = inodep->file_size;
2526 + i->i_op = &squashfs_dir_inode_ops_2;
2527 + i->i_fop = &squashfs_dir_ops_2;
2528 + i->i_mode |= S_IFDIR;
2529 + i->i_mtime.tv_sec = inodep->mtime;
2530 + i->i_atime.tv_sec = inodep->mtime;
2531 + i->i_ctime.tv_sec = inodep->mtime;
2532 + SQUASHFS_I(i)->start_block = inodep->start_block;
2533 + SQUASHFS_I(i)->offset = inodep->offset;
2534 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2535 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2537 + TRACE("Directory inode %x:%x, start_block %x, offset "
2538 + "%x\n", SQUASHFS_INODE_BLK(inode),
2539 + offset, inodep->start_block,
2543 + case SQUASHFS_LDIR_TYPE: {
2544 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2545 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2547 + if (msblk->swap) {
2548 + if (!squashfs_get_cached_block(s, (char *)
2549 + sinodep, block, offset,
2550 + sizeof(*sinodep), &next_block,
2553 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2556 + if (!squashfs_get_cached_block(s, (char *)
2557 + inodep, block, offset,
2558 + sizeof(*inodep), &next_block,
2562 + i->i_size = inodep->file_size;
2563 + i->i_op = &squashfs_dir_inode_ops_2;
2564 + i->i_fop = &squashfs_dir_ops_2;
2565 + i->i_mode |= S_IFDIR;
2566 + i->i_mtime.tv_sec = inodep->mtime;
2567 + i->i_atime.tv_sec = inodep->mtime;
2568 + i->i_ctime.tv_sec = inodep->mtime;
2569 + SQUASHFS_I(i)->start_block = inodep->start_block;
2570 + SQUASHFS_I(i)->offset = inodep->offset;
2571 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2572 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2574 + SQUASHFS_I(i)->u.s2.directory_index_count =
2576 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2578 + TRACE("Long directory inode %x:%x, start_block %x, "
2580 + SQUASHFS_INODE_BLK(inode), offset,
2581 + inodep->start_block, inodep->offset);
2584 + case SQUASHFS_SYMLINK_TYPE: {
2585 + struct squashfs_symlink_inode_header_2 *inodep =
2587 + struct squashfs_symlink_inode_header_2 *sinodep =
2590 + if (msblk->swap) {
2591 + if (!squashfs_get_cached_block(s, (char *)
2592 + sinodep, block, offset,
2593 + sizeof(*sinodep), &next_block,
2596 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2599 + if (!squashfs_get_cached_block(s, (char *)
2600 + inodep, block, offset,
2601 + sizeof(*inodep), &next_block,
2605 + i->i_size = inodep->symlink_size;
2606 + i->i_op = &page_symlink_inode_operations;
2607 + i->i_data.a_ops = &squashfs_symlink_aops;
2608 + i->i_mode |= S_IFLNK;
2609 + SQUASHFS_I(i)->start_block = next_block;
2610 + SQUASHFS_I(i)->offset = next_offset;
2612 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2614 + SQUASHFS_INODE_BLK(inode), offset,
2615 + next_block, next_offset);
2618 + case SQUASHFS_BLKDEV_TYPE:
2619 + case SQUASHFS_CHRDEV_TYPE: {
2620 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2621 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2623 + if (msblk->swap) {
2624 + if (!squashfs_get_cached_block(s, (char *)
2625 + sinodep, block, offset,
2626 + sizeof(*sinodep), &next_block,
2629 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2631 + if (!squashfs_get_cached_block(s, (char *)
2632 + inodep, block, offset,
2633 + sizeof(*inodep), &next_block,
2637 + i->i_mode |= (inodeb->inode_type ==
2638 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2640 + init_special_inode(i, i->i_mode,
2641 + old_decode_dev(inodep->rdev));
2643 + TRACE("Device inode %x:%x, rdev %x\n",
2644 + SQUASHFS_INODE_BLK(inode), offset,
2648 + case SQUASHFS_FIFO_TYPE:
2649 + case SQUASHFS_SOCKET_TYPE: {
2651 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2652 + ? S_IFIFO : S_IFSOCK;
2653 + init_special_inode(i, i->i_mode, 0);
2657 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2658 + inodeb->inode_type);
2659 + goto failed_read1;
2665 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2672 +static int get_dir_index_using_offset(struct super_block *s, long long
2673 + *next_block, unsigned int *next_offset,
2674 + long long index_start,
2675 + unsigned int index_offset, int i_count,
2678 + struct squashfs_sb_info *msblk = s->s_fs_info;
2679 + struct squashfs_super_block *sblk = &msblk->sblk;
2680 + int i, length = 0;
2681 + struct squashfs_dir_index_2 index;
2683 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2684 + i_count, (unsigned int) f_pos);
2689 + for (i = 0; i < i_count; i++) {
2690 + if (msblk->swap) {
2691 + struct squashfs_dir_index_2 sindex;
2692 + squashfs_get_cached_block(s, (char *) &sindex,
2693 + index_start, index_offset,
2694 + sizeof(sindex), &index_start,
2696 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2698 + squashfs_get_cached_block(s, (char *) &index,
2699 + index_start, index_offset,
2700 + sizeof(index), &index_start,
2703 + if (index.index > f_pos)
2706 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2707 + index.size + 1, &index_start,
2710 + length = index.index;
2711 + *next_block = index.start_block + sblk->directory_table_start;
2714 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2721 +static int get_dir_index_using_name(struct super_block *s, long long
2722 + *next_block, unsigned int *next_offset,
2723 + long long index_start,
2724 + unsigned int index_offset, int i_count,
2725 + const char *name, int size)
2727 + struct squashfs_sb_info *msblk = s->s_fs_info;
2728 + struct squashfs_super_block *sblk = &msblk->sblk;
2729 + int i, length = 0;
2730 + struct squashfs_dir_index_2 *index;
2733 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2735 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2736 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2737 + ERROR("Failed to allocate squashfs_dir_index\n");
2741 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2742 + strncpy(str, name, size);
2745 + for (i = 0; i < i_count; i++) {
2746 + if (msblk->swap) {
2747 + struct squashfs_dir_index_2 sindex;
2748 + squashfs_get_cached_block(s, (char *) &sindex,
2749 + index_start, index_offset,
2750 + sizeof(sindex), &index_start,
2752 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2754 + squashfs_get_cached_block(s, (char *) index,
2755 + index_start, index_offset,
2756 + sizeof(struct squashfs_dir_index_2),
2757 + &index_start, &index_offset);
2759 + squashfs_get_cached_block(s, index->name, index_start,
2760 + index_offset, index->size + 1,
2761 + &index_start, &index_offset);
2763 + index->name[index->size + 1] = '\0';
2765 + if (strcmp(index->name, str) > 0)
2768 + length = index->index;
2769 + *next_block = index->start_block + sblk->directory_table_start;
2772 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2779 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2781 + struct inode *i = file->f_dentry->d_inode;
2782 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2783 + struct squashfs_super_block *sblk = &msblk->sblk;
2784 + long long next_block = SQUASHFS_I(i)->start_block +
2785 + sblk->directory_table_start;
2786 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2788 + struct squashfs_dir_header_2 dirh;
2789 + struct squashfs_dir_entry_2 *dire;
2791 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2793 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2794 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2795 + ERROR("Failed to allocate squashfs_dir_entry\n");
2799 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2800 + SQUASHFS_I(i)->u.s2.directory_index_start,
2801 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2802 + SQUASHFS_I(i)->u.s2.directory_index_count,
2805 + while (length < i_size_read(i)) {
2806 + /* read directory header */
2807 + if (msblk->swap) {
2808 + struct squashfs_dir_header_2 sdirh;
2810 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2811 + next_block, next_offset, sizeof(sdirh),
2812 + &next_block, &next_offset))
2815 + length += sizeof(sdirh);
2816 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2818 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2819 + next_block, next_offset, sizeof(dirh),
2820 + &next_block, &next_offset))
2823 + length += sizeof(dirh);
2826 + dir_count = dirh.count + 1;
2827 + while (dir_count--) {
2828 + if (msblk->swap) {
2829 + struct squashfs_dir_entry_2 sdire;
2830 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2831 + &sdire, next_block, next_offset,
2832 + sizeof(sdire), &next_block,
2836 + length += sizeof(sdire);
2837 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2839 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2840 + dire, next_block, next_offset,
2841 + sizeof(*dire), &next_block,
2845 + length += sizeof(*dire);
2848 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2849 + next_block, next_offset,
2850 + dire->size + 1, &next_block,
2854 + length += dire->size + 1;
2856 + if (file->f_pos >= length)
2859 + dire->name[dire->size + 1] = '\0';
2861 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2862 + (unsigned int) dirent, dire->name,
2863 + dire->size + 1, (int) file->f_pos,
2864 + dirh.start_block, dire->offset,
2865 + squashfs_filetype_table[dire->type]);
2867 + if (filldir(dirent, dire->name, dire->size + 1,
2868 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2869 + dirh.start_block, dire->offset),
2870 + squashfs_filetype_table[dire->type])
2872 + TRACE("Filldir returned less than 0\n");
2875 + file->f_pos = length;
2884 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2891 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2892 + struct nameidata *nd)
2894 + const unsigned char *name = dentry->d_name.name;
2895 + int len = dentry->d_name.len;
2896 + struct inode *inode = NULL;
2897 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2898 + struct squashfs_super_block *sblk = &msblk->sblk;
2899 + long long next_block = SQUASHFS_I(i)->start_block +
2900 + sblk->directory_table_start;
2901 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2903 + struct squashfs_dir_header_2 dirh;
2904 + struct squashfs_dir_entry_2 *dire;
2905 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2907 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2909 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2910 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2911 + ERROR("Failed to allocate squashfs_dir_entry\n");
2915 + if (len > SQUASHFS_NAME_LEN)
2918 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2919 + SQUASHFS_I(i)->u.s2.directory_index_start,
2920 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2921 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2924 + while (length < i_size_read(i)) {
2925 + /* read directory header */
2926 + if (msblk->swap) {
2927 + struct squashfs_dir_header_2 sdirh;
2928 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2929 + next_block, next_offset, sizeof(sdirh),
2930 + &next_block, &next_offset))
2933 + length += sizeof(sdirh);
2934 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2936 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2937 + next_block, next_offset, sizeof(dirh),
2938 + &next_block, &next_offset))
2941 + length += sizeof(dirh);
2944 + dir_count = dirh.count + 1;
2945 + while (dir_count--) {
2946 + if (msblk->swap) {
2947 + struct squashfs_dir_entry_2 sdire;
2948 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2949 + &sdire, next_block,next_offset,
2950 + sizeof(sdire), &next_block,
2954 + length += sizeof(sdire);
2955 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2957 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2958 + dire, next_block,next_offset,
2959 + sizeof(*dire), &next_block,
2963 + length += sizeof(*dire);
2966 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2967 + next_block, next_offset, dire->size + 1,
2968 + &next_block, &next_offset))
2971 + length += dire->size + 1;
2973 + if (sorted && name[0] < dire->name[0])
2976 + if ((len == dire->size + 1) && !strncmp(name,
2977 + dire->name, len)) {
2978 + squashfs_inode_t ino =
2979 + SQUASHFS_MKINODE(dirh.start_block,
2981 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
2984 + TRACE("calling squashfs_iget for directory "
2985 + "entry %s, inode %x:%x, %lld\n", name,
2986 + dirh.start_block, dire->offset, ino);
2988 + inode = squashfs_iget(i->i_sb, ino, inode_number);
2997 + d_add(dentry, inode);
2998 + return ERR_PTR(0);
3001 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3007 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3009 + struct squashfs_super_block *sblk = &msblk->sblk;
3011 + msblk->read_inode = squashfs_read_inode_2;
3012 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3014 + sblk->bytes_used = sblk->bytes_used_2;
3015 + sblk->uid_start = sblk->uid_start_2;
3016 + sblk->guid_start = sblk->guid_start_2;
3017 + sblk->inode_table_start = sblk->inode_table_start_2;
3018 + sblk->directory_table_start = sblk->directory_table_start_2;
3019 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3023 diff -x .gitignore -Nurp linux-2.6.24/fs/squashfs/squashfs.h linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h
3024 --- linux-2.6.24/fs/squashfs/squashfs.h 1970-01-01 01:00:00.000000000 +0100
3025 +++ linux-2.6.24-squashfs3.3/fs/squashfs/squashfs.h 2007-08-19 04:23:16.000000000 +0100
3028 + * Squashfs - a compressed read only filesystem for Linux
3030 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3031 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3033 + * This program is free software; you can redistribute it and/or
3034 + * modify it under the terms of the GNU General Public License
3035 + * as published by the Free Software Foundation; either version 2,
3036 + * or (at your option) any later version.
3038 + * This program is distributed in the hope that it will be useful,
3039 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3040 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3041 + * GNU General Public License for more details.
3043 + * You should have received a copy of the GNU General Public License
3044 + * along with this program; if not, write to the Free Software
3045 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3050 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3051 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3054 +#ifdef SQUASHFS_TRACE
3055 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3057 +#define TRACE(s, args...) {}
3060 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3062 +#define SERROR(s, args...) do { \
3064 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3067 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3069 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3071 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3074 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3075 +#define SQSH_EXTERN
3076 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3077 + long long index, unsigned int length,
3078 + long long *next_index, int srclength);
3079 +extern int squashfs_get_cached_block(struct super_block *s, void *buffer,
3080 + long long block, unsigned int offset,
3081 + int length, long long *next_block,
3082 + unsigned int *next_offset);
3083 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3084 + squashfs_fragment_cache *fragment);
3085 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3086 + *s, long long start_block,
3088 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
3089 +extern const struct address_space_operations squashfs_symlink_aops;
3090 +extern const struct address_space_operations squashfs_aops;
3091 +extern struct inode_operations squashfs_dir_inode_ops;
3093 +#define SQSH_EXTERN static
3096 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3097 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3099 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3105 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3106 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3108 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3113 diff -x .gitignore -Nurp linux-2.6.24/include/linux/squashfs_fs.h linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h
3114 --- linux-2.6.24/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
3115 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs.h 2007-11-01 03:50:57.000000000 +0000
3117 +#ifndef SQUASHFS_FS
3118 +#define SQUASHFS_FS
3123 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
3124 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3126 + * This program is free software; you can redistribute it and/or
3127 + * modify it under the terms of the GNU General Public License
3128 + * as published by the Free Software Foundation; either version 2,
3129 + * or (at your option) any later version.
3131 + * This program is distributed in the hope that it will be useful,
3132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3134 + * GNU General Public License for more details.
3136 + * You should have received a copy of the GNU General Public License
3137 + * along with this program; if not, write to the Free Software
3138 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3143 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3144 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3147 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3148 +#define SQUASHFS_MAJOR 3
3149 +#define SQUASHFS_MINOR 1
3150 +#define SQUASHFS_MAGIC 0x73717368
3151 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3152 +#define SQUASHFS_START 0
3154 +/* size of metadata (inode and directory) blocks */
3155 +#define SQUASHFS_METADATA_SIZE 8192
3156 +#define SQUASHFS_METADATA_LOG 13
3158 +/* default size of data blocks */
3159 +#define SQUASHFS_FILE_SIZE 131072
3160 +#define SQUASHFS_FILE_LOG 17
3162 +#define SQUASHFS_FILE_MAX_SIZE 1048576
3164 +/* Max number of uids and gids */
3165 +#define SQUASHFS_UIDS 256
3166 +#define SQUASHFS_GUIDS 255
3168 +/* Max length of filename (not 255) */
3169 +#define SQUASHFS_NAME_LEN 256
3171 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3172 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3173 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3174 +#define SQUASHFS_USED_BLK ((long long) -2)
3176 +/* Filesystem flags */
3177 +#define SQUASHFS_NOI 0
3178 +#define SQUASHFS_NOD 1
3179 +#define SQUASHFS_CHECK 2
3180 +#define SQUASHFS_NOF 3
3181 +#define SQUASHFS_NO_FRAG 4
3182 +#define SQUASHFS_ALWAYS_FRAG 5
3183 +#define SQUASHFS_DUPLICATE 6
3184 +#define SQUASHFS_EXPORT 7
3186 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3188 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3191 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3194 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3197 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3200 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3201 + SQUASHFS_ALWAYS_FRAG)
3203 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3204 + SQUASHFS_DUPLICATE)
3206 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3209 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3212 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3213 + duplicate_checking, exortable) (noi | (nod << 1) | (check_data << 2) \
3214 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3215 + (duplicate_checking << 6) | (exportable << 7))
3217 +/* Max number of types and file types */
3218 +#define SQUASHFS_DIR_TYPE 1
3219 +#define SQUASHFS_FILE_TYPE 2
3220 +#define SQUASHFS_SYMLINK_TYPE 3
3221 +#define SQUASHFS_BLKDEV_TYPE 4
3222 +#define SQUASHFS_CHRDEV_TYPE 5
3223 +#define SQUASHFS_FIFO_TYPE 6
3224 +#define SQUASHFS_SOCKET_TYPE 7
3225 +#define SQUASHFS_LDIR_TYPE 8
3226 +#define SQUASHFS_LREG_TYPE 9
3228 +/* 1.0 filesystem type definitions */
3229 +#define SQUASHFS_TYPES 5
3230 +#define SQUASHFS_IPC_TYPE 0
3232 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3234 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3236 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3237 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3239 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3241 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3243 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
3244 + ~SQUASHFS_COMPRESSED_BIT_BLOCK)
3246 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3249 + * Inode number ops. Inodes consist of a compressed block number, and an
3250 + * uncompressed offset within that block
3252 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3254 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3256 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3259 +/* Compute 32 bit VFS inode number from squashfs inode number */
3260 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3264 +/* Translate between VFS mode and squashfs mode */
3265 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3267 +/* fragment and fragment table defines */
3268 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3270 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3271 + SQUASHFS_METADATA_SIZE)
3273 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3274 + SQUASHFS_METADATA_SIZE)
3276 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3277 + SQUASHFS_METADATA_SIZE - 1) / \
3278 + SQUASHFS_METADATA_SIZE)
3280 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3281 + sizeof(long long))
3283 +/* inode lookup table defines */
3284 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3286 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3287 + SQUASHFS_METADATA_SIZE)
3289 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3290 + SQUASHFS_METADATA_SIZE)
3292 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3293 + SQUASHFS_METADATA_SIZE - 1) / \
3294 + SQUASHFS_METADATA_SIZE)
3296 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3297 + sizeof(long long))
3299 +/* cached data constants for filesystem */
3300 +#define SQUASHFS_CACHED_BLKS 8
3302 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3304 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3305 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3307 +#define SQUASHFS_MARKER_BYTE 0xff
3309 +/* meta index cache */
3310 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3311 +#define SQUASHFS_META_ENTRIES 31
3312 +#define SQUASHFS_META_NUMBER 8
3313 +#define SQUASHFS_SLOTS 4
3315 +struct meta_entry {
3316 + long long data_block;
3317 + unsigned int index_block;
3318 + unsigned short offset;
3319 + unsigned short pad;
3322 +struct meta_index {
3323 + unsigned int inode_number;
3324 + unsigned int offset;
3325 + unsigned short entries;
3326 + unsigned short skip;
3327 + unsigned short locked;
3328 + unsigned short pad;
3329 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3334 + * definitions for structures on disk
3337 +typedef long long squashfs_block_t;
3338 +typedef long long squashfs_inode_t;
3340 +struct squashfs_super_block {
3341 + unsigned int s_magic;
3342 + unsigned int inodes;
3343 + unsigned int bytes_used_2;
3344 + unsigned int uid_start_2;
3345 + unsigned int guid_start_2;
3346 + unsigned int inode_table_start_2;
3347 + unsigned int directory_table_start_2;
3348 + unsigned int s_major:16;
3349 + unsigned int s_minor:16;
3350 + unsigned int block_size_1:16;
3351 + unsigned int block_log:16;
3352 + unsigned int flags:8;
3353 + unsigned int no_uids:8;
3354 + unsigned int no_guids:8;
3355 + unsigned int mkfs_time /* time of filesystem creation */;
3356 + squashfs_inode_t root_inode;
3357 + unsigned int block_size;
3358 + unsigned int fragments;
3359 + unsigned int fragment_table_start_2;
3360 + long long bytes_used;
3361 + long long uid_start;
3362 + long long guid_start;
3363 + long long inode_table_start;
3364 + long long directory_table_start;
3365 + long long fragment_table_start;
3366 + long long lookup_table_start;
3367 +} __attribute__ ((packed));
3369 +struct squashfs_dir_index {
3370 + unsigned int index;
3371 + unsigned int start_block;
3372 + unsigned char size;
3373 + unsigned char name[0];
3374 +} __attribute__ ((packed));
3376 +#define SQUASHFS_BASE_INODE_HEADER \
3377 + unsigned int inode_type:4; \
3378 + unsigned int mode:12; \
3379 + unsigned int uid:8; \
3380 + unsigned int guid:8; \
3381 + unsigned int mtime; \
3382 + unsigned int inode_number;
3384 +struct squashfs_base_inode_header {
3385 + SQUASHFS_BASE_INODE_HEADER;
3386 +} __attribute__ ((packed));
3388 +struct squashfs_ipc_inode_header {
3389 + SQUASHFS_BASE_INODE_HEADER;
3390 + unsigned int nlink;
3391 +} __attribute__ ((packed));
3393 +struct squashfs_dev_inode_header {
3394 + SQUASHFS_BASE_INODE_HEADER;
3395 + unsigned int nlink;
3396 + unsigned short rdev;
3397 +} __attribute__ ((packed));
3399 +struct squashfs_symlink_inode_header {
3400 + SQUASHFS_BASE_INODE_HEADER;
3401 + unsigned int nlink;
3402 + unsigned short symlink_size;
3404 +} __attribute__ ((packed));
3406 +struct squashfs_reg_inode_header {
3407 + SQUASHFS_BASE_INODE_HEADER;
3408 + squashfs_block_t start_block;
3409 + unsigned int fragment;
3410 + unsigned int offset;
3411 + unsigned int file_size;
3412 + unsigned short block_list[0];
3413 +} __attribute__ ((packed));
3415 +struct squashfs_lreg_inode_header {
3416 + SQUASHFS_BASE_INODE_HEADER;
3417 + unsigned int nlink;
3418 + squashfs_block_t start_block;
3419 + unsigned int fragment;
3420 + unsigned int offset;
3421 + long long file_size;
3422 + unsigned short block_list[0];
3423 +} __attribute__ ((packed));
3425 +struct squashfs_dir_inode_header {
3426 + SQUASHFS_BASE_INODE_HEADER;
3427 + unsigned int nlink;
3428 + unsigned int file_size:19;
3429 + unsigned int offset:13;
3430 + unsigned int start_block;
3431 + unsigned int parent_inode;
3432 +} __attribute__ ((packed));
3434 +struct squashfs_ldir_inode_header {
3435 + SQUASHFS_BASE_INODE_HEADER;
3436 + unsigned int nlink;
3437 + unsigned int file_size:27;
3438 + unsigned int offset:13;
3439 + unsigned int start_block;
3440 + unsigned int i_count:16;
3441 + unsigned int parent_inode;
3442 + struct squashfs_dir_index index[0];
3443 +} __attribute__ ((packed));
3445 +union squashfs_inode_header {
3446 + struct squashfs_base_inode_header base;
3447 + struct squashfs_dev_inode_header dev;
3448 + struct squashfs_symlink_inode_header symlink;
3449 + struct squashfs_reg_inode_header reg;
3450 + struct squashfs_lreg_inode_header lreg;
3451 + struct squashfs_dir_inode_header dir;
3452 + struct squashfs_ldir_inode_header ldir;
3453 + struct squashfs_ipc_inode_header ipc;
3456 +struct squashfs_dir_entry {
3457 + unsigned int offset:13;
3458 + unsigned int type:3;
3459 + unsigned int size:8;
3460 + int inode_number:16;
3462 +} __attribute__ ((packed));
3464 +struct squashfs_dir_header {
3465 + unsigned int count:8;
3466 + unsigned int start_block;
3467 + unsigned int inode_number;
3468 +} __attribute__ ((packed));
3470 +struct squashfs_fragment_entry {
3471 + long long start_block;
3472 + unsigned int size;
3473 + unsigned int pending;
3474 +} __attribute__ ((packed));
3476 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3477 +extern int squashfs_uncompress_init(void);
3478 +extern int squashfs_uncompress_exit(void);
3481 + * macros to convert each packed bitfield structure from little endian to big
3482 + * endian and vice versa. These are needed when creating or using a filesystem
3483 + * on a machine with different byte ordering to the target architecture.
3487 +#define SQUASHFS_SWAP_START \
3490 + unsigned long long val;\
3491 + unsigned char *s;\
3494 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3495 + SQUASHFS_SWAP_START\
3496 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3497 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3498 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3499 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3500 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3501 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3502 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3503 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3504 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3505 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3506 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3507 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3508 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3509 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3510 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3511 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3512 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3513 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3514 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3515 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3516 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3517 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3518 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3519 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3520 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3521 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3522 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3525 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3526 + SQUASHFS_MEMSET(s, d, n);\
3527 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3528 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3529 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3530 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3531 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3532 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3534 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3535 + SQUASHFS_SWAP_START\
3536 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3539 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3540 + SQUASHFS_SWAP_START\
3541 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3542 + sizeof(struct squashfs_ipc_inode_header))\
3543 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3546 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3547 + SQUASHFS_SWAP_START\
3548 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3549 + sizeof(struct squashfs_dev_inode_header)); \
3550 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3551 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3554 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3555 + SQUASHFS_SWAP_START\
3556 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3557 + sizeof(struct squashfs_symlink_inode_header));\
3558 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3559 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3562 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3563 + SQUASHFS_SWAP_START\
3564 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3565 + sizeof(struct squashfs_reg_inode_header));\
3566 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3567 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3568 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3569 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3572 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3573 + SQUASHFS_SWAP_START\
3574 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3575 + sizeof(struct squashfs_lreg_inode_header));\
3576 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3577 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3578 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3579 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3580 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3583 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3584 + SQUASHFS_SWAP_START\
3585 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3586 + sizeof(struct squashfs_dir_inode_header));\
3587 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3588 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3589 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3590 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3591 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3594 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3595 + SQUASHFS_SWAP_START\
3596 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3597 + sizeof(struct squashfs_ldir_inode_header));\
3598 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3599 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3600 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3601 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3602 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3603 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3606 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3609 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3610 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3611 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3614 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3615 + SQUASHFS_SWAP_START\
3616 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3617 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3618 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3619 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3622 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3623 + SQUASHFS_SWAP_START\
3624 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3625 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3626 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3627 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3628 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3631 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3632 + SQUASHFS_SWAP_START\
3633 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3634 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3635 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3638 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3640 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3642 + int bit_position;\
3643 + SQUASHFS_SWAP_START\
3644 + SQUASHFS_MEMSET(s, d, n * 2);\
3645 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3647 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3650 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3652 + int bit_position;\
3653 + SQUASHFS_SWAP_START\
3654 + SQUASHFS_MEMSET(s, d, n * 4);\
3655 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3657 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3660 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3662 + int bit_position;\
3663 + SQUASHFS_SWAP_START\
3664 + SQUASHFS_MEMSET(s, d, n * 8);\
3665 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3667 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3670 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3672 + int bit_position;\
3673 + SQUASHFS_SWAP_START\
3674 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3675 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3677 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3680 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3681 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3683 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3685 +struct squashfs_base_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 +} __attribute__ ((packed));
3692 +struct squashfs_ipc_inode_header_1 {
3693 + unsigned int inode_type:4;
3694 + unsigned int mode:12; /* protection */
3695 + unsigned int uid:4; /* index into uid table */
3696 + unsigned int guid:4; /* index into guid table */
3697 + unsigned int type:4;
3698 + unsigned int offset:4;
3699 +} __attribute__ ((packed));
3701 +struct squashfs_dev_inode_header_1 {
3702 + unsigned int inode_type:4;
3703 + unsigned int mode:12; /* protection */
3704 + unsigned int uid:4; /* index into uid table */
3705 + unsigned int guid:4; /* index into guid table */
3706 + unsigned short rdev;
3707 +} __attribute__ ((packed));
3709 +struct squashfs_symlink_inode_header_1 {
3710 + unsigned int inode_type:4;
3711 + unsigned int mode:12; /* protection */
3712 + unsigned int uid:4; /* index into uid table */
3713 + unsigned int guid:4; /* index into guid table */
3714 + unsigned short symlink_size;
3716 +} __attribute__ ((packed));
3718 +struct squashfs_reg_inode_header_1 {
3719 + unsigned int inode_type:4;
3720 + unsigned int mode:12; /* protection */
3721 + unsigned int uid:4; /* index into uid table */
3722 + unsigned int guid:4; /* index into guid table */
3723 + unsigned int mtime;
3724 + unsigned int start_block;
3725 + unsigned int file_size:32;
3726 + unsigned short block_list[0];
3727 +} __attribute__ ((packed));
3729 +struct squashfs_dir_inode_header_1 {
3730 + unsigned int inode_type:4;
3731 + unsigned int mode:12; /* protection */
3732 + unsigned int uid:4; /* index into uid table */
3733 + unsigned int guid:4; /* index into guid table */
3734 + unsigned int file_size:19;
3735 + unsigned int offset:13;
3736 + unsigned int mtime;
3737 + unsigned int start_block:24;
3738 +} __attribute__ ((packed));
3740 +union squashfs_inode_header_1 {
3741 + struct squashfs_base_inode_header_1 base;
3742 + struct squashfs_dev_inode_header_1 dev;
3743 + struct squashfs_symlink_inode_header_1 symlink;
3744 + struct squashfs_reg_inode_header_1 reg;
3745 + struct squashfs_dir_inode_header_1 dir;
3746 + struct squashfs_ipc_inode_header_1 ipc;
3749 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3750 + SQUASHFS_MEMSET(s, d, n);\
3751 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3752 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3753 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3754 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3756 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3757 + SQUASHFS_SWAP_START\
3758 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3761 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3762 + SQUASHFS_SWAP_START\
3763 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3764 + sizeof(struct squashfs_ipc_inode_header_1));\
3765 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3766 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3769 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3770 + SQUASHFS_SWAP_START\
3771 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3772 + sizeof(struct squashfs_dev_inode_header_1));\
3773 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3776 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3777 + SQUASHFS_SWAP_START\
3778 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3779 + sizeof(struct squashfs_symlink_inode_header_1));\
3780 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3783 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3784 + SQUASHFS_SWAP_START\
3785 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3786 + sizeof(struct squashfs_reg_inode_header_1));\
3787 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3788 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3789 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3792 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3793 + SQUASHFS_SWAP_START\
3794 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3795 + sizeof(struct squashfs_dir_inode_header_1));\
3796 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3797 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3798 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3799 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3804 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3806 +struct squashfs_dir_index_2 {
3807 + unsigned int index:27;
3808 + unsigned int start_block:29;
3809 + unsigned char size;
3810 + unsigned char name[0];
3811 +} __attribute__ ((packed));
3813 +struct squashfs_base_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_ipc_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 +} __attribute__ ((packed));
3827 +struct squashfs_dev_inode_header_2 {
3828 + unsigned int inode_type:4;
3829 + unsigned int mode:12; /* protection */
3830 + unsigned int uid:8; /* index into uid table */
3831 + unsigned int guid:8; /* index into guid table */
3832 + unsigned short rdev;
3833 +} __attribute__ ((packed));
3835 +struct squashfs_symlink_inode_header_2 {
3836 + unsigned int inode_type:4;
3837 + unsigned int mode:12; /* protection */
3838 + unsigned int uid:8; /* index into uid table */
3839 + unsigned int guid:8; /* index into guid table */
3840 + unsigned short symlink_size;
3842 +} __attribute__ ((packed));
3844 +struct squashfs_reg_inode_header_2 {
3845 + unsigned int inode_type:4;
3846 + unsigned int mode:12; /* protection */
3847 + unsigned int uid:8; /* index into uid table */
3848 + unsigned int guid:8; /* index into guid table */
3849 + unsigned int mtime;
3850 + unsigned int start_block;
3851 + unsigned int fragment;
3852 + unsigned int offset;
3853 + unsigned int file_size:32;
3854 + unsigned short block_list[0];
3855 +} __attribute__ ((packed));
3857 +struct squashfs_dir_inode_header_2 {
3858 + unsigned int inode_type:4;
3859 + unsigned int mode:12; /* protection */
3860 + unsigned int uid:8; /* index into uid table */
3861 + unsigned int guid:8; /* index into guid table */
3862 + unsigned int file_size:19;
3863 + unsigned int offset:13;
3864 + unsigned int mtime;
3865 + unsigned int start_block:24;
3866 +} __attribute__ ((packed));
3868 +struct squashfs_ldir_inode_header_2 {
3869 + unsigned int inode_type:4;
3870 + unsigned int mode:12; /* protection */
3871 + unsigned int uid:8; /* index into uid table */
3872 + unsigned int guid:8; /* index into guid table */
3873 + unsigned int file_size:27;
3874 + unsigned int offset:13;
3875 + unsigned int mtime;
3876 + unsigned int start_block:24;
3877 + unsigned int i_count:16;
3878 + struct squashfs_dir_index_2 index[0];
3879 +} __attribute__ ((packed));
3881 +union squashfs_inode_header_2 {
3882 + struct squashfs_base_inode_header_2 base;
3883 + struct squashfs_dev_inode_header_2 dev;
3884 + struct squashfs_symlink_inode_header_2 symlink;
3885 + struct squashfs_reg_inode_header_2 reg;
3886 + struct squashfs_dir_inode_header_2 dir;
3887 + struct squashfs_ldir_inode_header_2 ldir;
3888 + struct squashfs_ipc_inode_header_2 ipc;
3891 +struct squashfs_dir_header_2 {
3892 + unsigned int count:8;
3893 + unsigned int start_block:24;
3894 +} __attribute__ ((packed));
3896 +struct squashfs_dir_entry_2 {
3897 + unsigned int offset:13;
3898 + unsigned int type:3;
3899 + unsigned int size:8;
3901 +} __attribute__ ((packed));
3903 +struct squashfs_fragment_entry_2 {
3904 + unsigned int start_block;
3905 + unsigned int size;
3906 +} __attribute__ ((packed));
3908 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3909 + SQUASHFS_MEMSET(s, d, n);\
3910 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3911 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3912 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3913 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3915 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3916 + SQUASHFS_SWAP_START\
3917 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3920 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3921 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3923 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3924 + SQUASHFS_SWAP_START\
3925 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3926 + sizeof(struct squashfs_dev_inode_header_2)); \
3927 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3930 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3931 + SQUASHFS_SWAP_START\
3932 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3933 + sizeof(struct squashfs_symlink_inode_header_2));\
3934 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3937 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3938 + SQUASHFS_SWAP_START\
3939 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3940 + sizeof(struct squashfs_reg_inode_header_2));\
3941 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3942 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3943 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3944 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3945 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3948 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3949 + SQUASHFS_SWAP_START\
3950 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3951 + sizeof(struct squashfs_dir_inode_header_2));\
3952 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3953 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3954 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3955 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3958 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3959 + SQUASHFS_SWAP_START\
3960 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3961 + sizeof(struct squashfs_ldir_inode_header_2));\
3962 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3963 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3964 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3965 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3966 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3969 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3970 + SQUASHFS_SWAP_START\
3971 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3972 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3973 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3974 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3976 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3977 + SQUASHFS_SWAP_START\
3978 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3979 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3980 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3983 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3984 + SQUASHFS_SWAP_START\
3985 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3986 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3987 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3988 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3991 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3992 + SQUASHFS_SWAP_START\
3993 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3994 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3995 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3998 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
4000 +/* fragment and fragment table defines */
4001 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
4003 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
4004 + SQUASHFS_METADATA_SIZE)
4006 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4007 + SQUASHFS_METADATA_SIZE)
4009 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4010 + SQUASHFS_METADATA_SIZE - 1) / \
4011 + SQUASHFS_METADATA_SIZE)
4013 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4021 + * macros used to swap each structure entry, taking into account
4022 + * bitfields and different bitfield placing conventions on differing
4026 +#include <asm/byteorder.h>
4028 +#ifdef __BIG_ENDIAN
4029 + /* convert from little endian to big endian */
4030 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4033 + /* convert from big endian to little endian */
4034 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4035 + tbits, 64 - tbits - b_pos)
4038 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4041 + s = (unsigned char *)p + (pos / 8);\
4042 + d = ((unsigned char *) &val) + 7;\
4043 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4045 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4048 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4052 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
4053 --- linux-2.6.24/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
4054 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_i.h 2007-08-19 04:24:08.000000000 +0100
4056 +#ifndef SQUASHFS_FS_I
4057 +#define SQUASHFS_FS_I
4061 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4062 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4064 + * This program is free software; you can redistribute it and/or
4065 + * modify it under the terms of the GNU General Public License
4066 + * as published by the Free Software Foundation; either version 2,
4067 + * or (at your option) any later version.
4069 + * This program is distributed in the hope that it will be useful,
4070 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4071 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4072 + * GNU General Public License for more details.
4074 + * You should have received a copy of the GNU General Public License
4075 + * along with this program; if not, write to the Free Software
4076 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4081 +struct squashfs_inode_info {
4082 + long long start_block;
4083 + unsigned int offset;
4086 + long long fragment_start_block;
4087 + unsigned int fragment_size;
4088 + unsigned int fragment_offset;
4089 + long long block_list_start;
4092 + long long directory_index_start;
4093 + unsigned int directory_index_offset;
4094 + unsigned int directory_index_count;
4095 + unsigned int parent_inode;
4098 + struct inode vfs_inode;
4101 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
4102 --- linux-2.6.24/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
4103 +++ linux-2.6.24-squashfs3.3/include/linux/squashfs_fs_sb.h 2007-08-19 04:24:26.000000000 +0100
4105 +#ifndef SQUASHFS_FS_SB
4106 +#define SQUASHFS_FS_SB
4110 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
4111 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4113 + * This program is free software; you can redistribute it and/or
4114 + * modify it under the terms of the GNU General Public License
4115 + * as published by the Free Software Foundation; either version 2,
4116 + * or (at your option) any later version.
4118 + * This program is distributed in the hope that it will be useful,
4119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4121 + * GNU General Public License for more details.
4123 + * You should have received a copy of the GNU General Public License
4124 + * along with this program; if not, write to the Free Software
4125 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4127 + * squashfs_fs_sb.h
4130 +#include <linux/squashfs_fs.h>
4132 +struct squashfs_cache {
4135 + long long next_index;
4139 +struct squashfs_fragment_cache {
4142 + unsigned int locked;
4146 +struct squashfs_sb_info {
4147 + struct squashfs_super_block sblk;
4149 + int devblksize_log2;
4151 + struct squashfs_cache *block_cache;
4152 + struct squashfs_fragment_cache *fragment;
4154 + int next_fragment;
4155 + int next_meta_index;
4156 + unsigned int *uid;
4157 + unsigned int *guid;
4158 + long long *fragment_index;
4159 + unsigned int *fragment_index_2;
4161 + struct mutex read_data_mutex;
4162 + struct mutex read_page_mutex;
4163 + struct mutex block_cache_mutex;
4164 + struct mutex fragment_mutex;
4165 + struct mutex meta_index_mutex;
4166 + wait_queue_head_t waitq;
4167 + wait_queue_head_t fragment_wait_queue;
4168 + struct meta_index *meta_index;
4170 + long long *inode_lookup_table;
4171 + int unused_cache_blks;
4172 + int unused_frag_blks;
4173 + int (*read_inode)(struct inode *i, squashfs_inode_t \
4175 + long long (*read_blocklist)(struct inode *inode, int \
4176 + index, int readahead_blks, char *block_list, \
4177 + unsigned short **block_p, unsigned int *bsize);
4178 + int (*read_fragment_index_table)(struct super_block *s);
4181 diff -x .gitignore -Nurp linux-2.6.24/init/do_mounts_rd.c linux-2.6.24-squashfs3.3/init/do_mounts_rd.c
4182 --- linux-2.6.24/init/do_mounts_rd.c 2007-10-25 17:41:49.000000000 +0100
4183 +++ linux-2.6.24-squashfs3.3/init/do_mounts_rd.c 2007-11-01 05:06:25.000000000 +0000
4185 #include <linux/ext2_fs.h>
4186 #include <linux/romfs_fs.h>
4187 #include <linux/cramfs_fs.h>
4188 +#include <linux/squashfs_fs.h>
4189 #include <linux/initrd.h>
4190 #include <linux/string.h>
4192 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4193 * numbers could not be found.
4195 * We currently check for the following magic numbers:
4200 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4201 struct ext2_super_block *ext2sb;
4202 struct romfs_super_block *romfsb;
4203 struct cramfs_super *cramfsb;
4204 + struct squashfs_super_block *squashfsb;
4208 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4209 ext2sb = (struct ext2_super_block *) buf;
4210 romfsb = (struct romfs_super_block *) buf;
4211 cramfsb = (struct cramfs_super *) buf;
4212 + squashfsb = (struct squashfs_super_block *) buf;
4213 memset(buf, 0xe5, size);
4216 @@ -101,6 +105,18 @@ identify_ramdisk_image(int fd, int start
4220 + /* squashfs is at block zero too */
4221 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4222 + printk(KERN_NOTICE
4223 + "RAMDISK: squashfs filesystem found at block %d\n",
4225 + if (squashfsb->s_major < 3)
4226 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4228 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4233 * Read block 1 to test for minix and ext2 superblock