1 diff --new-file -ur linux-2.4.21/fs/Config.in linux-2.4.21-squashfs1.3/fs/Config.in
2 --- linux-2.4.21/fs/Config.in Thu Nov 28 23:53:15 2002
3 +++ linux-2.4.21-squashfs1.3/fs/Config.in Tue Jul 29 03:15:06 2003
5 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
7 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
8 +tristate 'Squashed file system support' CONFIG_SQUASHFS
9 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
10 define_bool CONFIG_RAMFS y
12 diff --new-file -ur linux-2.4.21/fs/Makefile linux-2.4.21-squashfs1.3/fs/Makefile
13 --- linux-2.4.21/fs/Makefile Thu Nov 28 23:53:15 2002
14 +++ linux-2.4.21-squashfs1.3/fs/Makefile Tue Jul 29 03:15:06 2003
16 subdir-$(CONFIG_BEFS_FS) += befs
17 subdir-$(CONFIG_JFS_FS) += jfs
18 subdir-$(CONFIG_XFS_FS) += xfs
19 +subdir-$(CONFIG_SQUASHFS) += squashfs
21 obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o
22 obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o
23 diff --new-file -ur linux-2.4.21/fs/squashfs/Makefile linux-2.4.21-squashfs1.3/fs/squashfs/Makefile
24 --- linux-2.4.21/fs/squashfs/Makefile Thu Jan 1 01:00:00 1970
25 +++ linux-2.4.21-squashfs1.3/fs/squashfs/Makefile Tue Jul 29 03:15:06 2003
28 +# Makefile for the linux squashfs routines.
31 +O_TARGET := squashfs.o
37 +include $(TOPDIR)/Rules.make
38 diff --new-file -ur linux-2.4.21/fs/squashfs/inode.c linux-2.4.21-squashfs1.3/fs/squashfs/inode.c
39 --- linux-2.4.21/fs/squashfs/inode.c Thu Jan 1 01:00:00 1970
40 +++ linux-2.4.21-squashfs1.3/fs/squashfs/inode.c Tue Jul 29 03:15:06 2003
43 + * Squashfs - a compressed read only filesystem for Linux
45 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
47 + * This program is free software; you can redistribute it and/or
48 + * modify it under the terms of the GNU General Public License
49 + * as published by the Free Software Foundation; either version
50 + * 2 of the License, or (at your option) any later version.
55 +#include <linux/types.h>
56 +#include <linux/squashfs_fs.h>
57 +#include <linux/module.h>
58 +#include <linux/errno.h>
59 +#include <linux/slab.h>
60 +#include <linux/fs.h>
61 +#include <linux/locks.h>
62 +#include <linux/init.h>
63 +#include <linux/dcache.h>
64 +#include <asm/uaccess.h>
65 +#include <linux/wait.h>
66 +#include <asm/semaphore.h>
68 +#include <linux/zlib.h>
69 +#include <linux/blkdev.h>
70 +#include <linux/vmalloc.h>
72 +#ifdef SQUASHFS_TRACE
73 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
75 +#define TRACE(s, args...) {}
78 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
80 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
81 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
83 +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
84 +static void squashfs_put_super(struct super_block *);
85 +static int squashfs_statfs(struct super_block *, struct statfs *);
86 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
87 +static int squashfs_readpage(struct file *file, struct page *page);
88 +static int squashfs_readdir(struct file *, void *, filldir_t);
89 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
90 +static unsigned int read_data(struct super_block *s, char *buffer,
91 + unsigned int index, int length, unsigned int *next_index);
92 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
93 + unsigned int block, unsigned int offset, int length,
94 + unsigned int *next_block, unsigned int *next_offset);
95 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
96 +static void squashfs_put_super(struct super_block *s);
98 +DECLARE_MUTEX(read_data_mutex);
100 +static z_stream stream;
102 +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
104 +static unsigned char squashfs_filetype_table[] = {
105 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
108 +static struct super_operations squashfs_ops = {
109 + statfs: squashfs_statfs,
110 + put_super: squashfs_put_super,
113 +static struct address_space_operations squashfs_symlink_aops = {
114 + readpage: squashfs_symlink_readpage
117 +static struct address_space_operations squashfs_aops = {
118 + readpage: squashfs_readpage
121 +static struct file_operations squashfs_dir_ops = {
122 + read: generic_read_dir,
123 + readdir: squashfs_readdir
126 +static struct inode_operations squashfs_dir_inode_ops = {
127 + lookup: squashfs_lookup
131 +static unsigned int read_data(struct super_block *s, char *buffer,
132 + unsigned int index, int length, unsigned int *next_index)
134 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
135 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
136 + unsigned short c_byte;
137 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
138 + unsigned int cur_index = index >> msBlk->devblksize_log2;
139 + int bytes, avail_bytes, b, k;
141 + unsigned int compressed;
143 + if(!(bh[0] = sb_bread(s, cur_index)))
149 + if(msBlk->devblksize - offset == 1) {
151 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
153 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
155 + if(!(bh[0] = sb_bread(s, ++cur_index)))
158 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data);
160 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data);
165 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
166 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
168 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
171 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
172 + if(offset == msBlk->devblksize) {
174 + if(!(bh[0] = sb_bread(s, ++cur_index)))
178 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
179 + ERROR("Metadata block marker corrupt @ %x\n", index);
187 + bytes = msBlk->devblksize - offset;
188 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
189 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
191 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
193 + for(b = 1; bytes < c_byte; b++) {
194 + if(!(bh[b] = sb_bread(s, ++cur_index)))
195 + goto block_release;
196 + bytes += msBlk->devblksize;
200 + down(&read_data_mutex);
202 + for(bytes = 0, k = 0; k < b; k++) {
203 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
204 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
205 + bytes += avail_bytes;
216 + stream.next_in = c_buffer;
217 + stream.avail_in = c_byte;
218 + stream.next_out = buffer;
219 + stream.avail_out = msBlk->read_size;
220 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
221 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
222 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
223 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
226 + bytes = stream.total_out;
227 + up(&read_data_mutex);
231 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
236 + while(--b >= 0) brelse(bh[b]);
239 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
244 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
245 + unsigned int block, unsigned int offset, int length,
246 + unsigned int *next_block, unsigned int *next_offset)
248 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
249 + int n, i, bytes, return_length = length;
250 + unsigned int next_index;
252 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
255 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
256 + if(msBlk->block_cache[i].block == block)
259 + down(&msBlk->block_cache_mutex);
260 + if(i == SQUASHFS_CACHED_BLKS) {
261 + /* read inode header block */
262 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
263 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
266 + up(&msBlk->block_cache_mutex);
267 + sleep_on(&msBlk->waitq);
270 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
272 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
273 + if(!(msBlk->block_cache[i].data = (unsigned char *)
274 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
275 + ERROR("Failed to allocate cache block\n");
276 + up(&msBlk->block_cache_mutex);
281 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
282 + up(&msBlk->block_cache_mutex);
283 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
285 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
288 + down(&msBlk->block_cache_mutex);
289 + wake_up(&msBlk->waitq);
290 + msBlk->block_cache[i].block = block;
291 + msBlk->block_cache[i].next_index = next_index;
292 + TRACE("Read cache block [%x:%x]\n", block, offset);
295 + if(msBlk->block_cache[i].block != block) {
296 + up(&msBlk->block_cache_mutex);
300 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
302 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
303 + if(msBlk->block_cache[i].length - offset == length) {
304 + *next_block = msBlk->block_cache[i].next_index;
307 + *next_block = block;
308 + *next_offset = offset + length;
311 + up(&msBlk->block_cache_mutex);
312 + return return_length;
315 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
318 + block = msBlk->block_cache[i].next_index;
319 + up(&msBlk->block_cache_mutex);
327 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
329 + struct inode *i = new_inode(s);
330 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
331 + squashfs_super_block *sBlk = &msBlk->sBlk;
332 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
333 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
334 + unsigned int next_block, next_offset;
335 + squashfs_base_inode_header inodeb;
337 + TRACE("Entered squashfs_iget\n");
340 + squashfs_base_inode_header sinodeb;
342 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
343 + sizeof(sinodeb), &next_block, &next_offset))
345 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
347 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
348 + sizeof(inodeb), &next_block, &next_offset))
353 + i->i_mtime = sBlk->mkfs_time;
354 + i->i_atime = sBlk->mkfs_time;
355 + i->i_ctime = sBlk->mkfs_time;
357 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
358 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
359 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
361 + i->i_mode = inodeb.mode;
363 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
364 + case SQUASHFS_FILE_TYPE: {
365 + squashfs_reg_inode_header inodep;
368 + squashfs_reg_inode_header sinodep;
370 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
371 + &next_block, &next_offset))
373 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
375 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
376 + &next_block, &next_offset))
379 + i->i_size = inodep.file_size;
380 + i->i_fop = &generic_ro_fops;
381 + i->i_data.a_ops = &squashfs_aops;
382 + i->i_mode |= S_IFREG;
383 + i->i_mtime = inodep.mtime;
384 + i->i_atime = inodep.mtime;
385 + i->i_ctime = inodep.mtime;
386 + i->u.squashfs_i.start_block = inodep.start_block;
387 + i->u.squashfs_i.block_list_start = next_block;
388 + i->u.squashfs_i.offset = next_offset;
389 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
390 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
393 + case SQUASHFS_DIR_TYPE: {
394 + squashfs_dir_inode_header inodep;
397 + squashfs_dir_inode_header sinodep;
399 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
400 + &next_block, &next_offset))
402 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
404 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
405 + &next_block, &next_offset))
408 + i->i_size = inodep.file_size;
409 + i->i_op = &squashfs_dir_inode_ops;
410 + i->i_fop = &squashfs_dir_ops;
411 + i->i_mode |= S_IFDIR;
412 + i->i_mtime = inodep.mtime;
413 + i->i_atime = inodep.mtime;
414 + i->i_ctime = inodep.mtime;
415 + i->u.squashfs_i.start_block = inodep.start_block;
416 + i->u.squashfs_i.offset = inodep.offset;
417 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
418 + inodep.start_block, inodep.offset);
421 + case SQUASHFS_SYMLINK_TYPE: {
422 + squashfs_symlink_inode_header inodep;
425 + squashfs_symlink_inode_header sinodep;
427 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
428 + &next_block, &next_offset))
430 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
432 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
433 + &next_block, &next_offset))
436 + i->i_size = inodep.symlink_size;
437 + i->i_op = &page_symlink_inode_operations;
438 + i->i_data.a_ops = &squashfs_symlink_aops;
439 + i->i_mode |= S_IFLNK;
440 + i->u.squashfs_i.start_block = next_block;
441 + i->u.squashfs_i.offset = next_offset;
442 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
443 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
446 + case SQUASHFS_BLKDEV_TYPE:
447 + case SQUASHFS_CHRDEV_TYPE: {
448 + squashfs_dev_inode_header inodep;
451 + squashfs_dev_inode_header sinodep;
453 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
454 + &next_block, &next_offset))
456 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
458 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
459 + &next_block, &next_offset))
463 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
464 + init_special_inode(i, i->i_mode, inodep.rdev);
465 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
468 + case SQUASHFS_IPC_TYPE: {
469 + squashfs_ipc_inode_header inodep;
472 + squashfs_ipc_inode_header sinodep;
474 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
475 + &next_block, &next_offset))
477 + SQUASHFS_SWAP_IPC_INODE_HEADER(&inodep, &sinodep);
479 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
480 + &next_block, &next_offset))
484 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
485 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
486 + init_special_inode(i, i->i_mode, 0);
490 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
494 + if(inodeb.guid == SQUASHFS_GUIDS)
495 + i->i_gid = i->i_uid;
497 + i->i_gid = msBlk->guid[inodeb.guid];
502 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
509 +static struct super_block *squashfs_read_super(struct super_block *s,
510 + void *data, int silent)
512 + kdev_t dev = s->s_dev;
513 + squashfs_sb_info *msBlk = &s->u.squashfs_sb;
514 + squashfs_super_block *sBlk = &msBlk->sBlk;
517 + TRACE("Entered squashfs_read_superblock\n");
519 + msBlk->devblksize = get_hardsect_size(dev);
520 + if(msBlk->devblksize < BLOCK_SIZE)
521 + msBlk->devblksize = BLOCK_SIZE;
522 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
523 + set_blocksize(dev, msBlk->devblksize);
524 + s->s_blocksize = msBlk->devblksize;
525 + s->s_blocksize_bits = msBlk->devblksize_log2;
527 + init_MUTEX(&msBlk->read_page_mutex);
528 + init_MUTEX(&msBlk->block_cache_mutex);
530 + init_waitqueue_head(&msBlk->waitq);
532 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
533 + SERROR("unable to read superblock\n");
537 + /* Check it is a SQUASHFS superblock */
539 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
540 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
541 + squashfs_super_block sblk;
542 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(dev));
543 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
544 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
547 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(dev));
552 + /* Check the MAJOR & MINOR versions */
553 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
554 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
555 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
559 + TRACE("Found valid superblock on %s\n", bdevname(dev));
560 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
561 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
562 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
563 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
564 + TRACE("Block size %d\n", sBlk->block_size);
565 + TRACE("Number of inodes %d\n", sBlk->inodes);
566 + TRACE("Number of uids %d\n", sBlk->no_uids);
567 + TRACE("Number of gids %d\n", sBlk->no_guids);
568 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
569 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
570 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
572 + s->s_flags |= MS_RDONLY;
573 + s->s_op = &squashfs_ops;
575 + /* Init inode_table block pointer array */
576 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
577 + ERROR("Failed to allocate block cache\n");
581 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
582 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
584 + msBlk->next_cache = 0;
586 + /* Allocate read_data block */
587 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
588 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
589 + ERROR("Failed to allocate read_data block\n");
590 + goto failed_mount1;
593 + /* Allocate read_page block */
594 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
595 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
596 + ERROR("Failed to allocate read_page block\n");
597 + goto failed_mount2;
600 + /* Allocate uid and gid tables */
601 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
602 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
603 + ERROR("Failed to allocate uid/gid table\n");
604 + goto failed_mount3;
606 + msBlk->guid = msBlk->uid + sBlk->no_uids;
609 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
611 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
612 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
613 + SERROR("unable to read uid/gid table\n");
614 + goto failed_mount4;
616 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
618 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
619 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
620 + SERROR("unable to read uid/gid table\n");
621 + goto failed_mount4;
624 + if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
625 + ERROR("Root inode create failed\n");
626 + goto failed_mount4;
629 + TRACE("Leaving squashfs_read_super\n");
635 + kfree(msBlk->read_page);
637 + kfree(msBlk->read_data);
639 + kfree(msBlk->block_cache);
645 +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
647 + squashfs_super_block *sBlk = &s->u.squashfs_sb.sBlk;
649 + TRACE("Entered squashfs_statfs\n");
650 + buf->f_type = SQUASHFS_MAGIC;
651 + buf->f_bsize = sBlk->block_size;
652 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
653 + buf->f_bfree = buf->f_bavail = 0;
654 + buf->f_files = sBlk->inodes;
656 + buf->f_namelen = SQUASHFS_NAME_LEN;
661 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
663 + struct inode *inode = page->mapping->host;
664 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
665 + int block = inode->u.squashfs_i.start_block;
666 + int offset = inode->u.squashfs_i.offset;
668 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
669 + page->index, inode->u.squashfs_i.start_block, inode->u.squashfs_i.offset);
671 + for(length = 0; length < index; length += bytes) {
672 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
673 + PAGE_CACHE_SIZE, &block, &offset))) {
674 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
679 + if(length != index) {
680 + ERROR("(squashfs_symlink_readpage) length != index\n");
684 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
685 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
686 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
689 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
690 + flush_dcache_page(page);
691 + SetPageUptodate(page);
699 +static int squashfs_readpage(struct file *file, struct page *page)
701 + struct inode *inode = page->mapping->host;
702 + squashfs_sb_info *msBlk = &inode->i_sb->u.squashfs_sb;
703 + squashfs_super_block *sBlk = &msBlk->sBlk;
704 + unsigned char block_list[SIZE];
705 + unsigned short *block_listp;
706 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
707 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
708 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
709 + int block = inode->u.squashfs_i.start_block, i = 0;
710 + int bytes = 0, block_ptr = inode->u.squashfs_i.block_list_start;
711 + int offset = inode->u.squashfs_i.offset;
712 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
713 + int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
715 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
716 + inode->u.squashfs_i.start_block);
718 + if(index > file_blocks)
722 + int blocks = (index + readahead_blks - i);
723 + if(blocks > (SIZE >> 1)) {
724 + if((index - i) <= (SIZE >> 1))
725 + blocks = index - i;
727 + blocks = SIZE >> 1;
731 + unsigned char sblock_list[SIZE];
732 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
733 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
736 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
738 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
739 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
742 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
743 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
744 + if(blocks >= readahead_blks)
748 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
749 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
750 + int start_index = page->index & ~mask;
751 + int end_index = start_index | mask;
752 + int byte_offset = 0;
754 + down(&msBlk->read_page_mutex);
755 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
756 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
760 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
761 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
763 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
765 + if(i == page->index) {
766 + memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
767 + memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
768 + flush_dcache_page(page);
769 + SetPageUptodate(page);
772 + struct page *push_page;
774 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
775 + memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
776 + memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
777 + flush_dcache_page(push_page);
778 + SetPageUptodate(push_page);
779 + UnlockPage(push_page);
780 + page_cache_release(push_page);
784 + up( &msBlk->read_page_mutex);
788 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
789 + if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
790 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
793 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
794 + char *p = (char *) page_address(page);
797 + if(i_end > file_blocks)
798 + i_end = file_blocks;
800 + while(index < i_end) {
801 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
802 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
805 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
814 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
815 + flush_dcache_page(page);
816 + SetPageUptodate(page);
823 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
825 + struct inode *i = file->f_dentry->d_inode;
826 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
827 + squashfs_super_block *sBlk = &msBlk->sBlk;
828 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
829 + i->u.squashfs_i.offset, length = 0, dirs_read = 0, dir_count;
830 + squashfs_dir_header dirh;
831 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
832 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
834 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
836 + while(length < i->i_size) {
837 + /* read directory header */
839 + squashfs_dir_header sdirh;
840 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
841 + next_offset, sizeof(sdirh), &next_block, &next_offset))
843 + length += sizeof(sdirh);
844 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
846 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
847 + next_offset, sizeof(dirh), &next_block, &next_offset))
849 + length += sizeof(dirh);
852 + dir_count = dirh.count + 1;
853 + while(dir_count--) {
855 + squashfs_dir_entry sdire;
856 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
857 + next_offset, sizeof(sdire), &next_block, &next_offset))
859 + length += sizeof(sdire);
860 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
862 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
863 + next_offset, sizeof(*dire), &next_block, &next_offset))
865 + length += sizeof(*dire);
868 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
869 + next_offset, dire->size + 1, &next_block, &next_offset))
871 + length += dire->size + 1;
873 + if(file->f_pos >= length)
876 + dire->name[dire->size + 1] = '\0';
878 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
879 + dire->name, dire->size + 1, (int) file->f_pos,
880 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
882 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
883 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
884 + TRACE("Filldir returned less than 0\n");
888 + file->f_pos = length;
896 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
901 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
903 + const char *name =dentry->d_name.name;
904 + int len = dentry->d_name.len;
905 + struct inode *inode = NULL;
906 + squashfs_sb_info *msBlk = &i->i_sb->u.squashfs_sb;
907 + squashfs_super_block *sBlk = &msBlk->sBlk;
908 + int next_block = i->u.squashfs_i.start_block + sBlk->directory_table_start, next_offset =
909 + i->u.squashfs_i.offset, length = 0, dir_count;
910 + squashfs_dir_header dirh;
911 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
912 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
914 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
916 + while(length < i->i_size) {
917 + /* read directory header */
919 + squashfs_dir_header sdirh;
920 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
921 + sizeof(sdirh), &next_block, &next_offset))
923 + length += sizeof(sdirh);
924 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
926 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
927 + sizeof(dirh), &next_block, &next_offset))
929 + length += sizeof(dirh);
932 + dir_count = dirh.count + 1;
933 + while(dir_count--) {
935 + squashfs_dir_entry sdire;
936 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
937 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
939 + length += sizeof(*dire);
940 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
942 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
943 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
945 + length += sizeof(*dire);
948 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
949 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
951 + length += dire->size + 1;
953 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
954 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
956 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
957 + name, dirh.start_block, dire->offset);
959 + inode = squashfs_iget(i->i_sb, ino);
967 + d_add(dentry, inode);
971 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
976 +static void squashfs_put_super(struct super_block *s)
978 + if(s->u.squashfs_sb.block_cache) kfree(s->u.squashfs_sb.block_cache);
979 + if(s->u.squashfs_sb.read_data) kfree(s->u.squashfs_sb.read_data);
980 + if(s->u.squashfs_sb.read_page) kfree(s->u.squashfs_sb.read_page);
981 + if(s->u.squashfs_sb.uid) kfree(s->u.squashfs_sb.uid);
982 + s->u.squashfs_sb.block_cache = (void *) s->u.squashfs_sb.uid =
983 + s->u.squashfs_sb.read_data = s->u.squashfs_sb.read_page = NULL;
987 +static int __init init_squashfs_fs(void)
990 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
991 + ERROR("Failed to allocate zlib workspace\n");
994 + return register_filesystem(&squashfs_fs_type);
998 +static void __exit exit_squashfs_fs(void)
1000 + vfree(stream.workspace);
1001 + unregister_filesystem(&squashfs_fs_type);
1007 +module_init(init_squashfs_fs);
1008 +module_exit(exit_squashfs_fs);
1009 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1010 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1011 +MODULE_LICENSE("GPL");
1012 diff --new-file -ur linux-2.4.21/include/linux/fs.h linux-2.4.21-squashfs1.3/include/linux/fs.h
1013 --- linux-2.4.21/include/linux/fs.h Fri Jun 13 15:51:38 2003
1014 +++ linux-2.4.21-squashfs1.3/include/linux/fs.h Tue Jul 29 03:15:06 2003
1016 #include <linux/hppfs_fs_i.h>
1017 #include <linux/jffs2_fs_i.h>
1018 #include <linux/cramfs_fs_sb.h>
1019 +#include <linux/squashfs_fs_i.h>
1022 * Attribute flags. These should be or-ed together to figure out what
1024 struct hostfs_inode_info hostfs_i;
1025 struct hppfs_inode_info hppfs_i;
1026 struct jffs2_inode_info jffs2_i;
1027 + struct squashfs_inode_info squashfs_i;
1032 #include <linux/usbdev_fs_sb.h>
1033 #include <linux/cramfs_fs_sb.h>
1034 #include <linux/jffs2_fs_sb.h>
1035 +#include <linux/squashfs_fs_sb.h>
1037 extern struct list_head super_blocks;
1038 extern spinlock_t sb_lock;
1040 struct usbdev_sb_info usbdevfs_sb;
1041 struct jffs2_sb_info jffs2_sb;
1042 struct cramfs_sb_info cramfs_sb;
1043 + struct squashfs_sb_info squashfs_sb;
1047 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs.h
1048 --- linux-2.4.21/include/linux/squashfs_fs.h Thu Jan 1 01:00:00 1970
1049 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs.h Tue Jul 29 03:15:06 2003
1051 +#ifndef SQUASHFS_FS
1052 +#define SQUASHFS_FS
1056 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1058 + * This program is free software; you can redistribute it and/or
1059 + * modify it under the terms of the GNU General Public License
1060 + * as published by the Free Software Foundation; either version
1061 + * 2 of the License, or (at your option) any later version.
1066 +#define SQUASHFS_MAJOR 1
1067 +#define SQUASHFS_MINOR 0
1068 +#define SQUASHFS_MAGIC 0x73717368
1069 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1070 +#define SQUASHFS_START 0
1072 +/* size of metadata (inode and directory) blocks */
1073 +#define SQUASHFS_METADATA_SIZE 8192
1074 +#define SQUASHFS_METADATA_LOG 13
1076 +/* default size of data blocks */
1077 +#define SQUASHFS_FILE_SIZE 32768
1078 +#define SQUASHFS_FILE_LOG 15
1080 +#define SQUASHFS_FILE_MAX_SIZE 32768
1082 +/* Max number of uids and gids */
1083 +#define SQUASHFS_UIDS 48
1084 +#define SQUASHFS_GUIDS 15
1086 +/* Max length of filename (not 255) */
1087 +#define SQUASHFS_NAME_LEN 256
1089 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1090 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1091 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1093 +/* Filesystem flags */
1094 +#define SQUASHFS_NOI 1
1095 +#define SQUASHFS_NOD 2
1096 +#define SQUASHFS_CHECK 4
1097 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1098 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1099 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1100 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1102 +/* Max number of types and file types */
1103 +#define SQUASHFS_TYPES 5
1104 +#define SQUASHFS_DIR_TYPE 1
1105 +#define SQUASHFS_FILE_TYPE 2
1106 +#define SQUASHFS_SYMLINK_TYPE 3
1107 +#define SQUASHFS_BLKDEV_TYPE 4
1108 +#define SQUASHFS_CHRDEV_TYPE 5
1110 +#define SQUASHFS_IPC_TYPE 0
1111 +#define SQUASHFS_FIFO_TYPE 6
1112 +#define SQUASHFS_SOCKET_TYPE 7
1114 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1115 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1116 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1117 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1119 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1122 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1123 + * offset within that block
1125 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1126 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1127 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1130 +/* Compute 32 bit VFS inode number from squashfs inode number */
1131 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1133 +/* Translate between VFS mode and squashfs mode */
1134 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1136 +/* cached data constants for filesystem */
1137 +#define SQUASHFS_CACHED_BLKS 8
1139 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1140 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1142 +#define SQUASHFS_MARKER_BYTE 0xff
1145 + * definitions for structures on disk
1148 +typedef unsigned int squashfs_block;
1149 +typedef long long squashfs_inode;
1151 +typedef unsigned int squashfs_uid;
1153 +typedef struct squashfs_super_block {
1154 + unsigned int s_magic;
1155 + unsigned int inodes;
1156 + unsigned int bytes_used;
1157 + unsigned int uid_start;
1158 + unsigned int guid_start;
1159 + unsigned int inode_table_start;
1160 + unsigned int directory_table_start;
1161 + unsigned int s_major:16;
1162 + unsigned int s_minor:16;
1163 + unsigned int block_size:16;
1164 + unsigned int block_log:16;
1165 + unsigned int flags:8;
1166 + unsigned int no_uids:8;
1167 + unsigned int no_guids:8;
1168 + time_t mkfs_time /* time of filesystem creation */;
1169 + squashfs_inode root_inode;
1170 +} __attribute__ ((packed)) squashfs_super_block;
1173 + unsigned int inode_type:4;
1174 + unsigned int mode:12; /* protection */
1175 + unsigned int uid:4; /* index into uid table */
1176 + unsigned int guid:4; /* index into guid table */
1177 +} __attribute__ ((packed)) squashfs_base_inode_header;
1180 + unsigned int inode_type:4;
1181 + unsigned int mode:12; /* protection */
1182 + unsigned int uid:4; /* index into uid table */
1183 + unsigned int guid:4; /* index into guid table */
1184 + unsigned int type:4;
1185 + unsigned int offset:4;
1186 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1189 + unsigned int inode_type:4;
1190 + unsigned int mode:12; /* protection */
1191 + unsigned int uid:4; /* index into uid table */
1192 + unsigned int guid:4; /* index into guid table */
1193 + unsigned short rdev;
1194 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1197 + unsigned int inode_type:4;
1198 + unsigned int mode:12; /* protection */
1199 + unsigned int uid:4; /* index into uid table */
1200 + unsigned int guid:4; /* index into guid table */
1201 + unsigned short symlink_size;
1203 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1206 + unsigned int inode_type:4;
1207 + unsigned int mode:12; /* protection */
1208 + unsigned int uid:4; /* index into uid table */
1209 + unsigned int guid:4; /* index into guid table */
1211 + squashfs_block start_block;
1212 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1213 + unsigned short block_list[0];
1214 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1217 + unsigned int inode_type:4;
1218 + unsigned int mode:12; /* protection */
1219 + unsigned int uid:4; /* index into uid table */
1220 + unsigned int guid:4; /* index into guid table */
1221 + unsigned int file_size:19;
1222 + unsigned int offset:13;
1224 + unsigned int start_block:24;
1225 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1228 + squashfs_base_inode_header base;
1229 + squashfs_dev_inode_header dev;
1230 + squashfs_symlink_inode_header symlink;
1231 + squashfs_reg_inode_header reg;
1232 + squashfs_dir_inode_header dir;
1233 + squashfs_ipc_inode_header ipc;
1234 +} squashfs_inode_header;
1237 + unsigned int offset:13;
1238 + unsigned int type:3;
1239 + unsigned int size:8;
1241 +} __attribute__ ((packed)) squashfs_dir_entry;
1244 + unsigned int count:8;
1245 + unsigned int start_block:24;
1246 +} __attribute__ ((packed)) squashfs_dir_header;
1249 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1250 +extern int squashfs_uncompress_init(void);
1251 +extern int squashfs_uncompress_exit(void);
1254 + * macros to convert each packed bitfield structure from little endian to big
1255 + * endian and vice versa. These are needed when creating or using a filesystem on a
1256 + * machine with different byte ordering to the target architecture.
1260 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1261 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1262 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1263 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1264 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1265 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1266 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1267 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1268 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1269 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1270 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1271 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1272 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1273 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1274 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1275 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1276 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1277 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1280 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1281 + SQUASHFS_MEMSET(s, d, n);\
1282 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1283 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1284 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1285 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1288 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1289 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1290 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
1291 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1293 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1294 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1295 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1298 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1299 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1300 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1303 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1304 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1305 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1306 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1307 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1310 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1311 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1312 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1313 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1314 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1315 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1318 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1319 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1320 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1321 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1324 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1325 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1326 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1327 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1328 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1331 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1333 + int bit_position;\
1334 + SQUASHFS_MEMSET(s, d, n * 2);\
1335 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1336 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1339 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1341 + int bit_position;\
1342 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1343 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1344 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1349 + * macros used to swap each structure entry, taking into account
1350 + * bitfields and different bitfield placing conventions on differing architectures
1352 +#include <asm/byteorder.h>
1353 +#ifdef __BIG_ENDIAN
1354 + /* convert from little endian to big endian */
1355 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1357 + /* convert from big endian to little endian */
1358 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1361 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1363 + int b_pos = pos % 8;\
1364 + unsigned long long val = 0;\
1365 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1366 + unsigned char *d = ((unsigned char *) &val) + 7;\
1367 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1369 + value = (val >> (SHIFT));\
1371 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1374 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs_i.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_i.h
1375 --- linux-2.4.21/include/linux/squashfs_fs_i.h Thu Jan 1 01:00:00 1970
1376 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_i.h Tue Jul 29 03:15:06 2003
1378 +#ifndef SQUASHFS_FS_I
1379 +#define SQUASHFS_FS_I
1383 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1385 + * This program is free software; you can redistribute it and/or
1386 + * modify it under the terms of the GNU General Public License
1387 + * as published by the Free Software Foundation; either version
1388 + * 2 of the License, or (at your option) any later version.
1393 +typedef struct squashfs_inode_info {
1394 + unsigned int start_block;
1395 + unsigned int block_list_start;
1396 + unsigned int offset;
1397 + } squashfs_inode_info;
1399 diff --new-file -ur linux-2.4.21/include/linux/squashfs_fs_sb.h linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_sb.h
1400 --- linux-2.4.21/include/linux/squashfs_fs_sb.h Thu Jan 1 01:00:00 1970
1401 +++ linux-2.4.21-squashfs1.3/include/linux/squashfs_fs_sb.h Tue Jul 29 03:15:06 2003
1403 +#ifndef SQUASHFS_FS_SB
1404 +#define SQUASHFS_FS_SB
1408 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1410 + * This program is free software; you can redistribute it and/or
1411 + * modify it under the terms of the GNU General Public License
1412 + * as published by the Free Software Foundation; either version
1413 + * 2 of the License, or (at your option) any later version.
1415 + * squashfs_fs_sb.h
1418 +#include <linux/squashfs_fs.h>
1421 + unsigned int block;
1423 + unsigned int next_index;
1427 +typedef struct squashfs_sb_info {
1428 + squashfs_super_block sBlk;
1430 + int devblksize_log2;
1432 + squashfs_cache *block_cache;
1434 + squashfs_uid *uid;
1435 + squashfs_uid *guid;
1436 + unsigned int read_size;
1439 + struct semaphore read_page_mutex;
1440 + struct semaphore block_cache_mutex;
1441 + wait_queue_head_t waitq;
1442 + } squashfs_sb_info;
1444 diff --new-file -ur linux-2.4.21/init/do_mounts.c linux-2.4.21-squashfs1.3/init/do_mounts.c
1445 --- linux-2.4.21/init/do_mounts.c Fri Jun 13 15:51:39 2003
1446 +++ linux-2.4.21-squashfs1.3/init/do_mounts.c Tue Jul 29 03:15:06 2003
1448 #include <linux/ext2_fs.h>
1449 #include <linux/romfs_fs.h>
1450 #include <linux/cramfs_fs.h>
1451 +#include <linux/squashfs_fs.h>
1453 #define BUILD_CRAMDISK
1462 identify_ramdisk_image(int fd, int start_block)
1464 struct ext2_super_block *ext2sb;
1465 struct romfs_super_block *romfsb;
1466 struct cramfs_super *cramfsb;
1467 + struct squashfs_super_block *squashfsb;
1472 ext2sb = (struct ext2_super_block *) buf;
1473 romfsb = (struct romfs_super_block *) buf;
1474 cramfsb = (struct cramfs_super *) buf;
1475 + squashfsb = (struct squashfs_super_block *) buf;
1476 memset(buf, 0xe5, size);
1479 @@ -522,6 +526,15 @@
1483 + /* squashfs is at block zero too */
1484 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
1485 + printk(KERN_NOTICE
1486 + "RAMDISK: squashfs filesystem found at block %d\n",
1488 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
1493 * Read block 1 to test for minix and ext2 superblock
1495 diff --new-file -ur linux-2.4.21/lib/Config.in linux-2.4.21-squashfs1.3/lib/Config.in
1496 --- linux-2.4.21/lib/Config.in Thu Nov 28 23:53:15 2002
1497 +++ linux-2.4.21-squashfs1.3/lib/Config.in Tue Jul 29 03:15:06 2003
1499 # Do we need the compression support?
1501 if [ "$CONFIG_CRAMFS" = "y" -o \
1502 + "$CONFIG_SQUASHFS" = "y" -o \
1503 "$CONFIG_PPP_DEFLATE" = "y" -o \
1504 "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
1505 "$CONFIG_JFFS2_FS" = "y" -o \
1506 "$CONFIG_ZISOFS_FS" = "y" ]; then
1507 define_tristate CONFIG_ZLIB_INFLATE y
1509 if [ "$CONFIG_CRAMFS" = "m" -o \
1510 + "$CONFIG_SQUASHFS" = "m" -o \
1511 "$CONFIG_PPP_DEFLATE" = "m" -o \
1512 "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
1513 "$CONFIG_JFFS2_FS" = "m" -o \
1514 "$CONFIG_ZISOFS_FS" = "m" ]; then