1 diff -Nurb src/linux/linux.orig/Makefile src/linux/linux/Makefile
2 --- src/linux/linux.orig/Makefile 2003-10-14 04:00:10.000000000 -0400
3 +++ src/linux/linux/Makefile 2004-05-25 21:12:24.000000000 -0400
5 FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net $(HPATH)/math-emu
8 -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
9 +HOSTCFLAGS = -Wall -Wstrict-prototypes -Os -fomit-frame-pointer
15 CPPFLAGS := -D__KERNEL__ -I$(HPATH)
17 -CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
18 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
19 -fno-strict-aliasing -fno-common
21 # Turn on -pg to instrument the kernel with calls to mcount().
22 diff -Nurb src/linux/linux.orig/arch/mips/brcm-boards/bcm947xx/setup.c src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c
23 --- src/linux/linux.orig/arch/mips/brcm-boards/bcm947xx/setup.c 2003-11-11 09:08:46.000000000 -0500
24 +++ src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c 2004-05-25 21:12:24.000000000 -0400
26 #include <linux/ext2_fs.h>
27 #include <linux/romfs_fs.h>
28 #include <linux/cramfs_fs.h>
29 +#include <linux/squashfs_fs.h>
34 #ifdef CONFIG_MTD_PARTITIONS
36 static struct mtd_partition bcm947xx_parts[] = {
37 - { name: "pmon", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
38 + { name: "pmon", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
39 { name: "linux", offset: 0, size: 0, },
40 { name: "rootfs", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
41 { name: "nvram", offset: 0, size: 0, },
42 + { name: "OpenWrt", offset: 0, size: 0, },
46 -struct mtd_partition * __init
47 -init_mtd_partitions(struct mtd_info *mtd, size_t size)
50 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
52 - struct minix_super_block *minixsb;
53 - struct ext2_super_block *ext2sb;
54 - struct romfs_super_block *romfsb;
55 struct cramfs_super *cramfsb;
56 + struct squashfs_super_block *squashfsb;
57 struct trx_header *trx;
59 unsigned char buf[512];
63 - minixsb = (struct minix_super_block *) buf;
64 - ext2sb = (struct ext2_super_block *) buf;
65 - romfsb = (struct romfs_super_block *) buf;
66 cramfsb = (struct cramfs_super *) buf;
67 + squashfsb = (struct squashfs_super_block *) buf;
68 trx = (struct trx_header *) buf;
70 - /* Look at every 64 KB boundary */
71 - for (off = 0; off < size; off += (64 * 1024)) {
75 + for (off = 0; off < size; off += mtd->erasesize) {
76 memset(buf, 0xe5, sizeof(buf));
79 - * Read block 0 to test for romfs and cramfs superblock
80 + * Read block 0 to test for cramfs superblock
82 if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
84 @@ -198,75 +200,105 @@
86 /* Try looking at TRX header for rootfs offset */
87 if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
88 - bcm947xx_parts[1].offset = off;
89 if (le32_to_cpu(trx->offsets[1]) > off)
90 off = le32_to_cpu(trx->offsets[1]);
94 - /* romfs is at block zero too */
95 - if (romfsb->word0 == ROMSB_WORD0 &&
96 - romfsb->word1 == ROMSB_WORD1) {
98 - "%s: romfs filesystem found at block %d\n",
99 - mtd->name, off / BLOCK_SIZE);
104 + /* need to find cramfs */
105 if (cramfsb->magic == CRAMFS_MAGIC) {
107 "%s: cramfs filesystem found at block %d\n",
108 mtd->name, off / BLOCK_SIZE);
113 - * Read block 1 to test for minix and ext2 superblock
115 - if (MTD_READ(mtd, off + BLOCK_SIZE, sizeof(buf), &len, buf) ||
116 - len != sizeof(buf))
120 - if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
121 - minixsb->s_magic == MINIX_SUPER_MAGIC2) {
123 - "%s: Minix filesystem found at block %d\n",
124 - mtd->name, off / BLOCK_SIZE);
125 + part->size = cramfsb->size;
130 - if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
132 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
134 - "%s: ext2 filesystem found at block %d\n",
135 + "%s: squashfs filesystem found at block %d\n",
136 mtd->name, off / BLOCK_SIZE);
137 + part->size = squashfsb->bytes_used+2048;
144 - "%s: Couldn't find valid ROM disk image\n",
145 + "%s: Couldn't find valid cramfs image\n",
150 + part->offset = off;
155 +struct mtd_partition * __init
156 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
159 + bcm947xx_parts[0].offset=0;
160 + bcm947xx_parts[0].size=256*1024;
163 /* Find and size nvram */
164 bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
165 bcm947xx_parts[3].size = size - bcm947xx_parts[3].offset;
167 /* Find and size rootfs */
169 - bcm947xx_parts[2].offset = off;
170 - bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
172 + //if (off < size) {
173 + // bcm947xx_parts[2].offset = off;
174 + // bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
177 + /* Find and size rootfs */
178 + find_root(mtd,size,&bcm947xx_parts[2]);
182 /* Size linux (kernel and rootfs) */
183 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
184 bcm947xx_parts[1].size = bcm947xx_parts[3].offset - bcm947xx_parts[1].offset;
188 + /* calculate leftover flash, and assign it to the jffs partition */
192 + // get the offset to the end of the root_fs
193 + spot=bcm947xx_parts[2].offset+bcm947xx_parts[2].size;
194 + // round it up to an erase size boundary
195 + spot+=mtd->erasesize-1;
196 + // mask the number to the boundary
197 + mask=mtd->erasesize;
199 + mask=mask^0xffffffff;
201 + // length = flashsize - start position - nvram size
203 + len=len-bcm947xx_parts[3].size;
206 + bcm947xx_parts[4].offset = spot;
207 + bcm947xx_parts[4].size = len;
213 bcm947xx_parts[0].size = bcm947xx_parts[1].offset - bcm947xx_parts[0].offset;
216 + //for(x=0; x<5; x++) {
217 + // printk(KERN_NOTICE
218 + // "Partition %d mask_flags %08x\n",
219 + // x,bcm947xx_parts[x].mask_flags);
223 return bcm947xx_parts;
226 diff -Nurb src/linux/linux.orig/drivers/mtd/maps/bcm947xx-flash.c src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c
227 --- src/linux/linux.orig/drivers/mtd/maps/bcm947xx-flash.c 2003-11-08 04:35:52.000000000 -0500
228 +++ src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c 2004-05-25 21:12:24.000000000 -0400
231 void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
233 + //memcpy_fromio(to, map->map_priv_1 + from, len);
235 memcpy_fromio(to, map->map_priv_1 + from, len);
238 + u16 *dest = (u16 *) to;
239 + u16 *src = (u16 *) (map->map_priv_1 + from);
241 + for (i = 0; i < (len / 2); i++) {
246 + *((u8 *)dest+len-1) = src[i] & 0xff;
250 void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
251 diff -Nurb src/linux/linux.orig/drivers/net/Makefile src/linux/linux/drivers/net/Makefile
252 --- src/linux/linux.orig/drivers/net/Makefile 2004-02-12 21:35:15.000000000 -0500
253 +++ src/linux/linux/drivers/net/Makefile 2004-05-25 21:12:24.000000000 -0400
255 list-multi := rcpci.o
256 rcpci-objs := rcpci45.o rclanmtl.o
262 ifeq ($(CONFIG_HW_QOS),y)
263 diff -Nurb src/linux/linux.orig/fs/Config.in src/linux/linux/fs/Config.in
264 --- src/linux/linux.orig/fs/Config.in 2003-07-04 04:12:05.000000000 -0400
265 +++ src/linux/linux/fs/Config.in 2004-05-25 21:13:03.000000000 -0400
267 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
269 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
270 +tristate 'Squashed file system support' CONFIG_SQUASHFS
271 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
272 define_bool CONFIG_RAMFS y
274 diff -Nurb src/linux/linux.orig/fs/Makefile src/linux/linux/fs/Makefile
275 --- src/linux/linux.orig/fs/Makefile 2003-07-04 04:12:05.000000000 -0400
276 +++ src/linux/linux/fs/Makefile 2004-05-25 21:13:03.000000000 -0400
278 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
279 subdir-$(CONFIG_BEFS_FS) += befs
280 subdir-$(CONFIG_JFS_FS) += jfs
281 +subdir-$(CONFIG_SQUASHFS) += squashfs
284 obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o
285 diff -Nurb src/linux/linux.orig/fs/squashfs/Makefile src/linux/linux/fs/squashfs/Makefile
286 --- src/linux/linux.orig/fs/squashfs/Makefile 1969-12-31 19:00:00.000000000 -0500
287 +++ src/linux/linux/fs/squashfs/Makefile 2004-05-25 21:13:03.000000000 -0400
290 +# Makefile for the linux squashfs routines.
293 +O_TARGET := squashfs.o
297 +obj-m := $(O_TARGET)
299 +include $(TOPDIR)/Rules.make
300 diff -Nurb src/linux/linux.orig/fs/squashfs/inode.c src/linux/linux/fs/squashfs/inode.c
301 --- src/linux/linux.orig/fs/squashfs/inode.c 1969-12-31 19:00:00.000000000 -0500
302 +++ src/linux/linux/fs/squashfs/inode.c 2004-05-25 21:13:03.000000000 -0400
305 + * Squashfs - a compressed read only filesystem for Linux
307 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
309 + * This program is free software; you can redistribute it and/or
310 + * modify it under the terms of the GNU General Public License
311 + * as published by the Free Software Foundation; either version 2,
312 + * or (at your option) any later version.
314 + * This program is distributed in the hope that it will be useful,
315 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
316 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
317 + * GNU General Public License for more details.
319 + * You should have received a copy of the GNU General Public License
320 + * along with this program; if not, write to the Free Software
321 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
322 + * Squashfs - a compressed read only filesystem for Linux
327 +#define SQUASHFS_1_0_COMPATIBILITY
329 +#include <linux/types.h>
330 +#include <linux/squashfs_fs.h>
331 +#include <linux/module.h>
332 +#include <linux/errno.h>
333 +#include <linux/slab.h>
334 +#include <linux/fs.h>
335 +#include <linux/locks.h>
336 +#include <linux/init.h>
337 +#include <linux/dcache.h>
338 +#include <asm/uaccess.h>
339 +#include <linux/wait.h>
340 +#include <asm/semaphore.h>
341 +#include <linux/zlib.h>
342 +#include <linux/blkdev.h>
343 +#include <linux/vmalloc.h>
345 +#ifdef SQUASHFS_TRACE
346 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
348 +#define TRACE(s, args...) {}
351 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
353 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
354 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
356 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
357 +static void squashfs_put_super(struct super_block *);
358 +static int squashfs_statfs(struct super_block *, struct statfs *);
359 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
360 +static int squashfs_readpage(struct file *file, struct page *page);
361 +static int squashfs_readpage4K(struct file *file, struct page *page);
362 +static int squashfs_readdir(struct file *, void *, filldir_t);
363 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
364 +static unsigned int read_data(struct super_block *s, char *buffer,
365 + unsigned int index, unsigned int length, int, unsigned int *next_index);
366 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
367 + unsigned int block, unsigned int offset, int length,
368 + unsigned int *next_block, unsigned int *next_offset);
369 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
370 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
371 + char *block_list, char **block_p, unsigned int *bsize);
372 +static void squashfs_put_super(struct super_block *s);
374 +#ifdef SQUASHFS_1_0_COMPATIBILITY
375 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page);
376 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode);
377 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
378 + char *block_list, char **block_p, unsigned int *bsize);
381 +DECLARE_MUTEX(read_data_mutex);
383 +static z_stream stream;
385 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
387 +static unsigned char squashfs_filetype_table[] = {
388 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
391 +static struct super_operations squashfs_ops = {
392 + statfs: squashfs_statfs,
393 + put_super: squashfs_put_super,
396 +static struct address_space_operations squashfs_symlink_aops = {
397 + readpage: squashfs_symlink_readpage
400 +static struct address_space_operations squashfs_aops = {
401 + readpage: squashfs_readpage
404 +static struct address_space_operations squashfs_aops_4K = {
405 + readpage: squashfs_readpage4K
408 +#ifdef SQUASHFS_1_0_COMPATIBILITY
409 +static struct address_space_operations squashfs_aops_lessthan4K = {
410 + readpage: squashfs_readpage_lessthan4K
414 +static struct file_operations squashfs_dir_ops = {
415 + read: generic_read_dir,
416 + readdir: squashfs_readdir
419 +static struct inode_operations squashfs_dir_inode_ops = {
420 + lookup: squashfs_lookup
424 +static unsigned int read_data(struct super_block *s, char *buffer,
425 + unsigned int index, unsigned int length, int datablock, unsigned int *next_index)
427 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
428 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
429 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
430 + unsigned int cur_index = index >> msBlk->devblksize_log2;
431 + int bytes, avail_bytes, b, k;
433 + unsigned int compressed;
434 + unsigned int c_byte = length;
437 + bytes = msBlk->devblksize - offset;
439 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
440 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
442 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
443 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
446 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
448 + if(!(bh[0] = sb_getblk(s, cur_index)))
449 + goto block_release;
450 + for(b = 1; bytes < c_byte; b++) {
451 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
452 + goto block_release;
453 + bytes += msBlk->devblksize;
455 + ll_rw_block(READ, b, bh);
457 + unsigned short temp;
458 + if(!(bh[0] = sb_bread(s, cur_index)))
461 + if(msBlk->devblksize - offset == 1) {
463 + ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
465 + ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset));
467 + if(!(bh[0] = sb_bread(s, ++cur_index)))
470 + ((unsigned char *) &temp)[0] = *((unsigned char *) bh[0]->b_data);
472 + ((unsigned char *) &temp)[1] = *((unsigned char *) bh[0]->b_data);
478 + unsigned short temp;
479 + ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
480 + ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
483 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
486 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
487 + if(offset == msBlk->devblksize) {
489 + if(!(bh[0] = sb_bread(s, ++cur_index)))
493 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
494 + ERROR("Metadata block marker corrupt @ %x\n", index);
501 + bytes = msBlk->devblksize - offset;
503 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
504 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
506 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
507 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
510 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
512 + for(b = 1; bytes < c_byte; b++) {
513 + if(!(bh[b] = sb_getblk(s, ++cur_index)))
514 + goto block_release;
515 + bytes += msBlk->devblksize;
517 + ll_rw_block(READ, b - 1, bh + 1);
521 + down(&read_data_mutex);
523 + for(bytes = 0, k = 0; k < b; k++) {
524 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
525 + wait_on_buffer(bh[k]);
526 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
527 + bytes += avail_bytes;
538 + stream.next_in = c_buffer;
539 + stream.avail_in = c_byte;
540 + stream.next_out = buffer;
541 + stream.avail_out = msBlk->read_size;
542 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
543 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
544 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
545 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
548 + bytes = stream.total_out;
549 + up(&read_data_mutex);
553 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
558 + while(--b >= 0) brelse(bh[b]);
561 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
566 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
567 + unsigned int block, unsigned int offset, int length,
568 + unsigned int *next_block, unsigned int *next_offset)
570 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
571 + int n, i, bytes, return_length = length;
572 + unsigned int next_index;
574 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
577 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
578 + if(msBlk->block_cache[i].block == block)
581 + down(&msBlk->block_cache_mutex);
582 + if(i == SQUASHFS_CACHED_BLKS) {
583 + /* read inode header block */
584 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
585 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
588 + up(&msBlk->block_cache_mutex);
589 + sleep_on(&msBlk->waitq);
592 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
594 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
595 + if(!(msBlk->block_cache[i].data = (unsigned char *)
596 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
597 + ERROR("Failed to allocate cache block\n");
598 + up(&msBlk->block_cache_mutex);
603 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
604 + up(&msBlk->block_cache_mutex);
605 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0, 0,
607 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
610 + down(&msBlk->block_cache_mutex);
611 + wake_up(&msBlk->waitq);
612 + msBlk->block_cache[i].block = block;
613 + msBlk->block_cache[i].next_index = next_index;
614 + TRACE("Read cache block [%x:%x]\n", block, offset);
617 + if(msBlk->block_cache[i].block != block) {
618 + up(&msBlk->block_cache_mutex);
622 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
624 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
625 + if(msBlk->block_cache[i].length - offset == length) {
626 + *next_block = msBlk->block_cache[i].next_index;
629 + *next_block = block;
630 + *next_offset = offset + length;
633 + up(&msBlk->block_cache_mutex);
634 + return return_length;
637 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
640 + block = msBlk->block_cache[i].next_index;
641 + up(&msBlk->block_cache_mutex);
649 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
651 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
652 + unsigned int start_block = msBlk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
653 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
654 + squashfs_fragment_entry fragment_entry;
657 + squashfs_fragment_entry sfragment_entry;
659 + if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
660 + sizeof(sfragment_entry), &start_block, &offset))
662 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
664 + if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
665 + sizeof(fragment_entry), &start_block, &offset))
668 + *fragment_start_block = fragment_entry.start_block;
669 + *fragment_size = fragment_entry.size;
675 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
677 + down(&msBlk->fragment_mutex);
678 + fragment->locked --;
679 + wake_up(&msBlk->fragment_wait_queue);
680 + up(&msBlk->fragment_mutex);
684 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
687 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
690 + down(&msBlk->fragment_mutex);
691 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS && msBlk->fragment[i].block != start_block; i++);
692 + if(i == SQUASHFS_CACHED_FRAGMENTS) {
693 + for(i = msBlk->next_fragment, n = SQUASHFS_CACHED_FRAGMENTS;
694 + n && msBlk->fragment[i].locked; n--, i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS);
697 + up(&msBlk->fragment_mutex);
698 + sleep_on(&msBlk->fragment_wait_queue);
701 + msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
703 + if(msBlk->fragment[i].data == NULL)
704 + if(!(msBlk->fragment[i].data = (unsigned char *)
705 + kmalloc(SQUASHFS_FILE_MAX_SIZE, GFP_KERNEL))) {
706 + ERROR("Failed to allocate fragment cache block\n");
707 + up(&msBlk->fragment_mutex);
711 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
712 + msBlk->fragment[i].locked = 1;
713 + up(&msBlk->fragment_mutex);
714 + if(!(msBlk->fragment[i].length = read_data(s, msBlk->fragment[i].data, start_block, length,
716 + ERROR("Unable to read fragment cache block [%x]\n", start_block);
717 + msBlk->fragment[i].locked = 0;
720 + msBlk->fragment[i].block = start_block;
721 + TRACE("New fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
722 + return &msBlk->fragment[i];
725 + msBlk->fragment[i].locked ++;
726 + up(&msBlk->fragment_mutex);
728 + TRACE("Got fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
729 + return &msBlk->fragment[i];
734 +#ifdef SQUASHFS_1_0_COMPATIBILITY
735 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
737 + struct inode *i = new_inode(s);
738 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
739 + squashfs_super_block *sBlk = &msBlk->sBlk;
740 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
741 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
742 + unsigned int next_block, next_offset;
743 + squashfs_base_inode_header_1 inodeb;
745 + TRACE("Entered squashfs_iget_1\n");
748 + squashfs_base_inode_header_1 sinodeb;
750 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
751 + sizeof(sinodeb), &next_block, &next_offset))
753 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
755 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
756 + sizeof(inodeb), &next_block, &next_offset))
761 + i->i_mtime = sBlk->mkfs_time;
762 + i->i_atime = sBlk->mkfs_time;
763 + i->i_ctime = sBlk->mkfs_time;
765 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
766 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
767 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
769 + i->i_mode = inodeb.mode;
771 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
772 + case SQUASHFS_FILE_TYPE: {
773 + squashfs_reg_inode_header_1 inodep;
776 + squashfs_reg_inode_header_1 sinodep;
778 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
779 + &next_block, &next_offset))
781 + SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
783 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
784 + &next_block, &next_offset))
787 + i->i_size = inodep.file_size;
788 + i->i_fop = &generic_ro_fops;
789 + if(sBlk->block_size > 4096)
790 + i->i_data.a_ops = &squashfs_aops;
791 + else if(sBlk->block_size == 4096)
792 + i->i_data.a_ops = &squashfs_aops_4K;
794 + i->i_data.a_ops = &squashfs_aops_lessthan4K;
795 + i->i_mode |= S_IFREG;
796 + i->i_mtime = inodep.mtime;
797 + i->i_atime = inodep.mtime;
798 + i->i_ctime = inodep.mtime;
799 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
800 + i->i_blksize = PAGE_CACHE_SIZE;
801 + i->u.squashfs_i.fragment_start_block = SQUASHFS_INVALID_BLK;
802 + i->u.squashfs_i.fragment_offset = 0;
803 + i->u.squashfs_i.start_block = inodep.start_block;
804 + i->u.squashfs_i.block_list_start = next_block;
805 + i->u.squashfs_i.offset = next_offset;
806 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
807 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
810 + case SQUASHFS_DIR_TYPE: {
811 + squashfs_dir_inode_header_1 inodep;
814 + squashfs_dir_inode_header_1 sinodep;
816 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
817 + &next_block, &next_offset))
819 + SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
821 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
822 + &next_block, &next_offset))
825 + i->i_size = inodep.file_size;
826 + i->i_op = &squashfs_dir_inode_ops;
827 + i->i_fop = &squashfs_dir_ops;
828 + i->i_mode |= S_IFDIR;
829 + i->i_mtime = inodep.mtime;
830 + i->i_atime = inodep.mtime;
831 + i->i_ctime = inodep.mtime;
832 + i->u.squashfs_i.start_block = inodep.start_block;
833 + i->u.squashfs_i.offset = inodep.offset;
834 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
835 + inodep.start_block, inodep.offset);
838 + case SQUASHFS_SYMLINK_TYPE: {
839 + squashfs_symlink_inode_header_1 inodep;
842 + squashfs_symlink_inode_header_1 sinodep;
844 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
845 + &next_block, &next_offset))
847 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
849 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
850 + &next_block, &next_offset))
853 + i->i_size = inodep.symlink_size;
854 + i->i_op = &page_symlink_inode_operations;
855 + i->i_data.a_ops = &squashfs_symlink_aops;
856 + i->i_mode |= S_IFLNK;
857 + i->u.squashfs_i.start_block = next_block;
858 + i->u.squashfs_i.offset = next_offset;
859 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
860 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
863 + case SQUASHFS_BLKDEV_TYPE:
864 + case SQUASHFS_CHRDEV_TYPE: {
865 + squashfs_dev_inode_header_1 inodep;
868 + squashfs_dev_inode_header_1 sinodep;
870 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
871 + &next_block, &next_offset))
873 + SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
875 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
876 + &next_block, &next_offset))
880 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
881 + init_special_inode(i, i->i_mode, inodep.rdev);
882 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
885 + case SQUASHFS_IPC_TYPE: {
886 + squashfs_ipc_inode_header_1 inodep;
889 + squashfs_ipc_inode_header_1 sinodep;
891 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
892 + &next_block, &next_offset))
894 + SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
896 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
897 + &next_block, &next_offset))
901 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
902 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
903 + init_special_inode(i, i->i_mode, 0);
907 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
911 + if(inodeb.guid == SQUASHFS_GUIDS)
912 + i->i_gid = i->i_uid;
914 + i->i_gid = msBlk->guid[inodeb.guid];
919 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
927 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
929 + struct inode *i = new_inode(s);
930 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
931 + squashfs_super_block *sBlk = &msBlk->sBlk;
932 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
933 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
934 + unsigned int next_block, next_offset;
935 + squashfs_base_inode_header inodeb;
937 + TRACE("Entered squashfs_iget\n");
940 + squashfs_base_inode_header sinodeb;
942 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
943 + sizeof(sinodeb), &next_block, &next_offset))
945 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
947 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
948 + sizeof(inodeb), &next_block, &next_offset))
953 + i->i_mtime = sBlk->mkfs_time;
954 + i->i_atime = sBlk->mkfs_time;
955 + i->i_ctime = sBlk->mkfs_time;
957 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
958 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
959 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
961 + i->i_mode = inodeb.mode;
963 + switch(inodeb.inode_type) {
964 + case SQUASHFS_FILE_TYPE: {
965 + squashfs_reg_inode_header inodep;
968 + squashfs_reg_inode_header sinodep;
970 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
971 + &next_block, &next_offset))
973 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
975 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
976 + &next_block, &next_offset))
979 + i->u.squashfs_i.fragment_start_block = SQUASHFS_INVALID_BLK;
980 + if(inodep.fragment != SQUASHFS_INVALID_BLK && !get_fragment_location(s, inodep.fragment,
981 + &i->u.squashfs_i.fragment_start_block, &i->u.squashfs_i.fragment_size))
984 + i->u.squashfs_i.fragment_offset = inodep.offset;
985 + i->i_size = inodep.file_size;
986 + i->i_fop = &generic_ro_fops;
987 + if(sBlk->block_size > 4096)
988 + i->i_data.a_ops = &squashfs_aops;
990 + i->i_data.a_ops = &squashfs_aops_4K;
991 + i->i_mode |= S_IFREG;
992 + i->i_mtime = inodep.mtime;
993 + i->i_atime = inodep.mtime;
994 + i->i_ctime = inodep.mtime;
995 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
996 + i->i_blksize = PAGE_CACHE_SIZE;
997 + i->u.squashfs_i.start_block = inodep.start_block;
998 + i->u.squashfs_i.block_list_start = next_block;
999 + i->u.squashfs_i.offset = next_offset;
1000 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x fragment_index %x fragment_offset %x\n",
1001 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset, inodep.fragment, inodep.offset);
1004 + case SQUASHFS_DIR_TYPE: {
1005 + squashfs_dir_inode_header inodep;
1008 + squashfs_dir_inode_header sinodep;
1010 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1011 + &next_block, &next_offset))
1013 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
1015 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1016 + &next_block, &next_offset))
1019 + i->i_size = inodep.file_size;
1020 + i->i_op = &squashfs_dir_inode_ops;
1021 + i->i_fop = &squashfs_dir_ops;
1022 + i->i_mode |= S_IFDIR;
1023 + i->i_mtime = inodep.mtime;
1024 + i->i_atime = inodep.mtime;
1025 + i->i_ctime = inodep.mtime;
1026 + i->u.squashfs_i.start_block = inodep.start_block;
1027 + i->u.squashfs_i.offset = inodep.offset;
1028 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
1029 + inodep.start_block, inodep.offset);
1032 + case SQUASHFS_SYMLINK_TYPE: {
1033 + squashfs_symlink_inode_header inodep;
1036 + squashfs_symlink_inode_header sinodep;
1038 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1039 + &next_block, &next_offset))
1041 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
1043 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1044 + &next_block, &next_offset))
1047 + i->i_size = inodep.symlink_size;
1048 + i->i_op = &page_symlink_inode_operations;
1049 + i->i_data.a_ops = &squashfs_symlink_aops;
1050 + i->i_mode |= S_IFLNK;
1051 + i->u.squashfs_i.start_block = next_block;
1052 + i->u.squashfs_i.offset = next_offset;
1053 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
1054 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
1057 + case SQUASHFS_BLKDEV_TYPE:
1058 + case SQUASHFS_CHRDEV_TYPE: {
1059 + squashfs_dev_inode_header inodep;
1062 + squashfs_dev_inode_header sinodep;
1064 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1065 + &next_block, &next_offset))
1067 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
1069 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1070 + &next_block, &next_offset))
1074 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
1075 + init_special_inode(i, i->i_mode, inodep.rdev);
1076 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
1079 + case SQUASHFS_FIFO_TYPE:
1080 + case SQUASHFS_SOCKET_TYPE: {
1082 + i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
1083 + init_special_inode(i, i->i_mode, 0);
1087 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
1088 + goto failed_read1;
1091 + if(inodeb.guid == SQUASHFS_GUIDS)
1092 + i->i_gid = i->i_uid;
1094 + i->i_gid = msBlk->guid[inodeb.guid];
1099 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
1106 +static struct super_block *squashfs_read_super(struct super_block *s,
1107 + void *data, int silent)
1109 + kdev_t dev = s->s_dev;
1110 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
1111 + squashfs_super_block *sBlk = &msBlk->sBlk;
1114 + TRACE("Entered squashfs_read_superblock\n");
1116 + msBlk->devblksize = get_hardsect_size(dev);
1117 + if(msBlk->devblksize < BLOCK_SIZE)
1118 + msBlk->devblksize = BLOCK_SIZE;
1119 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
1120 + set_blocksize(dev, msBlk->devblksize);
1121 + s->s_blocksize = msBlk->devblksize;
1122 + s->s_blocksize_bits = msBlk->devblksize_log2;
1124 + init_MUTEX(&msBlk->read_page_mutex);
1125 + init_MUTEX(&msBlk->block_cache_mutex);
1126 + init_MUTEX(&msBlk->fragment_mutex);
1128 + init_waitqueue_head(&msBlk->waitq);
1129 + init_waitqueue_head(&msBlk->fragment_wait_queue);
1131 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1132 + SERROR("unable to read superblock\n");
1133 + goto failed_mount;
1136 + /* Check it is a SQUASHFS superblock */
1138 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
1139 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
1140 + squashfs_super_block sblk;
1141 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
1142 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
1143 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
1146 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
1147 + goto failed_mount;
1151 + /* Check the MAJOR & MINOR versions */
1152 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1153 + if((sBlk->s_major != 1) && (sBlk->s_major != 2 || sBlk->s_minor > SQUASHFS_MINOR)) {
1154 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (1 : x) or (2 : <= %d)\n",
1155 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MINOR);
1156 + goto failed_mount;
1158 + if(sBlk->s_major == 1)
1159 + sBlk->block_size = sBlk->block_size_1;
1161 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
1162 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
1163 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
1164 + goto failed_mount;
1168 + TRACE("Found valid superblock on %s\n", bdevname(dev));
1169 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
1170 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
1171 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
1172 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
1173 + TRACE("Block size %d\n", sBlk->block_size);
1174 + TRACE("Number of inodes %d\n", sBlk->inodes);
1175 + if(sBlk->s_major > 1)
1176 + TRACE("Number of fragments %d\n", sBlk->fragments);
1177 + TRACE("Number of uids %d\n", sBlk->no_uids);
1178 + TRACE("Number of gids %d\n", sBlk->no_guids);
1179 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
1180 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
1181 + if(sBlk->s_major > 1)
1182 + TRACE("sBlk->fragment_table_start %x\n", sBlk->fragment_table_start);
1183 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
1185 + s->s_flags |= MS_RDONLY;
1186 + s->s_op = &squashfs_ops;
1188 + /* Init inode_table block pointer array */
1189 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1190 + ERROR("Failed to allocate block cache\n");
1191 + goto failed_mount;
1194 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1195 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1197 + msBlk->next_cache = 0;
1199 + /* Allocate read_data block */
1200 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
1201 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
1202 + ERROR("Failed to allocate read_data block\n");
1203 + goto failed_mount1;
1206 + /* Allocate read_page block */
1207 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
1208 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
1209 + ERROR("Failed to allocate read_page block\n");
1210 + goto failed_mount2;
1213 + /* Allocate uid and gid tables */
1214 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
1215 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
1216 + ERROR("Failed to allocate uid/gid table\n");
1217 + goto failed_mount3;
1219 + msBlk->guid = msBlk->uid + sBlk->no_uids;
1222 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1224 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1225 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1226 + SERROR("unable to read uid/gid table\n");
1227 + goto failed_mount4;
1229 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1231 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1232 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1233 + SERROR("unable to read uid/gid table\n");
1234 + goto failed_mount4;
1238 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1239 + if(sBlk->s_major == 1) {
1240 + msBlk->iget = squashfs_iget_1;
1241 + msBlk->read_blocklist = read_blocklist_1;
1242 + msBlk->fragment = (struct squashfs_fragment_cache *) msBlk->fragment_index = NULL;
1243 + goto allocate_root;
1246 + msBlk->iget = squashfs_iget;
1247 + msBlk->read_blocklist = read_blocklist;
1249 + if(!(msBlk->fragment = (struct squashfs_fragment_cache *) kmalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1250 + ERROR("Failed to allocate fragment block cache\n");
1251 + goto failed_mount4;
1254 + for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1255 + msBlk->fragment[i].locked = 0;
1256 + msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
1257 + msBlk->fragment[i].data = NULL;
1260 + msBlk->next_fragment = 0;
1262 + /* Allocate fragment index table */
1263 + if(!(msBlk->fragment_index = (squashfs_fragment_index *) kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), GFP_KERNEL))) {
1264 + ERROR("Failed to allocate uid/gid table\n");
1265 + goto failed_mount5;
1268 + if(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) &&
1269 + !read_data(s, (char *) msBlk->fragment_index, sBlk->fragment_table_start,
1270 + SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1271 + SERROR("unable to read fragment index table\n");
1272 + goto failed_mount6;
1277 + squashfs_fragment_index fragment;
1279 + for(i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments); i++) {
1280 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment), &msBlk->fragment_index[i], 1);
1281 + msBlk->fragment_index[i] = fragment;
1285 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1288 + if(!(s->s_root = d_alloc_root((msBlk->iget)(s, sBlk->root_inode)))) {
1289 + ERROR("Root inode create failed\n");
1290 + goto failed_mount5;
1293 + TRACE("Leaving squashfs_read_super\n");
1297 + kfree(msBlk->fragment_index);
1299 + kfree(msBlk->fragment);
1301 + kfree(msBlk->uid);
1303 + kfree(msBlk->read_page);
1305 + kfree(msBlk->read_data);
1307 + kfree(msBlk->block_cache);
1313 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1315 + squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
1317 + TRACE("Entered squashfs_statfs\n");
1318 + buf->f_type = SQUASHFS_MAGIC;
1319 + buf->f_bsize = sBlk->block_size;
1320 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
1321 + buf->f_bfree = buf->f_bavail = 0;
1322 + buf->f_files = sBlk->inodes;
1324 + buf->f_namelen = SQUASHFS_NAME_LEN;
1329 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1331 + struct inode *inode = page->mapping->host;
1332 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1333 + int block = inode->u.squashfs_i.start_block;
1334 + int offset = inode->u.squashfs_i.offset;
1335 + void *pageaddr = kmap(page);
1337 + TRACE("Entered squashfs_symlink_readpage, page index %x, start block %x, offset %x\n",
1338 + (unsigned int) page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
1340 + for(length = 0; length < index; length += bytes) {
1341 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
1342 + PAGE_CACHE_SIZE, &block, &offset))) {
1343 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1348 + if(length != index) {
1349 + ERROR("(squashfs_symlink_readpage) length != index\n");
1354 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
1355 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
1356 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1359 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1361 + flush_dcache_page(page);
1362 + SetPageUptodate(page);
1371 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1372 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
1373 + char *block_list, char **block_p, unsigned int *bsize)
1375 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1376 + unsigned short *block_listp;
1378 + int block_ptr = inode->u.squashfs_i.block_list_start;
1379 + int offset = inode->u.squashfs_i.offset;
1380 + int block = inode->u.squashfs_i.start_block;
1383 + int blocks = (index + readahead_blks - i);
1384 + if(blocks > (SIZE >> 1)) {
1385 + if((index - i) <= (SIZE >> 1))
1386 + blocks = index - i;
1388 + blocks = SIZE >> 1;
1392 + unsigned char sblock_list[SIZE];
1393 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1394 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1397 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1399 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1400 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1403 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1404 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1405 + if(blocks >= readahead_blks)
1410 + *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1412 + (unsigned short *) *block_p = block_listp;
1419 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1420 + char *block_list, char **block_p, unsigned int *bsize)
1422 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1423 + unsigned int *block_listp;
1425 + int block_ptr = inode->u.squashfs_i.block_list_start;
1426 + int offset = inode->u.squashfs_i.offset;
1427 + int block = inode->u.squashfs_i.start_block;
1430 + int blocks = (index + readahead_blks - i);
1431 + if(blocks > (SIZE >> 2)) {
1432 + if((index - i) <= (SIZE >> 2))
1433 + blocks = index - i;
1435 + blocks = SIZE >> 2;
1439 + unsigned char sblock_list[SIZE];
1440 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1441 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1444 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1446 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1447 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1450 + for(block_listp = (unsigned int *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1451 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1452 + if(blocks >= readahead_blks)
1456 + *bsize = *block_listp;
1461 +static int squashfs_readpage(struct file *file, struct page *page)
1463 + struct inode *inode = page->mapping->host;
1464 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1465 + squashfs_super_block *sBlk = &msBlk->sBlk;
1466 + unsigned char block_list[SIZE];
1467 + unsigned int bsize, block, i = 0, bytes = 0, byte_offset = 0;
1468 + int index = page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT);
1469 + void *pageaddr = kmap(page);
1470 + struct squashfs_fragment_cache *fragment;
1471 + char *data_ptr = msBlk->read_page;
1473 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1474 + int start_index = page->index & ~mask;
1475 + int end_index = start_index | mask;
1477 + TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1478 + inode->u.squashfs_i.start_block);
1480 + if(inode->u.squashfs_i.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log)) {
1481 + if((block = (msBlk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize)) == 0)
1484 + down(&msBlk->read_page_mutex);
1485 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, bsize, 1, NULL))) {
1486 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1487 + up(&msBlk->read_page_mutex);
1491 + if((fragment = get_cached_fragment(inode->i_sb, inode->u.squashfs_i.fragment_start_block, inode->u.squashfs_i.fragment_size)) == NULL) {
1492 + ERROR("Unable to read page, block %x, size %x\n", inode->u.squashfs_i.fragment_start_block, (int) inode->u.squashfs_i.fragment_size);
1495 + bytes = inode->u.squashfs_i.fragment_offset + (inode->i_size & (sBlk->block_size - 1));
1496 + byte_offset = inode->u.squashfs_i.fragment_offset;
1497 + data_ptr = fragment->data;
1500 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1501 + struct page *push_page;
1502 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1504 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1506 + if(i == page->index) {
1507 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1508 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1510 + flush_dcache_page(page);
1511 + SetPageUptodate(page);
1513 + } else if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1514 + void *pageaddr = kmap(push_page);
1515 + memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1516 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1517 + kunmap(push_page);
1518 + flush_dcache_page(push_page);
1519 + SetPageUptodate(push_page);
1520 + UnlockPage(push_page);
1521 + page_cache_release(push_page);
1525 + if(inode->u.squashfs_i.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log))
1526 + up(&msBlk->read_page_mutex);
1528 + release_cached_fragment(msBlk, fragment);
1533 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1535 + flush_dcache_page(page);
1536 + SetPageUptodate(page);
1543 +static int squashfs_readpage4K(struct file *file, struct page *page)
1545 + struct inode *inode = page->mapping->host;
1546 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1547 + squashfs_super_block *sBlk = &msBlk->sBlk;
1548 + unsigned char block_list[SIZE];
1549 + unsigned int bsize, block, bytes = 0;
1550 + void *pageaddr = kmap(page);
1552 + TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1553 + inode->u.squashfs_i.start_block);
1555 + if(page->index < (inode->i_size >> sBlk->block_log)) {
1556 + block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1558 + if(!(bytes = read_data(inode->i_sb, pageaddr, block, bsize, 1, NULL)))
1559 + ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1561 + struct squashfs_fragment_cache *fragment;
1563 + if((fragment = get_cached_fragment(inode->i_sb, inode->u.squashfs_i.fragment_start_block, inode->u.squashfs_i.fragment_size)) == NULL)
1564 + ERROR("Unable to read page, block %x, size %x\n", inode->u.squashfs_i.fragment_start_block, (int) inode->u.squashfs_i.fragment_size);
1566 + bytes = inode->i_size & (sBlk->block_size - 1);
1567 + memcpy(pageaddr, fragment->data + inode->u.squashfs_i.fragment_offset, bytes);
1568 + release_cached_fragment(msBlk, fragment);
1572 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1574 + flush_dcache_page(page);
1575 + SetPageUptodate(page);
1582 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1583 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1585 + struct inode *inode = page->mapping->host;
1586 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1587 + squashfs_super_block *sBlk = &msBlk->sBlk;
1588 + unsigned char block_list[SIZE];
1589 + unsigned short *block_listp, block, bytes = 0;
1590 + int index = page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
1591 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
1592 + int readahead_blks = 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
1593 + void *pageaddr = kmap(page);
1595 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1598 + TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1599 + inode->u.squashfs_i.start_block);
1601 + block = read_blocklist_1(inode, index, readahead_blks, block_list, (char **) &block_listp, NULL);
1603 + if(i_end > file_blocks)
1604 + i_end = file_blocks;
1606 + while(index < i_end) {
1607 + if(!(byte = read_data(inode->i_sb, pageaddr, block, *block_listp, 0, NULL))) {
1608 + ERROR("Unable to read page, block %x, size %x\n", block, *block_listp);
1611 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1619 + memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1621 + flush_dcache_page(page);
1622 + SetPageUptodate(page);
1630 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1632 + struct inode *i = file->f_dentry->d_inode;
1633 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1634 + squashfs_super_block *sBlk = &msBlk->sBlk;
1635 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1636 + i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
1637 + squashfs_dir_header dirh;
1638 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1639 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1641 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1643 + while(length < i->i_size) {
1644 + /* read directory header */
1646 + squashfs_dir_header sdirh;
1647 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1648 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1650 + length += sizeof(sdirh);
1651 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1653 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1654 + next_offset, sizeof(dirh), &next_block, &next_offset))
1656 + length += sizeof(dirh);
1659 + dir_count = dirh.count + 1;
1660 + while(dir_count--) {
1662 + squashfs_dir_entry sdire;
1663 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1664 + next_offset, sizeof(sdire), &next_block, &next_offset))
1666 + length += sizeof(sdire);
1667 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1669 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1670 + next_offset, sizeof(*dire), &next_block, &next_offset))
1672 + length += sizeof(*dire);
1675 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1676 + next_offset, dire->size + 1, &next_block, &next_offset))
1678 + length += dire->size + 1;
1680 + if(file->f_pos >= length)
1683 + dire->name[dire->size + 1] = '\0';
1685 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", (unsigned int) dirent,
1686 + dire->name, dire->size + 1, (int) file->f_pos,
1687 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1689 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1690 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1691 + TRACE("Filldir returned less than 0\n");
1695 + file->f_pos = length;
1703 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1708 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1710 + const char *name =dentry->d_name.name;
1711 + int len = dentry->d_name.len;
1712 + struct inode *inode = NULL;
1713 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1714 + squashfs_super_block *sBlk = &msBlk->sBlk;
1715 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1716 + i->u.squashfs_i.offset, length = 0, dir_count;
1717 + squashfs_dir_header dirh;
1718 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1719 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1721 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1723 + while(length < i->i_size) {
1724 + /* read directory header */
1726 + squashfs_dir_header sdirh;
1727 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1728 + sizeof(sdirh), &next_block, &next_offset))
1730 + length += sizeof(sdirh);
1731 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1733 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1734 + sizeof(dirh), &next_block, &next_offset))
1736 + length += sizeof(dirh);
1739 + dir_count = dirh.count + 1;
1740 + while(dir_count--) {
1742 + squashfs_dir_entry sdire;
1743 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1744 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1746 + length += sizeof(sdire);
1747 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1749 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1750 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1752 + length += sizeof(*dire);
1755 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1756 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1758 + length += dire->size + 1;
1760 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1761 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1763 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1764 + name, dirh.start_block, dire->offset);
1766 + inode = (msBlk->iget)(i->i_sb, ino);
1774 + d_add(dentry, inode);
1775 + return ERR_PTR(0);
1778 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1783 +static void squashfs_put_super(struct super_block *s)
1785 + if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
1786 + if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
1787 + if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
1788 + if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
1789 + s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
1790 + s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
1794 +static int __init init_squashfs_fs(void)
1797 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1798 + ERROR("Failed to allocate zlib workspace\n");
1801 + return register_filesystem(&squashfs_fs_type);
1805 +static void __exit exit_squashfs_fs(void)
1807 + vfree(stream.workspace);
1808 + unregister_filesystem(&squashfs_fs_type);
1814 +module_init(init_squashfs_fs);
1815 +module_exit(exit_squashfs_fs);
1816 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1817 +MODULE_AUTHOR("Phillip Lougher <plougher@users.sourceforge.net>");
1818 +MODULE_LICENSE("GPL");
1819 diff -Nurb src/linux/linux.orig/include/linux/fs.h src/linux/linux/include/linux/fs.h
1820 --- src/linux/linux.orig/include/linux/fs.h 2003-07-04 04:12:25.000000000 -0400
1821 +++ src/linux/linux/include/linux/fs.h 2004-05-25 21:13:03.000000000 -0400
1823 #include <linux/usbdev_fs_i.h>
1824 #include <linux/jffs2_fs_i.h>
1825 #include <linux/cramfs_fs_sb.h>
1826 +#include <linux/squashfs_fs_i.h>
1829 * Attribute flags. These should be or-ed together to figure out what
1831 struct socket socket_i;
1832 struct usbdev_inode_info usbdev_i;
1833 struct jffs2_inode_info jffs2_i;
1834 + struct squashfs_inode_info squashfs_i;
1839 #include <linux/usbdev_fs_sb.h>
1840 #include <linux/cramfs_fs_sb.h>
1841 #include <linux/jffs2_fs_sb.h>
1842 +#include <linux/squashfs_fs_sb.h>
1844 extern struct list_head super_blocks;
1845 extern spinlock_t sb_lock;
1847 struct usbdev_sb_info usbdevfs_sb;
1848 struct jffs2_sb_info jffs2_sb;
1849 struct cramfs_sb_info cramfs_sb;
1850 + struct squashfs_sb_info squashfs_sb;
1854 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs.h src/linux/linux/include/linux/squashfs_fs.h
1855 --- src/linux/linux.orig/include/linux/squashfs_fs.h 1969-12-31 19:00:00.000000000 -0500
1856 +++ src/linux/linux/include/linux/squashfs_fs.h 2004-05-25 21:13:03.000000000 -0400
1858 +#ifndef SQUASHFS_FS
1859 +#define SQUASHFS_FS
1863 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
1865 + * This program is free software; you can redistribute it and/or
1866 + * modify it under the terms of the GNU General Public License
1867 + * as published by the Free Software Foundation; either version 2,
1868 + * or (at your option) any later version.
1870 + * This program is distributed in the hope that it will be useful,
1871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1873 + * GNU General Public License for more details.
1875 + * You should have received a copy of the GNU General Public License
1876 + * along with this program; if not, write to the Free Software
1877 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1882 +#define SQUASHFS_MAJOR 2
1883 +#define SQUASHFS_MINOR 0
1884 +#define SQUASHFS_MAGIC 0x73717368
1885 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1886 +#define SQUASHFS_START 0
1888 +/* size of metadata (inode and directory) blocks */
1889 +#define SQUASHFS_METADATA_SIZE 8192
1890 +#define SQUASHFS_METADATA_LOG 13
1892 +/* default size of data blocks */
1893 +#define SQUASHFS_FILE_SIZE 65536
1894 +#define SQUASHFS_FILE_LOG 16
1896 +#define SQUASHFS_FILE_MAX_SIZE 65536
1898 +/* Max number of uids and gids */
1899 +#define SQUASHFS_UIDS 256
1900 +#define SQUASHFS_GUIDS 255
1902 +/* Max length of filename (not 255) */
1903 +#define SQUASHFS_NAME_LEN 256
1905 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1906 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1907 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1909 +/* Filesystem flags */
1910 +#define SQUASHFS_NOI 0
1911 +#define SQUASHFS_NOD 1
1912 +#define SQUASHFS_CHECK 2
1913 +#define SQUASHFS_NOF 3
1914 +#define SQUASHFS_NO_FRAG 4
1915 +#define SQUASHFS_ALWAYS_FRAG 5
1916 +#define SQUASHFS_DUPLICATE 6
1917 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
1918 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
1919 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
1920 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1921 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1922 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1923 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1924 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1925 +#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))
1927 +/* Max number of types and file types */
1928 +#define SQUASHFS_DIR_TYPE 1
1929 +#define SQUASHFS_FILE_TYPE 2
1930 +#define SQUASHFS_SYMLINK_TYPE 3
1931 +#define SQUASHFS_BLKDEV_TYPE 4
1932 +#define SQUASHFS_CHRDEV_TYPE 5
1933 +#define SQUASHFS_FIFO_TYPE 6
1934 +#define SQUASHFS_SOCKET_TYPE 7
1936 +/* 1.0 filesystem type definitions */
1937 +#define SQUASHFS_TYPES 5
1938 +#define SQUASHFS_IPC_TYPE 0
1940 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1941 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1942 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1943 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1945 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1947 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
1948 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
1949 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
1951 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
1954 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1955 + * offset within that block
1957 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1958 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1959 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1962 +/* Compute 32 bit VFS inode number from squashfs inode number */
1963 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1965 +/* Translate between VFS mode and squashfs mode */
1966 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1968 +/* fragment and fragment table defines */
1969 +typedef unsigned int squashfs_fragment_index;
1970 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
1971 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
1972 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
1973 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
1974 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
1975 +#define SQUASHFS_CACHED_FRAGMENTS 3
1977 +/* cached data constants for filesystem */
1978 +#define SQUASHFS_CACHED_BLKS 8
1980 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1981 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1983 +#define SQUASHFS_MARKER_BYTE 0xff
1986 + * definitions for structures on disk
1989 +typedef unsigned int squashfs_block;
1990 +typedef long long squashfs_inode;
1992 +typedef unsigned int squashfs_uid;
1994 +typedef struct squashfs_super_block {
1995 + unsigned int s_magic;
1996 + unsigned int inodes;
1997 + unsigned int bytes_used;
1998 + unsigned int uid_start;
1999 + unsigned int guid_start;
2000 + unsigned int inode_table_start;
2001 + unsigned int directory_table_start;
2002 + unsigned int s_major:16;
2003 + unsigned int s_minor:16;
2004 + unsigned int block_size_1:16;
2005 + unsigned int block_log:16;
2006 + unsigned int flags:8;
2007 + unsigned int no_uids:8;
2008 + unsigned int no_guids:8;
2009 + time_t mkfs_time /* time of filesystem creation */;
2010 + squashfs_inode root_inode;
2011 + unsigned int block_size;
2012 + unsigned int fragments;
2013 + unsigned int fragment_table_start;
2014 +} __attribute__ ((packed)) squashfs_super_block;
2017 + unsigned int inode_type:4;
2018 + unsigned int mode:12; /* protection */
2019 + unsigned int uid:8; /* index into uid table */
2020 + unsigned int guid:8; /* index into guid table */
2021 +} __attribute__ ((packed)) squashfs_base_inode_header;
2023 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
2026 + unsigned int inode_type:4;
2027 + unsigned int mode:12; /* protection */
2028 + unsigned int uid:8; /* index into uid table */
2029 + unsigned int guid:8; /* index into guid table */
2030 + unsigned short rdev;
2031 +} __attribute__ ((packed)) squashfs_dev_inode_header;
2034 + unsigned int inode_type:4;
2035 + unsigned int mode:12; /* protection */
2036 + unsigned int uid:8; /* index into uid table */
2037 + unsigned int guid:8; /* index into guid table */
2038 + unsigned short symlink_size;
2040 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
2043 + unsigned int inode_type:4;
2044 + unsigned int mode:12; /* protection */
2045 + unsigned int uid:8; /* index into uid table */
2046 + unsigned int guid:8; /* index into guid table */
2048 + squashfs_block start_block;
2049 + unsigned int fragment;
2050 + unsigned int offset;
2051 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2052 + unsigned short block_list[0];
2053 +} __attribute__ ((packed)) squashfs_reg_inode_header;
2056 + unsigned int inode_type:4;
2057 + unsigned int mode:12; /* protection */
2058 + unsigned int uid:8; /* index into uid table */
2059 + unsigned int guid:8; /* index into guid table */
2060 + unsigned int file_size:19;
2061 + unsigned int offset:13;
2063 + unsigned int start_block:24;
2064 +} __attribute__ ((packed)) squashfs_dir_inode_header;
2067 + squashfs_base_inode_header base;
2068 + squashfs_dev_inode_header dev;
2069 + squashfs_symlink_inode_header symlink;
2070 + squashfs_reg_inode_header reg;
2071 + squashfs_dir_inode_header dir;
2072 + squashfs_ipc_inode_header ipc;
2073 +} squashfs_inode_header;
2076 + unsigned int offset:13;
2077 + unsigned int type:3;
2078 + unsigned int size:8;
2080 +} __attribute__ ((packed)) squashfs_dir_entry;
2083 + unsigned int count:8;
2084 + unsigned int start_block:24;
2085 +} __attribute__ ((packed)) squashfs_dir_header;
2089 + unsigned int start_block;
2090 + unsigned int size;
2091 +} __attribute__ ((packed)) squashfs_fragment_entry;
2093 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
2094 +extern int squashfs_uncompress_init(void);
2095 +extern int squashfs_uncompress_exit(void);
2098 + * macros to convert each packed bitfield structure from little endian to big
2099 + * endian and vice versa. These are needed when creating or using a filesystem on a
2100 + * machine with different byte ordering to the target architecture.
2104 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
2105 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
2106 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
2107 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
2108 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
2109 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
2110 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
2111 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
2112 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
2113 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
2114 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
2115 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
2116 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
2117 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
2118 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
2119 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
2120 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
2121 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
2122 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
2123 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
2124 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
2127 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
2128 + SQUASHFS_MEMSET(s, d, n);\
2129 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2130 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2131 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
2132 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
2135 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
2137 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
2138 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
2139 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
2142 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
2143 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
2144 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
2147 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
2148 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
2149 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
2150 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
2151 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
2152 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
2153 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
2156 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
2157 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
2158 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
2159 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
2160 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2161 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2164 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2165 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2166 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
2167 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2170 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2171 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2172 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2173 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
2174 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
2177 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2178 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2179 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2180 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
2183 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2185 + int bit_position;\
2186 + SQUASHFS_MEMSET(s, d, n * 2);\
2187 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2188 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2191 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2193 + int bit_position;\
2194 + SQUASHFS_MEMSET(s, d, n * 4);\
2195 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2196 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2199 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2201 + int bit_position;\
2202 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
2203 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2204 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2207 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2209 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2211 + unsigned int inode_type:4;
2212 + unsigned int mode:12; /* protection */
2213 + unsigned int uid:4; /* index into uid table */
2214 + unsigned int guid:4; /* index into guid table */
2215 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2218 + unsigned int inode_type:4;
2219 + unsigned int mode:12; /* protection */
2220 + unsigned int uid:4; /* index into uid table */
2221 + unsigned int guid:4; /* index into guid table */
2222 + unsigned int type:4;
2223 + unsigned int offset:4;
2224 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2227 + unsigned int inode_type:4;
2228 + unsigned int mode:12; /* protection */
2229 + unsigned int uid:4; /* index into uid table */
2230 + unsigned int guid:4; /* index into guid table */
2231 + unsigned short rdev;
2232 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2235 + unsigned int inode_type:4;
2236 + unsigned int mode:12; /* protection */
2237 + unsigned int uid:4; /* index into uid table */
2238 + unsigned int guid:4; /* index into guid table */
2239 + unsigned short symlink_size;
2241 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2244 + unsigned int inode_type:4;
2245 + unsigned int mode:12; /* protection */
2246 + unsigned int uid:4; /* index into uid table */
2247 + unsigned int guid:4; /* index into guid table */
2249 + squashfs_block start_block;
2250 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2251 + unsigned short block_list[0];
2252 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2255 + unsigned int inode_type:4;
2256 + unsigned int mode:12; /* protection */
2257 + unsigned int uid:4; /* index into uid table */
2258 + unsigned int guid:4; /* index into guid table */
2259 + unsigned int file_size:19;
2260 + unsigned int offset:13;
2262 + unsigned int start_block:24;
2263 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
2265 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2266 + SQUASHFS_MEMSET(s, d, n);\
2267 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2268 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2269 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2270 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2273 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2274 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2275 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
2276 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2279 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2280 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2281 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2284 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2285 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2286 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2289 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2290 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2291 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2292 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2293 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2296 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2297 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2298 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2299 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2300 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2301 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2307 + * macros used to swap each structure entry, taking into account
2308 + * bitfields and different bitfield placing conventions on differing architectures
2310 +#include <asm/byteorder.h>
2311 +#ifdef __BIG_ENDIAN
2312 + /* convert from little endian to big endian */
2313 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2315 + /* convert from big endian to little endian */
2316 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2319 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2321 + int b_pos = pos % 8;\
2322 + unsigned long long val = 0;\
2323 + unsigned char *s = (unsigned char *)p + (pos / 8);\
2324 + unsigned char *d = ((unsigned char *) &val) + 7;\
2325 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2327 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2329 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
2332 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_i.h src/linux/linux/include/linux/squashfs_fs_i.h
2333 --- src/linux/linux.orig/include/linux/squashfs_fs_i.h 1969-12-31 19:00:00.000000000 -0500
2334 +++ src/linux/linux/include/linux/squashfs_fs_i.h 2004-05-25 21:13:03.000000000 -0400
2336 +#ifndef SQUASHFS_FS_I
2337 +#define SQUASHFS_FS_I
2341 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2343 + * This program is free software; you can redistribute it and/or
2344 + * modify it under the terms of the GNU General Public License
2345 + * as published by the Free Software Foundation; either version 2,
2346 + * or (at your option) any later version.
2348 + * This program is distributed in the hope that it will be useful,
2349 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2350 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2351 + * GNU General Public License for more details.
2353 + * You should have received a copy of the GNU General Public License
2354 + * along with this program; if not, write to the Free Software
2355 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2360 +typedef struct squashfs_inode_info {
2361 + unsigned int start_block;
2362 + unsigned int block_list_start;
2363 + unsigned int offset;
2364 + unsigned int fragment_start_block;
2365 + unsigned int fragment_size;
2366 + unsigned int fragment_offset;
2367 + } squashfs_inode_info;
2369 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_sb.h src/linux/linux/include/linux/squashfs_fs_sb.h
2370 --- src/linux/linux.orig/include/linux/squashfs_fs_sb.h 1969-12-31 19:00:00.000000000 -0500
2371 +++ src/linux/linux/include/linux/squashfs_fs_sb.h 2004-05-25 21:13:03.000000000 -0400
2373 +#ifndef SQUASHFS_FS_SB
2374 +#define SQUASHFS_FS_SB
2378 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2380 + * This program is free software; you can redistribute it and/or
2381 + * modify it under the terms of the GNU General Public License
2382 + * as published by the Free Software Foundation; either version 2,
2383 + * or (at your option) any later version.
2385 + * This program is distributed in the hope that it will be useful,
2386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2388 + * GNU General Public License for more details.
2390 + * You should have received a copy of the GNU General Public License
2391 + * along with this program; if not, write to the Free Software
2392 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2394 + * squashfs_fs_sb.h
2397 +#include <linux/squashfs_fs.h>
2400 + unsigned int block;
2402 + unsigned int next_index;
2406 +struct squashfs_fragment_cache {
2407 + unsigned int block;
2409 + unsigned int locked;
2413 +typedef struct squashfs_sb_info {
2414 + squashfs_super_block sBlk;
2416 + int devblksize_log2;
2418 + squashfs_cache *block_cache;
2419 + struct squashfs_fragment_cache *fragment;
2421 + int next_fragment;
2422 + squashfs_uid *uid;
2423 + squashfs_uid *guid;
2424 + squashfs_fragment_index *fragment_index;
2425 + unsigned int read_size;
2428 + struct semaphore read_page_mutex;
2429 + struct semaphore block_cache_mutex;
2430 + struct semaphore fragment_mutex;
2431 + wait_queue_head_t waitq;
2432 + wait_queue_head_t fragment_wait_queue;
2433 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
2434 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2435 + char *block_list, char **block_p, unsigned int *bsize);
2436 + } squashfs_sb_info;
2438 diff -Nurb src/linux/linux.orig/init/do_mounts.c src/linux/linux/init/do_mounts.c
2439 --- src/linux/linux.orig/init/do_mounts.c 2003-11-08 03:13:20.000000000 -0500
2440 +++ src/linux/linux/init/do_mounts.c 2004-05-25 21:13:03.000000000 -0400
2442 #include <linux/ext2_fs.h>
2443 #include <linux/romfs_fs.h>
2444 #include <linux/cramfs_fs.h>
2445 +#include <linux/squashfs_fs.h>
2447 #undef BUILD_CRAMDISK
2456 identify_ramdisk_image(int fd, int start_block)
2458 struct ext2_super_block *ext2sb;
2459 struct romfs_super_block *romfsb;
2460 struct cramfs_super *cramfsb;
2461 + struct squashfs_super_block *squashfsb;
2466 ext2sb = (struct ext2_super_block *) buf;
2467 romfsb = (struct romfs_super_block *) buf;
2468 cramfsb = (struct cramfs_super *) buf;
2469 + squashfsb = (struct squashfs_super_block *) buf;
2470 memset(buf, 0xe5, size);
2473 @@ -536,6 +540,15 @@
2477 + /* squashfs is at block zero too */
2478 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2479 + printk(KERN_NOTICE
2480 + "RAMDISK: squashfs filesystem found at block %d\n",
2482 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2487 * Read block 1 to test for minix and ext2 superblock
2489 diff -Nurb src/linux/linux.orig/kernel/ksyms.c src/linux/linux/kernel/ksyms.c
2490 --- src/linux/linux.orig/kernel/ksyms.c 2003-07-04 04:12:28.000000000 -0400
2491 +++ src/linux/linux/kernel/ksyms.c 2004-05-25 21:12:24.000000000 -0400
2493 EXPORT_SYMBOL(simple_strtoull);
2494 EXPORT_SYMBOL(system_utsname); /* UTS data */
2495 EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
2497 +//#ifndef __mips__ //bite me. -mbm.
2498 EXPORT_SYMBOL(sys_call_table);
2501 EXPORT_SYMBOL(machine_restart);
2502 EXPORT_SYMBOL(machine_halt);
2503 EXPORT_SYMBOL(machine_power_off);
2504 diff -Nurb src/linux/linux.orig/lib/Config.in src/linux/linux/lib/Config.in
2505 --- src/linux/linux.orig/lib/Config.in 2003-07-04 04:12:29.000000000 -0400
2506 +++ src/linux/linux/lib/Config.in 2004-05-25 21:13:03.000000000 -0400
2508 # Do we need the compression support?
2510 if [ "$CONFIG_CRAMFS" = "y" -o \
2511 + "$CONFIG_SQUASHFS" = "y" -o \
2512 "$CONFIG_PPP_DEFLATE" = "y" -o \
2513 "$CONFIG_JFFS2_FS" = "y" -o \
2514 "$CONFIG_ZISOFS_FS" = "y" ]; then
2515 define_tristate CONFIG_ZLIB_INFLATE y
2517 if [ "$CONFIG_CRAMFS" = "m" -o \
2518 + "$CONFIG_SQUASHFS" = "m" -o \
2519 "$CONFIG_PPP_DEFLATE" = "m" -o \
2520 "$CONFIG_JFFS2_FS" = "m" -o \
2521 "$CONFIG_ZISOFS_FS" = "m" ]; then