1 diff --new-file -ur linux-2.6.0-test7/fs/Kconfig linux-2.6.0-test7-squashfs1.3r2/fs/Kconfig
2 --- linux-2.6.0-test7/fs/Kconfig 2003-10-08 20:24:14.000000000 +0100
3 +++ linux-2.6.0-test7-squashfs1.3r2/fs/Kconfig 2003-10-14 02:37:09.000000000 +0100
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.0-test7/fs/Makefile linux-2.6.0-test7-squashfs1.3r2/fs/Makefile
35 --- linux-2.6.0-test7/fs/Makefile 2003-10-08 20:24:14.000000000 +0100
36 +++ linux-2.6.0-test7-squashfs1.3r2/fs/Makefile 2003-10-14 02:37:09.000000000 +0100
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.0-test7/fs/squashfs/inode.c linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/inode.c
46 --- linux-2.6.0-test7/fs/squashfs/inode.c 1970-01-01 01:00:00.000000000 +0100
47 +++ linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/inode.c 2003-10-14 02:37:09.000000000 +0100
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;
702 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
703 + page->index, SQUASHFS_I(inode)->start_block, SQUASHFS_I(i)->offset);
705 + for(length = 0; length < index; length += bytes) {
706 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, NULL, block, offset,
707 + PAGE_CACHE_SIZE, &block, &offset))) {
708 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
713 + if(length != index) {
714 + ERROR("(squashfs_symlink_readpage) length != index\n");
718 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
719 + if(!(bytes = squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset)))
720 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
723 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
724 + flush_dcache_page(page);
725 + SetPageUptodate(page);
733 +static int squashfs_readpage(struct file *file, struct page *page)
735 + struct inode *inode = page->mapping->host;
736 + squashfs_sb_info *msBlk = (squashfs_sb_info *)inode->i_sb->s_fs_info;
737 + squashfs_super_block *sBlk = &msBlk->sBlk;
738 + unsigned char block_list[SIZE];
739 + unsigned short *block_listp;
740 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
741 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
742 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
743 + int block = SQUASHFS_I(inode)->start_block, i = 0;
744 + int bytes = 0, block_ptr = SQUASHFS_I(inode)->block_list_start;
745 + int offset = SQUASHFS_I(inode)->offset;
746 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
747 + int readahead_blks = sBlk->block_log >= PAGE_CACHE_SHIFT ? 1 : 1 << (PAGE_CACHE_SHIFT - sBlk->block_log);
749 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
750 + SQUASHFS_I(inode)->start_block);
752 + if(index > file_blocks)
756 + int blocks = (index + readahead_blks - i);
757 + if(blocks > (SIZE >> 1)) {
758 + if((index - i) <= (SIZE >> 1))
759 + blocks = index - i;
761 + blocks = SIZE >> 1;
765 + unsigned char sblock_list[SIZE];
766 + if(!squashfs_get_cached_block(inode->i_sb, (char *) sblock_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
767 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
770 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
772 + if(!squashfs_get_cached_block(inode->i_sb, (char *) block_list, block_ptr, offset, blocks << 1, &block_ptr, &offset)) {
773 + ERROR("Unable to read block list [%d:%x]\n", block_ptr, offset);
776 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
777 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
778 + if(blocks >= readahead_blks)
782 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
783 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
784 + int start_index = page->index & ~mask;
785 + int end_index = start_index | mask;
786 + int byte_offset = 0;
788 + down(&msBlk->read_page_mutex);
789 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
790 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
794 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
795 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
797 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
799 + if(i == page->index) {
800 + memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
801 + memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
802 + flush_dcache_page(page);
803 + SetPageUptodate(page);
806 + struct page *push_page;
808 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
809 + memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
810 + memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
811 + flush_dcache_page(push_page);
812 + SetPageUptodate(push_page);
813 + unlock_page(push_page);
814 + page_cache_release(push_page);
818 + up( &msBlk->read_page_mutex);
822 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
823 + if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
824 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
827 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
828 + char *p = (char *) page_address(page);
831 + if(i_end > file_blocks)
832 + i_end = file_blocks;
834 + while(index < i_end) {
835 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
836 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
839 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
848 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
849 + flush_dcache_page(page);
850 + SetPageUptodate(page);
857 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
859 + struct inode *i = file->f_dentry->d_inode;
860 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
861 + squashfs_super_block *sBlk = &msBlk->sBlk;
862 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
863 + SQUASHFS_I(i)->offset, length = 0, dirs_read = 0, dir_count;
864 + squashfs_dir_header dirh;
865 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
866 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
868 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
871 + while(length < i->i_size) {
872 + /* read directory header */
874 + squashfs_dir_header sdirh;
875 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
876 + next_offset, sizeof(sdirh), &next_block, &next_offset))
878 + length += sizeof(sdirh);
879 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
881 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
882 + next_offset, sizeof(dirh), &next_block, &next_offset))
884 + length += sizeof(dirh);
887 + dir_count = dirh.count + 1;
888 + while(dir_count--) {
890 + squashfs_dir_entry sdire;
891 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
892 + next_offset, sizeof(sdire), &next_block, &next_offset))
894 + length += sizeof(sdire);
895 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
897 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
898 + next_offset, sizeof(*dire), &next_block, &next_offset))
900 + length += sizeof(*dire);
903 + if(!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
904 + next_offset, dire->size + 1, &next_block, &next_offset))
906 + length += dire->size + 1;
908 + if(file->f_pos >= length)
911 + dire->name[dire->size + 1] = '\0';
913 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
914 + dire->name, dire->size + 1, (int) file->f_pos,
915 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
917 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
918 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
919 + TRACE("Filldir returned less than 0\n");
924 + file->f_pos = length;
934 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
939 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry, struct nameidata *nd)
941 + const char *name =dentry->d_name.name;
942 + int len = dentry->d_name.len;
943 + struct inode *inode = NULL;
944 + squashfs_sb_info *msBlk = (squashfs_sb_info *)i->i_sb->s_fs_info;
945 + squashfs_super_block *sBlk = &msBlk->sBlk;
946 + int next_block = SQUASHFS_I(i)->start_block + sBlk->directory_table_start, next_offset =
947 + SQUASHFS_I(i)->offset, length = 0, dir_count;
948 + squashfs_dir_header dirh;
949 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
950 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
952 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
955 + while(length < i->i_size) {
956 + /* read directory header */
958 + squashfs_dir_header sdirh;
959 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
960 + sizeof(sdirh), &next_block, &next_offset))
962 + length += sizeof(sdirh);
963 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
965 + if(!squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
966 + sizeof(dirh), &next_block, &next_offset))
968 + length += sizeof(dirh);
971 + dir_count = dirh.count + 1;
972 + while(dir_count--) {
974 + squashfs_dir_entry sdire;
975 + if(!squashfs_get_cached_block(i->i_sb, (char *) &sdire,
976 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset))
978 + length += sizeof(sdire);
979 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
981 + if(!squashfs_get_cached_block(i->i_sb, (char *) dire,
982 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset))
984 + length += sizeof(*dire);
987 + if(!squashfs_get_cached_block(i->i_sb, dire->name,
988 + next_block, next_offset, dire->size + 1, &next_block, &next_offset))
990 + length += dire->size + 1;
992 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
993 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
995 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
996 + name, dirh.start_block, dire->offset);
998 + inode = squashfs_iget(i->i_sb, ino);
1006 + d_add(dentry, inode);
1008 + return ERR_PTR(0);
1011 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1016 +static void squashfs_put_super(struct super_block *s)
1018 + if(s->s_fs_info) {
1019 + squashfs_sb_info *sbi = (squashfs_sb_info *) s->s_fs_info;
1020 + if(sbi->block_cache) kfree(sbi->block_cache);
1021 + if(sbi->read_data) kfree(sbi->read_data);
1022 + if(sbi->read_page) kfree(sbi->read_page);
1023 + if(sbi->uid) kfree(sbi->uid);
1024 + kfree(s->s_fs_info);
1025 + s->s_fs_info = NULL;
1030 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
1032 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super);
1036 +static int __init init_squashfs_fs(void)
1038 + int err = init_inodecache();
1042 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1043 + ERROR("Failed to allocate zlib workspace\n");
1044 + destroy_inodecache();
1048 + if((err = register_filesystem(&squashfs_fs_type))) {
1049 + vfree(stream.workspace);
1050 + destroy_inodecache();
1057 +static void __exit exit_squashfs_fs(void)
1059 + vfree(stream.workspace);
1060 + unregister_filesystem(&squashfs_fs_type);
1061 + destroy_inodecache();
1065 +static kmem_cache_t * squashfs_inode_cachep;
1067 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1069 + struct squashfs_inode_info *ei;
1070 + ei = (struct squashfs_inode_info *)kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1073 + return &ei->vfs_inode;
1076 +static void squashfs_destroy_inode(struct inode *inode)
1078 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
1081 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1083 + struct squashfs_inode_info *ei = (struct squashfs_inode_info *) foo;
1085 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1086 + SLAB_CTOR_CONSTRUCTOR)
1087 + inode_init_once(&ei->vfs_inode);
1090 +static int init_inodecache(void)
1092 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
1093 + sizeof(struct squashfs_inode_info),
1094 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1096 + if (squashfs_inode_cachep == NULL)
1101 +static void destroy_inodecache(void)
1103 + if (kmem_cache_destroy(squashfs_inode_cachep))
1104 + printk(KERN_INFO "squashfs_inode_cache: not all structures were freed\n");
1107 +module_init(init_squashfs_fs);
1108 +module_exit(exit_squashfs_fs);
1109 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1110 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1111 +MODULE_LICENSE("GPL");
1112 diff --new-file -ur linux-2.6.0-test7/fs/squashfs/Makefile linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/Makefile
1113 --- linux-2.6.0-test7/fs/squashfs/Makefile 1970-01-01 01:00:00.000000000 +0100
1114 +++ linux-2.6.0-test7-squashfs1.3r2/fs/squashfs/Makefile 2003-10-14 02:37:09.000000000 +0100
1117 +# Makefile for the linux squashfs routines.
1120 +obj-$(CONFIG_SQUASHFS) += squashfs.o
1122 +squashfs-objs := inode.o
1123 diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs.h
1124 --- linux-2.6.0-test7/include/linux/squashfs_fs.h 1970-01-01 01:00:00.000000000 +0100
1125 +++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs.h 2003-10-14 02:37:09.000000000 +0100
1127 +#ifndef SQUASHFS_FS
1128 +#define SQUASHFS_FS
1132 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1134 + * This program is free software; you can redistribute it and/or
1135 + * modify it under the terms of the GNU General Public License
1136 + * as published by the Free Software Foundation; either version
1137 + * 2 of the License, or (at your option) any later version.
1142 +#define SQUASHFS_MAJOR 1
1143 +#define SQUASHFS_MINOR 0
1144 +#define SQUASHFS_MAGIC 0x73717368
1145 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1146 +#define SQUASHFS_START 0
1148 +/* size of metadata (inode and directory) blocks */
1149 +#define SQUASHFS_METADATA_SIZE 8192
1150 +#define SQUASHFS_METADATA_LOG 13
1152 +/* default size of data blocks */
1153 +#define SQUASHFS_FILE_SIZE 32768
1154 +#define SQUASHFS_FILE_LOG 15
1156 +#define SQUASHFS_FILE_MAX_SIZE 32768
1158 +/* Max number of uids and gids */
1159 +#define SQUASHFS_UIDS 48
1160 +#define SQUASHFS_GUIDS 15
1162 +/* Max length of filename (not 255) */
1163 +#define SQUASHFS_NAME_LEN 256
1165 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1166 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1167 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1169 +/* Filesystem flags */
1170 +#define SQUASHFS_NOI 1
1171 +#define SQUASHFS_NOD 2
1172 +#define SQUASHFS_CHECK 4
1173 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1174 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1175 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1176 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1178 +/* Max number of types and file types */
1179 +#define SQUASHFS_TYPES 5
1180 +#define SQUASHFS_DIR_TYPE 1
1181 +#define SQUASHFS_FILE_TYPE 2
1182 +#define SQUASHFS_SYMLINK_TYPE 3
1183 +#define SQUASHFS_BLKDEV_TYPE 4
1184 +#define SQUASHFS_CHRDEV_TYPE 5
1186 +#define SQUASHFS_IPC_TYPE 0
1187 +#define SQUASHFS_FIFO_TYPE 6
1188 +#define SQUASHFS_SOCKET_TYPE 7
1190 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1191 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1192 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1193 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1195 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1198 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1199 + * offset within that block
1201 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1202 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1203 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1206 +/* Compute 32 bit VFS inode number from squashfs inode number */
1207 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1209 +/* Translate between VFS mode and squashfs mode */
1210 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1212 +/* cached data constants for filesystem */
1213 +#define SQUASHFS_CACHED_BLKS 8
1215 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1216 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << (SQUASHFS_MAX_FILE_SIZE_LOG - 1))
1218 +#define SQUASHFS_MARKER_BYTE 0xff
1221 + * definitions for structures on disk
1224 +typedef unsigned int squashfs_block;
1225 +typedef long long squashfs_inode;
1227 +typedef unsigned int squashfs_uid;
1229 +typedef struct squashfs_super_block {
1230 + unsigned int s_magic;
1231 + unsigned int inodes;
1232 + unsigned int bytes_used;
1233 + unsigned int uid_start;
1234 + unsigned int guid_start;
1235 + unsigned int inode_table_start;
1236 + unsigned int directory_table_start;
1237 + unsigned int s_major:16;
1238 + unsigned int s_minor:16;
1239 + unsigned int block_size:16;
1240 + unsigned int block_log:16;
1241 + unsigned int flags:8;
1242 + unsigned int no_uids:8;
1243 + unsigned int no_guids:8;
1244 + time_t mkfs_time /* time of filesystem creation */;
1245 + squashfs_inode root_inode;
1246 +} __attribute__ ((packed)) squashfs_super_block;
1249 + unsigned int inode_type:4;
1250 + unsigned int mode:12; /* protection */
1251 + unsigned int uid:4; /* index into uid table */
1252 + unsigned int guid:4; /* index into guid table */
1253 +} __attribute__ ((packed)) squashfs_base_inode_header;
1256 + unsigned int inode_type:4;
1257 + unsigned int mode:12; /* protection */
1258 + unsigned int uid:4; /* index into uid table */
1259 + unsigned int guid:4; /* index into guid table */
1260 + unsigned int type:4;
1261 + unsigned int offset:4;
1262 +} __attribute__ ((packed)) squashfs_ipc_inode_header;
1265 + unsigned int inode_type:4;
1266 + unsigned int mode:12; /* protection */
1267 + unsigned int uid:4; /* index into uid table */
1268 + unsigned int guid:4; /* index into guid table */
1269 + unsigned short rdev;
1270 +} __attribute__ ((packed)) squashfs_dev_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 symlink_size;
1279 +} __attribute__ ((packed)) squashfs_symlink_inode_header;
1282 + unsigned int inode_type:4;
1283 + unsigned int mode:12; /* protection */
1284 + unsigned int uid:4; /* index into uid table */
1285 + unsigned int guid:4; /* index into guid table */
1287 + squashfs_block start_block;
1288 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG;
1289 + unsigned short block_list[0];
1290 +} __attribute__ ((packed)) squashfs_reg_inode_header;
1293 + unsigned int inode_type:4;
1294 + unsigned int mode:12; /* protection */
1295 + unsigned int uid:4; /* index into uid table */
1296 + unsigned int guid:4; /* index into guid table */
1297 + unsigned int file_size:19;
1298 + unsigned int offset:13;
1300 + unsigned int start_block:24;
1301 +} __attribute__ ((packed)) squashfs_dir_inode_header;
1304 + squashfs_base_inode_header base;
1305 + squashfs_dev_inode_header dev;
1306 + squashfs_symlink_inode_header symlink;
1307 + squashfs_reg_inode_header reg;
1308 + squashfs_dir_inode_header dir;
1309 + squashfs_ipc_inode_header ipc;
1310 +} squashfs_inode_header;
1313 + unsigned int offset:13;
1314 + unsigned int type:3;
1315 + unsigned int size:8;
1317 +} __attribute__ ((packed)) squashfs_dir_entry;
1320 + unsigned int count:8;
1321 + unsigned int start_block:24;
1322 +} __attribute__ ((packed)) squashfs_dir_header;
1325 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1326 +extern int squashfs_uncompress_init(void);
1327 +extern int squashfs_uncompress_exit(void);
1330 + * macros to convert each packed bitfield structure from little endian to big
1331 + * endian and vice versa. These are needed when creating or using a filesystem on a
1332 + * machine with different byte ordering to the target architecture.
1336 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1337 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1338 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1339 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1340 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1341 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1342 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1343 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1344 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1345 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1346 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1347 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1348 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1349 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1350 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1351 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1352 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1353 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1356 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1357 + SQUASHFS_MEMSET(s, d, n);\
1358 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1359 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1360 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1361 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1364 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
1365 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1366 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
1367 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
1369 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1370 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1371 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1374 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1375 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1376 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1379 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1380 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1381 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1382 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1383 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1386 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1387 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1388 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1389 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1390 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1391 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1394 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1395 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1396 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1397 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1400 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1401 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1402 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1403 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1404 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1407 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1409 + int bit_position;\
1410 + SQUASHFS_MEMSET(s, d, n * 2);\
1411 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1412 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1415 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1417 + int bit_position;\
1418 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1419 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1420 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1425 + * macros used to swap each structure entry, taking into account
1426 + * bitfields and different bitfield placing conventions on differing architectures
1428 +#include <asm/byteorder.h>
1429 +#ifdef __BIG_ENDIAN
1430 + /* convert from little endian to big endian */
1431 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1433 + /* convert from big endian to little endian */
1434 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1437 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1439 + int b_pos = pos % 8;\
1440 + unsigned long long val = 0;\
1441 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1442 + unsigned char *d = ((unsigned char *) &val) + 7;\
1443 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1445 + value = (val >> (SHIFT));\
1447 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1450 diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs_i.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_i.h
1451 --- linux-2.6.0-test7/include/linux/squashfs_fs_i.h 1970-01-01 01:00:00.000000000 +0100
1452 +++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_i.h 2003-10-14 02:37:09.000000000 +0100
1454 +#ifndef SQUASHFS_FS_I
1455 +#define SQUASHFS_FS_I
1459 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1461 + * This program is free software; you can redistribute it and/or
1462 + * modify it under the terms of the GNU General Public License
1463 + * as published by the Free Software Foundation; either version
1464 + * 2 of the License, or (at your option) any later version.
1469 +typedef struct squashfs_inode_info {
1470 + unsigned int start_block;
1471 + unsigned int block_list_start;
1472 + unsigned int offset;
1473 + struct inode vfs_inode;
1474 + } squashfs_inode_info;
1476 diff --new-file -ur linux-2.6.0-test7/include/linux/squashfs_fs_sb.h linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_sb.h
1477 --- linux-2.6.0-test7/include/linux/squashfs_fs_sb.h 1970-01-01 01:00:00.000000000 +0100
1478 +++ linux-2.6.0-test7-squashfs1.3r2/include/linux/squashfs_fs_sb.h 2003-10-14 02:37:09.000000000 +0100
1480 +#ifndef SQUASHFS_FS_SB
1481 +#define SQUASHFS_FS_SB
1485 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1487 + * This program is free software; you can redistribute it and/or
1488 + * modify it under the terms of the GNU General Public License
1489 + * as published by the Free Software Foundation; either version
1490 + * 2 of the License, or (at your option) any later version.
1492 + * squashfs_fs_sb.h
1495 +#include <linux/squashfs_fs.h>
1498 + unsigned int block;
1500 + unsigned int next_index;
1504 +typedef struct squashfs_sb_info {
1505 + squashfs_super_block sBlk;
1507 + int devblksize_log2;
1509 + squashfs_cache *block_cache;
1511 + squashfs_uid *uid;
1512 + squashfs_uid *guid;
1513 + unsigned int read_size;
1516 + struct semaphore read_page_mutex;
1517 + struct semaphore block_cache_mutex;
1518 + wait_queue_head_t waitq;
1519 + } squashfs_sb_info;