1 diff --new-file -ur linux-2.6.1/fs/Kconfig linux-2.6.1-squashfs1.3r3/fs/Kconfig
2 --- linux-2.6.1/fs/Kconfig 2004-01-09 06:59:44.000000000 +0000
3 +++ linux-2.6.1-squashfs1.3r3/fs/Kconfig 2004-01-17 23:44:35.000000000 +0000
9 + tristate "SquashFS - Squashed file system support"
12 + Saying Y here includes support for SquashFs (Compressed Read-Only File
13 + System). Squashfs is a highly compressed read-only filesystem for Linux.
14 + It uses zlib compression to compress both files, inodes and directories.
15 + Inodes in the system are very small and all blocks are packed to minimise
16 + data overhead. Block sizes greater than 4K are supported up to a maximum of 32K.
18 + Squashfs is intended for general read-only filesystem use, for archival
19 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
20 + systems where low overhead is needed. Further information and filesystem tools
21 + are available from http://squashfs.sourceforge.net.
23 + If you want to compile this as a module ( = code which can be
24 + inserted in and removed from the running kernel whenever you want),
25 + say M here and read <file:Documentation/modules.txt>. The module
26 + will be called squashfs. Note that the root file system (the one
27 + containing the directory /) cannot be compiled as a module.
32 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
34 diff --new-file -ur linux-2.6.1/fs/Makefile linux-2.6.1-squashfs1.3r3/fs/Makefile
35 --- linux-2.6.1/fs/Makefile 2004-01-09 06:59:44.000000000 +0000
36 +++ linux-2.6.1-squashfs1.3r3/fs/Makefile 2004-01-17 23:44:35.000000000 +0000
38 obj-$(CONFIG_JBD) += jbd/
39 obj-$(CONFIG_EXT2_FS) += ext2/
40 obj-$(CONFIG_CRAMFS) += cramfs/
41 +obj-$(CONFIG_SQUASHFS) += squashfs/
42 obj-$(CONFIG_RAMFS) += ramfs/
43 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
44 obj-$(CONFIG_CODA_FS) += coda/
45 diff --new-file -ur linux-2.6.1/fs/squashfs/inode.c linux-2.6.1-squashfs1.3r3/fs/squashfs/inode.c
46 --- linux-2.6.1/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
47 +++ linux-2.6.1-squashfs1.3r3/fs/squashfs/inode.c 2004-01-17 23:47:16.000000000 +0000
50 + * Squashfs - a compressed read only filesystem for Linux
52 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
54 + * This program is free software; you can redistribute it and/or
55 + * modify it under the terms of the GNU General Public License
56 + * as published by the Free Software Foundation; either version
57 + * 2 of the License, or (at your option) any later version.
62 +#include <linux/types.h>
63 +#include <linux/squashfs_fs.h>
64 +#include <linux/module.h>
65 +#include <linux/errno.h>
66 +#include <linux/slab.h>
67 +#include <linux/fs.h>
68 +#include <linux/smp_lock.h>
69 +#include <linux/slab.h>
70 +#include <linux/squashfs_fs_sb.h>
71 +#include <linux/squashfs_fs_i.h>
72 +#include <linux/buffer_head.h>
73 +#include <linux/vfs.h>
74 +#include <linux/init.h>
75 +#include <linux/dcache.h>
76 +#include <asm/uaccess.h>
77 +#include <linux/wait.h>
78 +#include <asm/semaphore.h>
79 +#include <linux/zlib.h>
80 +#include <linux/blkdev.h>
81 +#include <linux/vmalloc.h>
83 +#ifdef SQUASHFS_TRACE
84 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
86 +#define TRACE(s, args...) {}
89 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
91 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
92 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
94 +static void squashfs_put_super(struct super_block *);
95 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
96 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
97 +static int squashfs_readpage(struct file *file, struct page *page);
98 +static int squashfs_readdir(struct file *, void *, filldir_t);
99 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *, struct nameidata *);
100 +static unsigned int read_data(struct super_block *s, char *buffer,
101 + unsigned int index, int length, unsigned int *next_index);
102 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
103 + unsigned int block, unsigned int offset, int length,
104 + unsigned int *next_block, unsigned int *next_offset);
105 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
106 +static void squashfs_put_super(struct super_block *s);
107 +static struct super_block *squashfs_get_sb(struct file_system_type *, int, const char *, void *);
108 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
109 +static void squashfs_destroy_inode(struct inode *inode);
110 +static int init_inodecache(void);
111 +static void destroy_inodecache(void);
113 +DECLARE_MUTEX(read_data_mutex);
115 +static z_stream stream;
117 +static struct file_system_type squashfs_fs_type = {
118 + .owner = THIS_MODULE,
119 + .name = "squashfs",
120 + .get_sb = squashfs_get_sb,
121 + .kill_sb = kill_block_super,
122 + .fs_flags = FS_REQUIRES_DEV
125 +static unsigned char squashfs_filetype_table[] = {
126 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
129 +static struct super_operations squashfs_ops = {
130 + .alloc_inode = squashfs_alloc_inode,
131 + .destroy_inode = squashfs_destroy_inode,
132 + .statfs = squashfs_statfs,
133 + .put_super = squashfs_put_super,
136 +static struct address_space_operations squashfs_symlink_aops = {
137 + .readpage = squashfs_symlink_readpage
140 +static struct address_space_operations squashfs_aops = {
141 + .readpage = squashfs_readpage
144 +static struct file_operations squashfs_dir_ops = {
145 + .read = generic_read_dir,
146 + .readdir = squashfs_readdir
149 +static struct inode_operations squashfs_dir_inode_ops = {
150 + .lookup = squashfs_lookup
154 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
156 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
160 +static unsigned int read_data(struct super_block *s, char *buffer,
161 + unsigned int index, int length, unsigned int *next_index)
163 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
164 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
165 + unsigned short c_byte;
166 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
167 + unsigned int cur_index = index >> msBlk->devblksize_log2;
168 + int bytes, avail_bytes, b, k;
170 + unsigned int compressed;
172 + if(!(bh[0] = sb_bread(s, cur_index)))
178 + if(msBlk->devblksize - offset == 1) {
180 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
182 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
184 + if(!(bh[0] = sb_bread(s, ++cur_index)))
187 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data);
189 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data);
194 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
195 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
197 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
200 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
201 + if(offset == msBlk->devblksize) {
203 + if(!(bh[0] = sb_bread(s, ++cur_index)))
207 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
208 + ERROR("Metadata block marker corrupt @ %x\n", index);
216 + bytes = msBlk->devblksize - offset;
217 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
218 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
220 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
222 + for(b = 1; bytes < c_byte; b++) {
223 + if(!(bh[b] = sb_bread(s, ++cur_index)))
224 + goto block_release;
225 + bytes += msBlk->devblksize;
229 + down(&read_data_mutex);
231 + for(bytes = 0, k = 0; k < b; k++) {
232 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
233 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
234 + bytes += avail_bytes;
245 + stream.next_in = c_buffer;
246 + stream.avail_in = c_byte;
247 + stream.next_out = buffer;
248 + stream.avail_out = msBlk->read_size;
249 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
250 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
251 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
252 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
255 + bytes = stream.total_out;
256 + up(&read_data_mutex);
260 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
265 + while(--b >= 0) brelse(bh[b]);
268 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
273 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
274 + unsigned int block, unsigned int offset, int length,
275 + unsigned int *next_block, unsigned int *next_offset)
277 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
278 + int n, i, bytes, return_length = length;
279 + unsigned int next_index;
281 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
284 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
285 + if(msBlk->block_cache[i].block == block)
288 + down(&msBlk->block_cache_mutex);
289 + if(i == SQUASHFS_CACHED_BLKS) {
290 + /* read inode header block */
291 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
292 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
295 + up(&msBlk->block_cache_mutex);
296 + sleep_on(&msBlk->waitq);
299 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
301 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
302 + if(!(msBlk->block_cache[i].data = (unsigned char *)
303 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
304 + ERROR("Failed to allocate cache block\n");
305 + up(&msBlk->block_cache_mutex);
310 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
311 + up(&msBlk->block_cache_mutex);
312 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
314 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
317 + down(&msBlk->block_cache_mutex);
318 + wake_up(&msBlk->waitq);
319 + msBlk->block_cache[i].block = block;
320 + msBlk->block_cache[i].next_index = next_index;
321 + TRACE("Read cache block [%x:%x]\n", block, offset);
324 + if(msBlk->block_cache[i].block != block) {
325 + up(&msBlk->block_cache_mutex);
329 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
331 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
332 + if(msBlk->block_cache[i].length - offset == length) {
333 + *next_block = msBlk->block_cache[i].next_index;
336 + *next_block = block;
337 + *next_offset = offset + length;
340 + up(&msBlk->block_cache_mutex);
341 + return return_length;
344 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
347 + block = msBlk->block_cache[i].next_index;
348 + up(&msBlk->block_cache_mutex);
356 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
358 + struct inode *i = new_inode(s);
359 + squashfs_sb_info *msBlk = (squashfs_sb_info *)s->s_fs_info;
360 + squashfs_super_block *sBlk = &msBlk->sBlk;
361 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
362 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
363 + unsigned int next_block, next_offset;
364 + squashfs_base_inode_header inodeb;
366 + TRACE("Entered squashfs_iget\n");
369 + squashfs_base_inode_header sinodeb;
371 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
372 + sizeof(sinodeb), &next_block, &next_offset))
374 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
376 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
377 + sizeof(inodeb), &next_block, &next_offset))
382 + i->i_mtime.tv_sec = sBlk->mkfs_time;
383 + i->i_atime.tv_sec = sBlk->mkfs_time;
384 + i->i_ctime.tv_sec = sBlk->mkfs_time;
386 + if(inodeb.inode_type != SQUASHFS_IPC_TYPE)
387 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
388 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
390 + i->i_mode = inodeb.mode;
392 + switch(inodeb.inode_type == SQUASHFS_IPC_TYPE ? SQUASHFS_IPC_TYPE : (inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
393 + case SQUASHFS_FILE_TYPE: {
394 + squashfs_reg_inode_header inodep;
397 + squashfs_reg_inode_header sinodep;
399 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
400 + &next_block, &next_offset))
402 + SQUASHFS_SWAP_REG_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_fop = &generic_ro_fops;
410 + i->i_data.a_ops = &squashfs_aops;
411 + i->i_mode |= S_IFREG;
412 + i->i_mtime.tv_sec = inodep.mtime;
413 + i->i_atime.tv_sec = inodep.mtime;
414 + i->i_ctime.tv_sec = inodep.mtime;
415 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
416 + i->i_blksize = PAGE_CACHE_SIZE;
417 + SQUASHFS_I(i)->start_block = inodep.start_block;
418 + SQUASHFS_I(i)->block_list_start = next_block;
419 + SQUASHFS_I(i)->offset = next_offset;
420 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
421 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
424 + case SQUASHFS_DIR_TYPE: {
425 + squashfs_dir_inode_header inodep;
428 + squashfs_dir_inode_header sinodep;
430 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
431 + &next_block, &next_offset))
433 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
435 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
436 + &next_block, &next_offset))
439 + i->i_size = inodep.file_size;
440 + i->i_op = &squashfs_dir_inode_ops;
441 + i->i_fop = &squashfs_dir_ops;
442 + i->i_mode |= S_IFDIR;
443 + i->i_mtime.tv_sec = inodep.mtime;
444 + i->i_atime.tv_sec = inodep.mtime;
445 + i->i_ctime.tv_sec = inodep.mtime;
446 + SQUASHFS_I(i)->start_block = inodep.start_block;
447 + SQUASHFS_I(i)->offset = inodep.offset;
448 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
449 + inodep.start_block, inodep.offset);
452 + case SQUASHFS_SYMLINK_TYPE: {
453 + squashfs_symlink_inode_header inodep;
456 + squashfs_symlink_inode_header sinodep;
458 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
459 + &next_block, &next_offset))
461 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
463 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
464 + &next_block, &next_offset))
467 + i->i_size = inodep.symlink_size;
468 + i->i_op = &page_symlink_inode_operations;
469 + i->i_data.a_ops = &squashfs_symlink_aops;
470 + i->i_mode |= S_IFLNK;
471 + SQUASHFS_I(i)->start_block = next_block;
472 + SQUASHFS_I(i)->offset = next_offset;
473 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
474 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
477 + case SQUASHFS_BLKDEV_TYPE:
478 + case SQUASHFS_CHRDEV_TYPE: {
479 + squashfs_dev_inode_header inodep;
482 + squashfs_dev_inode_header sinodep;
484 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
485 + &next_block, &next_offset))
487 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
489 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
490 + &next_block, &next_offset))
494 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
495 + init_special_inode(i, i->i_mode, old_decode_dev(inodep.rdev));
496 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
499 + case SQUASHFS_IPC_TYPE: {
500 + squashfs_ipc_inode_header inodep;
503 + squashfs_ipc_inode_header sinodep;
505 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
506 + &next_block, &next_offset))
508 + SQUASHFS_SWAP_IPC_INODE_HEADER(&inodep, &sinodep);
510 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
511 + &next_block, &next_offset))
515 + i->i_mode |= (inodep.type == SQUASHFS_FIFO_TYPE) ? S_IFIFO : S_IFSOCK;
516 + i->i_uid = msBlk->uid[inodep.offset * 16 + inodeb.uid];
517 + init_special_inode(i, i->i_mode, 0);
521 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
525 + if(inodeb.guid == SQUASHFS_GUIDS)
526 + i->i_gid = i->i_uid;
528 + i->i_gid = msBlk->guid[inodeb.guid];
533 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
540 +static int squashfs_fill_super(struct super_block *s,
541 + void *data, int silent)
543 + squashfs_sb_info *msBlk;
544 + squashfs_super_block *sBlk;
546 + char b[BDEVNAME_SIZE];
548 + TRACE("Entered squashfs_read_superblock\n");
550 + if(!(msBlk = (squashfs_sb_info *) s->s_fs_info = (void *) kmalloc(sizeof(squashfs_sb_info), GFP_KERNEL))) {
551 + ERROR("Failed to allocate superblock\n");
554 + sBlk = &msBlk->sBlk;
556 + msBlk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
557 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
559 + init_MUTEX(&msBlk->read_page_mutex);
560 + init_MUTEX(&msBlk->block_cache_mutex);
562 + init_waitqueue_head(&msBlk->waitq);
564 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
565 + SERROR("unable to read superblock\n");
569 + /* Check it is a SQUASHFS superblock */
571 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
572 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
573 + squashfs_super_block sblk;
574 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", bdevname(s->s_bdev, b));
575 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
576 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
579 + SERROR("Can't find a SQUASHFS superblock on %s\n", bdevname(s->s_bdev, b));
584 + /* Check the MAJOR & MINOR versions */
585 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
586 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
587 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
591 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
592 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
593 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
594 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
595 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
596 + TRACE("Block size %d\n", sBlk->block_size);
597 + TRACE("Number of inodes %d\n", sBlk->inodes);
598 + TRACE("Number of uids %d\n", sBlk->no_uids);
599 + TRACE("Number of gids %d\n", sBlk->no_guids);
600 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
601 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
602 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
604 + s->s_flags |= MS_RDONLY;
605 + s->s_op = &squashfs_ops;
607 + /* Init inode_table block pointer array */
608 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
609 + ERROR("Failed to allocate block cache\n");
613 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
614 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
616 + msBlk->next_cache = 0;
618 + /* Allocate read_data block */
619 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
620 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
621 + ERROR("Failed to allocate read_data block\n");
622 + goto failed_mount1;
625 + /* Allocate read_page block */
626 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
627 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
628 + ERROR("Failed to allocate read_page block\n");
629 + goto failed_mount2;
632 + /* Allocate uid and gid tables */
633 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
634 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
635 + ERROR("Failed to allocate uid/gid table\n");
636 + goto failed_mount3;
638 + msBlk->guid = msBlk->uid + sBlk->no_uids;
641 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
643 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
644 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
645 + SERROR("unable to read uid/gid table\n");
646 + goto failed_mount4;
648 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
650 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
651 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
652 + SERROR("unable to read uid/gid table\n");
653 + goto failed_mount4;
656 + if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
657 + ERROR("Root inode create failed\n");
658 + goto failed_mount4;
661 + TRACE("Leaving squashfs_read_super\n");
667 + kfree(msBlk->read_page);
669 + kfree(msBlk->read_data);
671 + kfree(msBlk->block_cache);
673 + kfree(s->s_fs_info);
674 + s->s_fs_info = NULL;
679 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
681 + squashfs_super_block *sBlk = &((squashfs_sb_info *)s->s_fs_info)->sBlk;
683 + TRACE("Entered squashfs_statfs\n");
684 + buf->f_type = SQUASHFS_MAGIC;
685 + buf->f_bsize = sBlk->block_size;
686 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
687 + buf->f_bfree = buf->f_bavail = 0;
688 + buf->f_files = sBlk->inodes;
690 + buf->f_namelen = SQUASHFS_NAME_LEN;
695 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
697 + struct inode *inode = page->mapping->host;
698 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
699 + int block = SQUASHFS_I(inode)->start_block;
700 + int offset = SQUASHFS_I(inode)->offset;
701 + void *pageaddr = kmap(page);
703 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
704 + page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(i)->offset);
706 + for(length = 0; length < index; length += bytes) {
707 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
708 + PAGE_CACHE_SIZE, &block, &offset))) {
709 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
714 + if(length != index) {
715 + ERROR("(squashfs_symlink_readpage) length != index\n");
720 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
721 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset, bytes, &block, &offset)))
722 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
725 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
727 + flush_dcache_page(page);
728 + SetPageUptodate(page);
736 +static int squashfs_readpage(struct file *file, struct page *page)
738 + struct inode *inode = page->mapping->host;
739 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
740 + squashfs_super_block *sBlk = &msBlk->sBlk;
741 + unsigned char block_list[SIZE];
742 + unsigned short *block_listp;
743 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
744 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
745 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
746 + int block = SQUASHFS_I(inode)->start_block, i = 0;
747 + int bytes = 0, block_ptr = SQUASHFS_I(inode)->block_list_start;
748 + int offset = SQUASHFS_I(inode)->offset;
749 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
750 + int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
751 + void *pageaddr = kmap(page);
753 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
754 + SQUASHFS_I(inode)->start_block);
756 + if(index > file_blocks)
760 + int blocks = (index + readahead_blks - i);
761 + if(blocks > (SIZE >> 1)) {
762 + if((index - i) <= (SIZE >> 1))
763 + blocks = index - i;
765 + blocks = SIZE >> 1;
769 + unsigned char sblock_list[SIZE];
770 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
771 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
774 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
776 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
777 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
780 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
781 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
782 + if(blocks >= readahead_blks)
786 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
787 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
788 + int start_index = page->index & ~mask;
789 + int end_index = start_index | mask;
790 + int byte_offset = 0;
792 + down(&msBlk->read_page_mutex);
793 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
794 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
798 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
799 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
801 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
803 + if(i == page->index) {
804 + memcpy(pageaddr, msBlk->read_page + byte_offset, available_bytes);
805 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
807 + flush_dcache_page(page);
808 + SetPageUptodate(page);
811 + struct page *push_page;
813 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
814 + void *pageaddr = kmap(push_page);
815 + memcpy(pageaddr, msBlk->read_page + byte_offset, available_bytes);
816 + memset(pageaddr + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
818 + flush_dcache_page(push_page);
819 + SetPageUptodate(push_page);
820 + unlock_page(push_page);
821 + page_cache_release(push_page);
825 + up( &msBlk->read_page_mutex);
829 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
830 + if(!(bytes = read_data(inode->i_sb, pageaddr, block, *block_listp, NULL)))
831 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
834 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
835 + char *p = (char *) pageaddr;
838 + if(i_end > file_blocks)
839 + i_end = file_blocks;
841 + while(index < i_end) {
842 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
843 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
846 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
855 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
857 + flush_dcache_page(page);
858 + SetPageUptodate(page);
865 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
867 + struct inode *i = file->f_dentry->d_inode;
868 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
869 + squashfs_super_block *sBlk = &msBlk->sBlk;
870 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
871 + SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
872 + squashfs_dir_header dirh;
873 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
874 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
876 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
879 + while(length < i->i_size) {
880 + /* read directory header */
882 + squashfs_dir_header sdirh;
883 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
884 + next_offset, sizeof(sdirh), &next_block, &next_offset))
886 + length += sizeof(sdirh);
887 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
889 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
890 + next_offset, sizeof(dirh), &next_block, &next_offset))
892 + length += sizeof(dirh);
895 + dir_count = dirh.count + 1;
896 + while(dir_count--) {
898 + squashfs_dir_entry sdire;
899 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
900 + next_offset, sizeof(sdire), &next_block, &next_offset))
902 + length += sizeof(sdire);
903 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
905 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
906 + next_offset, sizeof(*dire), &next_block, &next_offset))
908 + length += sizeof(*dire);
911 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
912 + next_offset, dire->size + 1, &next_block, &next_offset))
914 + length += dire->size + 1;
916 + if(file->f_pos >= length)
919 + dire->name[dire->size + 1] = '\0';
921 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
922 + dire->name, dire->size + 1, (int) file->f_pos,
923 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
925 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
926 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
927 + TRACE("Filldir returned less than 0\n");
932 + file->f_pos = length;
942 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
947 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
949 + const char *name =dentry->d_name.name;
950 + int len = dentry->d_name.len;
951 + struct inode *inode = NULL;
952 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
953 + squashfs_super_block *sBlk = &msBlk->sBlk;
954 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
955 + SQUASHFS_I(i)->offset, length = 0, dir_count;
956 + squashfs_dir_header dirh;
957 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
958 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
960 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
963 + while(length < i->i_size) {
964 + /* read directory header */
966 + squashfs_dir_header sdirh;
967 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
968 + sizeof(sdirh), &next_block, &next_offset))
970 + length += sizeof(sdirh);
971 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
973 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
974 + sizeof(dirh), &next_block, &next_offset))
976 + length += sizeof(dirh);
979 + dir_count = dirh.count + 1;
980 + while(dir_count--) {
982 + squashfs_dir_entry sdire;
983 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
984 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
986 + length += sizeof(sdire);
987 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
989 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
990 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
992 + length += sizeof(*dire);
995 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
996 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
998 + length += dire->size + 1;
1000 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
1001 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
1003 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
1004 + name, dirh.start_block, dire->offset);
1006 + inode = squashfs_iget(i->i_sb, ino);
1014 + d_add(dentry, inode);
1016 + return ERR_PTR(0);
1019 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1024 +static void squashfs_put_super(struct super_block *s)
1026 + if(s->s_fs_info) {
1027 + squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1028 + if(sbi->block_cache) kfree(sbi->block_cache);
1029 + if(sbi->read_data) kfree(sbi->read_data);
1030 + if(sbi->read_page) kfree(sbi->read_page);
1031 + if(sbi->uid) kfree(sbi->uid);
1032 + kfree(s->s_fs_info);
1033 + s->s_fs_info = NULL;
1038 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1040 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1044 +static int __init init_squashfs_fs(void)
1046 + int err = init_inodecache();
1050 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1051 + ERROR("Failed to allocate zlib workspace\n");
1052 + destroy_inodecache();
1056 + if((err = register_filesystem(&squashfs_fs_type))) {
1057 + vfree(stream.workspace);
1058 + destroy_inodecache();
1065 +static void __exit exit_squashfs_fs(void)
1067 + vfree(stream.workspace);
1068 + unregister_filesystem(&squashfs_fs_type);
1069 + destroy_inodecache();
1073 +static kmem_cache_t * squashfs_inode_cachep;
1075 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1077 + struct squashfs_inode_info *ei;
1078 + ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1081 + return &ei->vfs_inode;
1084 +static void squashfs_destroy_inode(struct inode *inode)
1086 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1089 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1091 + struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1093 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1094 + SLAB_CTOR_CONSTRUCTOR)
1095 + inode_init_once(&ei->vfs_inode);
1098 +static int init_inodecache(void)
1100 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1101 + sizeof(struct squashfs_inode_info),
1102 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1104 + if (squashfs_inode_cachep == NULL)
1109 +static void destroy_inodecache(void)
1111 + if (kmem_cache_destroy(squashfs_inode_cachep))
1112 + printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1115 +module_init(init_squashfs_fs);
1116 +module_exit(exit_squashfs_fs);
1117 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1118 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1119 +MODULE_LICENSE("GPL");
1120 diff --new-file -ur linux-2.6.1/fs/squashfs/Makefile linux-2.6.1-squashfs1.3r3/fs/squashfs/Makefile
1121 --- linux-2.6.1/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
1122 +++ linux-2.6.1-squashfs1.3r3/fs/squashfs/Makefile 2004-01-17 23:44:35.000000000 +0000
1125 +# Makefile for the linux squashfs routines.
1128 +obj-$(CONFIG_SQUASHFS) += squashfs.o
1130 +squashfs-objs := inode.o
1131 diff --new-file -ur linux-2.6.1/include/linux/squashfs_fs.h linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs.h
1132 --- linux-2.6.1/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
1133 +++ linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs.h 2004-01-17 23:44:35.000000000 +0000
1135 +#ifndef SQUASHFS_FS
1136 +#define SQUASHFS_FS
1140 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1142 + * This program is free software; you can redistribute it and/or
1143 + * modify it under the terms of the GNU General Public License
1144 + * as published by the Free Software Foundation; either version
1145 + * 2 of the License, or (at your option) any later version.
1150 +#define SQUASHFS_MAJOR 1
1151 +#define SQUASHFS_MINOR 0
1152 +#define SQUASHFS_MAGIC 0x73717368
1153 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1154 +#define SQUASHFS_START 0
1156 +/* size of metadata (inode and directory) blocks */
1157 +#define SQUASHFS_METADATA_SIZE 8192
1158 +#define SQUASHFS_METADATA_LOG 13
1160 +/* default size of data blocks */
1161 +#define SQUASHFS_FILE_SIZE 32768
1162 +#define SQUASHFS_FILE_LOG 15
1164 +#define SQUASHFS_FILE_MAX_SIZE 32768
1166 +/* Max number of uids and gids */
1167 +#define SQUASHFS_UIDS 48
1168 +#define SQUASHFS_GUIDS 15
1170 +/* Max length of filename (not 255) */
1171 +#define SQUASHFS_NAME_LEN 256
1173 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1174 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1175 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1177 +/* Filesystem flags */
1178 +#define SQUASHFS_NOI 1
1179 +#define SQUASHFS_NOD 2
1180 +#define SQUASHFS_CHECK 4
1181 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1182 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1183 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1184 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1186 +/* Max number of types and file types */
1187 +#define SQUASHFS_TYPES 5
1188 +#define SQUASHFS_DIR_TYPE 1
1189 +#define SQUASHFS_FILE_TYPE 2
1190 +#define SQUASHFS_SYMLINK_TYPE 3
1191 +#define SQUASHFS_BLKDEV_TYPE 4
1192 +#define SQUASHFS_CHRDEV_TYPE 5
1194 +#define SQUASHFS_IPC_TYPE 0
1195 +#define SQUASHFS_FIFO_TYPE 6
1196 +#define SQUASHFS_SOCKET_TYPE 7
1198 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1199 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1200 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1201 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1203 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1206 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1207 + * offset within that block
1209 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1210 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1211 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1214 +/* Compute 32 bit VFS inode number from squashfs inode number */
1215 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1217 +/* Translate between VFS mode and squashfs mode */
1218 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1220 +/* cached data constants for filesystem */
1221 +#define SQUASHFS_CACHED_BLKS 8
1223 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1224 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1226 +#define SQUASHFS_MARKER_BYTE 0xff
1229 + * definitions for structures on disk
1232 +typedef unsigned int squashfs_block;
1233 +typedef long long squashfs_inode;
1235 +typedef unsigned int squashfs_uid;
1237 +typedef struct squashfs_super_block {
1238 + unsigned int s_magic;
1239 + unsigned int inodes;
1240 + unsigned int bytes_used;
1241 + unsigned int uid_start;
1242 + unsigned int guid_start;
1243 + unsigned int inode_table_start;
1244 + unsigned int directory_table_start;
1245 + unsigned int s_major:16;
1246 + unsigned int s_minor:16;
1247 + unsigned int block_size:16;
1248 + unsigned int block_log:16;
1249 + unsigned int flags:8;
1250 + unsigned int no_uids:8;
1251 + unsigned int no_guids:8;
1252 + time_t mkfs_time /* time of filesystem creation */;
1253 + squashfs_inode root_inode;
1254 +} __attribute__ ((packed)) squashfs_super_block;
1257 + unsigned int inode_type:4;
1258 + unsigned int mode:12; /* protection */
1259 + unsigned int uid:4; /* index into uid table */
1260 + unsigned int guid:4; /* index into guid table */
1261 +} __attribute__ ((packed)) squashfs_base_inode_header;
1264 + unsigned int inode_type:4;
1265 + unsigned int mode:12; /* protection */
1266 + unsigned int uid:4; /* index into uid table */
1267 + unsigned int guid:4; /* index into guid table */
1268 + unsigned int type:4;
1269 + unsigned int offset:4;
1270 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1273 + unsigned int inode_type:4;
1274 + unsigned int mode:12; /* protection */
1275 + unsigned int uid:4; /* index into uid table */
1276 + unsigned int guid:4; /* index into guid table */
1277 + unsigned short rdev;
1278 +} __attribute__ ((packed)) squashfs_dev_inode_header;
1281 + unsigned int inode_type:4;
1282 + unsigned int mode:12; /* protection */
1283 + unsigned int uid:4; /* index into uid table */
1284 + unsigned int guid:4; /* index into guid table */
1285 + unsigned short symlink_size;
1287 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1290 + unsigned int inode_type:4;
1291 + unsigned int mode:12; /* protection */
1292 + unsigned int uid:4; /* index into uid table */
1293 + unsigned int guid:4; /* index into guid table */
1295 + squashfs_block start_block;
1296 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1297 + unsigned short block_list[0];
1298 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1301 + unsigned int inode_type:4;
1302 + unsigned int mode:12; /* protection */
1303 + unsigned int uid:4; /* index into uid table */
1304 + unsigned int guid:4; /* index into guid table */
1305 + unsigned int file_size:19;
1306 + unsigned int offset:13;
1308 + unsigned int start_block:24;
1309 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1312 + squashfs_base_inode_header base;
1313 + squashfs_dev_inode_header dev;
1314 + squashfs_symlink_inode_header symlink;
1315 + squashfs_reg_inode_header reg;
1316 + squashfs_dir_inode_header dir;
1317 + squashfs_ipc_inode_header ipc;
1318 +} squashfs_inode_header;
1321 + unsigned int offset:13;
1322 + unsigned int type:3;
1323 + unsigned int size:8;
1325 +} __attribute__ ((packed)) squashfs_dir_entry;
1328 + unsigned int count:8;
1329 + unsigned int start_block:24;
1330 +} __attribute__ ((packed)) squashfs_dir_header;
1333 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1334 +extern int squashfs_uncompress_init(void);
1335 +extern int squashfs_uncompress_exit(void);
1338 + * macros to convert each packed bitfield structure from little endian to big
1339 + * endian and vice versa. These are needed when creating or using a filesystem on a
1340 + * machine with different byte ordering to the target architecture.
1344 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1345 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1346 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1347 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1348 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1349 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1350 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1351 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1352 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1353 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1354 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1355 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1356 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1357 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1358 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1359 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1360 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1361 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1364 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1365 + SQUASHFS_MEMSET(s, d, n);\
1366 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1367 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1368 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1369 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1372 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1373 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1374 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
1375 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1377 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1378 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1379 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1382 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1383 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1384 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1387 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1388 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1389 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1390 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1391 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1394 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1395 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1396 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1397 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1398 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1399 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1402 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1403 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1404 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1405 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1408 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1409 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1410 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1411 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1412 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1415 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1417 + int bit_position;\
1418 + SQUASHFS_MEMSET(s, d, n * 2);\
1419 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1420 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1423 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1425 + int bit_position;\
1426 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1427 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1428 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1433 + * macros used to swap each structure entry, taking into account
1434 + * bitfields and different bitfield placing conventions on differing architectures
1436 +#include <asm/byteorder.h>
1437 +#ifdef __BIG_ENDIAN
1438 + /* convert from little endian to big endian */
1439 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1441 + /* convert from big endian to little endian */
1442 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1445 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1447 + int b_pos = pos % 8;\
1448 + unsigned long long val = 0;\
1449 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1450 + unsigned char *d = ((unsigned char *) &val) + 7;\
1451 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1453 + value = (val >> (SHIFT));\
1455 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1458 diff --new-file -ur linux-2.6.1/include/linux/squashfs_fs_i.h linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs_i.h
1459 --- linux-2.6.1/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
1460 +++ linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs_i.h 2004-01-17 23:44:35.000000000 +0000
1462 +#ifndef SQUASHFS_FS_I
1463 +#define SQUASHFS_FS_I
1467 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1469 + * This program is free software; you can redistribute it and/or
1470 + * modify it under the terms of the GNU General Public License
1471 + * as published by the Free Software Foundation; either version
1472 + * 2 of the License, or (at your option) any later version.
1477 +typedef struct squashfs_inode_info {
1478 + unsigned int start_block;
1479 + unsigned int block_list_start;
1480 + unsigned int offset;
1481 + struct inode vfs_inode;
1482 + } squashfs_inode_info;
1484 diff --new-file -ur linux-2.6.1/include/linux/squashfs_fs_sb.h linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs_sb.h
1485 --- linux-2.6.1/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
1486 +++ linux-2.6.1-squashfs1.3r3/include/linux/squashfs_fs_sb.h 2004-01-17 23:44:35.000000000 +0000
1488 +#ifndef SQUASHFS_FS_SB
1489 +#define SQUASHFS_FS_SB
1493 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1495 + * This program is free software; you can redistribute it and/or
1496 + * modify it under the terms of the GNU General Public License
1497 + * as published by the Free Software Foundation; either version
1498 + * 2 of the License, or (at your option) any later version.
1500 + * squashfs_fs_sb.h
1503 +#include <linux/squashfs_fs.h>
1506 + unsigned int block;
1508 + unsigned int next_index;
1512 +typedef struct squashfs_sb_info {
1513 + squashfs_super_block sBlk;
1515 + int devblksize_log2;
1517 + squashfs_cache *block_cache;
1519 + squashfs_uid *uid;
1520 + squashfs_uid *guid;
1521 + unsigned int read_size;
1524 + struct semaphore read_page_mutex;
1525 + struct semaphore block_cache_mutex;
1526 + wait_queue_head_t waitq;
1527 + } squashfs_sb_info;