1 diff --new-file -urp linux-2.6.12/fs/Kconfig linux-2.6.12-squashfs2.2/fs/Kconfig
2 --- linux-2.6.12/fs/Kconfig 2005-06-17 20:48:29.000000000 +0100
3 +++ linux-2.6.12-squashfs2.2/fs/Kconfig 2005-07-04 02:35:35.000000000 +0100
4 @@ -1171,6 +1171,69 @@ config CRAMFS
9 + tristate "SquashFS 2.0 - Squashed file system support"
12 + Saying Y here includes support for SquashFs 2.0 (Compressed Read-Only File
13 + System). Squashfs is a highly compressed read-only filesystem for Linux.
14 + It uses zlib compression to compress both files, inodes and directories.
15 + Inodes in the system are very small and all blocks are packed to minimise
16 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
18 + Squashfs is intended for general read-only filesystem use, for archival
19 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
20 + systems where low overhead is needed. Further information and filesystem tools
21 + are available from http://squashfs.sourceforge.net.
23 + If you want to compile this as a module ( = code which can be
24 + inserted in and removed from the running kernel whenever you want),
25 + say M here and read <file:Documentation/modules.txt>. The module
26 + will be called squashfs. Note that the root file system (the one
27 + containing the directory /) cannot be compiled as a module.
31 +config SQUASHFS_EMBEDDED
33 + bool "Additional options for memory-constrained systems"
37 + Saying Y here allows you to specify cache sizes and how Squashfs
38 + allocates memory. This is only intended for memory constrained
43 +config SQUASHFS_FRAGMENT_CACHE_SIZE
44 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
48 + By default SquashFS caches the last 3 fragments read from
49 + the filesystem. Increasing this amount may mean SquashFS
50 + has to re-read fragments less often from disk, at the expense
51 + of extra system memory. Decreasing this amount will mean
52 + SquashFS uses less memory at the expense of extra reads from disk.
54 + Note there must be at least one cached fragment. Anything
55 + much more than three will probably not make much difference.
57 +config SQUASHFS_VMALLOC
58 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
62 + By default SquashFS uses kmalloc to obtain fragment cache memory.
63 + Kmalloc memory is the standard kernel allocator, but it can fail
64 + on memory constrained systems. Because of the way Vmalloc works,
65 + Vmalloc can succeed when kmalloc fails. Specifying this option
66 + will make SquashFS always use Vmalloc to allocate the
67 + fragment cache memory.
72 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
74 diff --new-file -urp linux-2.6.12/fs/Makefile linux-2.6.12-squashfs2.2/fs/Makefile
75 --- linux-2.6.12/fs/Makefile 2005-06-17 20:48:29.000000000 +0100
76 +++ linux-2.6.12-squashfs2.2/fs/Makefile 2005-07-04 02:35:35.000000000 +0100
77 @@ -52,6 +52,7 @@ obj-$(CONFIG_EXT3_FS) += ext3/ # Before
78 obj-$(CONFIG_JBD) += jbd/
79 obj-$(CONFIG_EXT2_FS) += ext2/
80 obj-$(CONFIG_CRAMFS) += cramfs/
81 +obj-$(CONFIG_SQUASHFS) += squashfs/
82 obj-$(CONFIG_RAMFS) += ramfs/
83 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
84 obj-$(CONFIG_CODA_FS) += coda/
85 diff --new-file -urp linux-2.6.12/fs/squashfs/inode.c linux-2.6.12-squashfs2.2/fs/squashfs/inode.c
86 --- linux-2.6.12/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
87 +++ linux-2.6.12-squashfs2.2/fs/squashfs/inode.c 2005-07-04 02:35:35.000000000 +0100
90 + * Squashfs - a compressed read only filesystem for Linux
92 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
94 + * This program is free software; you can redistribute it and/or
95 + * modify it under the terms of the GNU General Public License
96 + * as published by the Free Software Foundation; either version 2,
97 + * or (at your option) any later version.
99 + * This program is distributed in the hope that it will be useful,
100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 + * GNU General Public License for more details.
104 + * You should have received a copy of the GNU General Public License
105 + * along with this program; if not, write to the Free Software
106 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
111 +#define SQUASHFS_1_0_COMPATIBILITY
113 +#include <linux/types.h>
114 +#include <linux/squashfs_fs.h>
115 +#include <linux/module.h>
116 +#include <linux/errno.h>
117 +#include <linux/slab.h>
118 +#include <linux/fs.h>
119 +#include <linux/smp_lock.h>
120 +#include <linux/slab.h>
121 +#include <linux/squashfs_fs_sb.h>
122 +#include <linux/squashfs_fs_i.h>
123 +#include <linux/buffer_head.h>
124 +#include <linux/vfs.h>
125 +#include <linux/init.h>
126 +#include <linux/dcache.h>
127 +#include <asm/uaccess.h>
128 +#include <linux/wait.h>
129 +#include <asm/semaphore.h>
130 +#include <linux/zlib.h>
131 +#include <linux/blkdev.h>
132 +#include <linux/vmalloc.h>
134 +#ifdef SQUASHFS_TRACE
135 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
137 +#define TRACE(s, args...) {}
140 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
142 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
143 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
145 +static void squashfs_put_super(struct super_block *);
146 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
147 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
148 +static int squashfs_readpage(struct file *file, struct page *page);
149 +static int squashfs_readpage4K(struct file *file, struct page *page);
150 +static int squashfs_readdir(struct file *, void *, filldir_t);
151 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *, struct nameidata *);
152 +static unsigned int read_data(struct super_block *s, char *buffer,
153 + unsigned int index, unsigned int length, unsigned int *next_index);
154 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
155 + unsigned int block, unsigned int offset, int length,
156 + unsigned int *next_block, unsigned int *next_offset);
157 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
158 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
159 + char *block_list, unsigned short **block_p, unsigned int *bsize);
160 +static void squashfs_put_super(struct super_block *s);
161 +static struct super_block *squashfs_get_sb(struct file_system_type *, int, const char *, void *);
162 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
163 +static void squashfs_destroy_inode(struct inode *inode);
164 +static int init_inodecache(void);
165 +static void destroy_inodecache(void);
167 +#ifdef SQUASHFS_1_0_COMPATIBILITY
168 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page);
169 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode);
170 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
171 + char *block_list, unsigned short **block_p, unsigned int *bsize);
174 +DECLARE_MUTEX(read_data_mutex);
176 +static z_stream stream;
178 +static struct file_system_type squashfs_fs_type = {
179 + .owner = THIS_MODULE,
180 + .name = "squashfs",
181 + .get_sb = squashfs_get_sb,
182 + .kill_sb = kill_block_super,
183 + .fs_flags = FS_REQUIRES_DEV
186 +static unsigned char squashfs_filetype_table[] = {
187 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
190 +static struct super_operations squashfs_ops = {
191 + .alloc_inode = squashfs_alloc_inode,
192 + .destroy_inode = squashfs_destroy_inode,
193 + .statfs = squashfs_statfs,
194 + .put_super = squashfs_put_super,
197 +static struct address_space_operations squashfs_symlink_aops = {
198 + .readpage = squashfs_symlink_readpage
201 +static struct address_space_operations squashfs_aops = {
202 + .readpage = squashfs_readpage
205 +static struct address_space_operations squashfs_aops_4K = {
206 + .readpage = squashfs_readpage4K
209 +#ifdef SQUASHFS_1_0_COMPATIBILITY
210 +static struct address_space_operations squashfs_aops_lessthan4K = {
211 + .readpage = squashfs_readpage_lessthan4K
215 +static struct file_operations squashfs_dir_ops = {
216 + .read = generic_read_dir,
217 + .readdir = squashfs_readdir
220 +static struct inode_operations squashfs_dir_inode_ops = {
221 + .lookup = squashfs_lookup
225 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
227 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
231 +static struct buffer_head *get_block_length(struct super_block *s,
232 + int *cur_index, int *offset, int *c_byte)
234 + squashfs_sb_info *msblk = s->s_fs_info;
235 + unsigned short temp;
236 + struct buffer_head *bh;
238 + if (!(bh = sb_bread(s, *cur_index)))
241 + if (msblk->devblksize - *offset == 1) {
243 + ((unsigned char *) &temp)[1] = *((unsigned char *)
244 + (bh->b_data + *offset));
246 + ((unsigned char *) &temp)[0] = *((unsigned char *)
247 + (bh->b_data + *offset));
249 + if (!(bh = sb_bread(s, ++(*cur_index))))
252 + ((unsigned char *) &temp)[0] = *((unsigned char *)
255 + ((unsigned char *) &temp)[1] = *((unsigned char *)
261 + ((unsigned char *) &temp)[1] = *((unsigned char *)
262 + (bh->b_data + *offset));
263 + ((unsigned char *) &temp)[0] = *((unsigned char *)
264 + (bh->b_data + *offset + 1));
266 + ((unsigned char *) &temp)[0] = *((unsigned char *)
267 + (bh->b_data + *offset));
268 + ((unsigned char *) &temp)[1] = *((unsigned char *)
269 + (bh->b_data + *offset + 1));
275 + if (SQUASHFS_CHECK_DATA(msblk->sBlk.flags)) {
276 + if (*offset == msblk->devblksize) {
278 + if (!(bh = sb_bread(s, ++(*cur_index))))
282 + if (*((unsigned char *) (bh->b_data + *offset)) !=
283 + SQUASHFS_MARKER_BYTE) {
284 + ERROR("Metadata block marker corrupt @ %x\n",
298 +static unsigned int read_data(struct super_block *s, char *buffer,
299 + unsigned int index, unsigned int length, unsigned int *next_index)
301 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
302 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
303 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
304 + unsigned int cur_index = index >> msBlk->devblksize_log2;
305 + int bytes, avail_bytes, b = 0, k;
307 + unsigned int compressed;
308 + unsigned int c_byte = length;
311 + bytes = msBlk->devblksize - offset;
312 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
313 + c_buffer = compressed ? msBlk->read_data : buffer;
314 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
316 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
318 + if(!(bh[0] = sb_getblk(s, cur_index)))
319 + goto block_release;
320 + for(b = 1; bytes < c_byte; b++) {
321 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
322 + goto block_release;
323 + bytes += msBlk->devblksize;
325 + ll_rw_block(READ, b, bh);
327 + if(!(bh[0] = get_block_length(s, &cur_index, &offset, &c_byte)))
330 + bytes = msBlk->devblksize - offset;
331 + compressed = SQUASHFS_COMPRESSED(c_byte);
332 + c_buffer = compressed ? msBlk->read_data : buffer;
333 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
335 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
337 + for(b = 1; bytes < c_byte; b++) {
338 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
339 + goto block_release;
340 + bytes += msBlk->devblksize;
342 + ll_rw_block(READ, b - 1, bh + 1);
346 + down(&read_data_mutex);
348 + for(bytes = 0, k = 0; k < b; k++) {
349 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
350 + wait_on_buffer(bh[k]);
351 + if (!buffer_uptodate(bh[k]))
352 + goto block_release;
353 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
354 + bytes += avail_bytes;
365 + stream.next_in = c_buffer;
366 + stream.avail_in = c_byte;
367 + stream.next_out = buffer;
368 + stream.avail_out = msBlk->read_size;
369 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
370 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
371 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
372 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
375 + bytes = stream.total_out;
376 + up(&read_data_mutex);
380 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
385 + while(--b >= 0) brelse(bh[b]);
388 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
393 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
394 + unsigned int block, unsigned int offset, int length,
395 + unsigned int *next_block, unsigned int *next_offset)
397 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
398 + int n, i, bytes, return_length = length;
399 + unsigned int next_index;
401 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
404 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
405 + if(msBlk->block_cache[i].block == block)
408 + down(&msBlk->block_cache_mutex);
409 + if(i == SQUASHFS_CACHED_BLKS) {
410 + /* read inode header block */
411 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
412 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
417 + init_waitqueue_entry(&wait, current);
418 + add_wait_queue(&msBlk->waitq, &wait);
419 + up(&msBlk->block_cache_mutex);
420 + set_current_state(TASK_UNINTERRUPTIBLE);
422 + set_current_state(TASK_RUNNING);
423 + remove_wait_queue(&msBlk->waitq, &wait);
426 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
428 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
429 + if(!(msBlk->block_cache[i].data = (unsigned char *)
430 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
431 + ERROR("Failed to allocate cache block\n");
432 + up(&msBlk->block_cache_mutex);
437 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
438 + up(&msBlk->block_cache_mutex);
439 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
441 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
444 + down(&msBlk->block_cache_mutex);
445 + wake_up(&msBlk->waitq);
446 + msBlk->block_cache[i].block = block;
447 + msBlk->block_cache[i].next_index = next_index;
448 + TRACE("Read cache block [%x:%x]\n", block, offset);
451 + if(msBlk->block_cache[i].block != block) {
452 + up(&msBlk->block_cache_mutex);
456 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
458 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
459 + if(msBlk->block_cache[i].length - offset == length) {
460 + *next_block = msBlk->block_cache[i].next_index;
463 + *next_block = block;
464 + *next_offset = offset + length;
467 + up(&msBlk->block_cache_mutex);
468 + return return_length;
471 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
474 + block = msBlk->block_cache[i].next_index;
475 + up(&msBlk->block_cache_mutex);
483 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
485 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
486 + unsigned int start_block = msBlk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
487 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
488 + squashfs_fragment_entry fragment_entry;
491 + squashfs_fragment_entry sfragment_entry;
493 + if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
494 + sizeof(sfragment_entry), &start_block, &offset))
496 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
498 + if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
499 + sizeof(fragment_entry), &start_block, &offset))
502 + *fragment_start_block = fragment_entry.start_block;
503 + *fragment_size = fragment_entry.size;
509 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
511 + down(&msBlk->fragment_mutex);
512 + fragment->locked --;
513 + wake_up(&msBlk->fragment_wait_queue);
514 + up(&msBlk->fragment_mutex);
518 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
521 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
524 + down(&msBlk->fragment_mutex);
525 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS && msBlk->fragment[i].block != start_block; i++);
526 + if(i == SQUASHFS_CACHED_FRAGMENTS) {
527 + for(i = msBlk->next_fragment, n = SQUASHFS_CACHED_FRAGMENTS;
528 + n && msBlk->fragment[i].locked; n--, i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS);
533 + init_waitqueue_entry(&wait, current);
534 + add_wait_queue(&msBlk->fragment_wait_queue, &wait);
535 + up(&msBlk->fragment_mutex);
536 + set_current_state(TASK_UNINTERRUPTIBLE);
538 + set_current_state(TASK_RUNNING);
539 + remove_wait_queue(&msBlk->fragment_wait_queue, &wait);
542 + msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
544 + if(msBlk->fragment[i].data == NULL)
545 + if(!(msBlk->fragment[i].data = (unsigned char *)
546 + SQUASHFS_ALLOC(SQUASHFS_FILE_MAX_SIZE))) {
547 + ERROR("Failed to allocate fragment cache block\n");
548 + up(&msBlk->fragment_mutex);
552 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
553 + msBlk->fragment[i].locked = 1;
554 + up(&msBlk->fragment_mutex);
555 + if(!(msBlk->fragment[i].length = read_data(s, msBlk->fragment[i].data, start_block, length,
557 + ERROR("Unable to read fragment cache block [%x]\n", start_block);
558 + msBlk->fragment[i].locked = 0;
561 + msBlk->fragment[i].block = start_block;
562 + TRACE("New fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
563 + return &msBlk->fragment[i];
566 + msBlk->fragment[i].locked ++;
567 + up(&msBlk->fragment_mutex);
569 + TRACE("Got fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
570 + return &msBlk->fragment[i];
575 +#ifdef SQUASHFS_1_0_COMPATIBILITY
576 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
578 + struct inode *i = new_inode(s);
579 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
580 + squashfs_super_block *sBlk = &msBlk->sBlk;
581 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
582 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
583 + unsigned int next_block, next_offset;
584 + squashfs_base_inode_header_1 inodeb;
586 + TRACE("Entered squashfs_iget_1\n");
589 + squashfs_base_inode_header_1 sinodeb;
591 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
592 + sizeof(sinodeb), &next_block, &next_offset))
594 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
596 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
597 + sizeof(inodeb), &next_block, &next_offset))
602 + i->i_mtime.tv_sec = sBlk->mkfs_time;
603 + i->i_atime.tv_sec = sBlk->mkfs_time;
604 + i->i_ctime.tv_sec = sBlk->mkfs_time;
606 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
607 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
608 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
610 + i->i_mode = inodeb.mode;
612 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
613 + case SQUASHFS_FILE_TYPE: {
614 + squashfs_reg_inode_header_1 inodep;
617 + squashfs_reg_inode_header_1 sinodep;
619 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
620 + &next_block, &next_offset))
622 + SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
624 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
625 + &next_block, &next_offset))
628 + i->i_size = inodep.file_size;
629 + i->i_fop = &generic_ro_fops;
630 + if(sBlk->block_size > 4096)
631 + i->i_data.a_ops = &squashfs_aops;
632 + else if(sBlk->block_size == 4096)
633 + i->i_data.a_ops = &squashfs_aops_4K;
635 + i->i_data.a_ops = &squashfs_aops_lessthan4K;
636 + i->i_mode |= S_IFREG;
637 + i->i_mtime.tv_sec = inodep.mtime;
638 + i->i_atime.tv_sec = inodep.mtime;
639 + i->i_ctime.tv_sec = inodep.mtime;
640 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
641 + i->i_blksize = PAGE_CACHE_SIZE;
642 + SQUASHFS_I(i)->u.s1.fragment_start_block = SQUASHFS_INVALID_BLK;
643 + SQUASHFS_I(i)->u.s1.fragment_offset = 0;
644 + SQUASHFS_I(i)->start_block = inodep.start_block;
645 + SQUASHFS_I(i)->block_list_start = next_block;
646 + SQUASHFS_I(i)->offset = next_offset;
647 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
648 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
651 + case SQUASHFS_DIR_TYPE: {
652 + squashfs_dir_inode_header_1 inodep;
655 + squashfs_dir_inode_header_1 sinodep;
657 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
658 + &next_block, &next_offset))
660 + SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
662 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
663 + &next_block, &next_offset))
666 + i->i_size = inodep.file_size;
667 + i->i_op = &squashfs_dir_inode_ops;
668 + i->i_fop = &squashfs_dir_ops;
669 + i->i_mode |= S_IFDIR;
670 + i->i_mtime.tv_sec = inodep.mtime;
671 + i->i_atime.tv_sec = inodep.mtime;
672 + i->i_ctime.tv_sec = inodep.mtime;
673 + SQUASHFS_I(i)->start_block = inodep.start_block;
674 + SQUASHFS_I(i)->offset = inodep.offset;
675 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
676 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
677 + inodep.start_block, inodep.offset);
680 + case SQUASHFS_SYMLINK_TYPE: {
681 + squashfs_symlink_inode_header_1 inodep;
684 + squashfs_symlink_inode_header_1 sinodep;
686 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
687 + &next_block, &next_offset))
689 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
691 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
692 + &next_block, &next_offset))
695 + i->i_size = inodep.symlink_size;
696 + i->i_op = &page_symlink_inode_operations;
697 + i->i_data.a_ops = &squashfs_symlink_aops;
698 + i->i_mode |= S_IFLNK;
699 + SQUASHFS_I(i)->start_block = next_block;
700 + SQUASHFS_I(i)->offset = next_offset;
701 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
702 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
705 + case SQUASHFS_BLKDEV_TYPE:
706 + case SQUASHFS_CHRDEV_TYPE: {
707 + squashfs_dev_inode_header_1 inodep;
710 + squashfs_dev_inode_header_1 sinodep;
712 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
713 + &next_block, &next_offset))
715 + SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
717 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
718 + &next_block, &next_offset))
722 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
723 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
724 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
727 + case SQUASHFS_IPC_TYPE: {
728 + squashfs_ipc_inode_header_1 inodep;
731 + squashfs_ipc_inode_header_1 sinodep;
733 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
734 + &next_block, &next_offset))
736 + SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
738 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
739 + &next_block, &next_offset))
743 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
744 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
745 + init_special_inode(i, i->i_mode, 0);
749 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
753 + if(inodeb.guid == 15)
754 + i->i_gid = i->i_uid;
756 + i->i_gid = msBlk->guid[inodeb.guid];
758 + insert_inode_hash(i);
762 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
770 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
772 + struct inode *i = new_inode(s);
773 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
774 + squashfs_super_block *sBlk = &msBlk->sBlk;
775 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
776 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
777 + unsigned int next_block, next_offset;
778 + squashfs_base_inode_header inodeb;
780 + TRACE("Entered squashfs_iget\n");
783 + squashfs_base_inode_header sinodeb;
785 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
786 + sizeof(sinodeb), &next_block, &next_offset))
788 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
790 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
791 + sizeof(inodeb), &next_block, &next_offset))
796 + i->i_mtime.tv_sec = sBlk->mkfs_time;
797 + i->i_atime.tv_sec = sBlk->mkfs_time;
798 + i->i_ctime.tv_sec = sBlk->mkfs_time;
800 + i->i_uid = msBlk->uid[inodeb.uid];
801 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
803 + i->i_mode = inodeb.mode;
805 + switch(inodeb.inode_type) {
806 + case SQUASHFS_FILE_TYPE: {
807 + squashfs_reg_inode_header inodep;
810 + squashfs_reg_inode_header sinodep;
812 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
813 + &next_block, &next_offset))
815 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
817 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
818 + &next_block, &next_offset))
821 + SQUASHFS_I(i)->u.s1.fragment_start_block = SQUASHFS_INVALID_BLK;
822 + if(inodep.fragment != SQUASHFS_INVALID_BLK && !get_fragment_location(s, inodep.fragment,
823 + &SQUASHFS_I(i)->u.s1.fragment_start_block, &SQUASHFS_I(i)->u.s1.fragment_size))
826 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep.offset;
827 + i->i_size = inodep.file_size;
828 + i->i_fop = &generic_ro_fops;
829 + if(sBlk->block_size > 4096)
830 + i->i_data.a_ops = &squashfs_aops;
832 + i->i_data.a_ops = &squashfs_aops_4K;
833 + i->i_mode |= S_IFREG;
834 + i->i_mtime.tv_sec = inodep.mtime;
835 + i->i_atime.tv_sec = inodep.mtime;
836 + i->i_ctime.tv_sec = inodep.mtime;
837 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
838 + i->i_blksize = PAGE_CACHE_SIZE;
839 + SQUASHFS_I(i)->start_block = inodep.start_block;
840 + SQUASHFS_I(i)->block_list_start = next_block;
841 + SQUASHFS_I(i)->offset = next_offset;
842 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
843 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
846 + case SQUASHFS_DIR_TYPE: {
847 + squashfs_dir_inode_header inodep;
850 + squashfs_dir_inode_header sinodep;
852 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
853 + &next_block, &next_offset))
855 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
857 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
858 + &next_block, &next_offset))
861 + i->i_size = inodep.file_size;
862 + i->i_op = &squashfs_dir_inode_ops;
863 + i->i_fop = &squashfs_dir_ops;
864 + i->i_mode |= S_IFDIR;
865 + i->i_mtime.tv_sec = inodep.mtime;
866 + i->i_atime.tv_sec = inodep.mtime;
867 + i->i_ctime.tv_sec = inodep.mtime;
868 + SQUASHFS_I(i)->start_block = inodep.start_block;
869 + SQUASHFS_I(i)->offset = inodep.offset;
870 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
871 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
872 + inodep.start_block, inodep.offset);
875 + case SQUASHFS_LDIR_TYPE: {
876 + squashfs_ldir_inode_header inodep;
879 + squashfs_ldir_inode_header sinodep;
881 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
882 + &next_block, &next_offset))
884 + SQUASHFS_SWAP_LDIR_INODE_HEADER(&inodep, &sinodep);
886 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
887 + &next_block, &next_offset))
890 + i->i_size = inodep.file_size;
891 + i->i_op = &squashfs_dir_inode_ops;
892 + i->i_fop = &squashfs_dir_ops;
893 + i->i_mode |= S_IFDIR;
894 + i->i_mtime.tv_sec = inodep.mtime;
895 + i->i_atime.tv_sec = inodep.mtime;
896 + i->i_ctime.tv_sec = inodep.mtime;
897 + SQUASHFS_I(i)->start_block = inodep.start_block;
898 + SQUASHFS_I(i)->offset = inodep.offset;
899 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
900 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
901 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep.i_count;
902 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
903 + inodep.start_block, inodep.offset);
906 + case SQUASHFS_SYMLINK_TYPE: {
907 + squashfs_symlink_inode_header inodep;
910 + squashfs_symlink_inode_header sinodep;
912 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
913 + &next_block, &next_offset))
915 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
917 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
918 + &next_block, &next_offset))
921 + i->i_size = inodep.symlink_size;
922 + i->i_op = &page_symlink_inode_operations;
923 + i->i_data.a_ops = &squashfs_symlink_aops;
924 + i->i_mode |= S_IFLNK;
925 + SQUASHFS_I(i)->start_block = next_block;
926 + SQUASHFS_I(i)->offset = next_offset;
927 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
928 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
931 + case SQUASHFS_BLKDEV_TYPE:
932 + case SQUASHFS_CHRDEV_TYPE: {
933 + squashfs_dev_inode_header inodep;
936 + squashfs_dev_inode_header sinodep;
938 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
939 + &next_block, &next_offset))
941 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
943 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
944 + &next_block, &next_offset))
948 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
949 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
950 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
953 + case SQUASHFS_FIFO_TYPE:
954 + case SQUASHFS_SOCKET_TYPE: {
956 + i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
957 + init_special_inode(i, i->i_mode, 0);
961 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
965 + if(inodeb.guid == SQUASHFS_GUIDS)
966 + i->i_gid = i->i_uid;
968 + i->i_gid = msBlk->guid[inodeb.guid];
970 + insert_inode_hash(i);
974 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
981 +static int squashfs_fill_super(struct super_block *s,
982 + void *data, int silent)
984 + squashfs_sb_info *msBlk;
985 + squashfs_super_block *sBlk;
987 + char b[BDEVNAME_SIZE];
989 + TRACE("Entered squashfs_read_superblock\n");
991 + if(!(s->s_fs_info = (void *) kmalloc(sizeof(squashfs_sb_info), GFP_KERNEL))) {
992 + ERROR("Failed to allocate superblock\n");
995 + msBlk = (squashfs_sb_info *) s->s_fs_info;
996 + sBlk = &msBlk->sBlk;
998 + msBlk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
999 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
1001 + init_MUTEX(&msBlk->read_page_mutex);
1002 + init_MUTEX(&msBlk->block_cache_mutex);
1003 + init_MUTEX(&msBlk->fragment_mutex);
1005 + init_waitqueue_head(&msBlk->waitq);
1006 + init_waitqueue_head(&msBlk->fragment_wait_queue);
1008 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1009 + SERROR("unable to read superblock\n");
1010 + goto failed_mount;
1013 + /* Check it is a SQUASHFS superblock */
1015 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
1016 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
1017 + squashfs_super_block sblk;
1018 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(s->s_bdev, b));
1019 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
1020 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
1023 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(s->s_bdev, b));
1024 + goto failed_mount;
1028 + /* Check the MAJOR & MINOR versions */
1029 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1030 + if((sBlk->s_major != 1) && (sBlk->s_major != 2 || sBlk->s_minor > SQUASHFS_MINOR)) {
1031 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (1 : x) or (2 : <= %d)\n",
1032 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MINOR);
1033 + goto failed_mount;
1035 + if(sBlk->s_major == 1)
1036 + sBlk->block_size = sBlk->block_size_1;
1038 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
1039 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
1040 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
1041 + goto failed_mount;
1045 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1046 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
1047 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
1048 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
1049 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
1050 + TRACE("Block size %d\n", sBlk->block_size);
1051 + TRACE("Number of inodes %d\n", sBlk->inodes);
1052 + if(sBlk->s_major > 1)
1053 + TRACE("Number of fragments %d\n", sBlk->fragments);
1054 + TRACE("Number of uids %d\n", sBlk->no_uids);
1055 + TRACE("Number of gids %d\n", sBlk->no_guids);
1056 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
1057 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
1058 + if(sBlk->s_major > 1)
1059 + TRACE("sBlk->fragment_table_start %x\n", sBlk->fragment_table_start);
1060 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
1062 + s->s_flags |= MS_RDONLY;
1063 + s->s_op = &squashfs_ops;
1065 + /* Init inode_table block pointer array */
1066 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1067 + ERROR("Failed to allocate block cache\n");
1068 + goto failed_mount;
1071 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1072 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1074 + msBlk->next_cache = 0;
1076 + /* Allocate read_data block */
1077 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
1078 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
1079 + ERROR("Failed to allocate read_data block\n");
1080 + goto failed_mount1;
1083 + /* Allocate read_page block */
1084 + if(sBlk->block_size > PAGE_CACHE_SIZE) {
1085 + if(!(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
1086 + ERROR("Failed to allocate read_page block\n");
1087 + goto failed_mount2;
1090 + msBlk->read_page = NULL;
1092 + /* Allocate uid and gid tables */
1093 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
1094 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
1095 + ERROR("Failed to allocate uid/gid table\n");
1096 + goto failed_mount3;
1098 + msBlk->guid = msBlk->uid + sBlk->no_uids;
1101 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1103 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1104 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1105 + SERROR("unable to read uid/gid table\n");
1106 + goto failed_mount4;
1108 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1110 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1111 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1112 + SERROR("unable to read uid/gid table\n");
1113 + goto failed_mount4;
1117 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1118 + if(sBlk->s_major == 1) {
1119 + msBlk->iget = squashfs_iget_1;
1120 + msBlk->read_blocklist = read_blocklist_1;
1121 + msBlk->fragment = NULL;
1122 + msBlk->fragment_index = NULL;
1123 + goto allocate_root;
1126 + msBlk->iget = squashfs_iget;
1127 + msBlk->read_blocklist = read_blocklist;
1129 + if(!(msBlk->fragment = (struct squashfs_fragment_cache *) kmalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1130 + ERROR("Failed to allocate fragment block cache\n");
1131 + goto failed_mount4;
1134 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1135 + msBlk->fragment[i].locked = 0;
1136 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
1137 + msBlk->fragment[i].data = NULL;
1140 + msBlk->next_fragment = 0;
1142 + /* Allocate fragment index table */
1143 + if(!(msBlk->fragment_index = (squashfs_fragment_index *) kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), GFP_KERNEL))) {
1144 + ERROR("Failed to allocate uid/gid table\n");
1145 + goto failed_mount5;
1148 + if(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) &&
1149 + !read_data(s, (char *) msBlk->fragment_index, sBlk->fragment_table_start,
1150 + SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1151 + SERROR("unable to read fragment index table\n");
1152 + goto failed_mount6;
1157 + squashfs_fragment_index fragment;
1159 + for(i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments); i++) {
1160 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment), &msBlk->fragment_index[i], 1);
1161 + msBlk->fragment_index[i] = fragment;
1165 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1168 + if(!(s->s_root = d_alloc_root((msBlk->iget)(s, sBlk->root_inode)))) {
1169 + ERROR("Root inode create failed\n");
1170 + goto failed_mount5;
1173 + TRACE("Leaving squashfs_read_super\n");
1177 + kfree(msBlk->fragment_index);
1179 + kfree(msBlk->fragment);
1181 + kfree(msBlk->uid);
1183 + kfree(msBlk->read_page);
1185 + kfree(msBlk->read_data);
1187 + kfree(msBlk->block_cache);
1189 + kfree(s->s_fs_info);
1190 + s->s_fs_info = NULL;
1195 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1197 + squashfs_super_block *sBlk = &((squashfs_sb_info *)s->s_fs_info)->sBlk;
1199 + TRACE("Entered squashfs_statfs\n");
1200 + buf->f_type = SQUASHFS_MAGIC;
1201 + buf->f_bsize = sBlk->block_size;
1202 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
1203 + buf->f_bfree = buf->f_bavail = 0;
1204 + buf->f_files = sBlk->inodes;
1206 + buf->f_namelen = SQUASHFS_NAME_LEN;
1211 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1213 + struct inode *inode = page->mapping->host;
1214 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1215 + unsigned int block = SQUASHFS_I(inode)->start_block;
1216 + int offset = SQUASHFS_I(inode)->offset;
1217 + void *pageaddr = kmap(page);
1219 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
1220 + page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(inode)->offset);
1222 + for(length = 0; length < index; length += bytes) {
1223 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
1224 + PAGE_CACHE_SIZE, &block, &offset))) {
1225 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1230 + if(length != index) {
1231 + ERROR("(squashfs_symlink_readpage) length != index\n");
1236 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
1237 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
1238 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1241 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1243 + flush_dcache_page(page);
1244 + SetPageUptodate(page);
1245 + unlock_page(page);
1253 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1254 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
1255 + char *block_list, unsigned short **block_p, unsigned int *bsize)
1257 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1258 + unsigned short *block_listp;
1260 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1261 + int offset = SQUASHFS_I(inode)->offset;
1262 + unsigned int block = SQUASHFS_I(inode)->start_block;
1265 + int blocks = (index + readahead_blks - i);
1266 + if(blocks > (SIZE >> 1)) {
1267 + if((index - i) <= (SIZE >> 1))
1268 + blocks = index - i;
1270 + blocks = SIZE >> 1;
1274 + unsigned char sblock_list[SIZE];
1275 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1276 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1279 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1281 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1282 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1285 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1286 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1287 + if(blocks >= readahead_blks)
1292 + *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1294 + *block_p = block_listp;
1300 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1301 + char *block_list, unsigned short **block_p, unsigned int *bsize)
1303 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1304 + unsigned int *block_listp;
1306 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1307 + int offset = SQUASHFS_I(inode)->offset;
1308 + unsigned int block = SQUASHFS_I(inode)->start_block;
1311 + int blocks = (index + readahead_blks - i);
1312 + if(blocks > (SIZE >> 2)) {
1313 + if((index - i) <= (SIZE >> 2))
1314 + blocks = index - i;
1316 + blocks = SIZE >> 2;
1320 + unsigned char sblock_list[SIZE];
1321 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1322 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1325 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1327 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1328 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1331 + for(block_listp = (unsigned int *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1332 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1333 + if(blocks >= readahead_blks)
1337 + *bsize = *block_listp;
1342 +static int squashfs_readpage(struct file *file, struct page *page)
1344 + struct inode *inode = page->mapping->host;
1345 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1346 + squashfs_super_block *sBlk = &msBlk->sBlk;
1347 + unsigned char block_list[SIZE];
1348 + unsigned int bsize, block, i = 0, bytes = 0, byte_offset = 0;
1349 + int index = page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT);
1350 + void *pageaddr = kmap(page);
1351 + struct squashfs_fragment_cache *fragment = NULL;
1352 + char *data_ptr = msBlk->read_page;
1354 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1355 + int start_index = page->index & ~mask;
1356 + int end_index = start_index | mask;
1358 + TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1359 + SQUASHFS_I(inode)->start_block);
1361 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)) {
1365 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log)) {
1366 + if((block = (msBlk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize)) == 0)
1369 + down(&msBlk->read_page_mutex);
1370 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, bsize, NULL))) {
1371 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1372 + up(&msBlk->read_page_mutex);
1376 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->u.s1.fragment_start_block, SQUASHFS_I(inode)->u.s1.fragment_size)) == NULL) {
1377 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->u.s1.fragment_start_block, (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1380 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset + (inode->i_size & (sBlk->block_size - 1));
1381 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1382 + data_ptr = fragment->data;
1385 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1386 + struct page *push_page;
1387 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1389 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1391 + if(i == page->index) {
1392 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1393 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1395 + flush_dcache_page(page);
1396 + SetPageUptodate(page);
1397 + unlock_page(page);
1398 + } else if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1399 + void *pageaddr = kmap(push_page);
1400 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1401 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1402 + kunmap(push_page);
1403 + flush_dcache_page(push_page);
1404 + SetPageUptodate(push_page);
1405 + unlock_page(push_page);
1406 + page_cache_release(push_page);
1410 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log))
1411 + up(&msBlk->read_page_mutex);
1413 + release_cached_fragment(msBlk, fragment);
1418 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1420 + flush_dcache_page(page);
1421 + SetPageUptodate(page);
1422 + unlock_page(page);
1428 +static int squashfs_readpage4K(struct file *file, struct page *page)
1430 + struct inode *inode = page->mapping->host;
1431 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1432 + squashfs_super_block *sBlk = &msBlk->sBlk;
1433 + unsigned char block_list[SIZE];
1434 + unsigned int bsize, block, bytes = 0;
1435 + void *pageaddr = kmap(page);
1437 + TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1438 + SQUASHFS_I(inode)->start_block);
1440 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT)) {
1444 + if(SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK || page->index < (inode->i_size >> sBlk->block_log)) {
1445 + block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1447 + if(!(bytes = read_data(inode->i_sb, pageaddr, block, bsize, NULL)))
1448 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1450 + struct squashfs_fragment_cache *fragment;
1452 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->u.s1.fragment_start_block, SQUASHFS_I(inode)->u.s1.fragment_size)) == NULL)
1453 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->u.s1.fragment_start_block, (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1455 + bytes = inode->i_size & (sBlk->block_size - 1);
1456 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset, bytes);
1457 + release_cached_fragment(msBlk, fragment);
1462 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1464 + flush_dcache_page(page);
1465 + SetPageUptodate(page);
1466 + unlock_page(page);
1472 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1473 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1475 + struct inode *inode = page->mapping->host;
1476 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1477 + squashfs_super_block *sBlk = &msBlk->sBlk;
1478 + unsigned char block_list[SIZE];
1479 + unsigned short *block_listp, block, bytes = 0;
1480 + int index = page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
1481 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
1482 + int readahead_blks = 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
1483 + void *pageaddr = kmap(page);
1485 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1488 + TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1489 + SQUASHFS_I(inode)->start_block);
1491 + block = read_blocklist_1(inode, index, readahead_blks, block_list, &block_listp, NULL);
1493 + if(i_end > file_blocks)
1494 + i_end = file_blocks;
1496 + while(index < i_end) {
1497 + int c_byte = !SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_SIZE(*block_listp) | SQUASHFS_COMPRESSED_BIT_BLOCK : *block_listp;
1498 + if(!(byte = read_data(inode->i_sb, pageaddr, block, c_byte, NULL))) {
1499 + ERROR("Unable to read page, block %x, size %x\n", block, *block_listp);
1502 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1510 + memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1512 + flush_dcache_page(page);
1513 + SetPageUptodate(page);
1514 + unlock_page(page);
1521 +static int get_dir_index_using_offset(struct super_block *s, unsigned int *next_block,
1522 + unsigned int *next_offset, unsigned int index_start, unsigned int index_offset,
1523 + int i_count, long long f_pos)
1525 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
1526 + squashfs_super_block *sBlk = &msBlk->sBlk;
1527 + int i, length = 0;
1528 + squashfs_dir_index index;
1530 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n", i_count, (unsigned int) f_pos);
1535 + for(i = 0; i < i_count; i++) {
1537 + squashfs_dir_index sindex;
1538 + squashfs_get_cached_block(s, (char *) &sindex, index_start, index_offset,
1539 + sizeof(sindex), &index_start, &index_offset);
1540 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1542 + squashfs_get_cached_block(s, (char *) &index, index_start, index_offset,
1543 + sizeof(index), &index_start, &index_offset);
1545 + if(index.index > f_pos)
1548 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1549 + index.size + 1, &index_start, &index_offset);
1551 + length = index.index;
1552 + *next_block = index.start_block + sBlk->directory_table_start;
1555 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1560 +static int get_dir_index_using_name(struct super_block *s, unsigned int *next_block,
1561 + unsigned int *next_offset, unsigned int index_start, unsigned int index_offset,
1562 + int i_count, const char *name, int size)
1564 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
1565 + squashfs_super_block *sBlk = &msBlk->sBlk;
1566 + int i, length = 0;
1567 + char buffer[sizeof(squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1568 + squashfs_dir_index *index = (squashfs_dir_index *) buffer;
1569 + char str[SQUASHFS_NAME_LEN + 1];
1571 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1573 + strncpy(str, name, size);
1576 + for(i = 0; i < i_count; i++) {
1578 + squashfs_dir_index sindex;
1579 + squashfs_get_cached_block(s, (char *) &sindex, index_start, index_offset,
1580 + sizeof(sindex), &index_start, &index_offset);
1581 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1583 + squashfs_get_cached_block(s, (char *) index, index_start, index_offset,
1584 + sizeof(squashfs_dir_index), &index_start, &index_offset);
1586 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1587 + index->size + 1, &index_start, &index_offset);
1589 + index->name[index->size + 1] = '\0';
1591 + if(strcmp(index->name, str) > 0)
1594 + length = index->index;
1595 + *next_block = index->start_block + sBlk->directory_table_start;
1598 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1603 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1605 + struct inode *i = file->f_dentry->d_inode;
1606 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1607 + squashfs_super_block *sBlk = &msBlk->sBlk;
1608 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1609 + SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
1610 + squashfs_dir_header dirh;
1611 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1612 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1614 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1618 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset, SQUASHFS_I(i)->u.s2.directory_index_start,
1619 + SQUASHFS_I(i)->u.s2.directory_index_offset, SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1621 + while(length < i->i_size) {
1622 + /* read directory header */
1624 + squashfs_dir_header sdirh;
1625 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1626 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1628 + length += sizeof(sdirh);
1629 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1631 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1632 + next_offset, sizeof(dirh), &next_block, &next_offset))
1634 + length += sizeof(dirh);
1637 + dir_count = dirh.count + 1;
1638 + while(dir_count--) {
1640 + squashfs_dir_entry sdire;
1641 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1642 + next_offset, sizeof(sdire), &next_block, &next_offset))
1644 + length += sizeof(sdire);
1645 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1647 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1648 + next_offset, sizeof(*dire), &next_block, &next_offset))
1650 + length += sizeof(*dire);
1653 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1654 + next_offset, dire->size + 1, &next_block, &next_offset))
1656 + length += dire->size + 1;
1658 + if(file->f_pos >= length)
1661 + dire->name[dire->size + 1] = '\0';
1663 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", (unsigned int) dirent,
1664 + dire->name, dire->size + 1, (int) file->f_pos,
1665 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1667 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1668 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1669 + TRACE("Filldir returned less than 0\n");
1674 + file->f_pos = length;
1684 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1689 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
1691 + const unsigned char *name =dentry->d_name.name;
1692 + int len = dentry->d_name.len;
1693 + struct inode *inode = NULL;
1694 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1695 + squashfs_super_block *sBlk = &msBlk->sBlk;
1696 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1697 + SQUASHFS_I(i)->offset, length = 0, dir_count;
1698 + squashfs_dir_header dirh;
1699 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1700 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1701 + int squashfs_2_1 = sBlk->s_major == 2 && sBlk->s_minor == 1;
1703 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1707 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset, SQUASHFS_I(i)->u.s2.directory_index_start,
1708 + SQUASHFS_I(i)->u.s2.directory_index_offset, SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
1710 + while(length < i->i_size) {
1711 + /* read directory header */
1713 + squashfs_dir_header sdirh;
1714 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1715 + sizeof(sdirh), &next_block, &next_offset))
1717 + length += sizeof(sdirh);
1718 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1720 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1721 + sizeof(dirh), &next_block, &next_offset))
1723 + length += sizeof(dirh);
1726 + dir_count = dirh.count + 1;
1727 + while(dir_count--) {
1729 + squashfs_dir_entry sdire;
1730 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1731 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1733 + length += sizeof(sdire);
1734 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1736 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1737 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1739 + length += sizeof(*dire);
1742 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1743 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1745 + length += dire->size + 1;
1747 + if(squashfs_2_1 && name[0] < dire->name[0])
1750 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1751 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1753 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1754 + name, dirh.start_block, dire->offset);
1756 + inode = (msBlk->iget)(i->i_sb, ino);
1764 + d_add(dentry, inode);
1766 + return ERR_PTR(0);
1769 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1774 +static void squashfs_put_super(struct super_block *s)
1778 + if(s->s_fs_info) {
1779 + squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1780 + if(sbi->block_cache) {
1781 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1782 + if(sbi->block_cache[i].block != SQUASHFS_INVALID_BLK)
1783 + kfree(sbi->block_cache[i].data);
1784 + kfree(sbi->block_cache);
1786 + if(sbi->read_data) kfree(sbi->read_data);
1787 + if(sbi->read_page) kfree(sbi->read_page);
1788 + if(sbi->uid) kfree(sbi->uid);
1789 + if(sbi->fragment) {
1790 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
1791 + if(sbi->fragment[i].data != NULL)
1792 + SQUASHFS_FREE(sbi->fragment[i].data);
1793 + kfree(sbi->fragment);
1795 + if(sbi->fragment_index) kfree(sbi->fragment_index);
1796 + kfree(s->s_fs_info);
1797 + s->s_fs_info = NULL;
1802 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1804 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1808 +static int __init init_squashfs_fs(void)
1810 + int err = init_inodecache();
1814 + printk(KERN_INFO "Squashfs 2.2 (released 2005/07/03) (C) 2002-2005 Phillip Lougher\n");
1816 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1817 + ERROR("Failed to allocate zlib workspace\n");
1818 + destroy_inodecache();
1822 + if((err = register_filesystem(&squashfs_fs_type))) {
1823 + vfree(stream.workspace);
1824 + destroy_inodecache();
1831 +static void __exit exit_squashfs_fs(void)
1833 + vfree(stream.workspace);
1834 + unregister_filesystem(&squashfs_fs_type);
1835 + destroy_inodecache();
1839 +static kmem_cache_t * squashfs_inode_cachep;
1842 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1844 + struct squashfs_inode_info *ei;
1845 + ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1848 + return &ei->vfs_inode;
1852 +static void squashfs_destroy_inode(struct inode *inode)
1854 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1858 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1860 + struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1862 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1863 + SLAB_CTOR_CONSTRUCTOR)
1864 + inode_init_once(&ei->vfs_inode);
1868 +static int init_inodecache(void)
1870 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1871 + sizeof(struct squashfs_inode_info),
1872 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1874 + if (squashfs_inode_cachep == NULL)
1880 +static void destroy_inodecache(void)
1882 + if (kmem_cache_destroy(squashfs_inode_cachep))
1883 + printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1887 +module_init(init_squashfs_fs);
1888 +module_exit(exit_squashfs_fs);
1889 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1890 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1891 +MODULE_LICENSE("GPL");
1892 diff --new-file -urp linux-2.6.12/fs/squashfs/Makefile linux-2.6.12-squashfs2.2/fs/squashfs/Makefile
1893 --- linux-2.6.12/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
1894 +++ linux-2.6.12-squashfs2.2/fs/squashfs/Makefile 2005-07-04 02:35:35.000000000 +0100
1897 +# Makefile for the linux squashfs routines.
1900 +obj-$(CONFIG_SQUASHFS) += squashfs.o
1902 +squashfs-objs := inode.o
1903 diff --new-file -urp linux-2.6.12/include/linux/squashfs_fs.h linux-2.6.12-squashfs2.2/include/linux/squashfs_fs.h
1904 --- linux-2.6.12/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
1905 +++ linux-2.6.12-squashfs2.2/include/linux/squashfs_fs.h 2005-07-04 02:35:35.000000000 +0100
1907 +#ifndef SQUASHFS_FS
1908 +#define SQUASHFS_FS
1912 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
1914 + * This program is free software; you can redistribute it and/or
1915 + * modify it under the terms of the GNU General Public License
1916 + * as published by the Free Software Foundation; either version 2,
1917 + * or (at your option) any later version.
1919 + * This program is distributed in the hope that it will be useful,
1920 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1921 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1922 + * GNU General Public License for more details.
1924 + * You should have received a copy of the GNU General Public License
1925 + * along with this program; if not, write to the Free Software
1926 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1931 +#ifdef CONFIG_SQUASHFS_VMALLOC
1932 +#define SQUASHFS_ALLOC(a) vmalloc(a)
1933 +#define SQUASHFS_FREE(a) vfree(a)
1935 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
1936 +#define SQUASHFS_FREE(a) kfree(a)
1938 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
1939 +#define SQUASHFS_MAJOR 2
1940 +#define SQUASHFS_MINOR 1
1941 +#define SQUASHFS_MAGIC 0x73717368
1942 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1943 +#define SQUASHFS_START 0
1945 +/* size of metadata (inode and directory) blocks */
1946 +#define SQUASHFS_METADATA_SIZE 8192
1947 +#define SQUASHFS_METADATA_LOG 13
1949 +/* default size of data blocks */
1950 +#define SQUASHFS_FILE_SIZE 65536
1951 +#define SQUASHFS_FILE_LOG 16
1953 +#define SQUASHFS_FILE_MAX_SIZE 65536
1955 +/* Max number of uids and gids */
1956 +#define SQUASHFS_UIDS 256
1957 +#define SQUASHFS_GUIDS 255
1959 +/* Max length of filename (not 255) */
1960 +#define SQUASHFS_NAME_LEN 256
1962 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1963 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1964 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1966 +/* Filesystem flags */
1967 +#define SQUASHFS_NOI 0
1968 +#define SQUASHFS_NOD 1
1969 +#define SQUASHFS_CHECK 2
1970 +#define SQUASHFS_NOF 3
1971 +#define SQUASHFS_NO_FRAG 4
1972 +#define SQUASHFS_ALWAYS_FRAG 5
1973 +#define SQUASHFS_DUPLICATE 6
1974 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
1975 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
1976 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
1977 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1978 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1979 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1980 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1981 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1982 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking) (noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))
1984 +/* Max number of types and file types */
1985 +#define SQUASHFS_DIR_TYPE 1
1986 +#define SQUASHFS_FILE_TYPE 2
1987 +#define SQUASHFS_SYMLINK_TYPE 3
1988 +#define SQUASHFS_BLKDEV_TYPE 4
1989 +#define SQUASHFS_CHRDEV_TYPE 5
1990 +#define SQUASHFS_FIFO_TYPE 6
1991 +#define SQUASHFS_SOCKET_TYPE 7
1992 +#define SQUASHFS_LDIR_TYPE 8
1994 +/* 1.0 filesystem type definitions */
1995 +#define SQUASHFS_TYPES 5
1996 +#define SQUASHFS_IPC_TYPE 0
1998 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1999 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
2000 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
2001 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
2003 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
2005 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
2006 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
2007 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
2009 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
2012 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
2013 + * offset within that block
2015 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
2016 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
2017 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
2020 +/* Compute 32 bit VFS inode number from squashfs inode number */
2021 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
2023 +/* Translate between VFS mode and squashfs mode */
2024 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
2026 +/* fragment and fragment table defines */
2027 +typedef unsigned int squashfs_fragment_index;
2028 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
2029 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
2030 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
2031 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
2032 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
2034 +/* cached data constants for filesystem */
2035 +#define SQUASHFS_CACHED_BLKS 8
2037 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
2038 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
2040 +#define SQUASHFS_MARKER_BYTE 0xff
2044 + * definitions for structures on disk
2047 +typedef unsigned int squashfs_block;
2048 +typedef long long squashfs_inode;
2050 +typedef unsigned int squashfs_uid;
2052 +typedef struct squashfs_super_block {
2053 + unsigned int s_magic;
2054 + unsigned int inodes;
2055 + unsigned int bytes_used;
2056 + unsigned int uid_start;
2057 + unsigned int guid_start;
2058 + unsigned int inode_table_start;
2059 + unsigned int directory_table_start;
2060 + unsigned int s_major:16;
2061 + unsigned int s_minor:16;
2062 + unsigned int block_size_1:16;
2063 + unsigned int block_log:16;
2064 + unsigned int flags:8;
2065 + unsigned int no_uids:8;
2066 + unsigned int no_guids:8;
2067 + unsigned int mkfs_time /* time of filesystem creation */;
2068 + squashfs_inode root_inode;
2069 + unsigned int block_size;
2070 + unsigned int fragments;
2071 + unsigned int fragment_table_start;
2072 +} __attribute__ ((packed)) squashfs_super_block;
2075 + unsigned int index:27;
2076 + unsigned int start_block:29;
2077 + unsigned char size;
2078 + unsigned char name[0];
2079 +} __attribute__ ((packed)) squashfs_dir_index;
2082 + unsigned int inode_type:4;
2083 + unsigned int mode:12; /* protection */
2084 + unsigned int uid:8; /* index into uid table */
2085 + unsigned int guid:8; /* index into guid table */
2086 +} __attribute__ ((packed)) squashfs_base_inode_header;
2088 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
2091 + unsigned int inode_type:4;
2092 + unsigned int mode:12; /* protection */
2093 + unsigned int uid:8; /* index into uid table */
2094 + unsigned int guid:8; /* index into guid table */
2095 + unsigned short rdev;
2096 +} __attribute__ ((packed)) squashfs_dev_inode_header;
2099 + unsigned int inode_type:4;
2100 + unsigned int mode:12; /* protection */
2101 + unsigned int uid:8; /* index into uid table */
2102 + unsigned int guid:8; /* index into guid table */
2103 + unsigned short symlink_size;
2105 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
2108 + unsigned int inode_type:4;
2109 + unsigned int mode:12; /* protection */
2110 + unsigned int uid:8; /* index into uid table */
2111 + unsigned int guid:8; /* index into guid table */
2112 + unsigned int mtime;
2113 + squashfs_block start_block;
2114 + unsigned int fragment;
2115 + unsigned int offset;
2116 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2117 + unsigned short block_list[0];
2118 +} __attribute__ ((packed)) squashfs_reg_inode_header;
2121 + unsigned int inode_type:4;
2122 + unsigned int mode:12; /* protection */
2123 + unsigned int uid:8; /* index into uid table */
2124 + unsigned int guid:8; /* index into guid table */
2125 + unsigned int file_size:19;
2126 + unsigned int offset:13;
2127 + unsigned int mtime;
2128 + unsigned int start_block:24;
2129 +} __attribute__ ((packed)) squashfs_dir_inode_header;
2132 + unsigned int inode_type:4;
2133 + unsigned int mode:12; /* protection */
2134 + unsigned int uid:8; /* index into uid table */
2135 + unsigned int guid:8; /* index into guid table */
2136 + unsigned int file_size:27;
2137 + unsigned int offset:13;
2138 + unsigned int mtime;
2139 + unsigned int start_block:24;
2140 + unsigned int i_count:16;
2141 + squashfs_dir_index index[0];
2142 +} __attribute__ ((packed)) squashfs_ldir_inode_header;
2145 + squashfs_base_inode_header base;
2146 + squashfs_dev_inode_header dev;
2147 + squashfs_symlink_inode_header symlink;
2148 + squashfs_reg_inode_header reg;
2149 + squashfs_dir_inode_header dir;
2150 + squashfs_ldir_inode_header ldir;
2151 + squashfs_ipc_inode_header ipc;
2152 +} squashfs_inode_header;
2155 + unsigned int offset:13;
2156 + unsigned int type:3;
2157 + unsigned int size:8;
2159 +} __attribute__ ((packed)) squashfs_dir_entry;
2162 + unsigned int count:8;
2163 + unsigned int start_block:24;
2164 +} __attribute__ ((packed)) squashfs_dir_header;
2167 + unsigned int start_block;
2168 + unsigned int size;
2169 +} __attribute__ ((packed)) squashfs_fragment_entry;
2171 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
2172 +extern int squashfs_uncompress_init(void);
2173 +extern int squashfs_uncompress_exit(void);
2176 + * macros to convert each packed bitfield structure from little endian to big
2177 + * endian and vice versa. These are needed when creating or using a filesystem on a
2178 + * machine with different byte ordering to the target architecture.
2182 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
2183 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
2184 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
2185 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
2186 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
2187 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
2188 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
2189 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
2190 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
2191 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
2192 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
2193 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
2194 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
2195 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
2196 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
2197 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
2198 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
2199 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
2200 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
2201 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
2202 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
2205 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
2206 + SQUASHFS_MEMSET(s, d, n);\
2207 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2208 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2209 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
2210 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
2213 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
2215 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
2216 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
2217 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
2220 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
2221 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
2222 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
2225 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
2226 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
2227 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
2228 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
2229 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
2230 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
2231 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
2234 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
2235 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
2236 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
2237 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
2238 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2239 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2242 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
2243 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ldir_inode_header));\
2244 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
2245 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
2246 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
2247 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
2248 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
2251 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
2252 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_index));\
2253 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
2254 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
2255 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
2258 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2259 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2260 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
2261 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2264 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2265 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2266 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2267 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
2268 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
2271 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2272 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2273 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2274 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
2277 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2279 + int bit_position;\
2280 + SQUASHFS_MEMSET(s, d, n * 2);\
2281 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2282 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2285 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2287 + int bit_position;\
2288 + SQUASHFS_MEMSET(s, d, n * 4);\
2289 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2290 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2293 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2295 + int bit_position;\
2296 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
2297 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2298 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2301 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2303 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2305 + unsigned int inode_type:4;
2306 + unsigned int mode:12; /* protection */
2307 + unsigned int uid:4; /* index into uid table */
2308 + unsigned int guid:4; /* index into guid table */
2309 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2312 + unsigned int inode_type:4;
2313 + unsigned int mode:12; /* protection */
2314 + unsigned int uid:4; /* index into uid table */
2315 + unsigned int guid:4; /* index into guid table */
2316 + unsigned int type:4;
2317 + unsigned int offset:4;
2318 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2321 + unsigned int inode_type:4;
2322 + unsigned int mode:12; /* protection */
2323 + unsigned int uid:4; /* index into uid table */
2324 + unsigned int guid:4; /* index into guid table */
2325 + unsigned short rdev;
2326 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2329 + unsigned int inode_type:4;
2330 + unsigned int mode:12; /* protection */
2331 + unsigned int uid:4; /* index into uid table */
2332 + unsigned int guid:4; /* index into guid table */
2333 + unsigned short symlink_size;
2335 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2338 + unsigned int inode_type:4;
2339 + unsigned int mode:12; /* protection */
2340 + unsigned int uid:4; /* index into uid table */
2341 + unsigned int guid:4; /* index into guid table */
2342 + unsigned int mtime;
2343 + squashfs_block start_block;
2344 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2345 + unsigned short block_list[0];
2346 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2349 + unsigned int inode_type:4;
2350 + unsigned int mode:12; /* protection */
2351 + unsigned int uid:4; /* index into uid table */
2352 + unsigned int guid:4; /* index into guid table */
2353 + unsigned int file_size:19;
2354 + unsigned int offset:13;
2355 + unsigned int mtime;
2356 + unsigned int start_block:24;
2357 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
2359 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2360 + SQUASHFS_MEMSET(s, d, n);\
2361 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2362 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2363 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2364 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2367 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2368 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2369 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
2370 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2373 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2374 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2375 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2378 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2379 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2380 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2383 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2384 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2385 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2386 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2387 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2390 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2391 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2392 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2393 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2394 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2395 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2401 + * macros used to swap each structure entry, taking into account
2402 + * bitfields and different bitfield placing conventions on differing architectures
2404 +#include <asm/byteorder.h>
2405 +#ifdef __BIG_ENDIAN
2406 + /* convert from little endian to big endian */
2407 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2409 + /* convert from big endian to little endian */
2410 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2413 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2415 + int b_pos = pos % 8;\
2416 + unsigned long long val = 0;\
2417 + unsigned char *s = (unsigned char *)p + (pos / 8);\
2418 + unsigned char *d = ((unsigned char *) &val) + 7;\
2419 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2421 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2423 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
2426 diff --new-file -urp linux-2.6.12/include/linux/squashfs_fs_i.h linux-2.6.12-squashfs2.2/include/linux/squashfs_fs_i.h
2427 --- linux-2.6.12/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
2428 +++ linux-2.6.12-squashfs2.2/include/linux/squashfs_fs_i.h 2005-07-04 02:35:35.000000000 +0100
2430 +#ifndef SQUASHFS_FS_I
2431 +#define SQUASHFS_FS_I
2435 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
2437 + * This program is free software; you can redistribute it and/or
2438 + * modify it under the terms of the GNU General Public License
2439 + * as published by the Free Software Foundation; either version 2,
2440 + * or (at your option) any later version.
2442 + * This program is distributed in the hope that it will be useful,
2443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2445 + * GNU General Public License for more details.
2447 + * You should have received a copy of the GNU General Public License
2448 + * along with this program; if not, write to the Free Software
2449 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2454 +typedef struct squashfs_inode_info {
2455 + unsigned int start_block;
2456 + unsigned int block_list_start;
2457 + unsigned int offset;
2460 + unsigned int fragment_start_block;
2461 + unsigned int fragment_size;
2462 + unsigned int fragment_offset;
2465 + unsigned int directory_index_start;
2466 + unsigned int directory_index_offset;
2467 + unsigned int directory_index_count;
2470 + struct inode vfs_inode;
2471 + } squashfs_inode_info;
2473 diff --new-file -urp linux-2.6.12/include/linux/squashfs_fs_sb.h linux-2.6.12-squashfs2.2/include/linux/squashfs_fs_sb.h
2474 --- linux-2.6.12/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
2475 +++ linux-2.6.12-squashfs2.2/include/linux/squashfs_fs_sb.h 2005-07-04 02:35:35.000000000 +0100
2477 +#ifndef SQUASHFS_FS_SB
2478 +#define SQUASHFS_FS_SB
2482 + * Copyright (c) 2002, 2003, 2004, 2005 Phillip Lougher <phillip@lougher.demon.co.uk>
2484 + * This program is free software; you can redistribute it and/or
2485 + * modify it under the terms of the GNU General Public License
2486 + * as published by the Free Software Foundation; either version 2,
2487 + * or (at your option) any later version.
2489 + * This program is distributed in the hope that it will be useful,
2490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2492 + * GNU General Public License for more details.
2494 + * You should have received a copy of the GNU General Public License
2495 + * along with this program; if not, write to the Free Software
2496 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2498 + * squashfs_fs_sb.h
2501 +#include <linux/squashfs_fs.h>
2504 + unsigned int block;
2506 + unsigned int next_index;
2510 +struct squashfs_fragment_cache {
2511 + unsigned int block;
2513 + unsigned int locked;
2517 +typedef struct squashfs_sb_info {
2518 + squashfs_super_block sBlk;
2520 + int devblksize_log2;
2522 + squashfs_cache *block_cache;
2523 + struct squashfs_fragment_cache *fragment;
2525 + int next_fragment;
2526 + squashfs_uid *uid;
2527 + squashfs_uid *guid;
2528 + squashfs_fragment_index *fragment_index;
2529 + unsigned int read_size;
2532 + struct semaphore read_page_mutex;
2533 + struct semaphore block_cache_mutex;
2534 + struct semaphore fragment_mutex;
2535 + wait_queue_head_t waitq;
2536 + wait_queue_head_t fragment_wait_queue;
2537 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
2538 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2539 + char *block_list, unsigned short **block_p, unsigned int *bsize);
2540 + } squashfs_sb_info;
2542 diff --new-file -urp linux-2.6.12/init/do_mounts_rd.c linux-2.6.12-squashfs2.2/init/do_mounts_rd.c
2543 --- linux-2.6.12/init/do_mounts_rd.c 2005-06-17 20:48:29.000000000 +0100
2544 +++ linux-2.6.12-squashfs2.2/init/do_mounts_rd.c 2005-07-04 02:35:35.000000000 +0100
2546 #include <linux/ext2_fs.h>
2547 #include <linux/romfs_fs.h>
2548 #include <linux/cramfs_fs.h>
2549 +#include <linux/squashfs_fs.h>
2550 #include <linux/initrd.h>
2551 #include <linux/string.h>
2553 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
2554 * numbers could not be found.
2556 * We currently check for the following magic numbers:
2561 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
2562 struct ext2_super_block *ext2sb;
2563 struct romfs_super_block *romfsb;
2564 struct cramfs_super *cramfsb;
2565 + struct squashfs_super_block *squashfsb;
2569 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
2570 ext2sb = (struct ext2_super_block *) buf;
2571 romfsb = (struct romfs_super_block *) buf;
2572 cramfsb = (struct cramfs_super *) buf;
2573 + squashfsb = (struct squashfs_super_block *) buf;
2574 memset(buf, 0xe5, size);
2577 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
2581 + /* squashfs is at block zero too */
2582 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2583 + printk(KERN_NOTICE
2584 + "RAMDISK: squashfs filesystem found at block %d\n",
2586 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2591 * Read block 1 to test for minix and ext2 superblock