restructure; cleanup
[openwrt/svn-archive/archive.git] / obsolete-buildroot / sources / openwrt / kernel / patches / 120-openwrt.patch
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
4 @@ -17,7 +17,7 @@
5 FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net $(HPATH)/math-emu
6
7 HOSTCC = gcc
8 -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
9 +HOSTCFLAGS = -Wall -Wstrict-prototypes -Os -fomit-frame-pointer
10
11 CROSS_COMPILE =
12
13 @@ -88,7 +88,7 @@
14
15 CPPFLAGS := -D__KERNEL__ -I$(HPATH)
16
17 -CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
18 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
19 -fno-strict-aliasing -fno-common
20
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
25 @@ -27,6 +27,7 @@
26 #include <linux/ext2_fs.h>
27 #include <linux/romfs_fs.h>
28 #include <linux/cramfs_fs.h>
29 +#include <linux/squashfs_fs.h>
30 #endif
31
32 #include <typedefs.h>
33 @@ -160,37 +161,38 @@
34 #ifdef CONFIG_MTD_PARTITIONS
35
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, },
43 { name: NULL, },
44 };
45
46 -struct mtd_partition * __init
47 -init_mtd_partitions(struct mtd_info *mtd, size_t size)
48 +
49 +static int __init
50 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
51 {
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;
58 +
59 unsigned char buf[512];
60 int off;
61 size_t len;
62
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;
69
70 - /* Look at every 64 KB boundary */
71 - for (off = 0; off < size; off += (64 * 1024)) {
72 + part->offset = 0;
73 + part->size = 0;
74 +
75 + for (off = 0; off < size; off += mtd->erasesize) {
76 memset(buf, 0xe5, sizeof(buf));
77
78 /*
79 - * Read block 0 to test for romfs and cramfs superblock
80 + * Read block 0 to test for cramfs superblock
81 */
82 if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
83 len != sizeof(buf))
84 @@ -198,75 +200,105 @@
85
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]);
91 continue;
92 }
93
94 - /* romfs is at block zero too */
95 - if (romfsb->word0 == ROMSB_WORD0 &&
96 - romfsb->word1 == ROMSB_WORD1) {
97 - printk(KERN_NOTICE
98 - "%s: romfs filesystem found at block %d\n",
99 - mtd->name, off / BLOCK_SIZE);
100 - goto done;
101 - }
102 -
103 - /* so is cramfs */
104 + /* need to find cramfs */
105 if (cramfsb->magic == CRAMFS_MAGIC) {
106 printk(KERN_NOTICE
107 "%s: cramfs filesystem found at block %d\n",
108 mtd->name, off / BLOCK_SIZE);
109 - goto done;
110 - }
111
112 - /*
113 - * Read block 1 to test for minix and ext2 superblock
114 - */
115 - if (MTD_READ(mtd, off + BLOCK_SIZE, sizeof(buf), &len, buf) ||
116 - len != sizeof(buf))
117 - continue;
118 -
119 - /* Try minix */
120 - if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
121 - minixsb->s_magic == MINIX_SUPER_MAGIC2) {
122 - printk(KERN_NOTICE
123 - "%s: Minix filesystem found at block %d\n",
124 - mtd->name, off / BLOCK_SIZE);
125 + part->size = cramfsb->size;
126 goto done;
127 }
128
129 - /* Try ext2 */
130 - if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
131 + /* or squashfs */
132 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
133 printk(KERN_NOTICE
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;
138 goto done;
139 }
140 - }
141
142 + }
143 printk(KERN_NOTICE
144 - "%s: Couldn't find valid ROM disk image\n",
145 + "%s: Couldn't find valid cramfs image\n",
146 mtd->name);
147 + return -1;
148 +
149 +done:
150 + part->offset = off;
151 + return 0;
152 +}
153 +
154 +
155 +struct mtd_partition * __init
156 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
157 +{
158 +
159 + bcm947xx_parts[0].offset=0;
160 + bcm947xx_parts[0].size=256*1024;
161
162 - done:
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;
166
167 /* Find and size rootfs */
168 - if (off < size) {
169 - bcm947xx_parts[2].offset = off;
170 - bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
171 - }
172 + //if (off < size) {
173 + // bcm947xx_parts[2].offset = off;
174 + // bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
175 + //}
176 +
177 + /* Find and size rootfs */
178 + find_root(mtd,size,&bcm947xx_parts[2]);
179 +
180 +
181
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;
185
186 +
187 +
188 + /* calculate leftover flash, and assign it to the jffs partition */
189 + size_t spot;
190 + size_t len;
191 + size_t mask;
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;
198 + mask=mask-1;
199 + mask=mask^0xffffffff;
200 + spot&=mask;
201 + // length = flashsize - start position - nvram size
202 + len=size-spot;
203 + len=len-bcm947xx_parts[3].size;
204 +
205 +
206 + bcm947xx_parts[4].offset = spot;
207 + bcm947xx_parts[4].size = len;
208 +
209 +
210 +
211 +
212 /* Size pmon */
213 bcm947xx_parts[0].size = bcm947xx_parts[1].offset - bcm947xx_parts[0].offset;
214
215 + //int x;
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);
220 + //}
221 +
222 +
223 return bcm947xx_parts;
224 }
225
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
229 @@ -82,7 +82,21 @@
230
231 void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
232 {
233 + //memcpy_fromio(to, map->map_priv_1 + from, len);
234 + if (len==1) {
235 memcpy_fromio(to, map->map_priv_1 + from, len);
236 + } else {
237 + int i;
238 + u16 *dest = (u16 *) to;
239 + u16 *src = (u16 *) (map->map_priv_1 + from);
240 +
241 + for (i = 0; i < (len / 2); i++) {
242 + dest[i] = src[i];
243 + }
244 +
245 + if (len & 1)
246 + *((u8 *)dest+len-1) = src[i] & 0xff;
247 + }
248 }
249
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
254 @@ -25,7 +25,7 @@
255 list-multi := rcpci.o
256 rcpci-objs := rcpci45.o rclanmtl.o
257
258 -subdir-m += mac
259 +# subdir-m += mac
260 subdir-m += diag
261
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
266 @@ -47,6 +47,7 @@
267 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
268 fi
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
273
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
277 @@ -68,6 +68,7 @@
278 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
279 subdir-$(CONFIG_BEFS_FS) += befs
280 subdir-$(CONFIG_JFS_FS) += jfs
281 +subdir-$(CONFIG_SQUASHFS) += squashfs
282
283
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
288 @@ -0,0 +1,11 @@
289 +#
290 +# Makefile for the linux squashfs routines.
291 +#
292 +
293 +O_TARGET := squashfs.o
294 +
295 +obj-y := inode.o
296 +
297 +obj-m := $(O_TARGET)
298 +
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
303 @@ -0,0 +1,1515 @@
304 +/*
305 + * Squashfs - a compressed read only filesystem for Linux
306 + *
307 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
308 + *
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.
313 + *
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.
318 + *
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
323 + *
324 + * inode.c
325 + */
326 +
327 +#define SQUASHFS_1_0_COMPATIBILITY
328 +
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>
344 +
345 +#ifdef SQUASHFS_TRACE
346 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
347 +#else
348 +#define TRACE(s, args...) {}
349 +#endif
350 +
351 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
352 +
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)
355 +
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);
373 +
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);
379 +#endif
380 +
381 +DECLARE_MUTEX(read_data_mutex);
382 +
383 +static z_stream stream;
384 +
385 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
386 +
387 +static unsigned char squashfs_filetype_table[] = {
388 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
389 +};
390 +
391 +static struct super_operations squashfs_ops = {
392 + statfs: squashfs_statfs,
393 + put_super: squashfs_put_super,
394 +};
395 +
396 +static struct address_space_operations squashfs_symlink_aops = {
397 + readpage: squashfs_symlink_readpage
398 +};
399 +
400 +static struct address_space_operations squashfs_aops = {
401 + readpage: squashfs_readpage
402 +};
403 +
404 +static struct address_space_operations squashfs_aops_4K = {
405 + readpage: squashfs_readpage4K
406 +};
407 +
408 +#ifdef SQUASHFS_1_0_COMPATIBILITY
409 +static struct address_space_operations squashfs_aops_lessthan4K = {
410 + readpage: squashfs_readpage_lessthan4K
411 +};
412 +#endif
413 +
414 +static struct file_operations squashfs_dir_ops = {
415 + read: generic_read_dir,
416 + readdir: squashfs_readdir
417 +};
418 +
419 +static struct inode_operations squashfs_dir_inode_ops = {
420 + lookup: squashfs_lookup
421 +};
422 +
423 +
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)
426 +{
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;
432 + char *c_buffer;
433 + unsigned int compressed;
434 + unsigned int c_byte = length;
435 +
436 + if(c_byte) {
437 + bytes = msBlk->devblksize - offset;
438 + if(datablock) {
439 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
440 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
441 + } else {
442 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
443 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
444 + }
445 +
446 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
447 +
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;
454 + }
455 + ll_rw_block(READ, b, bh);
456 + } else {
457 + unsigned short temp;
458 + if(!(bh[0] = sb_bread(s, cur_index)))
459 + goto read_failure;
460 +
461 + if(msBlk->devblksize - offset == 1) {
462 + if(msBlk->swap)
463 + ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
464 + else
465 + ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset));
466 + brelse(bh[0]);
467 + if(!(bh[0] = sb_bread(s, ++cur_index)))
468 + goto read_failure;
469 + if(msBlk->swap)
470 + ((unsigned char *) &temp)[0] = *((unsigned char *) bh[0]->b_data);
471 + else
472 + ((unsigned char *) &temp)[1] = *((unsigned char *) bh[0]->b_data);
473 + c_byte = temp;
474 + offset = 1;
475 + }
476 + else {
477 + if(msBlk->swap) {
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));
481 + c_byte = temp;
482 + } else
483 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
484 + offset += 2;
485 + }
486 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
487 + if(offset == msBlk->devblksize) {
488 + brelse(bh[0]);
489 + if(!(bh[0] = sb_bread(s, ++cur_index)))
490 + goto read_failure;
491 + offset = 0;
492 + }
493 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
494 + ERROR("Metadata block marker corrupt @ %x\n", index);
495 + brelse(bh[0]);
496 + return 0;
497 + }
498 + offset ++;
499 + }
500 +
501 + bytes = msBlk->devblksize - offset;
502 + if(datablock) {
503 + c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
504 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
505 + } else {
506 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
507 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
508 + }
509 +
510 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
511 +
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;
516 + }
517 + ll_rw_block(READ, b - 1, bh + 1);
518 + }
519 +
520 + if(compressed)
521 + down(&read_data_mutex);
522 +
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;
528 + offset = 0;
529 + brelse(bh[k]);
530 + }
531 +
532 + /*
533 + * uncompress block
534 + */
535 + if(compressed) {
536 + int zlib_err;
537 +
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);
546 + bytes = 0;
547 + } else
548 + bytes = stream.total_out;
549 + up(&read_data_mutex);
550 + }
551 +
552 + if(next_index)
553 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
554 +
555 + return bytes;
556 +
557 +block_release:
558 + while(--b >= 0) brelse(bh[b]);
559 +
560 +read_failure:
561 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
562 + return 0;
563 +}
564 +
565 +
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)
569 +{
570 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
571 + int n, i, bytes, return_length = length;
572 + unsigned int next_index;
573 +
574 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
575 +
576 + for(;;) {
577 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
578 + if(msBlk->block_cache[i].block == block)
579 + break;
580 +
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)
586 + break;
587 + if(n == 0) {
588 + up(&msBlk->block_cache_mutex);
589 + sleep_on(&msBlk->waitq);
590 + continue;
591 + }
592 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
593 +
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);
599 + return 0;
600 + }
601 + }
602 +
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,
606 + &next_index))) {
607 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
608 + return 0;
609 + }
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);
615 + }
616 +
617 + if(msBlk->block_cache[i].block != block) {
618 + up(&msBlk->block_cache_mutex);
619 + continue;
620 + }
621 +
622 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
623 + if(buffer)
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;
627 + *next_offset = 0;
628 + } else {
629 + *next_block = block;
630 + *next_offset = offset + length;
631 + }
632 +
633 + up(&msBlk->block_cache_mutex);
634 + return return_length;
635 + } else {
636 + if(buffer) {
637 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
638 + buffer += bytes;
639 + }
640 + block = msBlk->block_cache[i].next_index;
641 + up(&msBlk->block_cache_mutex);
642 + length -= bytes;
643 + offset = 0;
644 + }
645 + }
646 +}
647 +
648 +
649 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
650 +{
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;
655 +
656 + if(msBlk->swap) {
657 + squashfs_fragment_entry sfragment_entry;
658 +
659 + if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
660 + sizeof(sfragment_entry), &start_block, &offset))
661 + return 0;
662 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
663 + } else
664 + if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
665 + sizeof(fragment_entry), &start_block, &offset))
666 + return 0;
667 +
668 + *fragment_start_block = fragment_entry.start_block;
669 + *fragment_size = fragment_entry.size;
670 +
671 + return 1;
672 +}
673 +
674 +
675 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
676 +{
677 + down(&msBlk->fragment_mutex);
678 + fragment->locked --;
679 + wake_up(&msBlk->fragment_wait_queue);
680 + up(&msBlk->fragment_mutex);
681 +}
682 +
683 +
684 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
685 +{
686 + int i, n;
687 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
688 +
689 + for(;;) {
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);
695 +
696 + if(n == 0) {
697 + up(&msBlk->fragment_mutex);
698 + sleep_on(&msBlk->fragment_wait_queue);
699 + continue;
700 + }
701 + msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
702 +
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);
708 + return NULL;
709 + }
710 +
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,
715 + 1, NULL))) {
716 + ERROR("Unable to read fragment cache block [%x]\n", start_block);
717 + msBlk->fragment[i].locked = 0;
718 + return NULL;
719 + }
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];
723 + }
724 +
725 + msBlk->fragment[i].locked ++;
726 + up(&msBlk->fragment_mutex);
727 +
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];
730 + }
731 +}
732 +
733 +
734 +#ifdef SQUASHFS_1_0_COMPATIBILITY
735 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
736 +{
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;
744 +
745 + TRACE("Entered squashfs_iget_1\n");
746 +
747 + if(msBlk->swap) {
748 + squashfs_base_inode_header_1 sinodeb;
749 +
750 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
751 + sizeof(sinodeb), &next_block, &next_offset))
752 + goto failed_read;
753 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
754 + } else
755 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
756 + sizeof(inodeb), &next_block, &next_offset))
757 + goto failed_read;
758 +
759 + i->i_nlink = 1;
760 +
761 + i->i_mtime = sBlk->mkfs_time;
762 + i->i_atime = sBlk->mkfs_time;
763 + i->i_ctime = sBlk->mkfs_time;
764 +
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);
768 +
769 + i->i_mode = inodeb.mode;
770 +
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;
774 +
775 + if(msBlk->swap) {
776 + squashfs_reg_inode_header_1 sinodep;
777 +
778 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
779 + &next_block, &next_offset))
780 + goto failed_read;
781 + SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
782 + } else
783 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
784 + &next_block, &next_offset))
785 + goto failed_read;
786 +
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;
793 + else
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);
808 + break;
809 + }
810 + case SQUASHFS_DIR_TYPE: {
811 + squashfs_dir_inode_header_1 inodep;
812 +
813 + if(msBlk->swap) {
814 + squashfs_dir_inode_header_1 sinodep;
815 +
816 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
817 + &next_block, &next_offset))
818 + goto failed_read;
819 + SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
820 + } else
821 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
822 + &next_block, &next_offset))
823 + goto failed_read;
824 +
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);
836 + break;
837 + }
838 + case SQUASHFS_SYMLINK_TYPE: {
839 + squashfs_symlink_inode_header_1 inodep;
840 +
841 + if(msBlk->swap) {
842 + squashfs_symlink_inode_header_1 sinodep;
843 +
844 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
845 + &next_block, &next_offset))
846 + goto failed_read;
847 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
848 + } else
849 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
850 + &next_block, &next_offset))
851 + goto failed_read;
852 +
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);
861 + break;
862 + }
863 + case SQUASHFS_BLKDEV_TYPE:
864 + case SQUASHFS_CHRDEV_TYPE: {
865 + squashfs_dev_inode_header_1 inodep;
866 +
867 + if(msBlk->swap) {
868 + squashfs_dev_inode_header_1 sinodep;
869 +
870 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
871 + &next_block, &next_offset))
872 + goto failed_read;
873 + SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
874 + } else
875 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
876 + &next_block, &next_offset))
877 + goto failed_read;
878 +
879 + i->i_size = 0;
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);
883 + break;
884 + }
885 + case SQUASHFS_IPC_TYPE: {
886 + squashfs_ipc_inode_header_1 inodep;
887 +
888 + if(msBlk->swap) {
889 + squashfs_ipc_inode_header_1 sinodep;
890 +
891 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
892 + &next_block, &next_offset))
893 + goto failed_read;
894 + SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
895 + } else
896 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
897 + &next_block, &next_offset))
898 + goto failed_read;
899 +
900 + i->i_size = 0;
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);
904 + break;
905 + }
906 + default:
907 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
908 + goto failed_read1;
909 + }
910 +
911 + if(inodeb.guid == SQUASHFS_GUIDS)
912 + i->i_gid = i->i_uid;
913 + else
914 + i->i_gid = msBlk->guid[inodeb.guid];
915 +
916 + return i;
917 +
918 +failed_read:
919 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
920 +
921 +failed_read1:
922 + return NULL;
923 +}
924 +#endif
925 +
926 +
927 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
928 +{
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;
936 +
937 + TRACE("Entered squashfs_iget\n");
938 +
939 + if(msBlk->swap) {
940 + squashfs_base_inode_header sinodeb;
941 +
942 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
943 + sizeof(sinodeb), &next_block, &next_offset))
944 + goto failed_read;
945 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
946 + } else
947 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
948 + sizeof(inodeb), &next_block, &next_offset))
949 + goto failed_read;
950 +
951 + i->i_nlink = 1;
952 +
953 + i->i_mtime = sBlk->mkfs_time;
954 + i->i_atime = sBlk->mkfs_time;
955 + i->i_ctime = sBlk->mkfs_time;
956 +
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);
960 +
961 + i->i_mode = inodeb.mode;
962 +
963 + switch(inodeb.inode_type) {
964 + case SQUASHFS_FILE_TYPE: {
965 + squashfs_reg_inode_header inodep;
966 +
967 + if(msBlk->swap) {
968 + squashfs_reg_inode_header sinodep;
969 +
970 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
971 + &next_block, &next_offset))
972 + goto failed_read;
973 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
974 + } else
975 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
976 + &next_block, &next_offset))
977 + goto failed_read;
978 +
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))
982 + goto failed_read;
983 +
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;
989 + else
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);
1002 + break;
1003 + }
1004 + case SQUASHFS_DIR_TYPE: {
1005 + squashfs_dir_inode_header inodep;
1006 +
1007 + if(msBlk->swap) {
1008 + squashfs_dir_inode_header sinodep;
1009 +
1010 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1011 + &next_block, &next_offset))
1012 + goto failed_read;
1013 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
1014 + } else
1015 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1016 + &next_block, &next_offset))
1017 + goto failed_read;
1018 +
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);
1030 + break;
1031 + }
1032 + case SQUASHFS_SYMLINK_TYPE: {
1033 + squashfs_symlink_inode_header inodep;
1034 +
1035 + if(msBlk->swap) {
1036 + squashfs_symlink_inode_header sinodep;
1037 +
1038 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1039 + &next_block, &next_offset))
1040 + goto failed_read;
1041 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
1042 + } else
1043 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1044 + &next_block, &next_offset))
1045 + goto failed_read;
1046 +
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);
1055 + break;
1056 + }
1057 + case SQUASHFS_BLKDEV_TYPE:
1058 + case SQUASHFS_CHRDEV_TYPE: {
1059 + squashfs_dev_inode_header inodep;
1060 +
1061 + if(msBlk->swap) {
1062 + squashfs_dev_inode_header sinodep;
1063 +
1064 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
1065 + &next_block, &next_offset))
1066 + goto failed_read;
1067 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
1068 + } else
1069 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
1070 + &next_block, &next_offset))
1071 + goto failed_read;
1072 +
1073 + i->i_size = 0;
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);
1077 + break;
1078 + }
1079 + case SQUASHFS_FIFO_TYPE:
1080 + case SQUASHFS_SOCKET_TYPE: {
1081 + i->i_size = 0;
1082 + i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
1083 + init_special_inode(i, i->i_mode, 0);
1084 + break;
1085 + }
1086 + default:
1087 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
1088 + goto failed_read1;
1089 + }
1090 +
1091 + if(inodeb.guid == SQUASHFS_GUIDS)
1092 + i->i_gid = i->i_uid;
1093 + else
1094 + i->i_gid = msBlk->guid[inodeb.guid];
1095 +
1096 + return i;
1097 +
1098 +failed_read:
1099 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
1100 +
1101 +failed_read1:
1102 + return NULL;
1103 +}
1104 +
1105 +
1106 +static struct super_block *squashfs_read_super(struct super_block *s,
1107 + void *data, int silent)
1108 +{
1109 + kdev_t dev = s->s_dev;
1110 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
1111 + squashfs_super_block *sBlk = &msBlk->sBlk;
1112 + int i;
1113 +
1114 + TRACE("Entered squashfs_read_superblock\n");
1115 +
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;
1123 +
1124 + init_MUTEX(&msBlk->read_page_mutex);
1125 + init_MUTEX(&msBlk->block_cache_mutex);
1126 + init_MUTEX(&msBlk->fragment_mutex);
1127 +
1128 + init_waitqueue_head(&msBlk->waitq);
1129 + init_waitqueue_head(&msBlk->fragment_wait_queue);
1130 +
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;
1134 + }
1135 +
1136 + /* Check it is a SQUASHFS superblock */
1137 + msBlk->swap = 0;
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));
1144 + msBlk->swap = 1;
1145 + } else {
1146 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
1147 + goto failed_mount;
1148 + }
1149 + }
1150 +
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;
1157 + }
1158 + if(sBlk->s_major == 1)
1159 + sBlk->block_size = sBlk->block_size_1;
1160 +#else
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;
1165 + }
1166 +#endif
1167 +
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);
1184 +
1185 + s->s_flags |= MS_RDONLY;
1186 + s->s_op = &squashfs_ops;
1187 +
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;
1192 + }
1193 +
1194 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1195 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1196 +
1197 + msBlk->next_cache = 0;
1198 +
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;
1204 + }
1205 +
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;
1211 + }
1212 +
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;
1218 + }
1219 + msBlk->guid = msBlk->uid + sBlk->no_uids;
1220 +
1221 + if(msBlk->swap) {
1222 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1223 +
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;
1228 + }
1229 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1230 + } else
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;
1235 + }
1236 +
1237 +
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;
1244 + }
1245 +#endif
1246 + msBlk->iget = squashfs_iget;
1247 + msBlk->read_blocklist = read_blocklist;
1248 +
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;
1252 + }
1253 +
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;
1258 + }
1259 +
1260 + msBlk->next_fragment = 0;
1261 +
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;
1266 + }
1267 +
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;
1273 + }
1274 +
1275 + if(msBlk->swap) {
1276 + int i;
1277 + squashfs_fragment_index fragment;
1278 +
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;
1282 + }
1283 + }
1284 +
1285 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1286 +allocate_root:
1287 +#endif
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;
1291 + }
1292 +
1293 + TRACE("Leaving squashfs_read_super\n");
1294 + return s;
1295 +
1296 +failed_mount6:
1297 + kfree(msBlk->fragment_index);
1298 +failed_mount5:
1299 + kfree(msBlk->fragment);
1300 +failed_mount4:
1301 + kfree(msBlk->uid);
1302 +failed_mount3:
1303 + kfree(msBlk->read_page);
1304 +failed_mount2:
1305 + kfree(msBlk->read_data);
1306 +failed_mount1:
1307 + kfree(msBlk->block_cache);
1308 +failed_mount:
1309 + return NULL;
1310 +}
1311 +
1312 +
1313 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1314 +{
1315 + squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
1316 +
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;
1323 + buf->f_ffree = 0;
1324 + buf->f_namelen = SQUASHFS_NAME_LEN;
1325 + return 0;
1326 +}
1327 +
1328 +
1329 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1330 +{
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);
1336 +
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);
1339 +
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);
1344 + goto skip_read;
1345 + }
1346 + }
1347 +
1348 + if(length != index) {
1349 + ERROR("(squashfs_symlink_readpage) length != index\n");
1350 + bytes = 0;
1351 + goto skip_read;
1352 + }
1353 +
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);
1357 +
1358 +skip_read:
1359 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1360 + kunmap(page);
1361 + flush_dcache_page(page);
1362 + SetPageUptodate(page);
1363 + UnlockPage(page);
1364 +
1365 + return 0;
1366 +}
1367 +
1368 +
1369 +#define SIZE 256
1370 +
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)
1374 +{
1375 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1376 + unsigned short *block_listp;
1377 + int i = 0;
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;
1381 +
1382 + for(;;) {
1383 + int blocks = (index + readahead_blks - i);
1384 + if(blocks > (SIZE >> 1)) {
1385 + if((index - i) <= (SIZE >> 1))
1386 + blocks = index - i;
1387 + else
1388 + blocks = SIZE >> 1;
1389 + }
1390 +
1391 + if(msBlk->swap) {
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);
1395 + return 0;
1396 + }
1397 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1398 + } else
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);
1401 + return 0;
1402 + }
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)
1406 + break;
1407 + }
1408 +
1409 + if(bsize)
1410 + *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1411 + else
1412 + (unsigned short *) *block_p = block_listp;
1413 + return block;
1414 +}
1415 +#endif
1416 +
1417 +
1418 +
1419 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1420 + char *block_list, char **block_p, unsigned int *bsize)
1421 +{
1422 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1423 + unsigned int *block_listp;
1424 + int i = 0;
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;
1428 +
1429 + for(;;) {
1430 + int blocks = (index + readahead_blks - i);
1431 + if(blocks > (SIZE >> 2)) {
1432 + if((index - i) <= (SIZE >> 2))
1433 + blocks = index - i;
1434 + else
1435 + blocks = SIZE >> 2;
1436 + }
1437 +
1438 + if(msBlk->swap) {
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);
1442 + return 0;
1443 + }
1444 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1445 + } else
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);
1448 + return 0;
1449 + }
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)
1453 + break;
1454 + }
1455 +
1456 + *bsize = *block_listp;
1457 + return block;
1458 +}
1459 +
1460 +
1461 +static int squashfs_readpage(struct file *file, struct page *page)
1462 +{
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;
1472 +
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;
1476 +
1477 + TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1478 + inode->u.squashfs_i.start_block);
1479 +
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)
1482 + goto skip_read;
1483 +
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);
1488 + goto skip_read;
1489 + }
1490 + } else {
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);
1493 + goto skip_read;
1494 + }
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;
1498 + }
1499 +
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;
1503 +
1504 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1505 +
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);
1509 + kunmap(page);
1510 + flush_dcache_page(page);
1511 + SetPageUptodate(page);
1512 + UnlockPage(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);
1522 + }
1523 + }
1524 +
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);
1527 + else
1528 + release_cached_fragment(msBlk, fragment);
1529 +
1530 + return 0;
1531 +
1532 +skip_read:
1533 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1534 + kunmap(page);
1535 + flush_dcache_page(page);
1536 + SetPageUptodate(page);
1537 + UnlockPage(page);
1538 +
1539 + return 0;
1540 +}
1541 +
1542 +
1543 +static int squashfs_readpage4K(struct file *file, struct page *page)
1544 +{
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);
1551 +
1552 + TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1553 + inode->u.squashfs_i.start_block);
1554 +
1555 + if(page->index < (inode->i_size >> sBlk->block_log)) {
1556 + block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1557 +
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);
1560 + } else {
1561 + struct squashfs_fragment_cache *fragment;
1562 +
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);
1565 + else {
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);
1569 + }
1570 + }
1571 +
1572 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1573 + kunmap(page);
1574 + flush_dcache_page(page);
1575 + SetPageUptodate(page);
1576 + UnlockPage(page);
1577 +
1578 + return 0;
1579 +}
1580 +
1581 +
1582 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1583 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1584 +{
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);
1594 +
1595 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1596 + int byte;
1597 +
1598 + TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1599 + inode->u.squashfs_i.start_block);
1600 +
1601 + block = read_blocklist_1(inode, index, readahead_blks, block_list, (char **) &block_listp, NULL);
1602 +
1603 + if(i_end > file_blocks)
1604 + i_end = file_blocks;
1605 +
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);
1609 + goto skip_read;
1610 + }
1611 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1612 + pageaddr += byte;
1613 + bytes += byte;
1614 + index ++;
1615 + block_listp ++;
1616 + }
1617 +
1618 +skip_read:
1619 + memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1620 + kunmap(page);
1621 + flush_dcache_page(page);
1622 + SetPageUptodate(page);
1623 + UnlockPage(page);
1624 +
1625 + return 0;
1626 +}
1627 +#endif
1628 +
1629 +
1630 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1631 +{
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;
1640 +
1641 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1642 +
1643 + while(length < i->i_size) {
1644 + /* read directory header */
1645 + if(msBlk->swap) {
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))
1649 + goto failed_read;
1650 + length += sizeof(sdirh);
1651 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1652 + } else {
1653 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1654 + next_offset, sizeof(dirh), &next_block, &next_offset))
1655 + goto failed_read;
1656 + length += sizeof(dirh);
1657 + }
1658 +
1659 + dir_count = dirh.count + 1;
1660 + while(dir_count--) {
1661 + if(msBlk->swap) {
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))
1665 + goto failed_read;
1666 + length += sizeof(sdire);
1667 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1668 + } else {
1669 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1670 + next_offset, sizeof(*dire), &next_block, &next_offset))
1671 + goto failed_read;
1672 + length += sizeof(*dire);
1673 + }
1674 +
1675 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1676 + next_offset, dire->size + 1, &next_block, &next_offset))
1677 + goto failed_read;
1678 + length += dire->size + 1;
1679 +
1680 + if(file->f_pos >= length)
1681 + continue;
1682 +
1683 + dire->name[dire->size + 1] = '\0';
1684 +
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]);
1688 +
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");
1692 + return dirs_read;
1693 + }
1694 +
1695 + file->f_pos = length;
1696 + dirs_read ++;
1697 + }
1698 + }
1699 +
1700 + return dirs_read;
1701 +
1702 +failed_read:
1703 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1704 + return 0;
1705 +}
1706 +
1707 +
1708 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1709 +{
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;
1720 +
1721 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1722 +
1723 + while(length < i->i_size) {
1724 + /* read directory header */
1725 + if(msBlk->swap) {
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))
1729 + goto failed_read;
1730 + length += sizeof(sdirh);
1731 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1732 + } else {
1733 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1734 + sizeof(dirh), &next_block, &next_offset))
1735 + goto failed_read;
1736 + length += sizeof(dirh);
1737 + }
1738 +
1739 + dir_count = dirh.count + 1;
1740 + while(dir_count--) {
1741 + if(msBlk->swap) {
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))
1745 + goto failed_read;
1746 + length += sizeof(sdire);
1747 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1748 + } else {
1749 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1750 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1751 + goto failed_read;
1752 + length += sizeof(*dire);
1753 + }
1754 +
1755 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1756 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1757 + goto failed_read;
1758 + length += dire->size + 1;
1759 +
1760 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1761 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1762 +
1763 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1764 + name, dirh.start_block, dire->offset);
1765 +
1766 + inode = (msBlk->iget)(i->i_sb, ino);
1767 +
1768 + goto exit_loop;
1769 + }
1770 + }
1771 + }
1772 +
1773 +exit_loop:
1774 + d_add(dentry, inode);
1775 + return ERR_PTR(0);
1776 +
1777 +failed_read:
1778 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1779 + goto exit_loop;
1780 +}
1781 +
1782 +
1783 +static void squashfs_put_super(struct super_block *s)
1784 +{
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;
1791 +}
1792 +
1793 +
1794 +static int __init init_squashfs_fs(void)
1795 +{
1796 +
1797 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1798 + ERROR("Failed to allocate zlib workspace\n");
1799 + return -ENOMEM;
1800 + }
1801 + return register_filesystem(&squashfs_fs_type);
1802 +}
1803 +
1804 +
1805 +static void __exit exit_squashfs_fs(void)
1806 +{
1807 + vfree(stream.workspace);
1808 + unregister_filesystem(&squashfs_fs_type);
1809 +}
1810 +
1811 +
1812 +EXPORT_NO_SYMBOLS;
1813 +
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
1822 @@ -313,6 +313,7 @@
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>
1827
1828 /*
1829 * Attribute flags. These should be or-ed together to figure out what
1830 @@ -503,6 +504,7 @@
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;
1835 void *generic_ip;
1836 } u;
1837 };
1838 @@ -697,6 +699,7 @@
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>
1843
1844 extern struct list_head super_blocks;
1845 extern spinlock_t sb_lock;
1846 @@ -755,6 +758,7 @@
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;
1851 void *generic_sbp;
1852 } u;
1853 /*
1854 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs.h src/linux/linux/include/linux/squashfs_fs.h
1855 --- src/linux/linux.orig/include/linux/squashfs_fs.h 1969-12-31 19:00:00.000000000 -0500
1856 +++ src/linux/linux/include/linux/squashfs_fs.h 2004-05-25 21:13:03.000000000 -0400
1857 @@ -0,0 +1,474 @@
1858 +#ifndef SQUASHFS_FS
1859 +#define SQUASHFS_FS
1860 +/*
1861 + * Squashfs
1862 + *
1863 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
1864 + *
1865 + * This program is free software; you can redistribute it and/or
1866 + * modify it under the terms of the GNU General Public License
1867 + * as published by the Free Software Foundation; either version 2,
1868 + * or (at your option) any later version.
1869 + *
1870 + * This program is distributed in the hope that it will be useful,
1871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1873 + * GNU General Public License for more details.
1874 + *
1875 + * You should have received a copy of the GNU General Public License
1876 + * along with this program; if not, write to the Free Software
1877 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1878 + *
1879 + * squashfs_fs.h
1880 + */
1881 +
1882 +#define SQUASHFS_MAJOR 2
1883 +#define SQUASHFS_MINOR 0
1884 +#define SQUASHFS_MAGIC 0x73717368
1885 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1886 +#define SQUASHFS_START 0
1887 +
1888 +/* size of metadata (inode and directory) blocks */
1889 +#define SQUASHFS_METADATA_SIZE 8192
1890 +#define SQUASHFS_METADATA_LOG 13
1891 +
1892 +/* default size of data blocks */
1893 +#define SQUASHFS_FILE_SIZE 65536
1894 +#define SQUASHFS_FILE_LOG 16
1895 +
1896 +#define SQUASHFS_FILE_MAX_SIZE 65536
1897 +
1898 +/* Max number of uids and gids */
1899 +#define SQUASHFS_UIDS 256
1900 +#define SQUASHFS_GUIDS 255
1901 +
1902 +/* Max length of filename (not 255) */
1903 +#define SQUASHFS_NAME_LEN 256
1904 +
1905 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1906 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1907 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1908 +
1909 +/* Filesystem flags */
1910 +#define SQUASHFS_NOI 0
1911 +#define SQUASHFS_NOD 1
1912 +#define SQUASHFS_CHECK 2
1913 +#define SQUASHFS_NOF 3
1914 +#define SQUASHFS_NO_FRAG 4
1915 +#define SQUASHFS_ALWAYS_FRAG 5
1916 +#define SQUASHFS_DUPLICATE 6
1917 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
1918 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, SQUASHFS_NOI)
1919 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_NOD)
1920 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1921 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1922 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1923 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1924 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1925 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, duplicate_checking) (noi | (nod << 1) | (check_data << 2) | (nof << 3) | (no_frag << 4) | (always_frag << 5) | (duplicate_checking << 6))
1926 +
1927 +/* Max number of types and file types */
1928 +#define SQUASHFS_DIR_TYPE 1
1929 +#define SQUASHFS_FILE_TYPE 2
1930 +#define SQUASHFS_SYMLINK_TYPE 3
1931 +#define SQUASHFS_BLKDEV_TYPE 4
1932 +#define SQUASHFS_CHRDEV_TYPE 5
1933 +#define SQUASHFS_FIFO_TYPE 6
1934 +#define SQUASHFS_SOCKET_TYPE 7
1935 +
1936 +/* 1.0 filesystem type definitions */
1937 +#define SQUASHFS_TYPES 5
1938 +#define SQUASHFS_IPC_TYPE 0
1939 +
1940 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1941 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1942 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1943 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1944 +
1945 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1946 +
1947 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
1948 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
1949 + (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
1950 +
1951 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
1952 +
1953 +/*
1954 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1955 + * offset within that block
1956 + */
1957 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1958 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1959 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1960 + + (B)))
1961 +
1962 +/* Compute 32 bit VFS inode number from squashfs inode number */
1963 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1964 +
1965 +/* Translate between VFS mode and squashfs mode */
1966 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1967 +
1968 +/* fragment and fragment table defines */
1969 +typedef unsigned int squashfs_fragment_index;
1970 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(squashfs_fragment_entry))
1971 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
1972 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
1973 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
1974 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
1975 +#define SQUASHFS_CACHED_FRAGMENTS 3
1976 +
1977 +/* cached data constants for filesystem */
1978 +#define SQUASHFS_CACHED_BLKS 8
1979 +
1980 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1981 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1982 +
1983 +#define SQUASHFS_MARKER_BYTE 0xff
1984 +
1985 +/*
1986 + * definitions for structures on disk
1987 + */
1988 +
1989 +typedef unsigned int squashfs_block;
1990 +typedef long long squashfs_inode;
1991 +
1992 +typedef unsigned int squashfs_uid;
1993 +
1994 +typedef struct squashfs_super_block {
1995 + unsigned int s_magic;
1996 + unsigned int inodes;
1997 + unsigned int bytes_used;
1998 + unsigned int uid_start;
1999 + unsigned int guid_start;
2000 + unsigned int inode_table_start;
2001 + unsigned int directory_table_start;
2002 + unsigned int s_major:16;
2003 + unsigned int s_minor:16;
2004 + unsigned int block_size_1:16;
2005 + unsigned int block_log:16;
2006 + unsigned int flags:8;
2007 + unsigned int no_uids:8;
2008 + unsigned int no_guids:8;
2009 + time_t mkfs_time /* time of filesystem creation */;
2010 + squashfs_inode root_inode;
2011 + unsigned int block_size;
2012 + unsigned int fragments;
2013 + unsigned int fragment_table_start;
2014 +} __attribute__ ((packed)) squashfs_super_block;
2015 +
2016 +typedef struct {
2017 + unsigned int inode_type:4;
2018 + unsigned int mode:12; /* protection */
2019 + unsigned int uid:8; /* index into uid table */
2020 + unsigned int guid:8; /* index into guid table */
2021 +} __attribute__ ((packed)) squashfs_base_inode_header;
2022 +
2023 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
2024 +
2025 +typedef struct {
2026 + unsigned int inode_type:4;
2027 + unsigned int mode:12; /* protection */
2028 + unsigned int uid:8; /* index into uid table */
2029 + unsigned int guid:8; /* index into guid table */
2030 + unsigned short rdev;
2031 +} __attribute__ ((packed)) squashfs_dev_inode_header;
2032 +
2033 +typedef struct {
2034 + unsigned int inode_type:4;
2035 + unsigned int mode:12; /* protection */
2036 + unsigned int uid:8; /* index into uid table */
2037 + unsigned int guid:8; /* index into guid table */
2038 + unsigned short symlink_size;
2039 + char symlink[0];
2040 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
2041 +
2042 +typedef struct {
2043 + unsigned int inode_type:4;
2044 + unsigned int mode:12; /* protection */
2045 + unsigned int uid:8; /* index into uid table */
2046 + unsigned int guid:8; /* index into guid table */
2047 + time_t mtime;
2048 + squashfs_block start_block;
2049 + unsigned int fragment;
2050 + unsigned int offset;
2051 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2052 + unsigned short block_list[0];
2053 +} __attribute__ ((packed)) squashfs_reg_inode_header;
2054 +
2055 +typedef struct {
2056 + unsigned int inode_type:4;
2057 + unsigned int mode:12; /* protection */
2058 + unsigned int uid:8; /* index into uid table */
2059 + unsigned int guid:8; /* index into guid table */
2060 + unsigned int file_size:19;
2061 + unsigned int offset:13;
2062 + time_t mtime;
2063 + unsigned int start_block:24;
2064 +} __attribute__ ((packed)) squashfs_dir_inode_header;
2065 +
2066 +typedef union {
2067 + squashfs_base_inode_header base;
2068 + squashfs_dev_inode_header dev;
2069 + squashfs_symlink_inode_header symlink;
2070 + squashfs_reg_inode_header reg;
2071 + squashfs_dir_inode_header dir;
2072 + squashfs_ipc_inode_header ipc;
2073 +} squashfs_inode_header;
2074 +
2075 +typedef struct {
2076 + unsigned int offset:13;
2077 + unsigned int type:3;
2078 + unsigned int size:8;
2079 + char name[0];
2080 +} __attribute__ ((packed)) squashfs_dir_entry;
2081 +
2082 +typedef struct {
2083 + unsigned int count:8;
2084 + unsigned int start_block:24;
2085 +} __attribute__ ((packed)) squashfs_dir_header;
2086 +
2087 +
2088 +typedef struct {
2089 + unsigned int start_block;
2090 + unsigned int size;
2091 +} __attribute__ ((packed)) squashfs_fragment_entry;
2092 +
2093 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
2094 +extern int squashfs_uncompress_init(void);
2095 +extern int squashfs_uncompress_exit(void);
2096 +
2097 +/*
2098 + * macros to convert each packed bitfield structure from little endian to big
2099 + * endian and vice versa. These are needed when creating or using a filesystem on a
2100 + * machine with different byte ordering to the target architecture.
2101 + *
2102 + */
2103 +
2104 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
2105 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
2106 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
2107 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
2108 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
2109 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
2110 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
2111 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
2112 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
2113 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
2114 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
2115 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
2116 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
2117 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
2118 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
2119 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
2120 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
2121 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
2122 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
2123 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
2124 + SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
2125 +}
2126 +
2127 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
2128 + SQUASHFS_MEMSET(s, d, n);\
2129 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2130 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2131 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
2132 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
2133 +}
2134 +
2135 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
2136 +
2137 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
2138 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
2139 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
2140 +}
2141 +
2142 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
2143 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
2144 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
2145 +}
2146 +
2147 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
2148 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
2149 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
2150 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
2151 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
2152 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
2153 + SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
2154 +}
2155 +
2156 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
2157 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
2158 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
2159 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
2160 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2161 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2162 +}
2163 +
2164 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2165 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2166 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
2167 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2168 +}
2169 +
2170 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2171 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2172 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2173 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
2174 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
2175 +}
2176 +
2177 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2178 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2179 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2180 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
2181 +}
2182 +
2183 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2184 + int entry;\
2185 + int bit_position;\
2186 + SQUASHFS_MEMSET(s, d, n * 2);\
2187 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2188 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2189 +}
2190 +
2191 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2192 + int entry;\
2193 + int bit_position;\
2194 + SQUASHFS_MEMSET(s, d, n * 4);\
2195 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2196 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2197 +}
2198 +
2199 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2200 + int entry;\
2201 + int bit_position;\
2202 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
2203 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2204 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2205 +}
2206 +
2207 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2208 +
2209 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2210 +typedef struct {
2211 + unsigned int inode_type:4;
2212 + unsigned int mode:12; /* protection */
2213 + unsigned int uid:4; /* index into uid table */
2214 + unsigned int guid:4; /* index into guid table */
2215 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2216 +
2217 +typedef struct {
2218 + unsigned int inode_type:4;
2219 + unsigned int mode:12; /* protection */
2220 + unsigned int uid:4; /* index into uid table */
2221 + unsigned int guid:4; /* index into guid table */
2222 + unsigned int type:4;
2223 + unsigned int offset:4;
2224 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2225 +
2226 +typedef struct {
2227 + unsigned int inode_type:4;
2228 + unsigned int mode:12; /* protection */
2229 + unsigned int uid:4; /* index into uid table */
2230 + unsigned int guid:4; /* index into guid table */
2231 + unsigned short rdev;
2232 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2233 +
2234 +typedef struct {
2235 + unsigned int inode_type:4;
2236 + unsigned int mode:12; /* protection */
2237 + unsigned int uid:4; /* index into uid table */
2238 + unsigned int guid:4; /* index into guid table */
2239 + unsigned short symlink_size;
2240 + char symlink[0];
2241 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2242 +
2243 +typedef struct {
2244 + unsigned int inode_type:4;
2245 + unsigned int mode:12; /* protection */
2246 + unsigned int uid:4; /* index into uid table */
2247 + unsigned int guid:4; /* index into guid table */
2248 + time_t mtime;
2249 + squashfs_block start_block;
2250 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2251 + unsigned short block_list[0];
2252 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2253 +
2254 +typedef struct {
2255 + unsigned int inode_type:4;
2256 + unsigned int mode:12; /* protection */
2257 + unsigned int uid:4; /* index into uid table */
2258 + unsigned int guid:4; /* index into guid table */
2259 + unsigned int file_size:19;
2260 + unsigned int offset:13;
2261 + time_t mtime;
2262 + unsigned int start_block:24;
2263 +} __attribute__ ((packed)) squashfs_dir_inode_header_1;
2264 +
2265 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2266 + SQUASHFS_MEMSET(s, d, n);\
2267 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2268 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2269 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2270 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2271 +}
2272 +
2273 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2274 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2275 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
2276 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2277 +}
2278 +
2279 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2280 + SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2281 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2282 +}
2283 +
2284 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2285 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2286 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2287 +}
2288 +
2289 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2290 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2291 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2292 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2293 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2294 +}
2295 +
2296 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2297 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2298 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2299 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2300 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2301 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2302 +}
2303 +#endif
2304 +
2305 +#ifdef __KERNEL__
2306 +/*
2307 + * macros used to swap each structure entry, taking into account
2308 + * bitfields and different bitfield placing conventions on differing architectures
2309 + */
2310 +#include <asm/byteorder.h>
2311 +#ifdef __BIG_ENDIAN
2312 + /* convert from little endian to big endian */
2313 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2314 +#else
2315 + /* convert from big endian to little endian */
2316 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2317 +#endif
2318 +
2319 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2320 + int bits;\
2321 + int b_pos = pos % 8;\
2322 + unsigned long long val = 0;\
2323 + unsigned char *s = (unsigned char *)p + (pos / 8);\
2324 + unsigned char *d = ((unsigned char *) &val) + 7;\
2325 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2326 + *d-- = *s++;\
2327 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2328 +}
2329 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
2330 +#endif
2331 +#endif
2332 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_i.h src/linux/linux/include/linux/squashfs_fs_i.h
2333 --- src/linux/linux.orig/include/linux/squashfs_fs_i.h 1969-12-31 19:00:00.000000000 -0500
2334 +++ src/linux/linux/include/linux/squashfs_fs_i.h 2004-05-25 21:13:03.000000000 -0400
2335 @@ -0,0 +1,33 @@
2336 +#ifndef SQUASHFS_FS_I
2337 +#define SQUASHFS_FS_I
2338 +/*
2339 + * Squashfs
2340 + *
2341 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2342 + *
2343 + * This program is free software; you can redistribute it and/or
2344 + * modify it under the terms of the GNU General Public License
2345 + * as published by the Free Software Foundation; either version 2,
2346 + * or (at your option) any later version.
2347 + *
2348 + * This program is distributed in the hope that it will be useful,
2349 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2350 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2351 + * GNU General Public License for more details.
2352 + *
2353 + * You should have received a copy of the GNU General Public License
2354 + * along with this program; if not, write to the Free Software
2355 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2356 + *
2357 + * squashfs_fs_i.h
2358 + */
2359 +
2360 +typedef struct squashfs_inode_info {
2361 + unsigned int start_block;
2362 + unsigned int block_list_start;
2363 + unsigned int offset;
2364 + unsigned int fragment_start_block;
2365 + unsigned int fragment_size;
2366 + unsigned int fragment_offset;
2367 + } squashfs_inode_info;
2368 +#endif
2369 diff -Nurb src/linux/linux.orig/include/linux/squashfs_fs_sb.h src/linux/linux/include/linux/squashfs_fs_sb.h
2370 --- src/linux/linux.orig/include/linux/squashfs_fs_sb.h 1969-12-31 19:00:00.000000000 -0500
2371 +++ src/linux/linux/include/linux/squashfs_fs_sb.h 2004-05-25 21:13:03.000000000 -0400
2372 @@ -0,0 +1,65 @@
2373 +#ifndef SQUASHFS_FS_SB
2374 +#define SQUASHFS_FS_SB
2375 +/*
2376 + * Squashfs
2377 + *
2378 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2379 + *
2380 + * This program is free software; you can redistribute it and/or
2381 + * modify it under the terms of the GNU General Public License
2382 + * as published by the Free Software Foundation; either version 2,
2383 + * or (at your option) any later version.
2384 + *
2385 + * This program is distributed in the hope that it will be useful,
2386 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2387 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2388 + * GNU General Public License for more details.
2389 + *
2390 + * You should have received a copy of the GNU General Public License
2391 + * along with this program; if not, write to the Free Software
2392 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2393 + *
2394 + * squashfs_fs_sb.h
2395 + */
2396 +
2397 +#include <linux/squashfs_fs.h>
2398 +
2399 +typedef struct {
2400 + unsigned int block;
2401 + int length;
2402 + unsigned int next_index;
2403 + char *data;
2404 + } squashfs_cache;
2405 +
2406 +struct squashfs_fragment_cache {
2407 + unsigned int block;
2408 + int length;
2409 + unsigned int locked;
2410 + char *data;
2411 + };
2412 +
2413 +typedef struct squashfs_sb_info {
2414 + squashfs_super_block sBlk;
2415 + int devblksize;
2416 + int devblksize_log2;
2417 + int swap;
2418 + squashfs_cache *block_cache;
2419 + struct squashfs_fragment_cache *fragment;
2420 + int next_cache;
2421 + int next_fragment;
2422 + squashfs_uid *uid;
2423 + squashfs_uid *guid;
2424 + squashfs_fragment_index *fragment_index;
2425 + unsigned int read_size;
2426 + char *read_data;
2427 + char *read_page;
2428 + struct semaphore read_page_mutex;
2429 + struct semaphore block_cache_mutex;
2430 + struct semaphore fragment_mutex;
2431 + wait_queue_head_t waitq;
2432 + wait_queue_head_t fragment_wait_queue;
2433 + struct inode *(*iget)(struct super_block *s, squashfs_inode inode);
2434 + unsigned int (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2435 + char *block_list, char **block_p, unsigned int *bsize);
2436 + } squashfs_sb_info;
2437 +#endif
2438 diff -Nurb src/linux/linux.orig/init/do_mounts.c src/linux/linux/init/do_mounts.c
2439 --- src/linux/linux.orig/init/do_mounts.c 2003-11-08 03:13:20.000000000 -0500
2440 +++ src/linux/linux/init/do_mounts.c 2004-05-25 21:13:03.000000000 -0400
2441 @@ -16,6 +16,7 @@
2442 #include <linux/ext2_fs.h>
2443 #include <linux/romfs_fs.h>
2444 #include <linux/cramfs_fs.h>
2445 +#include <linux/squashfs_fs.h>
2446
2447 #undef BUILD_CRAMDISK
2448
2449 @@ -470,6 +471,7 @@
2450 * ext2
2451 * romfs
2452 * gzip
2453 + * squashfs
2454 */
2455 static int __init
2456 identify_ramdisk_image(int fd, int start_block)
2457 @@ -479,6 +481,7 @@
2458 struct ext2_super_block *ext2sb;
2459 struct romfs_super_block *romfsb;
2460 struct cramfs_super *cramfsb;
2461 + struct squashfs_super_block *squashfsb;
2462 int nblocks = -1;
2463 unsigned char *buf;
2464
2465 @@ -490,6 +493,7 @@
2466 ext2sb = (struct ext2_super_block *) buf;
2467 romfsb = (struct romfs_super_block *) buf;
2468 cramfsb = (struct cramfs_super *) buf;
2469 + squashfsb = (struct squashfs_super_block *) buf;
2470 memset(buf, 0xe5, size);
2471
2472 /*
2473 @@ -536,6 +540,15 @@
2474 goto done;
2475 }
2476
2477 + /* squashfs is at block zero too */
2478 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2479 + printk(KERN_NOTICE
2480 + "RAMDISK: squashfs filesystem found at block %d\n",
2481 + start_block);
2482 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2483 + goto done;
2484 + }
2485 +
2486 /*
2487 * Read block 1 to test for minix and ext2 superblock
2488 */
2489 diff -Nurb src/linux/linux.orig/kernel/ksyms.c src/linux/linux/kernel/ksyms.c
2490 --- src/linux/linux.orig/kernel/ksyms.c 2003-07-04 04:12:28.000000000 -0400
2491 +++ src/linux/linux/kernel/ksyms.c 2004-05-25 21:12:24.000000000 -0400
2492 @@ -482,9 +482,9 @@
2493 EXPORT_SYMBOL(simple_strtoull);
2494 EXPORT_SYMBOL(system_utsname); /* UTS data */
2495 EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
2496 -#ifndef __mips__
2497 +//#ifndef __mips__ //bite me. -mbm.
2498 EXPORT_SYMBOL(sys_call_table);
2499 -#endif
2500 +//#endif
2501 EXPORT_SYMBOL(machine_restart);
2502 EXPORT_SYMBOL(machine_halt);
2503 EXPORT_SYMBOL(machine_power_off);
2504 diff -Nurb src/linux/linux.orig/lib/Config.in src/linux/linux/lib/Config.in
2505 --- src/linux/linux.orig/lib/Config.in 2003-07-04 04:12:29.000000000 -0400
2506 +++ src/linux/linux/lib/Config.in 2004-05-25 21:13:03.000000000 -0400
2507 @@ -8,12 +8,14 @@
2508 # Do we need the compression support?
2509 #
2510 if [ "$CONFIG_CRAMFS" = "y" -o \
2511 + "$CONFIG_SQUASHFS" = "y" -o \
2512 "$CONFIG_PPP_DEFLATE" = "y" -o \
2513 "$CONFIG_JFFS2_FS" = "y" -o \
2514 "$CONFIG_ZISOFS_FS" = "y" ]; then
2515 define_tristate CONFIG_ZLIB_INFLATE y
2516 else
2517 if [ "$CONFIG_CRAMFS" = "m" -o \
2518 + "$CONFIG_SQUASHFS" = "m" -o \
2519 "$CONFIG_PPP_DEFLATE" = "m" -o \
2520 "$CONFIG_JFFS2_FS" = "m" -o \
2521 "$CONFIG_ZISOFS_FS" = "m" ]; then