]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-wrt-2.4.20/120-openwrt.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-wrt-2.4.20 / 120-openwrt.patch
1
2 #
3 # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
4 #
5
6 --- linux-2.4.20/Makefile~120-openwrt   2005-01-07 02:52:47.163951000 -0500
7 +++ linux-2.4.20/Makefile       2005-01-07 02:54:46.351831784 -0500
8 @@ -17,7 +17,7 @@
9  FINDHPATH      = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net $(HPATH)/math-emu
10  
11  HOSTCC         = gcc
12 -HOSTCFLAGS     = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
13 +HOSTCFLAGS     = -Wall -Wstrict-prototypes -Os -fomit-frame-pointer
14  
15  CROSS_COMPILE  =
16  
17 @@ -88,7 +88,7 @@
18  
19  CPPFLAGS := -D__KERNEL__ -I$(HPATH)
20  
21 -CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
22 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
23           -fno-strict-aliasing -fno-common
24  
25  # Turn on -pg to instrument the kernel with calls to mcount().
26 --- linux-2.4.20/arch/mips/brcm-boards/bcm947xx/setup.c~120-openwrt     2005-01-07 02:52:47.170950000 -0500
27 +++ linux-2.4.20/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-07 02:54:46.351831784 -0500
28 @@ -28,6 +28,7 @@
29  #include <linux/ext2_fs.h>
30  #include <linux/romfs_fs.h>
31  #include <linux/cramfs_fs.h>
32 +#include <linux/squashfs_fs.h>
33  #endif
34  
35  #include <typedefs.h>
36 @@ -169,37 +170,38 @@
37  #ifdef CONFIG_MTD_PARTITIONS
38  
39  static struct mtd_partition bcm947xx_parts[] = {
40 -       { name: "pmon", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
41 +       { name: "pmon", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
42         { name: "linux", offset: 0, size: 0, },
43         { name: "rootfs", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
44         { name: "nvram", offset: 0, size: 0, },
45 +       { name: "OpenWrt", offset: 0, size: 0, },
46         { name: NULL, },
47  };
48  
49 -struct mtd_partition * __init
50 -init_mtd_partitions(struct mtd_info *mtd, size_t size)
51 +
52 +static int __init
53 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
54  {
55 -       struct minix_super_block *minixsb;
56 -       struct ext2_super_block *ext2sb;
57 -       struct romfs_super_block *romfsb;
58         struct cramfs_super *cramfsb;
59 +       struct squashfs_super_block *squashfsb;
60         struct trx_header *trx;
61 +
62         unsigned char buf[512];
63         int off;
64         size_t len;
65  
66 -       minixsb = (struct minix_super_block *) buf;
67 -       ext2sb = (struct ext2_super_block *) buf;
68 -       romfsb = (struct romfs_super_block *) buf;
69         cramfsb = (struct cramfs_super *) buf;
70 +       squashfsb = (struct squashfs_super_block *) buf;
71         trx = (struct trx_header *) buf;
72  
73 -       /* Look at every 64 KB boundary */
74 -       for (off = 0; off < size; off += (64 * 1024)) {
75 +       part->offset = 0;
76 +       part->size = 0;
77 +
78 +       for (off = 0; off < size; off += mtd->erasesize) {
79                 memset(buf, 0xe5, sizeof(buf));
80  
81                 /*
82 -                * Read block 0 to test for romfs and cramfs superblock
83 +                * Read block 0 to test for cramfs superblock
84                  */
85                 if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
86                     len != sizeof(buf))
87 @@ -207,75 +209,105 @@
88  
89                 /* Try looking at TRX header for rootfs offset */
90                 if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
91 -                       bcm947xx_parts[1].offset = off;
92                         if (le32_to_cpu(trx->offsets[1]) > off)
93                                 off = le32_to_cpu(trx->offsets[1]);
94                         continue;
95                 }
96  
97 -               /* romfs is at block zero too */
98 -               if (romfsb->word0 == ROMSB_WORD0 &&
99 -                   romfsb->word1 == ROMSB_WORD1) {
100 -                       printk(KERN_NOTICE
101 -                              "%s: romfs filesystem found at block %d\n",
102 -                              mtd->name, off / BLOCK_SIZE);
103 -                       goto done;
104 -               }
105 -
106 -               /* so is cramfs */
107 +               /* need to find cramfs */
108                 if (cramfsb->magic == CRAMFS_MAGIC) {
109                         printk(KERN_NOTICE
110                                "%s: cramfs filesystem found at block %d\n",
111                                mtd->name, off / BLOCK_SIZE);
112 -                       goto done;
113 -               }
114  
115 -               /*
116 -                * Read block 1 to test for minix and ext2 superblock
117 -                */
118 -               if (MTD_READ(mtd, off + BLOCK_SIZE, sizeof(buf), &len, buf) ||
119 -                   len != sizeof(buf))
120 -                       continue;
121 -
122 -               /* Try minix */
123 -               if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
124 -                   minixsb->s_magic == MINIX_SUPER_MAGIC2) {
125 -                       printk(KERN_NOTICE
126 -                              "%s: Minix filesystem found at block %d\n",
127 -                              mtd->name, off / BLOCK_SIZE);
128 +                       part->size = cramfsb->size;
129                         goto done;
130                 }
131  
132 -               /* Try ext2 */
133 -               if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
134 +               /* or squashfs */
135 +               if (squashfsb->s_magic == SQUASHFS_MAGIC) {
136                         printk(KERN_NOTICE
137 -                              "%s: ext2 filesystem found at block %d\n",
138 +                               "%s: squashfs filesystem found at block %d\n",
139                                mtd->name, off / BLOCK_SIZE);
140 +                       part->size = squashfsb->bytes_used+2048;
141                         goto done;
142                 }
143 -       }
144  
145 +       }
146         printk(KERN_NOTICE
147 -              "%s: Couldn't find valid ROM disk image\n",
148 +              "%s: Couldn't find valid cramfs image\n",
149                mtd->name);
150 +       return -1;
151 +       
152 +done:
153 +       part->offset = off;
154 +       return 0;
155 +}
156 +
157 +
158 +struct mtd_partition * __init
159 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
160 +{
161 +
162 +       bcm947xx_parts[0].offset=0;
163 +       bcm947xx_parts[0].size=256*1024;
164  
165 - done:
166         /* Find and size nvram */
167         bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
168         bcm947xx_parts[3].size = size - bcm947xx_parts[3].offset;
169  
170         /* Find and size rootfs */
171 -       if (off < size) {
172 -               bcm947xx_parts[2].offset = off;
173 -               bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
174 -       }
175 +       //if (off < size) {
176 +       //      bcm947xx_parts[2].offset = off;
177 +       //      bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
178 +       //}
179 +
180 +       /* Find and size rootfs */
181 +       find_root(mtd,size,&bcm947xx_parts[2]);
182 +       
183 +
184  
185         /* Size linux (kernel and rootfs) */
186 +       bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
187         bcm947xx_parts[1].size = bcm947xx_parts[3].offset - bcm947xx_parts[1].offset;
188  
189 +
190 +
191 +       /* calculate leftover flash, and assign it to the jffs partition */
192 +       size_t spot;
193 +       size_t len;
194 +       size_t mask;
195 +       //  get the offset to the end of the root_fs
196 +       spot=bcm947xx_parts[2].offset+bcm947xx_parts[2].size;
197 +       //  round it up to an erase size boundary
198 +    spot+=mtd->erasesize-1;
199 +       //  mask the number to the boundary
200 +       mask=mtd->erasesize;
201 +       mask=mask-1;
202 +       mask=mask^0xffffffff;
203 +       spot&=mask;
204 +       //  length = flashsize - start position - nvram size
205 +       len=size-spot;
206 +       len=len-bcm947xx_parts[3].size;
207 +       
208 +
209 +       bcm947xx_parts[4].offset = spot;
210 +       bcm947xx_parts[4].size = len;
211 +
212 +
213 +
214 +
215         /* Size pmon */
216         bcm947xx_parts[0].size = bcm947xx_parts[1].offset - bcm947xx_parts[0].offset;
217  
218 +       //int x;
219 +       //for(x=0; x<5; x++) {
220 +       //      printk(KERN_NOTICE
221 +       //                 "Partition %d mask_flags %08x\n",
222 +       //                 x,bcm947xx_parts[x].mask_flags);
223 +       //}
224 +
225 +
226         return bcm947xx_parts;
227  }
228  
229 --- linux-2.4.20/drivers/mtd/maps/bcm947xx-flash.c~120-openwrt  2005-01-07 02:52:47.190946000 -0500
230 +++ linux-2.4.20/drivers/mtd/maps/bcm947xx-flash.c      2005-01-07 02:54:46.352831632 -0500
231 @@ -82,7 +82,21 @@
232  
233  void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
234  {
235 +       //memcpy_fromio(to, map->map_priv_1 + from, len);
236 +       if (len==1) {
237         memcpy_fromio(to, map->map_priv_1 + from, len);
238 +       } else {
239 +               int i;
240 +               u16 *dest = (u16 *) to;
241 +               u16 *src  = (u16 *) (map->map_priv_1 + from);
242 +
243 +               for (i = 0; i < (len / 2); i++) {
244 +                       dest[i] = src[i];
245 +               }
246 +
247 +               if (len & 1)
248 +                       *((u8 *)dest+len-1) = src[i] & 0xff;
249 +       }
250  }
251  
252  void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
253 --- linux-2.4.20/drivers/net/Makefile~120-openwrt       2005-01-07 02:52:47.191946000 -0500
254 +++ linux-2.4.20/drivers/net/Makefile   2005-01-07 02:54:46.352831632 -0500
255 @@ -21,7 +21,7 @@
256  list-multi     :=      rcpci.o
257  rcpci-objs     :=      rcpci45.o rclanmtl.o
258  
259 -subdir-m += mac
260 +# subdir-m += mac
261  subdir-m += diag
262  
263  ifeq ($(CONFIG_HW_QOS),y)
264 --- linux-2.4.20/fs/Config.in~120-openwrt       2002-11-28 18:53:15.000000000 -0500
265 +++ linux-2.4.20/fs/Config.in   2005-01-07 02:54:46.352831632 -0500
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 --- linux-2.4.20/fs/Makefile~120-openwrt        2002-11-28 18:53:15.000000000 -0500
275 +++ linux-2.4.20/fs/Makefile    2005-01-07 02:54:46.353831480 -0500
276 @@ -68,6 +68,7 @@
277  subdir-$(CONFIG_SUN_OPENPROMFS)        += openpromfs
278  subdir-$(CONFIG_BEFS_FS)       += befs
279  subdir-$(CONFIG_JFS_FS)                += jfs
280 +subdir-$(CONFIG_SQUASHFS)      += squashfs
281  
282  
283  obj-$(CONFIG_BINFMT_AOUT)      += binfmt_aout.o
284 --- /dev/null   2004-04-06 13:56:48.000000000 -0400
285 +++ linux-2.4.20/fs/squashfs/Makefile   2005-01-07 02:54:46.353831480 -0500
286 @@ -0,0 +1,11 @@
287 +#
288 +# Makefile for the linux squashfs routines.
289 +#
290 +
291 +O_TARGET := squashfs.o
292 +
293 +obj-y  := inode.o
294 +
295 +obj-m := $(O_TARGET)
296 +
297 +include $(TOPDIR)/Rules.make
298 --- /dev/null   2004-04-06 13:56:48.000000000 -0400
299 +++ linux-2.4.20/fs/squashfs/inode.c    2005-01-07 02:54:46.355831176 -0500
300 @@ -0,0 +1,1515 @@
301 +/*
302 + * Squashfs - a compressed read only filesystem for Linux
303 + *
304 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
305 + *
306 + * This program is free software; you can redistribute it and/or
307 + * modify it under the terms of the GNU General Public License
308 + * as published by the Free Software Foundation; either version 2,
309 + * or (at your option) any later version.
310 + *
311 + * This program is distributed in the hope that it will be useful,
312 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
313 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
314 + * GNU General Public License for more details.
315 + *
316 + * You should have received a copy of the GNU General Public License
317 + * along with this program; if not, write to the Free Software
318 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
319 + * Squashfs - a compressed read only filesystem for Linux
320 + *
321 + * inode.c
322 + */
323 +
324 +#define SQUASHFS_1_0_COMPATIBILITY
325 +
326 +#include <linux/types.h>
327 +#include <linux/squashfs_fs.h>
328 +#include <linux/module.h>
329 +#include <linux/errno.h>
330 +#include <linux/slab.h>
331 +#include <linux/fs.h>
332 +#include <linux/locks.h>
333 +#include <linux/init.h>
334 +#include <linux/dcache.h>
335 +#include <asm/uaccess.h>
336 +#include <linux/wait.h>
337 +#include <asm/semaphore.h>
338 +#include <linux/zlib.h>
339 +#include <linux/blkdev.h>
340 +#include <linux/vmalloc.h>
341 +
342 +#ifdef SQUASHFS_TRACE
343 +#define TRACE(s, args...)                              printk(KERN_NOTICE "SQUASHFS: "s, ## args)
344 +#else
345 +#define TRACE(s, args...)                              {}
346 +#endif
347 +
348 +#define ERROR(s, args...)                              printk(KERN_ERR "SQUASHFS error: "s, ## args)
349 +
350 +#define SERROR(s, args...)                             if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
351 +#define WARNING(s, args...)                            printk(KERN_WARNING "SQUASHFS: "s, ## args)
352 +
353 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
354 +static void squashfs_put_super(struct super_block *);
355 +static int squashfs_statfs(struct super_block *, struct statfs *);
356 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
357 +static int squashfs_readpage(struct file *file, struct page *page);
358 +static int squashfs_readpage4K(struct file *file, struct page *page);
359 +static int squashfs_readdir(struct file *, void *, filldir_t);
360 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
361 +static unsigned int read_data(struct super_block *s, char *buffer,
362 +               unsigned int index, unsigned int length, int, unsigned int *next_index);
363 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
364 +               unsigned int block, unsigned int offset, int length,
365 +               unsigned int *next_block, unsigned int *next_offset);
366 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
367 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
368 +               char *block_list, char **block_p, unsigned int *bsize);
369 +static void squashfs_put_super(struct super_block *s);
370 +
371 +#ifdef SQUASHFS_1_0_COMPATIBILITY
372 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page);
373 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode);
374 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
375 +               char *block_list, char **block_p, unsigned int *bsize);
376 +#endif
377 +
378 +DECLARE_MUTEX(read_data_mutex);
379 +
380 +static z_stream stream;
381 +
382 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
383 +
384 +static unsigned char squashfs_filetype_table[] = {
385 +       DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
386 +};
387 +
388 +static struct super_operations squashfs_ops = {
389 +       statfs: squashfs_statfs,
390 +       put_super: squashfs_put_super,
391 +};
392 +
393 +static struct address_space_operations squashfs_symlink_aops = {
394 +       readpage: squashfs_symlink_readpage
395 +};
396 +
397 +static struct address_space_operations squashfs_aops = {
398 +       readpage: squashfs_readpage
399 +};
400 +
401 +static struct address_space_operations squashfs_aops_4K = {
402 +       readpage: squashfs_readpage4K
403 +};
404 +
405 +#ifdef SQUASHFS_1_0_COMPATIBILITY
406 +static struct address_space_operations squashfs_aops_lessthan4K = {
407 +       readpage: squashfs_readpage_lessthan4K
408 +};
409 +#endif
410 +
411 +static struct file_operations squashfs_dir_ops = {
412 +       read: generic_read_dir,
413 +       readdir: squashfs_readdir
414 +};
415 +
416 +static struct inode_operations squashfs_dir_inode_ops = {
417 +       lookup: squashfs_lookup
418 +};
419 +
420 +
421 +static unsigned int read_data(struct super_block *s, char *buffer,
422 +               unsigned int index, unsigned int length, int datablock, unsigned int *next_index)
423 +{
424 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
425 +       struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
426 +       unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
427 +       unsigned int cur_index = index >> msBlk->devblksize_log2;
428 +       int bytes, avail_bytes, b, k;
429 +       char *c_buffer;
430 +       unsigned int compressed;
431 +       unsigned int c_byte = length;
432 +
433 +       if(c_byte) {
434 +               bytes = msBlk->devblksize - offset;
435 +               if(datablock) {
436 +                       c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
437 +                       c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
438 +               } else {
439 +                       c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
440 +                       c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
441 +               }
442 +
443 +               TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
444 +
445 +               if(!(bh[0] = sb_getblk(s, cur_index)))
446 +                       goto block_release;
447 +               for(b = 1; bytes < c_byte; b++) {
448 +                       if(!(bh[b] = sb_getblk(s, ++cur_index)))
449 +                               goto block_release;
450 +                       bytes += msBlk->devblksize;
451 +               }
452 +               ll_rw_block(READ, b, bh);
453 +       } else {
454 +               unsigned short temp;
455 +               if(!(bh[0] = sb_bread(s, cur_index)))
456 +                       goto read_failure;
457 +
458 +               if(msBlk->devblksize - offset == 1) {
459 +                       if(msBlk->swap)
460 +                               ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
461 +                       else
462 +                               ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset));
463 +                       brelse(bh[0]);
464 +                       if(!(bh[0] = sb_bread(s, ++cur_index)))
465 +                               goto read_failure;
466 +                       if(msBlk->swap)
467 +                               ((unsigned char *) &temp)[0] = *((unsigned char *) bh[0]->b_data); 
468 +                       else
469 +                               ((unsigned char *) &temp)[1] = *((unsigned char *) bh[0]->b_data); 
470 +                       c_byte = temp;
471 +                       offset = 1;
472 +               }
473 +               else {
474 +                       if(msBlk->swap) {
475 +                               unsigned short temp;
476 +                               ((unsigned char *) &temp)[1] = *((unsigned char *) (bh[0]->b_data + offset));
477 +                               ((unsigned char *) &temp)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1)); 
478 +                               c_byte = temp;
479 +                       } else
480 +                               c_byte = *((unsigned short *) (bh[0]->b_data + offset));
481 +                       offset += 2;
482 +               }
483 +               if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
484 +                       if(offset == msBlk->devblksize) {
485 +                               brelse(bh[0]);
486 +                               if(!(bh[0] = sb_bread(s, ++cur_index)))
487 +                                       goto read_failure;
488 +                               offset = 0;
489 +                       }
490 +                       if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
491 +                               ERROR("Metadata block marker corrupt @ %x\n", index);
492 +                               brelse(bh[0]);
493 +                               return 0;
494 +                       }
495 +                       offset ++;
496 +               }
497 +
498 +               bytes = msBlk->devblksize - offset;
499 +               if(datablock) {
500 +                       c_buffer = (compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte)) ? msBlk->read_data : buffer;
501 +                       c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
502 +               } else {
503 +                       c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
504 +                       c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
505 +               }
506 +
507 +               TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
508 +
509 +               for(b = 1; bytes < c_byte; b++) {
510 +                       if(!(bh[b] = sb_getblk(s, ++cur_index)))
511 +                               goto block_release;
512 +                       bytes += msBlk->devblksize;
513 +               }
514 +               ll_rw_block(READ, b - 1, bh + 1);
515 +       }
516 +
517 +       if(compressed)
518 +               down(&read_data_mutex);
519 +
520 +       for(bytes = 0, k = 0; k < b; k++) {
521 +               avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
522 +               wait_on_buffer(bh[k]);
523 +               memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
524 +               bytes += avail_bytes;
525 +               offset = 0;
526 +               brelse(bh[k]);
527 +       }
528 +
529 +       /*
530 +        * uncompress block
531 +        */
532 +       if(compressed) {
533 +               int zlib_err;
534 +
535 +               stream.next_in = c_buffer;
536 +               stream.avail_in = c_byte;
537 +               stream.next_out = buffer;
538 +               stream.avail_out = msBlk->read_size;
539 +               if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
540 +                               ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
541 +                               ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
542 +                       ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
543 +                       bytes = 0;
544 +               } else
545 +                       bytes = stream.total_out;
546 +               up(&read_data_mutex);
547 +       }
548 +
549 +       if(next_index)
550 +               *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
551 +
552 +       return bytes;
553 +
554 +block_release:
555 +       while(--b >= 0) brelse(bh[b]);
556 +
557 +read_failure:
558 +       ERROR("sb_bread failed reading block 0x%x\n", cur_index);
559 +       return 0;
560 +}
561 +
562 +
563 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
564 +               unsigned int block, unsigned int offset, int length,
565 +               unsigned int *next_block, unsigned int *next_offset)
566 +{
567 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
568 +       int n, i, bytes, return_length = length;
569 +       unsigned int next_index;
570 +
571 +       TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
572 +
573 +       for(;;) {
574 +               for(i = 0; i < SQUASHFS_CACHED_BLKS; i++) 
575 +                       if(msBlk->block_cache[i].block == block)
576 +                               break; 
577 +               
578 +               down(&msBlk->block_cache_mutex);
579 +               if(i == SQUASHFS_CACHED_BLKS) {
580 +                       /* read inode header block */
581 +                       for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
582 +                               if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
583 +                                       break;
584 +                       if(n == 0) {
585 +                               up(&msBlk->block_cache_mutex);
586 +                               sleep_on(&msBlk->waitq);
587 +                               continue;
588 +                       }
589 +                       msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
590 +
591 +                       if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
592 +                               if(!(msBlk->block_cache[i].data = (unsigned char *)
593 +                                                       kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
594 +                                       ERROR("Failed to allocate cache block\n");
595 +                                       up(&msBlk->block_cache_mutex);
596 +                                       return 0;
597 +                               }
598 +                       }
599 +       
600 +                       msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
601 +                       up(&msBlk->block_cache_mutex);
602 +                       if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0, 0,
603 +                                                       &next_index))) {
604 +                               ERROR("Unable to read cache block [%x:%x]\n", block, offset);
605 +                               return 0;
606 +                       }
607 +                       down(&msBlk->block_cache_mutex);
608 +                       wake_up(&msBlk->waitq);
609 +                       msBlk->block_cache[i].block = block;
610 +                       msBlk->block_cache[i].next_index = next_index;
611 +                       TRACE("Read cache block [%x:%x]\n", block, offset);
612 +               }
613 +
614 +               if(msBlk->block_cache[i].block != block) {
615 +                       up(&msBlk->block_cache_mutex);
616 +                       continue;
617 +               }
618 +
619 +               if((bytes = msBlk->block_cache[i].length - offset) >= length) {
620 +                       if(buffer)
621 +                               memcpy(buffer, msBlk->block_cache[i].data + offset, length);
622 +                       if(msBlk->block_cache[i].length - offset == length) {
623 +                               *next_block = msBlk->block_cache[i].next_index;
624 +                               *next_offset = 0;
625 +                       } else {
626 +                               *next_block = block;
627 +                               *next_offset = offset + length;
628 +                       }
629 +       
630 +                       up(&msBlk->block_cache_mutex);
631 +                       return return_length;
632 +               } else {
633 +                       if(buffer) {
634 +                               memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
635 +                               buffer += bytes;
636 +                       }
637 +                       block = msBlk->block_cache[i].next_index;
638 +                       up(&msBlk->block_cache_mutex);
639 +                       length -= bytes;
640 +                       offset = 0;
641 +               }
642 +       }
643 +}
644 +
645 +
646 +static int get_fragment_location(struct super_block *s, unsigned int fragment, unsigned int *fragment_start_block, unsigned int *fragment_size)
647 +{
648 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
649 +       unsigned int start_block = msBlk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
650 +       int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
651 +       squashfs_fragment_entry fragment_entry;
652 +
653 +       if(msBlk->swap) {
654 +               squashfs_fragment_entry sfragment_entry;
655 +
656 +               if(!squashfs_get_cached_block(s, (char *) &sfragment_entry, start_block, offset,
657 +                                       sizeof(sfragment_entry), &start_block, &offset))
658 +                       return 0;
659 +               SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
660 +       } else
661 +               if(!squashfs_get_cached_block(s, (char *) &fragment_entry, start_block, offset,
662 +                                       sizeof(fragment_entry), &start_block, &offset))
663 +                       return 0;
664 +
665 +       *fragment_start_block = fragment_entry.start_block;
666 +       *fragment_size = fragment_entry.size;
667 +
668 +       return 1;
669 +}
670 +
671 +
672 +void release_cached_fragment(squashfs_sb_info *msBlk, struct squashfs_fragment_cache *fragment)
673 +{
674 +       down(&msBlk->fragment_mutex);
675 +       fragment->locked --;
676 +       wake_up(&msBlk->fragment_wait_queue);
677 +       up(&msBlk->fragment_mutex);
678 +}
679 +
680 +
681 +struct squashfs_fragment_cache *get_cached_fragment(struct super_block *s, unsigned int start_block, int length)
682 +{
683 +       int i, n;
684 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
685 +
686 +       for(;;) {
687 +               down(&msBlk->fragment_mutex);
688 +               for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS && msBlk->fragment[i].block != start_block; i++);
689 +               if(i == SQUASHFS_CACHED_FRAGMENTS) {
690 +                       for(i = msBlk->next_fragment, n = SQUASHFS_CACHED_FRAGMENTS;
691 +                               n && msBlk->fragment[i].locked; n--, i = (i + 1) % SQUASHFS_CACHED_FRAGMENTS);
692 +
693 +                       if(n == 0) {
694 +                               up(&msBlk->fragment_mutex);
695 +                               sleep_on(&msBlk->fragment_wait_queue);
696 +                               continue;
697 +                       }
698 +                       msBlk->next_fragment = (msBlk->next_fragment + 1) % SQUASHFS_CACHED_FRAGMENTS;
699 +                       
700 +                       if(msBlk->fragment[i].data == NULL)
701 +                               if(!(msBlk->fragment[i].data = (unsigned char *)
702 +                                                       kmalloc(SQUASHFS_FILE_MAX_SIZE, GFP_KERNEL))) {
703 +                                       ERROR("Failed to allocate fragment cache block\n");
704 +                                       up(&msBlk->fragment_mutex);
705 +                                       return NULL;
706 +                               }
707 +
708 +                       msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
709 +                       msBlk->fragment[i].locked = 1;
710 +                       up(&msBlk->fragment_mutex);
711 +                       if(!(msBlk->fragment[i].length = read_data(s, msBlk->fragment[i].data, start_block, length,
712 +                                                       1, NULL))) {
713 +                               ERROR("Unable to read fragment cache block [%x]\n", start_block);
714 +                               msBlk->fragment[i].locked = 0;
715 +                               return NULL;
716 +                       }
717 +                       msBlk->fragment[i].block = start_block;
718 +                       TRACE("New fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
719 +                       return &msBlk->fragment[i];
720 +               }
721 +
722 +               msBlk->fragment[i].locked ++;
723 +               up(&msBlk->fragment_mutex);
724 +               
725 +               TRACE("Got fragment %d, start block %d, locked %d\n", i, msBlk->fragment[i].block, msBlk->fragment[i].locked);
726 +               return &msBlk->fragment[i];
727 +       }
728 +}
729 +
730 +
731 +#ifdef SQUASHFS_1_0_COMPATIBILITY
732 +static struct inode *squashfs_iget_1(struct super_block *s, squashfs_inode inode)
733 +{
734 +       struct inode *i = new_inode(s);
735 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
736 +       squashfs_super_block *sBlk = &msBlk->sBlk;
737 +       unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
738 +       unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
739 +       unsigned int next_block, next_offset;
740 +       squashfs_base_inode_header_1 inodeb;
741 +
742 +       TRACE("Entered squashfs_iget_1\n");
743 +
744 +       if(msBlk->swap) {
745 +               squashfs_base_inode_header_1 sinodeb;
746 +
747 +               if(!squashfs_get_cached_block(s, (char *) &sinodeb, block,  offset,
748 +                                       sizeof(sinodeb), &next_block, &next_offset))
749 +                       goto failed_read;
750 +               SQUASHFS_SWAP_BASE_INODE_HEADER_1(&inodeb, &sinodeb, sizeof(sinodeb));
751 +       } else
752 +               if(!squashfs_get_cached_block(s, (char *) &inodeb, block,  offset,
753 +                                       sizeof(inodeb), &next_block, &next_offset))
754 +                       goto failed_read;
755 +
756 +       i->i_nlink = 1;
757 +
758 +       i->i_mtime = sBlk->mkfs_time;
759 +       i->i_atime = sBlk->mkfs_time;
760 +       i->i_ctime = sBlk->mkfs_time;
761 +
762 +       if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
763 +               i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
764 +       i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
765 +
766 +       i->i_mode = inodeb.mode;
767 +
768 +       switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
769 +               case SQUASHFS_FILE_TYPE: {
770 +                       squashfs_reg_inode_header_1 inodep;
771 +
772 +                       if(msBlk->swap) {
773 +                               squashfs_reg_inode_header_1 sinodep;
774 +
775 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
776 +                                                       &next_block, &next_offset))
777 +                                       goto failed_read;
778 +                               SQUASHFS_SWAP_REG_INODE_HEADER_1(&inodep, &sinodep);
779 +                       } else
780 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
781 +                                                       &next_block, &next_offset))
782 +                                       goto failed_read;
783 +
784 +                       i->i_size = inodep.file_size;
785 +                       i->i_fop = &generic_ro_fops;
786 +                       if(sBlk->block_size > 4096)
787 +                               i->i_data.a_ops = &squashfs_aops;
788 +                       else if(sBlk->block_size == 4096)
789 +                               i->i_data.a_ops = &squashfs_aops_4K;
790 +                       else
791 +                               i->i_data.a_ops = &squashfs_aops_lessthan4K;
792 +                       i->i_mode |= S_IFREG;
793 +                       i->i_mtime = inodep.mtime;
794 +                       i->i_atime = inodep.mtime;
795 +                       i->i_ctime = inodep.mtime;
796 +                       i->i_blocks = ((i->i_size - 1) >> 9) + 1;
797 +                       i->i_blksize = PAGE_CACHE_SIZE;
798 +                       i->u.squashfs_i.fragment_start_block = SQUASHFS_INVALID_BLK;
799 +                       i->u.squashfs_i.fragment_offset = 0;
800 +                       i->u.squashfs_i.start_block = inodep.start_block;
801 +                       i->u.squashfs_i.block_list_start = next_block;
802 +                       i->u.squashfs_i.offset = next_offset;
803 +                       TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
804 +                                       SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
805 +                       break;
806 +               }
807 +               case SQUASHFS_DIR_TYPE: {
808 +                       squashfs_dir_inode_header_1 inodep;
809 +
810 +                       if(msBlk->swap) {
811 +                               squashfs_dir_inode_header_1 sinodep;
812 +
813 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
814 +                                                       &next_block, &next_offset))
815 +                                       goto failed_read;
816 +                               SQUASHFS_SWAP_DIR_INODE_HEADER_1(&inodep, &sinodep);
817 +                       } else
818 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
819 +                                                       &next_block, &next_offset))
820 +                                       goto failed_read;
821 +
822 +                       i->i_size = inodep.file_size;
823 +                       i->i_op = &squashfs_dir_inode_ops;
824 +                       i->i_fop = &squashfs_dir_ops;
825 +                       i->i_mode |= S_IFDIR;
826 +                       i->i_mtime = inodep.mtime;
827 +                       i->i_atime = inodep.mtime;
828 +                       i->i_ctime = inodep.mtime;
829 +                       i->u.squashfs_i.start_block = inodep.start_block;
830 +                       i->u.squashfs_i.offset = inodep.offset;
831 +                       TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
832 +                                       inodep.start_block, inodep.offset);
833 +                       break;
834 +               }
835 +               case SQUASHFS_SYMLINK_TYPE: {
836 +                       squashfs_symlink_inode_header_1 inodep;
837 +       
838 +                       if(msBlk->swap) {
839 +                               squashfs_symlink_inode_header_1 sinodep;
840 +
841 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
842 +                                                       &next_block, &next_offset))
843 +                                       goto failed_read;
844 +                               SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(&inodep, &sinodep);
845 +                       } else
846 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
847 +                                                       &next_block, &next_offset))
848 +                                       goto failed_read;
849 +
850 +                       i->i_size = inodep.symlink_size;
851 +                       i->i_op = &page_symlink_inode_operations;
852 +                       i->i_data.a_ops = &squashfs_symlink_aops;
853 +                       i->i_mode |= S_IFLNK;
854 +                       i->u.squashfs_i.start_block = next_block;
855 +                       i->u.squashfs_i.offset = next_offset;
856 +                       TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
857 +                               SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
858 +                       break;
859 +                }
860 +                case SQUASHFS_BLKDEV_TYPE:
861 +                case SQUASHFS_CHRDEV_TYPE: {
862 +                       squashfs_dev_inode_header_1 inodep;
863 +
864 +                       if(msBlk->swap) {
865 +                               squashfs_dev_inode_header_1 sinodep;
866 +
867 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
868 +                                                       &next_block, &next_offset))
869 +                                       goto failed_read;
870 +                               SQUASHFS_SWAP_DEV_INODE_HEADER_1(&inodep, &sinodep);
871 +                       } else  
872 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
873 +                                                       &next_block, &next_offset))
874 +                                       goto failed_read;
875 +
876 +                       i->i_size = 0;
877 +                       i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
878 +                       init_special_inode(i, i->i_mode, inodep.rdev);
879 +                       TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
880 +                       break;
881 +                }
882 +                case SQUASHFS_IPC_TYPE: {
883 +                       squashfs_ipc_inode_header_1 inodep;
884 +
885 +                       if(msBlk->swap) {
886 +                               squashfs_ipc_inode_header_1 sinodep;
887 +
888 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
889 +                                                       &next_block, &next_offset))
890 +                                       goto failed_read;
891 +                               SQUASHFS_SWAP_IPC_INODE_HEADER_1(&inodep, &sinodep);
892 +                       } else  
893 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
894 +                                                       &next_block, &next_offset))
895 +                                       goto failed_read;
896 +
897 +                       i->i_size = 0;
898 +                       i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
899 +                       i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
900 +                       init_special_inode(i, i->i_mode, 0);
901 +                       break;
902 +                }
903 +                default:
904 +                       ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
905 +                               goto failed_read1;
906 +       }
907 +       
908 +       if(inodeb.guid == SQUASHFS_GUIDS)
909 +               i->i_gid = i->i_uid;
910 +       else
911 +               i->i_gid = msBlk->guid[inodeb.guid];
912 +
913 +       return i;
914 +
915 +failed_read:
916 +       ERROR("Unable to read inode [%x:%x]\n", block, offset);
917 +
918 +failed_read1:
919 +       return NULL;
920 +}
921 +#endif
922 +
923 +
924 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
925 +{
926 +       struct inode *i = new_inode(s);
927 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
928 +       squashfs_super_block *sBlk = &msBlk->sBlk;
929 +       unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
930 +       unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
931 +       unsigned int next_block, next_offset;
932 +       squashfs_base_inode_header inodeb;
933 +
934 +       TRACE("Entered squashfs_iget\n");
935 +
936 +       if(msBlk->swap) {
937 +               squashfs_base_inode_header sinodeb;
938 +
939 +               if(!squashfs_get_cached_block(s, (char *) &sinodeb, block,  offset,
940 +                                       sizeof(sinodeb), &next_block, &next_offset))
941 +                       goto failed_read;
942 +               SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
943 +       } else
944 +               if(!squashfs_get_cached_block(s, (char *) &inodeb, block,  offset,
945 +                                       sizeof(inodeb), &next_block, &next_offset))
946 +                       goto failed_read;
947 +
948 +       i->i_nlink = 1;
949 +
950 +       i->i_mtime = sBlk->mkfs_time;
951 +       i->i_atime = sBlk->mkfs_time;
952 +       i->i_ctime = sBlk->mkfs_time;
953 +
954 +       if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
955 +               i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
956 +       i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
957 +
958 +       i->i_mode = inodeb.mode;
959 +
960 +       switch(inodeb.inode_type) {
961 +               case SQUASHFS_FILE_TYPE: {
962 +                       squashfs_reg_inode_header inodep;
963 +
964 +                       if(msBlk->swap) {
965 +                               squashfs_reg_inode_header sinodep;
966 +
967 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
968 +                                                       &next_block, &next_offset))
969 +                                       goto failed_read;
970 +                               SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
971 +                       } else
972 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
973 +                                                       &next_block, &next_offset))
974 +                                       goto failed_read;
975 +
976 +                       i->u.squashfs_i.fragment_start_block = SQUASHFS_INVALID_BLK;
977 +                       if(inodep.fragment != SQUASHFS_INVALID_BLK && !get_fragment_location(s, inodep.fragment,
978 +                                                       &i->u.squashfs_i.fragment_start_block, &i->u.squashfs_i.fragment_size))
979 +                               goto failed_read;
980 +
981 +                       i->u.squashfs_i.fragment_offset = inodep.offset;
982 +                       i->i_size = inodep.file_size;
983 +                       i->i_fop = &generic_ro_fops;
984 +                       if(sBlk->block_size > 4096)
985 +                               i->i_data.a_ops = &squashfs_aops;
986 +                       else
987 +                               i->i_data.a_ops = &squashfs_aops_4K;
988 +                       i->i_mode |= S_IFREG;
989 +                       i->i_mtime = inodep.mtime;
990 +                       i->i_atime = inodep.mtime;
991 +                       i->i_ctime = inodep.mtime;
992 +                       i->i_blocks = ((i->i_size - 1) >> 9) + 1;
993 +                       i->i_blksize = PAGE_CACHE_SIZE;
994 +                       i->u.squashfs_i.start_block = inodep.start_block;
995 +                       i->u.squashfs_i.block_list_start = next_block;
996 +                       i->u.squashfs_i.offset = next_offset;
997 +                       TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x fragment_index %x fragment_offset %x\n",
998 +                                       SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset, inodep.fragment, inodep.offset);
999 +                       break;
1000 +               }
1001 +               case SQUASHFS_DIR_TYPE: {
1002 +                       squashfs_dir_inode_header inodep;
1003 +
1004 +                       if(msBlk->swap) {
1005 +                               squashfs_dir_inode_header sinodep;
1006 +
1007 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
1008 +                                                       &next_block, &next_offset))
1009 +                                       goto failed_read;
1010 +                               SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
1011 +                       } else
1012 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
1013 +                                                       &next_block, &next_offset))
1014 +                                       goto failed_read;
1015 +
1016 +                       i->i_size = inodep.file_size;
1017 +                       i->i_op = &squashfs_dir_inode_ops;
1018 +                       i->i_fop = &squashfs_dir_ops;
1019 +                       i->i_mode |= S_IFDIR;
1020 +                       i->i_mtime = inodep.mtime;
1021 +                       i->i_atime = inodep.mtime;
1022 +                       i->i_ctime = inodep.mtime;
1023 +                       i->u.squashfs_i.start_block = inodep.start_block;
1024 +                       i->u.squashfs_i.offset = inodep.offset;
1025 +                       TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
1026 +                                       inodep.start_block, inodep.offset);
1027 +                       break;
1028 +               }
1029 +               case SQUASHFS_SYMLINK_TYPE: {
1030 +                       squashfs_symlink_inode_header inodep;
1031 +       
1032 +                       if(msBlk->swap) {
1033 +                               squashfs_symlink_inode_header sinodep;
1034 +
1035 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
1036 +                                                       &next_block, &next_offset))
1037 +                                       goto failed_read;
1038 +                               SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
1039 +                       } else
1040 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
1041 +                                                       &next_block, &next_offset))
1042 +                                       goto failed_read;
1043 +
1044 +                       i->i_size = inodep.symlink_size;
1045 +                       i->i_op = &page_symlink_inode_operations;
1046 +                       i->i_data.a_ops = &squashfs_symlink_aops;
1047 +                       i->i_mode |= S_IFLNK;
1048 +                       i->u.squashfs_i.start_block = next_block;
1049 +                       i->u.squashfs_i.offset = next_offset;
1050 +                       TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
1051 +                               SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
1052 +                       break;
1053 +                }
1054 +                case SQUASHFS_BLKDEV_TYPE:
1055 +                case SQUASHFS_CHRDEV_TYPE: {
1056 +                       squashfs_dev_inode_header inodep;
1057 +
1058 +                       if(msBlk->swap) {
1059 +                               squashfs_dev_inode_header sinodep;
1060 +
1061 +                               if(!squashfs_get_cached_block(s, (char *) &sinodep, block,  offset, sizeof(sinodep),
1062 +                                                       &next_block, &next_offset))
1063 +                                       goto failed_read;
1064 +                               SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
1065 +                       } else  
1066 +                               if(!squashfs_get_cached_block(s, (char *) &inodep, block,  offset, sizeof(inodep),
1067 +                                                       &next_block, &next_offset))
1068 +                                       goto failed_read;
1069 +
1070 +                       i->i_size = 0;
1071 +                       i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
1072 +                       init_special_inode(i, i->i_mode, inodep.rdev);
1073 +                       TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
1074 +                       break;
1075 +                }
1076 +                case SQUASHFS_FIFO_TYPE:
1077 +                case SQUASHFS_SOCKET_TYPE: {
1078 +                       i->i_size = 0;
1079 +                       i->i_mode |= (inodeb.inode_type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
1080 +                       init_special_inode(i, i->i_mode, 0);
1081 +                       break;
1082 +                }
1083 +                default:
1084 +                       ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
1085 +                               goto failed_read1;
1086 +       }
1087 +       
1088 +       if(inodeb.guid == SQUASHFS_GUIDS)
1089 +               i->i_gid = i->i_uid;
1090 +       else
1091 +               i->i_gid = msBlk->guid[inodeb.guid];
1092 +
1093 +       return i;
1094 +
1095 +failed_read:
1096 +       ERROR("Unable to read inode [%x:%x]\n", block, offset);
1097 +
1098 +failed_read1:
1099 +       return NULL;
1100 +}
1101 +
1102 +
1103 +static struct super_block *squashfs_read_super(struct super_block *s,
1104 +               void *data, int silent)
1105 +{
1106 +       kdev_t dev = s->s_dev;
1107 +       squashfs_sb_info *msBlk = &s->u.squashfs_sb;
1108 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1109 +       int i;
1110 +
1111 +       TRACE("Entered squashfs_read_superblock\n");
1112 +
1113 +       msBlk->devblksize = get_hardsect_size(dev);
1114 +       if(msBlk->devblksize < BLOCK_SIZE)
1115 +               msBlk->devblksize = BLOCK_SIZE;
1116 +       msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
1117 +       set_blocksize(dev, msBlk->devblksize);
1118 +       s->s_blocksize = msBlk->devblksize;
1119 +       s->s_blocksize_bits = msBlk->devblksize_log2;
1120 +
1121 +       init_MUTEX(&msBlk->read_page_mutex);
1122 +       init_MUTEX(&msBlk->block_cache_mutex);
1123 +       init_MUTEX(&msBlk->fragment_mutex);
1124 +       
1125 +       init_waitqueue_head(&msBlk->waitq);
1126 +       init_waitqueue_head(&msBlk->fragment_wait_queue);
1127 +
1128 +       if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1129 +               SERROR("unable to read superblock\n");
1130 +               goto failed_mount;
1131 +       }
1132 +
1133 +       /* Check it is a SQUASHFS superblock */
1134 +       msBlk->swap = 0;
1135 +       if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
1136 +               if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
1137 +                       squashfs_super_block sblk;
1138 +                       WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
1139 +                       SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
1140 +                       memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
1141 +                       msBlk->swap = 1;
1142 +               } else  {
1143 +                       SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
1144 +                       goto failed_mount;
1145 +               }
1146 +       }
1147 +
1148 +       /* Check the MAJOR & MINOR versions */
1149 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1150 +       if((sBlk->s_major != 1) && (sBlk->s_major != 2 || sBlk->s_minor > SQUASHFS_MINOR)) {
1151 +               SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (1 : x) or (2 : <= %d)\n",
1152 +                               sBlk->s_major, sBlk->s_minor, SQUASHFS_MINOR);
1153 +               goto failed_mount;
1154 +       }
1155 +       if(sBlk->s_major == 1)
1156 +               sBlk->block_size = sBlk->block_size_1;
1157 +#else
1158 +       if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
1159 +               SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
1160 +                               sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
1161 +               goto failed_mount;
1162 +       }
1163 +#endif
1164 +
1165 +       TRACE("Found valid superblock on %s\n", bdevname(dev));
1166 +       TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
1167 +       TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
1168 +       TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
1169 +       TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
1170 +       TRACE("Block size %d\n", sBlk->block_size);
1171 +       TRACE("Number of inodes %d\n", sBlk->inodes);
1172 +       if(sBlk->s_major > 1)
1173 +               TRACE("Number of fragments %d\n", sBlk->fragments);
1174 +       TRACE("Number of uids %d\n", sBlk->no_uids);
1175 +       TRACE("Number of gids %d\n", sBlk->no_guids);
1176 +       TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
1177 +       TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
1178 +               if(sBlk->s_major > 1)
1179 +       TRACE("sBlk->fragment_table_start %x\n", sBlk->fragment_table_start);
1180 +       TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
1181 +
1182 +       s->s_flags |= MS_RDONLY;
1183 +       s->s_op = &squashfs_ops;
1184 +
1185 +       /* Init inode_table block pointer array */
1186 +       if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1187 +               ERROR("Failed to allocate block cache\n");
1188 +               goto failed_mount;
1189 +       }
1190 +
1191 +       for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1192 +               msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1193 +
1194 +       msBlk->next_cache = 0;
1195 +
1196 +       /* Allocate read_data block */
1197 +       msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
1198 +       if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
1199 +               ERROR("Failed to allocate read_data block\n");
1200 +               goto failed_mount1;
1201 +       }
1202 +
1203 +       /* Allocate read_page block */
1204 +       if(sBlk->block_size > PAGE_CACHE_SIZE && 
1205 +          !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
1206 +               ERROR("Failed to allocate read_page block\n");
1207 +               goto failed_mount2;
1208 +       }
1209 +
1210 +       /* Allocate uid and gid tables */
1211 +       if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
1212 +               sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
1213 +               ERROR("Failed to allocate uid/gid table\n");
1214 +               goto failed_mount3;
1215 +       }
1216 +       msBlk->guid = msBlk->uid + sBlk->no_uids;
1217 +   
1218 +       if(msBlk->swap) {
1219 +               squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
1220 +
1221 +               if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1222 +                               sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1223 +                       SERROR("unable to read uid/gid table\n");
1224 +                       goto failed_mount4;
1225 +               }
1226 +               SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
1227 +       } else
1228 +               if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
1229 +                               sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1230 +                       SERROR("unable to read uid/gid table\n");
1231 +                       goto failed_mount4;
1232 +               }
1233 +
1234 +
1235 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1236 +       if(sBlk->s_major == 1) {
1237 +               msBlk->iget = squashfs_iget_1;
1238 +               msBlk->read_blocklist = read_blocklist_1;
1239 +               msBlk->fragment = (struct squashfs_fragment_cache *) msBlk->fragment_index = NULL;
1240 +               goto allocate_root;
1241 +       }
1242 +#endif
1243 +       msBlk->iget = squashfs_iget;
1244 +       msBlk->read_blocklist = read_blocklist;
1245 +
1246 +       if(!(msBlk->fragment = (struct squashfs_fragment_cache *) kmalloc(sizeof(struct squashfs_fragment_cache) * SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1247 +               ERROR("Failed to allocate fragment block cache\n");
1248 +               goto failed_mount4;
1249 +       }
1250 +
1251 +       for(i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1252 +               msBlk->fragment[i].locked = 0;
1253 +               msBlk->fragment[i].block = SQUASHFS_INVALID_BLK;
1254 +               msBlk->fragment[i].data = NULL;
1255 +       }
1256 +
1257 +       msBlk->next_fragment = 0;
1258 +
1259 +       /* Allocate fragment index table */
1260 +       if(!(msBlk->fragment_index = (squashfs_fragment_index *) kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments), GFP_KERNEL))) {
1261 +               ERROR("Failed to allocate uid/gid table\n");
1262 +               goto failed_mount5;
1263 +       }
1264 +   
1265 +       if(SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) &&
1266 +               !read_data(s, (char *) msBlk->fragment_index, sBlk->fragment_table_start,
1267 +               SQUASHFS_FRAGMENT_INDEX_BYTES(sBlk->fragments) | SQUASHFS_COMPRESSED_BIT, 0, NULL)) {
1268 +                       SERROR("unable to read fragment index table\n");
1269 +                       goto failed_mount6;
1270 +       }
1271 +
1272 +       if(msBlk->swap) {
1273 +               int i;
1274 +               squashfs_fragment_index fragment;
1275 +
1276 +               for(i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments); i++) {
1277 +                       SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment), &msBlk->fragment_index[i], 1);
1278 +                       msBlk->fragment_index[i] = fragment;
1279 +               }
1280 +       }
1281 +
1282 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1283 +allocate_root:
1284 +#endif
1285 +       if(!(s->s_root = d_alloc_root((msBlk->iget)(s, sBlk->root_inode)))) {
1286 +               ERROR("Root inode create failed\n");
1287 +               goto failed_mount5;
1288 +       }
1289 +
1290 +       TRACE("Leaving squashfs_read_super\n");
1291 +       return s;
1292 +
1293 +failed_mount6:
1294 +       kfree(msBlk->fragment_index);
1295 +failed_mount5:
1296 +       kfree(msBlk->fragment);
1297 +failed_mount4:
1298 +       kfree(msBlk->uid);
1299 +failed_mount3:
1300 +       kfree(msBlk->read_page);
1301 +failed_mount2:
1302 +       kfree(msBlk->read_data);
1303 +failed_mount1:
1304 +       kfree(msBlk->block_cache);
1305 +failed_mount:
1306 +       return NULL;
1307 +}
1308 +
1309 +
1310 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
1311 +{
1312 +       squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
1313 +
1314 +       TRACE("Entered squashfs_statfs\n");
1315 +       buf->f_type = SQUASHFS_MAGIC;
1316 +       buf->f_bsize = sBlk->block_size;
1317 +       buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
1318 +       buf->f_bfree = buf->f_bavail = 0;
1319 +       buf->f_files = sBlk->inodes;
1320 +       buf->f_ffree = 0;
1321 +       buf->f_namelen = SQUASHFS_NAME_LEN;
1322 +       return 0;
1323 +}
1324 +
1325 +
1326 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1327 +{
1328 +       struct inode *inode = page->mapping->host;
1329 +       int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1330 +       int block = inode->u.squashfs_i.start_block;
1331 +       int offset = inode->u.squashfs_i.offset;
1332 +       void *pageaddr = kmap(page);
1333 +
1334 +       TRACE("Entered squashfs_symlink_readpage, page index %x, start block %x, offset %x\n",
1335 +               (unsigned int) page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
1336 +
1337 +       for(length = 0; length < index; length += bytes) {
1338 +               if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
1339 +                                       PAGE_CACHE_SIZE, &block, &offset))) {
1340 +                       ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1341 +                       goto skip_read;
1342 +               }
1343 +       }
1344 +
1345 +       if(length != index) {
1346 +               ERROR("(squashfs_symlink_readpage) length != index\n");
1347 +               bytes = 0;
1348 +               goto skip_read;
1349 +       }
1350 +
1351 +       bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
1352 +       if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
1353 +               ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
1354 +
1355 +skip_read:
1356 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1357 +       kunmap(page);
1358 +       flush_dcache_page(page);
1359 +       SetPageUptodate(page);
1360 +       UnlockPage(page);
1361 +
1362 +       return 0;
1363 +}
1364 +
1365 +
1366 +#define SIZE 256
1367 +
1368 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1369 +static unsigned int read_blocklist_1(struct inode *inode, int index, int readahead_blks,
1370 +               char *block_list, char **block_p, unsigned int *bsize)
1371 +{
1372 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1373 +       unsigned short *block_listp;
1374 +       int i = 0;
1375 +       int block_ptr = inode->u.squashfs_i.block_list_start;
1376 +       int offset = inode->u.squashfs_i.offset;
1377 +       int block = inode->u.squashfs_i.start_block;
1378 +
1379 +       for(;;) {
1380 +               int blocks = (index + readahead_blks - i);
1381 +               if(blocks > (SIZE >> 1)) {
1382 +                       if((index - i) <= (SIZE >> 1))
1383 +                               blocks = index - i;
1384 +                       else
1385 +                               blocks = SIZE >> 1;
1386 +               }
1387 +
1388 +               if(msBlk->swap) {
1389 +                       unsigned char sblock_list[SIZE];
1390 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1391 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1392 +                               return 0;
1393 +                       }
1394 +                       SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1395 +               } else
1396 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1397 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1398 +                               return 0;
1399 +                       }
1400 +               for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1401 +                       block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1402 +               if(blocks >= readahead_blks)
1403 +                       break;
1404 +       }
1405 +
1406 +       if(bsize)
1407 +               *bsize = SQUASHFS_COMPRESSED_SIZE(*block_listp) | (!SQUASHFS_COMPRESSED(*block_listp) ? SQUASHFS_COMPRESSED_BIT_BLOCK : 0);
1408 +       else
1409 +               (unsigned short *) *block_p = block_listp;
1410 +       return block;
1411 +}
1412 +#endif
1413 +
1414 +
1415 +
1416 +static unsigned int read_blocklist(struct inode *inode, int index, int readahead_blks,
1417 +               char *block_list, char **block_p, unsigned int *bsize)
1418 +{
1419 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1420 +       unsigned int *block_listp;
1421 +       int i = 0;
1422 +       int block_ptr = inode->u.squashfs_i.block_list_start;
1423 +       int offset = inode->u.squashfs_i.offset;
1424 +       int block = inode->u.squashfs_i.start_block;
1425 +
1426 +       for(;;) {
1427 +               int blocks = (index + readahead_blks - i);
1428 +               if(blocks > (SIZE >> 2)) {
1429 +                       if((index - i) <= (SIZE >> 2))
1430 +                               blocks = index - i;
1431 +                       else
1432 +                               blocks = SIZE >> 2;
1433 +               }
1434 +
1435 +               if(msBlk->swap) {
1436 +                       unsigned char sblock_list[SIZE];
1437 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1438 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1439 +                               return 0;
1440 +                       }
1441 +                       SQUASHFS_SWAP_INTS(((unsigned int *)block_list), ((unsigned int *)sblock_list), blocks);
1442 +               } else
1443 +                       if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 2, &block_ptr, &offset)) {
1444 +                               ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1445 +                               return 0;
1446 +                       }
1447 +               for(block_listp = (unsigned int *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1448 +                       block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1449 +               if(blocks >= readahead_blks)
1450 +                       break;
1451 +       }
1452 +
1453 +       *bsize = *block_listp;
1454 +       return block;
1455 +}
1456 +
1457 +
1458 +static int squashfs_readpage(struct file *file, struct page *page)
1459 +{
1460 +       struct inode *inode = page->mapping->host;
1461 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1462 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1463 +       unsigned char block_list[SIZE];
1464 +       unsigned int bsize, block, i = 0, bytes = 0, byte_offset = 0;
1465 +       int index = page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT);
1466 +       void *pageaddr = kmap(page);
1467 +       struct squashfs_fragment_cache *fragment;
1468 +       char *data_ptr = msBlk->read_page;
1469 +       
1470 +       int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1471 +       int start_index = page->index & ~mask;
1472 +       int end_index = start_index | mask;
1473 +
1474 +       TRACE("Entered squashfs_readpage, page index %x, start block %x\n", (unsigned int) page->index,
1475 +               inode->u.squashfs_i.start_block);
1476 +
1477 +       if(inode->u.squashfs_i.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log)) {
1478 +               if((block = (msBlk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize)) == 0)
1479 +                       goto skip_read;
1480 +
1481 +               down(&msBlk->read_page_mutex);
1482 +               if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, bsize, 1, NULL))) {
1483 +                       ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1484 +                       up(&msBlk->read_page_mutex);
1485 +                       goto skip_read;
1486 +               }
1487 +       } else {
1488 +               if((fragment = get_cached_fragment(inode->i_sb, inode->u.squashfs_i.fragment_start_block, inode->u.squashfs_i.fragment_size)) == NULL) {
1489 +                       ERROR("Unable to read page, block %x, size %x\n", inode->u.squashfs_i.fragment_start_block, (int) inode->u.squashfs_i.fragment_size);
1490 +                       goto skip_read;
1491 +               }
1492 +               bytes = inode->u.squashfs_i.fragment_offset + (inode->i_size & (sBlk->block_size - 1));
1493 +               byte_offset = inode->u.squashfs_i.fragment_offset;
1494 +               data_ptr = fragment->data;
1495 +       }
1496 +
1497 +       for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1498 +               struct page *push_page;
1499 +               int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1500 +
1501 +               TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1502 +
1503 +               if(i == page->index)  {
1504 +                       memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1505 +                       memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1506 +                       kunmap(page);
1507 +                       flush_dcache_page(page);
1508 +                       SetPageUptodate(page);
1509 +                       UnlockPage(page);
1510 +               } else if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1511 +                       void *pageaddr = kmap(push_page);
1512 +                       memcpy(pageaddr, data_ptr + byte_offset, available_bytes);
1513 +                       memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1514 +                       kunmap(push_page);
1515 +                       flush_dcache_page(push_page);
1516 +                       SetPageUptodate(push_page);
1517 +                       UnlockPage(push_page);
1518 +                       page_cache_release(push_page);
1519 +               }
1520 +       }
1521 +
1522 +       if(inode->u.squashfs_i.fragment_start_block == SQUASHFS_INVALID_BLK || index < (inode->i_size >> sBlk->block_log))
1523 +               up(&msBlk->read_page_mutex);
1524 +       else
1525 +               release_cached_fragment(msBlk, fragment);
1526 +
1527 +       return 0;
1528 +
1529 +skip_read:
1530 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1531 +       kunmap(page);
1532 +       flush_dcache_page(page);
1533 +       SetPageUptodate(page);
1534 +       UnlockPage(page);
1535 +
1536 +       return 0;
1537 +}
1538 +
1539 +
1540 +static int squashfs_readpage4K(struct file *file, struct page *page)
1541 +{
1542 +       struct inode *inode = page->mapping->host;
1543 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1544 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1545 +       unsigned char block_list[SIZE];
1546 +       unsigned int bsize, block, bytes = 0;
1547 +       void *pageaddr = kmap(page);
1548 +       
1549 +       TRACE("Entered squashfs_readpage4K, page index %x, start block %x\n", (unsigned int) page->index,
1550 +               inode->u.squashfs_i.start_block);
1551 +
1552 +       if(page->index < (inode->i_size >> sBlk->block_log)) {
1553 +               block = (msBlk->read_blocklist)(inode, page->index, 1, block_list, NULL, &bsize);
1554 +
1555 +               if(!(bytes = read_data(inode->i_sb, pageaddr, block, bsize, 1, NULL)))
1556 +                       ERROR("Unable to read page, block %x, size %x\n", block, bsize);
1557 +       } else {
1558 +               struct squashfs_fragment_cache *fragment;
1559 +
1560 +               if((fragment = get_cached_fragment(inode->i_sb, inode->u.squashfs_i.fragment_start_block, inode->u.squashfs_i.fragment_size)) == NULL)
1561 +                       ERROR("Unable to read page, block %x, size %x\n", inode->u.squashfs_i.fragment_start_block, (int) inode->u.squashfs_i.fragment_size);
1562 +               else {
1563 +                       bytes = inode->i_size & (sBlk->block_size - 1);
1564 +                       memcpy(pageaddr, fragment->data + inode->u.squashfs_i.fragment_offset, bytes);
1565 +                       release_cached_fragment(msBlk, fragment);
1566 +               }
1567 +       }
1568 +
1569 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1570 +       kunmap(page);
1571 +       flush_dcache_page(page);
1572 +       SetPageUptodate(page);
1573 +       UnlockPage(page);
1574 +
1575 +       return 0;
1576 +}
1577 +
1578 +
1579 +#ifdef SQUASHFS_1_0_COMPATIBILITY
1580 +static int squashfs_readpage_lessthan4K(struct file *file, struct page *page)
1581 +{
1582 +       struct inode *inode = page->mapping->host;
1583 +       squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
1584 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1585 +       unsigned char block_list[SIZE];
1586 +       unsigned short *block_listp, block, bytes = 0;
1587 +       int index = page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
1588 +       int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
1589 +       int readahead_blks = 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
1590 +       void *pageaddr = kmap(page);
1591 +       
1592 +       int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1593 +       int byte;
1594 +
1595 +       TRACE("Entered squashfs_readpage_lessthan4K, page index %x, start block %x\n", (unsigned int) page->index,
1596 +               inode->u.squashfs_i.start_block);
1597 +
1598 +       block = read_blocklist_1(inode, index, readahead_blks, block_list, (char **) &block_listp, NULL);
1599 +
1600 +       if(i_end > file_blocks)
1601 +               i_end = file_blocks;
1602 +
1603 +       while(index < i_end) {
1604 +               if(!(byte = read_data(inode->i_sb, pageaddr, block, *block_listp, 0, NULL))) {
1605 +                       ERROR("Unable to read page, block %x, size %x\n", block, *block_listp);
1606 +                       goto skip_read;
1607 +               }
1608 +               block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1609 +               pageaddr += byte;
1610 +               bytes += byte;
1611 +               index ++;
1612 +               block_listp ++;
1613 +       }
1614 +
1615 +skip_read:
1616 +       memset(pageaddr, 0, PAGE_CACHE_SIZE - bytes);
1617 +       kunmap(page);
1618 +       flush_dcache_page(page);
1619 +       SetPageUptodate(page);
1620 +       UnlockPage(page);
1621 +
1622 +       return 0;
1623 +}
1624 +#endif
1625 +
1626 +
1627 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1628 +{
1629 +       struct inode *i = file->f_dentry->d_inode;
1630 +       squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1631 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1632 +       int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1633 +               i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
1634 +       squashfs_dir_header dirh;
1635 +       char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1636 +       squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1637 +
1638 +       TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1639 +
1640 +       while(length < i->i_size) {
1641 +               /* read directory header */
1642 +               if(msBlk->swap) {
1643 +                       squashfs_dir_header sdirh;
1644 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1645 +                                               next_offset, sizeof(sdirh), &next_block, &next_offset))
1646 +                               goto failed_read;
1647 +                       length += sizeof(sdirh);
1648 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1649 +               } else {
1650 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1651 +                                               next_offset, sizeof(dirh), &next_block, &next_offset))
1652 +                               goto failed_read;
1653 +                       length += sizeof(dirh);
1654 +               }
1655 +
1656 +               dir_count = dirh.count + 1;
1657 +               while(dir_count--) {
1658 +                       if(msBlk->swap) {
1659 +                               squashfs_dir_entry sdire;
1660 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1661 +                                                       next_offset, sizeof(sdire), &next_block, &next_offset))
1662 +                                       goto failed_read;
1663 +                               length += sizeof(sdire);
1664 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1665 +                       } else {
1666 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1667 +                                                       next_offset, sizeof(*dire), &next_block, &next_offset))
1668 +                                       goto failed_read;
1669 +                               length += sizeof(*dire);
1670 +                       }
1671 +
1672 +                       if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1673 +                                               next_offset, dire->size + 1, &next_block, &next_offset))
1674 +                               goto failed_read;
1675 +                       length += dire->size + 1;
1676 +
1677 +                       if(file->f_pos >= length)
1678 +                               continue;
1679 +
1680 +                       dire->name[dire->size + 1] = '\0';
1681 +
1682 +                       TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", (unsigned int) dirent,
1683 +                       dire->name, dire->size + 1, (int) file->f_pos,
1684 +                       dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1685 +
1686 +                       if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1687 +                                                       dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1688 +                               TRACE("Filldir returned less than 0\n");
1689 +                               return dirs_read;
1690 +                       }
1691 +
1692 +                       file->f_pos = length;
1693 +                       dirs_read ++;
1694 +               }
1695 +       }
1696 +
1697 +       return dirs_read;
1698 +
1699 +failed_read:
1700 +       ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1701 +       return 0;
1702 +}
1703 +
1704 +
1705 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1706 +{
1707 +       const char *name =dentry->d_name.name;
1708 +       int len = dentry->d_name.len;
1709 +       struct inode *inode = NULL;
1710 +       squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1711 +       squashfs_super_block *sBlk = &msBlk->sBlk;
1712 +       int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1713 +               i->u.squashfs_i.offset, length = 0, dir_count;
1714 +       squashfs_dir_header dirh;
1715 +       char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1716 +       squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1717 +
1718 +       TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1719 +
1720 +       while(length < i->i_size) {
1721 +               /* read directory header */
1722 +               if(msBlk->swap) {
1723 +                       squashfs_dir_header sdirh;
1724 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1725 +                                               sizeof(sdirh), &next_block, &next_offset))
1726 +                               goto failed_read;
1727 +                       length += sizeof(sdirh);
1728 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1729 +               } else {
1730 +                       if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1731 +                                               sizeof(dirh), &next_block, &next_offset))
1732 +                               goto failed_read;
1733 +                       length += sizeof(dirh);
1734 +               }
1735 +
1736 +               dir_count = dirh.count + 1;
1737 +               while(dir_count--) {
1738 +                       if(msBlk->swap) {
1739 +                               squashfs_dir_entry sdire;
1740 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1741 +                                                       next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1742 +                                       goto failed_read;
1743 +                               length += sizeof(sdire);
1744 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1745 +                       } else {
1746 +                               if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1747 +                                                       next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1748 +                                       goto failed_read;
1749 +                               length += sizeof(*dire);
1750 +                       }
1751 +
1752 +                       if(!squashfs_get_cached_block(i->i_sb, dire->name,
1753 +                                               next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1754 +                               goto failed_read;
1755 +                       length += dire->size + 1;
1756 +
1757 +                       if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1758 +                               squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1759 +
1760 +                               TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1761 +                                               name, dirh.start_block, dire->offset);
1762 +
1763 +                               inode = (msBlk->iget)(i->i_sb, ino);
1764 +
1765 +                               goto exit_loop;
1766 +                       }
1767 +               }
1768 +       }
1769 +
1770 +exit_loop:
1771 +       d_add(dentry, inode);
1772 +       return ERR_PTR(0);
1773 +
1774 +failed_read:
1775 +       ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1776 +       goto exit_loop;
1777 +}
1778 +
1779 +
1780 +static void squashfs_put_super(struct super_block *s)
1781 +{
1782 +       if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
1783 +       if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
1784 +       if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
1785 +       if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
1786 +       s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
1787 +               s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
1788 +}
1789 +
1790 +
1791 +static int __init init_squashfs_fs(void)
1792 +{
1793 +
1794 +       if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1795 +               ERROR("Failed to allocate zlib workspace\n");
1796 +               return -ENOMEM;
1797 +       }
1798 +       return register_filesystem(&squashfs_fs_type);
1799 +}
1800 +
1801 +
1802 +static void __exit exit_squashfs_fs(void)
1803 +{
1804 +       vfree(stream.workspace);
1805 +       unregister_filesystem(&squashfs_fs_type);
1806 +}
1807 +
1808 +
1809 +EXPORT_NO_SYMBOLS;
1810 +
1811 +module_init(init_squashfs_fs);
1812 +module_exit(exit_squashfs_fs);
1813 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1814 +MODULE_AUTHOR("Phillip Lougher <plougher@users.sourceforge.net>");
1815 +MODULE_LICENSE("GPL");
1816 --- linux-2.4.20/include/linux/fs.h~120-openwrt 2002-11-28 18:53:15.000000000 -0500
1817 +++ linux-2.4.20/include/linux/fs.h     2005-01-07 02:54:46.357830872 -0500
1818 @@ -320,6 +320,7 @@
1819  #include <linux/usbdev_fs_i.h>
1820  #include <linux/jffs2_fs_i.h>
1821  #include <linux/cramfs_fs_sb.h>
1822 +#include <linux/squashfs_fs_i.h>
1823  
1824  /*
1825   * Attribute flags.  These should be or-ed together to figure out what
1826 @@ -510,6 +511,7 @@
1827                 struct socket                   socket_i;
1828                 struct usbdev_inode_info        usbdev_i;
1829                 struct jffs2_inode_info         jffs2_i;
1830 +               struct squashfs_inode_info      squashfs_i;
1831                 void                            *generic_ip;
1832         } u;
1833  };
1834 @@ -704,6 +706,7 @@
1835  #include <linux/usbdev_fs_sb.h>
1836  #include <linux/cramfs_fs_sb.h>
1837  #include <linux/jffs2_fs_sb.h>
1838 +#include <linux/squashfs_fs_sb.h>
1839  
1840  extern struct list_head super_blocks;
1841  extern spinlock_t sb_lock;
1842 @@ -762,6 +765,7 @@
1843                 struct usbdev_sb_info   usbdevfs_sb;
1844                 struct jffs2_sb_info    jffs2_sb;
1845                 struct cramfs_sb_info   cramfs_sb;
1846 +               struct squashfs_sb_info squashfs_sb;
1847                 void                    *generic_sbp;
1848         } u;
1849         /*
1850 --- /dev/null   2004-04-06 13:56:48.000000000 -0400
1851 +++ linux-2.4.20/include/linux/squashfs_fs.h    2005-01-07 02:54:46.357830872 -0500
1852 @@ -0,0 +1,474 @@
1853 +#ifndef SQUASHFS_FS
1854 +#define SQUASHFS_FS
1855 +/*
1856 + * Squashfs
1857 + *
1858 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
1859 + *
1860 + * This program is free software; you can redistribute it and/or
1861 + * modify it under the terms of the GNU General Public License
1862 + * as published by the Free Software Foundation; either version 2,
1863 + * or (at your option) any later version.
1864 + *
1865 + * This program is distributed in the hope that it will be useful,
1866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1868 + * GNU General Public License for more details.
1869 + *
1870 + * You should have received a copy of the GNU General Public License
1871 + * along with this program; if not, write to the Free Software
1872 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1873 + *
1874 + * squashfs_fs.h
1875 + */
1876 +
1877 +#define SQUASHFS_MAJOR                 2
1878 +#define SQUASHFS_MINOR                 0
1879 +#define SQUASHFS_MAGIC                 0x73717368
1880 +#define SQUASHFS_MAGIC_SWAP            0x68737173
1881 +#define SQUASHFS_START                 0
1882 +
1883 +/* size of metadata (inode and directory) blocks */
1884 +#define SQUASHFS_METADATA_SIZE         8192
1885 +#define SQUASHFS_METADATA_LOG          13
1886 +
1887 +/* default size of data blocks */
1888 +#define SQUASHFS_FILE_SIZE             65536
1889 +#define SQUASHFS_FILE_LOG              16
1890 +
1891 +#define SQUASHFS_FILE_MAX_SIZE         65536
1892 +
1893 +/* Max number of uids and gids */
1894 +#define SQUASHFS_UIDS                  256
1895 +#define SQUASHFS_GUIDS                 255
1896 +
1897 +/* Max length of filename (not 255) */
1898 +#define SQUASHFS_NAME_LEN              256
1899 +
1900 +#define SQUASHFS_INVALID               ((long long) 0xffffffffffff)
1901 +#define SQUASHFS_INVALID_BLK           ((long long) 0xffffffff)
1902 +#define SQUASHFS_USED_BLK              ((long long) 0xfffffffe)
1903 +
1904 +/* Filesystem flags */
1905 +#define SQUASHFS_NOI                   0
1906 +#define SQUASHFS_NOD                   1
1907 +#define SQUASHFS_CHECK                 2
1908 +#define SQUASHFS_NOF                   3
1909 +#define SQUASHFS_NO_FRAG               4
1910 +#define SQUASHFS_ALWAYS_FRAG           5
1911 +#define SQUASHFS_DUPLICATE             6
1912 +#define SQUASHFS_BIT(flag, bit)                ((flag >> bit) & 1)
1913 +#define SQUASHFS_UNCOMPRESSED_INODES(flags)    SQUASHFS_BIT(flags, SQUASHFS_NOI)
1914 +#define SQUASHFS_UNCOMPRESSED_DATA(flags)      SQUASHFS_BIT(flags, SQUASHFS_NOD)
1915 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, SQUASHFS_NOF)
1916 +#define SQUASHFS_NO_FRAGMENTS(flags)           SQUASHFS_BIT(flags, SQUASHFS_NO_FRAG)
1917 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags)       SQUASHFS_BIT(flags, SQUASHFS_ALWAYS_FRAG)
1918 +#define SQUASHFS_DUPLICATES(flags)             SQUASHFS_BIT(flags, SQUASHFS_DUPLICATE)
1919 +#define SQUASHFS_CHECK_DATA(flags)             SQUASHFS_BIT(flags, SQUASHFS_CHECK)
1920 +#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))
1921 +
1922 +/* Max number of types and file types */
1923 +#define SQUASHFS_DIR_TYPE              1
1924 +#define SQUASHFS_FILE_TYPE             2
1925 +#define SQUASHFS_SYMLINK_TYPE          3
1926 +#define SQUASHFS_BLKDEV_TYPE           4
1927 +#define SQUASHFS_CHRDEV_TYPE           5
1928 +#define SQUASHFS_FIFO_TYPE             6
1929 +#define SQUASHFS_SOCKET_TYPE           7
1930 +
1931 +/* 1.0 filesystem type definitions */
1932 +#define SQUASHFS_TYPES                 5
1933 +#define SQUASHFS_IPC_TYPE              0
1934 +
1935 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1936 +#define SQUASHFS_COMPRESSED_BIT                (1 << 15)
1937 +#define SQUASHFS_COMPRESSED_SIZE(B)    (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1938 +                                       (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1939 +
1940 +#define SQUASHFS_COMPRESSED(B)         (!((B) & SQUASHFS_COMPRESSED_BIT))
1941 +
1942 +#define SQUASHFS_COMPRESSED_BIT_BLOCK          (1 << 24)
1943 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)      (((B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? \
1944 +                                       (B) & ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
1945 +
1946 +#define SQUASHFS_COMPRESSED_BLOCK(B)           (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
1947 +
1948 +/*
1949 + * Inode number ops.  Inodes consist of a compressed block number, and an uncompressed
1950 + * offset within that block
1951 + */
1952 +#define SQUASHFS_INODE_BLK(a)          ((unsigned int) ((a) >> 16))
1953 +#define SQUASHFS_INODE_OFFSET(a)       ((unsigned int) ((a) & 0xffff))
1954 +#define SQUASHFS_MKINODE(A, B)         ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1955 +                                       + (B)))
1956 +
1957 +/* Compute 32 bit VFS inode number from squashfs inode number */
1958 +#define SQUASHFS_MK_VFS_INODE(a, b)    ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1959 +
1960 +/* Translate between VFS mode and squashfs mode */
1961 +#define SQUASHFS_MODE(a)               ((a) & 0xfff)
1962 +
1963 +/* fragment and fragment table defines */
1964 +typedef unsigned int                   squashfs_fragment_index;
1965 +#define SQUASHFS_FRAGMENT_BYTES(A)     (A * sizeof(squashfs_fragment_entry))
1966 +#define SQUASHFS_FRAGMENT_INDEX(A)     (SQUASHFS_FRAGMENT_BYTES(A) / SQUASHFS_METADATA_SIZE)
1967 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)      (SQUASHFS_FRAGMENT_BYTES(A) % SQUASHFS_METADATA_SIZE)
1968 +#define SQUASHFS_FRAGMENT_INDEXES(A)   ((SQUASHFS_FRAGMENT_BYTES(A) + SQUASHFS_METADATA_SIZE - 1) / SQUASHFS_METADATA_SIZE)
1969 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)       (SQUASHFS_FRAGMENT_INDEXES(A) * sizeof(squashfs_fragment_index))
1970 +#define SQUASHFS_CACHED_FRAGMENTS      3
1971 +
1972 +/* cached data constants for filesystem */
1973 +#define SQUASHFS_CACHED_BLKS           8
1974 +
1975 +#define SQUASHFS_MAX_FILE_SIZE_LOG     32
1976 +#define SQUASHFS_MAX_FILE_SIZE         ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1977 +
1978 +#define SQUASHFS_MARKER_BYTE           0xff
1979 +
1980 +/*
1981 + * definitions for structures on disk
1982 + */
1983 +
1984 +typedef unsigned int           squashfs_block;
1985 +typedef long long              squashfs_inode;
1986 +
1987 +typedef unsigned int           squashfs_uid;
1988 +
1989 +typedef struct squashfs_super_block {
1990 +       unsigned int            s_magic;
1991 +       unsigned int            inodes;
1992 +       unsigned int            bytes_used;
1993 +       unsigned int            uid_start;
1994 +       unsigned int            guid_start;
1995 +       unsigned int            inode_table_start;
1996 +       unsigned int            directory_table_start;
1997 +       unsigned int            s_major:16;
1998 +       unsigned int            s_minor:16;
1999 +       unsigned int            block_size_1:16;
2000 +       unsigned int            block_log:16;
2001 +       unsigned int            flags:8;
2002 +       unsigned int            no_uids:8;
2003 +       unsigned int            no_guids:8;
2004 +       time_t                  mkfs_time /* time of filesystem creation */;
2005 +       squashfs_inode          root_inode;
2006 +       unsigned int            block_size;
2007 +       unsigned int            fragments;
2008 +       unsigned int            fragment_table_start;
2009 +} __attribute__ ((packed)) squashfs_super_block;
2010 +
2011 +typedef struct {
2012 +       unsigned int            inode_type:4;
2013 +       unsigned int            mode:12; /* protection */
2014 +       unsigned int            uid:8; /* index into uid table */
2015 +       unsigned int            guid:8; /* index into guid table */
2016 +} __attribute__ ((packed)) squashfs_base_inode_header;
2017 +
2018 +typedef squashfs_base_inode_header squashfs_ipc_inode_header;
2019 +
2020 +typedef struct {
2021 +       unsigned int            inode_type:4;
2022 +       unsigned int            mode:12; /* protection */
2023 +       unsigned int            uid:8; /* index into uid table */
2024 +       unsigned int            guid:8; /* index into guid table */
2025 +       unsigned short          rdev;
2026 +} __attribute__ ((packed)) squashfs_dev_inode_header;
2027 +       
2028 +typedef struct {
2029 +       unsigned int            inode_type:4;
2030 +       unsigned int            mode:12; /* protection */
2031 +       unsigned int            uid:8; /* index into uid table */
2032 +       unsigned int            guid:8; /* index into guid table */
2033 +       unsigned short          symlink_size;
2034 +       char                    symlink[0];
2035 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
2036 +
2037 +typedef struct {
2038 +       unsigned int            inode_type:4;
2039 +       unsigned int            mode:12; /* protection */
2040 +       unsigned int            uid:8; /* index into uid table */
2041 +       unsigned int            guid:8; /* index into guid table */
2042 +       time_t                  mtime;
2043 +       squashfs_block          start_block;
2044 +       unsigned int            fragment;
2045 +       unsigned int            offset;
2046 +       unsigned int            file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2047 +       unsigned short          block_list[0];
2048 +} __attribute__ ((packed)) squashfs_reg_inode_header;
2049 +
2050 +typedef struct {
2051 +       unsigned int            inode_type:4;
2052 +       unsigned int            mode:12; /* protection */
2053 +       unsigned int            uid:8; /* index into uid table */
2054 +       unsigned int            guid:8; /* index into guid table */
2055 +       unsigned int            file_size:19;
2056 +       unsigned int            offset:13;
2057 +       time_t                  mtime;
2058 +       unsigned int            start_block:24;
2059 +} __attribute__  ((packed)) squashfs_dir_inode_header;
2060 +
2061 +typedef union {
2062 +       squashfs_base_inode_header      base;
2063 +       squashfs_dev_inode_header       dev;
2064 +       squashfs_symlink_inode_header   symlink;
2065 +       squashfs_reg_inode_header       reg;
2066 +       squashfs_dir_inode_header       dir;
2067 +       squashfs_ipc_inode_header       ipc;
2068 +} squashfs_inode_header;
2069 +       
2070 +typedef struct {
2071 +       unsigned int            offset:13;
2072 +       unsigned int            type:3;
2073 +       unsigned int            size:8;
2074 +       char                    name[0];
2075 +} __attribute__ ((packed)) squashfs_dir_entry;
2076 +
2077 +typedef struct {
2078 +       unsigned int            count:8;
2079 +       unsigned int            start_block:24;
2080 +} __attribute__ ((packed)) squashfs_dir_header;
2081 +
2082 +
2083 +typedef struct {
2084 +       unsigned int            start_block;
2085 +       unsigned int            size;
2086 +} __attribute__ ((packed)) squashfs_fragment_entry;
2087 +
2088 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
2089 +extern int squashfs_uncompress_init(void);
2090 +extern int squashfs_uncompress_exit(void);
2091 +
2092 +/*
2093 + * macros to convert each packed bitfield structure from little endian to big
2094 + * endian and vice versa.  These are needed when creating or using a filesystem on a
2095 + * machine with different byte ordering to the target architecture.
2096 + *
2097 + */
2098 +
2099 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
2100 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
2101 +       SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
2102 +       SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
2103 +       SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
2104 +       SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
2105 +       SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
2106 +       SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
2107 +       SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
2108 +       SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
2109 +       SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
2110 +       SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
2111 +       SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
2112 +       SQUASHFS_SWAP((s)->flags, d, 288, 8);\
2113 +       SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
2114 +       SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
2115 +       SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
2116 +       SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
2117 +       SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
2118 +       SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
2119 +       SQUASHFS_SWAP((s)->fragment_table_start, d, 472, 32);\
2120 +}
2121 +
2122 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
2123 +       SQUASHFS_MEMSET(s, d, n);\
2124 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2125 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2126 +       SQUASHFS_SWAP((s)->uid, d, 16, 8);\
2127 +       SQUASHFS_SWAP((s)->guid, d, 24, 8);\
2128 +}
2129 +
2130 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_ipc_inode_header))
2131 +
2132 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
2133 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
2134 +       SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
2135 +}
2136 +
2137 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
2138 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
2139 +       SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
2140 +}
2141 +
2142 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
2143 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
2144 +       SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
2145 +       SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
2146 +       SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
2147 +       SQUASHFS_SWAP((s)->offset, d, 128, 32);\
2148 +       SQUASHFS_SWAP((s)->file_size, d, 160, SQUASHFS_MAX_FILE_SIZE_LOG);\
2149 +}
2150 +
2151 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
2152 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
2153 +       SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
2154 +       SQUASHFS_SWAP((s)->offset, d, 51, 13);\
2155 +       SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
2156 +       SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
2157 +}
2158 +
2159 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
2160 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
2161 +       SQUASHFS_SWAP((s)->count, d, 0, 8);\
2162 +       SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
2163 +}
2164 +
2165 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
2166 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
2167 +       SQUASHFS_SWAP((s)->offset, d, 0, 13);\
2168 +       SQUASHFS_SWAP((s)->type, d, 13, 3);\
2169 +       SQUASHFS_SWAP((s)->size, d, 16, 8);\
2170 +}
2171 +
2172 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
2173 +       SQUASHFS_MEMSET(s, d, sizeof(squashfs_fragment_entry));\
2174 +       SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
2175 +       SQUASHFS_SWAP((s)->size, d, 32, 32);\
2176 +}
2177 +
2178 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
2179 +       int entry;\
2180 +       int bit_position;\
2181 +       SQUASHFS_MEMSET(s, d, n * 2);\
2182 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
2183 +               SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
2184 +}
2185 +
2186 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
2187 +       int entry;\
2188 +       int bit_position;\
2189 +       SQUASHFS_MEMSET(s, d, n * 4);\
2190 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 32)\
2191 +               SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
2192 +}
2193 +
2194 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
2195 +       int entry;\
2196 +       int bit_position;\
2197 +       SQUASHFS_MEMSET(s, d, n * bits / 8);\
2198 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
2199 +               SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
2200 +}
2201 +
2202 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
2203 +
2204 +#ifdef SQUASHFS_1_0_COMPATIBILITY
2205 +typedef struct {
2206 +       unsigned int            inode_type:4;
2207 +       unsigned int            mode:12; /* protection */
2208 +       unsigned int            uid:4; /* index into uid table */
2209 +       unsigned int            guid:4; /* index into guid table */
2210 +} __attribute__ ((packed)) squashfs_base_inode_header_1;
2211 +
2212 +typedef struct {
2213 +       unsigned int            inode_type:4;
2214 +       unsigned int            mode:12; /* protection */
2215 +       unsigned int            uid:4; /* index into uid table */
2216 +       unsigned int            guid:4; /* index into guid table */
2217 +       unsigned int            type:4;
2218 +       unsigned int            offset:4;
2219 +} __attribute__ ((packed)) squashfs_ipc_inode_header_1;
2220 +
2221 +typedef struct {
2222 +       unsigned int            inode_type:4;
2223 +       unsigned int            mode:12; /* protection */
2224 +       unsigned int            uid:4; /* index into uid table */
2225 +       unsigned int            guid:4; /* index into guid table */
2226 +       unsigned short          rdev;
2227 +} __attribute__ ((packed)) squashfs_dev_inode_header_1;
2228 +       
2229 +typedef struct {
2230 +       unsigned int            inode_type:4;
2231 +       unsigned int            mode:12; /* protection */
2232 +       unsigned int            uid:4; /* index into uid table */
2233 +       unsigned int            guid:4; /* index into guid table */
2234 +       unsigned short          symlink_size;
2235 +       char                    symlink[0];
2236 +} __attribute__ ((packed)) squashfs_symlink_inode_header_1;
2237 +
2238 +typedef struct {
2239 +       unsigned int            inode_type:4;
2240 +       unsigned int            mode:12; /* protection */
2241 +       unsigned int            uid:4; /* index into uid table */
2242 +       unsigned int            guid:4; /* index into guid table */
2243 +       time_t                  mtime;
2244 +       squashfs_block          start_block;
2245 +       unsigned int            file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
2246 +       unsigned short          block_list[0];
2247 +} __attribute__ ((packed)) squashfs_reg_inode_header_1;
2248 +
2249 +typedef struct {
2250 +       unsigned int            inode_type:4;
2251 +       unsigned int            mode:12; /* protection */
2252 +       unsigned int            uid:4; /* index into uid table */
2253 +       unsigned int            guid:4; /* index into guid table */
2254 +       unsigned int            file_size:19;
2255 +       unsigned int            offset:13;
2256 +       time_t                  mtime;
2257 +       unsigned int            start_block:24;
2258 +} __attribute__  ((packed)) squashfs_dir_inode_header_1;
2259 +
2260 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
2261 +       SQUASHFS_MEMSET(s, d, n);\
2262 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
2263 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
2264 +       SQUASHFS_SWAP((s)->uid, d, 16, 4);\
2265 +       SQUASHFS_SWAP((s)->guid, d, 20, 4);\
2266 +}
2267 +
2268 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
2269 +       SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_ipc_inode_header_1));\
2270 +       SQUASHFS_SWAP((s)->type, d, 24, 4);\
2271 +       SQUASHFS_SWAP((s)->offset, d, 28, 4);\
2272 +}
2273 +
2274 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
2275 +       SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, sizeof(squashfs_dev_inode_header_1));\
2276 +       SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
2277 +}
2278 +
2279 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
2280 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header_1));\
2281 +       SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
2282 +}
2283 +
2284 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
2285 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header_1));\
2286 +       SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
2287 +       SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
2288 +       SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
2289 +}
2290 +
2291 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
2292 +       SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header_1));\
2293 +       SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
2294 +       SQUASHFS_SWAP((s)->offset, d, 43, 13);\
2295 +       SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
2296 +       SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
2297 +}
2298 +#endif
2299 +
2300 +#ifdef __KERNEL__
2301 +/*
2302 + * macros used to swap each structure entry, taking into account
2303 + * bitfields and different bitfield placing conventions on differing architectures
2304 + */
2305 +#include <asm/byteorder.h>
2306 +#ifdef __BIG_ENDIAN
2307 +       /* convert from little endian to big endian */
2308 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
2309 +#else
2310 +       /* convert from big endian to little endian */ 
2311 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
2312 +#endif
2313 +
2314 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
2315 +       int bits;\
2316 +       int b_pos = pos % 8;\
2317 +       unsigned long long val = 0;\
2318 +       unsigned char *s = (unsigned char *)p + (pos / 8);\
2319 +       unsigned char *d = ((unsigned char *) &val) + 7;\
2320 +       for(bits = 0; bits < (tbits + b_pos); bits += 8) \
2321 +               *d-- = *s++;\
2322 +       value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
2323 +}
2324 +#define SQUASHFS_MEMSET(s, d, n)       memset(s, 0, n);
2325 +#endif
2326 +#endif
2327 --- /dev/null   2004-04-06 13:56:48.000000000 -0400
2328 +++ linux-2.4.20/include/linux/squashfs_fs_i.h  2005-01-07 02:54:46.358830720 -0500
2329 @@ -0,0 +1,33 @@
2330 +#ifndef SQUASHFS_FS_I
2331 +#define SQUASHFS_FS_I
2332 +/*
2333 + * Squashfs
2334 + *
2335 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2336 + *
2337 + * This program is free software; you can redistribute it and/or
2338 + * modify it under the terms of the GNU General Public License
2339 + * as published by the Free Software Foundation; either version 2,
2340 + * or (at your option) any later version.
2341 + *
2342 + * This program is distributed in the hope that it will be useful,
2343 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2344 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2345 + * GNU General Public License for more details.
2346 + *
2347 + * You should have received a copy of the GNU General Public License
2348 + * along with this program; if not, write to the Free Software
2349 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2350 + *
2351 + * squashfs_fs_i.h
2352 + */
2353 +
2354 +typedef struct squashfs_inode_info {
2355 +       unsigned int    start_block;
2356 +       unsigned int    block_list_start;
2357 +       unsigned int    offset;
2358 +       unsigned int    fragment_start_block;
2359 +       unsigned int    fragment_size;
2360 +       unsigned int    fragment_offset;
2361 +       } squashfs_inode_info;
2362 +#endif
2363 --- /dev/null   2004-04-06 13:56:48.000000000 -0400
2364 +++ linux-2.4.20/include/linux/squashfs_fs_sb.h 2005-01-07 02:54:46.358830720 -0500
2365 @@ -0,0 +1,65 @@
2366 +#ifndef SQUASHFS_FS_SB
2367 +#define SQUASHFS_FS_SB
2368 +/*
2369 + * Squashfs
2370 + *
2371 + * Copyright (c) 2002, 2003, 2004 Phillip Lougher <plougher@users.sourceforge.net>
2372 + *
2373 + * This program is free software; you can redistribute it and/or
2374 + * modify it under the terms of the GNU General Public License
2375 + * as published by the Free Software Foundation; either version 2,
2376 + * or (at your option) any later version.
2377 + *
2378 + * This program is distributed in the hope that it will be useful,
2379 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2380 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2381 + * GNU General Public License for more details.
2382 + *
2383 + * You should have received a copy of the GNU General Public License
2384 + * along with this program; if not, write to the Free Software
2385 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2386 + *
2387 + * squashfs_fs_sb.h
2388 + */
2389 +
2390 +#include <linux/squashfs_fs.h>
2391 +
2392 +typedef struct {
2393 +       unsigned int    block;
2394 +       int             length;
2395 +       unsigned int    next_index;
2396 +       char            *data;
2397 +       } squashfs_cache;
2398 +
2399 +struct squashfs_fragment_cache {
2400 +       unsigned int    block;
2401 +       int             length;
2402 +       unsigned int    locked;
2403 +       char            *data;
2404 +       };
2405 +
2406 +typedef struct squashfs_sb_info {
2407 +       squashfs_super_block    sBlk;
2408 +       int                     devblksize;
2409 +       int                     devblksize_log2;
2410 +       int                     swap;
2411 +       squashfs_cache          *block_cache;
2412 +       struct squashfs_fragment_cache  *fragment;
2413 +       int                     next_cache;
2414 +       int                     next_fragment;
2415 +       squashfs_uid            *uid;
2416 +       squashfs_uid            *guid;
2417 +       squashfs_fragment_index         *fragment_index;
2418 +       unsigned int            read_size;
2419 +       char                    *read_data;
2420 +       char                    *read_page;
2421 +       struct semaphore        read_page_mutex;
2422 +       struct semaphore        block_cache_mutex;
2423 +       struct semaphore        fragment_mutex;
2424 +       wait_queue_head_t       waitq;
2425 +       wait_queue_head_t       fragment_wait_queue;
2426 +       struct inode            *(*iget)(struct super_block *s, squashfs_inode inode);
2427 +       unsigned int            (*read_blocklist)(struct inode *inode, int index, int readahead_blks,
2428 +                                       char *block_list, char **block_p, unsigned int *bsize);
2429 +       } squashfs_sb_info;
2430 +#endif
2431 --- linux-2.4.20/init/do_mounts.c~120-openwrt   2005-01-07 02:52:47.205944000 -0500
2432 +++ linux-2.4.20/init/do_mounts.c       2005-01-07 02:55:17.301126776 -0500
2433 @@ -15,6 +15,8 @@
2434  #include <linux/minix_fs.h>
2435  #include <linux/ext2_fs.h>
2436  #include <linux/romfs_fs.h>
2437 +#include <linux/cramfs_fs.h>
2438 +#include <linux/squashfs_fs.h>
2439  
2440  #define BUILD_CRAMDISK
2441  
2442 @@ -469,6 +471,7 @@
2443   *     ext2
2444   *     romfs
2445   *     gzip
2446 + *     squashfs
2447   */
2448  static int __init 
2449  identify_ramdisk_image(int fd, int start_block)
2450 @@ -478,6 +481,7 @@
2451         struct ext2_super_block *ext2sb;
2452         struct romfs_super_block *romfsb;
2453         struct cramfs_super *cramfsb;
2454 +       struct squashfs_super_block *squashfsb;
2455         int nblocks = -1;
2456         unsigned char *buf;
2457  
2458 @@ -489,6 +493,7 @@
2459         ext2sb = (struct ext2_super_block *) buf;
2460         romfsb = (struct romfs_super_block *) buf;
2461         cramfsb = (struct cramfs_super *) buf;
2462 +       squashfsb = (struct squashfs_super_block *) buf;
2463         memset(buf, 0xe5, size);
2464  
2465         /*
2466 @@ -535,6 +540,15 @@
2467                 goto done;
2468         }
2469  
2470 +       /* squashfs is at block zero too */
2471 +       if (squashfsb->s_magic == SQUASHFS_MAGIC) {
2472 +               printk(KERN_NOTICE
2473 +                      "RAMDISK: squashfs filesystem found at block %d\n",
2474 +                      start_block);
2475 +               nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
2476 +               goto done;
2477 +       }
2478 +
2479         /*
2480          * Read block 1 to test for minix and ext2 superblock
2481          */
2482 --- linux-2.4.20/kernel/ksyms.c~120-openwrt     2002-11-28 18:53:15.000000000 -0500
2483 +++ linux-2.4.20/kernel/ksyms.c 2005-01-07 02:54:46.362830112 -0500
2484 @@ -482,9 +482,9 @@
2485  EXPORT_SYMBOL(simple_strtoull);
2486  EXPORT_SYMBOL(system_utsname); /* UTS data */
2487  EXPORT_SYMBOL(uts_sem);                /* UTS semaphore */
2488 -#ifndef __mips__
2489 +//#ifndef __mips__ //bite me. -mbm.
2490  EXPORT_SYMBOL(sys_call_table);
2491 -#endif
2492 +//#endif
2493  EXPORT_SYMBOL(machine_restart);
2494  EXPORT_SYMBOL(machine_halt);
2495  EXPORT_SYMBOL(machine_power_off);
2496 --- linux-2.4.20/lib/Config.in~120-openwrt      2002-11-28 18:53:15.000000000 -0500
2497 +++ linux-2.4.20/lib/Config.in  2005-01-07 02:54:46.363829960 -0500
2498 @@ -8,12 +8,14 @@
2499  # Do we need the compression support?
2500  #
2501  if [ "$CONFIG_CRAMFS" = "y" -o \
2502 +     "$CONFIG_SQUASHFS" = "y" -o \
2503       "$CONFIG_PPP_DEFLATE" = "y" -o \
2504       "$CONFIG_JFFS2_FS" = "y" -o \
2505       "$CONFIG_ZISOFS_FS" = "y" ]; then
2506     define_tristate CONFIG_ZLIB_INFLATE y
2507  else
2508    if [ "$CONFIG_CRAMFS" = "m" -o \
2509 +       "$CONFIG_SQUASHFS" = "m" -o \
2510         "$CONFIG_PPP_DEFLATE" = "m" -o \
2511         "$CONFIG_JFFS2_FS" = "m" -o \
2512         "$CONFIG_ZISOFS_FS" = "m" ]; then