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/fs.h.orig src/linux/linux/include/linux/fs.h.orig
1855 --- src/linux/linux.orig/include/linux/fs.h.orig 1969-12-31 19:00:00.000000000 -0500
1856 +++ src/linux/linux/include/linux/fs.h.orig 2004-05-25 21:12:42.000000000 -0400
1858 +#ifndef _LINUX_FS_H
1859 +#define _LINUX_FS_H
1862 + * This file has definitions for some important file table
1866 +#include <linux/config.h>
1867 +#include <linux/linkage.h>
1868 +#include <linux/limits.h>
1869 +#include <linux/wait.h>
1870 +#include <linux/types.h>
1871 +#include <linux/vfs.h>
1872 +#include <linux/net.h>
1873 +#include <linux/kdev_t.h>
1874 +#include <linux/ioctl.h>
1875 +#include <linux/list.h>
1876 +#include <linux/dcache.h>
1877 +#include <linux/stat.h>
1878 +#include <linux/cache.h>
1879 +#include <linux/stddef.h>
1880 +#include <linux/string.h>
1882 +#include <asm/atomic.h>
1883 +#include <asm/bitops.h>
1885 +struct poll_table_struct;
1889 + * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
1890 + * the file limit at runtime and only root can increase the per-process
1891 + * nr_file rlimit, so it's safe to set up a ridiculously high absolute
1892 + * upper limit on files-per-process.
1894 + * Some programs (notably those using select()) may have to be
1895 + * recompiled to take full advantage of the new limits..
1898 +/* Fixed constants first: */
1900 +#define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
1901 +#define INR_OPEN 1024 /* Initial setting for nfile rlimits */
1903 +#define BLOCK_SIZE_BITS 10
1904 +#define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
1906 +/* And dynamically-tunable limits and defaults: */
1907 +struct files_stat_struct {
1908 + int nr_files; /* read only */
1909 + int nr_free_files; /* read only */
1910 + int max_files; /* tunable */
1912 +extern struct files_stat_struct files_stat;
1914 +struct inodes_stat_t {
1919 +extern struct inodes_stat_t inodes_stat;
1921 +extern int leases_enable, dir_notify_enable, lease_break_time;
1923 +#define NR_FILE 8192 /* this can well be larger on a larger system */
1924 +#define NR_RESERVED_FILES 10 /* reserved for root */
1925 +#define NR_SUPER 256
1928 +#define MAY_WRITE 2
1931 +#define FMODE_READ 1
1932 +#define FMODE_WRITE 2
1936 +#define READA 2 /* read-ahead - don't block if no resources */
1937 +#define SPECIAL 4 /* For non-blockdevice requests in request queue */
1943 +/* public flags for file_system_type */
1944 +#define FS_REQUIRES_DEV 1
1945 +#define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
1946 +#define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
1947 + * FS_NO_DCACHE is not set.
1949 +#define FS_SINGLE 8 /* Filesystem that can have only one superblock */
1950 +#define FS_NOMOUNT 16 /* Never mount from userland */
1951 +#define FS_LITTER 32 /* Keeps the tree in dcache */
1952 +#define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
1953 + * as nfs_rename() will be cleaned up
1956 + * These are the fs-independent mount-flags: up to 32 flags are supported
1958 +#define MS_RDONLY 1 /* Mount read-only */
1959 +#define MS_NOSUID 2 /* Ignore suid and sgid bits */
1960 +#define MS_NODEV 4 /* Disallow access to device special files */
1961 +#define MS_NOEXEC 8 /* Disallow program execution */
1962 +#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
1963 +#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
1964 +#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
1965 +#define MS_NOATIME 1024 /* Do not update access times. */
1966 +#define MS_NODIRATIME 2048 /* Do not update directory access times */
1967 +#define MS_BIND 4096
1968 +#define MS_MOVE 8192
1969 +#define MS_REC 16384
1970 +#define MS_VERBOSE 32768
1971 +#define MS_ACTIVE (1<<30)
1972 +#define MS_NOUSER (1<<31)
1975 + * Superblock flags that can be altered by MS_REMOUNT
1977 +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
1981 + * Old magic mount flag and mask
1983 +#define MS_MGC_VAL 0xC0ED0000
1984 +#define MS_MGC_MSK 0xffff0000
1986 +/* Inode flags - they have nothing to superblock flags now */
1988 +#define S_SYNC 1 /* Writes are synced at once */
1989 +#define S_NOATIME 2 /* Do not update access times */
1990 +#define S_QUOTA 4 /* Quota initialized for file */
1991 +#define S_APPEND 8 /* Append-only file */
1992 +#define S_IMMUTABLE 16 /* Immutable file */
1993 +#define S_DEAD 32 /* removed, but still open directory */
1994 +#define S_NOQUOTA 64 /* Inode is not counted to quota */
1997 + * Note that nosuid etc flags are inode-specific: setting some file-system
1998 + * flags just means all the inodes inherit those flags by default. It might be
1999 + * possible to override it selectively if you really wanted to with some
2000 + * ioctl() that is not currently implemented.
2002 + * Exception: MS_RDONLY is always applied to the entire file system.
2004 + * Unfortunately, it is possible to change a filesystems flags with it mounted
2005 + * with files in use. This means that all of the inodes will not have their
2006 + * i_flags updated. Hence, i_flags no longer inherit the superblock mount
2007 + * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
2009 +#define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
2011 +#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
2012 +#define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
2013 +#define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
2015 +#define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
2016 +#define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
2017 +#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
2018 +#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
2019 +#define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
2020 +#define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
2022 +#define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
2024 +/* the read-only stuff doesn't really belong here, but any other place is
2025 + probably as bad and I don't want to create yet another include file. */
2027 +#define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
2028 +#define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
2029 +#define BLKRRPART _IO(0x12,95) /* re-read partition table */
2030 +#define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
2031 +#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
2032 +#define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
2033 +#define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
2034 +#define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
2035 +#define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
2036 +#define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
2037 +#define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
2038 +#define BLKSSZGET _IO(0x12,104)/* get block device sector size */
2039 +/* A jump here: 108-111 have been used for various private purposes. */
2040 +#define BLKBSZGET _IOR(0x12,112,sizeof(int))
2041 +#define BLKBSZSET _IOW(0x12,113,sizeof(int))
2042 +#define BLKGETSIZE64 _IOR(0x12,114,sizeof(u64)) /* return device size in bytes (u64 *arg) */
2044 +#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
2045 +#define FIBMAP _IO(0x00,1) /* bmap access */
2046 +#define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
2050 +#include <asm/semaphore.h>
2051 +#include <asm/byteorder.h>
2053 +extern void update_atime (struct inode *);
2054 +#define UPDATE_ATIME(inode) update_atime (inode)
2056 +extern void buffer_init(unsigned long);
2057 +extern void inode_init(unsigned long);
2058 +extern void mnt_init(unsigned long);
2059 +extern void files_init(unsigned long mempages);
2061 +/* bh state bits */
2062 +enum bh_state_bits {
2063 + BH_Uptodate, /* 1 if the buffer contains valid data */
2064 + BH_Dirty, /* 1 if the buffer is dirty */
2065 + BH_Lock, /* 1 if the buffer is locked */
2066 + BH_Req, /* 0 if the buffer has been invalidated */
2067 + BH_Mapped, /* 1 if the buffer has a disk mapping */
2068 + BH_New, /* 1 if the buffer is new and not yet written out */
2069 + BH_Async, /* 1 if the buffer is under end_buffer_io_async I/O */
2070 + BH_Wait_IO, /* 1 if we should write out this buffer */
2071 + BH_Launder, /* 1 if we can throttle on this buffer */
2072 + BH_JBD, /* 1 if it has an attached journal_head */
2074 + BH_PrivateStart,/* not a state bit, but the first bit available
2075 + * for private allocation by other entities
2079 +#define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512)
2082 + * Try to keep the most commonly used fields in single cache lines (16
2083 + * bytes) to improve performance. This ordering should be
2084 + * particularly beneficial on 32-bit processors.
2086 + * We use the first 16 bytes for the data which is used in searches
2087 + * over the block hash lists (ie. getblk() and friends).
2089 + * The second 16 bytes we use for lru buffer scans, as used by
2090 + * sync_buffers() and refill_freelist(). -- sct
2092 +struct buffer_head {
2093 + /* First cache line: */
2094 + struct buffer_head *b_next; /* Hash queue list */
2095 + unsigned long b_blocknr; /* block number */
2096 + unsigned short b_size; /* block size */
2097 + unsigned short b_list; /* List that this buffer appears */
2098 + kdev_t b_dev; /* device (B_FREE = free) */
2100 + atomic_t b_count; /* users using this block */
2101 + kdev_t b_rdev; /* Real device */
2102 + unsigned long b_state; /* buffer state bitmap (see above) */
2103 + unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
2105 + struct buffer_head *b_next_free;/* lru/free list linkage */
2106 + struct buffer_head *b_prev_free;/* doubly linked list of buffers */
2107 + struct buffer_head *b_this_page;/* circular list of buffers in one page */
2108 + struct buffer_head *b_reqnext; /* request queue */
2110 + struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
2111 + char * b_data; /* pointer to data block */
2112 + struct page *b_page; /* the page this bh is mapped to */
2113 + void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
2114 + void *b_private; /* reserved for b_end_io */
2116 + unsigned long b_rsector; /* Real buffer location on disk */
2117 + wait_queue_head_t b_wait;
2119 + struct inode * b_inode;
2120 + struct list_head b_inode_buffers; /* doubly linked list of inode dirty buffers */
2123 +typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
2124 +void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
2126 +#define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
2128 +#define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
2129 +#define buffer_dirty(bh) __buffer_state(bh,Dirty)
2130 +#define buffer_locked(bh) __buffer_state(bh,Lock)
2131 +#define buffer_req(bh) __buffer_state(bh,Req)
2132 +#define buffer_mapped(bh) __buffer_state(bh,Mapped)
2133 +#define buffer_new(bh) __buffer_state(bh,New)
2134 +#define buffer_async(bh) __buffer_state(bh,Async)
2135 +#define buffer_launder(bh) __buffer_state(bh,Launder)
2137 +#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
2139 +extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
2141 +#define touch_buffer(bh) mark_page_accessed(bh->b_page)
2144 +#include <linux/pipe_fs_i.h>
2145 +#include <linux/minix_fs_i.h>
2146 +#include <linux/ext2_fs_i.h>
2147 +#include <linux/ext3_fs_i.h>
2148 +#include <linux/hpfs_fs_i.h>
2149 +#include <linux/ntfs_fs_i.h>
2150 +#include <linux/msdos_fs_i.h>
2151 +#include <linux/umsdos_fs_i.h>
2152 +#include <linux/iso_fs_i.h>
2153 +#include <linux/nfs_fs_i.h>
2154 +#include <linux/sysv_fs_i.h>
2155 +#include <linux/affs_fs_i.h>
2156 +#include <linux/ufs_fs_i.h>
2157 +#include <linux/efs_fs_i.h>
2158 +#include <linux/coda_fs_i.h>
2159 +#include <linux/romfs_fs_i.h>
2160 +#include <linux/shmem_fs.h>
2161 +#include <linux/smb_fs_i.h>
2162 +#include <linux/hfs_fs_i.h>
2163 +#include <linux/adfs_fs_i.h>
2164 +#include <linux/qnx4_fs_i.h>
2165 +#include <linux/reiserfs_fs_i.h>
2166 +#include <linux/bfs_fs_i.h>
2167 +#include <linux/udf_fs_i.h>
2168 +#include <linux/ncp_fs_i.h>
2169 +#include <linux/proc_fs_i.h>
2170 +#include <linux/usbdev_fs_i.h>
2171 +#include <linux/jffs2_fs_i.h>
2172 +#include <linux/cramfs_fs_sb.h>
2175 + * Attribute flags. These should be or-ed together to figure out what
2176 + * has been changed!
2178 +#define ATTR_MODE 1
2181 +#define ATTR_SIZE 8
2182 +#define ATTR_ATIME 16
2183 +#define ATTR_MTIME 32
2184 +#define ATTR_CTIME 64
2185 +#define ATTR_ATIME_SET 128
2186 +#define ATTR_MTIME_SET 256
2187 +#define ATTR_FORCE 512 /* Not a change, but a change it */
2188 +#define ATTR_ATTR_FLAG 1024
2191 + * This is the Inode Attributes structure, used for notify_change(). It
2192 + * uses the above definitions as flags, to know which values have changed.
2193 + * Also, in this manner, a Filesystem can look at only the values it cares
2194 + * about. Basically, these are the attributes that the VFS layer can
2195 + * request to change from the FS layer.
2197 + * Derek Atkins <warlord@MIT.EDU> 94-10-20
2200 + unsigned int ia_valid;
2208 + unsigned int ia_attr_flags;
2212 + * This is the inode attributes flag definitions
2214 +#define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
2215 +#define ATTR_FLAG_NOATIME 2 /* Don't update atime */
2216 +#define ATTR_FLAG_APPEND 4 /* Append-only file */
2217 +#define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
2218 +#define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
2221 + * Includes for diskquotas and mount structures.
2223 +#include <linux/quota.h>
2224 +#include <linux/mount.h>
2227 + * oh the beauties of C type declarations.
2230 +struct address_space;
2233 +struct address_space_operations {
2234 + int (*writepage)(struct page *);
2235 + int (*readpage)(struct file *, struct page *);
2236 + int (*sync_page)(struct page *);
2238 + * ext3 requires that a successful prepare_write() call be followed
2239 + * by a commit_write() call - they must be balanced
2241 + int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
2242 + int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
2243 + /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
2244 + int (*bmap)(struct address_space *, long);
2245 + int (*flushpage) (struct page *, unsigned long);
2246 + int (*releasepage) (struct page *, int);
2247 +#define KERNEL_HAS_O_DIRECT /* this is for modules out of the kernel */
2248 + int (*direct_IO)(int, struct inode *, struct kiobuf *, unsigned long, int);
2251 +struct address_space {
2252 + struct list_head clean_pages; /* list of clean pages */
2253 + struct list_head dirty_pages; /* list of dirty pages */
2254 + struct list_head locked_pages; /* list of locked pages */
2255 + unsigned long nrpages; /* number of total pages */
2256 + struct address_space_operations *a_ops; /* methods */
2257 + struct inode *host; /* owner: inode, block_device */
2258 + struct vm_area_struct *i_mmap; /* list of private mappings */
2259 + struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
2260 + spinlock_t i_shared_lock; /* and spinlock protecting it */
2261 + int gfp_mask; /* how to allocate the pages */
2264 +struct char_device {
2265 + struct list_head hash;
2269 + struct semaphore sem;
2272 +struct block_device {
2273 + struct list_head bd_hash;
2274 + atomic_t bd_count;
2275 + struct inode * bd_inode;
2276 + dev_t bd_dev; /* not a kdev_t - it's a search key */
2278 + const struct block_device_operations *bd_op;
2279 + struct semaphore bd_sem; /* open/close mutex */
2280 + struct list_head bd_inodes;
2284 + struct list_head i_hash;
2285 + struct list_head i_list;
2286 + struct list_head i_dentry;
2288 + struct list_head i_dirty_buffers;
2289 + struct list_head i_dirty_data_buffers;
2291 + unsigned long i_ino;
2303 + unsigned int i_blkbits;
2304 + unsigned long i_blksize;
2305 + unsigned long i_blocks;
2306 + unsigned long i_version;
2307 + struct semaphore i_sem;
2308 + struct semaphore i_zombie;
2309 + struct inode_operations *i_op;
2310 + struct file_operations *i_fop; /* former ->i_op->default_file_ops */
2311 + struct super_block *i_sb;
2312 + wait_queue_head_t i_wait;
2313 + struct file_lock *i_flock;
2314 + struct address_space *i_mapping;
2315 + struct address_space i_data;
2316 + struct dquot *i_dquot[MAXQUOTAS];
2317 + /* These three should probably be a union */
2318 + struct list_head i_devices;
2319 + struct pipe_inode_info *i_pipe;
2320 + struct block_device *i_bdev;
2321 + struct char_device *i_cdev;
2323 + unsigned long i_dnotify_mask; /* Directory notify events */
2324 + struct dnotify_struct *i_dnotify; /* for directory notifications */
2326 + unsigned long i_state;
2328 + unsigned int i_flags;
2329 + unsigned char i_sock;
2331 + atomic_t i_writecount;
2332 + unsigned int i_attr_flags;
2333 + __u32 i_generation;
2335 + struct minix_inode_info minix_i;
2336 + struct ext2_inode_info ext2_i;
2337 + struct ext3_inode_info ext3_i;
2338 + struct hpfs_inode_info hpfs_i;
2339 + struct ntfs_inode_info ntfs_i;
2340 + struct msdos_inode_info msdos_i;
2341 + struct umsdos_inode_info umsdos_i;
2342 + struct iso_inode_info isofs_i;
2343 + struct nfs_inode_info nfs_i;
2344 + struct sysv_inode_info sysv_i;
2345 + struct affs_inode_info affs_i;
2346 + struct ufs_inode_info ufs_i;
2347 + struct efs_inode_info efs_i;
2348 + struct romfs_inode_info romfs_i;
2349 + struct shmem_inode_info shmem_i;
2350 + struct coda_inode_info coda_i;
2351 + struct smb_inode_info smbfs_i;
2352 + struct hfs_inode_info hfs_i;
2353 + struct adfs_inode_info adfs_i;
2354 + struct qnx4_inode_info qnx4_i;
2355 + struct reiserfs_inode_info reiserfs_i;
2356 + struct bfs_inode_info bfs_i;
2357 + struct udf_inode_info udf_i;
2358 + struct ncp_inode_info ncpfs_i;
2359 + struct proc_inode_info proc_i;
2360 + struct socket socket_i;
2361 + struct usbdev_inode_info usbdev_i;
2362 + struct jffs2_inode_info jffs2_i;
2367 +struct fown_struct {
2368 + int pid; /* pid or -pgrp where SIGIO should be sent */
2369 + uid_t uid, euid; /* uid/euid of process setting the owner */
2370 + int signum; /* posix.1b rt signal to be delivered on IO */
2374 + struct list_head f_list;
2375 + struct dentry *f_dentry;
2376 + struct vfsmount *f_vfsmnt;
2377 + struct file_operations *f_op;
2379 + unsigned int f_flags;
2382 + unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
2383 + struct fown_struct f_owner;
2384 + unsigned int f_uid, f_gid;
2387 + unsigned long f_version;
2389 + /* needed for tty driver, and maybe others */
2390 + void *private_data;
2392 + /* preallocated helper kiobuf to speedup O_DIRECT */
2393 + struct kiobuf *f_iobuf;
2394 + long f_iobuf_lock;
2396 +extern spinlock_t files_lock;
2397 +#define file_list_lock() spin_lock(&files_lock);
2398 +#define file_list_unlock() spin_unlock(&files_lock);
2400 +#define get_file(x) atomic_inc(&(x)->f_count)
2401 +#define file_count(x) atomic_read(&(x)->f_count)
2403 +extern int init_private_file(struct file *, struct dentry *, int);
2405 +#define MAX_NON_LFS ((1UL<<31) - 1)
2407 +/* Page cache limit. The filesystems should put that into their s_maxbytes
2408 + limits, otherwise bad things can happen in VM. */
2409 +#if BITS_PER_LONG==32
2410 +#define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
2411 +#elif BITS_PER_LONG==64
2412 +#define MAX_LFS_FILESIZE 0x7fffffffffffffff
2417 +#define FL_BROKEN 4 /* broken flock() emulation */
2418 +#define FL_ACCESS 8 /* for processes suspended by mandatory locking */
2419 +#define FL_LOCKD 16 /* lock held by rpc.lockd */
2420 +#define FL_LEASE 32 /* lease held on this file */
2423 + * The POSIX file lock owner is determined by
2424 + * the "struct files_struct" in the thread group
2425 + * (or NULL for no owner - BSD locks).
2427 + * Lockd stuffs a "host" pointer into this.
2429 +typedef struct files_struct *fl_owner_t;
2432 + struct file_lock *fl_next; /* singly linked list for this inode */
2433 + struct list_head fl_link; /* doubly linked list of all locks */
2434 + struct list_head fl_block; /* circular list of blocked processes */
2435 + fl_owner_t fl_owner;
2436 + unsigned int fl_pid;
2437 + wait_queue_head_t fl_wait;
2438 + struct file *fl_file;
2439 + unsigned char fl_flags;
2440 + unsigned char fl_type;
2444 + void (*fl_notify)(struct file_lock *); /* unblock callback */
2445 + void (*fl_insert)(struct file_lock *); /* lock insertion callback */
2446 + void (*fl_remove)(struct file_lock *); /* lock removal callback */
2448 + struct fasync_struct * fl_fasync; /* for lease break notifications */
2449 + unsigned long fl_break_time; /* for nonblocking lease breaks */
2452 + struct nfs_lock_info nfs_fl;
2456 +/* The following constant reflects the upper bound of the file/locking space */
2458 +#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
2459 +#define OFFSET_MAX INT_LIMIT(loff_t)
2460 +#define OFFT_OFFSET_MAX INT_LIMIT(off_t)
2463 +extern struct list_head file_lock_list;
2465 +#include <linux/fcntl.h>
2467 +extern int fcntl_getlk(unsigned int, struct flock *);
2468 +extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
2470 +extern int fcntl_getlk64(unsigned int, struct flock64 *);
2471 +extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
2474 +extern void locks_init_lock(struct file_lock *);
2475 +extern void locks_copy_lock(struct file_lock *, struct file_lock *);
2476 +extern void locks_remove_posix(struct file *, fl_owner_t);
2477 +extern void locks_remove_flock(struct file *);
2478 +extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
2479 +extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
2480 +extern void posix_block_lock(struct file_lock *, struct file_lock *);
2481 +extern void posix_unblock_lock(struct file_lock *);
2482 +extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
2483 +extern int __get_lease(struct inode *inode, unsigned int flags);
2484 +extern time_t lease_get_mtime(struct inode *);
2485 +extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
2486 +extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
2488 +struct fasync_struct {
2491 + struct fasync_struct *fa_next; /* singly linked list */
2492 + struct file *fa_file;
2495 +#define FASYNC_MAGIC 0x4601
2497 +/* SMP safe fasync helpers: */
2498 +extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
2499 +/* can be called from interrupts */
2500 +extern void kill_fasync(struct fasync_struct **, int, int);
2501 +/* only for net: no internal synchronization */
2502 +extern void __kill_fasync(struct fasync_struct *, int, int);
2505 + struct dentry *dentry;
2506 + struct vfsmount *mnt;
2508 + unsigned int flags;
2512 +#define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
2513 +#define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
2515 +struct quota_mount_options
2517 + unsigned int flags; /* Flags for diskquotas on this device */
2518 + struct semaphore dqio_sem; /* lock device while I/O in progress */
2519 + struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
2520 + struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
2521 + time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */
2522 + time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */
2523 + char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */
2530 +#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
2531 +#define MNT_DETACH 0x00000002 /* Just detach from the tree */
2533 +#include <linux/minix_fs_sb.h>
2534 +#include <linux/ext2_fs_sb.h>
2535 +#include <linux/ext3_fs_sb.h>
2536 +#include <linux/hpfs_fs_sb.h>
2537 +#include <linux/ntfs_fs_sb.h>
2538 +#include <linux/msdos_fs_sb.h>
2539 +#include <linux/iso_fs_sb.h>
2540 +#include <linux/nfs_fs_sb.h>
2541 +#include <linux/sysv_fs_sb.h>
2542 +#include <linux/affs_fs_sb.h>
2543 +#include <linux/ufs_fs_sb.h>
2544 +#include <linux/efs_fs_sb.h>
2545 +#include <linux/romfs_fs_sb.h>
2546 +#include <linux/smb_fs_sb.h>
2547 +#include <linux/hfs_fs_sb.h>
2548 +#include <linux/adfs_fs_sb.h>
2549 +#include <linux/qnx4_fs_sb.h>
2550 +#include <linux/reiserfs_fs_sb.h>
2551 +#include <linux/bfs_fs_sb.h>
2552 +#include <linux/udf_fs_sb.h>
2553 +#include <linux/ncp_fs_sb.h>
2554 +#include <linux/usbdev_fs_sb.h>
2555 +#include <linux/cramfs_fs_sb.h>
2556 +#include <linux/jffs2_fs_sb.h>
2558 +extern struct list_head super_blocks;
2559 +extern spinlock_t sb_lock;
2561 +#define sb_entry(list) list_entry((list), struct super_block, s_list)
2562 +#define S_BIAS (1<<30)
2563 +struct super_block {
2564 + struct list_head s_list; /* Keep this first */
2566 + unsigned long s_blocksize;
2567 + unsigned char s_blocksize_bits;
2568 + unsigned char s_dirt;
2569 + unsigned long long s_maxbytes; /* Max file size */
2570 + struct file_system_type *s_type;
2571 + struct super_operations *s_op;
2572 + struct dquot_operations *dq_op;
2573 + unsigned long s_flags;
2574 + unsigned long s_magic;
2575 + struct dentry *s_root;
2576 + struct rw_semaphore s_umount;
2577 + struct semaphore s_lock;
2579 + atomic_t s_active;
2581 + struct list_head s_dirty; /* dirty inodes */
2582 + struct list_head s_locked_inodes;/* inodes being synced */
2583 + struct list_head s_files;
2585 + struct block_device *s_bdev;
2586 + struct list_head s_instances;
2587 + struct quota_mount_options s_dquot; /* Diskquota specific options */
2590 + struct minix_sb_info minix_sb;
2591 + struct ext2_sb_info ext2_sb;
2592 + struct ext3_sb_info ext3_sb;
2593 + struct hpfs_sb_info hpfs_sb;
2594 + struct ntfs_sb_info ntfs_sb;
2595 + struct msdos_sb_info msdos_sb;
2596 + struct isofs_sb_info isofs_sb;
2597 + struct nfs_sb_info nfs_sb;
2598 + struct sysv_sb_info sysv_sb;
2599 + struct affs_sb_info affs_sb;
2600 + struct ufs_sb_info ufs_sb;
2601 + struct efs_sb_info efs_sb;
2602 + struct shmem_sb_info shmem_sb;
2603 + struct romfs_sb_info romfs_sb;
2604 + struct smb_sb_info smbfs_sb;
2605 + struct hfs_sb_info hfs_sb;
2606 + struct adfs_sb_info adfs_sb;
2607 + struct qnx4_sb_info qnx4_sb;
2608 + struct reiserfs_sb_info reiserfs_sb;
2609 + struct bfs_sb_info bfs_sb;
2610 + struct udf_sb_info udf_sb;
2611 + struct ncp_sb_info ncpfs_sb;
2612 + struct usbdev_sb_info usbdevfs_sb;
2613 + struct jffs2_sb_info jffs2_sb;
2614 + struct cramfs_sb_info cramfs_sb;
2615 + void *generic_sbp;
2618 + * The next field is for VFS *only*. No filesystems have any business
2619 + * even looking at it. You had been warned.
2621 + struct semaphore s_vfs_rename_sem; /* Kludge */
2623 + /* The next field is used by knfsd when converting a (inode number based)
2624 + * file handle into a dentry. As it builds a path in the dcache tree from
2625 + * the bottom up, there may for a time be a subpath of dentrys which is not
2626 + * connected to the main tree. This semaphore ensure that there is only ever
2627 + * one such free path per filesystem. Note that unconnected files (or other
2628 + * non-directories) are allowed, but not unconnected diretories.
2630 + struct semaphore s_nfsd_free_path_sem;
2634 + * VFS helper functions..
2636 +extern int vfs_create(struct inode *, struct dentry *, int);
2637 +extern int vfs_mkdir(struct inode *, struct dentry *, int);
2638 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
2639 +extern int vfs_symlink(struct inode *, struct dentry *, const char *);
2640 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
2641 +extern int vfs_rmdir(struct inode *, struct dentry *);
2642 +extern int vfs_unlink(struct inode *, struct dentry *);
2643 +extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
2648 +#define DT_UNKNOWN 0
2659 + * This is the "filldir" function type, used by readdir() to let
2660 + * the kernel specify what kind of dirent layout it wants to have.
2661 + * This allows the kernel to read directories into kernel space or
2662 + * to have different dirent layouts depending on the binary type.
2664 +typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);
2666 +struct block_device_operations {
2667 + int (*open) (struct inode *, struct file *);
2668 + int (*release) (struct inode *, struct file *);
2669 + int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
2670 + int (*check_media_change) (kdev_t);
2671 + int (*revalidate) (kdev_t);
2672 + struct module *owner;
2677 + * read, write, poll, fsync, readv, writev can be called
2678 + * without the big kernel lock held in all filesystems.
2680 +struct file_operations {
2681 + struct module *owner;
2682 + loff_t (*llseek) (struct file *, loff_t, int);
2683 + ssize_t (*read) (struct file *, char *, size_t, loff_t *);
2684 + ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
2685 + int (*readdir) (struct file *, void *, filldir_t);
2686 + unsigned int (*poll) (struct file *, struct poll_table_struct *);
2687 + int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
2688 + int (*mmap) (struct file *, struct vm_area_struct *);
2689 + int (*open) (struct inode *, struct file *);
2690 + int (*flush) (struct file *);
2691 + int (*release) (struct inode *, struct file *);
2692 + int (*fsync) (struct file *, struct dentry *, int datasync);
2693 + int (*fasync) (int, struct file *, int);
2694 + int (*lock) (struct file *, int, struct file_lock *);
2695 + ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
2696 + ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
2697 + ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
2698 + unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
2701 +struct inode_operations {
2702 + int (*create) (struct inode *,struct dentry *,int);
2703 + struct dentry * (*lookup) (struct inode *,struct dentry *);
2704 + int (*link) (struct dentry *,struct inode *,struct dentry *);
2705 + int (*unlink) (struct inode *,struct dentry *);
2706 + int (*symlink) (struct inode *,struct dentry *,const char *);
2707 + int (*mkdir) (struct inode *,struct dentry *,int);
2708 + int (*rmdir) (struct inode *,struct dentry *);
2709 + int (*mknod) (struct inode *,struct dentry *,int,int);
2710 + int (*rename) (struct inode *, struct dentry *,
2711 + struct inode *, struct dentry *);
2712 + int (*readlink) (struct dentry *, char *,int);
2713 + int (*follow_link) (struct dentry *, struct nameidata *);
2714 + void (*truncate) (struct inode *);
2715 + int (*permission) (struct inode *, int);
2716 + int (*revalidate) (struct dentry *);
2717 + int (*setattr) (struct dentry *, struct iattr *);
2718 + int (*getattr) (struct dentry *, struct iattr *);
2719 + int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
2720 + ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
2721 + ssize_t (*listxattr) (struct dentry *, char *, size_t);
2722 + int (*removexattr) (struct dentry *, const char *);
2728 + * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
2729 + * without the big kernel lock held in all filesystems.
2731 +struct super_operations {
2732 + void (*read_inode) (struct inode *);
2734 + /* reiserfs kludge. reiserfs needs 64 bits of information to
2735 + ** find an inode. We are using the read_inode2 call to get
2736 + ** that information. We don't like this, and are waiting on some
2737 + ** VFS changes for the real solution.
2738 + ** iget4 calls read_inode2, iff it is defined
2740 + void (*read_inode2) (struct inode *, void *) ;
2741 + void (*dirty_inode) (struct inode *);
2742 + void (*write_inode) (struct inode *, int);
2743 + void (*put_inode) (struct inode *);
2744 + void (*delete_inode) (struct inode *);
2745 + void (*put_super) (struct super_block *);
2746 + void (*write_super) (struct super_block *);
2747 + void (*write_super_lockfs) (struct super_block *);
2748 + void (*unlockfs) (struct super_block *);
2749 + int (*statfs) (struct super_block *, struct statfs *);
2750 + int (*remount_fs) (struct super_block *, int *, char *);
2751 + void (*clear_inode) (struct inode *);
2752 + void (*umount_begin) (struct super_block *);
2754 + /* Following are for knfsd to interact with "interesting" filesystems
2755 + * Currently just reiserfs, but possibly FAT and others later
2757 + * fh_to_dentry is given a filehandle fragement with length, and a type flag
2758 + * and must return a dentry for the referenced object or, if "parent" is
2759 + * set, a dentry for the parent of the object.
2760 + * If a dentry cannot be found, a "root" dentry should be created and
2761 + * flaged as DCACHE_NFSD_DISCONNECTED. nfsd_iget is an example implementation.
2763 + * dentry_to_fh is given a dentry and must generate the filesys specific
2764 + * part of the file handle. Available length is passed in *lenp and used
2765 + * length should be returned therein.
2766 + * If need_parent is set, then dentry_to_fh should encode sufficient information
2767 + * to find the (current) parent.
2768 + * dentry_to_fh should return a 1byte "type" which will be passed back in
2769 + * the fhtype arguement to fh_to_dentry. Type of 0 is reserved.
2770 + * If filesystem was exportable before the introduction of fh_to_dentry,
2771 + * types 1 and 2 should be used is that same way as the generic code.
2772 + * Type 255 means error.
2774 + * Lengths are in units of 4bytes, not bytes.
2776 + struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh, int len, int fhtype, int parent);
2777 + int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int need_parent);
2778 + int (*show_options)(struct seq_file *, struct vfsmount *);
2781 +/* Inode state bits.. */
2782 +#define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
2783 +#define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
2784 +#define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
2786 +#define I_FREEING 16
2789 +#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
2791 +extern void __mark_inode_dirty(struct inode *, int);
2792 +static inline void mark_inode_dirty(struct inode *inode)
2794 + __mark_inode_dirty(inode, I_DIRTY);
2797 +static inline void mark_inode_dirty_sync(struct inode *inode)
2799 + __mark_inode_dirty(inode, I_DIRTY_SYNC);
2802 +static inline void mark_inode_dirty_pages(struct inode *inode)
2804 + __mark_inode_dirty(inode, I_DIRTY_PAGES);
2807 +struct dquot_operations {
2808 + void (*initialize) (struct inode *, short);
2809 + void (*drop) (struct inode *);
2810 + int (*alloc_block) (struct inode *, unsigned long, char);
2811 + int (*alloc_inode) (const struct inode *, unsigned long);
2812 + void (*free_block) (struct inode *, unsigned long);
2813 + void (*free_inode) (const struct inode *, unsigned long);
2814 + int (*transfer) (struct inode *, struct iattr *);
2817 +struct file_system_type {
2820 + struct super_block *(*read_super) (struct super_block *, void *, int);
2821 + struct module *owner;
2822 + struct file_system_type * next;
2823 + struct list_head fs_supers;
2826 +#define DECLARE_FSTYPE(var,type,read,flags) \
2827 +struct file_system_type var = { \
2829 + read_super: read, \
2830 + fs_flags: flags, \
2831 + owner: THIS_MODULE, \
2834 +#define DECLARE_FSTYPE_DEV(var,type,read) \
2835 + DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
2837 +/* Alas, no aliases. Too much hassle with bringing module.h everywhere */
2838 +#define fops_get(fops) \
2839 + (((fops) && (fops)->owner) \
2840 + ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \
2843 +#define fops_put(fops) \
2845 + if ((fops) && (fops)->owner) \
2846 + __MOD_DEC_USE_COUNT((fops)->owner); \
2849 +extern int register_filesystem(struct file_system_type *);
2850 +extern int unregister_filesystem(struct file_system_type *);
2851 +extern struct vfsmount *kern_mount(struct file_system_type *);
2852 +extern int may_umount(struct vfsmount *);
2853 +extern long do_mount(char *, char *, char *, unsigned long, void *);
2855 +#define kern_umount mntput
2857 +extern int vfs_statfs(struct super_block *, struct statfs *);
2859 +/* Return value for VFS lock functions - tells locks.c to lock conventionally
2860 + * REALLY kosha for root NFS and nfs_lock
2862 +#define LOCK_USE_CLNT 1
2864 +#define FLOCK_VERIFY_READ 1
2865 +#define FLOCK_VERIFY_WRITE 2
2867 +extern int locks_mandatory_locked(struct inode *);
2868 +extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
2871 + * Candidates for mandatory locking have the setgid bit set
2872 + * but no group execute bit - an otherwise meaningless combination.
2874 +#define MANDATORY_LOCK(inode) \
2875 + (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
2877 +static inline int locks_verify_locked(struct inode *inode)
2879 + if (MANDATORY_LOCK(inode))
2880 + return locks_mandatory_locked(inode);
2884 +static inline int locks_verify_area(int read_write, struct inode *inode,
2885 + struct file *filp, loff_t offset,
2888 + if (inode->i_flock && MANDATORY_LOCK(inode))
2889 + return locks_mandatory_area(read_write, inode, filp, offset, count);
2893 +static inline int locks_verify_truncate(struct inode *inode,
2894 + struct file *filp,
2897 + if (inode->i_flock && MANDATORY_LOCK(inode))
2898 + return locks_mandatory_area(
2899 + FLOCK_VERIFY_WRITE, inode, filp,
2900 + size < inode->i_size ? size : inode->i_size,
2901 + (size < inode->i_size ? inode->i_size - size
2902 + : size - inode->i_size)
2907 +static inline int get_lease(struct inode *inode, unsigned int mode)
2909 + if (inode->i_flock)
2910 + return __get_lease(inode, mode);
2916 +asmlinkage long sys_open(const char *, int, int);
2917 +asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
2918 +extern int do_truncate(struct dentry *, loff_t start);
2920 +extern struct file *filp_open(const char *, int, int);
2921 +extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
2922 +extern int filp_close(struct file *, fl_owner_t id);
2923 +extern char * getname(const char *);
2926 +extern void vfs_caches_init(unsigned long);
2928 +#define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
2929 +#define putname(name) kmem_cache_free(names_cachep, (void *)(name))
2931 +enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
2932 +extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
2933 +extern int unregister_blkdev(unsigned int, const char *);
2934 +extern struct block_device *bdget(dev_t);
2935 +extern int bd_acquire(struct inode *inode);
2936 +extern void bd_forget(struct inode *inode);
2937 +extern void bdput(struct block_device *);
2938 +extern struct char_device *cdget(dev_t);
2939 +extern void cdput(struct char_device *);
2940 +extern int blkdev_open(struct inode *, struct file *);
2941 +extern int blkdev_close(struct inode *, struct file *);
2942 +extern struct file_operations def_blk_fops;
2943 +extern struct address_space_operations def_blk_aops;
2944 +extern struct file_operations def_fifo_fops;
2945 +extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
2946 +extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
2947 +extern int blkdev_put(struct block_device *, int);
2950 +extern const struct block_device_operations *get_blkfops(unsigned int);
2951 +extern int register_chrdev(unsigned int, const char *, struct file_operations *);
2952 +extern int unregister_chrdev(unsigned int, const char *);
2953 +extern int chrdev_open(struct inode *, struct file *);
2954 +extern const char * bdevname(kdev_t);
2955 +extern const char * cdevname(kdev_t);
2956 +extern const char * kdevname(kdev_t);
2957 +extern void init_special_inode(struct inode *, umode_t, int);
2959 +/* Invalid inode operations -- fs/bad_inode.c */
2960 +extern void make_bad_inode(struct inode *);
2961 +extern int is_bad_inode(struct inode *);
2963 +extern struct file_operations read_fifo_fops;
2964 +extern struct file_operations write_fifo_fops;
2965 +extern struct file_operations rdwr_fifo_fops;
2966 +extern struct file_operations read_pipe_fops;
2967 +extern struct file_operations write_pipe_fops;
2968 +extern struct file_operations rdwr_pipe_fops;
2970 +extern int fs_may_remount_ro(struct super_block *);
2972 +extern int FASTCALL(try_to_free_buffers(struct page *, unsigned int));
2973 +extern void refile_buffer(struct buffer_head * buf);
2974 +extern void create_empty_buffers(struct page *, kdev_t, unsigned long);
2975 +extern void end_buffer_io_sync(struct buffer_head *bh, int uptodate);
2977 +/* reiserfs_writepage needs this */
2978 +extern void set_buffer_async_io(struct buffer_head *bh) ;
2980 +#define BUF_CLEAN 0
2981 +#define BUF_LOCKED 1 /* Buffers scheduled for write */
2982 +#define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
2985 +static inline void get_bh(struct buffer_head * bh)
2987 + atomic_inc(&(bh)->b_count);
2990 +static inline void put_bh(struct buffer_head *bh)
2992 + smp_mb__before_atomic_dec();
2993 + atomic_dec(&bh->b_count);
2997 + * This is called by bh->b_end_io() handlers when I/O has completed.
2999 +static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
3002 + set_bit(BH_Uptodate, &bh->b_state);
3004 + clear_bit(BH_Uptodate, &bh->b_state);
3007 +#define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
3009 +static inline void __mark_buffer_clean(struct buffer_head *bh)
3011 + refile_buffer(bh);
3014 +static inline void mark_buffer_clean(struct buffer_head * bh)
3016 + if (atomic_set_buffer_clean(bh))
3017 + __mark_buffer_clean(bh);
3020 +extern void FASTCALL(__mark_dirty(struct buffer_head *bh));
3021 +extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh));
3022 +extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
3023 +extern void FASTCALL(buffer_insert_inode_queue(struct buffer_head *, struct inode *));
3024 +extern void FASTCALL(buffer_insert_inode_data_queue(struct buffer_head *, struct inode *));
3026 +static inline int atomic_set_buffer_dirty(struct buffer_head *bh)
3028 + return test_and_set_bit(BH_Dirty, &bh->b_state);
3031 +static inline void mark_buffer_async(struct buffer_head * bh, int on)
3034 + set_bit(BH_Async, &bh->b_state);
3036 + clear_bit(BH_Async, &bh->b_state);
3040 + * If an error happens during the make_request, this function
3041 + * has to be recalled. It marks the buffer as clean and not
3042 + * uptodate, and it notifys the upper layer about the end
3045 +static inline void buffer_IO_error(struct buffer_head * bh)
3047 + mark_buffer_clean(bh);
3049 + * b_end_io has to clear the BH_Uptodate bitflag in the error case!
3051 + bh->b_end_io(bh, 0);
3054 +static inline void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
3056 + mark_buffer_dirty(bh);
3057 + buffer_insert_inode_queue(bh, inode);
3060 +extern void set_buffer_flushtime(struct buffer_head *);
3061 +extern void balance_dirty(void);
3062 +extern int check_disk_change(kdev_t);
3063 +extern int invalidate_inodes(struct super_block *);
3064 +extern int invalidate_device(kdev_t, int);
3065 +extern void invalidate_inode_pages(struct inode *);
3066 +extern void invalidate_inode_pages2(struct address_space *);
3067 +extern void invalidate_inode_buffers(struct inode *);
3068 +#define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
3069 +#define destroy_buffers(dev) __invalidate_buffers((dev), 1)
3070 +extern void invalidate_bdev(struct block_device *, int);
3071 +extern void __invalidate_buffers(kdev_t dev, int);
3072 +extern void sync_inodes(kdev_t);
3073 +extern void sync_unlocked_inodes(void);
3074 +extern void write_inode_now(struct inode *, int);
3075 +extern int sync_buffers(kdev_t, int);
3076 +extern void sync_dev(kdev_t);
3077 +extern int fsync_dev(kdev_t);
3078 +extern int fsync_super(struct super_block *);
3079 +extern int fsync_no_super(kdev_t);
3080 +extern void sync_inodes_sb(struct super_block *);
3081 +extern int fsync_buffers_list(struct list_head *);
3082 +static inline int fsync_inode_buffers(struct inode *inode)
3084 + return fsync_buffers_list(&inode->i_dirty_buffers);
3086 +static inline int fsync_inode_data_buffers(struct inode *inode)
3088 + return fsync_buffers_list(&inode->i_dirty_data_buffers);
3090 +extern int inode_has_buffers(struct inode *);
3091 +extern int filemap_fdatasync(struct address_space *);
3092 +extern int filemap_fdatawait(struct address_space *);
3093 +extern void sync_supers(kdev_t);
3094 +extern int bmap(struct inode *, int);
3095 +extern int notify_change(struct dentry *, struct iattr *);
3096 +extern int permission(struct inode *, int);
3097 +extern int vfs_permission(struct inode *, int);
3098 +extern int get_write_access(struct inode *);
3099 +extern int deny_write_access(struct file *);
3100 +static inline void put_write_access(struct inode * inode)
3102 + atomic_dec(&inode->i_writecount);
3104 +static inline void allow_write_access(struct file *file)
3107 + atomic_inc(&file->f_dentry->d_inode->i_writecount);
3109 +extern int do_pipe(int *);
3111 +extern int open_namei(const char *, int, int, struct nameidata *);
3113 +extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
3114 +extern struct file * open_exec(const char *);
3116 +/* fs/dcache.c -- generic fs support functions */
3117 +extern int is_subdir(struct dentry *, struct dentry *);
3118 +extern ino_t find_inode_number(struct dentry *, struct qstr *);
3121 + * Kernel pointers have redundant information, so we can use a
3122 + * scheme where we can return either an error code or a dentry
3123 + * pointer with the same return value.
3125 + * This should be a per-architecture thing, to allow different
3126 + * error and pointer decisions.
3128 +static inline void *ERR_PTR(long error)
3130 + return (void *) error;
3133 +static inline long PTR_ERR(const void *ptr)
3135 + return (long) ptr;
3138 +static inline long IS_ERR(const void *ptr)
3140 + return (unsigned long)ptr > (unsigned long)-1000L;
3144 + * The bitmask for a lookup event:
3145 + * - follow links at the end
3146 + * - require a directory
3147 + * - ending slashes ok even for nonexistent files
3148 + * - internal "there are more path compnents" flag
3150 +#define LOOKUP_FOLLOW (1)
3151 +#define LOOKUP_DIRECTORY (2)
3152 +#define LOOKUP_CONTINUE (4)
3153 +#define LOOKUP_POSITIVE (8)
3154 +#define LOOKUP_PARENT (16)
3155 +#define LOOKUP_NOALT (32)
3157 + * Type of the last component on LOOKUP_PARENT
3159 +enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
3162 + * "descriptor" for what we're up to with a read for sendfile().
3163 + * This allows us to use the same read code yet
3164 + * have multiple different users of the data that
3165 + * we read from a file.
3167 + * The simplest case just copies the data to user
3175 +} read_descriptor_t;
3177 +typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
3179 +/* needed for stackable file system support */
3180 +extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
3182 +extern int FASTCALL(__user_walk(const char *, unsigned, struct nameidata *));
3183 +extern int FASTCALL(path_init(const char *, unsigned, struct nameidata *));
3184 +extern int FASTCALL(path_walk(const char *, struct nameidata *));
3185 +extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *));
3186 +extern int FASTCALL(link_path_walk(const char *, struct nameidata *));
3187 +extern void path_release(struct nameidata *);
3188 +extern int follow_down(struct vfsmount **, struct dentry **);
3189 +extern int follow_up(struct vfsmount **, struct dentry **);
3190 +extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
3191 +extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
3192 +#define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
3193 +#define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
3195 +extern void iput(struct inode *);
3196 +extern void force_delete(struct inode *);
3197 +extern struct inode * igrab(struct inode *);
3198 +extern ino_t iunique(struct super_block *, ino_t);
3200 +typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
3201 +extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
3202 +static inline struct inode *iget(struct super_block *sb, unsigned long ino)
3204 + return iget4(sb, ino, NULL, NULL);
3207 +extern void clear_inode(struct inode *);
3208 +extern struct inode * get_empty_inode(void);
3210 +static inline struct inode * new_inode(struct super_block *sb)
3212 + struct inode *inode = get_empty_inode();
3215 + inode->i_dev = sb->s_dev;
3216 + inode->i_blkbits = sb->s_blocksize_bits;
3220 +extern void remove_suid(struct inode *inode);
3222 +extern void insert_inode_hash(struct inode *);
3223 +extern void remove_inode_hash(struct inode *);
3224 +extern struct file * get_empty_filp(void);
3225 +extern void file_move(struct file *f, struct list_head *list);
3226 +extern struct buffer_head * get_hash_table(kdev_t, int, int);
3227 +extern struct buffer_head * getblk(kdev_t, int, int);
3228 +extern void ll_rw_block(int, int, struct buffer_head * bh[]);
3229 +extern void submit_bh(int, struct buffer_head *);
3230 +extern int is_read_only(kdev_t);
3231 +extern void __brelse(struct buffer_head *);
3232 +static inline void brelse(struct buffer_head *buf)
3237 +extern void __bforget(struct buffer_head *);
3238 +static inline void bforget(struct buffer_head *buf)
3243 +extern int set_blocksize(kdev_t, int);
3244 +extern int sb_set_blocksize(struct super_block *, int);
3245 +extern int sb_min_blocksize(struct super_block *, int);
3246 +extern struct buffer_head * bread(kdev_t, int, int);
3247 +static inline struct buffer_head * sb_bread(struct super_block *sb, int block)
3249 + return bread(sb->s_dev, block, sb->s_blocksize);
3251 +static inline struct buffer_head * sb_getblk(struct super_block *sb, int block)
3253 + return getblk(sb->s_dev, block, sb->s_blocksize);
3255 +static inline struct buffer_head * sb_get_hash_table(struct super_block *sb, int block)
3257 + return get_hash_table(sb->s_dev, block, sb->s_blocksize);
3259 +extern void wakeup_bdflush(void);
3260 +extern void put_unused_buffer_head(struct buffer_head * bh);
3261 +extern struct buffer_head * get_unused_buffer_head(int async);
3263 +extern int brw_page(int, struct page *, kdev_t, int [], int);
3265 +typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
3267 +/* Generic buffer handling for block filesystems.. */
3268 +extern int try_to_release_page(struct page * page, int gfp_mask);
3269 +extern int discard_bh_page(struct page *, unsigned long, int);
3270 +#define block_flushpage(page, offset) discard_bh_page(page, offset, 1)
3271 +#define block_invalidate_page(page) discard_bh_page(page, 0, 0)
3272 +extern int block_symlink(struct inode *, const char *, int);
3273 +extern int block_write_full_page(struct page*, get_block_t*);
3274 +extern int block_read_full_page(struct page*, get_block_t*);
3275 +extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
3276 +extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
3278 +extern int generic_cont_expand(struct inode *inode, loff_t size) ;
3279 +extern int block_commit_write(struct page *page, unsigned from, unsigned to);
3280 +extern int block_sync_page(struct page *);
3282 +int generic_block_bmap(struct address_space *, long, get_block_t *);
3283 +int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
3284 +int block_truncate_page(struct address_space *, loff_t, get_block_t *);
3285 +extern int generic_direct_IO(int, struct inode *, struct kiobuf *, unsigned long, int, get_block_t *);
3286 +extern int waitfor_one_page(struct page *);
3287 +extern int writeout_one_page(struct page *);
3289 +extern int generic_file_mmap(struct file *, struct vm_area_struct *);
3290 +extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
3291 +extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
3292 +extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
3293 +extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t);
3294 +extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
3295 +extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
3296 +extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
3297 +extern int generic_file_open(struct inode * inode, struct file * filp);
3299 +extern struct file_operations generic_ro_fops;
3301 +extern int vfs_readlink(struct dentry *, char *, int, const char *);
3302 +extern int vfs_follow_link(struct nameidata *, const char *);
3303 +extern int page_readlink(struct dentry *, char *, int);
3304 +extern int page_follow_link(struct dentry *, struct nameidata *);
3305 +extern struct inode_operations page_symlink_inode_operations;
3307 +extern int vfs_readdir(struct file *, filldir_t, void *);
3308 +extern int dcache_dir_open(struct inode *, struct file *);
3309 +extern int dcache_dir_close(struct inode *, struct file *);
3310 +extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
3311 +extern int dcache_dir_fsync(struct file *, struct dentry *, int);
3312 +extern int dcache_readdir(struct file *, void *, filldir_t);
3313 +extern struct file_operations dcache_dir_ops;
3315 +extern struct file_system_type *get_fs_type(const char *name);
3316 +extern struct super_block *get_super(kdev_t);
3317 +extern void drop_super(struct super_block *sb);
3318 +static inline int is_mounted(kdev_t dev)
3320 + struct super_block *sb = get_super(dev);
3327 +unsigned long generate_cluster(kdev_t, int b[], int);
3328 +unsigned long generate_cluster_swab32(kdev_t, int b[], int);
3329 +extern kdev_t ROOT_DEV;
3330 +extern char root_device_name[];
3333 +extern void show_buffers(void);
3335 +#ifdef CONFIG_BLK_DEV_INITRD
3336 +extern unsigned int real_root_dev;
3339 +extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
3340 +extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
3341 +extern int read_ahead[];
3343 +extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
3344 +extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
3346 +extern int file_fsync(struct file *, struct dentry *, int);
3347 +extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
3348 +extern int generic_osync_inode(struct inode *, int);
3349 +#define OSYNC_METADATA (1<<0)
3350 +#define OSYNC_DATA (1<<1)
3351 +#define OSYNC_INODE (1<<2)
3353 +extern int inode_change_ok(struct inode *, struct iattr *);
3354 +extern int inode_setattr(struct inode *, struct iattr *);
3357 + * Common dentry functions for inclusion in the VFS
3358 + * or in other stackable file systems. Some of these
3359 + * functions were in linux/fs/ C (VFS) files.
3364 + * Locking the parent is needed to:
3365 + * - serialize directory operations
3366 + * - make sure the parent doesn't change from
3367 + * under us in the middle of an operation.
3369 + * NOTE! Right now we'd rather use a "struct inode"
3370 + * for this, but as I expect things to move toward
3371 + * using dentries instead for most things it is
3372 + * probably better to start with the conceptually
3373 + * better interface of relying on a path of dentries.
3375 +static inline struct dentry *lock_parent(struct dentry *dentry)
3377 + struct dentry *dir = dget(dentry->d_parent);
3379 + down(&dir->d_inode->i_sem);
3383 +static inline struct dentry *get_parent(struct dentry *dentry)
3385 + return dget(dentry->d_parent);
3388 +static inline void unlock_dir(struct dentry *dir)
3390 + up(&dir->d_inode->i_sem);
3395 + * Whee.. Deadlock country. Happily there are only two VFS
3396 + * operations that does this..
3398 +static inline void double_down(struct semaphore *s1, struct semaphore *s2)
3401 + if ((unsigned long) s1 < (unsigned long) s2) {
3402 + struct semaphore *tmp = s2;
3403 + s2 = s1; s1 = tmp;
3411 + * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
3412 + * not equal to 1st and not equal to 2nd - the first case (target is parent of
3413 + * source) would be already caught, the second is plain impossible (target is
3414 + * its own parent and that case would be caught even earlier). Very messy.
3415 + * I _think_ that it works, but no warranties - please, look it through.
3416 + * Pox on bloody lusers who mandated overwriting rename() for directories...
3419 +static inline void triple_down(struct semaphore *s1,
3420 + struct semaphore *s2,
3421 + struct semaphore *s3)
3424 + if ((unsigned long) s1 < (unsigned long) s2) {
3425 + if ((unsigned long) s1 < (unsigned long) s3) {
3426 + struct semaphore *tmp = s3;
3427 + s3 = s1; s1 = tmp;
3429 + if ((unsigned long) s1 < (unsigned long) s2) {
3430 + struct semaphore *tmp = s2;
3431 + s2 = s1; s1 = tmp;
3434 + if ((unsigned long) s1 < (unsigned long) s3) {
3435 + struct semaphore *tmp = s3;
3436 + s3 = s1; s1 = tmp;
3438 + if ((unsigned long) s2 < (unsigned long) s3) {
3439 + struct semaphore *tmp = s3;
3440 + s3 = s2; s2 = tmp;
3444 + } else if ((unsigned long) s2 < (unsigned long) s3) {
3445 + struct semaphore *tmp = s3;
3446 + s3 = s2; s2 = tmp;
3452 +static inline void double_up(struct semaphore *s1, struct semaphore *s2)
3459 +static inline void triple_up(struct semaphore *s1,
3460 + struct semaphore *s2,
3461 + struct semaphore *s3)
3469 +static inline void double_lock(struct dentry *d1, struct dentry *d2)
3471 + double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
3474 +static inline void double_unlock(struct dentry *d1, struct dentry *d2)
3476 + double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
3481 +#endif /* __KERNEL__ */
3483 +#endif /* _LINUX_FS_H */
3484 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs.h src/linux/linux/include/linux/squashfs_fs.h
3485 --- src/linux/linux.orig/include/linux/squashfs_fs.h 1969-12-31 19:00:00.000000000 -0500
3486 +++ src/linux/linux/include/linux/squashfs_fs.h 2004-05-25 21:13:03.000000000 -0400
3488 +#ifndef SQUASHFS_FS
3489 +#define SQUASHFS_FS
3493 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
3495 + * This program is free software; you can redistribute it and/or
3496 + * modify it under the terms of the GNU General Public License
3497 + * as published by the Free Software Foundation; either version 2,
3498 + * or (at your option) any later version.
3500 + * This program is distributed in the hope that it will be useful,
3501 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3502 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3503 + * GNU General Public License for more details.
3505 + * You should have received a copy of the GNU General Public License
3506 + * along with this program; if not, write to the Free Software
3507 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3512 +#define SQUASHFS_MAJOR 2
3513 +#define SQUASHFS_MINOR 0
3514 +#define SQUASHFS_MAGIC 0x73717368
3515 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3516 +#define SQUASHFS_START 0
3518 +/* size of metadata (inode and directory) blocks */
3519 +#define SQUASHFS_METADATA_SIZE 8192
3520 +#define SQUASHFS_METADATA_LOG 13
3522 +/* default size of data blocks */
3523 +#define SQUASHFS_FILE_SIZE 65536
3524 +#define SQUASHFS_FILE_LOG 16
3526 +#define SQUASHFS_FILE_MAX_SIZE 65536
3528 +/* Max number of uids and gids */
3529 +#define SQUASHFS_UIDS 256
3530 +#define SQUASHFS_GUIDS 255
3532 +/* Max length of filename (not 255) */
3533 +#define SQUASHFS_NAME_LEN 256
3535 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3536 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
3537 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
3539 +/* Filesystem flags */
3540 +#define SQUASHFS_NOI 0
3541 +#define SQUASHFS_NOD 1
3542 +#define SQUASHFS_CHECK 2
3543 +#define SQUASHFS_NOF 3
3544 +#define SQUASHFS_NO_FRAG 4
3545 +#define SQUASHFS_ALWAYS_FRAG 5
3546 +#define SQUASHFS_DUPLICATE 6
3547 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3548 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
3549 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
3550 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
3551 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
3552 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
3553 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
3554 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
3555 +#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))
3557 +/* Max number of types and file types */
3558 +#define SQUASHFS_DIR_TYPE 1
3559 +#define SQUASHFS_FILE_TYPE 2
3560 +#define SQUASHFS_SYMLINK_TYPE 3
3561 +#define SQUASHFS_BLKDEV_TYPE 4
3562 +#define SQUASHFS_CHRDEV_TYPE 5
3563 +#define SQUASHFS_FIFO_TYPE 6
3564 +#define SQUASHFS_SOCKET_TYPE 7
3566 +/* 1.0 filesystem type definitions */
3567 +#define SQUASHFS_TYPES 5
3568 +#define SQUASHFS_IPC_TYPE 0
3570 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
3571 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3572 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3573 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3575 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3577 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3578 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
3579 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3581 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3584 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
3585 + * offset within that block
3587 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3588 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3589 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
3592 +/* Compute 32 bit VFS inode number from squashfs inode number */
3593 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
3595 +/* Translate between VFS mode and squashfs mode */
3596 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3598 +/* fragment and fragment table defines */
3599 +typedef unsigned int squashfs_fragment_index;
3600 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
3601 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
3602 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
3603 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
3604 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
3605 +#define SQUASHFS_CACHED_FRAGMENTS 3
3607 +/* cached data constants for filesystem */
3608 +#define SQUASHFS_CACHED_BLKS 8
3610 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
3611 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
3613 +#define SQUASHFS_MARKER_BYTE 0xff
3616 + * definitions for structures on disk
3619 +typedef unsigned int squashfs_block;
3620 +typedef long long squashfs_inode;
3622 +typedef unsigned int squashfs_uid;
3624 +typedef struct squashfs_super_block {
3625 + unsigned int s_magic;
3626 + unsigned int inodes;
3627 + unsigned int bytes_used;
3628 + unsigned int uid_start;
3629 + unsigned int guid_start;
3630 + unsigned int inode_table_start;
3631 + unsigned int directory_table_start;
3632 + unsigned int s_major:16;
3633 + unsigned int s_minor:16;
3634 + unsigned int block_size_1:16;
3635 + unsigned int block_log:16;
3636 + unsigned int flags:8;
3637 + unsigned int no_uids:8;
3638 + unsigned int no_guids:8;
3639 + time_t mkfs_time /* time of filesystem creation */;
3640 + squashfs_inode root_inode;
3641 + unsigned int block_size;
3642 + unsigned int fragments;
3643 + unsigned int fragment_table_start;
3644 +} __attribute__ ((packed)) squashfs_super_block;
3647 + unsigned int inode_type:4;
3648 + unsigned int mode:12; /* protection */
3649 + unsigned int uid:8; /* index into uid table */
3650 + unsigned int guid:8; /* index into guid table */
3651 +} __attribute__ ((packed)) squashfs_base_inode_header;
3653 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
3656 + unsigned int inode_type:4;
3657 + unsigned int mode:12; /* protection */
3658 + unsigned int uid:8; /* index into uid table */
3659 + unsigned int guid:8; /* index into guid table */
3660 + unsigned short rdev;
3661 +} __attribute__ ((packed)) squashfs_dev_inode_header;
3664 + unsigned int inode_type:4;
3665 + unsigned int mode:12; /* protection */
3666 + unsigned int uid:8; /* index into uid table */
3667 + unsigned int guid:8; /* index into guid table */
3668 + unsigned short symlink_size;
3670 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
3673 + unsigned int inode_type:4;
3674 + unsigned int mode:12; /* protection */
3675 + unsigned int uid:8; /* index into uid table */
3676 + unsigned int guid:8; /* index into guid table */
3678 + squashfs_block start_block;
3679 + unsigned int fragment;
3680 + unsigned int offset;
3681 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
3682 + unsigned short block_list[0];
3683 +} __attribute__ ((packed)) squashfs_reg_inode_header;
3686 + unsigned int inode_type:4;
3687 + unsigned int mode:12; /* protection */
3688 + unsigned int uid:8; /* index into uid table */
3689 + unsigned int guid:8; /* index into guid table */
3690 + unsigned int file_size:19;
3691 + unsigned int offset:13;
3693 + unsigned int start_block:24;
3694 +} __attribute__ ((packed)) squashfs_dir_inode_header;
3697 + squashfs_base_inode_header base;
3698 + squashfs_dev_inode_header dev;
3699 + squashfs_symlink_inode_header symlink;
3700 + squashfs_reg_inode_header reg;
3701 + squashfs_dir_inode_header dir;
3702 + squashfs_ipc_inode_header ipc;
3703 +} squashfs_inode_header;
3706 + unsigned int offset:13;
3707 + unsigned int type:3;
3708 + unsigned int size:8;
3710 +} __attribute__ ((packed)) squashfs_dir_entry;
3713 + unsigned int count:8;
3714 + unsigned int start_block:24;
3715 +} __attribute__ ((packed)) squashfs_dir_header;
3719 + unsigned int start_block;
3720 + unsigned int size;
3721 +} __attribute__ ((packed)) squashfs_fragment_entry;
3723 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3724 +extern int squashfs_uncompress_init(void);
3725 +extern int squashfs_uncompress_exit(void);
3728 + * macros to convert each packed bitfield structure from little endian to big
3729 + * endian and vice versa. These are needed when creating or using a filesystem on a
3730 + * machine with different byte ordering to the target architecture.
3734 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3735 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
3736 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3737 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3738 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
3739 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
3740 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
3741 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
3742 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
3743 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3744 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3745 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3746 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3747 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3748 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3749 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3750 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3751 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3752 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3753 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3754 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
3757 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3758 + SQUASHFS_MEMSET(s, d, n);\
3759 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3760 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3761 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3762 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3765 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
3767 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3768 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
3769 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3772 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3773 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
3774 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3777 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3778 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
3779 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3780 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3781 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3782 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3783 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
3786 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3787 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
3788 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3789 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3790 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3791 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3794 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3795 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
3796 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3797 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3800 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3801 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
3802 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3803 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3804 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3807 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3808 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
3809 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3810 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3813 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3815 + int bit_position;\
3816 + SQUASHFS_MEMSET(s, d, n * 2);\
3817 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
3818 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3821 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3823 + int bit_position;\
3824 + SQUASHFS_MEMSET(s, d, n * 4);\
3825 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
3826 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3829 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3831 + int bit_position;\
3832 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3833 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
3834 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3837 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3839 +#ifdef SQUASHFS_1_0_COMPATIBILITY
3841 + unsigned int inode_type:4;
3842 + unsigned int mode:12; /* protection */
3843 + unsigned int uid:4; /* index into uid table */
3844 + unsigned int guid:4; /* index into guid table */
3845 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
3848 + unsigned int inode_type:4;
3849 + unsigned int mode:12; /* protection */
3850 + unsigned int uid:4; /* index into uid table */
3851 + unsigned int guid:4; /* index into guid table */
3852 + unsigned int type:4;
3853 + unsigned int offset:4;
3854 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
3857 + unsigned int inode_type:4;
3858 + unsigned int mode:12; /* protection */
3859 + unsigned int uid:4; /* index into uid table */
3860 + unsigned int guid:4; /* index into guid table */
3861 + unsigned short rdev;
3862 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
3865 + unsigned int inode_type:4;
3866 + unsigned int mode:12; /* protection */
3867 + unsigned int uid:4; /* index into uid table */
3868 + unsigned int guid:4; /* index into guid table */
3869 + unsigned short symlink_size;
3871 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
3874 + unsigned int inode_type:4;
3875 + unsigned int mode:12; /* protection */
3876 + unsigned int uid:4; /* index into uid table */
3877 + unsigned int guid:4; /* index into guid table */
3879 + squashfs_block start_block;
3880 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
3881 + unsigned short block_list[0];
3882 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
3885 + unsigned int inode_type:4;
3886 + unsigned int mode:12; /* protection */
3887 + unsigned int uid:4; /* index into uid table */
3888 + unsigned int guid:4; /* index into guid table */
3889 + unsigned int file_size:19;
3890 + unsigned int offset:13;
3892 + unsigned int start_block:24;
3893 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
3895 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3896 + SQUASHFS_MEMSET(s, d, n);\
3897 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3898 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3899 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3900 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
3903 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3904 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
3905 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3906 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3909 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3910 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
3911 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3914 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3915 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
3916 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3919 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3920 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
3921 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3922 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3923 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
3926 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3927 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
3928 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3929 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3930 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3931 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3937 + * macros used to swap each structure entry, taking into account
3938 + * bitfields and different bitfield placing conventions on differing architectures
3940 +#include <asm/byteorder.h>
3941 +#ifdef __BIG_ENDIAN
3942 + /* convert from little endian to big endian */
3943 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
3945 + /* convert from big endian to little endian */
3946 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
3949 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3951 + int b_pos = pos % 8;\
3952 + unsigned long long val = 0;\
3953 + unsigned char *s = (unsigned char *)p + (pos / 8);\
3954 + unsigned char *d = ((unsigned char *) &val) + 7;\
3955 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3957 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3959 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3962 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_i.h src/linux/linux/include/linux/squashfs_fs_i.h
3963 --- src/linux/linux.orig/include/linux/squashfs_fs_i.h 1969-12-31 19:00:00.000000000 -0500
3964 +++ src/linux/linux/include/linux/squashfs_fs_i.h 2004-05-25 21:13:03.000000000 -0400
3966 +#ifndef SQUASHFS_FS_I
3967 +#define SQUASHFS_FS_I
3971 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
3973 + * This program is free software; you can redistribute it and/or
3974 + * modify it under the terms of the GNU General Public License
3975 + * as published by the Free Software Foundation; either version 2,
3976 + * or (at your option) any later version.
3978 + * This program is distributed in the hope that it will be useful,
3979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3981 + * GNU General Public License for more details.
3983 + * You should have received a copy of the GNU General Public License
3984 + * along with this program; if not, write to the Free Software
3985 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3990 +typedef struct squashfs_inode_info {
3991 + unsigned int start_block;
3992 + unsigned int block_list_start;
3993 + unsigned int offset;
3994 + unsigned int fragment_start_block;
3995 + unsigned int fragment_size;
3996 + unsigned int fragment_offset;
3997 + } squashfs_inode_info;
3999 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_sb.h src/linux/linux/include/linux/squashfs_fs_sb.h
4000 --- src/linux/linux.orig/include/linux/squashfs_fs_sb.h 1969-12-31 19:00:00.000000000 -0500
4001 +++ src/linux/linux/include/linux/squashfs_fs_sb.h 2004-05-25 21:13:03.000000000 -0400
4003 +#ifndef SQUASHFS_FS_SB
4004 +#define SQUASHFS_FS_SB
4008 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
4010 + * This program is free software; you can redistribute it and/or
4011 + * modify it under the terms of the GNU General Public License
4012 + * as published by the Free Software Foundation; either version 2,
4013 + * or (at your option) any later version.
4015 + * This program is distributed in the hope that it will be useful,
4016 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4017 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4018 + * GNU General Public License for more details.
4020 + * You should have received a copy of the GNU General Public License
4021 + * along with this program; if not, write to the Free Software
4022 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4024 + * squashfs_fs_sb.h
4027 +#include <linux/squashfs_fs.h>
4030 + unsigned int block;
4032 + unsigned int next_index;
4036 +struct squashfs_fragment_cache {
4037 + unsigned int block;
4039 + unsigned int locked;
4043 +typedef struct squashfs_sb_info {
4044 + squashfs_super_block sBlk;
4046 + int devblksize_log2;
4048 + squashfs_cache *block_cache;
4049 + struct squashfs_fragment_cache *fragment;
4051 + int next_fragment;
4052 + squashfs_uid *uid;
4053 + squashfs_uid *guid;
4054 + squashfs_fragment_index *fragment_index;
4055 + unsigned int read_size;
4058 + struct semaphore read_page_mutex;
4059 + struct semaphore block_cache_mutex;
4060 + struct semaphore fragment_mutex;
4061 + wait_queue_head_t waitq;
4062 + wait_queue_head_t fragment_wait_queue;
4063 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
4064 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
4065 + char *block_list, char **block_p, unsigned int *bsize);
4066 + } squashfs_sb_info;
4068 diff -Nurb src/linux/linux.orig/init/do_mounts.c src/linux/linux/init/do_mounts.c
4069 --- src/linux/linux.orig/init/do_mounts.c 2003-11-08 03:13:20.000000000 -0500
4070 +++ src/linux/linux/init/do_mounts.c 2004-05-25 21:13:03.000000000 -0400
4072 #include <linux/ext2_fs.h>
4073 #include <linux/romfs_fs.h>
4074 #include <linux/cramfs_fs.h>
4075 +#include <linux/squashfs_fs.h>
4077 #undef BUILD_CRAMDISK
4086 identify_ramdisk_image(int fd, int start_block)
4088 struct ext2_super_block *ext2sb;
4089 struct romfs_super_block *romfsb;
4090 struct cramfs_super *cramfsb;
4091 + struct squashfs_super_block *squashfsb;
4096 ext2sb = (struct ext2_super_block *) buf;
4097 romfsb = (struct romfs_super_block *) buf;
4098 cramfsb = (struct cramfs_super *) buf;
4099 + squashfsb = (struct squashfs_super_block *) buf;
4100 memset(buf, 0xe5, size);
4103 @@ -536,6 +540,15 @@
4107 + /* squashfs is at block zero too */
4108 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4109 + printk(KERN_NOTICE
4110 + "RAMDISK: squashfs filesystem found at block %d\n",
4112 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4117 * Read block 1 to test for minix and ext2 superblock
4119 diff -Nurb src/linux/linux.orig/init/do_mounts.c.orig src/linux/linux/init/do_mounts.c.orig
4120 --- src/linux/linux.orig/init/do_mounts.c.orig 1969-12-31 19:00:00.000000000 -0500
4121 +++ src/linux/linux/init/do_mounts.c.orig 2004-05-25 21:12:42.000000000 -0400
4123 +#define __KERNEL_SYSCALLS__
4124 +#include <linux/config.h>
4125 +#include <linux/slab.h>
4126 +#include <linux/devfs_fs_kernel.h>
4127 +#include <linux/unistd.h>
4128 +#include <linux/ctype.h>
4129 +#include <linux/blk.h>
4130 +#include <linux/fd.h>
4131 +#include <linux/tty.h>
4132 +#include <linux/init.h>
4134 +#include <linux/nfs_fs.h>
4135 +#include <linux/nfs_fs_sb.h>
4136 +#include <linux/nfs_mount.h>
4137 +#include <linux/minix_fs.h>
4138 +#include <linux/ext2_fs.h>
4139 +#include <linux/romfs_fs.h>
4140 +#include <linux/cramfs_fs.h>
4141 +#include <linux/squashfs_fs.h>
4143 +#undef BUILD_CRAMDISK
4145 +extern int get_filesystem_list(char * buf);
4147 +extern asmlinkage long sys_mount(char *dev_name, char *dir_name, char *type,
4148 + unsigned long flags, void *data);
4149 +extern asmlinkage long sys_mkdir(const char *name, int mode);
4150 +extern asmlinkage long sys_chdir(const char *name);
4151 +extern asmlinkage long sys_fchdir(int fd);
4152 +extern asmlinkage long sys_chroot(const char *name);
4153 +extern asmlinkage long sys_unlink(const char *name);
4154 +extern asmlinkage long sys_symlink(const char *old, const char *new);
4155 +extern asmlinkage long sys_mknod(const char *name, int mode, dev_t dev);
4156 +extern asmlinkage long sys_umount(char *name, int flags);
4157 +extern asmlinkage long sys_ioctl(int fd, int cmd, unsigned long arg);
4159 +#ifdef CONFIG_BLK_DEV_INITRD
4160 +unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */
4161 +static int __initdata mount_initrd = 1;
4163 +static int __init no_initrd(char *str)
4169 +__setup("noinitrd", no_initrd);
4171 +static int __initdata mount_initrd = 0;
4174 +int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
4176 +int root_mountflags = MS_RDONLY | MS_VERBOSE;
4177 +static char root_device_name[64];
4179 +/* this is initialized in init/main.c */
4182 +static int do_devfs = 0;
4184 +static int __init load_ramdisk(char *str)
4186 + rd_doload = simple_strtol(str,NULL,0) & 3;
4189 +__setup("load_ramdisk=", load_ramdisk);
4191 +static int __init readonly(char *str)
4195 + root_mountflags |= MS_RDONLY;
4199 +static int __init readwrite(char *str)
4203 + root_mountflags &= ~MS_RDONLY;
4207 +__setup("ro", readonly);
4208 +__setup("rw", readwrite);
4210 +static struct dev_name_struct {
4213 +} root_dev_names[] __initdata = {
4214 + { "nfs", 0x00ff },
4215 + { "hda", 0x0300 },
4216 + { "hdb", 0x0340 },
4217 + { "loop", 0x0700 },
4218 + { "hdc", 0x1600 },
4219 + { "hdd", 0x1640 },
4220 + { "hde", 0x2100 },
4221 + { "hdf", 0x2140 },
4222 + { "hdg", 0x2200 },
4223 + { "hdh", 0x2240 },
4224 + { "hdi", 0x3800 },
4225 + { "hdj", 0x3840 },
4226 + { "hdk", 0x3900 },
4227 + { "hdl", 0x3940 },
4228 + { "hdm", 0x5800 },
4229 + { "hdn", 0x5840 },
4230 + { "hdo", 0x5900 },
4231 + { "hdp", 0x5940 },
4232 + { "hdq", 0x5A00 },
4233 + { "hdr", 0x5A40 },
4234 + { "hds", 0x5B00 },
4235 + { "hdt", 0x5B40 },
4236 + { "sda", 0x0800 },
4237 + { "sdb", 0x0810 },
4238 + { "sdc", 0x0820 },
4239 + { "sdd", 0x0830 },
4240 + { "sde", 0x0840 },
4241 + { "sdf", 0x0850 },
4242 + { "sdg", 0x0860 },
4243 + { "sdh", 0x0870 },
4244 + { "sdi", 0x0880 },
4245 + { "sdj", 0x0890 },
4246 + { "sdk", 0x08a0 },
4247 + { "sdl", 0x08b0 },
4248 + { "sdm", 0x08c0 },
4249 + { "sdn", 0x08d0 },
4250 + { "sdo", 0x08e0 },
4251 + { "sdp", 0x08f0 },
4252 + { "ada", 0x1c00 },
4253 + { "adb", 0x1c10 },
4254 + { "adc", 0x1c20 },
4255 + { "add", 0x1c30 },
4256 + { "ade", 0x1c40 },
4259 + { "xda", 0x0d00 },
4260 + { "xdb", 0x0d40 },
4261 + { "ram", 0x0100 },
4262 + { "scd", 0x0b00 },
4263 + { "mcd", 0x1700 },
4264 + { "cdu535", 0x1800 },
4265 + { "sonycd", 0x1800 },
4266 + { "aztcd", 0x1d00 },
4267 + { "cm206cd", 0x2000 },
4268 + { "gscd", 0x1000 },
4269 + { "sbpcd", 0x1900 },
4270 + { "eda", 0x2400 },
4271 + { "edb", 0x2440 },
4272 + { "pda", 0x2d00 },
4273 + { "pdb", 0x2d10 },
4274 + { "pdc", 0x2d20 },
4275 + { "pdd", 0x2d30 },
4276 + { "pcd", 0x2e00 },
4278 + { "apblock", APBLOCK_MAJOR << 8},
4279 + { "ddv", DDV_MAJOR << 8},
4280 + { "jsfd", JSFD_MAJOR << 8},
4281 +#if defined(CONFIG_ARCH_S390)
4282 + { "dasda", (DASD_MAJOR << MINORBITS) },
4283 + { "dasdb", (DASD_MAJOR << MINORBITS) + (1 << 2) },
4284 + { "dasdc", (DASD_MAJOR << MINORBITS) + (2 << 2) },
4285 + { "dasdd", (DASD_MAJOR << MINORBITS) + (3 << 2) },
4286 + { "dasde", (DASD_MAJOR << MINORBITS) + (4 << 2) },
4287 + { "dasdf", (DASD_MAJOR << MINORBITS) + (5 << 2) },
4288 + { "dasdg", (DASD_MAJOR << MINORBITS) + (6 << 2) },
4289 + { "dasdh", (DASD_MAJOR << MINORBITS) + (7 << 2) },
4291 +#if defined(CONFIG_BLK_CPQ_DA) || defined(CONFIG_BLK_CPQ_DA_MODULE)
4292 + { "ida/c0d0p",0x4800 },
4293 + { "ida/c0d1p",0x4810 },
4294 + { "ida/c0d2p",0x4820 },
4295 + { "ida/c0d3p",0x4830 },
4296 + { "ida/c0d4p",0x4840 },
4297 + { "ida/c0d5p",0x4850 },
4298 + { "ida/c0d6p",0x4860 },
4299 + { "ida/c0d7p",0x4870 },
4300 + { "ida/c0d8p",0x4880 },
4301 + { "ida/c0d9p",0x4890 },
4302 + { "ida/c0d10p",0x48A0 },
4303 + { "ida/c0d11p",0x48B0 },
4304 + { "ida/c0d12p",0x48C0 },
4305 + { "ida/c0d13p",0x48D0 },
4306 + { "ida/c0d14p",0x48E0 },
4307 + { "ida/c0d15p",0x48F0 },
4308 + { "ida/c1d0p",0x4900 },
4309 + { "ida/c2d0p",0x4A00 },
4310 + { "ida/c3d0p",0x4B00 },
4311 + { "ida/c4d0p",0x4C00 },
4312 + { "ida/c5d0p",0x4D00 },
4313 + { "ida/c6d0p",0x4E00 },
4314 + { "ida/c7d0p",0x4F00 },
4316 +#if defined(CONFIG_BLK_CPQ_CISS_DA) || defined(CONFIG_BLK_CPQ_CISS_DA_MODULE)
4317 + { "cciss/c0d0p",0x6800 },
4318 + { "cciss/c0d1p",0x6810 },
4319 + { "cciss/c0d2p",0x6820 },
4320 + { "cciss/c0d3p",0x6830 },
4321 + { "cciss/c0d4p",0x6840 },
4322 + { "cciss/c0d5p",0x6850 },
4323 + { "cciss/c0d6p",0x6860 },
4324 + { "cciss/c0d7p",0x6870 },
4325 + { "cciss/c0d8p",0x6880 },
4326 + { "cciss/c0d9p",0x6890 },
4327 + { "cciss/c0d10p",0x68A0 },
4328 + { "cciss/c0d11p",0x68B0 },
4329 + { "cciss/c0d12p",0x68C0 },
4330 + { "cciss/c0d13p",0x68D0 },
4331 + { "cciss/c0d14p",0x68E0 },
4332 + { "cciss/c0d15p",0x68F0 },
4333 + { "cciss/c1d0p",0x6900 },
4334 + { "cciss/c2d0p",0x6A00 },
4335 + { "cciss/c3d0p",0x6B00 },
4336 + { "cciss/c4d0p",0x6C00 },
4337 + { "cciss/c5d0p",0x6D00 },
4338 + { "cciss/c6d0p",0x6E00 },
4339 + { "cciss/c7d0p",0x6F00 },
4341 + { "ataraid/d0p",0x7200 },
4342 + { "ataraid/d1p",0x7210 },
4343 + { "ataraid/d2p",0x7220 },
4344 + { "ataraid/d3p",0x7230 },
4345 + { "ataraid/d4p",0x7240 },
4346 + { "ataraid/d5p",0x7250 },
4347 + { "ataraid/d6p",0x7260 },
4348 + { "ataraid/d7p",0x7270 },
4349 + { "ataraid/d8p",0x7280 },
4350 + { "ataraid/d9p",0x7290 },
4351 + { "ataraid/d10p",0x72A0 },
4352 + { "ataraid/d11p",0x72B0 },
4353 + { "ataraid/d12p",0x72C0 },
4354 + { "ataraid/d13p",0x72D0 },
4355 + { "ataraid/d14p",0x72E0 },
4356 + { "ataraid/d15p",0x72F0 },
4357 + { "nftla", 0x5d00 },
4358 + { "nftlb", 0x5d10 },
4359 + { "nftlc", 0x5d20 },
4360 + { "nftld", 0x5d30 },
4361 + { "ftla", 0x2c00 },
4362 + { "ftlb", 0x2c08 },
4363 + { "ftlc", 0x2c10 },
4364 + { "ftld", 0x2c18 },
4365 +#if defined(CONFIG_MTD_BLOCK) || defined(CONFIG_MTD_BLOCK_RO)
4366 + { "mtdblock", 0x1f00 },
4367 + { "mtdblock0",0x1f00 },
4368 + { "mtdblock1",0x1f01 },
4369 + { "mtdblock2",0x1f02 },
4370 + { "mtdblock3",0x1f03 },
4372 +#ifdef CONFIG_BLK_DEV_DUMMY
4373 + { "dummy",0x2000 },
4378 +kdev_t __init name_to_kdev_t(char *line)
4380 + int base = 0, offs;
4383 + if (strncmp(line,"/dev/",5) == 0) {
4384 + struct dev_name_struct *dev = root_dev_names;
4387 + int len = strlen(dev->name);
4388 + if (strncmp(line,dev->name,len) == 0) {
4394 + } while (dev->name);
4396 + offs = simple_strtoul(line, &end, base?10:16);
4399 + return to_kdev_t(base + offs);
4402 +static int __init root_dev_setup(char *line)
4407 + ROOT_DEV = name_to_kdev_t(line);
4408 + memset (root_device_name, 0, sizeof root_device_name);
4409 + if (strncmp (line, "/dev/", 5) == 0) line += 5;
4410 + for (i = 0; i < sizeof root_device_name - 1; ++i)
4413 + if ( isspace (ch) || (ch == ',') || (ch == '\0') ) break;
4414 + root_device_name[i] = ch;
4419 +__setup("root=", root_dev_setup);
4421 +static char * __initdata root_mount_data;
4422 +static int __init root_data_setup(char *str)
4424 + root_mount_data = str;
4428 +static char * __initdata root_fs_names;
4429 +static int __init fs_names_setup(char *str)
4431 + root_fs_names = str;
4435 +__setup("rootflags=", root_data_setup);
4436 +__setup("rootfstype=", fs_names_setup);
4438 +static void __init get_fs_names(char *page)
4442 + if (root_fs_names) {
4443 + strcpy(page, root_fs_names);
4449 + int len = get_filesystem_list(page);
4453 + for (p = page-1; p; p = next) {
4454 + next = strchr(++p, '\n');
4457 + while ((*s++ = *p++) != '\n')
4464 +static void __init mount_block_root(char *name, int flags)
4466 + char *fs_names = __getname();
4469 + get_fs_names(fs_names);
4471 + for (p = fs_names; *p; p += strlen(p)+1) {
4472 + int err = sys_mount(name, "/root", p, flags, root_mount_data);
4477 + flags |= MS_RDONLY;
4483 + * Allow the user to distinguish between failed open
4484 + * and bad superblock on root device.
4486 + printk ("VFS: Cannot open root device \"%s\" or %s\n",
4487 + root_device_name, kdevname (ROOT_DEV));
4488 + printk ("Please append a correct \"root=\" boot option\n");
4489 + panic("VFS: Unable to mount root fs on %s",
4490 + kdevname(ROOT_DEV));
4492 + panic("VFS: Unable to mount root fs on %s", kdevname(ROOT_DEV));
4494 + putname(fs_names);
4495 + sys_chdir("/root");
4496 + ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
4497 + printk("VFS: Mounted root (%s filesystem)%s.\n",
4498 + current->fs->pwdmnt->mnt_sb->s_type->name,
4499 + (current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY) ? " readonly" : "");
4502 +#ifdef CONFIG_ROOT_NFS
4503 +static int __init mount_nfs_root(void)
4505 + void *data = nfs_root_data();
4507 + if (data && sys_mount("/dev/root","/root","nfs",root_mountflags,data) == 0)
4513 +static int __init create_dev(char *name, kdev_t dev, char *devfs_name)
4521 + return sys_mknod(name, S_IFBLK|0600, kdev_t_to_nr(dev));
4523 + handle = devfs_find_handle(NULL, dev ? NULL : devfs_name,
4524 + MAJOR(dev), MINOR(dev), DEVFS_SPECIAL_BLK, 1);
4527 + n = devfs_generate_path(handle, path + 5, sizeof (path) - 5);
4530 + return sys_symlink(path + n + 5, name);
4533 +#if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
4534 +static void __init change_floppy(char *fmt, ...)
4536 + struct termios termios;
4541 + va_start(args, fmt);
4542 + vsprintf(buf, fmt, args);
4544 + fd = open("/dev/root", O_RDWR | O_NDELAY, 0);
4546 + sys_ioctl(fd, FDEJECT, 0);
4549 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
4550 + fd = open("/dev/console", O_RDWR, 0);
4552 + sys_ioctl(fd, TCGETS, (long)&termios);
4553 + termios.c_lflag &= ~ICANON;
4554 + sys_ioctl(fd, TCSETSF, (long)&termios);
4556 + termios.c_lflag |= ICANON;
4557 + sys_ioctl(fd, TCSETSF, (long)&termios);
4563 +#ifdef CONFIG_BLK_DEV_RAM
4565 +int __initdata rd_prompt = 1; /* 1 = prompt for RAM disk, 0 = don't prompt */
4567 +static int __init prompt_ramdisk(char *str)
4569 + rd_prompt = simple_strtol(str,NULL,0) & 1;
4572 +__setup("prompt_ramdisk=", prompt_ramdisk);
4574 +int __initdata rd_image_start; /* starting block # of image */
4576 +static int __init ramdisk_start_setup(char *str)
4578 + rd_image_start = simple_strtol(str,NULL,0);
4581 +__setup("ramdisk_start=", ramdisk_start_setup);
4583 +static int __init crd_load(int in_fd, int out_fd);
4586 + * This routine tries to find a RAM disk image to load, and returns the
4587 + * number of blocks to read for a non-compressed image, 0 if the image
4588 + * is a compressed image, and -1 if an image with the right magic
4589 + * numbers could not be found.
4591 + * We currently check for the following magic numbers:
4598 +identify_ramdisk_image(int fd, int start_block)
4600 + const int size = 512;
4601 + struct minix_super_block *minixsb;
4602 + struct ext2_super_block *ext2sb;
4603 + struct romfs_super_block *romfsb;
4604 + struct cramfs_super *cramfsb;
4605 + struct squashfs_super_block *squashfsb;
4607 + unsigned char *buf;
4609 + buf = kmalloc(size, GFP_KERNEL);
4613 + minixsb = (struct minix_super_block *) buf;
4614 + ext2sb = (struct ext2_super_block *) buf;
4615 + romfsb = (struct romfs_super_block *) buf;
4616 + cramfsb = (struct cramfs_super *) buf;
4617 + squashfsb = (struct squashfs_super_block *) buf;
4618 + memset(buf, 0xe5, size);
4621 + * Read block 0 to test for gzipped kernel
4623 + lseek(fd, start_block * BLOCK_SIZE, 0);
4624 + read(fd, buf, size);
4627 + * If it matches the gzip magic numbers, return -1
4629 + if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) {
4630 + printk(KERN_NOTICE
4631 + "RAMDISK: Compressed image found at block %d\n",
4637 +#ifdef CONFIG_BLK_DEV_INITRD
4639 + * Fallback if size cannot be determined by superblock
4641 + nblocks = (initrd_end-initrd_start+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4644 + /* romfs is at block zero too */
4645 + if (romfsb->word0 == ROMSB_WORD0 &&
4646 + romfsb->word1 == ROMSB_WORD1) {
4647 + printk(KERN_NOTICE
4648 + "RAMDISK: romfs filesystem found at block %d\n",
4650 + nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4654 + /* so is cramfs */
4655 + if (cramfsb->magic == CRAMFS_MAGIC) {
4656 + printk(KERN_NOTICE
4657 + "RAMDISK: cramfs filesystem found at block %d\n",
4659 + if (cramfsb->flags & CRAMFS_FLAG_FSID_VERSION_2)
4660 + nblocks = (cramfsb->size+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4665 + * Read block 1 to test for minix and ext2 superblock
4667 + lseek(fd, (start_block+1) * BLOCK_SIZE, 0);
4668 + read(fd, buf, size);
4671 + if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
4672 + minixsb->s_magic == MINIX_SUPER_MAGIC2) {
4673 + printk(KERN_NOTICE
4674 + "RAMDISK: Minix filesystem found at block %d\n",
4676 + nblocks = minixsb->s_nzones << minixsb->s_log_zone_size;
4681 + if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
4682 + printk(KERN_NOTICE
4683 + "RAMDISK: ext2 filesystem found at block %d\n",
4685 + nblocks = le32_to_cpu(ext2sb->s_blocks_count);
4689 + printk(KERN_NOTICE
4690 + "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
4695 + lseek(fd, start_block * BLOCK_SIZE, 0);
4701 +static int __init rd_load_image(char *from)
4705 +#ifdef CONFIG_BLK_DEV_RAM
4706 + int in_fd, out_fd;
4707 + unsigned long rd_blocks, devblocks;
4710 + unsigned short rotate = 0;
4711 +#if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
4712 + char rotator[4] = { '|' , '/' , '-' , '\\' };
4715 + out_fd = open("/dev/ram", O_RDWR, 0);
4719 + in_fd = open(from, O_RDONLY, 0);
4721 + goto noclose_input;
4723 + nblocks = identify_ramdisk_image(in_fd, rd_image_start);
4727 + if (nblocks == 0) {
4728 +#ifdef BUILD_CRAMDISK
4729 + if (crd_load(in_fd, out_fd) == 0)
4730 + goto successful_load;
4732 + printk(KERN_NOTICE
4733 + "RAMDISK: Kernel does not support compressed "
4734 + "RAM disk images\n");
4740 + * NOTE NOTE: nblocks suppose that the blocksize is BLOCK_SIZE, so
4741 + * rd_load_image will work only with filesystem BLOCK_SIZE wide!
4742 + * So make sure to use 1k blocksize while generating ext2fs
4745 + if (sys_ioctl(out_fd, BLKGETSIZE, (unsigned long)&rd_blocks) < 0)
4750 + if (nblocks > rd_blocks) {
4751 + printk("RAMDISK: image too big! (%d/%d blocks)\n",
4752 + nblocks, rd_blocks);
4757 + * OK, time to copy in the data
4759 + buf = kmalloc(BLOCK_SIZE, GFP_KERNEL);
4761 + printk(KERN_ERR "RAMDISK: could not allocate buffer\n");
4765 + if (sys_ioctl(in_fd, BLKGETSIZE, (unsigned long)&devblocks) < 0)
4770 + if (strcmp(from, "/dev/initrd") == 0)
4771 + devblocks = nblocks;
4773 + if (devblocks == 0) {
4774 + printk(KERN_ERR "RAMDISK: could not determine device size\n");
4778 + printk(KERN_NOTICE "RAMDISK: Loading %d blocks [%d disk%s] into ram disk... ",
4779 + nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : "");
4780 + for (i=0; i < nblocks; i++) {
4781 + if (i && (i % devblocks == 0)) {
4782 + printk("done disk #%d.\n", i/devblocks);
4784 + if (close(in_fd)) {
4785 + printk("Error closing the disk.\n");
4786 + goto noclose_input;
4788 + change_floppy("disk #%d", i/devblocks+1);
4789 + in_fd = open(from, O_RDONLY, 0);
4791 + printk("Error opening disk.\n");
4792 + goto noclose_input;
4794 + printk("Loading disk #%d... ", i/devblocks+1);
4796 + read(in_fd, buf, BLOCK_SIZE);
4797 + write(out_fd, buf, BLOCK_SIZE);
4798 +#if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES)
4800 + printk("%c\b", rotator[rotate & 0x3]);
4805 + printk("done.\n");
4815 + sys_unlink("/dev/ram");
4820 +static int __init rd_load_disk(int n)
4822 +#ifdef CONFIG_BLK_DEV_RAM
4824 + change_floppy("root floppy disk to be loaded into RAM disk");
4825 + create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, n), NULL);
4827 + return rd_load_image("/dev/root");
4830 +#ifdef CONFIG_DEVFS_FS
4832 +static void __init convert_name(char *prefix, char *name, char *p, int part)
4834 + int host, bus, target, lun;
4837 + char *base = p - 1;
4839 + /* Decode "c#b#t#u#" */
4842 + host = simple_strtol(p, &p, 10);
4845 + bus = simple_strtol(p, &p, 10);
4848 + target = simple_strtol(p, &p, 10);
4851 + lun = simple_strtol(p, &p, 10);
4853 + sprintf(dest, "%s/host%d/bus%d/target%d/lun%d",
4854 + prefix, host, bus, target, lun);
4855 + else if (*p++ == 'p')
4856 + sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/part%s",
4857 + prefix, host, bus, target, lun, p);
4859 + sprintf(dest, "%s/host%d/bus%d/target%d/lun%d/disc",
4860 + prefix, host, bus, target, lun);
4862 + sprintf(src, "/dev/%s", name);
4863 + sys_mkdir(src, 0755);
4865 + sprintf(src, "/dev/%s", name);
4866 + sys_symlink(dest, src);
4869 +static void __init devfs_make_root(char *name)
4872 + if (!strncmp(name, "sd/", 3))
4873 + convert_name("../scsi", name, name+3, 1);
4874 + else if (!strncmp(name, "sr/", 3))
4875 + convert_name("../scsi", name, name+3, 0);
4876 + else if (!strncmp(name, "ide/hd/", 7))
4877 + convert_name("..", name, name + 7, 1);
4878 + else if (!strncmp(name, "ide/cd/", 7))
4879 + convert_name("..", name, name + 7, 0);
4882 +static void __init devfs_make_root(char *name)
4887 +static void __init mount_root(void)
4889 +#ifdef CONFIG_ROOT_NFS
4890 + if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) {
4891 + if (mount_nfs_root()) {
4892 + sys_chdir("/root");
4893 + ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
4894 + printk("VFS: Mounted root (nfs filesystem).\n");
4897 + printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
4898 + ROOT_DEV = MKDEV(FLOPPY_MAJOR, 0);
4901 + devfs_make_root(root_device_name);
4902 + create_dev("/dev/root", ROOT_DEV, root_device_name);
4903 +#ifdef CONFIG_BLK_DEV_FD
4904 + if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
4905 + /* rd_doload is 2 for a dual initrd/ramload setup */
4906 + if (rd_doload==2) {
4907 + if (rd_load_disk(1)) {
4908 + ROOT_DEV = MKDEV(RAMDISK_MAJOR, 1);
4909 + create_dev("/dev/root", ROOT_DEV, NULL);
4912 + change_floppy("root floppy");
4915 +#if defined(CONFIG_MTD_BLOCK) || defined(CONFIG_MTD_BLOCK_RO)
4916 + if (MAJOR(ROOT_DEV) == 31) {
4917 + /* rd_doload is for a ramload setup */
4919 + if (rd_load_disk(0)) {
4920 + ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
4921 + create_dev("/dev/root", ROOT_DEV, NULL);
4926 + mount_block_root("/dev/root", root_mountflags);
4929 +#ifdef CONFIG_BLK_DEV_INITRD
4930 +static int old_fd, root_fd;
4931 +static int do_linuxrc(void * shell)
4933 + static char *argv[] = { "linuxrc", NULL, };
4934 + extern char * envp_init[];
4942 + (void) open("/dev/console",O_RDWR,0);
4945 + return execve(shell, argv, envp_init);
4950 +static void __init handle_initrd(void)
4952 +#ifdef CONFIG_BLK_DEV_INITRD
4953 + int ram0 = kdev_t_to_nr(MKDEV(RAMDISK_MAJOR,0));
4957 + create_dev("/dev/root.old", ram0, NULL);
4958 + /* mount initrd on rootfs' /root */
4959 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
4960 + sys_mkdir("/old", 0700);
4961 + root_fd = open("/", 0, 0);
4962 + old_fd = open("/old", 0, 0);
4963 + /* move initrd over / and chdir/chroot in initrd root */
4964 + sys_chdir("/root");
4965 + sys_mount(".", "/", NULL, MS_MOVE, NULL);
4967 + mount_devfs_fs ();
4969 + pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
4971 + while (pid != wait(&i))
4975 + /* move initrd to rootfs' /old */
4976 + sys_fchdir(old_fd);
4977 + sys_mount("/", ".", NULL, MS_MOVE, NULL);
4978 + /* switch root and cwd back to / of rootfs */
4979 + sys_fchdir(root_fd);
4981 + sys_umount("/old/dev", 0);
4983 + if (real_root_dev == ram0) {
4984 + sys_chdir("/old");
4988 + ROOT_DEV = real_root_dev;
4991 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
4992 + error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
4996 + int fd = open("/dev/root.old", O_RDWR, 0);
4997 + printk("failed\n");
4998 + printk(KERN_NOTICE "Unmounting old root\n");
4999 + sys_umount("/old", MNT_DETACH);
5000 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
5004 + error = sys_ioctl(fd, BLKFLSBUF, 0);
5007 + printk(!error ? "okay\n" : "failed\n");
5012 +static int __init initrd_load(void)
5014 +#ifdef CONFIG_BLK_DEV_INITRD
5015 + create_dev("/dev/ram", MKDEV(RAMDISK_MAJOR, 0), NULL);
5016 + create_dev("/dev/initrd", MKDEV(RAMDISK_MAJOR, INITRD_MINOR), NULL);
5018 + return rd_load_image("/dev/initrd");
5022 + * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
5024 +void prepare_namespace(void)
5026 + int is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
5027 +#ifdef CONFIG_ALL_PPC
5028 + extern void arch_discover_root(void);
5029 + arch_discover_root();
5030 +#endif /* CONFIG_ALL_PPC */
5031 +#ifdef CONFIG_BLK_DEV_INITRD
5032 + if (!initrd_start)
5034 + real_root_dev = ROOT_DEV;
5036 + sys_mkdir("/dev", 0700);
5037 + sys_mkdir("/root", 0700);
5038 + sys_mknod("/dev/console", S_IFCHR|0600, MKDEV(TTYAUX_MAJOR, 1));
5039 +#ifdef CONFIG_DEVFS_FS
5040 + sys_mount("devfs", "/dev", "devfs", 0, NULL);
5044 + create_dev("/dev/root", ROOT_DEV, NULL);
5045 + if (mount_initrd) {
5046 + if (initrd_load() && ROOT_DEV != MKDEV(RAMDISK_MAJOR, 0)) {
5050 + } else if (is_floppy && rd_doload && rd_load_disk(0))
5051 + ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
5054 + sys_umount("/dev", 0);
5055 + sys_mount(".", "/", NULL, MS_MOVE, NULL);
5057 + mount_devfs_fs ();
5060 +#if defined(BUILD_CRAMDISK) && defined(CONFIG_BLK_DEV_RAM)
5063 + * gzip declarations
5066 +#define OF(args) args
5069 +#define memzero(s, n) memset ((s), 0, (n))
5072 +typedef unsigned char uch;
5073 +typedef unsigned short ush;
5074 +typedef unsigned long ulg;
5076 +#define INBUFSIZ 4096
5077 +#define WSIZE 0x8000 /* window size--must be a power of two, and */
5078 + /* at least 32K for zip's deflate method */
5081 +static uch *window;
5083 +static unsigned insize; /* valid bytes in inbuf */
5084 +static unsigned inptr; /* index of next byte to be processed in inbuf */
5085 +static unsigned outcnt; /* bytes in output buffer */
5086 +static int exit_code;
5087 +static long bytes_out;
5088 +static int crd_infd, crd_outfd;
5090 +#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
5092 +/* Diagnostic functions (stubbed out) */
5093 +#define Assert(cond,msg)
5097 +#define Tracec(c,x)
5098 +#define Tracecv(c,x)
5100 +#define STATIC static
5102 +static int fill_inbuf(void);
5103 +static void flush_window(void);
5104 +static void *malloc(int size);
5105 +static void free(void *where);
5106 +static void error(char *m);
5107 +static void gzip_mark(void **);
5108 +static void gzip_release(void **);
5110 +#include "../lib/inflate.c"
5112 +static void __init *malloc(int size)
5114 + return kmalloc(size, GFP_KERNEL);
5117 +static void __init free(void *where)
5122 +static void __init gzip_mark(void **ptr)
5126 +static void __init gzip_release(void **ptr)
5131 +/* ===========================================================================
5132 + * Fill the input buffer. This is called only when the buffer is empty
5133 + * and at least one byte is really needed.
5135 +static int __init fill_inbuf(void)
5137 + if (exit_code) return -1;
5139 + insize = read(crd_infd, inbuf, INBUFSIZ);
5140 + if (insize == 0) return -1;
5147 +/* ===========================================================================
5148 + * Write the output window window[0..outcnt-1] and update crc and bytes_out.
5149 + * (Used for the decompressed data only.)
5151 +static void __init flush_window(void)
5153 + ulg c = crc; /* temporary variable */
5157 + write(crd_outfd, window, outcnt);
5159 + for (n = 0; n < outcnt; n++) {
5161 + c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
5164 + bytes_out += (ulg)outcnt;
5168 +static void __init error(char *x)
5170 + printk(KERN_ERR "%s", x);
5174 +static int __init crd_load(int in_fd, int out_fd)
5178 + insize = 0; /* valid bytes in inbuf */
5179 + inptr = 0; /* index of next byte to be processed in inbuf */
5180 + outcnt = 0; /* bytes in output buffer */
5183 + crc = (ulg)0xffffffffL; /* shift register contents */
5186 + crd_outfd = out_fd;
5187 + inbuf = kmalloc(INBUFSIZ, GFP_KERNEL);
5189 + printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n");
5192 + window = kmalloc(WSIZE, GFP_KERNEL);
5193 + if (window == 0) {
5194 + printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n");
5199 + result = gunzip();
5205 +#endif /* BUILD_CRAMDISK && CONFIG_BLK_DEV_RAM */
5206 diff -Nurb src/linux/linux.orig/kernel/ksyms.c src/linux/linux/kernel/ksyms.c
5207 --- src/linux/linux.orig/kernel/ksyms.c 2003-07-04 04:12:28.000000000 -0400
5208 +++ src/linux/linux/kernel/ksyms.c 2004-05-25 21:12:24.000000000 -0400
5210 EXPORT_SYMBOL(simple_strtoull);
5211 EXPORT_SYMBOL(system_utsname); /* UTS data */
5212 EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
5214 +//#ifndef __mips__ //bite me. -mbm.
5215 EXPORT_SYMBOL(sys_call_table);
5218 EXPORT_SYMBOL(machine_restart);
5219 EXPORT_SYMBOL(machine_halt);
5220 EXPORT_SYMBOL(machine_power_off);
5221 diff -Nurb src/linux/linux.orig/lib/Config.in src/linux/linux/lib/Config.in
5222 --- src/linux/linux.orig/lib/Config.in 2003-07-04 04:12:29.000000000 -0400
5223 +++ src/linux/linux/lib/Config.in 2004-05-25 21:13:03.000000000 -0400
5225 # Do we need the compression support?
5227 if [ "$CONFIG_CRAMFS" = "y" -o \
5228 + "$CONFIG_SQUASHFS" = "y" -o \
5229 "$CONFIG_PPP_DEFLATE" = "y" -o \
5230 "$CONFIG_JFFS2_FS" = "y" -o \
5231 "$CONFIG_ZISOFS_FS" = "y" ]; then
5232 define_tristate CONFIG_ZLIB_INFLATE y
5234 if [ "$CONFIG_CRAMFS" = "m" -o \
5235 + "$CONFIG_SQUASHFS" = "m" -o \
5236 "$CONFIG_PPP_DEFLATE" = "m" -o \
5237 "$CONFIG_JFFS2_FS" = "m" -o \
5238 "$CONFIG_ZISOFS_FS" = "m" ]; then