1 diff -Naur linux-2.6.0-test1-ac2/fs/Kconfig linux-2.6.0-test1-ac2-sfs/fs/Kconfig
2 --- linux-2.6.0-test1-ac2/fs/Kconfig 2003-07-10 13:10:54.000000000 -0700
3 +++ linux-2.6.0-test1-ac2-sfs/fs/Kconfig 2003-07-20 01:36:53.000000000 -0700
9 + tristate "Squashfs file system support"
11 + Saying Y here includes support for Squashfs. Squashfs is a
12 + highly compressed read-only filesystem for Linux. It uses zlib
13 + compression to compress both files, inodes and directories.
14 + Inodes in the system are very small and all blocks are packed
15 + to minimise data overhead. Block sizes greater than 4K are
16 + supported up to a maximum of 32K.
18 + See <http://squashfs.sourceforge.net/> for further information.
20 + If you want to compile this as a module ( = code which can be
21 + inserted in and removed from the running kernel whenever you want),
22 + say M here and read <file:Documentation/modules.txt>. The module
23 + will be called squashfs. Note that the root file system (the one
24 + containing the directory /) cannot be compiled as a module.
29 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
31 diff -Naur linux-2.6.0-test1-ac2/fs/Makefile linux-2.6.0-test1-ac2-sfs/fs/Makefile
32 --- linux-2.6.0-test1-ac2/fs/Makefile 2003-07-10 13:10:55.000000000 -0700
33 +++ linux-2.6.0-test1-ac2-sfs/fs/Makefile 2003-07-16 13:45:34.000000000 -0700
35 obj-$(CONFIG_JBD) += jbd/
36 obj-$(CONFIG_EXT2_FS) += ext2/
37 obj-$(CONFIG_CRAMFS) += cramfs/
38 +obj-$(CONFIG_SQUASHFS) += squashfs/
39 obj-$(CONFIG_RAMFS) += ramfs/
40 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
41 obj-$(CONFIG_CODA_FS) += coda/
42 diff -Naur linux-2.6.0-test1-ac2/fs/squashfs/Makefile linux-2.6.0-test1-ac2-sfs/fs/squashfs/Makefile
43 --- linux-2.6.0-test1-ac2/fs/squashfs/Makefile 1969-12-31 16:00:00.000000000 -0800
44 +++ linux-2.6.0-test1-ac2-sfs/fs/squashfs/Makefile 2003-07-15 12:17:43.000000000 -0700
47 +# Makefile for the linux squashfs routines.
50 +obj-$(CONFIG_SQUASHFS) += squashfs.o
52 +squashfs-objs := inode.o
54 diff -Naur linux-2.6.0-test1-ac2/fs/squashfs/inode.c linux-2.6.0-test1-ac2-sfs/fs/squashfs/inode.c
55 --- linux-2.6.0-test1-ac2/fs/squashfs/inode.c 1969-12-31 16:00:00.000000000 -0800
56 +++ linux-2.6.0-test1-ac2-sfs/fs/squashfs/inode.c 2003-07-20 02:08:01.000000000 -0700
59 + * Squashfs - a compressed read only filesystem for Linux
61 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
63 + * This program is free software; you can redistribute it and/or
64 + * modify it under the terms of the GNU General Public License
65 + * as published by the Free Software Foundation; either version
66 + * 2 of the License, or (at your option) any later version.
71 +#include <linux/types.h>
72 +#include <linux/module.h>
73 +#include <linux/errno.h>
74 +#include <linux/slab.h>
75 +#include <linux/fs.h>
76 +#include <linux/init.h>
77 +#include <linux/dcache.h>
78 +#include <asm/uaccess.h>
79 +#include <linux/wait.h>
80 +#include <asm/semaphore.h>
81 +#include <linux/zlib.h>
82 +#include <linux/blkdev.h>
83 +#include <linux/vmalloc.h>
84 +#include <linux/smp_lock.h>
85 +#include <linux/buffer_head.h>
86 +#include <linux/squashfs_fs_sb.h>
87 +#include <linux/vfs.h>
89 +#ifdef SQUASHFS_TRACE
90 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
92 +#define TRACE(s, args...) {}
95 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
97 +#define SERROR(s, args...) if(!silent) printk(KERN_ERR "SQUASHFS error: "s, ## args)
98 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
100 +typedef struct squashfs_inode_info {
101 + unsigned int start_block;
102 + unsigned int block_list_start;
103 + unsigned int offset;
105 + struct inode vfs_inode;
106 +} squashfs_inode_info;
108 +static inline struct squashfs_inode_info *SQUASH_I(struct inode *inode)
110 + return container_of(inode, struct squashfs_inode_info, vfs_inode);
113 +static int squashfs_fill_super(struct super_block *, void *, int);
114 +static void squashfs_put_super(struct super_block *);
115 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
116 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
117 +static int squashfs_readpage(struct file *file, struct page *page);
118 +static int squashfs_readdir(struct file *, void *, filldir_t);
119 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *, struct nameidata *);
120 +static unsigned int read_data(struct super_block *s, char *buffer,
121 + unsigned int index, int length, unsigned int *next_index);
122 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
123 + unsigned int block, unsigned int offset, int length,
124 + unsigned int *next_block, unsigned int *next_offset);
125 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode);
126 +static void squashfs_put_super(struct super_block *s);
127 +static struct super_block *squashfs_get_sb(struct file_system_type *, int, const char *, void *);
128 +static struct inode *squashfs_alloc_inode(struct super_block *);
129 +static void squashfs_destroy_inode(struct inode *);
131 +DECLARE_MUTEX(read_data_mutex);
133 +static z_stream stream;
135 +static unsigned char squashfs_filetype_table[] = {
136 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR
139 +static struct super_operations squashfs_ops = {
140 + .alloc_inode = squashfs_alloc_inode,
141 + .destroy_inode = squashfs_destroy_inode,
142 + .statfs = squashfs_statfs,
143 + .put_super = squashfs_put_super,
146 +static struct address_space_operations squashfs_symlink_aops = {
147 + .readpage = squashfs_symlink_readpage
150 +static struct address_space_operations squashfs_aops = {
151 + .readpage = squashfs_readpage
154 +static struct file_operations squashfs_dir_ops = {
155 + .read = generic_read_dir,
156 + .readdir = squashfs_readdir
159 +static struct inode_operations squashfs_dir_inode_ops = {
160 + .lookup = squashfs_lookup
163 +static struct file_system_type squashfs_fs_type = {
164 + .owner = THIS_MODULE,
165 + .name = "squashfs",
166 + .get_sb = squashfs_get_sb,
167 + .kill_sb = kill_block_super,
168 + .fs_flags = FS_REQUIRES_DEV,
171 +static unsigned int read_data(struct super_block *s, char *buffer,
172 + unsigned int index, int length, unsigned int *next_index)
174 + squashfs_sb_info *msBlk = s->s_fs_info;
175 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >> msBlk->devblksize_log2) + 2];
176 + unsigned short c_byte;
177 + unsigned int offset = index & ((1 << msBlk->devblksize_log2) - 1);
178 + unsigned int cur_index = index >> msBlk->devblksize_log2;
179 + int bytes, avail_bytes, b, k;
181 + unsigned int compressed;
183 + if(!(bh[0] = sb_bread(s, cur_index)))
189 + if(msBlk->devblksize - offset == 1) {
191 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
193 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset));
195 + if(!(bh[0] = sb_bread(s, ++cur_index)))
198 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) bh[0]->b_data);
200 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) bh[0]->b_data);
205 + ((unsigned char *) &c_byte)[1] = *((unsigned char *) (bh[0]->b_data + offset));
206 + ((unsigned char *) &c_byte)[0] = *((unsigned char *) (bh[0]->b_data + offset + 1));
208 + c_byte = *((unsigned short *) (bh[0]->b_data + offset));
211 + if(SQUASHFS_CHECK_DATA(msBlk->sBlk.flags)) {
212 + if(offset == msBlk->devblksize) {
214 + if(!(bh[0] = sb_bread(s, ++cur_index)))
218 + if(*((unsigned char *) (bh[0]->b_data + offset)) != SQUASHFS_MARKER_BYTE) {
219 + ERROR("Metadata block marker corrupt @ %x\n", index);
227 + bytes = msBlk->devblksize - offset;
228 + c_buffer = (compressed = SQUASHFS_COMPRESSED(c_byte)) ? msBlk->read_data : buffer;
229 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
231 + TRACE("Block @ 0x%x, %scompressed size %d\n", index, compressed ? "" : "un", (unsigned int) c_byte);
233 + for(b = 1; bytes < c_byte; b++) {
234 + if(!(bh[b] = sb_bread(s, ++cur_index)))
235 + goto block_release;
236 + bytes += msBlk->devblksize;
240 + down(&read_data_mutex);
242 + for(bytes = 0, k = 0; k < b; k++) {
243 + avail_bytes = (c_byte - bytes) > (msBlk->devblksize - offset) ? msBlk->devblksize - offset : c_byte - bytes;
244 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
245 + bytes += avail_bytes;
256 + stream.next_in = c_buffer;
257 + stream.avail_in = c_byte;
258 + stream.next_out = buffer;
259 + stream.avail_out = msBlk->read_size;
260 + if(((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
261 + ((zlib_err = zlib_inflate(&stream, Z_FINISH)) != Z_STREAM_END) ||
262 + ((zlib_err = zlib_inflateEnd(&stream)) != Z_OK)) {
263 + ERROR("zlib_fs returned unexpected result 0x%x\n", zlib_err);
266 + bytes = stream.total_out;
267 + up(&read_data_mutex);
271 + *next_index = index + c_byte + (length ? 0 : (SQUASHFS_CHECK_DATA(msBlk->sBlk.flags) ? 3 : 2));
276 + while(--b >= 0) brelse(bh[b]);
279 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
284 +static int squashfs_get_cached_block(struct super_block *s, char *buffer,
285 + unsigned int block, unsigned int offset, int length,
286 + unsigned int *next_block, unsigned int *next_offset)
288 + squashfs_sb_info *msBlk = s->s_fs_info;
289 + int n, i, bytes, return_length = length;
290 + unsigned int next_index;
292 + TRACE("Entered squashfs_get_cached_block [%x:%x]\n", block, offset);
295 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
296 + if(msBlk->block_cache[i].block == block)
299 + down(&msBlk->block_cache_mutex);
300 + if(i == SQUASHFS_CACHED_BLKS) {
301 + /* read inode header block */
302 + for(i = msBlk->next_cache, n = SQUASHFS_CACHED_BLKS; n ; n --, i = (i + 1) % SQUASHFS_CACHED_BLKS)
303 + if(msBlk->block_cache[i].block != SQUASHFS_USED_BLK)
306 + up(&msBlk->block_cache_mutex);
307 + sleep_on(&msBlk->waitq);
310 + msBlk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
312 + if(msBlk->block_cache[i].block == SQUASHFS_INVALID_BLK) {
313 + if(!(msBlk->block_cache[i].data = (unsigned char *)
314 + kmalloc(SQUASHFS_METADATA_SIZE, GFP_KERNEL))) {
315 + ERROR("Failed to allocate cache block\n");
316 + up(&msBlk->block_cache_mutex);
321 + msBlk->block_cache[i].block = SQUASHFS_USED_BLK;
322 + up(&msBlk->block_cache_mutex);
323 + if(!(msBlk->block_cache[i].length = read_data(s, msBlk->block_cache[i].data, block, 0,
325 + ERROR("Unable to read cache block [%x:%x]\n", block, offset);
328 + down(&msBlk->block_cache_mutex);
329 + wake_up(&msBlk->waitq);
330 + msBlk->block_cache[i].block = block;
331 + msBlk->block_cache[i].next_index = next_index;
332 + TRACE("Read cache block [%x:%x]\n", block, offset);
335 + if(msBlk->block_cache[i].block != block) {
336 + up(&msBlk->block_cache_mutex);
340 + if((bytes = msBlk->block_cache[i].length - offset) >= length) {
341 + memcpy(buffer, msBlk->block_cache[i].data + offset, length);
342 + if(msBlk->block_cache[i].length - offset == length) {
343 + *next_block = msBlk->block_cache[i].next_index;
346 + *next_block = block;
347 + *next_offset = offset + length;
350 + up(&msBlk->block_cache_mutex);
351 + return return_length;
353 + memcpy(buffer, msBlk->block_cache[i].data + offset, bytes);
354 + block = msBlk->block_cache[i].next_index;
355 + up(&msBlk->block_cache_mutex);
364 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode inode)
366 + struct inode *i = new_inode(s);
367 + struct squashfs_inode_info *sqi = SQUASH_I(i);
368 + squashfs_sb_info *msBlk = s->s_fs_info;
369 + squashfs_super_block *sBlk = &msBlk->sBlk;
370 + unsigned int block = SQUASHFS_INODE_BLK(inode) + sBlk->inode_table_start;
371 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
372 + unsigned int next_block, next_offset;
373 + squashfs_base_inode_header inodeb;
375 + TRACE("Entered squashfs_iget\n");
378 + squashfs_base_inode_header sinodeb;
380 + if(!squashfs_get_cached_block(s, (char *) &sinodeb, block, offset,
381 + sizeof(sinodeb), &next_block, &next_offset))
383 + SQUASHFS_SWAP_BASE_INODE_HEADER(&inodeb, &sinodeb, sizeof(sinodeb));
385 + if(!squashfs_get_cached_block(s, (char *) &inodeb, block, offset,
386 + sizeof(inodeb), &next_block, &next_offset))
391 + i->i_mtime.tv_sec = sBlk->mkfs_time;
392 + i->i_atime.tv_sec = sBlk->mkfs_time;
393 + i->i_ctime.tv_sec = sBlk->mkfs_time;
394 + i->i_mtime.tv_nsec = i->i_atime.tv_nsec = i->i_ctime.tv_nsec = 0;
395 + i->i_uid = msBlk->uid[((inodeb.inode_type - 1) / SQUASHFS_TYPES) * 16 + inodeb.uid];
396 + i->i_ino = SQUASHFS_MK_VFS_INODE(block - sBlk->inode_table_start, offset);
398 + if(inodeb.guid == SQUASHFS_GUIDS)
399 + i->i_gid = i->i_uid;
401 + i->i_gid = msBlk->guid[inodeb.guid];
403 + i->i_mode = inodeb.mode;
405 + switch((inodeb.inode_type - 1) % SQUASHFS_TYPES + 1) {
406 + case SQUASHFS_FILE_TYPE: {
407 + squashfs_reg_inode_header inodep;
410 + squashfs_reg_inode_header sinodep;
412 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
413 + &next_block, &next_offset))
415 + SQUASHFS_SWAP_REG_INODE_HEADER(&inodep, &sinodep);
417 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
418 + &next_block, &next_offset))
421 + i->i_size = inodep.file_size;
422 + i->i_fop = &generic_ro_fops;
423 + i->i_data.a_ops = &squashfs_aops;
424 + i->i_mode |= S_IFREG;
426 + i->i_mtime.tv_sec = inodep.mtime;
427 + i->i_atime.tv_sec = inodep.mtime;
428 + i->i_ctime.tv_sec = inodep.mtime;
429 + i->i_mtime.tv_nsec = i->i_atime.tv_nsec =
430 + i->i_ctime.tv_nsec = 0;
431 + sqi->start_block = inodep.start_block;
432 + sqi->block_list_start = next_block;
433 + sqi->offset = next_offset;
434 + TRACE("File inode %x:%x, start_block %x, block_list_start %x, offset %x\n",
435 + SQUASHFS_INODE_BLK(inode), offset, inodep.start_block, next_block, next_offset);
438 + case SQUASHFS_DIR_TYPE: {
439 + squashfs_dir_inode_header inodep;
442 + squashfs_dir_inode_header sinodep;
444 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
445 + &next_block, &next_offset))
447 + SQUASHFS_SWAP_DIR_INODE_HEADER(&inodep, &sinodep);
449 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
450 + &next_block, &next_offset))
453 + i->i_size = inodep.file_size;
454 + i->i_op = &squashfs_dir_inode_ops;
455 + i->i_fop = &squashfs_dir_ops;
456 + i->i_mode |= S_IFDIR;
457 + i->i_mtime.tv_sec = inodep.mtime;
458 + i->i_atime.tv_sec = inodep.mtime;
459 + i->i_ctime.tv_sec = inodep.mtime;
460 + i->i_mtime.tv_nsec = i->i_atime.tv_nsec =
461 + i->i_ctime.tv_nsec = 0;
462 + sqi->start_block = inodep.start_block;
463 + sqi->offset = inodep.offset;
464 + TRACE("Directory inode %x:%x, start_block %x, offset %x\n", SQUASHFS_INODE_BLK(inode), offset,
465 + inodep.start_block, inodep.offset);
468 + case SQUASHFS_SYMLINK_TYPE: {
469 + squashfs_symlink_inode_header inodep;
472 + squashfs_symlink_inode_header sinodep;
474 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
475 + &next_block, &next_offset))
477 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(&inodep, &sinodep);
479 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
480 + &next_block, &next_offset))
483 + i->i_size = inodep.symlink_size;
484 + i->i_op = &page_symlink_inode_operations;
485 + i->i_data.a_ops = &squashfs_symlink_aops;
486 + i->i_mode |= S_IFLNK;
487 + sqi->start_block = next_block;
488 + sqi->offset = next_offset;
489 + TRACE("Symbolic link inode %x:%x, start_block %x, offset %x\n",
490 + SQUASHFS_INODE_BLK(inode), offset, next_block, next_offset);
493 + case SQUASHFS_BLKDEV_TYPE:
494 + case SQUASHFS_CHRDEV_TYPE: {
495 + squashfs_dev_inode_header inodep;
498 + squashfs_dev_inode_header sinodep;
500 + if(!squashfs_get_cached_block(s, (char *) &sinodep, block, offset, sizeof(sinodep),
501 + &next_block, &next_offset))
503 + SQUASHFS_SWAP_DEV_INODE_HEADER(&inodep, &sinodep);
505 + if(!squashfs_get_cached_block(s, (char *) &inodep, block, offset, sizeof(inodep),
506 + &next_block, &next_offset))
510 + i->i_mode |= (inodeb.inode_type == SQUASHFS_CHRDEV_TYPE) ? S_IFCHR : S_IFBLK;
511 + init_special_inode(i, i->i_mode, inodep.rdev);
512 + TRACE("Device inode %x:%x, rdev %x\n", SQUASHFS_INODE_BLK(inode), offset, inodep.rdev);
516 + ERROR("Unknown inode type %d in squashfs_iget!\n", inodeb.inode_type);
523 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
530 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
532 + char bbuf[BDEVNAME_SIZE];
533 + squashfs_sb_info *msBlk;
534 + squashfs_super_block *sBlk;
537 + TRACE("Entered squashfs_fill_super\n");
539 + msBlk = kmalloc(sizeof(squashfs_sb_info), GFP_KERNEL);
542 + s->s_fs_info = msBlk;
543 + sBlk = &(msBlk->sBlk);
544 + memset(msBlk, 0, sizeof(squashfs_sb_info));
546 + msBlk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
547 + msBlk->devblksize_log2 = ffz(~msBlk->devblksize);
549 + init_MUTEX(&msBlk->read_page_mutex);
550 + init_MUTEX(&msBlk->block_cache_mutex);
552 + init_waitqueue_head(&msBlk->waitq);
554 + if(!read_data(s, (char *) sBlk, SQUASHFS_START, sizeof(squashfs_super_block) | SQUASHFS_COMPRESSED_BIT, NULL)) {
555 + SERROR("unable to read superblock\n");
559 + /* Check it is a SQUASHFS superblock */
561 + if((s->s_magic = sBlk->s_magic) != SQUASHFS_MAGIC) {
562 + if(sBlk->s_magic == SQUASHFS_MAGIC_SWAP) {
563 + squashfs_super_block sblk;
564 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n", __bdevname(s->s_dev, bbuf));
565 + SQUASHFS_SWAP_SUPER_BLOCK(&sblk, sBlk);
566 + memcpy(sBlk, &sblk, sizeof(squashfs_super_block));
569 + SERROR("Can't find a SQUASHFS superblock on %s\n", __bdevname(s->s_dev, bbuf));
574 + /* Check the MAJOR & MINOR versions */
575 + if(sBlk->s_major != SQUASHFS_MAJOR || sBlk->s_minor > SQUASHFS_MINOR) {
576 + SERROR("Major/Minor mismatch, filesystem is (%d:%d), I support (%d: <= %d)\n",
577 + sBlk->s_major, sBlk->s_minor, SQUASHFS_MAJOR, SQUASHFS_MINOR);
581 + TRACE("Found valid superblock on %s\n", __bdevname(s->s_dev, bbuf));
582 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sBlk->flags) ? "un" : "");
583 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sBlk->flags) ? "un" : "");
584 + TRACE("Check data is %s present in the filesystem\n", SQUASHFS_CHECK_DATA(sBlk->flags) ? "" : "not");
585 + TRACE("Filesystem size %d bytes\n", sBlk->bytes_used);
586 + TRACE("Block size %d\n", sBlk->block_size);
587 + TRACE("Number of inodes %d\n", sBlk->inodes);
588 + TRACE("Number of uids %d\n", sBlk->no_uids);
589 + TRACE("Number of gids %d\n", sBlk->no_guids);
590 + TRACE("sBlk->inode_table_start %x\n", sBlk->inode_table_start);
591 + TRACE("sBlk->directory_table_start %x\n", sBlk->directory_table_start);
592 + TRACE("sBlk->uid_start %x\n", sBlk->uid_start);
594 + s->s_flags |= MS_RDONLY;
595 + s->s_op = &squashfs_ops;
597 + /* Init inode_table block pointer array */
598 + if(!(msBlk->block_cache = (squashfs_cache *) kmalloc(sizeof(squashfs_cache) * SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
599 + ERROR("Failed to allocate block cache\n");
603 + for(i = 0; i < SQUASHFS_CACHED_BLKS; i++)
604 + msBlk->block_cache[i].block = SQUASHFS_INVALID_BLK;
606 + msBlk->next_cache = 0;
608 + /* Allocate read_data block */
609 + msBlk->read_size = (sBlk->block_size < SQUASHFS_METADATA_SIZE) ? SQUASHFS_METADATA_SIZE : sBlk->block_size;
610 + if(!(msBlk->read_data = (char *) kmalloc(msBlk->read_size, GFP_KERNEL))) {
611 + ERROR("Failed to allocate read_data block\n");
612 + goto failed_mount1;
615 + /* Allocate read_page block */
616 + if(sBlk->block_size > PAGE_CACHE_SIZE &&
617 + !(msBlk->read_page = (char *) kmalloc(sBlk->block_size, GFP_KERNEL))) {
618 + ERROR("Failed to allocate read_page block\n");
619 + goto failed_mount2;
622 + /* Allocate uid and gid tables */
623 + if(!(msBlk->uid = (squashfs_uid *) kmalloc((sBlk->no_uids +
624 + sBlk->no_guids) * sizeof(squashfs_uid), GFP_KERNEL))) {
625 + ERROR("Failed to allocate uid/gid table\n");
626 + goto failed_mount3;
628 + msBlk->guid = msBlk->uid + sBlk->no_uids;
631 + squashfs_uid suid[sBlk->no_uids + sBlk->no_guids];
633 + if(!read_data(s, (char *) &suid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
634 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
635 + SERROR("unable to read uid/gid table\n");
636 + goto failed_mount4;
638 + SQUASHFS_SWAP_DATA(msBlk->uid, suid, (sBlk->no_uids + sBlk->no_guids), (sizeof(squashfs_uid) * 8));
640 + if(!read_data(s, (char *) msBlk->uid, sBlk->uid_start, ((sBlk->no_uids + sBlk->no_guids) *
641 + sizeof(squashfs_uid)) | SQUASHFS_COMPRESSED_BIT, NULL)) {
642 + SERROR("unable to read uid/gid table\n");
643 + goto failed_mount4;
646 + if(!(s->s_root = d_alloc_root(squashfs_iget(s, sBlk->root_inode)))) {
647 + ERROR("Root inode create failed\n");
648 + goto failed_mount4;
651 + TRACE("Leaving squashfs_fill_super\n");
657 + kfree(msBlk->read_page);
659 + kfree(msBlk->read_data);
661 + kfree(msBlk->block_cache);
664 + s->s_fs_info = NULL;
669 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
671 + squashfs_super_block *sBlk = &((squashfs_sb_info*)(s->s_fs_info))->sBlk;
673 + TRACE("Entered squashfs_statfs\n");
674 + buf->f_type = SQUASHFS_MAGIC;
675 + buf->f_bsize = sBlk->block_size;
676 + buf->f_blocks = ((sBlk->bytes_used - 1) >> sBlk->block_log) + 1;
677 + buf->f_bfree = buf->f_bavail = 0;
678 + buf->f_files = sBlk->inodes;
680 + buf->f_namelen = SQUASHFS_NAME_LEN;
685 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
687 + struct inode *inode = page->mapping->host;
688 + struct squashfs_inode_info *sqi = SQUASH_I(inode);
689 + int index = page->index << PAGE_CACHE_SHIFT, length = 0, bytes;
690 + int block = sqi->start_block;
691 + int offset = sqi->offset;
694 + TRACE("Entered squashfs_symlink_readpage, page index %d, start block %x, offset %x\n",
695 + page->index, sqi->start_block, sqi->offset);
697 + if (! (buffer = kmalloc(PAGE_CACHE_SIZE, GFP_KERNEL))) {
698 + ERROR("Failed to allocate symblic link buffer\n");
702 + while(length < index) {
703 + if(length += bytes = squashfs_get_cached_block(inode->i_sb, buffer, block, offset,
704 + PAGE_CACHE_SIZE, &block, &offset), !bytes) {
705 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
710 + if(length != index) {
711 + ERROR("(squashfs_symlink_readpage) length != index\n");
716 + bytes = (inode->i_size - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : inode->i_size - length;
717 + if(!squashfs_get_cached_block(inode->i_sb, page_address(page), block, offset, bytes, &block, &offset))
718 + ERROR("Unable to read symbolic link [%x:%x]\n", block, offset);
722 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
723 + flush_dcache_page(page);
724 + SetPageUptodate(page);
732 +static int squashfs_readpage(struct file *file, struct page *page)
734 + struct inode *inode = page->mapping->host;
735 + struct squashfs_inode_info *sqi = SQUASH_I(inode);
736 + squashfs_sb_info *msBlk = inode->i_sb->s_fs_info;
737 + squashfs_super_block *sBlk = &msBlk->sBlk;
738 + unsigned short *block_listp;
739 + int index = sBlk->block_log > PAGE_CACHE_SHIFT ?
740 + page->index >> (sBlk->block_log - PAGE_CACHE_SHIFT) :
741 + page->index << (PAGE_CACHE_SHIFT - sBlk->block_log);
742 + int block = sqi->start_block, i = 0;
743 + int bytes = sqi->block_list_start;
744 + int offset = sqi->offset;
745 + int file_blocks = ((inode->i_size - 1) >> sBlk->block_log) + 1;
749 + TRACE("Entered squashfs_readpage, page index %d, start block %x\n", page->index,
753 + block_list = kmalloc(SIZE, GFP_KERNEL);
754 + sblock_list = kmalloc(SIZE, GFP_KERNEL);
755 + if (! (block_list && sblock_list)) {
756 + ERROR("Unable to allocate readpage buffer\n");
762 + if (! (block_list = kmalloc(SIZE, GFP_KERNEL))) {
763 + ERROR("Unable to allocate readpage buffer\n");
768 + if(index > file_blocks)
772 + int blocks = (index + 1 - i) > (SIZE >> 1) ? SIZE >> 1 : (index + 1 - i);
774 + if(!squashfs_get_cached_block(inode->i_sb, sblock_list, bytes, offset, blocks << 1, &bytes, &offset)) {
775 + ERROR("Unable to read block list [%d:%x]\n", bytes, offset);
778 + SQUASHFS_SWAP_SHORTS(((unsigned short *)block_list), ((unsigned short *)sblock_list), blocks);
780 + if(!squashfs_get_cached_block(inode->i_sb, block_list, bytes, offset, blocks << 1, &bytes, &offset)) {
781 + ERROR("Unable to read block list [%d:%x]\n", bytes, offset);
784 + for(block_listp = (unsigned short *) block_list; i < index && blocks; i ++, block_listp ++, blocks --)
785 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
790 + if(sBlk->block_log > PAGE_CACHE_SHIFT) {
791 + int mask = (1 << (sBlk->block_log - PAGE_CACHE_SHIFT)) - 1;
792 + int start_index = page->index & ~mask;
793 + int end_index = start_index | mask;
794 + int byte_offset = 0;
796 + down(&msBlk->read_page_mutex);
797 + if(!(bytes = read_data(inode->i_sb, msBlk->read_page, block, *block_listp, NULL))) {
798 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
802 + for(i = start_index; i <= end_index && byte_offset < bytes; i++, byte_offset += PAGE_CACHE_SIZE) {
803 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE : bytes - byte_offset;
805 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n", bytes, i, byte_offset, available_bytes);
807 + if(i == page->index) {
808 + memcpy(page_address(page), msBlk->read_page + byte_offset, available_bytes);
809 + memset(page_address(page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
810 + flush_dcache_page(page);
811 + SetPageUptodate(page);
814 + struct page *push_page;
816 + if((push_page = grab_cache_page_nowait(page->mapping, i))) {
817 + memcpy(page_address(push_page), msBlk->read_page + byte_offset, available_bytes);
818 + memset(page_address(push_page) + available_bytes, 0, PAGE_CACHE_SIZE - available_bytes);
819 + flush_dcache_page(push_page);
820 + SetPageUptodate(push_page);
821 + unlock_page(push_page);
822 + page_cache_release(push_page);
826 + up( &msBlk->read_page_mutex);
828 + kfree(sblock_list);
831 + } else if(sBlk->block_log == PAGE_CACHE_SHIFT) {
832 + if(!(bytes = read_data(inode->i_sb, page_address(page), block, *block_listp, NULL)))
833 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
836 + int i_end = index + (1 << (PAGE_CACHE_SHIFT - sBlk->block_log));
837 + char *p = (char *) page_address(page);
840 + if(i_end > file_blocks)
841 + i_end = file_blocks;
843 + while(index < i_end) {
844 + if(!(byte = read_data(inode->i_sb, p, block, *block_listp, NULL))) {
845 + ERROR("Unable to read page, block %x, size %x\n", block, (int) *block_listp);
848 + block += SQUASHFS_COMPRESSED_SIZE(*block_listp);
858 + kfree(sblock_list);
859 + memset(page_address(page) + bytes, 0, PAGE_CACHE_SIZE - bytes);
860 + flush_dcache_page(page);
861 + SetPageUptodate(page);
868 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
870 + struct inode *i = file->f_dentry->d_inode;
871 + struct squashfs_inode_info *sqi = SQUASH_I(i);
872 + squashfs_sb_info *msBlk = i->i_sb->s_fs_info;
873 + squashfs_super_block *sBlk = &msBlk->sBlk;
874 + int next_block = sqi->start_block + sBlk->directory_table_start, next_offset =
875 + sqi->offset, length = 0, dirs_read = 0, dir_count, bytes;
876 + squashfs_dir_header dirh;
877 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
878 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
880 + TRACE("Entered squashfs_readdir [%x:%x]\n", next_block, next_offset);
884 + while(length < i->i_size) {
885 + /* read directory header */
887 + squashfs_dir_header sdirh;
888 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block,
889 + next_offset, sizeof(sdirh), &next_block, &next_offset), !bytes)
891 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
893 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block,
894 + next_offset, sizeof(dirh), &next_block, &next_offset), !bytes)
897 + dir_count = dirh.count + 1;
898 + while(dir_count--) {
900 + squashfs_dir_entry sdire;
901 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &sdire, next_block,
902 + next_offset, sizeof(sdire), &next_block, &next_offset), !bytes)
904 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
906 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) dire, next_block,
907 + next_offset, sizeof(*dire), &next_block, &next_offset), !bytes)
910 + if(length += bytes = squashfs_get_cached_block(i->i_sb, dire->name, next_block,
911 + next_offset, dire->size + 1, &next_block, &next_offset), !bytes)
914 + if(file->f_pos >= length)
917 + dire->name[dire->size + 1] = '\0';
919 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n", dirent,
920 + dire->name, dire->size + 1, (int) file->f_pos,
921 + dirh.start_block, dire->offset, squashfs_filetype_table[dire->type]);
923 + if(filldir(dirent, dire->name, dire->size + 1, file->f_pos, SQUASHFS_MK_VFS_INODE(dirh.start_block,
924 + dire->offset), squashfs_filetype_table[dire->type]) < 0) {
925 + TRACE("Filldir returned less than 0\n");
930 + file->f_pos = length;
938 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
944 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
945 + struct nameidata *nd)
947 + const char *name =dentry->d_name.name;
948 + int len = dentry->d_name.len;
949 + struct inode *inode = NULL;
950 + struct squashfs_inode_info *sqi = SQUASH_I(i);
951 + squashfs_sb_info *msBlk = i->i_sb->s_fs_info;
952 + squashfs_super_block *sBlk = &msBlk->sBlk;
953 + int next_block = sqi->start_block + sBlk->directory_table_start, next_offset =
954 + sqi->offset, length = 0, dir_count, bytes;
955 + squashfs_dir_header dirh;
956 + char buffer[sizeof(squashfs_dir_entry) + SQUASHFS_NAME_LEN];
957 + squashfs_dir_entry *dire = (squashfs_dir_entry *) buffer;
959 + TRACE("Entered squashfs_lookup [%x:%x]\n", next_block, next_offset);
961 + while(length < i->i_size) {
962 + /* read directory header */
964 + squashfs_dir_header sdirh;
965 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &sdirh, next_block, next_offset,
966 + sizeof(sdirh), &next_block, &next_offset), !bytes)
968 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
970 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &dirh, next_block, next_offset,
971 + sizeof(dirh), &next_block, &next_offset), !bytes)
974 + dir_count = dirh.count + 1;
975 + while(dir_count--) {
977 + squashfs_dir_entry sdire;
978 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) &sdire,
979 + next_block,next_offset, sizeof(sdire), &next_block, &next_offset), !bytes)
981 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
983 + if(length += bytes = squashfs_get_cached_block(i->i_sb, (char *) dire,
984 + next_block,next_offset, sizeof(*dire), &next_block, &next_offset), !bytes)
987 + if(length += bytes = squashfs_get_cached_block(i->i_sb, dire->name,
988 + next_block, next_offset, dire->size + 1, &next_block, &next_offset), !bytes)
991 + if((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
992 + squashfs_inode ino = SQUASHFS_MKINODE(dirh.start_block, dire->offset);
994 + TRACE("calling squashfs_iget for directory entry %s, inode %x:%x\n",
995 + name, dirh.start_block, dire->offset);
997 + inode = squashfs_iget(i->i_sb, ino);
1005 + d_add(dentry, inode);
1006 + return ERR_PTR(0);
1009 + ERROR("Unable to read directory block [%x:%x]\n", next_block, next_offset);
1014 +static void squashfs_put_super(struct super_block *s)
1016 + squashfs_sb_info *msBlk = s->s_fs_info;
1017 + kfree(msBlk->block_cache);
1018 + kfree(msBlk->read_data);
1019 + kfree(msBlk->read_page);
1020 + kfree(msBlk->uid);
1022 + s->s_fs_info = NULL;
1025 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type,
1026 + int flags, const char *dev_name, void *data)
1028 + return get_sb_bdev(fs_type, flags, dev_name, data,
1029 + squashfs_fill_super);
1032 +static kmem_cache_t * squashfs_inode_cachep;
1034 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
1036 + struct squashfs_inode_info *ii;
1037 + ii = (struct squashfs_inode_info *)
1038 + kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
1041 + ii->vfs_inode.i_version = 1;
1042 + return &ii->vfs_inode;
1045 +static void squashfs_destroy_inode(struct inode *inode)
1047 + kmem_cache_free(squashfs_inode_cachep, SQUASH_I(inode));
1050 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
1052 + struct squashfs_inode_info *sqi = (struct squashfs_inode_info *) foo;
1054 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
1055 + SLAB_CTOR_CONSTRUCTOR) {
1056 + inode_init_once(&sqi->vfs_inode);
1060 +static int init_inodecache(void)
1062 + squashfs_inode_cachep =
1063 + kmem_cache_create("squashfs_inode_cache",
1064 + sizeof(struct squashfs_inode_info),
1065 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
1067 + if (squashfs_inode_cachep == NULL)
1072 +static void destroy_inodecache(void)
1074 + kmem_cache_destroy(squashfs_inode_cachep);
1077 +static int __init init_squashfs_fs(void)
1080 + if(!(stream.workspace = (char *) vmalloc(zlib_inflate_workspacesize()))) {
1081 + ERROR("Failed to allocate zlib workspace\n");
1084 + if (init_inodecache())
1086 + return register_filesystem(&squashfs_fs_type);
1090 +static void __exit exit_squashfs_fs(void)
1092 + destroy_inodecache();
1093 + vfree(stream.workspace);
1094 + unregister_filesystem(&squashfs_fs_type);
1098 +module_init(init_squashfs_fs);
1099 +module_exit(exit_squashfs_fs);
1100 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
1101 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
1102 +MODULE_LICENSE("GPL");
1103 diff -Naur linux-2.6.0-test1-ac2/include/linux/squashfs_fs.h linux-2.6.0-test1-ac2-sfs/include/linux/squashfs_fs.h
1104 --- linux-2.6.0-test1-ac2/include/linux/squashfs_fs.h 1969-12-31 16:00:00.000000000 -0800
1105 +++ linux-2.6.0-test1-ac2-sfs/include/linux/squashfs_fs.h 2003-07-18 16:12:47.000000000 -0700
1107 +#ifndef SQUASHFS_FS
1108 +#define SQUASHFS_FS
1112 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1114 + * This program is free software; you can redistribute it and/or
1115 + * modify it under the terms of the GNU General Public License
1116 + * as published by the Free Software Foundation; either version
1117 + * 2 of the License, or (at your option) any later version.
1122 +#define SQUASHFS_MAJOR 1
1123 +#define SQUASHFS_MINOR 0
1124 +#define SQUASHFS_MAGIC 0x73717368
1125 +#define SQUASHFS_MAGIC_SWAP 0x68737173
1126 +#define SQUASHFS_START 0
1128 +/* size of metadata (inode and directory) blocks */
1129 +#define SQUASHFS_METADATA_SIZE 8192
1130 +#define SQUASHFS_METADATA_LOG 13
1132 +/* default size of data blocks */
1133 +#define SQUASHFS_FILE_SIZE 32768
1134 +#define SQUASHFS_FILE_LOG 15
1136 +#define SQUASHFS_FILE_MAX_SIZE 32768
1138 +/* Max number of uids and gids */
1139 +#define SQUASHFS_UIDS 48
1140 +#define SQUASHFS_GUIDS 15
1142 +/* Max length of filename (not 255) */
1143 +#define SQUASHFS_NAME_LEN 256
1145 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
1146 +#define SQUASHFS_INVALID_BLK ((long long) 0xffffffff)
1147 +#define SQUASHFS_USED_BLK ((long long) 0xfffffffe)
1149 +/* Filesystem flags */
1150 +#define SQUASHFS_NOI 1
1151 +#define SQUASHFS_NOD 2
1152 +#define SQUASHFS_CHECK 4
1153 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) (flags & SQUASHFS_NOI)
1154 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) (flags & SQUASHFS_NOD)
1155 +#define SQUASHFS_CHECK_DATA(flags) (flags & SQUASHFS_CHECK)
1156 +#define SQUASHFS_MKFLAGS(noi, nod, check_data) (noi | (nod << 1) | (check_data << 2))
1158 +/* Max number of types and file types */
1159 +#define SQUASHFS_TYPES 5
1160 +#define SQUASHFS_DIR_TYPE 1
1161 +#define SQUASHFS_FILE_TYPE 2
1162 +#define SQUASHFS_SYMLINK_TYPE 3
1163 +#define SQUASHFS_BLKDEV_TYPE 4
1164 +#define SQUASHFS_CHRDEV_TYPE 5
1166 +/* Flag whether block is compressed or uncompressed, bit is set if block is uncompressed */
1167 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
1168 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
1169 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
1171 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
1174 + * Inode number ops. Inodes consist of a compressed block number, and an uncompressed
1175 + * offset within that block
1177 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
1178 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
1179 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode)(((squashfs_inode) (A) << 16)\
1182 +/* Compute 32 bit VFS inode number from squashfs inode number */
1183 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + ((b) >> 2) + 1))
1185 +/* Translate between VFS mode and squashfs mode */
1186 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
1188 +/* cached data constants for filesystem */
1189 +#define SQUASHFS_CACHED_BLKS 8
1191 +#define SQUASHFS_MAX_FILE_SIZE_LOG 32
1192 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << SQUASHFS_MAX_FILE_SIZE_LOG - 1)
1194 +#define SQUASHFS_MARKER_BYTE 0xff
1197 + * definitions for structures on disk
1200 +typedef unsigned int squashfs_block;
1201 +typedef long long squashfs_inode;
1203 +typedef unsigned int squashfs_uid;
1205 +typedef struct squashfs_super_block {
1206 + unsigned int s_magic __attribute__ ((packed));
1207 + unsigned int inodes __attribute__ ((packed));
1208 + unsigned int bytes_used __attribute__ ((packed));
1209 + unsigned int uid_start __attribute__ ((packed));
1210 + unsigned int guid_start __attribute__ ((packed));
1211 + unsigned int inode_table_start __attribute__ ((packed));
1212 + unsigned int directory_table_start __attribute__ ((packed));
1213 + unsigned int s_major:16 __attribute__ ((packed));
1214 + unsigned int s_minor:16 __attribute__ ((packed));
1215 + unsigned int block_size:16 __attribute__ ((packed));
1216 + unsigned int block_log:16 __attribute__ ((packed));
1217 + unsigned int flags:8 __attribute__ ((packed));
1218 + unsigned int no_uids:8 __attribute__ ((packed));
1219 + unsigned int no_guids:8 __attribute__ ((packed));
1220 + time_t mkfs_time /* time of filesystem creation */ __attribute__ ((packed));
1221 + squashfs_inode root_inode __attribute__ ((packed));
1222 +} squashfs_super_block;
1225 + unsigned int inode_type:4 __attribute__ ((packed));
1226 + unsigned int mode:12 __attribute__ ((packed)); /* protection */
1227 + unsigned int uid:4 __attribute__ ((packed)); /* index into uid table */
1228 + unsigned int guid:4 __attribute__ ((packed)); /* index into guid table */
1229 +} squashfs_base_inode_header;
1232 + unsigned int inode_type:4 __attribute__ ((packed));
1233 + unsigned int mode:12 __attribute__ ((packed)); /* protection */
1234 + unsigned int uid:4 __attribute__ ((packed)); /* index into uid table */
1235 + unsigned int guid:4 __attribute__ ((packed)); /* index into guid table */
1236 + unsigned short rdev __attribute__ ((packed));
1237 +} squashfs_dev_inode_header;
1240 + unsigned int inode_type:4 __attribute__ ((packed));
1241 + unsigned int mode:12 __attribute__ ((packed)); /* protection */
1242 + unsigned int uid:4 __attribute__ ((packed)); /* index into uid table */
1243 + unsigned int guid:4 __attribute__ ((packed)); /* index into guid table */
1244 + unsigned short symlink_size __attribute__ ((packed));
1245 + char symlink[0] __attribute__ ((packed));
1246 +} squashfs_symlink_inode_header;
1249 + unsigned int inode_type:4 __attribute__ ((packed));
1250 + unsigned int mode:12 __attribute__ ((packed)); /* protection */
1251 + unsigned int uid:4 __attribute__ ((packed)); /* index into uid table */
1252 + unsigned int guid:4 __attribute__ ((packed)); /* index into guid table */
1253 + time_t mtime __attribute__ ((packed));
1254 + squashfs_block start_block __attribute__ ((packed));
1255 + unsigned int file_size:SQUASHFS_MAX_FILE_SIZE_LOG __attribute__ ((packed));
1256 + unsigned short block_list[0] __attribute__ ((packed));
1257 +} squashfs_reg_inode_header;
1260 + unsigned int inode_type:4 __attribute__ ((packed));
1261 + unsigned int mode:12 __attribute__ ((packed)); /* protection */
1262 + unsigned int uid:4 __attribute__ ((packed)); /* index into uid table */
1263 + unsigned int guid:4 __attribute__ ((packed)); /* index into guid table */
1264 + unsigned int file_size:19 __attribute__ ((packed));
1265 + unsigned int offset:13 __attribute__ ((packed));
1266 + time_t mtime __attribute__ ((packed));
1267 + unsigned int start_block:24 __attribute__ ((packed));
1268 +} squashfs_dir_inode_header;
1271 + squashfs_base_inode_header base;
1272 + squashfs_dev_inode_header dev;
1273 + squashfs_symlink_inode_header symlink;
1274 + squashfs_reg_inode_header reg;
1275 + squashfs_dir_inode_header dir;
1276 +} squashfs_inode_header;
1279 + unsigned int offset:13 __attribute__ ((packed));
1280 + unsigned int type:3 __attribute__ ((packed));
1281 + unsigned int size:8 __attribute__ ((packed));
1282 + char name[0] __attribute__ ((packed));
1283 +} squashfs_dir_entry;
1286 + unsigned int count:8 __attribute__ ((packed));
1287 + unsigned int start_block:24 __attribute__ ((packed));
1288 +} squashfs_dir_header;
1291 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
1292 +extern int squashfs_uncompress_init(void);
1293 +extern int squashfs_uncompress_exit(void);
1296 + * macros to convert each packed bitfield structure from little endian to big
1297 + * endian and vice versa. These are needed when creating or using a filesystem on a
1298 + * machine with different byte ordering to the target architecture.
1302 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
1303 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_super_block));\
1304 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
1305 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
1306 + SQUASHFS_SWAP((s)->bytes_used, d, 64, 32);\
1307 + SQUASHFS_SWAP((s)->uid_start, d, 96, 32);\
1308 + SQUASHFS_SWAP((s)->guid_start, d, 128, 32);\
1309 + SQUASHFS_SWAP((s)->inode_table_start, d, 160, 32);\
1310 + SQUASHFS_SWAP((s)->directory_table_start, d, 192, 32);\
1311 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
1312 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
1313 + SQUASHFS_SWAP((s)->block_size, d, 256, 16);\
1314 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
1315 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
1316 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
1317 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
1318 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
1319 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
1322 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
1323 + SQUASHFS_MEMSET(s, d, n);\
1324 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
1325 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
1326 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
1327 + SQUASHFS_SWAP((s)->guid, d, 20, 4);\
1330 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
1331 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dev_inode_header));\
1332 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
1335 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
1336 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_symlink_inode_header));\
1337 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
1340 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
1341 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_reg_inode_header));\
1342 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
1343 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
1344 + SQUASHFS_SWAP((s)->file_size, d, 88, SQUASHFS_MAX_FILE_SIZE_LOG);\
1347 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
1348 + SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, sizeof(squashfs_dir_inode_header));\
1349 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
1350 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
1351 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
1352 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
1355 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
1356 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_header));\
1357 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
1358 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
1361 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
1362 + SQUASHFS_MEMSET(s, d, sizeof(squashfs_dir_entry));\
1363 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
1364 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
1365 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
1368 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
1370 + int bit_position;\
1371 + SQUASHFS_MEMSET(s, d, n * 2);\
1372 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += 16)\
1373 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
1376 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
1378 + int bit_position;\
1379 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
1380 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += bits)\
1381 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
1386 + * macros used to swap each structure entry, taking into account
1387 + * bitfields and different bitfield placing conventions on differing architectures
1389 +#include <asm/byteorder.h>
1390 +#ifdef __BIG_ENDIAN
1391 + /* convert from little endian to big endian */
1392 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
1394 + /* convert from big endian to little endian */
1395 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
1398 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
1400 + int b_pos = pos % 8;\
1401 + unsigned long long val = 0;\
1402 + unsigned char *s = (unsigned char *)p + (pos / 8);\
1403 + unsigned char *d = ((unsigned char *) &val) + 7;\
1404 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
1406 + value = val >> (SHIFT);\
1408 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
1411 diff -Naur linux-2.6.0-test1-ac2/include/linux/squashfs_fs_sb.h linux-2.6.0-test1-ac2-sfs/include/linux/squashfs_fs_sb.h
1412 --- linux-2.6.0-test1-ac2/include/linux/squashfs_fs_sb.h 1969-12-31 16:00:00.000000000 -0800
1413 +++ linux-2.6.0-test1-ac2-sfs/include/linux/squashfs_fs_sb.h 2003-07-18 16:12:47.000000000 -0700
1415 +#ifndef SQUASHFS_FS_SB
1416 +#define SQUASHFS_FS_SB
1420 + * Copyright (c) 2002 Phillip Lougher <phillip@lougher.demon.co.uk>
1422 + * This program is free software; you can redistribute it and/or
1423 + * modify it under the terms of the GNU General Public License
1424 + * as published by the Free Software Foundation; either version
1425 + * 2 of the License, or (at your option) any later version.
1427 + * squashfs_fs_sb.h
1430 +#include <linux/squashfs_fs.h>
1433 + unsigned int block;
1435 + unsigned int next_index;
1439 +typedef struct squashfs_sb_info {
1440 + squashfs_super_block sBlk;
1442 + int devblksize_log2;
1444 + squashfs_cache *block_cache;
1446 + squashfs_uid *uid;
1447 + squashfs_uid *guid;
1448 + unsigned int read_size;
1451 + struct semaphore read_page_mutex;
1452 + struct semaphore block_cache_mutex;
1453 + wait_queue_head_t waitq;
1454 + } squashfs_sb_info;
1456 diff -Naur linux-2.6.0-test1-ac2/lib/Kconfig linux-2.6.0-test1-ac2-sfs/lib/Kconfig
1457 --- linux-2.6.0-test1-ac2/lib/Kconfig 2003-05-04 16:53:32.000000000 -0700
1458 +++ linux-2.6.0-test1-ac2-sfs/lib/Kconfig 2003-07-16 16:40:44.000000000 -0700
1463 - default y if CRAMFS=y || PPP_DEFLATE=y || JFFS2_FS=y || ZISOFS_FS=y || BINFMT_ZFLAT=y || CRYPTO_DEFLATE=y
1464 - default m if CRAMFS=m || PPP_DEFLATE=m || JFFS2_FS=m || ZISOFS_FS=m || BINFMT_ZFLAT=m || CRYPTO_DEFLATE=m
1465 + default y if CRAMFS=y || SQUASHFS=y || PPP_DEFLATE=y || JFFS2_FS=y || ZISOFS_FS=y || BINFMT_ZFLAT=y || CRYPTO_DEFLATE=y
1466 + default m if CRAMFS=m || SQUASHFS=m || PPP_DEFLATE=m || JFFS2_FS=m || ZISOFS_FS=m || BINFMT_ZFLAT=m || CRYPTO_DEFLATE=m