67223f0128e83e01a82789bf12254a11853367e8
[openwrt.git] / obsolete-buildroot / sources / openwrt-wrt54g-linux.patch
1 diff -urN src/linux-dist/linux/Makefile src/linux/linux/Makefile
2 --- src/linux-dist/linux/Makefile 2003-10-14 03:00:10.000000000 -0500
3 +++ src/linux/linux/Makefile 2004-03-29 17:00:53.000000000 -0600
4 @@ -17,7 +17,7 @@
5 FINDHPATH = $(HPATH)/asm $(HPATH)/linux $(HPATH)/scsi $(HPATH)/net $(HPATH)/math-emu
6
7 HOSTCC = gcc
8 -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
9 +HOSTCFLAGS = -Wall -Wstrict-prototypes -Os -fomit-frame-pointer
10
11 CROSS_COMPILE =
12
13 @@ -88,7 +88,7 @@
14
15 CPPFLAGS := -D__KERNEL__ -I$(HPATH)
16
17 -CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
18 +CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -Os \
19 -fno-strict-aliasing -fno-common
20
21 # Turn on -pg to instrument the kernel with calls to mcount().
22 diff -urN src/linux-dist/linux/arch/mips/brcm-boards/bcm947xx/setup.c src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c
23 --- src/linux-dist/linux/arch/mips/brcm-boards/bcm947xx/setup.c 2003-11-11 08:08:46.000000000 -0600
24 +++ src/linux/linux/arch/mips/brcm-boards/bcm947xx/setup.c 2004-03-29 17:00:53.000000000 -0600
25 @@ -27,6 +27,7 @@
26 #include <linux/ext2_fs.h>
27 #include <linux/romfs_fs.h>
28 #include <linux/cramfs_fs.h>
29 +#include <linux/squashfs_fs.h>
30 #endif
31
32 #include <typedefs.h>
33 @@ -160,37 +161,38 @@
34 #ifdef CONFIG_MTD_PARTITIONS
35
36 static struct mtd_partition bcm947xx_parts[] = {
37 - { name: "pmon", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
38 + { name: "pmon", offset: 0, size: 0, mask_flags: MTD_WRITEABLE, },
39 { name: "linux", offset: 0, size: 0, },
40 { name: "rootfs", offset: 0, size: 0, /*mask_flags: MTD_WRITEABLE,*/ },
41 { name: "nvram", offset: 0, size: 0, },
42 + { name: "OpenWrt", offset: 0, size: 0, },
43 { name: NULL, },
44 };
45
46 -struct mtd_partition * __init
47 -init_mtd_partitions(struct mtd_info *mtd, size_t size)
48 +
49 +static int __init
50 +find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
51 {
52 - struct minix_super_block *minixsb;
53 - struct ext2_super_block *ext2sb;
54 - struct romfs_super_block *romfsb;
55 struct cramfs_super *cramfsb;
56 + struct squashfs_super_block *squashfsb;
57 struct trx_header *trx;
58 +
59 unsigned char buf[512];
60 int off;
61 size_t len;
62
63 - minixsb = (struct minix_super_block *) buf;
64 - ext2sb = (struct ext2_super_block *) buf;
65 - romfsb = (struct romfs_super_block *) buf;
66 cramfsb = (struct cramfs_super *) buf;
67 + squashfsb = (struct squashfs_super_block *) buf;
68 trx = (struct trx_header *) buf;
69
70 - /* Look at every 64 KB boundary */
71 - for (off = 0; off < size; off += (64 * 1024)) {
72 + part->offset = 0;
73 + part->size = 0;
74 +
75 + for (off = 0; off < size; off += mtd->erasesize) {
76 memset(buf, 0xe5, sizeof(buf));
77
78 /*
79 - * Read block 0 to test for romfs and cramfs superblock
80 + * Read block 0 to test for cramfs superblock
81 */
82 if (MTD_READ(mtd, off, sizeof(buf), &len, buf) ||
83 len != sizeof(buf))
84 @@ -198,75 +200,105 @@
85
86 /* Try looking at TRX header for rootfs offset */
87 if (le32_to_cpu(trx->magic) == TRX_MAGIC) {
88 - bcm947xx_parts[1].offset = off;
89 if (le32_to_cpu(trx->offsets[1]) > off)
90 off = le32_to_cpu(trx->offsets[1]);
91 continue;
92 }
93
94 - /* romfs is at block zero too */
95 - if (romfsb->word0 == ROMSB_WORD0 &&
96 - romfsb->word1 == ROMSB_WORD1) {
97 - printk(KERN_NOTICE
98 - "%s: romfs filesystem found at block %d\n",
99 - mtd->name, off / BLOCK_SIZE);
100 - goto done;
101 - }
102 -
103 - /* so is cramfs */
104 + /* need to find cramfs */
105 if (cramfsb->magic == CRAMFS_MAGIC) {
106 printk(KERN_NOTICE
107 "%s: cramfs filesystem found at block %d\n",
108 mtd->name, off / BLOCK_SIZE);
109 - goto done;
110 - }
111 -
112 - /*
113 - * Read block 1 to test for minix and ext2 superblock
114 - */
115 - if (MTD_READ(mtd, off + BLOCK_SIZE, sizeof(buf), &len, buf) ||
116 - len != sizeof(buf))
117 - continue;
118
119 - /* Try minix */
120 - if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
121 - minixsb->s_magic == MINIX_SUPER_MAGIC2) {
122 - printk(KERN_NOTICE
123 - "%s: Minix filesystem found at block %d\n",
124 - mtd->name, off / BLOCK_SIZE);
125 + part->size = cramfsb->size;
126 goto done;
127 }
128
129 - /* Try ext2 */
130 - if (ext2sb->s_magic == cpu_to_le16(EXT2_SUPER_MAGIC)) {
131 + /* or squashfs */
132 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
133 printk(KERN_NOTICE
134 - "%s: ext2 filesystem found at block %d\n",
135 + "%s: squashfs filesystem found at block %d\n",
136 mtd->name, off / BLOCK_SIZE);
137 + part->size = squashfsb->bytes_used+2048;
138 goto done;
139 }
140 - }
141
142 + }
143 printk(KERN_NOTICE
144 - "%s: Couldn't find valid ROM disk image\n",
145 + "%s: Couldn't find valid cramfs image\n",
146 mtd->name);
147 + return -1;
148 +
149 +done:
150 + part->offset = off;
151 + return 0;
152 +}
153 +
154 +
155 +struct mtd_partition * __init
156 +init_mtd_partitions(struct mtd_info *mtd, size_t size)
157 +{
158 +
159 + bcm947xx_parts[0].offset=0;
160 + bcm947xx_parts[0].size=256*1024;
161
162 - done:
163 /* Find and size nvram */
164 bcm947xx_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
165 bcm947xx_parts[3].size = size - bcm947xx_parts[3].offset;
166
167 /* Find and size rootfs */
168 - if (off < size) {
169 - bcm947xx_parts[2].offset = off;
170 - bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
171 - }
172 + //if (off < size) {
173 + // bcm947xx_parts[2].offset = off;
174 + // bcm947xx_parts[2].size = bcm947xx_parts[3].offset - bcm947xx_parts[2].offset;
175 + //}
176 +
177 + /* Find and size rootfs */
178 + find_root(mtd,size,&bcm947xx_parts[2]);
179 +
180 +
181
182 /* Size linux (kernel and rootfs) */
183 + bcm947xx_parts[1].offset = bcm947xx_parts[0].size;
184 bcm947xx_parts[1].size = bcm947xx_parts[3].offset - bcm947xx_parts[1].offset;
185
186 +
187 +
188 + /* calculate leftover flash, and assign it to the jffs partition */
189 + size_t spot;
190 + size_t len;
191 + size_t mask;
192 + // get the offset to the end of the root_fs
193 + spot=bcm947xx_parts[2].offset+bcm947xx_parts[2].size;
194 + // round it up to an erase size boundary
195 + spot+=mtd->erasesize-1;
196 + // mask the number to the boundary
197 + mask=mtd->erasesize;
198 + mask=mask-1;
199 + mask=mask^0xffffffff;
200 + spot&=mask;
201 + // length = flashsize - start position - nvram size
202 + len=size-spot;
203 + len=len-bcm947xx_parts[3].size;
204 +
205 +
206 + bcm947xx_parts[4].offset = spot;
207 + bcm947xx_parts[4].size = len;
208 +
209 +
210 +
211 +
212 /* Size pmon */
213 bcm947xx_parts[0].size = bcm947xx_parts[1].offset - bcm947xx_parts[0].offset;
214
215 + //int x;
216 + //for(x=0; x<5; x++) {
217 + // printk(KERN_NOTICE
218 + // "Partition %d mask_flags %08x\n",
219 + // x,bcm947xx_parts[x].mask_flags);
220 + //}
221 +
222 +
223 return bcm947xx_parts;
224 }
225
226 diff -urN src/linux-dist/linux/drivers/mtd/maps/bcm947xx-flash.c src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c
227 --- src/linux-dist/linux/drivers/mtd/maps/bcm947xx-flash.c 2003-11-08 03:35:52.000000000 -0600
228 +++ src/linux/linux/drivers/mtd/maps/bcm947xx-flash.c 2004-03-29 17:00:53.000000000 -0600
229 @@ -82,7 +82,21 @@
230
231 void bcm947xx_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
232 {
233 + //memcpy_fromio(to, map->map_priv_1 + from, len);
234 + if (len==1) {
235 memcpy_fromio(to, map->map_priv_1 + from, len);
236 + } else {
237 + int i;
238 + u16 *dest = (u16 *) to;
239 + u16 *src = (u16 *) (map->map_priv_1 + from);
240 +
241 + for (i = 0; i < (len / 2); i++) {
242 + dest[i] = src[i];
243 + }
244 +
245 + if (len & 1)
246 + *((u8 *)dest+len-1) = src[i] & 0xff;
247 + }
248 }
249
250 void bcm947xx_map_write8(struct map_info *map, __u8 d, unsigned long adr)
251 diff -urN src/linux-dist/linux/drivers/net/Makefile src/linux/linux/drivers/net/Makefile
252 --- src/linux-dist/linux/drivers/net/Makefile 2004-02-12 20:35:15.000000000 -0600
253 +++ src/linux/linux/drivers/net/Makefile 2004-03-29 17:00:53.000000000 -0600
254 @@ -25,7 +25,7 @@
255 list-multi := rcpci.o
256 rcpci-objs := rcpci45.o rclanmtl.o
257
258 -subdir-m += mac
259 +# subdir-m += mac
260 subdir-m += diag
261
262 ifeq ($(CONFIG_HW_QOS),y)
263 diff -urN src/linux-dist/linux/fs/Config.in src/linux/linux/fs/Config.in
264 --- src/linux-dist/linux/fs/Config.in 2003-07-04 03:12:05.000000000 -0500
265 +++ src/linux/linux/fs/Config.in 2004-03-29 17:00:53.000000000 -0600
266 @@ -47,6 +47,7 @@
267 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
268 fi
269 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
270 +tristate 'Squashed file system support' CONFIG_SQUASHFS
271 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
272 define_bool CONFIG_RAMFS y
273
274 diff -urN src/linux-dist/linux/fs/Makefile src/linux/linux/fs/Makefile
275 --- src/linux-dist/linux/fs/Makefile 2003-07-04 03:12:05.000000000 -0500
276 +++ src/linux/linux/fs/Makefile 2004-03-29 17:00:53.000000000 -0600
277 @@ -68,6 +68,7 @@
278 subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
279 subdir-$(CONFIG_BEFS_FS) += befs
280 subdir-$(CONFIG_JFS_FS) += jfs
281 +subdir-$(CONFIG_SQUASHFS) += squashfs
282
283
284 obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o
285 diff -urN src/linux-dist/linux/fs/squashfs/Makefile src/linux/linux/fs/squashfs/Makefile
286 --- src/linux-dist/linux/fs/squashfs/Makefile 1969-12-31 18:00:00.000000000 -0600
287 +++ src/linux/linux/fs/squashfs/Makefile 2004-03-29 17:00:53.000000000 -0600
288 @@ -0,0 +1,11 @@
289 +#
290 +# Makefile for the linux squashfs routines.
291 +#
292 +
293 +O_TARGET := squashfs.o
294 +
295 +obj-y := inode.o
296 +
297 +obj-m := $(O_TARGET)
298 +
299 +include $(TOPDIR)/Rules.make
300 diff -urN src/linux-dist/linux/fs/squashfs/inode.c src/linux/linux/fs/squashfs/inode.c
301 --- src/linux-dist/linux/fs/squashfs/inode.c 1969-12-31 18:00:00.000000000 -0600
302 +++ src/linux/linux/fs/squashfs/inode.c 2004-03-29 17:00:53.000000000 -0600
303 @@ -0,0 +1,972 @@
304 +/*
305 + * Squashfs - a compressed read only filesystem for Linux
306 + *
307 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
308 + *
309 + * This program is free software; you can redistribute it and/or
310 + * modify it under the terms of the GNU General Public License
311 + * as published by the Free Software Foundation; either version
312 + * 2 of the License, or (at your option) any later version.
313 + *
314 + * inode.c
315 + */
316 +
317 +#include <linux/types.h>
318 +#include <linux/squashfs_fs.h>
319 +#include <linux/module.h>
320 +#include <linux/errno.h>
321 +#include <linux/slab.h>
322 +#include <linux/fs.h>
323 +#include <linux/locks.h>
324 +#include <linux/init.h>
325 +#include <linux/dcache.h>
326 +#include <asm/uaccess.h>
327 +#include <linux/wait.h>
328 +#include <asm/semaphore.h>
329 +
330 +#include <linux/zlib.h>
331 +#include <linux/blkdev.h>
332 +#include <linux/vmalloc.h>
333 +
334 +#ifdef SQUASHFS_TRACE
335 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
336 +#else
337 +#define TRACE(s, args...) {}
338 +#endif
339 +
340 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
341 +
342 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
343 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
344 +
345 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
346 +static void squashfs_put_super(struct super_block *);
347 +static int squashfs_statfs(struct super_block *, struct statfs *);
348 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
349 +static int squashfs_readpage(struct file *file, struct page *page);
350 +static int squashfs_readdir(struct file *, void *, filldir_t);
351 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
352 +static unsigned int read_data(struct super_block *s, char *buffer,
353 + unsigned int index, int length, unsigned int *next_index);
354 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
355 + unsigned int block, unsigned int offset, int length,
356 + unsigned int *next_block, unsigned int *next_offset);
357 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
358 +static void squashfs_put_super(struct super_block *s);
359 +
360 +DECLARE_MUTEX(read_data_mutex);
361 +
362 +static z_stream stream;
363 +
364 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
365 +
366 +static unsigned char squashfs_filetype_table[] = {
367 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
368 +};
369 +
370 +static struct super_operations squashfs_ops = {
371 + statfs: squashfs_statfs,
372 + put_super: squashfs_put_super,
373 +};
374 +
375 +static struct address_space_operations squashfs_symlink_aops = {
376 + readpage: squashfs_symlink_readpage
377 +};
378 +
379 +static struct address_space_operations squashfs_aops = {
380 + readpage: squashfs_readpage
381 +};
382 +
383 +static struct file_operations squashfs_dir_ops = {
384 + read: generic_read_dir,
385 + readdir: squashfs_readdir
386 +};
387 +
388 +static struct inode_operations squashfs_dir_inode_ops = {
389 + lookup: squashfs_lookup
390 +};
391 +
392 +
393 +static unsigned int read_data(struct super_block *s, char *buffer,
394 + unsigned int index, int length, unsigned int *next_index)
395 +{
396 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
397 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
398 + unsigned short c_byte;
399 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
400 + unsigned int cur_index = index >> msBlk->devblksize_log2;
401 + int bytes, avail_bytes, b, k;
402 + char *c_buffer;
403 + unsigned int compressed;
404 +
405 + if(!(bh[0] = sb_bread(s, cur_index)))
406 + goto read_failure;
407 +
408 + if(length)
409 + c_byte = length;
410 + else {
411 + if(msBlk->devblksize - offset == 1) {
412 + if(msBlk->swap)
413 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
414 + else
415 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
416 + brelse(bh[0]);
417 + if(!(bh[0] = sb_bread(s, ++cur_index)))
418 + goto read_failure;
419 + if(msBlk->swap)
420 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data);
421 + else
422 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data);
423 + offset = 1;
424 + }
425 + else {
426 + if(msBlk->swap) {
427 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
428 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
429 + } else
430 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
431 + offset += 2;
432 + }
433 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
434 + if(offset == msBlk->devblksize) {
435 + brelse(bh[0]);
436 + if(!(bh[0] = sb_bread(s, ++cur_index)))
437 + goto read_failure;
438 + offset = 0;
439 + }
440 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
441 + ERROR("Metadata block marker corrupt @ %x\n", index);
442 + brelse(bh[0]);
443 + return 0;
444 + }
445 + offset ++;
446 + }
447 + }
448 +
449 + bytes = msBlk->devblksize - offset;
450 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
451 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
452 +
453 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
454 +
455 + for(b = 1; bytes < c_byte; b++) {
456 + if(!(bh[b] = sb_bread(s, ++cur_index)))
457 + goto block_release;
458 + bytes += msBlk->devblksize;
459 + }
460 +
461 + if(compressed)
462 + down(&read_data_mutex);
463 +
464 + for(bytes = 0, k = 0; k < b; k++) {
465 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
466 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
467 + bytes += avail_bytes;
468 + offset = 0;
469 + brelse(bh[k]);
470 + }
471 +
472 + /*
473 + * uncompress block
474 + */
475 + if(compressed) {
476 + int zlib_err;
477 +
478 + stream.next_in = c_buffer;
479 + stream.avail_in = c_byte;
480 + stream.next_out = buffer;
481 + stream.avail_out = msBlk->read_size;
482 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
483 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
484 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
485 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
486 + bytes = 0;
487 + } else
488 + bytes = stream.total_out;
489 + up(&read_data_mutex);
490 + }
491 +
492 + if(next_index)
493 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
494 +
495 + return bytes;
496 +
497 +block_release:
498 + while(--b >= 0) brelse(bh[b]);
499 +
500 +read_failure:
501 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
502 + return 0;
503 +}
504 +
505 +
506 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
507 + unsigned int block, unsigned int offset, int length,
508 + unsigned int *next_block, unsigned int *next_offset)
509 +{
510 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
511 + int n, i, bytes, return_length = length;
512 + unsigned int next_index;
513 +
514 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
515 +
516 + for(;;) {
517 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
518 + if(msBlk->block_cache[i].block == block)
519 + break;
520 +
521 + down(&msBlk->block_cache_mutex);
522 + if(i == SQUASHFS_CACHED_BLKS) {
523 + /* read inode header block */
524 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
525 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
526 + break;
527 + if(n == 0) {
528 + up(&msBlk->block_cache_mutex);
529 + sleep_on(&msBlk->waitq);
530 + continue;
531 + }
532 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
533 +
534 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
535 + if(!(msBlk->block_cache[i].data = (unsigned char *)
536 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
537 + ERROR("Failed to allocate cache block\n");
538 + up(&msBlk->block_cache_mutex);
539 + return 0;
540 + }
541 + }
542 +
543 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
544 + up(&msBlk->block_cache_mutex);
545 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
546 + &next_index))) {
547 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
548 + return 0;
549 + }
550 + down(&msBlk->block_cache_mutex);
551 + wake_up(&msBlk->waitq);
552 + msBlk->block_cache[i].block = block;
553 + msBlk->block_cache[i].next_index = next_index;
554 + TRACE("Read cache block [%x:%x]\n", block, offset);
555 + }
556 +
557 + if(msBlk->block_cache[i].block != block) {
558 + up(&msBlk->block_cache_mutex);
559 + continue;
560 + }
561 +
562 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
563 + if(buffer)
564 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
565 + if(msBlk->block_cache[i].length - offset == length) {
566 + *next_block = msBlk->block_cache[i].next_index;
567 + *next_offset = 0;
568 + } else {
569 + *next_block = block;
570 + *next_offset = offset + length;
571 + }
572 +
573 + up(&msBlk->block_cache_mutex);
574 + return return_length;
575 + } else {
576 + if(buffer) {
577 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
578 + buffer += bytes;
579 + }
580 + block = msBlk->block_cache[i].next_index;
581 + up(&msBlk->block_cache_mutex);
582 + length -= bytes;
583 + offset = 0;
584 + }
585 + }
586 +}
587 +
588 +
589 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
590 +{
591 + struct inode *i = new_inode(s);
592 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
593 + squashfs_super_block *sBlk = &msBlk->sBlk;
594 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
595 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
596 + unsigned int next_block, next_offset;
597 + squashfs_base_inode_header inodeb;
598 +
599 + TRACE("Entered squashfs_iget\n");
600 +
601 + if(msBlk->swap) {
602 + squashfs_base_inode_header sinodeb;
603 +
604 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
605 + sizeof(sinodeb), &next_block, &next_offset))
606 + goto failed_read;
607 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
608 + } else
609 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
610 + sizeof(inodeb), &next_block, &next_offset))
611 + goto failed_read;
612 +
613 + i->i_nlink = 1;
614 +
615 + i->i_mtime = sBlk->mkfs_time;
616 + i->i_atime = sBlk->mkfs_time;
617 + i->i_ctime = sBlk->mkfs_time;
618 +
619 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
620 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
621 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
622 +
623 + i->i_mode = inodeb.mode;
624 +
625 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
626 + case SQUASHFS_FILE_TYPE: {
627 + squashfs_reg_inode_header inodep;
628 +
629 + if(msBlk->swap) {
630 + squashfs_reg_inode_header sinodep;
631 +
632 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
633 + &next_block, &next_offset))
634 + goto failed_read;
635 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
636 + } else
637 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
638 + &next_block, &next_offset))
639 + goto failed_read;
640 +
641 + i->i_size = inodep.file_size;
642 + i->i_fop = &generic_ro_fops;
643 + i->i_data.a_ops = &squashfs_aops;
644 + i->i_mode |= S_IFREG;
645 + i->i_mtime = inodep.mtime;
646 + i->i_atime = inodep.mtime;
647 + i->i_ctime = inodep.mtime;
648 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
649 + i->i_blksize = PAGE_CACHE_SIZE;
650 + i->u.squashfs_i.start_block = inodep.start_block;
651 + i->u.squashfs_i.block_list_start = next_block;
652 + i->u.squashfs_i.offset = next_offset;
653 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
654 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
655 + break;
656 + }
657 + case SQUASHFS_DIR_TYPE: {
658 + squashfs_dir_inode_header inodep;
659 +
660 + if(msBlk->swap) {
661 + squashfs_dir_inode_header sinodep;
662 +
663 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
664 + &next_block, &next_offset))
665 + goto failed_read;
666 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
667 + } else
668 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
669 + &next_block, &next_offset))
670 + goto failed_read;
671 +
672 + i->i_size = inodep.file_size;
673 + i->i_op = &squashfs_dir_inode_ops;
674 + i->i_fop = &squashfs_dir_ops;
675 + i->i_mode |= S_IFDIR;
676 + i->i_mtime = inodep.mtime;
677 + i->i_atime = inodep.mtime;
678 + i->i_ctime = inodep.mtime;
679 + i->u.squashfs_i.start_block = inodep.start_block;
680 + i->u.squashfs_i.offset = inodep.offset;
681 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
682 + inodep.start_block, inodep.offset);
683 + break;
684 + }
685 + case SQUASHFS_SYMLINK_TYPE: {
686 + squashfs_symlink_inode_header inodep;
687 +
688 + if(msBlk->swap) {
689 + squashfs_symlink_inode_header sinodep;
690 +
691 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
692 + &next_block, &next_offset))
693 + goto failed_read;
694 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
695 + } else
696 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
697 + &next_block, &next_offset))
698 + goto failed_read;
699 +
700 + i->i_size = inodep.symlink_size;
701 + i->i_op = &page_symlink_inode_operations;
702 + i->i_data.a_ops = &squashfs_symlink_aops;
703 + i->i_mode |= S_IFLNK;
704 + i->u.squashfs_i.start_block = next_block;
705 + i->u.squashfs_i.offset = next_offset;
706 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
707 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
708 + break;
709 + }
710 + case SQUASHFS_BLKDEV_TYPE:
711 + case SQUASHFS_CHRDEV_TYPE: {
712 + squashfs_dev_inode_header inodep;
713 +
714 + if(msBlk->swap) {
715 + squashfs_dev_inode_header sinodep;
716 +
717 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
718 + &next_block, &next_offset))
719 + goto failed_read;
720 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
721 + } else
722 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
723 + &next_block, &next_offset))
724 + goto failed_read;
725 +
726 + i->i_size = 0;
727 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
728 + init_special_inode(i, i->i_mode, inodep.rdev);
729 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
730 + break;
731 + }
732 + case SQUASHFS_IPC_TYPE: {
733 + squashfs_ipc_inode_header inodep;
734 +
735 + if(msBlk->swap) {
736 + squashfs_ipc_inode_header sinodep;
737 +
738 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
739 + &next_block, &next_offset))
740 + goto failed_read;
741 + SQUASHFS_SWAP_IPC_INODE_HEADER(&inodep, &sinodep);
742 + } else
743 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
744 + &next_block, &next_offset))
745 + goto failed_read;
746 +
747 + i->i_size = 0;
748 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
749 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
750 + init_special_inode(i, i->i_mode, 0);
751 + break;
752 + }
753 + default:
754 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
755 + goto failed_read1;
756 + }
757 +
758 + if(inodeb.guid == SQUASHFS_GUIDS)
759 + i->i_gid = i->i_uid;
760 + else
761 + i->i_gid = msBlk->guid[inodeb.guid];
762 +
763 + return i;
764 +
765 +failed_read:
766 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
767 +
768 +failed_read1:
769 + return NULL;
770 +}
771 +
772 +
773 +static struct super_block *squashfs_read_super(struct super_block *s,
774 + void *data, int silent)
775 +{
776 + kdev_t dev = s->s_dev;
777 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
778 + squashfs_super_block *sBlk = &msBlk->sBlk;
779 + int i;
780 +
781 + TRACE("Entered squashfs_read_superblock\n");
782 +
783 + msBlk->devblksize = get_hardsect_size(dev);
784 + if(msBlk->devblksize < BLOCK_SIZE)
785 + msBlk->devblksize = BLOCK_SIZE;
786 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
787 + set_blocksize(dev, msBlk->devblksize);
788 + s->s_blocksize = msBlk->devblksize;
789 + s->s_blocksize_bits = msBlk->devblksize_log2;
790 +
791 + init_MUTEX(&msBlk->read_page_mutex);
792 + init_MUTEX(&msBlk->block_cache_mutex);
793 +
794 + init_waitqueue_head(&msBlk->waitq);
795 +
796 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
797 + SERROR("unable to read superblock\n");
798 + goto failed_mount;
799 + }
800 +
801 + /* Check it is a SQUASHFS superblock */
802 + msBlk->swap = 0;
803 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
804 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
805 + squashfs_super_block sblk;
806 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
807 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
808 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
809 + msBlk->swap = 1;
810 + } else {
811 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
812 + goto failed_mount;
813 + }
814 + }
815 +
816 + /* Check the MAJOR & MINOR versions */
817 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
818 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
819 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
820 + goto failed_mount;
821 + }
822 +
823 + TRACE("Found valid superblock on %s\n", bdevname(dev));
824 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
825 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
826 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
827 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
828 + TRACE("Block size %d\n", sBlk->block_size);
829 + TRACE("Number of inodes %d\n", sBlk->inodes);
830 + TRACE("Number of uids %d\n", sBlk->no_uids);
831 + TRACE("Number of gids %d\n", sBlk->no_guids);
832 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
833 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
834 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
835 +
836 + s->s_flags |= MS_RDONLY;
837 + s->s_op = &squashfs_ops;
838 +
839 + /* Init inode_table block pointer array */
840 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
841 + ERROR("Failed to allocate block cache\n");
842 + goto failed_mount;
843 + }
844 +
845 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
846 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
847 +
848 + msBlk->next_cache = 0;
849 +
850 + /* Allocate read_data block */
851 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
852 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
853 + ERROR("Failed to allocate read_data block\n");
854 + goto failed_mount1;
855 + }
856 +
857 + /* Allocate read_page block */
858 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
859 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
860 + ERROR("Failed to allocate read_page block\n");
861 + goto failed_mount2;
862 + }
863 +
864 + /* Allocate uid and gid tables */
865 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
866 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
867 + ERROR("Failed to allocate uid/gid table\n");
868 + goto failed_mount3;
869 + }
870 + msBlk->guid = msBlk->uid + sBlk->no_uids;
871 +
872 + if(msBlk->swap) {
873 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
874 +
875 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
876 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
877 + SERROR("unable to read uid/gid table\n");
878 + goto failed_mount4;
879 + }
880 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
881 + } else
882 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
883 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
884 + SERROR("unable to read uid/gid table\n");
885 + goto failed_mount4;
886 + }
887 +
888 + if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
889 + ERROR("Root inode create failed\n");
890 + goto failed_mount4;
891 + }
892 +
893 + TRACE("Leaving squashfs_read_super\n");
894 + return s;
895 +
896 +failed_mount4:
897 + kfree(msBlk->uid);
898 +failed_mount3:
899 + kfree(msBlk->read_page);
900 +failed_mount2:
901 + kfree(msBlk->read_data);
902 +failed_mount1:
903 + kfree(msBlk->block_cache);
904 +failed_mount:
905 + return NULL;
906 +}
907 +
908 +
909 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
910 +{
911 + squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
912 +
913 + TRACE("Entered squashfs_statfs\n");
914 + buf->f_type = SQUASHFS_MAGIC;
915 + buf->f_bsize = sBlk->block_size;
916 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
917 + buf->f_bfree = buf->f_bavail = 0;
918 + buf->f_files = sBlk->inodes;
919 + buf->f_ffree = 0;
920 + buf->f_namelen = SQUASHFS_NAME_LEN;
921 + return 0;
922 +}
923 +
924 +
925 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
926 +{
927 + struct inode *inode = page->mapping->host;
928 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
929 + int block = inode->u.squashfs_i.start_block;
930 + int offset = inode->u.squashfs_i.offset;
931 +
932 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
933 + page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
934 +
935 + for(length = 0; length < index; length += bytes) {
936 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
937 + PAGE_CACHE_SIZE, &block, &offset))) {
938 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
939 + goto skip_read;
940 + }
941 + }
942 +
943 + if(length != index) {
944 + ERROR("(squashfs_symlink_readpage) length != index\n");
945 + return 0;
946 + }
947 +
948 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
949 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
950 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
951 +
952 +skip_read:
953 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
954 + flush_dcache_page(page);
955 + SetPageUptodate(page);
956 + UnlockPage(page);
957 +
958 + return 0;
959 +}
960 +
961 +
962 +#define SIZE 256
963 +static int squashfs_readpage(struct file *file, struct page *page)
964 +{
965 + struct inode *inode = page->mapping->host;
966 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
967 + squashfs_super_block *sBlk = &msBlk->sBlk;
968 + unsigned char block_list[SIZE];
969 + unsigned short *block_listp;
970 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
971 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
972 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
973 + int block = inode->u.squashfs_i.start_block, i = 0;
974 + int bytes = 0, block_ptr = inode->u.squashfs_i.block_list_start;
975 + int offset = inode->u.squashfs_i.offset;
976 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
977 + int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
978 +
979 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
980 + inode->u.squashfs_i.start_block);
981 +
982 + if(index > file_blocks)
983 + goto skip_read;
984 +
985 + for(;;) {
986 + int blocks = (index + readahead_blks - i);
987 + if(blocks > (SIZE >> 1)) {
988 + if((index - i) <= (SIZE >> 1))
989 + blocks = index - i;
990 + else
991 + blocks = SIZE >> 1;
992 + }
993 +
994 + if(msBlk->swap) {
995 + unsigned char sblock_list[SIZE];
996 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
997 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
998 + goto skip_read;
999 + }
1000 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
1001 + } else
1002 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
1003 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
1004 + goto skip_read;
1005 + }
1006 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
1007 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1008 + if(blocks >= readahead_blks)
1009 + break;
1010 + }
1011 +
1012 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
1013 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
1014 + int start_index = page->index & ~mask;
1015 + int end_index = start_index | mask;
1016 + int byte_offset = 0;
1017 +
1018 + down(&msBlk->read_page_mutex);
1019 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
1020 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1021 + goto skip_read;
1022 + }
1023 +
1024 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
1025 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
1026 +
1027 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
1028 +
1029 + if(i == page->index) {
1030 + memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
1031 + memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1032 + flush_dcache_page(page);
1033 + SetPageUptodate(page);
1034 + UnlockPage(page);
1035 + } else {
1036 + struct page *push_page;
1037 +
1038 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
1039 + memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
1040 + memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
1041 + flush_dcache_page(push_page);
1042 + SetPageUptodate(push_page);
1043 + UnlockPage(push_page);
1044 + page_cache_release(push_page);
1045 + }
1046 + }
1047 + }
1048 + up( &msBlk->read_page_mutex);
1049 +
1050 + return 0;
1051 +
1052 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
1053 + if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
1054 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1055 +
1056 + } else {
1057 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
1058 + char *p = (char *) page_address(page);
1059 + int byte;
1060 +
1061 + if(i_end > file_blocks)
1062 + i_end = file_blocks;
1063 +
1064 + while(index < i_end) {
1065 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
1066 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
1067 + goto skip_read;
1068 + }
1069 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
1070 + p += byte;
1071 + bytes += byte;
1072 + index ++;
1073 + block_listp ++;
1074 + }
1075 + }
1076 +
1077 +skip_read:
1078 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
1079 + flush_dcache_page(page);
1080 + SetPageUptodate(page);
1081 + UnlockPage(page);
1082 +
1083 + return 0;
1084 +}
1085 +
1086 +
1087 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1088 +{
1089 + struct inode *i = file->f_dentry->d_inode;
1090 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1091 + squashfs_super_block *sBlk = &msBlk->sBlk;
1092 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1093 + i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
1094 + squashfs_dir_header dirh;
1095 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1096 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1097 +
1098 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
1099 +
1100 + while(length < i->i_size) {
1101 + /* read directory header */
1102 + if(msBlk->swap) {
1103 + squashfs_dir_header sdirh;
1104 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
1105 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1106 + goto failed_read;
1107 + length += sizeof(sdirh);
1108 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1109 + } else {
1110 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
1111 + next_offset, sizeof(dirh), &next_block, &next_offset))
1112 + goto failed_read;
1113 + length += sizeof(dirh);
1114 + }
1115 +
1116 + dir_count = dirh.count + 1;
1117 + while(dir_count--) {
1118 + if(msBlk->swap) {
1119 + squashfs_dir_entry sdire;
1120 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
1121 + next_offset, sizeof(sdire), &next_block, &next_offset))
1122 + goto failed_read;
1123 + length += sizeof(sdire);
1124 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1125 + } else {
1126 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
1127 + next_offset, sizeof(*dire), &next_block, &next_offset))
1128 + goto failed_read;
1129 + length += sizeof(*dire);
1130 + }
1131 +
1132 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1133 + next_offset, dire->size + 1, &next_block, &next_offset))
1134 + goto failed_read;
1135 + length += dire->size + 1;
1136 +
1137 + if(file->f_pos >= length)
1138 + continue;
1139 +
1140 + dire->name[dire->size + 1] = '\0';
1141 +
1142 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
1143 + dire->name, dire->size + 1, (int) file->f_pos,
1144 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
1145 +
1146 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
1147 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
1148 + TRACE("Filldir returned less than 0\n");
1149 + return dirs_read;
1150 + }
1151 +
1152 + file->f_pos = length;
1153 + dirs_read ++;
1154 + }
1155 + }
1156 +
1157 + return dirs_read;
1158 +
1159 +failed_read:
1160 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1161 + return 0;
1162 +}
1163 +
1164 +
1165 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
1166 +{
1167 + const char *name =dentry->d_name.name;
1168 + int len = dentry->d_name.len;
1169 + struct inode *inode = NULL;
1170 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
1171 + squashfs_super_block *sBlk = &msBlk->sBlk;
1172 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
1173 + i->u.squashfs_i.offset, length = 0, dir_count;
1174 + squashfs_dir_header dirh;
1175 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1176 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
1177 +
1178 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
1179 +
1180 + while(length < i->i_size) {
1181 + /* read directory header */
1182 + if(msBlk->swap) {
1183 + squashfs_dir_header sdirh;
1184 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
1185 + sizeof(sdirh), &next_block, &next_offset))
1186 + goto failed_read;
1187 + length += sizeof(sdirh);
1188 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1189 + } else {
1190 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
1191 + sizeof(dirh), &next_block, &next_offset))
1192 + goto failed_read;
1193 + length += sizeof(dirh);
1194 + }
1195 +
1196 + dir_count = dirh.count + 1;
1197 + while(dir_count--) {
1198 + if(msBlk->swap) {
1199 + squashfs_dir_entry sdire;
1200 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
1201 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
1202 + goto failed_read;
1203 + length += sizeof(*dire);
1204 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1205 + } else {
1206 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
1207 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
1208 + goto failed_read;
1209 + length += sizeof(*dire);
1210 + }
1211 +
1212 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
1213 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
1214 + goto failed_read;
1215 + length += dire->size + 1;
1216 +
1217 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1218 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1219 +
1220 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1221 + name, dirh.start_block, dire->offset);
1222 +
1223 + inode = squashfs_iget(i->i_sb, ino);
1224 +
1225 + goto exit_loop;
1226 + }
1227 + }
1228 + }
1229 +
1230 +exit_loop:
1231 + d_add(dentry, inode);
1232 + return ERR_PTR(0);
1233 +
1234 +failed_read:
1235 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1236 + goto exit_loop;
1237 +}
1238 +
1239 +
1240 +static void squashfs_put_super(struct super_block *s)
1241 +{
1242 + if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
1243 + if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
1244 + if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
1245 + if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
1246 + s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
1247 + s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
1248 +}
1249 +
1250 +
1251 +static int __init init_squashfs_fs(void)
1252 +{
1253 +
1254 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1255 + ERROR("Failed to allocate zlib workspace\n");
1256 + return -ENOMEM;
1257 + }
1258 + return register_filesystem(&squashfs_fs_type);
1259 +}
1260 +
1261 +
1262 +static void __exit exit_squashfs_fs(void)
1263 +{
1264 + vfree(stream.workspace);
1265 + unregister_filesystem(&squashfs_fs_type);
1266 +}
1267 +
1268 +
1269 +EXPORT_NO_SYMBOLS;
1270 +
1271 +module_init(init_squashfs_fs);
1272 +module_exit(exit_squashfs_fs);
1273 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1274 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1275 +MODULE_LICENSE("GPL");
1276 diff -urN src/linux-dist/linux/include/linux/fs.h src/linux/linux/include/linux/fs.h
1277 --- src/linux-dist/linux/include/linux/fs.h 2003-07-04 03:12:25.000000000 -0500
1278 +++ src/linux/linux/include/linux/fs.h 2004-03-29 17:00:53.000000000 -0600
1279 @@ -313,6 +313,7 @@
1280 #include <linux/usbdev_fs_i.h>
1281 #include <linux/jffs2_fs_i.h>
1282 #include <linux/cramfs_fs_sb.h>
1283 +#include <linux/squashfs_fs_i.h>
1284
1285 /*
1286 * Attribute flags. These should be or-ed together to figure out what
1287 @@ -503,6 +504,7 @@
1288 struct socket socket_i;
1289 struct usbdev_inode_info usbdev_i;
1290 struct jffs2_inode_info jffs2_i;
1291 + struct squashfs_inode_info squashfs_i;
1292 void *generic_ip;
1293 } u;
1294 };
1295 @@ -697,6 +699,7 @@
1296 #include <linux/usbdev_fs_sb.h>
1297 #include <linux/cramfs_fs_sb.h>
1298 #include <linux/jffs2_fs_sb.h>
1299 +#include <linux/squashfs_fs_sb.h>
1300
1301 extern struct list_head super_blocks;
1302 extern spinlock_t sb_lock;
1303 @@ -755,6 +758,7 @@
1304 struct usbdev_sb_info usbdevfs_sb;
1305 struct jffs2_sb_info jffs2_sb;
1306 struct cramfs_sb_info cramfs_sb;
1307 + struct squashfs_sb_info squashfs_sb;
1308 void *generic_sbp;
1309 } u;
1310 /*
1311 diff -urN src/linux-dist/linux/include/linux/squashfs_fs.h src/linux/linux/include/linux/squashfs_fs.h
1312 --- src/linux-dist/linux/include/linux/squashfs_fs.h 1969-12-31 18:00:00.000000000 -0600
1313 +++ src/linux/linux/include/linux/squashfs_fs.h 2004-03-29 17:00:53.000000000 -0600
1314 @@ -0,0 +1,323 @@
1315 +#ifndef SQUASHFS_FS
1316 +#define SQUASHFS_FS
1317 +/*
1318 + * Squashfs
1319 + *
1320 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1321 + *
1322 + * This program is free software; you can redistribute it and/or
1323 + * modify it under the terms of the GNU General Public License
1324 + * as published by the Free Software Foundation; either version
1325 + * 2 of the License, or (at your option) any later version.
1326 + *
1327 + * squashfs_fs.h
1328 + */
1329 +
1330 +#define SQUASHFS_MAJOR 1
1331 +#define SQUASHFS_MINOR 0
1332 +#define SQUASHFS_MAGIC 0x73717368
1333 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1334 +#define SQUASHFS_START 0
1335 +
1336 +/* size of metadata (inode and directory) blocks */
1337 +#define SQUASHFS_METADATA_SIZE 8192
1338 +#define SQUASHFS_METADATA_LOG 13
1339 +
1340 +/* default size of data blocks */
1341 +#define SQUASHFS_FILE_SIZE 32768
1342 +#define SQUASHFS_FILE_LOG 15
1343 +
1344 +#define SQUASHFS_FILE_MAX_SIZE 32768
1345 +
1346 +/* Max number of uids and gids */
1347 +#define SQUASHFS_UIDS 48
1348 +#define SQUASHFS_GUIDS 15
1349 +
1350 +/* Max length of filename (not 255) */
1351 +#define SQUASHFS_NAME_LEN 256
1352 +
1353 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1354 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1355 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1356 +
1357 +/* Filesystem flags */
1358 +#define SQUASHFS_NOI 1
1359 +#define SQUASHFS_NOD 2
1360 +#define SQUASHFS_CHECK 4
1361 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1362 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1363 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1364 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1365 +
1366 +/* Max number of types and file types */
1367 +#define SQUASHFS_TYPES 5
1368 +#define SQUASHFS_DIR_TYPE 1
1369 +#define SQUASHFS_FILE_TYPE 2
1370 +#define SQUASHFS_SYMLINK_TYPE 3
1371 +#define SQUASHFS_BLKDEV_TYPE 4
1372 +#define SQUASHFS_CHRDEV_TYPE 5
1373 +
1374 +#define SQUASHFS_IPC_TYPE 0
1375 +#define SQUASHFS_FIFO_TYPE 6
1376 +#define SQUASHFS_SOCKET_TYPE 7
1377 +
1378 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1379 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1380 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1381 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1382 +
1383 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1384 +
1385 +/*
1386 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1387 + * offset within that block
1388 + */
1389 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1390 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1391 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1392 + + (B)))
1393 +
1394 +/* Compute 32 bit VFS inode number from squashfs inode number */
1395 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1396 +
1397 +/* Translate between VFS mode and squashfs mode */
1398 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1399 +
1400 +/* cached data constants for filesystem */
1401 +#define SQUASHFS_CACHED_BLKS 8
1402 +
1403 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1404 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1405 +
1406 +#define SQUASHFS_MARKER_BYTE 0xff
1407 +
1408 +/*
1409 + * definitions for structures on disk
1410 + */
1411 +
1412 +typedef unsigned int squashfs_block;
1413 +typedef long long squashfs_inode;
1414 +
1415 +typedef unsigned int squashfs_uid;
1416 +
1417 +typedef struct squashfs_super_block {
1418 + unsigned int s_magic;
1419 + unsigned int inodes;
1420 + unsigned int bytes_used;
1421 + unsigned int uid_start;
1422 + unsigned int guid_start;
1423 + unsigned int inode_table_start;
1424 + unsigned int directory_table_start;
1425 + unsigned int s_major:16;
1426 + unsigned int s_minor:16;
1427 + unsigned int block_size:16;
1428 + unsigned int block_log:16;
1429 + unsigned int flags:8;
1430 + unsigned int no_uids:8;
1431 + unsigned int no_guids:8;
1432 + time_t mkfs_time /* time of filesystem creation */;
1433 + squashfs_inode root_inode;
1434 +} __attribute__ ((packed)) squashfs_super_block;
1435 +
1436 +typedef struct {
1437 + unsigned int inode_type:4;
1438 + unsigned int mode:12; /* protection */
1439 + unsigned int uid:4; /* index into uid table */
1440 + unsigned int guid:4; /* index into guid table */
1441 +} __attribute__ ((packed)) squashfs_base_inode_header;
1442 +
1443 +typedef struct {
1444 + unsigned int inode_type:4;
1445 + unsigned int mode:12; /* protection */
1446 + unsigned int uid:4; /* index into uid table */
1447 + unsigned int guid:4; /* index into guid table */
1448 + unsigned int type:4;
1449 + unsigned int offset:4;
1450 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1451 +
1452 +typedef struct {
1453 + unsigned int inode_type:4;
1454 + unsigned int mode:12; /* protection */
1455 + unsigned int uid:4; /* index into uid table */
1456 + unsigned int guid:4; /* index into guid table */
1457 + unsigned short rdev;
1458 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1459 +
1460 +typedef struct {
1461 + unsigned int inode_type:4;
1462 + unsigned int mode:12; /* protection */
1463 + unsigned int uid:4; /* index into uid table */
1464 + unsigned int guid:4; /* index into guid table */
1465 + unsigned short symlink_size;
1466 + char symlink[0];
1467 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1468 +
1469 +typedef struct {
1470 + unsigned int inode_type:4;
1471 + unsigned int mode:12; /* protection */
1472 + unsigned int uid:4; /* index into uid table */
1473 + unsigned int guid:4; /* index into guid table */
1474 + time_t mtime;
1475 + squashfs_block start_block;
1476 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1477 + unsigned short block_list[0];
1478 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1479 +
1480 +typedef struct {
1481 + unsigned int inode_type:4;
1482 + unsigned int mode:12; /* protection */
1483 + unsigned int uid:4; /* index into uid table */
1484 + unsigned int guid:4; /* index into guid table */
1485 + unsigned int file_size:19;
1486 + unsigned int offset:13;
1487 + time_t mtime;
1488 + unsigned int start_block:24;
1489 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1490 +
1491 +typedef union {
1492 + squashfs_base_inode_header base;
1493 + squashfs_dev_inode_header dev;
1494 + squashfs_symlink_inode_header symlink;
1495 + squashfs_reg_inode_header reg;
1496 + squashfs_dir_inode_header dir;
1497 + squashfs_ipc_inode_header ipc;
1498 +} squashfs_inode_header;
1499 +
1500 +typedef struct {
1501 + unsigned int offset:13;
1502 + unsigned int type:3;
1503 + unsigned int size:8;
1504 + char name[0];
1505 +} __attribute__ ((packed)) squashfs_dir_entry;
1506 +
1507 +typedef struct {
1508 + unsigned int count:8;
1509 + unsigned int start_block:24;
1510 +} __attribute__ ((packed)) squashfs_dir_header;
1511 +
1512 +
1513 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1514 +extern int squashfs_uncompress_init(void);
1515 +extern int squashfs_uncompress_exit(void);
1516 +
1517 +/*
1518 + * macros to convert each packed bitfield structure from little endian to big
1519 + * endian and vice versa. These are needed when creating or using a filesystem on a
1520 + * machine with different byte ordering to the target architecture.
1521 + *
1522 + */
1523 +
1524 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1525 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1526 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1527 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1528 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1529 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1530 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1531 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1532 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1533 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1534 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1535 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1536 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1537 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1538 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1539 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1540 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1541 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1542 +}
1543 +
1544 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1545 + SQUASHFS_MEMSET(s, d, n);\
1546 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1547 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1548 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1549 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1550 +}
1551 +
1552 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1553 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1554 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
1555 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1556 +}
1557 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1558 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1559 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1560 +}
1561 +
1562 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1563 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1564 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1565 +}
1566 +
1567 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1568 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1569 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1570 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1571 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1572 +}
1573 +
1574 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1575 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1576 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1577 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1578 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1579 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1580 +}
1581 +
1582 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1583 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1584 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1585 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1586 +}
1587 +
1588 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1589 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1590 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1591 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1592 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1593 +}
1594 +
1595 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1596 + int entry;\
1597 + int bit_position;\
1598 + SQUASHFS_MEMSET(s, d, n * 2);\
1599 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1600 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1601 +}
1602 +
1603 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1604 + int entry;\
1605 + int bit_position;\
1606 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1607 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1608 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1609 +}
1610 +
1611 +#ifdef __KERNEL__
1612 +/*
1613 + * macros used to swap each structure entry, taking into account
1614 + * bitfields and different bitfield placing conventions on differing architectures
1615 + */
1616 +#include <asm/byteorder.h>
1617 +#ifdef __BIG_ENDIAN
1618 + /* convert from little endian to big endian */
1619 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1620 +#else
1621 + /* convert from big endian to little endian */
1622 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1623 +#endif
1624 +
1625 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1626 + int bits;\
1627 + int b_pos = pos % 8;\
1628 + unsigned long long val = 0;\
1629 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1630 + unsigned char *d = ((unsigned char *) &val) + 7;\
1631 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1632 + *d-- = *s++;\
1633 + value = (val >> (SHIFT));\
1634 +}
1635 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1636 +#endif
1637 +#endif
1638 diff -urN src/linux-dist/linux/include/linux/squashfs_fs_i.h src/linux/linux/include/linux/squashfs_fs_i.h
1639 --- src/linux-dist/linux/include/linux/squashfs_fs_i.h 1969-12-31 18:00:00.000000000 -0600
1640 +++ src/linux/linux/include/linux/squashfs_fs_i.h 2004-03-29 17:00:53.000000000 -0600
1641 @@ -0,0 +1,21 @@
1642 +#ifndef SQUASHFS_FS_I
1643 +#define SQUASHFS_FS_I
1644 +/*
1645 + * Squashfs
1646 + *
1647 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1648 + *
1649 + * This program is free software; you can redistribute it and/or
1650 + * modify it under the terms of the GNU General Public License
1651 + * as published by the Free Software Foundation; either version
1652 + * 2 of the License, or (at your option) any later version.
1653 + *
1654 + * squashfs_fs_i.h
1655 + */
1656 +
1657 +typedef struct squashfs_inode_info {
1658 + unsigned int start_block;
1659 + unsigned int block_list_start;
1660 + unsigned int offset;
1661 + } squashfs_inode_info;
1662 +#endif
1663 diff -urN src/linux-dist/linux/include/linux/squashfs_fs_sb.h src/linux/linux/include/linux/squashfs_fs_sb.h
1664 --- src/linux-dist/linux/include/linux/squashfs_fs_sb.h 1969-12-31 18:00:00.000000000 -0600
1665 +++ src/linux/linux/include/linux/squashfs_fs_sb.h 2004-03-29 17:00:53.000000000 -0600
1666 @@ -0,0 +1,41 @@
1667 +#ifndef SQUASHFS_FS_SB
1668 +#define SQUASHFS_FS_SB
1669 +/*
1670 + * Squashfs
1671 + *
1672 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1673 + *
1674 + * This program is free software; you can redistribute it and/or
1675 + * modify it under the terms of the GNU General Public License
1676 + * as published by the Free Software Foundation; either version
1677 + * 2 of the License, or (at your option) any later version.
1678 + *
1679 + * squashfs_fs_sb.h
1680 + */
1681 +
1682 +#include <linux/squashfs_fs.h>
1683 +
1684 +typedef struct {
1685 + unsigned int block;
1686 + int length;
1687 + unsigned int next_index;
1688 + char *data;
1689 + } squashfs_cache;
1690 +
1691 +typedef struct squashfs_sb_info {
1692 + squashfs_super_block sBlk;
1693 + int devblksize;
1694 + int devblksize_log2;
1695 + int swap;
1696 + squashfs_cache *block_cache;
1697 + int next_cache;
1698 + squashfs_uid *uid;
1699 + squashfs_uid *guid;
1700 + unsigned int read_size;
1701 + char *read_data;
1702 + char *read_page;
1703 + struct semaphore read_page_mutex;
1704 + struct semaphore block_cache_mutex;
1705 + wait_queue_head_t waitq;
1706 + } squashfs_sb_info;
1707 +#endif
1708 diff -urN src/linux-dist/linux/init/do_mounts.c src/linux/linux/init/do_mounts.c
1709 --- src/linux-dist/linux/init/do_mounts.c 2003-11-08 02:13:20.000000000 -0600
1710 +++ src/linux/linux/init/do_mounts.c 2004-03-29 17:00:53.000000000 -0600
1711 @@ -16,6 +16,7 @@
1712 #include <linux/ext2_fs.h>
1713 #include <linux/romfs_fs.h>
1714 #include <linux/cramfs_fs.h>
1715 +#include <linux/squashfs_fs.h>
1716
1717 #undef BUILD_CRAMDISK
1718
1719 @@ -470,6 +471,7 @@
1720 * ext2
1721 * romfs
1722 * gzip
1723 + * squashfs
1724 */
1725 static int __init
1726 identify_ramdisk_image(int fd, int start_block)
1727 @@ -479,6 +481,7 @@
1728 struct ext2_super_block *ext2sb;
1729 struct romfs_super_block *romfsb;
1730 struct cramfs_super *cramfsb;
1731 + struct squashfs_super_block *squashfsb;
1732 int nblocks = -1;
1733 unsigned char *buf;
1734
1735 @@ -490,6 +493,7 @@
1736 ext2sb = (struct ext2_super_block *) buf;
1737 romfsb = (struct romfs_super_block *) buf;
1738 cramfsb = (struct cramfs_super *) buf;
1739 + squashfsb = (struct squashfs_super_block *) buf;
1740 memset(buf, 0xe5, size);
1741
1742 /*
1743 @@ -536,6 +540,15 @@
1744 goto done;
1745 }
1746
1747 + /* squashfs is at block zero too */
1748 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
1749 + printk(KERN_NOTICE
1750 + "RAMDISK: squashfs filesystem found at block %d\n",
1751 + start_block);
1752 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
1753 + goto done;
1754 + }
1755 +
1756 /*
1757 * Read block 1 to test for minix and ext2 superblock
1758 */
1759 diff -urN src/linux-dist/linux/kernel/ksyms.c src/linux/linux/kernel/ksyms.c
1760 --- src/linux-dist/linux/kernel/ksyms.c 2003-07-04 03:12:28.000000000 -0500
1761 +++ src/linux/linux/kernel/ksyms.c 2004-03-29 17:00:53.000000000 -0600
1762 @@ -482,9 +483,9 @@
1763 EXPORT_SYMBOL(simple_strtoull);
1764 EXPORT_SYMBOL(system_utsname); /* UTS data */
1765 EXPORT_SYMBOL(uts_sem); /* UTS semaphore */
1766 -#ifndef __mips__
1767 +//#ifndef __mips__ //bite me. -mbm.
1768 EXPORT_SYMBOL(sys_call_table);
1769 -#endif
1770 +//#endif
1771 EXPORT_SYMBOL(machine_restart);
1772 EXPORT_SYMBOL(machine_halt);
1773 EXPORT_SYMBOL(machine_power_off);
1774 diff -urN src/linux-dist/linux/lib/Config.in src/linux/linux/lib/Config.in
1775 --- src/linux-dist/linux/lib/Config.in 2003-07-04 03:12:29.000000000 -0500
1776 +++ src/linux/linux/lib/Config.in 2004-03-29 17:00:53.000000000 -0600
1777 @@ -8,12 +8,14 @@
1778 # Do we need the compression support?
1779 #
1780 if [ "$CONFIG_CRAMFS" = "y" -o \
1781 + "$CONFIG_SQUASHFS" = "y" -o \
1782 "$CONFIG_PPP_DEFLATE" = "y" -o \
1783 "$CONFIG_JFFS2_FS" = "y" -o \
1784 "$CONFIG_ZISOFS_FS" = "y" ]; then
1785 define_tristate CONFIG_ZLIB_INFLATE y
1786 else
1787 if [ "$CONFIG_CRAMFS" = "m" -o \
1788 + "$CONFIG_SQUASHFS" = "m" -o \
1789 "$CONFIG_PPP_DEFLATE" = "m" -o \
1790 "$CONFIG_JFFS2_FS" = "m" -o \
1791 "$CONFIG_ZISOFS_FS" = "m" ]; then
This page took 0.116362 seconds and 3 git commands to generate.