1 diff -urN src/linux-dist/linux/Makefile src/linux/linux/Makefile
2 --- src/linux-dist/linux/Makefile 2003-10-14 03:00:10.000000000 -0500
3 +++ src/linux/linux/Makefile 2004-03-29 17:00:53.000000000 -0600
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 -urN src/linux-dist/linux/arch/mips/brcm-boards/bcm947xx/setup.c src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c
23 --- src/linux-dist/linux/arch/mips/brcm-boards/bcm947xx/setup.c 2003-11-11 08:08:46.000000000 -0600
24 +++ src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c 2004-03-29 17:00:53.000000000 -0600
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 -urN src/linux-dist/linux/drivers/mtd/maps/bcm947xx-flash.c src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c
227 --- src/linux-dist/linux/drivers/mtd/maps/bcm947xx-flash.c 2003-11-08 03:35:52.000000000 -0600
228 +++ src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c 2004-03-29 17:00:53.000000000 -0600
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 -urN src/linux-dist/linux/drivers/net/Makefile src/linux/linux/drivers/net/Makefile
252 --- src/linux-dist/linux/drivers/net/Makefile 2004-02-12 20:35:15.000000000 -0600
253 +++ src/linux/linux/drivers/net/Makefile 2004-03-29 17:00:53.000000000 -0600
255 list-multi := rcpci.o
256 rcpci-objs := rcpci45.o rclanmtl.o
262 ifeq ($(CONFIG_HW_QOS),y)
263 diff -urN src/linux-dist/linux/fs/Config.in src/linux/linux/fs/Config.in
264 --- src/linux-dist/linux/fs/Config.in 2003-07-04 03:12:05.000000000 -0500
265 +++ src/linux/linux/fs/Config.in 2004-03-29 17:00:53.000000000 -0600
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 -urN src/linux-dist/linux/fs/Makefile src/linux/linux/fs/Makefile
275 --- src/linux-dist/linux/fs/Makefile 2003-07-04 03:12:05.000000000 -0500
276 +++ src/linux/linux/fs/Makefile 2004-03-29 17:00:53.000000000 -0600
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 -urN src/linux-dist/linux/fs/squashfs/Makefile src/linux/linux/fs/squashfs/Makefile
286 --- src/linux-dist/linux/fs/squashfs/Makefile 1969-12-31 18:00:00.000000000 -0600
287 +++ src/linux/linux/fs/squashfs/Makefile 2004-03-29 17:00:53.000000000 -0600
290 +# Makefile for the linux squashfs routines.
293 +O_TARGET := squashfs.o
297 +obj-m := $(O_TARGET)
299 +include $(TOPDIR)/Rules.make
300 diff -urN src/linux-dist/linux/fs/squashfs/inode.c src/linux/linux/fs/squashfs/inode.c
301 --- src/linux-dist/linux/fs/squashfs/inode.c 1969-12-31 18:00:00.000000000 -0600
302 +++ src/linux/linux/fs/squashfs/inode.c 2004-03-29 17:00:53.000000000 -0600
305 + * Squashfs - a compressed read only filesystem for Linux
307 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
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
312 + * 2 of the License, or (at your option) any later version.
317 +#include <linux/types.h>
318 +#include <linux/squashfs_fs.h>
319 +#include <linux/module.h>
320 +#include <linux/errno.h>
321 +#include <linux/slab.h>
322 +#include <linux/fs.h>
323 +#include <linux/locks.h>
324 +#include <linux/init.h>
325 +#include <linux/dcache.h>
326 +#include <asm/uaccess.h>
327 +#include <linux/wait.h>
328 +#include <asm/semaphore.h>
330 +#include <linux/zlib.h>
331 +#include <linux/blkdev.h>
332 +#include <linux/vmalloc.h>
334 +#ifdef SQUASHFS_TRACE
335 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
337 +#define TRACE(s, args...) {}
340 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
342 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
343 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
345 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
346 +static void squashfs_put_super(struct super_block *);
347 +static int squashfs_statfs(struct super_block *, struct statfs *);
348 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
349 +static int squashfs_readpage(struct file *file, struct page *page);
350 +static int squashfs_readdir(struct file *, void *, filldir_t);
351 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
352 +static unsigned int read_data(struct super_block *s, char *buffer,
353 + unsigned int index, int length, unsigned int *next_index);
354 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
355 + unsigned int block, unsigned int offset, int length,
356 + unsigned int *next_block, unsigned int *next_offset);
357 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
358 +static void squashfs_put_super(struct super_block *s);
360 +DECLARE_MUTEX(read_data_mutex);
362 +static z_stream stream;
364 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
366 +static unsigned char squashfs_filetype_table[] = {
367 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
370 +static struct super_operations squashfs_ops = {
371 + statfs: squashfs_statfs,
372 + put_super: squashfs_put_super,
375 +static struct address_space_operations squashfs_symlink_aops = {
376 + readpage: squashfs_symlink_readpage
379 +static struct address_space_operations squashfs_aops = {
380 + readpage: squashfs_readpage
383 +static struct file_operations squashfs_dir_ops = {
384 + read: generic_read_dir,
385 + readdir: squashfs_readdir
388 +static struct inode_operations squashfs_dir_inode_ops = {
389 + lookup: squashfs_lookup
393 +static unsigned int read_data(struct super_block *s, char *buffer,
394 + unsigned int index, int length, unsigned int *next_index)
396 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
397 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
398 + unsigned short c_byte;
399 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
400 + unsigned int cur_index = index >> msBlk->devblksize_log2;
401 + int bytes, avail_bytes, b, k;
403 + unsigned int compressed;
405 + if(!(bh[0] = sb_bread(s, cur_index)))
411 + if(msBlk->devblksize - offset == 1) {
413 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
415 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
417 + if(!(bh[0] = sb_bread(s, ++cur_index)))
420 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data);
422 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data);
427 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
428 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
430 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
433 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
434 + if(offset == msBlk->devblksize) {
436 + if(!(bh[0] = sb_bread(s, ++cur_index)))
440 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
441 + ERROR("Metadata block marker corrupt @ %x\n", index);
449 + bytes = msBlk->devblksize - offset;
450 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
451 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
453 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
455 + for(b = 1; bytes < c_byte; b++) {
456 + if(!(bh[b] = sb_bread(s, ++cur_index)))
457 + goto block_release;
458 + bytes += msBlk->devblksize;
462 + down(&read_data_mutex);
464 + for(bytes = 0, k = 0; k < b; k++) {
465 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
466 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
467 + bytes += avail_bytes;
478 + stream.next_in = c_buffer;
479 + stream.avail_in = c_byte;
480 + stream.next_out = buffer;
481 + stream.avail_out = msBlk->read_size;
482 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
483 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
484 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
485 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
488 + bytes = stream.total_out;
489 + up(&read_data_mutex);
493 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
498 + while(--b >= 0) brelse(bh[b]);
501 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
506 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
507 + unsigned int block, unsigned int offset, int length,
508 + unsigned int *next_block, unsigned int *next_offset)
510 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
511 + int n, i, bytes, return_length = length;
512 + unsigned int next_index;
514 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
517 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
518 + if(msBlk->block_cache[i].block == block)
521 + down(&msBlk->block_cache_mutex);
522 + if(i == SQUASHFS_CACHED_BLKS) {
523 + /* read inode header block */
524 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
525 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
528 + up(&msBlk->block_cache_mutex);
529 + sleep_on(&msBlk->waitq);
532 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
534 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
535 + if(!(msBlk->block_cache[i].data = (unsigned char *)
536 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
537 + ERROR("Failed to allocate cache block\n");
538 + up(&msBlk->block_cache_mutex);
543 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
544 + up(&msBlk->block_cache_mutex);
545 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
547 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
550 + down(&msBlk->block_cache_mutex);
551 + wake_up(&msBlk->waitq);
552 + msBlk->block_cache[i].block = block;
553 + msBlk->block_cache[i].next_index = next_index;
554 + TRACE("Read cache block [%x:%x]\n", block, offset);
557 + if(msBlk->block_cache[i].block != block) {
558 + up(&msBlk->block_cache_mutex);
562 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
564 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
565 + if(msBlk->block_cache[i].length - offset == length) {
566 + *next_block = msBlk->block_cache[i].next_index;
569 + *next_block = block;
570 + *next_offset = offset + length;
573 + up(&msBlk->block_cache_mutex);
574 + return return_length;
577 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
580 + block = msBlk->block_cache[i].next_index;
581 + up(&msBlk->block_cache_mutex);
589 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
591 + struct inode *i = new_inode(s);
592 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
593 + squashfs_super_block *sBlk = &msBlk->sBlk;
594 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
595 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
596 + unsigned int next_block, next_offset;
597 + squashfs_base_inode_header inodeb;
599 + TRACE("Entered squashfs_iget\n");
602 + squashfs_base_inode_header sinodeb;
604 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
605 + sizeof(sinodeb), &next_block, &next_offset))
607 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
609 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
610 + sizeof(inodeb), &next_block, &next_offset))
615 + i->i_mtime = sBlk->mkfs_time;
616 + i->i_atime = sBlk->mkfs_time;
617 + i->i_ctime = sBlk->mkfs_time;
619 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
620 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
621 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
623 + i->i_mode = inodeb.mode;
625 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
626 + case SQUASHFS_FILE_TYPE: {
627 + squashfs_reg_inode_header inodep;
630 + squashfs_reg_inode_header sinodep;
632 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
633 + &next_block, &next_offset))
635 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
637 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
638 + &next_block, &next_offset))
641 + i->i_size = inodep.file_size;
642 + i->i_fop = &generic_ro_fops;
643 + i->i_data.a_ops = &squashfs_aops;
644 + i->i_mode |= S_IFREG;
645 + i->i_mtime = inodep.mtime;
646 + i->i_atime = inodep.mtime;
647 + i->i_ctime = inodep.mtime;
648 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
649 + i->i_blksize = PAGE_CACHE_SIZE;
650 + i->u.squashfs_i.start_block = inodep.start_block;
651 + i->u.squashfs_i.block_list_start = next_block;
652 + i->u.squashfs_i.offset = next_offset;
653 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
654 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
657 + case SQUASHFS_DIR_TYPE: {
658 + squashfs_dir_inode_header inodep;
661 + squashfs_dir_inode_header sinodep;
663 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
664 + &next_block, &next_offset))
666 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
668 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
669 + &next_block, &next_offset))
672 + i->i_size = inodep.file_size;
673 + i->i_op = &squashfs_dir_inode_ops;
674 + i->i_fop = &squashfs_dir_ops;
675 + i->i_mode |= S_IFDIR;
676 + i->i_mtime = inodep.mtime;
677 + i->i_atime = inodep.mtime;
678 + i->i_ctime = inodep.mtime;
679 + i->u.squashfs_i.start_block = inodep.start_block;
680 + i->u.squashfs_i.offset = inodep.offset;
681 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
682 + inodep.start_block, inodep.offset);
685 + case SQUASHFS_SYMLINK_TYPE: {
686 + squashfs_symlink_inode_header inodep;
689 + squashfs_symlink_inode_header sinodep;
691 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
692 + &next_block, &next_offset))
694 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
696 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
697 + &next_block, &next_offset))
700 + i->i_size = inodep.symlink_size;
701 + i->i_op = &page_symlink_inode_operations;
702 + i->i_data.a_ops = &squashfs_symlink_aops;
703 + i->i_mode |= S_IFLNK;
704 + i->u.squashfs_i.start_block = next_block;
705 + i->u.squashfs_i.offset = next_offset;
706 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
707 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
710 + case SQUASHFS_BLKDEV_TYPE:
711 + case SQUASHFS_CHRDEV_TYPE: {
712 + squashfs_dev_inode_header inodep;
715 + squashfs_dev_inode_header sinodep;
717 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
718 + &next_block, &next_offset))
720 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
722 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
723 + &next_block, &next_offset))
727 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
728 + init_special_inode(i, i->i_mode, inodep.rdev);
729 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
732 + case SQUASHFS_IPC_TYPE: {
733 + squashfs_ipc_inode_header inodep;
736 + squashfs_ipc_inode_header sinodep;
738 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
739 + &next_block, &next_offset))
741 + SQUASHFS_SWAP_IPC_INODE_HEADER(&inodep, &sinodep);
743 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
744 + &next_block, &next_offset))
748 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
749 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
750 + init_special_inode(i, i->i_mode, 0);
754 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
758 + if(inodeb.guid == SQUASHFS_GUIDS)
759 + i->i_gid = i->i_uid;
761 + i->i_gid = msBlk->guid[inodeb.guid];
766 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
773 +static struct super_block *squashfs_read_super(struct super_block *s,
774 + void *data, int silent)
776 + kdev_t dev = s->s_dev;
777 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
778 + squashfs_super_block *sBlk = &msBlk->sBlk;
781 + TRACE("Entered squashfs_read_superblock\n");
783 + msBlk->devblksize = get_hardsect_size(dev);
784 + if(msBlk->devblksize < BLOCK_SIZE)
785 + msBlk->devblksize = BLOCK_SIZE;
786 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
787 + set_blocksize(dev, msBlk->devblksize);
788 + s->s_blocksize = msBlk->devblksize;
789 + s->s_blocksize_bits = msBlk->devblksize_log2;
791 + init_MUTEX(&msBlk->read_page_mutex);
792 + init_MUTEX(&msBlk->block_cache_mutex);
794 + init_waitqueue_head(&msBlk->waitq);
796 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
797 + SERROR("unable to read superblock\n");
801 + /* Check it is a SQUASHFS superblock */
803 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
804 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
805 + squashfs_super_block sblk;
806 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
807 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
808 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
811 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
816 + /* Check the MAJOR & MINOR versions */
817 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
818 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
819 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
823 + TRACE("Found valid superblock on %s\n", bdevname(dev));
824 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
825 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
826 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
827 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
828 + TRACE("Block size %d\n", sBlk->block_size);
829 + TRACE("Number of inodes %d\n", sBlk->inodes);
830 + TRACE("Number of uids %d\n", sBlk->no_uids);
831 + TRACE("Number of gids %d\n", sBlk->no_guids);
832 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
833 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
834 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
836 + s->s_flags |= MS_RDONLY;
837 + s->s_op = &squashfs_ops;
839 + /* Init inode_table block pointer array */
840 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
841 + ERROR("Failed to allocate block cache\n");
845 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
846 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
848 + msBlk->next_cache = 0;
850 + /* Allocate read_data block */
851 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
852 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
853 + ERROR("Failed to allocate read_data block\n");
854 + goto failed_mount1;
857 + /* Allocate read_page block */
858 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
859 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
860 + ERROR("Failed to allocate read_page block\n");
861 + goto failed_mount2;
864 + /* Allocate uid and gid tables */
865 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
866 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
867 + ERROR("Failed to allocate uid/gid table\n");
868 + goto failed_mount3;
870 + msBlk->guid = msBlk->uid + sBlk->no_uids;
873 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
875 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
876 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
877 + SERROR("unable to read uid/gid table\n");
878 + goto failed_mount4;
880 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
882 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
883 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
884 + SERROR("unable to read uid/gid table\n");
885 + goto failed_mount4;
888 + if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
889 + ERROR("Root inode create failed\n");
890 + goto failed_mount4;
893 + TRACE("Leaving squashfs_read_super\n");
899 + kfree(msBlk->read_page);
901 + kfree(msBlk->read_data);
903 + kfree(msBlk->block_cache);
909 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
911 + squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
913 + TRACE("Entered squashfs_statfs\n");
914 + buf->f_type = SQUASHFS_MAGIC;
915 + buf->f_bsize = sBlk->block_size;
916 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
917 + buf->f_bfree = buf->f_bavail = 0;
918 + buf->f_files = sBlk->inodes;
920 + buf->f_namelen = SQUASHFS_NAME_LEN;
925 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
927 + struct inode *inode = page->mapping->host;
928 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
929 + int block = inode->u.squashfs_i.start_block;
930 + int offset = inode->u.squashfs_i.offset;
932 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
933 + page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
935 + for(length = 0; length < index; length += bytes) {
936 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
937 + PAGE_CACHE_SIZE, &block, &offset))) {
938 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
943 + if(length != index) {
944 + ERROR("(squashfs_symlink_readpage) length != index\n");
948 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
949 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
950 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
953 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
954 + flush_dcache_page(page);
955 + SetPageUptodate(page);
963 +static int squashfs_readpage(struct file *file, struct page *page)
965 + struct inode *inode = page->mapping->host;
966 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
967 + squashfs_super_block *sBlk = &msBlk->sBlk;
968 + unsigned char block_list[SIZE];
969 + unsigned short *block_listp;
970 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
971 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
972 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
973 + int block = inode->u.squashfs_i.start_block, i = 0;
974 + int bytes = 0, block_ptr = inode->u.squashfs_i.block_list_start;
975 + int offset = inode->u.squashfs_i.offset;
976 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
977 + int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
979 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
980 + inode->u.squashfs_i.start_block);
982 + if(index > file_blocks)
986 + int blocks = (index + readahead_blks - i);
987 + if(blocks > (SIZE >> 1)) {
988 + if((index - i) <= (SIZE >> 1))
989 + blocks = index - i;
991 + blocks = SIZE >> 1;
995 + unsigned char sblock_list[SIZE];
996 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
997 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1000 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1002 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1003 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1006 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1007 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1008 + if(blocks >= readahead_blks)
1012 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
1013 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1014 + int start_index = page->index & ~mask;
1015 + int end_index = start_index | mask;
1016 + int byte_offset = 0;
1018 + down(&msBlk->read_page_mutex);
1019 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
1020 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1024 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1025 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1027 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1029 + if(i == page->index) {
1030 + memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
1031 + memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1032 + flush_dcache_page(page);
1033 + SetPageUptodate(page);
1036 + struct page *push_page;
1038 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1039 + memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
1040 + memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1041 + flush_dcache_page(push_page);
1042 + SetPageUptodate(push_page);
1043 + UnlockPage(push_page);
1044 + page_cache_release(push_page);
1048 + up( &msBlk->read_page_mutex);
1052 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
1053 + if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
1054 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1057 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1058 + char *p = (char *) page_address(page);
1061 + if(i_end > file_blocks)
1062 + i_end = file_blocks;
1064 + while(index < i_end) {
1065 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
1066 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1069 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1078 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
1079 + flush_dcache_page(page);
1080 + SetPageUptodate(page);
1087 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1089 + struct inode *i = file->f_dentry->d_inode;
1090 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1091 + squashfs_super_block *sBlk = &msBlk->sBlk;
1092 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1093 + i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
1094 + squashfs_dir_header dirh;
1095 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1096 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1098 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1100 + while(length < i->i_size) {
1101 + /* read directory header */
1103 + squashfs_dir_header sdirh;
1104 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1105 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1107 + length += sizeof(sdirh);
1108 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1110 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1111 + next_offset, sizeof(dirh), &next_block, &next_offset))
1113 + length += sizeof(dirh);
1116 + dir_count = dirh.count + 1;
1117 + while(dir_count--) {
1119 + squashfs_dir_entry sdire;
1120 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1121 + next_offset, sizeof(sdire), &next_block, &next_offset))
1123 + length += sizeof(sdire);
1124 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1126 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1127 + next_offset, sizeof(*dire), &next_block, &next_offset))
1129 + length += sizeof(*dire);
1132 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1133 + next_offset, dire->size + 1, &next_block, &next_offset))
1135 + length += dire->size + 1;
1137 + if(file->f_pos >= length)
1140 + dire->name[dire->size + 1] = '\0';
1142 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
1143 + dire->name, dire->size + 1, (int) file->f_pos,
1144 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1146 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1147 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1148 + TRACE("Filldir returned less than 0\n");
1152 + file->f_pos = length;
1160 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1165 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1167 + const char *name =dentry->d_name.name;
1168 + int len = dentry->d_name.len;
1169 + struct inode *inode = NULL;
1170 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1171 + squashfs_super_block *sBlk = &msBlk->sBlk;
1172 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1173 + i->u.squashfs_i.offset, length = 0, dir_count;
1174 + squashfs_dir_header dirh;
1175 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1176 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1178 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1180 + while(length < i->i_size) {
1181 + /* read directory header */
1183 + squashfs_dir_header sdirh;
1184 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1185 + sizeof(sdirh), &next_block, &next_offset))
1187 + length += sizeof(sdirh);
1188 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1190 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1191 + sizeof(dirh), &next_block, &next_offset))
1193 + length += sizeof(dirh);
1196 + dir_count = dirh.count + 1;
1197 + while(dir_count--) {
1199 + squashfs_dir_entry sdire;
1200 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1201 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1203 + length += sizeof(*dire);
1204 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1206 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1207 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1209 + length += sizeof(*dire);
1212 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1213 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1215 + length += dire->size + 1;
1217 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1218 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1220 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1221 + name, dirh.start_block, dire->offset);
1223 + inode = squashfs_iget(i->i_sb, ino);
1231 + d_add(dentry, inode);
1232 + return ERR_PTR(0);
1235 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1240 +static void squashfs_put_super(struct super_block *s)
1242 + if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
1243 + if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
1244 + if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
1245 + if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
1246 + s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
1247 + s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
1251 +static int __init init_squashfs_fs(void)
1254 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1255 + ERROR("Failed to allocate zlib workspace\n");
1258 + return register_filesystem(&squashfs_fs_type);
1262 +static void __exit exit_squashfs_fs(void)
1264 + vfree(stream.workspace);
1265 + unregister_filesystem(&squashfs_fs_type);
1271 +module_init(init_squashfs_fs);
1272 +module_exit(exit_squashfs_fs);
1273 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1274 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1275 +MODULE_LICENSE("GPL");
1276 diff -urN src/linux-dist/linux/include/linux/fs.h src/linux/linux/include/linux/fs.h
1277 --- src/linux-dist/linux/include/linux/fs.h 2003-07-04 03:12:25.000000000 -0500
1278 +++ src/linux/linux/include/linux/fs.h 2004-03-29 17:00:53.000000000 -0600
1280 #include <linux/usbdev_fs_i.h>
1281 #include <linux/jffs2_fs_i.h>
1282 #include <linux/cramfs_fs_sb.h>
1283 +#include <linux/squashfs_fs_i.h>
1286 * Attribute flags. These should be or-ed together to figure out what
1288 struct socket socket_i;
1289 struct usbdev_inode_info usbdev_i;
1290 struct jffs2_inode_info jffs2_i;
1291 + struct squashfs_inode_info squashfs_i;
1296 #include <linux/usbdev_fs_sb.h>
1297 #include <linux/cramfs_fs_sb.h>
1298 #include <linux/jffs2_fs_sb.h>
1299 +#include <linux/squashfs_fs_sb.h>
1301 extern struct list_head super_blocks;
1302 extern spinlock_t sb_lock;
1304 struct usbdev_sb_info usbdevfs_sb;
1305 struct jffs2_sb_info jffs2_sb;
1306 struct cramfs_sb_info cramfs_sb;
1307 + struct squashfs_sb_info squashfs_sb;
1311 diff -urN src/linux-dist/linux/include/linux/squashfs_fs.h src/linux/linux/include/linux/squashfs_fs.h
1312 --- src/linux-dist/linux/include/linux/squashfs_fs.h 1969-12-31 18:00:00.000000000 -0600
1313 +++ src/linux/linux/include/linux/squashfs_fs.h 2004-03-29 17:00:53.000000000 -0600
1315 +#ifndef SQUASHFS_FS
1316 +#define SQUASHFS_FS
1320 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1322 + * This program is free software; you can redistribute it and/or
1323 + * modify it under the terms of the GNU General Public License
1324 + * as published by the Free Software Foundation; either version
1325 + * 2 of the License, or (at your option) any later version.
1330 +#define SQUASHFS_MAJOR 1
1331 +#define SQUASHFS_MINOR 0
1332 +#define SQUASHFS_MAGIC 0x73717368
1333 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1334 +#define SQUASHFS_START 0
1336 +/* size of metadata (inode and directory) blocks */
1337 +#define SQUASHFS_METADATA_SIZE 8192
1338 +#define SQUASHFS_METADATA_LOG 13
1340 +/* default size of data blocks */
1341 +#define SQUASHFS_FILE_SIZE 32768
1342 +#define SQUASHFS_FILE_LOG 15
1344 +#define SQUASHFS_FILE_MAX_SIZE 32768
1346 +/* Max number of uids and gids */
1347 +#define SQUASHFS_UIDS 48
1348 +#define SQUASHFS_GUIDS 15
1350 +/* Max length of filename (not 255) */
1351 +#define SQUASHFS_NAME_LEN 256
1353 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1354 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1355 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1357 +/* Filesystem flags */
1358 +#define SQUASHFS_NOI 1
1359 +#define SQUASHFS_NOD 2
1360 +#define SQUASHFS_CHECK 4
1361 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1362 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1363 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1364 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1366 +/* Max number of types and file types */
1367 +#define SQUASHFS_TYPES 5
1368 +#define SQUASHFS_DIR_TYPE 1
1369 +#define SQUASHFS_FILE_TYPE 2
1370 +#define SQUASHFS_SYMLINK_TYPE 3
1371 +#define SQUASHFS_BLKDEV_TYPE 4
1372 +#define SQUASHFS_CHRDEV_TYPE 5
1374 +#define SQUASHFS_IPC_TYPE 0
1375 +#define SQUASHFS_FIFO_TYPE 6
1376 +#define SQUASHFS_SOCKET_TYPE 7
1378 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1379 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1380 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1381 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1383 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1386 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1387 + * offset within that block
1389 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1390 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1391 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1394 +/* Compute 32 bit VFS inode number from squashfs inode number */
1395 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1397 +/* Translate between VFS mode and squashfs mode */
1398 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1400 +/* cached data constants for filesystem */
1401 +#define SQUASHFS_CACHED_BLKS 8
1403 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1404 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1406 +#define SQUASHFS_MARKER_BYTE 0xff
1409 + * definitions for structures on disk
1412 +typedef unsigned int squashfs_block;
1413 +typedef long long squashfs_inode;
1415 +typedef unsigned int squashfs_uid;
1417 +typedef struct squashfs_super_block {
1418 + unsigned int s_magic;
1419 + unsigned int inodes;
1420 + unsigned int bytes_used;
1421 + unsigned int uid_start;
1422 + unsigned int guid_start;
1423 + unsigned int inode_table_start;
1424 + unsigned int directory_table_start;
1425 + unsigned int s_major:16;
1426 + unsigned int s_minor:16;
1427 + unsigned int block_size:16;
1428 + unsigned int block_log:16;
1429 + unsigned int flags:8;
1430 + unsigned int no_uids:8;
1431 + unsigned int no_guids:8;
1432 + time_t mkfs_time /* time of filesystem creation */;
1433 + squashfs_inode root_inode;
1434 +} __attribute__ ((packed)) squashfs_super_block;
1437 + unsigned int inode_type:4;
1438 + unsigned int mode:12; /* protection */
1439 + unsigned int uid:4; /* index into uid table */
1440 + unsigned int guid:4; /* index into guid table */
1441 +} __attribute__ ((packed)) squashfs_base_inode_header;
1444 + unsigned int inode_type:4;
1445 + unsigned int mode:12; /* protection */
1446 + unsigned int uid:4; /* index into uid table */
1447 + unsigned int guid:4; /* index into guid table */
1448 + unsigned int type:4;
1449 + unsigned int offset:4;
1450 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1453 + unsigned int inode_type:4;
1454 + unsigned int mode:12; /* protection */
1455 + unsigned int uid:4; /* index into uid table */
1456 + unsigned int guid:4; /* index into guid table */
1457 + unsigned short rdev;
1458 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1461 + unsigned int inode_type:4;
1462 + unsigned int mode:12; /* protection */
1463 + unsigned int uid:4; /* index into uid table */
1464 + unsigned int guid:4; /* index into guid table */
1465 + unsigned short symlink_size;
1467 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1470 + unsigned int inode_type:4;
1471 + unsigned int mode:12; /* protection */
1472 + unsigned int uid:4; /* index into uid table */
1473 + unsigned int guid:4; /* index into guid table */
1475 + squashfs_block start_block;
1476 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1477 + unsigned short block_list[0];
1478 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1481 + unsigned int inode_type:4;
1482 + unsigned int mode:12; /* protection */
1483 + unsigned int uid:4; /* index into uid table */
1484 + unsigned int guid:4; /* index into guid table */
1485 + unsigned int file_size:19;
1486 + unsigned int offset:13;
1488 + unsigned int start_block:24;
1489 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1492 + squashfs_base_inode_header base;
1493 + squashfs_dev_inode_header dev;
1494 + squashfs_symlink_inode_header symlink;
1495 + squashfs_reg_inode_header reg;
1496 + squashfs_dir_inode_header dir;
1497 + squashfs_ipc_inode_header ipc;
1498 +} squashfs_inode_header;
1501 + unsigned int offset:13;
1502 + unsigned int type:3;
1503 + unsigned int size:8;
1505 +} __attribute__ ((packed)) squashfs_dir_entry;
1508 + unsigned int count:8;
1509 + unsigned int start_block:24;
1510 +} __attribute__ ((packed)) squashfs_dir_header;
1513 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1514 +extern int squashfs_uncompress_init(void);
1515 +extern int squashfs_uncompress_exit(void);
1518 + * macros to convert each packed bitfield structure from little endian to big
1519 + * endian and vice versa. These are needed when creating or using a filesystem on a
1520 + * machine with different byte ordering to the target architecture.
1524 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1525 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1526 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1527 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1528 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1529 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1530 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1531 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1532 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1533 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1534 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1535 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1536 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1537 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1538 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1539 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1540 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1541 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1544 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1545 + SQUASHFS_MEMSET(s, d, n);\
1546 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1547 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1548 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1549 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1552 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1553 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1554 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
1555 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1557 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1558 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1559 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1562 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1563 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1564 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1567 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1568 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1569 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1570 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1571 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1574 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1575 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1576 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1577 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1578 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1579 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1582 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1583 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1584 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1585 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1588 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1589 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1590 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1591 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1592 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1595 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1597 + int bit_position;\
1598 + SQUASHFS_MEMSET(s, d, n * 2);\
1599 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1600 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1603 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1605 + int bit_position;\
1606 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1607 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1608 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1613 + * macros used to swap each structure entry, taking into account
1614 + * bitfields and different bitfield placing conventions on differing architectures
1616 +#include <asm/byteorder.h>
1617 +#ifdef __BIG_ENDIAN
1618 + /* convert from little endian to big endian */
1619 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1621 + /* convert from big endian to little endian */
1622 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1625 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1627 + int b_pos = pos % 8;\
1628 + unsigned long long val = 0;\
1629 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1630 + unsigned char *d = ((unsigned char *) &val) + 7;\
1631 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1633 + value = (val >> (SHIFT));\
1635 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1638 diff -urN src/linux-dist/linux/include/linux/squashfs_fs_i.h src/linux/linux/include/linux/squashfs_fs_i.h
1639 --- src/linux-dist/linux/include/linux/squashfs_fs_i.h 1969-12-31 18:00:00.000000000 -0600
1640 +++ src/linux/linux/include/linux/squashfs_fs_i.h 2004-03-29 17:00:53.000000000 -0600
1642 +#ifndef SQUASHFS_FS_I
1643 +#define SQUASHFS_FS_I
1647 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1649 + * This program is free software; you can redistribute it and/or
1650 + * modify it under the terms of the GNU General Public License
1651 + * as published by the Free Software Foundation; either version
1652 + * 2 of the License, or (at your option) any later version.
1657 +typedef struct squashfs_inode_info {
1658 + unsigned int start_block;
1659 + unsigned int block_list_start;
1660 + unsigned int offset;
1661 + } squashfs_inode_info;
1663 diff -urN src/linux-dist/linux/include/linux/squashfs_fs_sb.h src/linux/linux/include/linux/squashfs_fs_sb.h
1664 --- src/linux-dist/linux/include/linux/squashfs_fs_sb.h 1969-12-31 18:00:00.000000000 -0600
1665 +++ src/linux/linux/include/linux/squashfs_fs_sb.h 2004-03-29 17:00:53.000000000 -0600
1667 +#ifndef SQUASHFS_FS_SB
1668 +#define SQUASHFS_FS_SB
1672 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1674 + * This program is free software; you can redistribute it and/or
1675 + * modify it under the terms of the GNU General Public License
1676 + * as published by the Free Software Foundation; either version
1677 + * 2 of the License, or (at your option) any later version.
1679 + * squashfs_fs_sb.h
1682 +#include <linux/squashfs_fs.h>
1685 + unsigned int block;
1687 + unsigned int next_index;
1691 +typedef struct squashfs_sb_info {
1692 + squashfs_super_block sBlk;
1694 + int devblksize_log2;
1696 + squashfs_cache *block_cache;
1698 + squashfs_uid *uid;
1699 + squashfs_uid *guid;
1700 + unsigned int read_size;
1703 + struct semaphore read_page_mutex;
1704 + struct semaphore block_cache_mutex;
1705 + wait_queue_head_t waitq;
1706 + } squashfs_sb_info;
1708 diff -urN src/linux-dist/linux/init/do_mounts.c src/linux/linux/init/do_mounts.c
1709 --- src/linux-dist/linux/init/do_mounts.c 2003-11-08 02:13:20.000000000 -0600
1710 +++ src/linux/linux/init/do_mounts.c 2004-03-29 17:00:53.000000000 -0600
1712 #include <linux/ext2_fs.h>
1713 #include <linux/romfs_fs.h>
1714 #include <linux/cramfs_fs.h>
1715 +#include <linux/squashfs_fs.h>
1717 #undef BUILD_CRAMDISK
1726 identify_ramdisk_image(int fd, int start_block)
1728 struct ext2_super_block *ext2sb;
1729 struct romfs_super_block *romfsb;
1730 struct cramfs_super *cramfsb;
1731 + struct squashfs_super_block *squashfsb;
1736 ext2sb = (struct ext2_super_block *) buf;
1737 romfsb = (struct romfs_super_block *) buf;
1738 cramfsb = (struct cramfs_super *) buf;
1739 + squashfsb = (struct squashfs_super_block *) buf;
1740 memset(buf, 0xe5, size);
1743 @@ -536,6 +540,15 @@
1747 + /* squashfs is at block zero too */
1748 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
1749 + printk(KERN_NOTICE
1750 + "RAMDISK: squashfs filesystem found at block %d\n",
1752 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
1757 * Read block 1 to test for minix and ext2 superblock
1759 diff -urN src/linux-dist/linux/kernel/ksyms.c src/linux/linux/kernel/ksyms.c
1760 --- src/linux-dist/linux/kernel/ksyms.c 2003-07-04 03:12:28.000000000 -0500
1761 +++ src/linux/linux/kernel/ksyms.c 2004-03-29 17:00:53.000000000 -0600
1763 EXPORT_SYMBOL(simple_strtoull);
1764 EXPORT_SYMBOL(system_utsname); /* UTS data */
1765 EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
1767 +//#ifndef __mips__ //bite me. -mbm.
1768 EXPORT_SYMBOL(sys_call_table);
1771 EXPORT_SYMBOL(machine_restart);
1772 EXPORT_SYMBOL(machine_halt);
1773 EXPORT_SYMBOL(machine_power_off);
1774 diff -urN src/linux-dist/linux/lib/Config.in src/linux/linux/lib/Config.in
1775 --- src/linux-dist/linux/lib/Config.in 2003-07-04 03:12:29.000000000 -0500
1776 +++ src/linux/linux/lib/Config.in 2004-03-29 17:00:53.000000000 -0600
1778 # Do we need the compression support?
1780 if [ "$CONFIG_CRAMFS" = "y" -o \
1781 + "$CONFIG_SQUASHFS" = "y" -o \
1782 "$CONFIG_PPP_DEFLATE" = "y" -o \
1783 "$CONFIG_JFFS2_FS" = "y" -o \
1784 "$CONFIG_ZISOFS_FS" = "y" ]; then
1785 define_tristate CONFIG_ZLIB_INFLATE y
1787 if [ "$CONFIG_CRAMFS" = "m" -o \
1788 + "$CONFIG_SQUASHFS" = "m" -o \
1789 "$CONFIG_PPP_DEFLATE" = "m" -o \
1790 "$CONFIG_JFFS2_FS" = "m" -o \
1791 "$CONFIG_ZISOFS_FS" = "m" ]; then