1 diff --new-file -ur linux-2.6.8.1/fs/Kconfig linux-2.6.8.1-squashfs2.0/fs/Kconfig
2 --- linux-2.6.8.1/fs/Kconfig 2004-08-14 11:55:33.000000000 +0100
3 +++ linux-2.6.8.1-squashfs2.0/fs/Kconfig 2004-08-30 13:36:25.000000000 +0100
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.
32 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
34 diff --new-file -ur linux-2.6.8.1/fs/Makefile linux-2.6.8.1-squashfs2.0/fs/Makefile
35 --- linux-2.6.8.1/fs/Makefile 2004-08-14 11:55:33.000000000 +0100
36 +++ linux-2.6.8.1-squashfs2.0/fs/Makefile 2004-08-30 13:36:25.000000000 +0100
38 obj-$(CONFIG_JBD) += jbd/
39 obj-$(CONFIG_EXT2_FS) += ext2/
40 obj-$(CONFIG_CRAMFS) += cramfs/
41 +obj-$(CONFIG_SQUASHFS) += squashfs/
42 obj-$(CONFIG_RAMFS) += ramfs/
43 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
44 obj-$(CONFIG_CODA_FS) += coda/
45 diff --new-file -ur linux-2.6.8.1/fs/squashfs/inode.c linux-2.6.8.1-squashfs2.0/fs/squashfs/inode.c
46 --- linux-2.6.8.1/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
47 +++ linux-2.6.8.1-squashfs2.0/fs/squashfs/inode.c 2004-08-30 13:41:34.000000000 +0100
50 + * Squashfs - a compressed read only filesystem for Linux
52 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
54 + * This program is free software; you can redistribute it and/or
55 + * modify it under the terms of the GNU General Public License
56 + * as published by the Free Software Foundation; either version 2,
57 + * or (at your option) any later version.
59 + * This program is distributed in the hope that it will be useful,
60 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
61 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62 + * GNU General Public License for more details.
64 + * You should have received a copy of the GNU General Public License
65 + * along with this program; if not, write to the Free Software
66 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
71 +#define SQUASHFS_1_0_COMPATIBILITY
73 +#include <linux/types.h>
74 +#include <linux/squashfs_fs.h>
75 +#include <linux/module.h>
76 +#include <linux/errno.h>
77 +#include <linux/slab.h>
78 +#include <linux/fs.h>
79 +#include <linux/smp_lock.h>
80 +#include <linux/slab.h>
81 +#include <linux/squashfs_fs_sb.h>
82 +#include <linux/squashfs_fs_i.h>
83 +#include <linux/buffer_head.h>
84 +#include <linux/vfs.h>
85 +#include <linux/init.h>
86 +#include <linux/dcache.h>
87 +#include <asm/uaccess.h>
88 +#include <linux/wait.h>
89 +#include <asm/semaphore.h>
90 +#include <linux/zlib.h>
91 +#include <linux/blkdev.h>
92 +#include <linux/vmalloc.h>
94 +#ifdef SQUASHFS_TRACE
95 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
97 +#define TRACE(s, args...) {}
100 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
102 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
103 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
105 +static void squashfs_put_super(struct super_block *);
106 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
107 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
108 +static int squashfs_readpage(struct file *file, struct page *page);
109 +static int squashfs_readpage4K(struct file *file, struct page *page);
110 +static int squashfs_readdir(struct file *, void *, filldir_t);
111 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *, struct nameidata *);
112 +static unsigned int read_data(struct super_block *s, char *buffer,
113 + unsigned int index, unsigned int length, int, unsigned int *next_index);
114 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
115 + unsigned int block, unsigned int offset, int length,
116 + unsigned int *next_block, unsigned int *next_offset);
117 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
118 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
119 + char *block_list, char **block_p, unsigned int *bsize);
120 +static void squashfs_put_super(struct super_block *s);
121 +static struct super_block *squashfs_get_sb(struct file_system_type *, int, const char *, void *);
122 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
123 +static void squashfs_destroy_inode(struct inode *inode);
124 +static int init_inodecache(void);
125 +static void destroy_inodecache(void);
127 +#ifdef SQUASHFS_1_0_COMPATIBILITY
128 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page);
129 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode);
130 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
131 + char *block_list, char **block_p, unsigned int *bsize);
134 +DECLARE_MUTEX(read_data_mutex);
136 +static z_stream stream;
138 +static struct file_system_type squashfs_fs_type = {
139 + .owner = THIS_MODULE,
140 + .name = "squashfs",
141 + .get_sb = squashfs_get_sb,
142 + .kill_sb = kill_block_super,
143 + .fs_flags = FS_REQUIRES_DEV
146 +static unsigned char squashfs_filetype_table[] = {
147 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
150 +static struct super_operations squashfs_ops = {
151 + .alloc_inode = squashfs_alloc_inode,
152 + .destroy_inode = squashfs_destroy_inode,
153 + .statfs = squashfs_statfs,
154 + .put_super = squashfs_put_super,
157 +static struct address_space_operations squashfs_symlink_aops = {
158 + .readpage = squashfs_symlink_readpage
161 +static struct address_space_operations squashfs_aops = {
162 + .readpage = squashfs_readpage
165 +static struct address_space_operations squashfs_aops_4K = {
166 + .readpage = squashfs_readpage4K
169 +#ifdef SQUASHFS_1_0_COMPATIBILITY
170 +static struct address_space_operations squashfs_aops_lessthan4K = {
171 + .readpage = squashfs_readpage_lessthan4K
175 +static struct file_operations squashfs_dir_ops = {
176 + .read = generic_read_dir,
177 + .readdir = squashfs_readdir
180 +static struct inode_operations squashfs_dir_inode_ops = {
181 + .lookup = squashfs_lookup
185 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
187 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
191 +static unsigned int read_data(struct super_block *s, char *buffer,
192 + unsigned int index, unsigned int length, int datablock, unsigned int *next_index)
194 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
195 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
196 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
197 + unsigned int cur_index = index >> msBlk->devblksize_log2;
198 + int bytes, avail_bytes, b, k;
200 + unsigned int compressed;
201 + unsigned int c_byte = length;
204 + bytes = msBlk->devblksize - offset;
206 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
207 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
209 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
210 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
213 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
215 + if(!(bh[0] = sb_getblk(s, cur_index)))
216 + goto block_release;
217 + for(b = 1; bytes < c_byte; b++) {
218 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
219 + goto block_release;
220 + bytes += msBlk->devblksize;
222 + ll_rw_block(READ, b, bh);
224 + unsigned short temp;
225 + if(!(bh[0] = sb_bread(s, cur_index)))
228 + if(msBlk->devblksize - offset == 1) {
230 + ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
232 + ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset));
234 + if(!(bh[0] = sb_bread(s, ++cur_index)))
237 + ((unsigned char *) &temp)[0] = *((unsigned char *) bh[0]->b_data);
239 + ((unsigned char *) &temp)[1] = *((unsigned char *) bh[0]->b_data);
245 + unsigned short temp;
246 + ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
247 + ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
250 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
253 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
254 + if(offset == msBlk->devblksize) {
256 + if(!(bh[0] = sb_bread(s, ++cur_index)))
260 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
261 + ERROR("Metadata block marker corrupt @ %x\n", index);
268 + bytes = msBlk->devblksize - offset;
270 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
271 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
273 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
274 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
277 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
279 + for(b = 1; bytes < c_byte; b++) {
280 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
281 + goto block_release;
282 + bytes += msBlk->devblksize;
284 + ll_rw_block(READ, b - 1, bh + 1);
288 + down(&read_data_mutex);
290 + for(bytes = 0, k = 0; k < b; k++) {
291 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
292 + wait_on_buffer(bh[k]);
293 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
294 + bytes += avail_bytes;
305 + stream.next_in = c_buffer;
306 + stream.avail_in = c_byte;
307 + stream.next_out = buffer;
308 + stream.avail_out = msBlk->read_size;
309 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
310 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
311 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
312 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
315 + bytes = stream.total_out;
316 + up(&read_data_mutex);
320 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
325 + while(--b >= 0) brelse(bh[b]);
328 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
333 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
334 + unsigned int block, unsigned int offset, int length,
335 + unsigned int *next_block, unsigned int *next_offset)
337 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
338 + int n, i, bytes, return_length = length;
339 + unsigned int next_index;
341 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
344 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
345 + if(msBlk->block_cache[i].block == block)
348 + down(&msBlk->block_cache_mutex);
349 + if(i == SQUASHFS_CACHED_BLKS) {
350 + /* read inode header block */
351 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
352 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
357 + init_waitqueue_entry(&wait, current);
358 + add_wait_queue(&msBlk->waitq, &wait);
359 + up(&msBlk->block_cache_mutex);
360 + set_current_state(TASK_UNINTERRUPTIBLE);
362 + set_current_state(TASK_RUNNING);
363 + remove_wait_queue(&msBlk->waitq, &wait);
366 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
368 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
369 + if(!(msBlk->block_cache[i].data = (unsigned char *)
370 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
371 + ERROR("Failed to allocate cache block\n");
372 + up(&msBlk->block_cache_mutex);
377 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
378 + up(&msBlk->block_cache_mutex);
379 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0, 0,
381 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
384 + down(&msBlk->block_cache_mutex);
385 + wake_up(&msBlk->waitq);
386 + msBlk->block_cache[i].block = block;
387 + msBlk->block_cache[i].next_index = next_index;
388 + TRACE("Read cache block [%x:%x]\n", block, offset);
391 + if(msBlk->block_cache[i].block != block) {
392 + up(&msBlk->block_cache_mutex);
396 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
398 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
399 + if(msBlk->block_cache[i].length - offset == length) {
400 + *next_block = msBlk->block_cache[i].next_index;
403 + *next_block = block;
404 + *next_offset = offset + length;
407 + up(&msBlk->block_cache_mutex);
408 + return return_length;
411 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
414 + block = msBlk->block_cache[i].next_index;
415 + up(&msBlk->block_cache_mutex);
423 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
425 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
426 + unsigned int start_block = msBlk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
427 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
428 + squashfs_fragment_entry fragment_entry;
431 + squashfs_fragment_entry sfragment_entry;
433 + if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
434 + sizeof(sfragment_entry), &start_block, &offset))
436 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
438 + if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
439 + sizeof(fragment_entry), &start_block, &offset))
442 + *fragment_start_block = fragment_entry.start_block;
443 + *fragment_size = fragment_entry.size;
449 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
451 + down(&msBlk->fragment_mutex);
452 + fragment->locked --;
453 + wake_up(&msBlk->fragment_wait_queue);
454 + up(&msBlk->fragment_mutex);
458 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
461 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
464 + down(&msBlk->fragment_mutex);
465 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS && msBlk->fragment[i].block != start_block; i++);
466 + if(i == SQUASHFS_CACHED_FRAGMENTS) {
467 + for(i = msBlk->next_fragment, n = SQUASHFS_CACHED_FRAGMENTS;
468 + n && msBlk->fragment[i].locked; n--, i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS);
473 + init_waitqueue_entry(&wait, current);
474 + add_wait_queue(&msBlk->fragment_wait_queue, &wait);
475 + up(&msBlk->fragment_mutex);
476 + set_current_state(TASK_UNINTERRUPTIBLE);
478 + set_current_state(TASK_RUNNING);
479 + remove_wait_queue(&msBlk->fragment_wait_queue, &wait);
482 + msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
484 + if(msBlk->fragment[i].data == NULL)
485 + if(!(msBlk->fragment[i].data = (unsigned char *)
486 + kmalloc(SQUASHFS_FILE_MAX_SIZE, GFP_KERNEL))) {
487 + ERROR("Failed to allocate fragment cache block\n");
488 + up(&msBlk->fragment_mutex);
492 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
493 + msBlk->fragment[i].locked = 1;
494 + up(&msBlk->fragment_mutex);
495 + if(!(msBlk->fragment[i].length = read_data(s, msBlk->fragment[i].data, start_block, length,
497 + ERROR("Unable to read fragment cache block [%x]\n", start_block);
498 + msBlk->fragment[i].locked = 0;
501 + msBlk->fragment[i].block = start_block;
502 + TRACE("New fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
503 + return &msBlk->fragment[i];
506 + msBlk->fragment[i].locked ++;
507 + up(&msBlk->fragment_mutex);
509 + TRACE("Got fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
510 + return &msBlk->fragment[i];
515 +#ifdef SQUASHFS_1_0_COMPATIBILITY
516 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
518 + struct inode *i = new_inode(s);
519 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
520 + squashfs_super_block *sBlk = &msBlk->sBlk;
521 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
522 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
523 + unsigned int next_block, next_offset;
524 + squashfs_base_inode_header_1 inodeb;
526 + TRACE("Entered squashfs_iget_1\n");
529 + squashfs_base_inode_header_1 sinodeb;
531 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
532 + sizeof(sinodeb), &next_block, &next_offset))
534 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
536 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
537 + sizeof(inodeb), &next_block, &next_offset))
542 + i->i_mtime.tv_sec = sBlk->mkfs_time;
543 + i->i_atime.tv_sec = sBlk->mkfs_time;
544 + i->i_ctime.tv_sec = sBlk->mkfs_time;
546 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
547 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
548 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
550 + i->i_mode = inodeb.mode;
552 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
553 + case SQUASHFS_FILE_TYPE: {
554 + squashfs_reg_inode_header_1 inodep;
557 + squashfs_reg_inode_header_1 sinodep;
559 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
560 + &next_block, &next_offset))
562 + SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
564 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
565 + &next_block, &next_offset))
568 + i->i_size = inodep.file_size;
569 + i->i_fop = &generic_ro_fops;
570 + if(sBlk->block_size > 4096)
571 + i->i_data.a_ops = &squashfs_aops;
572 + else if(sBlk->block_size == 4096)
573 + i->i_data.a_ops = &squashfs_aops_4K;
575 + i->i_data.a_ops = &squashfs_aops_lessthan4K;
576 + i->i_mode |= S_IFREG;
577 + i->i_mtime.tv_sec = inodep.mtime;
578 + i->i_atime.tv_sec = inodep.mtime;
579 + i->i_ctime.tv_sec = inodep.mtime;
580 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
581 + i->i_blksize = PAGE_CACHE_SIZE;
582 + SQUASHFS_I(i)->fragment_start_block = SQUASHFS_INVALID_BLK;
583 + SQUASHFS_I(i)->fragment_offset = 0;
584 + SQUASHFS_I(i)->start_block = inodep.start_block;
585 + SQUASHFS_I(i)->block_list_start = next_block;
586 + SQUASHFS_I(i)->offset = next_offset;
587 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
588 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
591 + case SQUASHFS_DIR_TYPE: {
592 + squashfs_dir_inode_header_1 inodep;
595 + squashfs_dir_inode_header_1 sinodep;
597 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
598 + &next_block, &next_offset))
600 + SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
602 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
603 + &next_block, &next_offset))
606 + i->i_size = inodep.file_size;
607 + i->i_op = &squashfs_dir_inode_ops;
608 + i->i_fop = &squashfs_dir_ops;
609 + i->i_mode |= S_IFDIR;
610 + i->i_mtime.tv_sec = inodep.mtime;
611 + i->i_atime.tv_sec = inodep.mtime;
612 + i->i_ctime.tv_sec = inodep.mtime;
613 + SQUASHFS_I(i)->start_block = inodep.start_block;
614 + SQUASHFS_I(i)->offset = inodep.offset;
615 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
616 + inodep.start_block, inodep.offset);
619 + case SQUASHFS_SYMLINK_TYPE: {
620 + squashfs_symlink_inode_header_1 inodep;
623 + squashfs_symlink_inode_header_1 sinodep;
625 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
626 + &next_block, &next_offset))
628 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
630 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
631 + &next_block, &next_offset))
634 + i->i_size = inodep.symlink_size;
635 + i->i_op = &page_symlink_inode_operations;
636 + i->i_data.a_ops = &squashfs_symlink_aops;
637 + i->i_mode |= S_IFLNK;
638 + SQUASHFS_I(i)->start_block = next_block;
639 + SQUASHFS_I(i)->offset = next_offset;
640 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
641 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
644 + case SQUASHFS_BLKDEV_TYPE:
645 + case SQUASHFS_CHRDEV_TYPE: {
646 + squashfs_dev_inode_header_1 inodep;
649 + squashfs_dev_inode_header_1 sinodep;
651 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
652 + &next_block, &next_offset))
654 + SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
656 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
657 + &next_block, &next_offset))
661 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
662 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
663 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
666 + case SQUASHFS_IPC_TYPE: {
667 + squashfs_ipc_inode_header_1 inodep;
670 + squashfs_ipc_inode_header_1 sinodep;
672 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
673 + &next_block, &next_offset))
675 + SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
677 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
678 + &next_block, &next_offset))
682 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
683 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
684 + init_special_inode(i, i->i_mode, 0);
688 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
692 + if(inodeb.guid == 15)
693 + i->i_gid = i->i_uid;
695 + i->i_gid = msBlk->guid[inodeb.guid];
700 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
708 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
710 + struct inode *i = new_inode(s);
711 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
712 + squashfs_super_block *sBlk = &msBlk->sBlk;
713 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
714 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
715 + unsigned int next_block, next_offset;
716 + squashfs_base_inode_header inodeb;
718 + TRACE("Entered squashfs_iget\n");
721 + squashfs_base_inode_header sinodeb;
723 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
724 + sizeof(sinodeb), &next_block, &next_offset))
726 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
728 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
729 + sizeof(inodeb), &next_block, &next_offset))
734 + i->i_mtime.tv_sec = sBlk->mkfs_time;
735 + i->i_atime.tv_sec = sBlk->mkfs_time;
736 + i->i_ctime.tv_sec = sBlk->mkfs_time;
738 + i->i_uid = msBlk->uid[inodeb.uid];
739 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
741 + i->i_mode = inodeb.mode;
743 + switch(inodeb.inode_type) {
744 + case SQUASHFS_FILE_TYPE: {
745 + squashfs_reg_inode_header inodep;
748 + squashfs_reg_inode_header sinodep;
750 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
751 + &next_block, &next_offset))
753 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
755 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
756 + &next_block, &next_offset))
759 + SQUASHFS_I(i)->fragment_start_block = SQUASHFS_INVALID_BLK;
760 + if(inodep.fragment != SQUASHFS_INVALID_BLK && !get_fragment_location(s, inodep.fragment,
761 + &SQUASHFS_I(i)->fragment_start_block, &SQUASHFS_I(i)->fragment_size))
764 + SQUASHFS_I(i)->fragment_offset = inodep.offset;
765 + i->i_size = inodep.file_size;
766 + i->i_fop = &generic_ro_fops;
767 + if(sBlk->block_size > 4096)
768 + i->i_data.a_ops = &squashfs_aops;
770 + i->i_data.a_ops = &squashfs_aops_4K;
771 + i->i_mode |= S_IFREG;
772 + i->i_mtime.tv_sec = inodep.mtime;
773 + i->i_atime.tv_sec = inodep.mtime;
774 + i->i_ctime.tv_sec = inodep.mtime;
775 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
776 + i->i_blksize = PAGE_CACHE_SIZE;
777 + SQUASHFS_I(i)->start_block = inodep.start_block;
778 + SQUASHFS_I(i)->block_list_start = next_block;
779 + SQUASHFS_I(i)->offset = next_offset;
780 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
781 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
784 + case SQUASHFS_DIR_TYPE: {
785 + squashfs_dir_inode_header inodep;
788 + squashfs_dir_inode_header sinodep;
790 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
791 + &next_block, &next_offset))
793 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
795 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
796 + &next_block, &next_offset))
799 + i->i_size = inodep.file_size;
800 + i->i_op = &squashfs_dir_inode_ops;
801 + i->i_fop = &squashfs_dir_ops;
802 + i->i_mode |= S_IFDIR;
803 + i->i_mtime.tv_sec = inodep.mtime;
804 + i->i_atime.tv_sec = inodep.mtime;
805 + i->i_ctime.tv_sec = inodep.mtime;
806 + SQUASHFS_I(i)->start_block = inodep.start_block;
807 + SQUASHFS_I(i)->offset = inodep.offset;
808 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
809 + inodep.start_block, inodep.offset);
812 + case SQUASHFS_SYMLINK_TYPE: {
813 + squashfs_symlink_inode_header inodep;
816 + squashfs_symlink_inode_header sinodep;
818 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
819 + &next_block, &next_offset))
821 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
823 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
824 + &next_block, &next_offset))
827 + i->i_size = inodep.symlink_size;
828 + i->i_op = &page_symlink_inode_operations;
829 + i->i_data.a_ops = &squashfs_symlink_aops;
830 + i->i_mode |= S_IFLNK;
831 + SQUASHFS_I(i)->start_block = next_block;
832 + SQUASHFS_I(i)->offset = next_offset;
833 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
834 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
837 + case SQUASHFS_BLKDEV_TYPE:
838 + case SQUASHFS_CHRDEV_TYPE: {
839 + squashfs_dev_inode_header inodep;
842 + squashfs_dev_inode_header sinodep;
844 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
845 + &next_block, &next_offset))
847 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
849 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
850 + &next_block, &next_offset))
854 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
855 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
856 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
859 + case SQUASHFS_FIFO_TYPE:
860 + case SQUASHFS_SOCKET_TYPE: {
862 + i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
863 + init_special_inode(i, i->i_mode, 0);
867 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
871 + if(inodeb.guid == SQUASHFS_GUIDS)
872 + i->i_gid = i->i_uid;
874 + i->i_gid = msBlk->guid[inodeb.guid];
879 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
886 +static int squashfs_fill_super(struct super_block *s,
887 + void *data, int silent)
889 + squashfs_sb_info *msBlk;
890 + squashfs_super_block *sBlk;
892 + char b[BDEVNAME_SIZE];
894 + TRACE("Entered squashfs_read_superblock\n");
896 + if(!(msBlk = (squashfs_sb_info *) s->s_fs_info = (void *) kmalloc(sizeof(squashfs_sb_info), GFP_KERNEL))) {
897 + ERROR("Failed to allocate superblock\n");
900 + sBlk = &msBlk->sBlk;
902 + msBlk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
903 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
905 + init_MUTEX(&msBlk->read_page_mutex);
906 + init_MUTEX(&msBlk->block_cache_mutex);
907 + init_MUTEX(&msBlk->fragment_mutex);
909 + init_waitqueue_head(&msBlk->waitq);
910 + init_waitqueue_head(&msBlk->fragment_wait_queue);
912 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
913 + SERROR("unable to read superblock\n");
917 + /* Check it is a SQUASHFS superblock */
919 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
920 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
921 + squashfs_super_block sblk;
922 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(s->s_bdev, b));
923 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
924 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
927 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(s->s_bdev, b));
932 + /* Check the MAJOR & MINOR versions */
933 +#ifdef SQUASHFS_1_0_COMPATIBILITY
934 + if((sBlk->s_major != 1) && (sBlk->s_major != 2 || sBlk->s_minor > SQUASHFS_MINOR)) {
935 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (1 : x) or (2 : <= %d)\n",
936 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MINOR);
939 + if(sBlk->s_major == 1)
940 + sBlk->block_size = sBlk->block_size_1;
942 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
943 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
944 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
949 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
950 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
951 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
952 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
953 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
954 + TRACE("Block size %d\n", sBlk->block_size);
955 + TRACE("Number of inodes %d\n", sBlk->inodes);
956 + if(sBlk->s_major > 1)
957 + TRACE("Number of fragments %d\n", sBlk->fragments);
958 + TRACE("Number of uids %d\n", sBlk->no_uids);
959 + TRACE("Number of gids %d\n", sBlk->no_guids);
960 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
961 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
962 + if(sBlk->s_major > 1)
963 + TRACE("sBlk->fragment_table_start %x\n", sBlk->fragment_table_start);
964 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
966 + s->s_flags |= MS_RDONLY;
967 + s->s_op = &squashfs_ops;
969 + /* Init inode_table block pointer array */
970 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
971 + ERROR("Failed to allocate block cache\n");
975 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
976 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
978 + msBlk->next_cache = 0;
980 + /* Allocate read_data block */
981 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
982 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
983 + ERROR("Failed to allocate read_data block\n");
984 + goto failed_mount1;
987 + /* Allocate read_page block */
988 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
989 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
990 + ERROR("Failed to allocate read_page block\n");
991 + goto failed_mount2;
994 + /* Allocate uid and gid tables */
995 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
996 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
997 + ERROR("Failed to allocate uid/gid table\n");
998 + goto failed_mount3;
1000 + msBlk->guid = msBlk->uid + sBlk->no_uids;
1003 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1005 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1006 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1007 + SERROR("unable to read uid/gid table\n");
1008 + goto failed_mount4;
1010 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1012 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1013 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1014 + SERROR("unable to read uid/gid table\n");
1015 + goto failed_mount4;
1019 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1020 + if(sBlk->s_major == 1) {
1021 + msBlk->iget = squashfs_iget_1;
1022 + msBlk->read_blocklist = read_blocklist_1;
1023 + msBlk->fragment = (struct squashfs_fragment_cache *) msBlk->fragment_index = NULL;
1024 + goto allocate_root;
1027 + msBlk->iget = squashfs_iget;
1028 + msBlk->read_blocklist = read_blocklist;
1030 + if(!(msBlk->fragment = (struct squashfs_fragment_cache *) kmalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1031 + ERROR("Failed to allocate fragment block cache\n");
1032 + goto failed_mount4;
1035 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1036 + msBlk->fragment[i].locked = 0;
1037 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
1038 + msBlk->fragment[i].data = NULL;
1041 + msBlk->next_fragment = 0;
1043 + /* Allocate fragment index table */
1044 + if(!(msBlk->fragment_index = (squashfs_fragment_index *) kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), GFP_KERNEL))) {
1045 + ERROR("Failed to allocate uid/gid table\n");
1046 + goto failed_mount5;
1049 + if(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) &&
1050 + !read_data(s, (char *) msBlk->fragment_index, sBlk->fragment_table_start,
1051 + SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1052 + SERROR("unable to read fragment index table\n");
1053 + goto failed_mount6;
1058 + squashfs_fragment_index fragment;
1060 + for(i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments); i++) {
1061 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment), &msBlk->fragment_index[i], 1);
1062 + msBlk->fragment_index[i] = fragment;
1066 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1069 + if(!(s->s_root = d_alloc_root((msBlk->iget)(s, sBlk->root_inode)))) {
1070 + ERROR("Root inode create failed\n");
1071 + goto failed_mount5;
1074 + TRACE("Leaving squashfs_read_super\n");
1078 + kfree(msBlk->fragment_index);
1080 + kfree(msBlk->fragment);
1082 + kfree(msBlk->uid);
1084 + kfree(msBlk->read_page);
1086 + kfree(msBlk->read_data);
1088 + kfree(msBlk->block_cache);
1090 + kfree(s->s_fs_info);
1091 + s->s_fs_info = NULL;
1096 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1098 + squashfs_super_block *sBlk = &((squashfs_sb_info *)s->s_fs_info)->sBlk;
1100 + TRACE("Entered squashfs_statfs\n");
1101 + buf->f_type = SQUASHFS_MAGIC;
1102 + buf->f_bsize = sBlk->block_size;
1103 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
1104 + buf->f_bfree = buf->f_bavail = 0;
1105 + buf->f_files = sBlk->inodes;
1107 + buf->f_namelen = SQUASHFS_NAME_LEN;
1112 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1114 + struct inode *inode = page->mapping->host;
1115 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1116 + int block = SQUASHFS_I(inode)->start_block;
1117 + int offset = SQUASHFS_I(inode)->offset;
1118 + void *pageaddr = kmap(page);
1120 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
1121 + page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(inode)->offset);
1123 + for(length = 0; length < index; length += bytes) {
1124 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
1125 + PAGE_CACHE_SIZE, &block, &offset))) {
1126 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1131 + if(length != index) {
1132 + ERROR("(squashfs_symlink_readpage) length != index\n");
1137 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
1138 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
1139 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1142 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1144 + flush_dcache_page(page);
1145 + SetPageUptodate(page);
1146 + unlock_page(page);
1154 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1155 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
1156 + char *block_list, char **block_p, unsigned int *bsize)
1158 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1159 + unsigned short *block_listp;
1161 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1162 + int offset = SQUASHFS_I(inode)->offset;
1163 + int block = SQUASHFS_I(inode)->start_block;
1166 + int blocks = (index + readahead_blks - i);
1167 + if(blocks > (SIZE >> 1)) {
1168 + if((index - i) <= (SIZE >> 1))
1169 + blocks = index - i;
1171 + blocks = SIZE >> 1;
1175 + unsigned char sblock_list[SIZE];
1176 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1177 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1180 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1182 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1183 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1186 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1187 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1188 + if(blocks >= readahead_blks)
1193 + *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1195 + (unsigned short *) *block_p = block_listp;
1201 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1202 + char *block_list, char **block_p, unsigned int *bsize)
1204 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1205 + unsigned int *block_listp;
1207 + int block_ptr = SQUASHFS_I(inode)->block_list_start;
1208 + int offset = SQUASHFS_I(inode)->offset;
1209 + int block = SQUASHFS_I(inode)->start_block;
1212 + int blocks = (index + readahead_blks - i);
1213 + if(blocks > (SIZE >> 2)) {
1214 + if((index - i) <= (SIZE >> 2))
1215 + blocks = index - i;
1217 + blocks = SIZE >> 2;
1221 + unsigned char sblock_list[SIZE];
1222 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1223 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1226 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1228 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1229 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1232 + for(block_listp = (unsigned int *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1233 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1234 + if(blocks >= readahead_blks)
1238 + *bsize = *block_listp;
1243 +static int squashfs_readpage(struct file *file, struct page *page)
1245 + struct inode *inode = page->mapping->host;
1246 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1247 + squashfs_super_block *sBlk = &msBlk->sBlk;
1248 + unsigned char block_list[SIZE];
1249 + unsigned int bsize, block, i = 0, bytes = 0, byte_offset = 0;
1250 + int index = page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT);
1251 + void *pageaddr = kmap(page);
1252 + struct squashfs_fragment_cache *fragment;
1253 + char *data_ptr = msBlk->read_page;
1255 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1256 + int start_index = page->index & ~mask;
1257 + int end_index = start_index | mask;
1259 + TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1260 + SQUASHFS_I(inode)->start_block);
1262 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT))
1265 + if(SQUASHFS_I(inode)->fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log)) {
1266 + if((block = (msBlk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize)) == 0)
1269 + down(&msBlk->read_page_mutex);
1270 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, bsize, 1, NULL))) {
1271 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1272 + up(&msBlk->read_page_mutex);
1276 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->fragment_start_block, SQUASHFS_I(inode)->fragment_size)) == NULL) {
1277 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->fragment_start_block, (int) SQUASHFS_I(inode)->fragment_size);
1280 + bytes = SQUASHFS_I(inode)->fragment_offset + (inode->i_size & (sBlk->block_size - 1));
1281 + byte_offset = SQUASHFS_I(inode)->fragment_offset;
1282 + data_ptr = fragment->data;
1285 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1286 + struct page *push_page;
1287 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1289 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1291 + if(i == page->index) {
1292 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1293 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1295 + flush_dcache_page(page);
1296 + SetPageUptodate(page);
1297 + unlock_page(page);
1298 + } else if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1299 + void *pageaddr = kmap(push_page);
1300 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1301 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1302 + kunmap(push_page);
1303 + flush_dcache_page(push_page);
1304 + SetPageUptodate(push_page);
1305 + unlock_page(push_page);
1306 + page_cache_release(push_page);
1310 + if(SQUASHFS_I(inode)->fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log))
1311 + up(&msBlk->read_page_mutex);
1313 + release_cached_fragment(msBlk, fragment);
1318 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1320 + flush_dcache_page(page);
1321 + SetPageUptodate(page);
1322 + unlock_page(page);
1328 +static int squashfs_readpage4K(struct file *file, struct page *page)
1330 + struct inode *inode = page->mapping->host;
1331 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1332 + squashfs_super_block *sBlk = &msBlk->sBlk;
1333 + unsigned char block_list[SIZE];
1334 + unsigned int bsize, block, bytes = 0;
1335 + void *pageaddr = kmap(page);
1337 + TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1338 + SQUASHFS_I(inode)->start_block);
1340 + if(page->index >= ((inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT))
1343 + if(page->index < (inode->i_size >> sBlk->block_log)) {
1344 + block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1346 + if(!(bytes = read_data(inode->i_sb, pageaddr, block, bsize, 1, NULL)))
1347 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1349 + struct squashfs_fragment_cache *fragment;
1351 + if((fragment = get_cached_fragment(inode->i_sb, SQUASHFS_I(inode)->fragment_start_block, SQUASHFS_I(inode)->fragment_size)) == NULL)
1352 + ERROR("Unable to read page, block %x, size %x\n", SQUASHFS_I(inode)->fragment_start_block, (int) SQUASHFS_I(inode)->fragment_size);
1354 + bytes = inode->i_size & (sBlk->block_size - 1);
1355 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->fragment_offset, bytes);
1356 + release_cached_fragment(msBlk, fragment);
1361 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1363 + flush_dcache_page(page);
1364 + SetPageUptodate(page);
1365 + unlock_page(page);
1371 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1372 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1374 + struct inode *inode = page->mapping->host;
1375 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
1376 + squashfs_super_block *sBlk = &msBlk->sBlk;
1377 + unsigned char block_list[SIZE];
1378 + unsigned short *block_listp, block, bytes = 0;
1379 + int index = page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
1380 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
1381 + int readahead_blks = 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
1382 + void *pageaddr = kmap(page);
1384 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1387 + TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1388 + SQUASHFS_I(inode)->start_block);
1390 + block = read_blocklist_1(inode, index, readahead_blks, block_list, (char **) &block_listp, NULL);
1392 + if(i_end > file_blocks)
1393 + i_end = file_blocks;
1395 + while(index < i_end) {
1396 + if(!(byte = read_data(inode->i_sb, pageaddr, block, *block_listp, 0, NULL))) {
1397 + ERROR("Unable to read page, block %x, size %x\n", block, *block_listp);
1400 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1408 + memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1410 + flush_dcache_page(page);
1411 + SetPageUptodate(page);
1412 + unlock_page(page);
1419 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1421 + struct inode *i = file->f_dentry->d_inode;
1422 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1423 + squashfs_super_block *sBlk = &msBlk->sBlk;
1424 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1425 + SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
1426 + squashfs_dir_header dirh;
1427 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1428 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1430 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1433 + while(length < i->i_size) {
1434 + /* read directory header */
1436 + squashfs_dir_header sdirh;
1437 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1438 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1440 + length += sizeof(sdirh);
1441 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1443 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1444 + next_offset, sizeof(dirh), &next_block, &next_offset))
1446 + length += sizeof(dirh);
1449 + dir_count = dirh.count + 1;
1450 + while(dir_count--) {
1452 + squashfs_dir_entry sdire;
1453 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1454 + next_offset, sizeof(sdire), &next_block, &next_offset))
1456 + length += sizeof(sdire);
1457 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1459 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1460 + next_offset, sizeof(*dire), &next_block, &next_offset))
1462 + length += sizeof(*dire);
1465 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1466 + next_offset, dire->size + 1, &next_block, &next_offset))
1468 + length += dire->size + 1;
1470 + if(file->f_pos >= length)
1473 + dire->name[dire->size + 1] = '\0';
1475 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", (unsigned int) dirent,
1476 + dire->name, dire->size + 1, (int) file->f_pos,
1477 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1479 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1480 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1481 + TRACE("Filldir returned less than 0\n");
1486 + file->f_pos = length;
1496 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1501 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
1503 + const char *name =dentry->d_name.name;
1504 + int len = dentry->d_name.len;
1505 + struct inode *inode = NULL;
1506 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
1507 + squashfs_super_block *sBlk = &msBlk->sBlk;
1508 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
1509 + SQUASHFS_I(i)->offset, length = 0, dir_count;
1510 + squashfs_dir_header dirh;
1511 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1512 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1514 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1517 + while(length < i->i_size) {
1518 + /* read directory header */
1520 + squashfs_dir_header sdirh;
1521 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1522 + sizeof(sdirh), &next_block, &next_offset))
1524 + length += sizeof(sdirh);
1525 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1527 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1528 + sizeof(dirh), &next_block, &next_offset))
1530 + length += sizeof(dirh);
1533 + dir_count = dirh.count + 1;
1534 + while(dir_count--) {
1536 + squashfs_dir_entry sdire;
1537 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1538 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1540 + length += sizeof(sdire);
1541 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1543 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1544 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1546 + length += sizeof(*dire);
1549 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1550 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1552 + length += dire->size + 1;
1554 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1555 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1557 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1558 + name, dirh.start_block, dire->offset);
1560 + inode = (msBlk->iget)(i->i_sb, ino);
1568 + d_add(dentry, inode);
1570 + return ERR_PTR(0);
1573 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1578 +static void squashfs_put_super(struct super_block *s)
1580 + if(s->s_fs_info) {
1581 + squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1582 + if(sbi->block_cache) kfree(sbi->block_cache);
1583 + if(sbi->read_data) kfree(sbi->read_data);
1584 + if(sbi->read_page) kfree(sbi->read_page);
1585 + if(sbi->uid) kfree(sbi->uid);
1586 + if(sbi->fragment) kfree(sbi->fragment);
1587 + if(sbi->fragment_index) kfree(sbi->fragment_index);
1588 + kfree(s->s_fs_info);
1589 + s->s_fs_info = NULL;
1594 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1596 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1600 +static int __init init_squashfs_fs(void)
1602 + int err = init_inodecache();
1606 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1607 + ERROR("Failed to allocate zlib workspace\n");
1608 + destroy_inodecache();
1612 + if((err = register_filesystem(&squashfs_fs_type))) {
1613 + vfree(stream.workspace);
1614 + destroy_inodecache();
1621 +static void __exit exit_squashfs_fs(void)
1623 + vfree(stream.workspace);
1624 + unregister_filesystem(&squashfs_fs_type);
1625 + destroy_inodecache();
1629 +static kmem_cache_t * squashfs_inode_cachep;
1632 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1634 + struct squashfs_inode_info *ei;
1635 + ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1638 + return &ei->vfs_inode;
1642 +static void squashfs_destroy_inode(struct inode *inode)
1644 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1648 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1650 + struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1652 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1653 + SLAB_CTOR_CONSTRUCTOR)
1654 + inode_init_once(&ei->vfs_inode);
1658 +static int init_inodecache(void)
1660 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1661 + sizeof(struct squashfs_inode_info),
1662 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1664 + if (squashfs_inode_cachep == NULL)
1670 +static void destroy_inodecache(void)
1672 + if (kmem_cache_destroy(squashfs_inode_cachep))
1673 + printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1677 +module_init(init_squashfs_fs);
1678 +module_exit(exit_squashfs_fs);
1679 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1680 +MODULE_AUTHOR("Phillip Lougher <plougher@users.sourceforge.net>");
1681 +MODULE_LICENSE("GPL");
1682 diff --new-file -ur linux-2.6.8.1/fs/squashfs/Makefile linux-2.6.8.1-squashfs2.0/fs/squashfs/Makefile
1683 --- linux-2.6.8.1/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
1684 +++ linux-2.6.8.1-squashfs2.0/fs/squashfs/Makefile 2004-08-30 13:36:25.000000000 +0100
1687 +# Makefile for the linux squashfs routines.
1690 +obj-$(CONFIG_SQUASHFS) += squashfs.o
1692 +squashfs-objs := inode.o
1693 diff --new-file -ur linux-2.6.8.1/include/linux/squashfs_fs.h linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs.h
1694 --- linux-2.6.8.1/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
1695 +++ linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs.h 2004-08-30 13:36:25.000000000 +0100
1697 +#ifndef SQUASHFS_FS
1698 +#define SQUASHFS_FS
1702 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
1704 + * This program is free software; you can redistribute it and/or
1705 + * modify it under the terms of the GNU General Public License
1706 + * as published by the Free Software Foundation; either version 2,
1707 + * or (at your option) any later version.
1709 + * This program is distributed in the hope that it will be useful,
1710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1712 + * GNU General Public License for more details.
1714 + * You should have received a copy of the GNU General Public License
1715 + * along with this program; if not, write to the Free Software
1716 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1721 +#define SQUASHFS_MAJOR 2
1722 +#define SQUASHFS_MINOR 0
1723 +#define SQUASHFS_MAGIC 0x73717368
1724 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1725 +#define SQUASHFS_START 0
1727 +/* size of metadata (inode and directory) blocks */
1728 +#define SQUASHFS_METADATA_SIZE 8192
1729 +#define SQUASHFS_METADATA_LOG 13
1731 +/* default size of data blocks */
1732 +#define SQUASHFS_FILE_SIZE 65536
1733 +#define SQUASHFS_FILE_LOG 16
1735 +#define SQUASHFS_FILE_MAX_SIZE 65536
1737 +/* Max number of uids and gids */
1738 +#define SQUASHFS_UIDS 256
1739 +#define SQUASHFS_GUIDS 255
1741 +/* Max length of filename (not 255) */
1742 +#define SQUASHFS_NAME_LEN 256
1744 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1745 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1746 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1748 +/* Filesystem flags */
1749 +#define SQUASHFS_NOI 0
1750 +#define SQUASHFS_NOD 1
1751 +#define SQUASHFS_CHECK 2
1752 +#define SQUASHFS_NOF 3
1753 +#define SQUASHFS_NO_FRAG 4
1754 +#define SQUASHFS_ALWAYS_FRAG 5
1755 +#define SQUASHFS_DUPLICATE 6
1756 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
1757 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
1758 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
1759 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1760 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1761 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1762 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1763 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1764 +#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))
1766 +/* Max number of types and file types */
1767 +#define SQUASHFS_DIR_TYPE 1
1768 +#define SQUASHFS_FILE_TYPE 2
1769 +#define SQUASHFS_SYMLINK_TYPE 3
1770 +#define SQUASHFS_BLKDEV_TYPE 4
1771 +#define SQUASHFS_CHRDEV_TYPE 5
1772 +#define SQUASHFS_FIFO_TYPE 6
1773 +#define SQUASHFS_SOCKET_TYPE 7
1775 +/* 1.0 filesystem type definitions */
1776 +#define SQUASHFS_TYPES 5
1777 +#define SQUASHFS_IPC_TYPE 0
1779 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1780 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1781 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1782 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1784 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1786 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
1787 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
1788 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
1790 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
1793 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1794 + * offset within that block
1796 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1797 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1798 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1801 +/* Compute 32 bit VFS inode number from squashfs inode number */
1802 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1804 +/* Translate between VFS mode and squashfs mode */
1805 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1807 +/* fragment and fragment table defines */
1808 +typedef unsigned int squashfs_fragment_index;
1809 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
1810 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
1811 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
1812 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
1813 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
1814 +#define SQUASHFS_CACHED_FRAGMENTS 3
1816 +/* cached data constants for filesystem */
1817 +#define SQUASHFS_CACHED_BLKS 8
1819 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1820 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1822 +#define SQUASHFS_MARKER_BYTE 0xff
1825 + * definitions for structures on disk
1828 +typedef unsigned int squashfs_block;
1829 +typedef long long squashfs_inode;
1831 +typedef unsigned int squashfs_uid;
1833 +typedef struct squashfs_super_block {
1834 + unsigned int s_magic;
1835 + unsigned int inodes;
1836 + unsigned int bytes_used;
1837 + unsigned int uid_start;
1838 + unsigned int guid_start;
1839 + unsigned int inode_table_start;
1840 + unsigned int directory_table_start;
1841 + unsigned int s_major:16;
1842 + unsigned int s_minor:16;
1843 + unsigned int block_size_1:16;
1844 + unsigned int block_log:16;
1845 + unsigned int flags:8;
1846 + unsigned int no_uids:8;
1847 + unsigned int no_guids:8;
1848 + unsigned int mkfs_time /* time of filesystem creation */;
1849 + squashfs_inode root_inode;
1850 + unsigned int block_size;
1851 + unsigned int fragments;
1852 + unsigned int fragment_table_start;
1853 +} __attribute__ ((packed)) squashfs_super_block;
1856 + unsigned int inode_type:4;
1857 + unsigned int mode:12; /* protection */
1858 + unsigned int uid:8; /* index into uid table */
1859 + unsigned int guid:8; /* index into guid table */
1860 +} __attribute__ ((packed)) squashfs_base_inode_header;
1862 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
1865 + unsigned int inode_type:4;
1866 + unsigned int mode:12; /* protection */
1867 + unsigned int uid:8; /* index into uid table */
1868 + unsigned int guid:8; /* index into guid table */
1869 + unsigned short rdev;
1870 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1873 + unsigned int inode_type:4;
1874 + unsigned int mode:12; /* protection */
1875 + unsigned int uid:8; /* index into uid table */
1876 + unsigned int guid:8; /* index into guid table */
1877 + unsigned short symlink_size;
1879 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1882 + unsigned int inode_type:4;
1883 + unsigned int mode:12; /* protection */
1884 + unsigned int uid:8; /* index into uid table */
1885 + unsigned int guid:8; /* index into guid table */
1886 + unsigned int mtime;
1887 + squashfs_block start_block;
1888 + unsigned int fragment;
1889 + unsigned int offset;
1890 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1891 + unsigned short block_list[0];
1892 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1895 + unsigned int inode_type:4;
1896 + unsigned int mode:12; /* protection */
1897 + unsigned int uid:8; /* index into uid table */
1898 + unsigned int guid:8; /* index into guid table */
1899 + unsigned int file_size:19;
1900 + unsigned int offset:13;
1901 + unsigned int mtime;
1902 + unsigned int start_block:24;
1903 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1906 + squashfs_base_inode_header base;
1907 + squashfs_dev_inode_header dev;
1908 + squashfs_symlink_inode_header symlink;
1909 + squashfs_reg_inode_header reg;
1910 + squashfs_dir_inode_header dir;
1911 + squashfs_ipc_inode_header ipc;
1912 +} squashfs_inode_header;
1915 + unsigned int offset:13;
1916 + unsigned int type:3;
1917 + unsigned int size:8;
1919 +} __attribute__ ((packed)) squashfs_dir_entry;
1922 + unsigned int count:8;
1923 + unsigned int start_block:24;
1924 +} __attribute__ ((packed)) squashfs_dir_header;
1928 + unsigned int start_block;
1929 + unsigned int size;
1930 +} __attribute__ ((packed)) squashfs_fragment_entry;
1932 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1933 +extern int squashfs_uncompress_init(void);
1934 +extern int squashfs_uncompress_exit(void);
1937 + * macros to convert each packed bitfield structure from little endian to big
1938 + * endian and vice versa. These are needed when creating or using a filesystem on a
1939 + * machine with different byte ordering to the target architecture.
1943 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1944 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1945 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1946 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1947 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1948 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1949 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1950 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1951 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1952 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1953 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1954 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
1955 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1956 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1957 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1958 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1959 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1960 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1961 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
1962 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
1963 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
1966 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1967 + SQUASHFS_MEMSET(s, d, n);\
1968 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1969 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1970 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
1971 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
1974 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
1976 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1977 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1978 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
1981 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1982 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1983 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
1986 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1987 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1988 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
1989 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
1990 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
1991 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
1992 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
1995 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1996 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1997 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
1998 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
1999 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2000 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2003 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2004 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2005 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
2006 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2009 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2010 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2011 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2012 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
2013 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
2016 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2017 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2018 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2019 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
2022 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2024 + int bit_position;\
2025 + SQUASHFS_MEMSET(s, d, n * 2);\
2026 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2027 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2030 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2032 + int bit_position;\
2033 + SQUASHFS_MEMSET(s, d, n * 4);\
2034 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2035 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2038 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2040 + int bit_position;\
2041 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
2042 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2043 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2046 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2048 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2050 + unsigned int inode_type:4;
2051 + unsigned int mode:12; /* protection */
2052 + unsigned int uid:4; /* index into uid table */
2053 + unsigned int guid:4; /* index into guid table */
2054 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2057 + unsigned int inode_type:4;
2058 + unsigned int mode:12; /* protection */
2059 + unsigned int uid:4; /* index into uid table */
2060 + unsigned int guid:4; /* index into guid table */
2061 + unsigned int type:4;
2062 + unsigned int offset:4;
2063 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2066 + unsigned int inode_type:4;
2067 + unsigned int mode:12; /* protection */
2068 + unsigned int uid:4; /* index into uid table */
2069 + unsigned int guid:4; /* index into guid table */
2070 + unsigned short rdev;
2071 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2074 + unsigned int inode_type:4;
2075 + unsigned int mode:12; /* protection */
2076 + unsigned int uid:4; /* index into uid table */
2077 + unsigned int guid:4; /* index into guid table */
2078 + unsigned short symlink_size;
2080 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2083 + unsigned int inode_type:4;
2084 + unsigned int mode:12; /* protection */
2085 + unsigned int uid:4; /* index into uid table */
2086 + unsigned int guid:4; /* index into guid table */
2087 + unsigned int mtime;
2088 + squashfs_block start_block;
2089 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2090 + unsigned short block_list[0];
2091 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2094 + unsigned int inode_type:4;
2095 + unsigned int mode:12; /* protection */
2096 + unsigned int uid:4; /* index into uid table */
2097 + unsigned int guid:4; /* index into guid table */
2098 + unsigned int file_size:19;
2099 + unsigned int offset:13;
2100 + unsigned int mtime;
2101 + unsigned int start_block:24;
2102 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
2104 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2105 + SQUASHFS_MEMSET(s, d, n);\
2106 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2107 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2108 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2109 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2112 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2113 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2114 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
2115 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2118 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2119 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2120 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2123 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2124 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2125 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2128 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2129 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2130 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2131 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2132 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2135 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2136 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2137 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2138 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2139 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2140 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2146 + * macros used to swap each structure entry, taking into account
2147 + * bitfields and different bitfield placing conventions on differing architectures
2149 +#include <asm/byteorder.h>
2150 +#ifdef __BIG_ENDIAN
2151 + /* convert from little endian to big endian */
2152 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2154 + /* convert from big endian to little endian */
2155 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2158 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2160 + int b_pos = pos % 8;\
2161 + unsigned long long val = 0;\
2162 + unsigned char *s = (unsigned char *)p + (pos / 8);\
2163 + unsigned char *d = ((unsigned char *) &val) + 7;\
2164 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2166 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2168 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
2171 diff --new-file -ur linux-2.6.8.1/include/linux/squashfs_fs_i.h linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs_i.h
2172 --- linux-2.6.8.1/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
2173 +++ linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs_i.h 2004-08-30 13:36:25.000000000 +0100
2175 +#ifndef SQUASHFS_FS_I
2176 +#define SQUASHFS_FS_I
2180 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2182 + * This program is free software; you can redistribute it and/or
2183 + * modify it under the terms of the GNU General Public License
2184 + * as published by the Free Software Foundation; either version 2,
2185 + * or (at your option) any later version.
2187 + * This program is distributed in the hope that it will be useful,
2188 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2189 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2190 + * GNU General Public License for more details.
2192 + * You should have received a copy of the GNU General Public License
2193 + * along with this program; if not, write to the Free Software
2194 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2199 +typedef struct squashfs_inode_info {
2200 + unsigned int start_block;
2201 + unsigned int block_list_start;
2202 + unsigned int offset;
2203 + unsigned int fragment_start_block;
2204 + unsigned int fragment_size;
2205 + unsigned int fragment_offset;
2206 + struct inode vfs_inode;
2207 + } squashfs_inode_info;
2209 diff --new-file -ur linux-2.6.8.1/include/linux/squashfs_fs_sb.h linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs_sb.h
2210 --- linux-2.6.8.1/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
2211 +++ linux-2.6.8.1-squashfs2.0/include/linux/squashfs_fs_sb.h 2004-08-30 13:36:25.000000000 +0100
2213 +#ifndef SQUASHFS_FS_SB
2214 +#define SQUASHFS_FS_SB
2218 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2220 + * This program is free software; you can redistribute it and/or
2221 + * modify it under the terms of the GNU General Public License
2222 + * as published by the Free Software Foundation; either version 2,
2223 + * or (at your option) any later version.
2225 + * This program is distributed in the hope that it will be useful,
2226 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2227 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2228 + * GNU General Public License for more details.
2230 + * You should have received a copy of the GNU General Public License
2231 + * along with this program; if not, write to the Free Software
2232 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2234 + * squashfs_fs_sb.h
2237 +#include <linux/squashfs_fs.h>
2240 + unsigned int block;
2242 + unsigned int next_index;
2246 +struct squashfs_fragment_cache {
2247 + unsigned int block;
2249 + unsigned int locked;
2253 +typedef struct squashfs_sb_info {
2254 + squashfs_super_block sBlk;
2256 + int devblksize_log2;
2258 + squashfs_cache *block_cache;
2259 + struct squashfs_fragment_cache *fragment;
2261 + int next_fragment;
2262 + squashfs_uid *uid;
2263 + squashfs_uid *guid;
2264 + squashfs_fragment_index *fragment_index;
2265 + unsigned int read_size;
2268 + struct semaphore read_page_mutex;
2269 + struct semaphore block_cache_mutex;
2270 + struct semaphore fragment_mutex;
2271 + wait_queue_head_t waitq;
2272 + wait_queue_head_t fragment_wait_queue;
2273 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
2274 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2275 + char *block_list, char **block_p, unsigned int *bsize);
2276 + } squashfs_sb_info;
2278 diff --new-file -ur linux-2.6.8.1/init/do_mounts_rd.c linux-2.6.8.1-squashfs2.0/init/do_mounts_rd.c
2279 --- linux-2.6.8.1/init/do_mounts_rd.c 2004-08-14 11:55:48.000000000 +0100
2280 +++ linux-2.6.8.1-squashfs2.0/init/do_mounts_rd.c 2004-08-30 13:36:25.000000000 +0100
2282 #include <linux/ext2_fs.h>
2283 #include <linux/romfs_fs.h>
2284 #include <linux/cramfs_fs.h>
2285 +#include <linux/squashfs_fs.h>
2286 #include <linux/initrd.h>
2287 #include <linux/string.h>
2290 * numbers could not be found.
2292 * We currently check for the following magic numbers:
2298 struct ext2_super_block *ext2sb;
2299 struct romfs_super_block *romfsb;
2300 struct cramfs_super *cramfsb;
2301 + struct squashfs_super_block *squashfsb;
2306 ext2sb = (struct ext2_super_block *) buf;
2307 romfsb = (struct romfs_super_block *) buf;
2308 cramfsb = (struct cramfs_super *) buf;
2309 + squashfsb = (struct squashfs_super_block *) buf;
2310 memset(buf, 0xe5, size);
2313 @@ -101,6 +105,15 @@
2317 + /* squashfs is at block zero too */
2318 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2319 + printk(KERN_NOTICE
2320 + "RAMDISK: squashfs filesystem found at block %d\n",
2322 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2327 * Read block 1 to test for minix and ext2 superblock