1 --- kernel-power-2.6.28.orig/fs/Kconfig
2 +++ kernel-power-2.6.28/fs/Kconfig
8 + tristate "SquashFS 3.4 - Squashed file system support"
11 + Saying Y here includes support for SquashFS 3.4 (a Compressed
12 + Read-Only File System). Squashfs is a highly compressed read-only
13 + filesystem for Linux. It uses zlib compression to compress both
14 + files, inodes and directories. Inodes in the system are very small
15 + and all blocks are packed to minimise data overhead. Block sizes
16 + greater than 4K are supported up to a maximum of 1 Mbytes (default
17 + block size 128K). SquashFS 3.3 supports 64 bit filesystems and files
18 + (larger than 4GB), full uid/gid information, hard links and timestamps.
20 + Squashfs is intended for general read-only filesystem use, for
21 + archival use (i.e. in cases where a .tar.gz file may be used), and in
22 + embedded systems where low overhead is needed. Further information
23 + and filesystem tools are available from http://squashfs.sourceforge.net.
25 + If you want to compile this as a module ( = code which can be
26 + inserted in and removed from the running kernel whenever you want),
27 + say M here and read <file:Documentation/modules.txt>. The module
28 + will be called squashfs. Note that the root file system (the one
29 + containing the directory /) cannot be compiled as a module.
33 +config SQUASHFS_EMBEDDED
35 + bool "Additional option for memory-constrained systems"
39 + Saying Y here allows you to specify cache size.
43 +config SQUASHFS_FRAGMENT_CACHE_SIZE
44 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
48 + By default SquashFS caches the last 3 fragments read from
49 + the filesystem. Increasing this amount may mean SquashFS
50 + has to re-read fragments less often from disk, at the expense
51 + of extra system memory. Decreasing this amount will mean
52 + SquashFS uses less memory at the expense of extra reads from disk.
54 + Note there must be at least one cached fragment. Anything
55 + much more than three will probably not make much difference.
58 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
60 --- kernel-power-2.6.28.orig/fs/Makefile
61 +++ kernel-power-2.6.28/fs/Makefile
63 obj-$(CONFIG_JBD2) += jbd2/
64 obj-$(CONFIG_EXT2_FS) += ext2/
65 obj-$(CONFIG_CRAMFS) += cramfs/
66 +obj-$(CONFIG_SQUASHFS) += squashfs/
68 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
69 obj-$(CONFIG_CODA_FS) += coda/
71 +++ kernel-power-2.6.28/fs/squashfs/Makefile
74 +# Makefile for the linux squashfs routines.
77 +obj-$(CONFIG_SQUASHFS) += squashfs.o
78 +squashfs-y += inode.o
79 +squashfs-y += squashfs2_0.o
81 +++ kernel-power-2.6.28/fs/squashfs/inode.c
84 + * Squashfs - a compressed read only filesystem for Linux
86 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
87 + * Phillip Lougher <phillip@lougher.demon.co.uk>
89 + * This program is free software; you can redistribute it and/or
90 + * modify it under the terms of the GNU General Public License
91 + * as published by the Free Software Foundation; either version 2,
92 + * or (at your option) any later version.
94 + * This program is distributed in the hope that it will be useful,
95 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
96 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 + * GNU General Public License for more details.
99 + * You should have received a copy of the GNU General Public License
100 + * along with this program; if not, write to the Free Software
101 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
106 +#include <linux/squashfs_fs.h>
107 +#include <linux/module.h>
108 +#include <linux/zlib.h>
109 +#include <linux/fs.h>
110 +#include <linux/squashfs_fs_sb.h>
111 +#include <linux/squashfs_fs_i.h>
112 +#include <linux/buffer_head.h>
113 +#include <linux/vfs.h>
114 +#include <linux/vmalloc.h>
115 +#include <linux/spinlock.h>
116 +#include <linux/smp_lock.h>
117 +#include <linux/exportfs.h>
119 +#include "squashfs.h"
121 +static struct dentry *squashfs_fh_to_dentry(struct super_block *s,
122 + struct fid *fid, int fh_len, int fh_type);
123 +static struct dentry *squashfs_fh_to_parent(struct super_block *s,
124 + struct fid *fid, int fh_len, int fh_type);
125 +static struct dentry *squashfs_get_parent(struct dentry *child);
126 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
127 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
128 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
129 +static long long read_blocklist(struct inode *inode, int index,
130 + int readahead_blks, char *block_list,
131 + unsigned short **block_p, unsigned int *bsize);
132 +static int squashfs_readpage(struct file *file, struct page *page);
133 +static int squashfs_readdir(struct file *, void *, filldir_t);
134 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
135 + struct nameidata *);
136 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
137 +static void squashfs_put_super(struct super_block *);
138 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
139 + struct vfsmount *);
140 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
141 +static void squashfs_destroy_inode(struct inode *inode);
142 +static int init_inodecache(void);
143 +static void destroy_inodecache(void);
145 +static struct file_system_type squashfs_fs_type = {
146 + .owner = THIS_MODULE,
147 + .name = "squashfs",
148 + .get_sb = squashfs_get_sb,
149 + .kill_sb = kill_block_super,
150 + .fs_flags = FS_REQUIRES_DEV
153 +static const unsigned char squashfs_filetype_table[] = {
154 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
157 +static struct super_operations squashfs_super_ops = {
158 + .alloc_inode = squashfs_alloc_inode,
159 + .destroy_inode = squashfs_destroy_inode,
160 + .statfs = squashfs_statfs,
161 + .put_super = squashfs_put_super,
162 + .remount_fs = squashfs_remount
165 +static struct export_operations squashfs_export_ops = {
166 + .fh_to_dentry = squashfs_fh_to_dentry,
167 + .fh_to_parent = squashfs_fh_to_parent,
168 + .get_parent = squashfs_get_parent
171 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
172 + .readpage = squashfs_symlink_readpage
175 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
176 + .readpage = squashfs_readpage
179 +static const struct file_operations squashfs_dir_ops = {
180 + .read = generic_read_dir,
181 + .readdir = squashfs_readdir
184 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
185 + .lookup = squashfs_lookup
189 +static struct buffer_head *get_block_length(struct super_block *s,
190 + int *cur_index, int *offset, int *c_byte)
192 + struct squashfs_sb_info *msblk = s->s_fs_info;
193 + unsigned short temp;
194 + struct buffer_head *bh;
196 + if (!(bh = sb_bread(s, *cur_index)))
199 + if (msblk->devblksize - *offset == 1) {
201 + ((unsigned char *) &temp)[1] = *((unsigned char *)
202 + (bh->b_data + *offset));
204 + ((unsigned char *) &temp)[0] = *((unsigned char *)
205 + (bh->b_data + *offset));
207 + if (!(bh = sb_bread(s, ++(*cur_index))))
210 + ((unsigned char *) &temp)[0] = *((unsigned char *)
213 + ((unsigned char *) &temp)[1] = *((unsigned char *)
219 + ((unsigned char *) &temp)[1] = *((unsigned char *)
220 + (bh->b_data + *offset));
221 + ((unsigned char *) &temp)[0] = *((unsigned char *)
222 + (bh->b_data + *offset + 1));
224 + ((unsigned char *) &temp)[0] = *((unsigned char *)
225 + (bh->b_data + *offset));
226 + ((unsigned char *) &temp)[1] = *((unsigned char *)
227 + (bh->b_data + *offset + 1));
233 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
234 + if (*offset == msblk->devblksize) {
236 + if (!(bh = sb_bread(s, ++(*cur_index))))
240 + if (*((unsigned char *) (bh->b_data + *offset)) !=
241 + SQUASHFS_MARKER_BYTE) {
242 + ERROR("Metadata block marker corrupt @ %x\n",
256 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
257 + long long index, unsigned int length,
258 + long long *next_index, int srclength)
260 + struct squashfs_sb_info *msblk = s->s_fs_info;
261 + struct squashfs_super_block *sblk = &msblk->sblk;
262 + struct buffer_head **bh;
263 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
264 + unsigned int cur_index = index >> msblk->devblksize_log2;
265 + int bytes, avail_bytes, b = 0, k = 0;
266 + unsigned int compressed;
267 + unsigned int c_byte = length;
269 + bh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *
270 + sizeof(struct buffer_head *), GFP_KERNEL);
276 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
277 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
279 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index,
280 + compressed ? "" : "un", (unsigned int) c_byte, srclength);
282 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
285 + for (b = 0; bytes < (int) c_byte; b++, cur_index++) {
286 + bh[b] = sb_getblk(s, cur_index);
288 + goto block_release;
289 + bytes += msblk->devblksize;
291 + ll_rw_block(READ, b, bh);
293 + if (index < 0 || (index + 2) > sblk->bytes_used)
296 + bh[0] = get_block_length(s, &cur_index, &offset, &c_byte);
301 + bytes = msblk->devblksize - offset;
302 + compressed = SQUASHFS_COMPRESSED(c_byte);
303 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
305 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
306 + ? "" : "un", (unsigned int) c_byte);
308 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
309 + goto block_release;
311 + for (; bytes < c_byte; b++) {
312 + bh[b] = sb_getblk(s, ++cur_index);
314 + goto block_release;
315 + bytes += msblk->devblksize;
317 + ll_rw_block(READ, b - 1, bh + 1);
327 + mutex_lock(&msblk->read_data_mutex);
329 + msblk->stream.next_out = buffer;
330 + msblk->stream.avail_out = srclength;
332 + for (bytes = 0; k < b; k++) {
333 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
335 + wait_on_buffer(bh[k]);
336 + if (!buffer_uptodate(bh[k]))
337 + goto release_mutex;
339 + msblk->stream.next_in = bh[k]->b_data + offset;
340 + msblk->stream.avail_in = avail_bytes;
343 + zlib_err = zlib_inflateInit(&msblk->stream);
344 + if (zlib_err != Z_OK) {
345 + ERROR("zlib_inflateInit returned unexpected result 0x%x,"
346 + " srclength %d\n", zlib_err, srclength);
347 + goto release_mutex;
350 + if (avail_bytes == 0) {
357 + zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
358 + if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
359 + ERROR("zlib_inflate returned unexpected result 0x%x,"
360 + " srclength %d, avail_in %d, avail_out %d\n", zlib_err,
361 + srclength, msblk->stream.avail_in, msblk->stream.avail_out);
362 + goto release_mutex;
365 + bytes += avail_bytes;
370 + if (zlib_err != Z_STREAM_END)
371 + goto release_mutex;
373 + zlib_err = zlib_inflateEnd(&msblk->stream);
374 + if (zlib_err != Z_OK) {
375 + ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
376 + " srclength %d\n", zlib_err, srclength);
377 + goto release_mutex;
379 + bytes = msblk->stream.total_out;
380 + mutex_unlock(&msblk->read_data_mutex);
384 + for(i = 0; i < b; i++) {
385 + wait_on_buffer(bh[i]);
386 + if (!buffer_uptodate(bh[i]))
387 + goto block_release;
390 + for (bytes = 0; k < b; k++) {
391 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
393 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
394 + bytes += avail_bytes;
401 + *next_index = index + c_byte + (length ? 0 :
402 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));
408 + mutex_unlock(&msblk->read_data_mutex);
415 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
421 +static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,
422 + struct squashfs_cache *cache, long long block, int length)
425 + struct squashfs_cache_entry *entry;
427 + spin_lock(&cache->lock);
430 + for (i = 0; i < cache->entries && cache->entry[i].block != block; i++);
432 + if (i == cache->entries) {
433 + if (cache->unused_blks == 0) {
435 + spin_unlock(&cache->lock);
436 + wait_event(cache->wait_queue, cache->unused_blks);
437 + spin_lock(&cache->lock);
442 + i = cache->next_blk;
443 + for (n = 0; n < cache->entries; n++) {
444 + if (cache->entry[i].locked == 0)
446 + i = (i + 1) % cache->entries;
449 + cache->next_blk = (i + 1) % cache->entries;
450 + entry = &cache->entry[i];
452 + cache->unused_blks --;
453 + entry->block = block;
455 + entry->pending = 1;
456 + entry->waiting = 0;
458 + spin_unlock(&cache->lock);
460 + entry->length = squashfs_read_data(s, entry->data,
461 + block, length, &entry->next_index, cache->block_size);
463 + spin_lock(&cache->lock);
465 + if (entry->length == 0)
468 + entry->pending = 0;
469 + spin_unlock(&cache->lock);
470 + if (entry->waiting)
471 + wake_up_all(&entry->wait_queue);
475 + entry = &cache->entry[i];
476 + if (entry->locked == 0)
477 + cache->unused_blks --;
480 + if (entry->pending) {
482 + spin_unlock(&cache->lock);
483 + wait_event(entry->wait_queue, !entry->pending);
487 + spin_unlock(&cache->lock);
492 + TRACE("Got %s %d, start block %lld, locked %d, error %d\n", i,
493 + cache->name, entry->block, entry->locked, entry->error);
495 + ERROR("Unable to read %s cache entry [%llx]\n", cache->name, block);
500 +static void squashfs_cache_put(struct squashfs_cache *cache,
501 + struct squashfs_cache_entry *entry)
503 + spin_lock(&cache->lock);
505 + if (entry->locked == 0) {
506 + cache->unused_blks ++;
507 + spin_unlock(&cache->lock);
508 + if (cache->waiting)
509 + wake_up(&cache->wait_queue);
511 + spin_unlock(&cache->lock);
515 +static void squashfs_cache_delete(struct squashfs_cache *cache)
522 + for (i = 0; i < cache->entries; i++)
523 + if (cache->entry[i].data) {
524 + if (cache->use_vmalloc)
525 + vfree(cache->entry[i].data);
527 + kfree(cache->entry[i].data);
534 +static struct squashfs_cache *squashfs_cache_init(char *name, int entries,
535 + int block_size, int use_vmalloc)
538 + struct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +
539 + entries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);
540 + if (cache == NULL) {
541 + ERROR("Failed to allocate %s cache\n", name);
545 + cache->next_blk = 0;
546 + cache->unused_blks = entries;
547 + cache->entries = entries;
548 + cache->block_size = block_size;
549 + cache->use_vmalloc = use_vmalloc;
550 + cache->name = name;
551 + cache->waiting = 0;
552 + spin_lock_init(&cache->lock);
553 + init_waitqueue_head(&cache->wait_queue);
555 + for (i = 0; i < entries; i++) {
556 + init_waitqueue_head(&cache->entry[i].wait_queue);
557 + cache->entry[i].block = SQUASHFS_INVALID_BLK;
558 + cache->entry[i].data = use_vmalloc ? vmalloc(block_size) :
559 + kmalloc(block_size, GFP_KERNEL);
560 + if (cache->entry[i].data == NULL) {
561 + ERROR("Failed to allocate %s cache entry\n", name);
569 + squashfs_cache_delete(cache);
575 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,
576 + long long block, unsigned int offset,
577 + int length, long long *next_block,
578 + unsigned int *next_offset)
580 + struct squashfs_sb_info *msblk = s->s_fs_info;
581 + int bytes, return_length = length;
582 + struct squashfs_cache_entry *entry;
584 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
587 + entry = squashfs_cache_get(s, msblk->block_cache, block, 0);
588 + bytes = entry->length - offset;
590 + if (entry->error || bytes < 1) {
593 + } else if (bytes >= length) {
595 + memcpy(buffer, entry->data + offset, length);
596 + if (entry->length - offset == length) {
597 + *next_block = entry->next_index;
600 + *next_block = block;
601 + *next_offset = offset + length;
606 + memcpy(buffer, entry->data + offset, bytes);
607 + buffer = (char *) buffer + bytes;
609 + block = entry->next_index;
610 + squashfs_cache_put(msblk->block_cache, entry);
617 + squashfs_cache_put(msblk->block_cache, entry);
618 + return return_length;
622 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
623 + long long *fragment_start_block,
624 + unsigned int *fragment_size)
626 + struct squashfs_sb_info *msblk = s->s_fs_info;
627 + long long start_block =
628 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
629 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
630 + struct squashfs_fragment_entry fragment_entry;
633 + struct squashfs_fragment_entry sfragment_entry;
635 + if (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,
636 + sizeof(sfragment_entry), &start_block, &offset))
638 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
640 + if (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,
641 + sizeof(fragment_entry), &start_block, &offset))
644 + *fragment_start_block = fragment_entry.start_block;
645 + *fragment_size = fragment_entry.size;
654 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,
655 + struct squashfs_cache_entry *fragment)
657 + squashfs_cache_put(msblk->fragment_cache, fragment);
662 +struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,
663 + long long start_block, int length)
665 + struct squashfs_sb_info *msblk = s->s_fs_info;
667 + return squashfs_cache_get(s, msblk->fragment_cache, start_block, length);
671 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
672 + struct squashfs_base_inode_header *inodeb)
674 + i->i_ino = inodeb->inode_number;
675 + i->i_mtime.tv_sec = inodeb->mtime;
676 + i->i_atime.tv_sec = inodeb->mtime;
677 + i->i_ctime.tv_sec = inodeb->mtime;
678 + i->i_uid = msblk->uid[inodeb->uid];
679 + i->i_mode = inodeb->mode;
682 + if (inodeb->guid == SQUASHFS_GUIDS)
683 + i->i_gid = i->i_uid;
685 + i->i_gid = msblk->guid[inodeb->guid];
689 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
691 + struct squashfs_sb_info *msblk = s->s_fs_info;
692 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
693 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
694 + squashfs_inode_t inode;
696 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
699 + squashfs_inode_t sinode;
701 + if (!squashfs_get_cached_block(s, &sinode, start, offset,
702 + sizeof(sinode), &start, &offset))
704 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
705 + } else if (!squashfs_get_cached_block(s, &inode, start, offset,
706 + sizeof(inode), &start, &offset))
709 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
714 + return SQUASHFS_INVALID_BLK;
719 +static struct dentry *squashfs_export_iget(struct super_block *s,
720 + unsigned int inode_number)
722 + squashfs_inode_t inode;
723 + struct dentry *dentry = ERR_PTR(-ENOENT);
725 + TRACE("Entered squashfs_export_iget\n");
727 + inode = squashfs_inode_lookup(s, inode_number);
728 + if(inode != SQUASHFS_INVALID_BLK)
729 + dentry = d_obtain_alias(squashfs_iget(s, inode, inode_number));
735 +static struct dentry *squashfs_fh_to_dentry(struct super_block *s,
736 + struct fid *fid, int fh_len, int fh_type)
738 + if((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||
742 + return squashfs_export_iget(s, fid->i32.ino);
746 +static struct dentry *squashfs_fh_to_parent(struct super_block *s,
747 + struct fid *fid, int fh_len, int fh_type)
749 + if(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)
752 + return squashfs_export_iget(s, fid->i32.parent_ino);
756 +static struct dentry *squashfs_get_parent(struct dentry *child)
758 + struct inode *i = child->d_inode;
760 + TRACE("Entered squashfs_get_parent\n");
762 + return squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
766 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,
767 + squashfs_inode_t inode, unsigned int inode_number)
769 + struct squashfs_sb_info *msblk = s->s_fs_info;
770 + struct inode *i = iget_locked(s, inode_number);
772 + TRACE("Entered squashfs_iget\n");
774 + if(i && (i->i_state & I_NEW)) {
775 + (msblk->read_inode)(i, inode);
776 + unlock_new_inode(i);
783 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
785 + struct super_block *s = i->i_sb;
786 + struct squashfs_sb_info *msblk = s->s_fs_info;
787 + struct squashfs_super_block *sblk = &msblk->sblk;
788 + long long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;
789 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
790 + long long next_block;
791 + unsigned int next_offset;
792 + union squashfs_inode_header id, sid;
793 + struct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;
795 + TRACE("Entered squashfs_read_inode\n");
798 + if (!squashfs_get_cached_block(s, sinodeb, block, offset,
799 + sizeof(*sinodeb), &next_block, &next_offset))
801 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));
803 + if (!squashfs_get_cached_block(s, inodeb, block, offset,
804 + sizeof(*inodeb), &next_block, &next_offset))
807 + squashfs_new_inode(msblk, i, inodeb);
809 + switch(inodeb->inode_type) {
810 + case SQUASHFS_FILE_TYPE: {
811 + unsigned int frag_size;
812 + long long frag_blk;
813 + struct squashfs_reg_inode_header *inodep = &id.reg;
814 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
817 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
818 + sizeof(*sinodep), &next_block, &next_offset))
820 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
822 + if (!squashfs_get_cached_block(s, inodep, block, offset,
823 + sizeof(*inodep), &next_block, &next_offset))
826 + frag_blk = SQUASHFS_INVALID_BLK;
828 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
829 + if(!get_fragment_location(s, inodep->fragment, &frag_blk,
834 + i->i_size = inodep->file_size;
835 + i->i_fop = &generic_ro_fops;
836 + i->i_mode |= S_IFREG;
837 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
838 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
839 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
840 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
841 + SQUASHFS_I(i)->start_block = inodep->start_block;
842 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
843 + SQUASHFS_I(i)->offset = next_offset;
844 + i->i_data.a_ops = &squashfs_aops;
846 + TRACE("File inode %x:%x, start_block %llx, "
847 + "block_list_start %llx, offset %x\n",
848 + SQUASHFS_INODE_BLK(inode), offset,
849 + inodep->start_block, next_block,
853 + case SQUASHFS_LREG_TYPE: {
854 + unsigned int frag_size;
855 + long long frag_blk;
856 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
857 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
860 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
861 + sizeof(*sinodep), &next_block, &next_offset))
863 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
865 + if (!squashfs_get_cached_block(s, inodep, block, offset,
866 + sizeof(*inodep), &next_block, &next_offset))
869 + frag_blk = SQUASHFS_INVALID_BLK;
871 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
872 + if (!get_fragment_location(s, inodep->fragment, &frag_blk,
876 + i->i_nlink = inodep->nlink;
877 + i->i_size = inodep->file_size;
878 + i->i_fop = &generic_ro_fops;
879 + i->i_mode |= S_IFREG;
880 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
881 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
882 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
883 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
884 + SQUASHFS_I(i)->start_block = inodep->start_block;
885 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
886 + SQUASHFS_I(i)->offset = next_offset;
887 + i->i_data.a_ops = &squashfs_aops;
889 + TRACE("File inode %x:%x, start_block %llx, "
890 + "block_list_start %llx, offset %x\n",
891 + SQUASHFS_INODE_BLK(inode), offset,
892 + inodep->start_block, next_block,
896 + case SQUASHFS_DIR_TYPE: {
897 + struct squashfs_dir_inode_header *inodep = &id.dir;
898 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
901 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
902 + sizeof(*sinodep), &next_block, &next_offset))
904 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
906 + if (!squashfs_get_cached_block(s, inodep, block, offset,
907 + sizeof(*inodep), &next_block, &next_offset))
910 + i->i_nlink = inodep->nlink;
911 + i->i_size = inodep->file_size;
912 + i->i_op = &squashfs_dir_inode_ops;
913 + i->i_fop = &squashfs_dir_ops;
914 + i->i_mode |= S_IFDIR;
915 + SQUASHFS_I(i)->start_block = inodep->start_block;
916 + SQUASHFS_I(i)->offset = inodep->offset;
917 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
918 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
920 + TRACE("Directory inode %x:%x, start_block %x, offset "
921 + "%x\n", SQUASHFS_INODE_BLK(inode),
922 + offset, inodep->start_block,
926 + case SQUASHFS_LDIR_TYPE: {
927 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
928 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
931 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
932 + sizeof(*sinodep), &next_block, &next_offset))
934 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);
936 + if (!squashfs_get_cached_block(s, inodep, block, offset,
937 + sizeof(*inodep), &next_block, &next_offset))
940 + i->i_nlink = inodep->nlink;
941 + i->i_size = inodep->file_size;
942 + i->i_op = &squashfs_dir_inode_ops;
943 + i->i_fop = &squashfs_dir_ops;
944 + i->i_mode |= S_IFDIR;
945 + SQUASHFS_I(i)->start_block = inodep->start_block;
946 + SQUASHFS_I(i)->offset = inodep->offset;
947 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
948 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
949 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;
950 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
952 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n",
953 + SQUASHFS_INODE_BLK(inode), offset,
954 + inodep->start_block, inodep->offset);
957 + case SQUASHFS_SYMLINK_TYPE: {
958 + struct squashfs_symlink_inode_header *inodep = &id.symlink;
959 + struct squashfs_symlink_inode_header *sinodep = &sid.symlink;
962 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
963 + sizeof(*sinodep), &next_block, &next_offset))
965 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);
967 + if (!squashfs_get_cached_block(s, inodep, block, offset,
968 + sizeof(*inodep), &next_block, &next_offset))
971 + i->i_nlink = inodep->nlink;
972 + i->i_size = inodep->symlink_size;
973 + i->i_op = &page_symlink_inode_operations;
974 + i->i_data.a_ops = &squashfs_symlink_aops;
975 + i->i_mode |= S_IFLNK;
976 + SQUASHFS_I(i)->start_block = next_block;
977 + SQUASHFS_I(i)->offset = next_offset;
979 + TRACE("Symbolic link inode %x:%x, start_block %llx, offset %x\n",
980 + SQUASHFS_INODE_BLK(inode), offset,
981 + next_block, next_offset);
984 + case SQUASHFS_BLKDEV_TYPE:
985 + case SQUASHFS_CHRDEV_TYPE: {
986 + struct squashfs_dev_inode_header *inodep = &id.dev;
987 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
990 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
991 + sizeof(*sinodep), &next_block, &next_offset))
993 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
995 + if (!squashfs_get_cached_block(s, inodep, block, offset,
996 + sizeof(*inodep), &next_block, &next_offset))
999 + i->i_nlink = inodep->nlink;
1000 + i->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?
1001 + S_IFCHR : S_IFBLK;
1002 + init_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));
1004 + TRACE("Device inode %x:%x, rdev %x\n",
1005 + SQUASHFS_INODE_BLK(inode), offset, inodep->rdev);
1008 + case SQUASHFS_FIFO_TYPE:
1009 + case SQUASHFS_SOCKET_TYPE: {
1010 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
1011 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
1013 + if (msblk->swap) {
1014 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
1015 + sizeof(*sinodep), &next_block, &next_offset))
1017 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
1019 + if (!squashfs_get_cached_block(s, inodep, block, offset,
1020 + sizeof(*inodep), &next_block, &next_offset))
1023 + i->i_nlink = inodep->nlink;
1024 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
1025 + ? S_IFIFO : S_IFSOCK;
1026 + init_special_inode(i, i->i_mode, 0);
1030 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1031 + inodeb->inode_type);
1032 + goto failed_read1;
1038 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1041 + make_bad_inode(i);
1046 +static int read_inode_lookup_table(struct super_block *s)
1048 + struct squashfs_sb_info *msblk = s->s_fs_info;
1049 + struct squashfs_super_block *sblk = &msblk->sblk;
1050 + unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(sblk->inodes);
1052 + TRACE("In read_inode_lookup_table, length %d\n", length);
1054 + /* Allocate inode lookup table */
1055 + msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);
1056 + if (msblk->inode_lookup_table == NULL) {
1057 + ERROR("Failed to allocate inode lookup table\n");
1061 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1062 + sblk->lookup_table_start, length |
1063 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1064 + ERROR("unable to read inode lookup table\n");
1068 + if (msblk->swap) {
1072 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1074 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1075 + &msblk->inode_lookup_table[i], 1);
1076 + msblk->inode_lookup_table[i] = block;
1084 +static int read_fragment_index_table(struct super_block *s)
1086 + struct squashfs_sb_info *msblk = s->s_fs_info;
1087 + struct squashfs_super_block *sblk = &msblk->sblk;
1088 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1093 + /* Allocate fragment index table */
1094 + msblk->fragment_index = kmalloc(length, GFP_KERNEL);
1095 + if (msblk->fragment_index == NULL) {
1096 + ERROR("Failed to allocate fragment index table\n");
1100 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1101 + sblk->fragment_table_start, length |
1102 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1103 + ERROR("unable to read fragment index table\n");
1107 + if (msblk->swap) {
1109 + long long fragment;
1111 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1113 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1114 + &msblk->fragment_index[i], 1);
1115 + msblk->fragment_index[i] = fragment;
1123 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1125 + struct squashfs_super_block *sblk = &msblk->sblk;
1127 + msblk->read_inode = squashfs_read_inode;
1128 + msblk->read_blocklist = read_blocklist;
1129 + msblk->read_fragment_index_table = read_fragment_index_table;
1131 + if (sblk->s_major == 1) {
1132 + if (!squashfs_1_0_supported(msblk)) {
1133 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1134 + "are unsupported\n");
1135 + SERROR("Please recompile with Squashfs 1.0 support enabled\n");
1138 + } else if (sblk->s_major == 2) {
1139 + if (!squashfs_2_0_supported(msblk)) {
1140 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1141 + "are unsupported\n");
1142 + SERROR("Please recompile with Squashfs 2.0 support enabled\n");
1145 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1147 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1148 + "filesystem\n", sblk->s_major, sblk->s_minor);
1149 + SERROR("Please update your kernel\n");
1157 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1159 + struct squashfs_sb_info *msblk;
1160 + struct squashfs_super_block *sblk;
1161 + char b[BDEVNAME_SIZE];
1162 + struct inode *root;
1164 + TRACE("Entered squashfs_fill_superblock\n");
1166 + s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1167 + if (s->s_fs_info == NULL) {
1168 + ERROR("Failed to allocate superblock\n");
1171 + msblk = s->s_fs_info;
1173 + msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1174 + if (msblk->stream.workspace == NULL) {
1175 + ERROR("Failed to allocate zlib workspace\n");
1178 + sblk = &msblk->sblk;
1180 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1181 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1183 + mutex_init(&msblk->read_data_mutex);
1184 + mutex_init(&msblk->read_page_mutex);
1185 + mutex_init(&msblk->meta_index_mutex);
1187 + /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1188 + * beyond filesystem end. As we're using squashfs_read_data to read sblk here,
1189 + * first set sblk->bytes_used to a useful value */
1190 + sblk->bytes_used = sizeof(struct squashfs_super_block);
1191 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1192 + sizeof(struct squashfs_super_block) |
1193 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1194 + SERROR("unable to read superblock\n");
1195 + goto failed_mount;
1198 + /* Check it is a SQUASHFS superblock */
1199 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1200 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1201 + struct squashfs_super_block ssblk;
1203 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1204 + bdevname(s->s_bdev, b));
1206 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1207 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1210 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1211 + bdevname(s->s_bdev, b));
1212 + goto failed_mount;
1216 + /* Check the MAJOR & MINOR versions */
1217 + if(!supported_squashfs_filesystem(msblk, silent))
1218 + goto failed_mount;
1220 + /* Check the filesystem does not extend beyond the end of the
1222 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1223 + goto failed_mount;
1225 + /* Check the root inode for sanity */
1226 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1227 + goto failed_mount;
1229 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1230 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)
1232 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1234 + TRACE("Check data is %spresent in the filesystem\n",
1235 + SQUASHFS_CHECK_DATA(sblk->flags) ? "" : "not ");
1236 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1237 + TRACE("Block size %d\n", sblk->block_size);
1238 + TRACE("Number of inodes %d\n", sblk->inodes);
1239 + if (sblk->s_major > 1)
1240 + TRACE("Number of fragments %d\n", sblk->fragments);
1241 + TRACE("Number of uids %d\n", sblk->no_uids);
1242 + TRACE("Number of gids %d\n", sblk->no_guids);
1243 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1244 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1245 + if (sblk->s_major > 1)
1246 + TRACE("sblk->fragment_table_start %llx\n", sblk->fragment_table_start);
1247 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1249 + s->s_maxbytes = MAX_LFS_FILESIZE;
1250 + s->s_flags |= MS_RDONLY;
1251 + s->s_op = &squashfs_super_ops;
1253 + msblk->block_cache = squashfs_cache_init("metadata", SQUASHFS_CACHED_BLKS,
1254 + SQUASHFS_METADATA_SIZE, 0);
1255 + if (msblk->block_cache == NULL)
1256 + goto failed_mount;
1258 + /* Allocate read_page block */
1259 + msblk->read_page = vmalloc(sblk->block_size);
1260 + if (msblk->read_page == NULL) {
1261 + ERROR("Failed to allocate read_page block\n");
1262 + goto failed_mount;
1265 + /* Allocate uid and gid tables */
1266 + msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1267 + sizeof(unsigned int), GFP_KERNEL);
1268 + if (msblk->uid == NULL) {
1269 + ERROR("Failed to allocate uid/gid table\n");
1270 + goto failed_mount;
1272 + msblk->guid = msblk->uid + sblk->no_uids;
1274 + if (msblk->swap) {
1275 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1277 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1278 + ((sblk->no_uids + sblk->no_guids) *
1279 + sizeof(unsigned int)) |
1280 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1281 + ERROR("unable to read uid/gid table\n");
1282 + goto failed_mount;
1285 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1286 + sblk->no_guids), (sizeof(unsigned int) * 8));
1288 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1289 + ((sblk->no_uids + sblk->no_guids) *
1290 + sizeof(unsigned int)) |
1291 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1292 + ERROR("unable to read uid/gid table\n");
1293 + goto failed_mount;
1297 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1298 + goto allocate_root;
1300 + msblk->fragment_cache = squashfs_cache_init("fragment",
1301 + SQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);
1302 + if (msblk->fragment_cache == NULL)
1303 + goto failed_mount;
1305 + /* Allocate and read fragment index table */
1306 + if (msblk->read_fragment_index_table(s) == 0)
1307 + goto failed_mount;
1309 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1310 + goto allocate_root;
1312 + /* Allocate and read inode lookup table */
1313 + if (read_inode_lookup_table(s) == 0)
1314 + goto failed_mount;
1316 + s->s_export_op = &squashfs_export_ops;
1319 + root = new_inode(s);
1320 + if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1321 + goto failed_mount;
1322 + insert_inode_hash(root);
1324 + s->s_root = d_alloc_root(root);
1325 + if (s->s_root == NULL) {
1326 + ERROR("Root inode create failed\n");
1328 + goto failed_mount;
1331 + TRACE("Leaving squashfs_fill_super\n");
1335 + kfree(msblk->inode_lookup_table);
1336 + kfree(msblk->fragment_index);
1337 + squashfs_cache_delete(msblk->fragment_cache);
1338 + kfree(msblk->uid);
1339 + vfree(msblk->read_page);
1340 + squashfs_cache_delete(msblk->block_cache);
1341 + kfree(msblk->fragment_index_2);
1342 + vfree(msblk->stream.workspace);
1343 + kfree(s->s_fs_info);
1344 + s->s_fs_info = NULL;
1352 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1354 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1355 + struct squashfs_super_block *sblk = &msblk->sblk;
1357 + TRACE("Entered squashfs_statfs\n");
1359 + buf->f_type = SQUASHFS_MAGIC;
1360 + buf->f_bsize = sblk->block_size;
1361 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1362 + buf->f_bfree = buf->f_bavail = 0;
1363 + buf->f_files = sblk->inodes;
1365 + buf->f_namelen = SQUASHFS_NAME_LEN;
1371 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1373 + struct inode *inode = page->mapping->host;
1374 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;
1375 + long long block = SQUASHFS_I(inode)->start_block;
1376 + int offset = SQUASHFS_I(inode)->offset;
1377 + void *pageaddr = kmap(page);
1379 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1380 + "%llx, offset %x\n", page->index,
1381 + SQUASHFS_I(inode)->start_block,
1382 + SQUASHFS_I(inode)->offset);
1384 + for (length = 0; length < index; length += bytes) {
1385 + bytes = squashfs_get_cached_block(inode->i_sb, NULL, block,
1386 + offset, PAGE_CACHE_SIZE, &block, &offset);
1388 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1393 + if (length != index) {
1394 + ERROR("(squashfs_symlink_readpage) length != index\n");
1399 + avail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);
1401 + bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,
1402 + avail_bytes, &block, &offset);
1404 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1407 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1409 + flush_dcache_page(page);
1410 + SetPageUptodate(page);
1411 + unlock_page(page);
1417 +static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1419 + struct meta_index *meta = NULL;
1420 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1423 + mutex_lock(&msblk->meta_index_mutex);
1425 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1427 + if (msblk->meta_index == NULL)
1428 + goto not_allocated;
1430 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++) {
1431 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1432 + msblk->meta_index[i].offset >= offset &&
1433 + msblk->meta_index[i].offset <= index &&
1434 + msblk->meta_index[i].locked == 0) {
1435 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1436 + msblk->meta_index[i].offset);
1437 + meta = &msblk->meta_index[i];
1438 + offset = meta->offset;
1446 + mutex_unlock(&msblk->meta_index_mutex);
1452 +static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1454 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1455 + struct meta_index *meta = NULL;
1458 + mutex_lock(&msblk->meta_index_mutex);
1460 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1462 + if (msblk->meta_index == NULL) {
1463 + msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1464 + SQUASHFS_META_NUMBER, GFP_KERNEL);
1465 + if (msblk->meta_index == NULL) {
1466 + ERROR("Failed to allocate meta_index\n");
1469 + for (i = 0; i < SQUASHFS_META_NUMBER; i++) {
1470 + msblk->meta_index[i].inode_number = 0;
1471 + msblk->meta_index[i].locked = 0;
1473 + msblk->next_meta_index = 0;
1476 + for (i = SQUASHFS_META_NUMBER; i &&
1477 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1478 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1479 + SQUASHFS_META_NUMBER;
1482 + TRACE("empty_meta_index: failed!\n");
1486 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1487 + msblk->next_meta_index,
1488 + &msblk->meta_index[msblk->next_meta_index]);
1490 + meta = &msblk->meta_index[msblk->next_meta_index];
1491 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1492 + SQUASHFS_META_NUMBER;
1494 + meta->inode_number = inode->i_ino;
1495 + meta->offset = offset;
1496 + meta->skip = skip;
1497 + meta->entries = 0;
1501 + mutex_unlock(&msblk->meta_index_mutex);
1506 +static void release_meta_index(struct inode *inode, struct meta_index *meta)
1513 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1514 + long long *start_block, int *offset)
1516 + struct squashfs_sb_info *msblk = s->s_fs_info;
1517 + unsigned int *block_listp;
1520 + if (msblk->swap) {
1521 + char sblock_list[blocks << 2];
1523 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1524 + *offset, blocks << 2, start_block, offset)) {
1525 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1528 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1529 + ((unsigned int *)sblock_list), blocks);
1531 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1532 + *offset, blocks << 2, start_block, offset)) {
1533 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1538 + for (block_listp = (unsigned int *) block_list; blocks;
1539 + block_listp++, blocks --)
1540 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1551 +static inline int calculate_skip(int blocks) {
1552 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1553 + return skip >= 7 ? 7 : skip + 1;
1557 +static int get_meta_index(struct inode *inode, int index,
1558 + long long *index_block, int *index_offset,
1559 + long long *data_block, char *block_list)
1561 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1562 + struct squashfs_super_block *sblk = &msblk->sblk;
1563 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1565 + struct meta_index *meta;
1566 + struct meta_entry *meta_entry;
1567 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1568 + int cur_offset = SQUASHFS_I(inode)->offset;
1569 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1572 + index /= SQUASHFS_META_INDEXES * skip;
1574 + while (offset < index) {
1575 + meta = locate_meta_index(inode, index, offset + 1);
1577 + if (meta == NULL) {
1578 + meta = empty_meta_index(inode, offset + 1, skip);
1582 + if(meta->entries == 0)
1585 + offset = index < meta->offset + meta->entries ? index :
1586 + meta->offset + meta->entries - 1;
1588 + meta_entry = &meta->meta_entry[offset - meta->offset];
1589 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1590 + cur_offset = meta_entry->offset;
1591 + cur_data_block = meta_entry->data_block;
1592 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1593 + "meta->entries %d\n", offset, meta->offset, meta->entries);
1594 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1595 + " data_block 0x%llx\n", cur_index_block,
1596 + cur_offset, cur_data_block);
1599 + for (i = meta->offset + meta->entries; i <= index &&
1600 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1601 + int blocks = skip * SQUASHFS_META_INDEXES;
1604 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;
1605 + int res = read_block_index(inode->i_sb, block, block_list,
1606 + &cur_index_block, &cur_offset);
1611 + cur_data_block += res;
1615 + meta_entry = &meta->meta_entry[i - meta->offset];
1616 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1617 + meta_entry->offset = cur_offset;
1618 + meta_entry->data_block = cur_data_block;
1623 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1624 + meta->offset, meta->entries);
1626 + release_meta_index(inode, meta);
1630 + *index_block = cur_index_block;
1631 + *index_offset = cur_offset;
1632 + *data_block = cur_data_block;
1634 + return offset * SQUASHFS_META_INDEXES * skip;
1637 + release_meta_index(inode, meta);
1642 +static long long read_blocklist(struct inode *inode, int index,
1643 + int readahead_blks, char *block_list,
1644 + unsigned short **block_p, unsigned int *bsize)
1646 + long long block_ptr;
1649 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1652 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1653 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset, block);
1661 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1662 + int res = read_block_index(inode->i_sb, blocks, block_list,
1663 + &block_ptr, &offset);
1670 + if (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)
1672 + *bsize = *((unsigned int *) block_list);
1681 +static int squashfs_readpage(struct file *file, struct page *page)
1683 + struct inode *inode = page->mapping->host;
1684 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1685 + struct squashfs_super_block *sblk = &msblk->sblk;
1686 + unsigned char *block_list = NULL;
1688 + unsigned int bsize, i;
1690 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1692 + struct squashfs_cache_entry *fragment = NULL;
1693 + char *data_ptr = msblk->read_page;
1695 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1696 + int start_index = page->index & ~mask;
1697 + int end_index = start_index | mask;
1698 + int file_end = i_size_read(inode) >> sblk->block_log;
1701 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1702 + page->index, SQUASHFS_I(inode)->start_block);
1704 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1705 + PAGE_CACHE_SHIFT))
1708 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1709 + || index < file_end) {
1710 + block_list = kmalloc(SIZE, GFP_KERNEL);
1711 + if (block_list == NULL) {
1712 + ERROR("Failed to allocate block_list\n");
1716 + block = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);
1720 + if (bsize == 0) { /* hole */
1721 + bytes = index == file_end ?
1722 + (i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;
1725 + mutex_lock(&msblk->read_page_mutex);
1727 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1728 + bsize, NULL, sblk->block_size);
1731 + ERROR("Unable to read page, block %llx, size %x\n", block, bsize);
1732 + mutex_unlock(&msblk->read_page_mutex);
1737 + fragment = get_cached_fragment(inode->i_sb,
1738 + SQUASHFS_I(inode)-> u.s1.fragment_start_block,
1739 + SQUASHFS_I(inode)->u.s1.fragment_size);
1741 + if (fragment->error) {
1742 + ERROR("Unable to read page, block %llx, size %x\n",
1743 + SQUASHFS_I(inode)->u.s1.fragment_start_block,
1744 + (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1745 + release_cached_fragment(msblk, fragment);
1748 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1749 + data_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;
1752 + for (i = start_index; i <= end_index && bytes > 0; i++,
1753 + bytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {
1754 + struct page *push_page;
1755 + int avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);
1757 + TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
1759 + push_page = (i == page->index) ? page :
1760 + grab_cache_page_nowait(page->mapping, i);
1765 + if (PageUptodate(push_page))
1768 + pageaddr = kmap_atomic(push_page, KM_USER0);
1769 + memcpy(pageaddr, data_ptr, avail);
1770 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1771 + kunmap_atomic(pageaddr, KM_USER0);
1772 + flush_dcache_page(push_page);
1773 + SetPageUptodate(push_page);
1775 + unlock_page(push_page);
1776 + if(i != page->index)
1777 + page_cache_release(push_page);
1780 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1781 + || index < file_end) {
1783 + mutex_unlock(&msblk->read_page_mutex);
1784 + kfree(block_list);
1786 + release_cached_fragment(msblk, fragment);
1791 + SetPageError(page);
1793 + pageaddr = kmap_atomic(page, KM_USER0);
1794 + memset(pageaddr, 0, PAGE_CACHE_SIZE);
1795 + kunmap_atomic(pageaddr, KM_USER0);
1796 + flush_dcache_page(page);
1797 + if (!PageError(page))
1798 + SetPageUptodate(page);
1799 + unlock_page(page);
1801 + kfree(block_list);
1806 +static int get_dir_index_using_offset(struct super_block *s,
1807 + long long *next_block, unsigned int *next_offset,
1808 + long long index_start, unsigned int index_offset, int i_count,
1811 + struct squashfs_sb_info *msblk = s->s_fs_info;
1812 + struct squashfs_super_block *sblk = &msblk->sblk;
1813 + int i, length = 0;
1814 + struct squashfs_dir_index index;
1816 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1817 + i_count, (unsigned int) f_pos);
1823 + for (i = 0; i < i_count; i++) {
1824 + if (msblk->swap) {
1825 + struct squashfs_dir_index sindex;
1826 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1827 + sizeof(sindex), &index_start, &index_offset);
1828 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1830 + squashfs_get_cached_block(s, &index, index_start, index_offset,
1831 + sizeof(index), &index_start, &index_offset);
1833 + if (index.index > f_pos)
1836 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1837 + index.size + 1, &index_start, &index_offset);
1839 + length = index.index;
1840 + *next_block = index.start_block + sblk->directory_table_start;
1843 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1846 + return length + 3;
1850 +static int get_dir_index_using_name(struct super_block *s,
1851 + long long *next_block, unsigned int *next_offset,
1852 + long long index_start, unsigned int index_offset, int i_count,
1853 + const char *name, int size)
1855 + struct squashfs_sb_info *msblk = s->s_fs_info;
1856 + struct squashfs_super_block *sblk = &msblk->sblk;
1857 + int i, length = 0;
1858 + struct squashfs_dir_index *index;
1861 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1863 + str = kmalloc(sizeof(struct squashfs_dir_index) +
1864 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);
1865 + if (str == NULL) {
1866 + ERROR("Failed to allocate squashfs_dir_index\n");
1870 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1871 + strncpy(str, name, size);
1874 + for (i = 0; i < i_count; i++) {
1875 + if (msblk->swap) {
1876 + struct squashfs_dir_index sindex;
1877 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1878 + sizeof(sindex), &index_start, &index_offset);
1879 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1881 + squashfs_get_cached_block(s, index, index_start, index_offset,
1882 + sizeof(struct squashfs_dir_index), &index_start, &index_offset);
1884 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1885 + index->size + 1, &index_start, &index_offset);
1887 + index->name[index->size + 1] = '\0';
1889 + if (strcmp(index->name, str) > 0)
1892 + length = index->index;
1893 + *next_block = index->start_block + sblk->directory_table_start;
1896 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1900 + return length + 3;
1904 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1906 + struct inode *i = file->f_dentry->d_inode;
1907 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1908 + struct squashfs_super_block *sblk = &msblk->sblk;
1909 + long long next_block = SQUASHFS_I(i)->start_block +
1910 + sblk->directory_table_start;
1911 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
1912 + struct squashfs_dir_header dirh;
1913 + struct squashfs_dir_entry *dire;
1915 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1917 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1918 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
1919 + if (dire == NULL) {
1920 + ERROR("Failed to allocate squashfs_dir_entry\n");
1924 + while(file->f_pos < 3) {
1928 + if(file->f_pos == 0) {
1935 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1937 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1938 + (unsigned int) dirent, name, size, (int)
1939 + file->f_pos, i_ino, squashfs_filetype_table[1]);
1941 + if (filldir(dirent, name, size, file->f_pos, i_ino,
1942 + squashfs_filetype_table[1]) < 0) {
1943 + TRACE("Filldir returned less than 0\n");
1946 + file->f_pos += size;
1949 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1950 + SQUASHFS_I(i)->u.s2.directory_index_start,
1951 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1952 + SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1954 + while (length < i_size_read(i)) {
1955 + /* read directory header */
1956 + if (msblk->swap) {
1957 + struct squashfs_dir_header sdirh;
1959 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
1960 + next_offset, sizeof(sdirh), &next_block, &next_offset))
1963 + length += sizeof(sdirh);
1964 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1966 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
1967 + next_offset, sizeof(dirh), &next_block, &next_offset))
1970 + length += sizeof(dirh);
1973 + dir_count = dirh.count + 1;
1974 + while (dir_count--) {
1975 + if (msblk->swap) {
1976 + struct squashfs_dir_entry sdire;
1977 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
1978 + next_offset, sizeof(sdire), &next_block, &next_offset))
1981 + length += sizeof(sdire);
1982 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1984 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
1985 + next_offset, sizeof(*dire), &next_block, &next_offset))
1988 + length += sizeof(*dire);
1991 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
1992 + next_offset, dire->size + 1, &next_block, &next_offset))
1995 + length += dire->size + 1;
1997 + if (file->f_pos >= length)
2000 + dire->name[dire->size + 1] = '\0';
2002 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2003 + (unsigned int) dirent, dire->name, dire->size + 1,
2004 + (int) file->f_pos, dirh.start_block, dire->offset,
2005 + dirh.inode_number + dire->inode_number,
2006 + squashfs_filetype_table[dire->type]);
2008 + if (filldir(dirent, dire->name, dire->size + 1, file->f_pos,
2009 + dirh.inode_number + dire->inode_number,
2010 + squashfs_filetype_table[dire->type]) < 0) {
2011 + TRACE("Filldir returned less than 0\n");
2014 + file->f_pos = length;
2023 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2030 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2031 + struct nameidata *nd)
2033 + const unsigned char *name = dentry->d_name.name;
2034 + int len = dentry->d_name.len;
2035 + struct inode *inode = NULL;
2036 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2037 + struct squashfs_super_block *sblk = &msblk->sblk;
2038 + long long next_block = SQUASHFS_I(i)->start_block +
2039 + sblk->directory_table_start;
2040 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
2041 + struct squashfs_dir_header dirh;
2042 + struct squashfs_dir_entry *dire;
2044 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2046 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2047 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
2048 + if (dire == NULL) {
2049 + ERROR("Failed to allocate squashfs_dir_entry\n");
2053 + if (len > SQUASHFS_NAME_LEN)
2056 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2057 + SQUASHFS_I(i)->u.s2.directory_index_start,
2058 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2059 + SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
2061 + while (length < i_size_read(i)) {
2062 + /* read directory header */
2063 + if (msblk->swap) {
2064 + struct squashfs_dir_header sdirh;
2065 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
2066 + next_offset, sizeof(sdirh), &next_block, &next_offset))
2069 + length += sizeof(sdirh);
2070 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2072 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2073 + next_offset, sizeof(dirh), &next_block, &next_offset))
2076 + length += sizeof(dirh);
2079 + dir_count = dirh.count + 1;
2080 + while (dir_count--) {
2081 + if (msblk->swap) {
2082 + struct squashfs_dir_entry sdire;
2083 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2084 + next_offset, sizeof(sdire), &next_block, &next_offset))
2087 + length += sizeof(sdire);
2088 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2090 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2091 + next_offset, sizeof(*dire), &next_block, &next_offset))
2094 + length += sizeof(*dire);
2097 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2098 + next_offset, dire->size + 1, &next_block, &next_offset))
2101 + length += dire->size + 1;
2103 + if (name[0] < dire->name[0])
2106 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2107 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2110 + TRACE("calling squashfs_iget for directory entry %s, inode"
2111 + " %x:%x, %d\n", name, dirh.start_block, dire->offset,
2112 + dirh.inode_number + dire->inode_number);
2114 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2124 + return d_splice_alias(inode, dentry);
2125 + d_add(dentry, inode);
2126 + return ERR_PTR(0);
2129 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2135 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
2137 + *flags |= MS_RDONLY;
2142 +static void squashfs_put_super(struct super_block *s)
2144 + if (s->s_fs_info) {
2145 + struct squashfs_sb_info *sbi = s->s_fs_info;
2146 + squashfs_cache_delete(sbi->block_cache);
2147 + squashfs_cache_delete(sbi->fragment_cache);
2148 + vfree(sbi->read_page);
2150 + kfree(sbi->fragment_index);
2151 + kfree(sbi->fragment_index_2);
2152 + kfree(sbi->meta_index);
2153 + vfree(sbi->stream.workspace);
2154 + kfree(s->s_fs_info);
2155 + s->s_fs_info = NULL;
2160 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2161 + const char *dev_name, void *data, struct vfsmount *mnt)
2163 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2168 +static int __init init_squashfs_fs(void)
2170 + int err = init_inodecache();
2174 + printk(KERN_INFO "squashfs: version 3.4 (2008/08/26) "
2175 + "Phillip Lougher\n");
2177 + err = register_filesystem(&squashfs_fs_type);
2179 + destroy_inodecache();
2186 +static void __exit exit_squashfs_fs(void)
2188 + unregister_filesystem(&squashfs_fs_type);
2189 + destroy_inodecache();
2193 +static struct kmem_cache * squashfs_inode_cachep;
2196 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2198 + struct squashfs_inode_info *ei;
2199 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2200 + return ei ? &ei->vfs_inode : NULL;
2204 +static void squashfs_destroy_inode(struct inode *inode)
2206 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2210 +static void init_once(void *foo)
2212 + struct squashfs_inode_info *ei = foo;
2214 + inode_init_once(&ei->vfs_inode);
2218 +static int __init init_inodecache(void)
2220 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2221 + sizeof(struct squashfs_inode_info), 0,
2222 + SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);
2223 + if (squashfs_inode_cachep == NULL)
2229 +static void destroy_inodecache(void)
2231 + kmem_cache_destroy(squashfs_inode_cachep);
2235 +module_init(init_squashfs_fs);
2236 +module_exit(exit_squashfs_fs);
2237 +MODULE_DESCRIPTION("squashfs 3.4, a compressed read-only filesystem");
2238 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2239 +MODULE_LICENSE("GPL");
2241 +++ kernel-power-2.6.28/fs/squashfs/squashfs.h
2244 + * Squashfs - a compressed read only filesystem for Linux
2246 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
2247 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2249 + * This program is free software; you can redistribute it and/or
2250 + * modify it under the terms of the GNU General Public License
2251 + * as published by the Free Software Foundation; either version 2,
2252 + * or (at your option) any later version.
2254 + * This program is distributed in the hope that it will be useful,
2255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2257 + * GNU General Public License for more details.
2259 + * You should have received a copy of the GNU General Public License
2260 + * along with this program; if not, write to the Free Software
2261 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2266 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2267 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2270 +#ifdef SQUASHFS_TRACE
2271 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
2273 +#define TRACE(s, args...) {}
2276 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
2278 +#define SERROR(s, args...) do { \
2280 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
2283 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
2285 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
2287 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
2290 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
2291 +#define SQSH_EXTERN
2292 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
2293 + long long index, unsigned int length,
2294 + long long *next_index, int srclength);
2295 +extern int squashfs_get_cached_block(struct super_block *s, void *buffer,
2296 + long long block, unsigned int offset,
2297 + int length, long long *next_block,
2298 + unsigned int *next_offset);
2299 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
2300 + squashfs_cache_entry *fragment);
2301 +extern struct squashfs_cache_entry *get_cached_fragment(struct super_block
2302 + *s, long long start_block,
2304 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
2305 +extern const struct address_space_operations squashfs_symlink_aops;
2306 +extern const struct address_space_operations squashfs_aops;
2307 +extern struct inode_operations squashfs_dir_inode_ops;
2309 +#define SQSH_EXTERN static
2312 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2313 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
2315 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
2321 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2322 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
2324 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2330 +++ kernel-power-2.6.28/fs/squashfs/squashfs2_0.c
2333 + * Squashfs - a compressed read only filesystem for Linux
2335 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
2336 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2338 + * This program is free software; you can redistribute it and/or
2339 + * modify it under the terms of the GNU General Public License
2340 + * as published by the Free Software Foundation; either version 2,
2341 + * or (at your option) any later version.
2343 + * This program is distributed in the hope that it will be useful,
2344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2346 + * GNU General Public License for more details.
2348 + * You should have received a copy of the GNU General Public License
2349 + * along with this program; if not, write to the Free Software
2350 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2355 +#include <linux/squashfs_fs.h>
2356 +#include <linux/module.h>
2357 +#include <linux/zlib.h>
2358 +#include <linux/fs.h>
2359 +#include <linux/squashfs_fs_sb.h>
2360 +#include <linux/squashfs_fs_i.h>
2362 +#include "squashfs.h"
2363 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2364 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2365 + struct nameidata *);
2367 +static struct file_operations squashfs_dir_ops_2 = {
2368 + .read = generic_read_dir,
2369 + .readdir = squashfs_readdir_2
2372 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2373 + .lookup = squashfs_lookup_2
2376 +static unsigned char squashfs_filetype_table[] = {
2377 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2380 +static int read_fragment_index_table_2(struct super_block *s)
2382 + struct squashfs_sb_info *msblk = s->s_fs_info;
2383 + struct squashfs_super_block *sblk = &msblk->sblk;
2385 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2386 + (sblk->fragments), GFP_KERNEL))) {
2387 + ERROR("Failed to allocate uid/gid table\n");
2391 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2392 + !squashfs_read_data(s, (char *)
2393 + msblk->fragment_index_2,
2394 + sblk->fragment_table_start,
2395 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2396 + (sblk->fragments) |
2397 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2398 + ERROR("unable to read fragment index table\n");
2402 + if (msblk->swap) {
2404 + unsigned int fragment;
2406 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2408 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2409 + &msblk->fragment_index_2[i], 1);
2410 + msblk->fragment_index_2[i] = fragment;
2418 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2419 + long long *fragment_start_block,
2420 + unsigned int *fragment_size)
2422 + struct squashfs_sb_info *msblk = s->s_fs_info;
2423 + long long start_block =
2424 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2425 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2426 + struct squashfs_fragment_entry_2 fragment_entry;
2428 + if (msblk->swap) {
2429 + struct squashfs_fragment_entry_2 sfragment_entry;
2431 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2432 + start_block, offset,
2433 + sizeof(sfragment_entry), &start_block,
2436 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2438 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2439 + start_block, offset,
2440 + sizeof(fragment_entry), &start_block,
2444 + *fragment_start_block = fragment_entry.start_block;
2445 + *fragment_size = fragment_entry.size;
2454 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2455 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2457 + struct squashfs_super_block *sblk = &msblk->sblk;
2460 + i->i_mtime.tv_sec = sblk->mkfs_time;
2461 + i->i_atime.tv_sec = sblk->mkfs_time;
2462 + i->i_ctime.tv_sec = sblk->mkfs_time;
2463 + i->i_uid = msblk->uid[inodeb->uid];
2464 + i->i_mode = inodeb->mode;
2467 + if (inodeb->guid == SQUASHFS_GUIDS)
2468 + i->i_gid = i->i_uid;
2470 + i->i_gid = msblk->guid[inodeb->guid];
2474 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2476 + struct super_block *s = i->i_sb;
2477 + struct squashfs_sb_info *msblk = s->s_fs_info;
2478 + struct squashfs_super_block *sblk = &msblk->sblk;
2479 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2480 + sblk->inode_table_start;
2481 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2482 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block -
2483 + sblk->inode_table_start, offset);
2484 + long long next_block;
2485 + unsigned int next_offset;
2486 + union squashfs_inode_header_2 id, sid;
2487 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2488 + *sinodeb = &sid.base;
2490 + TRACE("Entered squashfs_read_inode_2\n");
2492 + if (msblk->swap) {
2493 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2494 + offset, sizeof(*sinodeb), &next_block,
2497 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2498 + sizeof(*sinodeb));
2500 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2501 + offset, sizeof(*inodeb), &next_block,
2505 + squashfs_new_inode(msblk, i, inodeb, ino);
2507 + switch(inodeb->inode_type) {
2508 + case SQUASHFS_FILE_TYPE: {
2509 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2510 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2511 + long long frag_blk;
2512 + unsigned int frag_size = 0;
2514 + if (msblk->swap) {
2515 + if (!squashfs_get_cached_block(s, (char *)
2516 + sinodep, block, offset,
2517 + sizeof(*sinodep), &next_block,
2520 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2522 + if (!squashfs_get_cached_block(s, (char *)
2523 + inodep, block, offset,
2524 + sizeof(*inodep), &next_block,
2528 + frag_blk = SQUASHFS_INVALID_BLK;
2529 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2530 + !get_fragment_location_2(s,
2531 + inodep->fragment, &frag_blk, &frag_size))
2534 + i->i_size = inodep->file_size;
2535 + i->i_fop = &generic_ro_fops;
2536 + i->i_mode |= S_IFREG;
2537 + i->i_mtime.tv_sec = inodep->mtime;
2538 + i->i_atime.tv_sec = inodep->mtime;
2539 + i->i_ctime.tv_sec = inodep->mtime;
2540 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2541 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2542 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2543 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2544 + SQUASHFS_I(i)->start_block = inodep->start_block;
2545 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2546 + SQUASHFS_I(i)->offset = next_offset;
2547 + i->i_data.a_ops = &squashfs_aops;
2549 + TRACE("File inode %x:%x, start_block %x, "
2550 + "block_list_start %llx, offset %x\n",
2551 + SQUASHFS_INODE_BLK(inode), offset,
2552 + inodep->start_block, next_block,
2556 + case SQUASHFS_DIR_TYPE: {
2557 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2558 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2560 + if (msblk->swap) {
2561 + if (!squashfs_get_cached_block(s, (char *)
2562 + sinodep, block, offset,
2563 + sizeof(*sinodep), &next_block,
2566 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2568 + if (!squashfs_get_cached_block(s, (char *)
2569 + inodep, block, offset,
2570 + sizeof(*inodep), &next_block,
2574 + i->i_size = inodep->file_size;
2575 + i->i_op = &squashfs_dir_inode_ops_2;
2576 + i->i_fop = &squashfs_dir_ops_2;
2577 + i->i_mode |= S_IFDIR;
2578 + i->i_mtime.tv_sec = inodep->mtime;
2579 + i->i_atime.tv_sec = inodep->mtime;
2580 + i->i_ctime.tv_sec = inodep->mtime;
2581 + SQUASHFS_I(i)->start_block = inodep->start_block;
2582 + SQUASHFS_I(i)->offset = inodep->offset;
2583 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2584 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2586 + TRACE("Directory inode %x:%x, start_block %x, offset "
2587 + "%x\n", SQUASHFS_INODE_BLK(inode),
2588 + offset, inodep->start_block,
2592 + case SQUASHFS_LDIR_TYPE: {
2593 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2594 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2596 + if (msblk->swap) {
2597 + if (!squashfs_get_cached_block(s, (char *)
2598 + sinodep, block, offset,
2599 + sizeof(*sinodep), &next_block,
2602 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + inodep, block, offset,
2607 + sizeof(*inodep), &next_block,
2611 + i->i_size = inodep->file_size;
2612 + i->i_op = &squashfs_dir_inode_ops_2;
2613 + i->i_fop = &squashfs_dir_ops_2;
2614 + i->i_mode |= S_IFDIR;
2615 + i->i_mtime.tv_sec = inodep->mtime;
2616 + i->i_atime.tv_sec = inodep->mtime;
2617 + i->i_ctime.tv_sec = inodep->mtime;
2618 + SQUASHFS_I(i)->start_block = inodep->start_block;
2619 + SQUASHFS_I(i)->offset = inodep->offset;
2620 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2621 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2623 + SQUASHFS_I(i)->u.s2.directory_index_count =
2625 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2627 + TRACE("Long directory inode %x:%x, start_block %x, "
2629 + SQUASHFS_INODE_BLK(inode), offset,
2630 + inodep->start_block, inodep->offset);
2633 + case SQUASHFS_SYMLINK_TYPE: {
2634 + struct squashfs_symlink_inode_header_2 *inodep =
2636 + struct squashfs_symlink_inode_header_2 *sinodep =
2639 + if (msblk->swap) {
2640 + if (!squashfs_get_cached_block(s, (char *)
2641 + sinodep, block, offset,
2642 + sizeof(*sinodep), &next_block,
2645 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2648 + if (!squashfs_get_cached_block(s, (char *)
2649 + inodep, block, offset,
2650 + sizeof(*inodep), &next_block,
2654 + i->i_size = inodep->symlink_size;
2655 + i->i_op = &page_symlink_inode_operations;
2656 + i->i_data.a_ops = &squashfs_symlink_aops;
2657 + i->i_mode |= S_IFLNK;
2658 + SQUASHFS_I(i)->start_block = next_block;
2659 + SQUASHFS_I(i)->offset = next_offset;
2661 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2663 + SQUASHFS_INODE_BLK(inode), offset,
2664 + next_block, next_offset);
2667 + case SQUASHFS_BLKDEV_TYPE:
2668 + case SQUASHFS_CHRDEV_TYPE: {
2669 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2670 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2672 + if (msblk->swap) {
2673 + if (!squashfs_get_cached_block(s, (char *)
2674 + sinodep, block, offset,
2675 + sizeof(*sinodep), &next_block,
2678 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2680 + if (!squashfs_get_cached_block(s, (char *)
2681 + inodep, block, offset,
2682 + sizeof(*inodep), &next_block,
2686 + i->i_mode |= (inodeb->inode_type ==
2687 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2689 + init_special_inode(i, i->i_mode,
2690 + old_decode_dev(inodep->rdev));
2692 + TRACE("Device inode %x:%x, rdev %x\n",
2693 + SQUASHFS_INODE_BLK(inode), offset,
2697 + case SQUASHFS_FIFO_TYPE:
2698 + case SQUASHFS_SOCKET_TYPE: {
2700 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2701 + ? S_IFIFO : S_IFSOCK;
2702 + init_special_inode(i, i->i_mode, 0);
2706 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2707 + inodeb->inode_type);
2708 + goto failed_read1;
2714 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2721 +static int get_dir_index_using_offset(struct super_block *s, long long
2722 + *next_block, unsigned int *next_offset,
2723 + long long index_start,
2724 + unsigned int index_offset, int i_count,
2727 + struct squashfs_sb_info *msblk = s->s_fs_info;
2728 + struct squashfs_super_block *sblk = &msblk->sblk;
2729 + int i, length = 0;
2730 + struct squashfs_dir_index_2 index;
2732 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2733 + i_count, (unsigned int) f_pos);
2738 + for (i = 0; i < i_count; i++) {
2739 + if (msblk->swap) {
2740 + struct squashfs_dir_index_2 sindex;
2741 + squashfs_get_cached_block(s, (char *) &sindex,
2742 + index_start, index_offset,
2743 + sizeof(sindex), &index_start,
2745 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2747 + squashfs_get_cached_block(s, (char *) &index,
2748 + index_start, index_offset,
2749 + sizeof(index), &index_start,
2752 + if (index.index > f_pos)
2755 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2756 + index.size + 1, &index_start,
2759 + length = index.index;
2760 + *next_block = index.start_block + sblk->directory_table_start;
2763 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2770 +static int get_dir_index_using_name(struct super_block *s, long long
2771 + *next_block, unsigned int *next_offset,
2772 + long long index_start,
2773 + unsigned int index_offset, int i_count,
2774 + const char *name, int size)
2776 + struct squashfs_sb_info *msblk = s->s_fs_info;
2777 + struct squashfs_super_block *sblk = &msblk->sblk;
2778 + int i, length = 0;
2779 + struct squashfs_dir_index_2 *index;
2782 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2784 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2785 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2786 + ERROR("Failed to allocate squashfs_dir_index\n");
2790 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2791 + strncpy(str, name, size);
2794 + for (i = 0; i < i_count; i++) {
2795 + if (msblk->swap) {
2796 + struct squashfs_dir_index_2 sindex;
2797 + squashfs_get_cached_block(s, (char *) &sindex,
2798 + index_start, index_offset,
2799 + sizeof(sindex), &index_start,
2801 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2803 + squashfs_get_cached_block(s, (char *) index,
2804 + index_start, index_offset,
2805 + sizeof(struct squashfs_dir_index_2),
2806 + &index_start, &index_offset);
2808 + squashfs_get_cached_block(s, index->name, index_start,
2809 + index_offset, index->size + 1,
2810 + &index_start, &index_offset);
2812 + index->name[index->size + 1] = '\0';
2814 + if (strcmp(index->name, str) > 0)
2817 + length = index->index;
2818 + *next_block = index->start_block + sblk->directory_table_start;
2821 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2828 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2830 + struct inode *i = file->f_dentry->d_inode;
2831 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2832 + struct squashfs_super_block *sblk = &msblk->sblk;
2833 + long long next_block = SQUASHFS_I(i)->start_block +
2834 + sblk->directory_table_start;
2835 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2837 + struct squashfs_dir_header_2 dirh;
2838 + struct squashfs_dir_entry_2 *dire;
2840 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2842 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2843 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2844 + ERROR("Failed to allocate squashfs_dir_entry\n");
2848 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2849 + SQUASHFS_I(i)->u.s2.directory_index_start,
2850 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2851 + SQUASHFS_I(i)->u.s2.directory_index_count,
2854 + while (length < i_size_read(i)) {
2855 + /* read directory header */
2856 + if (msblk->swap) {
2857 + struct squashfs_dir_header_2 sdirh;
2859 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2860 + next_block, next_offset, sizeof(sdirh),
2861 + &next_block, &next_offset))
2864 + length += sizeof(sdirh);
2865 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2867 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2868 + next_block, next_offset, sizeof(dirh),
2869 + &next_block, &next_offset))
2872 + length += sizeof(dirh);
2875 + dir_count = dirh.count + 1;
2876 + while (dir_count--) {
2877 + if (msblk->swap) {
2878 + struct squashfs_dir_entry_2 sdire;
2879 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2880 + &sdire, next_block, next_offset,
2881 + sizeof(sdire), &next_block,
2885 + length += sizeof(sdire);
2886 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2888 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2889 + dire, next_block, next_offset,
2890 + sizeof(*dire), &next_block,
2894 + length += sizeof(*dire);
2897 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2898 + next_block, next_offset,
2899 + dire->size + 1, &next_block,
2903 + length += dire->size + 1;
2905 + if (file->f_pos >= length)
2908 + dire->name[dire->size + 1] = '\0';
2910 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2911 + (unsigned int) dirent, dire->name,
2912 + dire->size + 1, (int) file->f_pos,
2913 + dirh.start_block, dire->offset,
2914 + squashfs_filetype_table[dire->type]);
2916 + if (filldir(dirent, dire->name, dire->size + 1,
2917 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2918 + dirh.start_block, dire->offset),
2919 + squashfs_filetype_table[dire->type])
2921 + TRACE("Filldir returned less than 0\n");
2924 + file->f_pos = length;
2933 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2940 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2941 + struct nameidata *nd)
2943 + const unsigned char *name = dentry->d_name.name;
2944 + int len = dentry->d_name.len;
2945 + struct inode *inode = NULL;
2946 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2947 + struct squashfs_super_block *sblk = &msblk->sblk;
2948 + long long next_block = SQUASHFS_I(i)->start_block +
2949 + sblk->directory_table_start;
2950 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2952 + struct squashfs_dir_header_2 dirh;
2953 + struct squashfs_dir_entry_2 *dire;
2954 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2956 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2958 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2959 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2960 + ERROR("Failed to allocate squashfs_dir_entry\n");
2964 + if (len > SQUASHFS_NAME_LEN)
2967 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2968 + SQUASHFS_I(i)->u.s2.directory_index_start,
2969 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2970 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2973 + while (length < i_size_read(i)) {
2974 + /* read directory header */
2975 + if (msblk->swap) {
2976 + struct squashfs_dir_header_2 sdirh;
2977 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2978 + next_block, next_offset, sizeof(sdirh),
2979 + &next_block, &next_offset))
2982 + length += sizeof(sdirh);
2983 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2985 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2986 + next_block, next_offset, sizeof(dirh),
2987 + &next_block, &next_offset))
2990 + length += sizeof(dirh);
2993 + dir_count = dirh.count + 1;
2994 + while (dir_count--) {
2995 + if (msblk->swap) {
2996 + struct squashfs_dir_entry_2 sdire;
2997 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2998 + &sdire, next_block,next_offset,
2999 + sizeof(sdire), &next_block,
3003 + length += sizeof(sdire);
3004 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
3006 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3007 + dire, next_block,next_offset,
3008 + sizeof(*dire), &next_block,
3012 + length += sizeof(*dire);
3015 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
3016 + next_block, next_offset, dire->size + 1,
3017 + &next_block, &next_offset))
3020 + length += dire->size + 1;
3022 + if (sorted && name[0] < dire->name[0])
3025 + if ((len == dire->size + 1) && !strncmp(name,
3026 + dire->name, len)) {
3027 + squashfs_inode_t ino =
3028 + SQUASHFS_MKINODE(dirh.start_block,
3030 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
3033 + TRACE("calling squashfs_iget for directory "
3034 + "entry %s, inode %x:%x, %lld\n", name,
3035 + dirh.start_block, dire->offset, ino);
3037 + inode = squashfs_iget(i->i_sb, ino, inode_number);
3046 + d_add(dentry, inode);
3047 + return ERR_PTR(0);
3050 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3056 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3058 + struct squashfs_super_block *sblk = &msblk->sblk;
3060 + msblk->read_inode = squashfs_read_inode_2;
3061 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3063 + sblk->bytes_used = sblk->bytes_used_2;
3064 + sblk->uid_start = sblk->uid_start_2;
3065 + sblk->guid_start = sblk->guid_start_2;
3066 + sblk->inode_table_start = sblk->inode_table_start_2;
3067 + sblk->directory_table_start = sblk->directory_table_start_2;
3068 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3073 +++ kernel-power-2.6.28/include/linux/squashfs_fs.h
3075 +#ifndef SQUASHFS_FS
3076 +#define SQUASHFS_FS
3081 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
3082 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3084 + * This program is free software; you can redistribute it and/or
3085 + * modify it under the terms of the GNU General Public License
3086 + * as published by the Free Software Foundation; either version 2,
3087 + * or (at your option) any later version.
3089 + * This program is distributed in the hope that it will be useful,
3090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3092 + * GNU General Public License for more details.
3094 + * You should have received a copy of the GNU General Public License
3095 + * along with this program; if not, write to the Free Software
3096 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3101 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3102 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3105 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3106 +#define SQUASHFS_MAJOR 3
3107 +#define SQUASHFS_MINOR 1
3108 +#define SQUASHFS_MAGIC 0x73717368
3109 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3110 +#define SQUASHFS_START 0
3112 +/* size of metadata (inode and directory) blocks */
3113 +#define SQUASHFS_METADATA_SIZE 8192
3114 +#define SQUASHFS_METADATA_LOG 13
3116 +/* default size of data blocks */
3117 +#define SQUASHFS_FILE_SIZE 131072
3118 +#define SQUASHFS_FILE_LOG 17
3120 +#define SQUASHFS_FILE_MAX_SIZE 1048576
3122 +/* Max number of uids and gids */
3123 +#define SQUASHFS_UIDS 256
3124 +#define SQUASHFS_GUIDS 255
3126 +/* Max length of filename (not 255) */
3127 +#define SQUASHFS_NAME_LEN 256
3129 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3130 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3131 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3132 +#define SQUASHFS_USED_BLK ((long long) -2)
3134 +/* Filesystem flags */
3135 +#define SQUASHFS_NOI 0
3136 +#define SQUASHFS_NOD 1
3137 +#define SQUASHFS_CHECK 2
3138 +#define SQUASHFS_NOF 3
3139 +#define SQUASHFS_NO_FRAG 4
3140 +#define SQUASHFS_ALWAYS_FRAG 5
3141 +#define SQUASHFS_DUPLICATE 6
3142 +#define SQUASHFS_EXPORT 7
3144 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3146 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3149 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3152 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3155 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3158 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3159 + SQUASHFS_ALWAYS_FRAG)
3161 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3162 + SQUASHFS_DUPLICATE)
3164 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3167 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3170 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3171 + duplicate_checking, exportable) (noi | (nod << 1) | (check_data << 2) \
3172 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3173 + (duplicate_checking << 6) | (exportable << 7))
3175 +/* Max number of types and file types */
3176 +#define SQUASHFS_DIR_TYPE 1
3177 +#define SQUASHFS_FILE_TYPE 2
3178 +#define SQUASHFS_SYMLINK_TYPE 3
3179 +#define SQUASHFS_BLKDEV_TYPE 4
3180 +#define SQUASHFS_CHRDEV_TYPE 5
3181 +#define SQUASHFS_FIFO_TYPE 6
3182 +#define SQUASHFS_SOCKET_TYPE 7
3183 +#define SQUASHFS_LDIR_TYPE 8
3184 +#define SQUASHFS_LREG_TYPE 9
3186 +/* 1.0 filesystem type definitions */
3187 +#define SQUASHFS_TYPES 5
3188 +#define SQUASHFS_IPC_TYPE 0
3190 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3192 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3194 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3195 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3197 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3199 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3201 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
3202 + ~SQUASHFS_COMPRESSED_BIT_BLOCK)
3204 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3207 + * Inode number ops. Inodes consist of a compressed block number, and an
3208 + * uncompressed offset within that block
3210 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3212 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3214 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3217 +/* Compute 32 bit VFS inode number from squashfs inode number */
3218 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3222 +/* Translate between VFS mode and squashfs mode */
3223 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3225 +/* fragment and fragment table defines */
3226 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3228 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3229 + SQUASHFS_METADATA_SIZE)
3231 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3232 + SQUASHFS_METADATA_SIZE)
3234 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3235 + SQUASHFS_METADATA_SIZE - 1) / \
3236 + SQUASHFS_METADATA_SIZE)
3238 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3239 + sizeof(long long))
3241 +/* inode lookup table defines */
3242 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3244 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3245 + SQUASHFS_METADATA_SIZE)
3247 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3248 + SQUASHFS_METADATA_SIZE)
3250 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3251 + SQUASHFS_METADATA_SIZE - 1) / \
3252 + SQUASHFS_METADATA_SIZE)
3254 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3255 + sizeof(long long))
3257 +/* cached data constants for filesystem */
3258 +#define SQUASHFS_CACHED_BLKS 8
3260 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3262 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3263 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3265 +#define SQUASHFS_MARKER_BYTE 0xff
3267 +/* meta index cache */
3268 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3269 +#define SQUASHFS_META_ENTRIES 31
3270 +#define SQUASHFS_META_NUMBER 8
3271 +#define SQUASHFS_SLOTS 4
3273 +struct meta_entry {
3274 + long long data_block;
3275 + unsigned int index_block;
3276 + unsigned short offset;
3277 + unsigned short pad;
3280 +struct meta_index {
3281 + unsigned int inode_number;
3282 + unsigned int offset;
3283 + unsigned short entries;
3284 + unsigned short skip;
3285 + unsigned short locked;
3286 + unsigned short pad;
3287 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3292 + * definitions for structures on disk
3295 +typedef long long squashfs_block_t;
3296 +typedef long long squashfs_inode_t;
3298 +struct squashfs_super_block {
3299 + unsigned int s_magic;
3300 + unsigned int inodes;
3301 + unsigned int bytes_used_2;
3302 + unsigned int uid_start_2;
3303 + unsigned int guid_start_2;
3304 + unsigned int inode_table_start_2;
3305 + unsigned int directory_table_start_2;
3306 + unsigned int s_major:16;
3307 + unsigned int s_minor:16;
3308 + unsigned int block_size_1:16;
3309 + unsigned int block_log:16;
3310 + unsigned int flags:8;
3311 + unsigned int no_uids:8;
3312 + unsigned int no_guids:8;
3313 + unsigned int mkfs_time /* time of filesystem creation */;
3314 + squashfs_inode_t root_inode;
3315 + unsigned int block_size;
3316 + unsigned int fragments;
3317 + unsigned int fragment_table_start_2;
3318 + long long bytes_used;
3319 + long long uid_start;
3320 + long long guid_start;
3321 + long long inode_table_start;
3322 + long long directory_table_start;
3323 + long long fragment_table_start;
3324 + long long lookup_table_start;
3325 +} __attribute__ ((packed));
3327 +struct squashfs_dir_index {
3328 + unsigned int index;
3329 + unsigned int start_block;
3330 + unsigned char size;
3331 + unsigned char name[0];
3332 +} __attribute__ ((packed));
3334 +#define SQUASHFS_BASE_INODE_HEADER \
3335 + unsigned int inode_type:4; \
3336 + unsigned int mode:12; \
3337 + unsigned int uid:8; \
3338 + unsigned int guid:8; \
3339 + unsigned int mtime; \
3340 + unsigned int inode_number;
3342 +struct squashfs_base_inode_header {
3343 + SQUASHFS_BASE_INODE_HEADER;
3344 +} __attribute__ ((packed));
3346 +struct squashfs_ipc_inode_header {
3347 + SQUASHFS_BASE_INODE_HEADER;
3348 + unsigned int nlink;
3349 +} __attribute__ ((packed));
3351 +struct squashfs_dev_inode_header {
3352 + SQUASHFS_BASE_INODE_HEADER;
3353 + unsigned int nlink;
3354 + unsigned short rdev;
3355 +} __attribute__ ((packed));
3357 +struct squashfs_symlink_inode_header {
3358 + SQUASHFS_BASE_INODE_HEADER;
3359 + unsigned int nlink;
3360 + unsigned short symlink_size;
3362 +} __attribute__ ((packed));
3364 +struct squashfs_reg_inode_header {
3365 + SQUASHFS_BASE_INODE_HEADER;
3366 + squashfs_block_t start_block;
3367 + unsigned int fragment;
3368 + unsigned int offset;
3369 + unsigned int file_size;
3370 + unsigned short block_list[0];
3371 +} __attribute__ ((packed));
3373 +struct squashfs_lreg_inode_header {
3374 + SQUASHFS_BASE_INODE_HEADER;
3375 + unsigned int nlink;
3376 + squashfs_block_t start_block;
3377 + unsigned int fragment;
3378 + unsigned int offset;
3379 + long long file_size;
3380 + unsigned short block_list[0];
3381 +} __attribute__ ((packed));
3383 +struct squashfs_dir_inode_header {
3384 + SQUASHFS_BASE_INODE_HEADER;
3385 + unsigned int nlink;
3386 + unsigned int file_size:19;
3387 + unsigned int offset:13;
3388 + unsigned int start_block;
3389 + unsigned int parent_inode;
3390 +} __attribute__ ((packed));
3392 +struct squashfs_ldir_inode_header {
3393 + SQUASHFS_BASE_INODE_HEADER;
3394 + unsigned int nlink;
3395 + unsigned int file_size:27;
3396 + unsigned int offset:13;
3397 + unsigned int start_block;
3398 + unsigned int i_count:16;
3399 + unsigned int parent_inode;
3400 + struct squashfs_dir_index index[0];
3401 +} __attribute__ ((packed));
3403 +union squashfs_inode_header {
3404 + struct squashfs_base_inode_header base;
3405 + struct squashfs_dev_inode_header dev;
3406 + struct squashfs_symlink_inode_header symlink;
3407 + struct squashfs_reg_inode_header reg;
3408 + struct squashfs_lreg_inode_header lreg;
3409 + struct squashfs_dir_inode_header dir;
3410 + struct squashfs_ldir_inode_header ldir;
3411 + struct squashfs_ipc_inode_header ipc;
3414 +struct squashfs_dir_entry {
3415 + unsigned int offset:13;
3416 + unsigned int type:3;
3417 + unsigned int size:8;
3418 + int inode_number:16;
3420 +} __attribute__ ((packed));
3422 +struct squashfs_dir_header {
3423 + unsigned int count:8;
3424 + unsigned int start_block;
3425 + unsigned int inode_number;
3426 +} __attribute__ ((packed));
3428 +struct squashfs_fragment_entry {
3429 + long long start_block;
3430 + unsigned int size;
3431 + unsigned int unused;
3432 +} __attribute__ ((packed));
3434 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3435 +extern int squashfs_uncompress_init(void);
3436 +extern int squashfs_uncompress_exit(void);
3439 + * macros to convert each packed bitfield structure from little endian to big
3440 + * endian and vice versa. These are needed when creating or using a filesystem
3441 + * on a machine with different byte ordering to the target architecture.
3445 +#define SQUASHFS_SWAP_START \
3448 + unsigned long long val;\
3449 + unsigned char *s;\
3452 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3453 + SQUASHFS_SWAP_START\
3454 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3455 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3456 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3457 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3458 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3459 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3460 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3461 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3462 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3463 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3464 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3465 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3466 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3467 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3468 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3469 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3470 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3471 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3472 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3473 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3474 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3475 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3476 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3477 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3478 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3479 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3480 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3483 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3484 + SQUASHFS_MEMSET(s, d, n);\
3485 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3486 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3487 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3488 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3489 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3490 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3492 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3493 + SQUASHFS_SWAP_START\
3494 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3497 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3498 + SQUASHFS_SWAP_START\
3499 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3500 + sizeof(struct squashfs_ipc_inode_header))\
3501 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3504 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3505 + SQUASHFS_SWAP_START\
3506 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3507 + sizeof(struct squashfs_dev_inode_header)); \
3508 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3509 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3512 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3513 + SQUASHFS_SWAP_START\
3514 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3515 + sizeof(struct squashfs_symlink_inode_header));\
3516 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3517 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3520 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3521 + SQUASHFS_SWAP_START\
3522 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3523 + sizeof(struct squashfs_reg_inode_header));\
3524 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3525 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3526 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3527 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3530 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3531 + SQUASHFS_SWAP_START\
3532 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3533 + sizeof(struct squashfs_lreg_inode_header));\
3534 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3535 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3536 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3537 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3538 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3541 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3542 + SQUASHFS_SWAP_START\
3543 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3544 + sizeof(struct squashfs_dir_inode_header));\
3545 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3546 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3547 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3548 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3549 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3552 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3553 + SQUASHFS_SWAP_START\
3554 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3555 + sizeof(struct squashfs_ldir_inode_header));\
3556 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3557 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3558 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3559 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3560 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3561 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3564 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3565 + SQUASHFS_SWAP_START\
3566 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3567 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3568 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3569 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3572 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3573 + SQUASHFS_SWAP_START\
3574 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3575 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3576 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3577 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3580 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3581 + SQUASHFS_SWAP_START\
3582 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3583 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3584 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3585 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3586 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3589 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3590 + SQUASHFS_SWAP_START\
3591 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3592 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3593 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3596 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3598 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3600 + int bit_position;\
3601 + SQUASHFS_SWAP_START\
3602 + SQUASHFS_MEMSET(s, d, n * 2);\
3603 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3605 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3608 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3610 + int bit_position;\
3611 + SQUASHFS_SWAP_START\
3612 + SQUASHFS_MEMSET(s, d, n * 4);\
3613 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3615 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3618 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3620 + int bit_position;\
3621 + SQUASHFS_SWAP_START\
3622 + SQUASHFS_MEMSET(s, d, n * 8);\
3623 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3625 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3628 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3630 + int bit_position;\
3631 + SQUASHFS_SWAP_START\
3632 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3633 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3635 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3638 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3639 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3641 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3643 +struct squashfs_base_inode_header_1 {
3644 + unsigned int inode_type:4;
3645 + unsigned int mode:12; /* protection */
3646 + unsigned int uid:4; /* index into uid table */
3647 + unsigned int guid:4; /* index into guid table */
3648 +} __attribute__ ((packed));
3650 +struct squashfs_ipc_inode_header_1 {
3651 + unsigned int inode_type:4;
3652 + unsigned int mode:12; /* protection */
3653 + unsigned int uid:4; /* index into uid table */
3654 + unsigned int guid:4; /* index into guid table */
3655 + unsigned int type:4;
3656 + unsigned int offset:4;
3657 +} __attribute__ ((packed));
3659 +struct squashfs_dev_inode_header_1 {
3660 + unsigned int inode_type:4;
3661 + unsigned int mode:12; /* protection */
3662 + unsigned int uid:4; /* index into uid table */
3663 + unsigned int guid:4; /* index into guid table */
3664 + unsigned short rdev;
3665 +} __attribute__ ((packed));
3667 +struct squashfs_symlink_inode_header_1 {
3668 + unsigned int inode_type:4;
3669 + unsigned int mode:12; /* protection */
3670 + unsigned int uid:4; /* index into uid table */
3671 + unsigned int guid:4; /* index into guid table */
3672 + unsigned short symlink_size;
3674 +} __attribute__ ((packed));
3676 +struct squashfs_reg_inode_header_1 {
3677 + unsigned int inode_type:4;
3678 + unsigned int mode:12; /* protection */
3679 + unsigned int uid:4; /* index into uid table */
3680 + unsigned int guid:4; /* index into guid table */
3681 + unsigned int mtime;
3682 + unsigned int start_block;
3683 + unsigned int file_size:32;
3684 + unsigned short block_list[0];
3685 +} __attribute__ ((packed));
3687 +struct squashfs_dir_inode_header_1 {
3688 + unsigned int inode_type:4;
3689 + unsigned int mode:12; /* protection */
3690 + unsigned int uid:4; /* index into uid table */
3691 + unsigned int guid:4; /* index into guid table */
3692 + unsigned int file_size:19;
3693 + unsigned int offset:13;
3694 + unsigned int mtime;
3695 + unsigned int start_block:24;
3696 +} __attribute__ ((packed));
3698 +union squashfs_inode_header_1 {
3699 + struct squashfs_base_inode_header_1 base;
3700 + struct squashfs_dev_inode_header_1 dev;
3701 + struct squashfs_symlink_inode_header_1 symlink;
3702 + struct squashfs_reg_inode_header_1 reg;
3703 + struct squashfs_dir_inode_header_1 dir;
3704 + struct squashfs_ipc_inode_header_1 ipc;
3707 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3708 + SQUASHFS_MEMSET(s, d, n);\
3709 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3710 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3711 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3712 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3714 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3715 + SQUASHFS_SWAP_START\
3716 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3719 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3720 + SQUASHFS_SWAP_START\
3721 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3722 + sizeof(struct squashfs_ipc_inode_header_1));\
3723 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3724 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3727 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3728 + SQUASHFS_SWAP_START\
3729 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3730 + sizeof(struct squashfs_dev_inode_header_1));\
3731 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3734 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3735 + SQUASHFS_SWAP_START\
3736 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3737 + sizeof(struct squashfs_symlink_inode_header_1));\
3738 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3741 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3742 + SQUASHFS_SWAP_START\
3743 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3744 + sizeof(struct squashfs_reg_inode_header_1));\
3745 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3746 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3747 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3750 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3751 + SQUASHFS_SWAP_START\
3752 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3753 + sizeof(struct squashfs_dir_inode_header_1));\
3754 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3755 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3756 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3757 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3762 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3764 +struct squashfs_dir_index_2 {
3765 + unsigned int index:27;
3766 + unsigned int start_block:29;
3767 + unsigned char size;
3768 + unsigned char name[0];
3769 +} __attribute__ ((packed));
3771 +struct squashfs_base_inode_header_2 {
3772 + unsigned int inode_type:4;
3773 + unsigned int mode:12; /* protection */
3774 + unsigned int uid:8; /* index into uid table */
3775 + unsigned int guid:8; /* index into guid table */
3776 +} __attribute__ ((packed));
3778 +struct squashfs_ipc_inode_header_2 {
3779 + unsigned int inode_type:4;
3780 + unsigned int mode:12; /* protection */
3781 + unsigned int uid:8; /* index into uid table */
3782 + unsigned int guid:8; /* index into guid table */
3783 +} __attribute__ ((packed));
3785 +struct squashfs_dev_inode_header_2 {
3786 + unsigned int inode_type:4;
3787 + unsigned int mode:12; /* protection */
3788 + unsigned int uid:8; /* index into uid table */
3789 + unsigned int guid:8; /* index into guid table */
3790 + unsigned short rdev;
3791 +} __attribute__ ((packed));
3793 +struct squashfs_symlink_inode_header_2 {
3794 + unsigned int inode_type:4;
3795 + unsigned int mode:12; /* protection */
3796 + unsigned int uid:8; /* index into uid table */
3797 + unsigned int guid:8; /* index into guid table */
3798 + unsigned short symlink_size;
3800 +} __attribute__ ((packed));
3802 +struct squashfs_reg_inode_header_2 {
3803 + unsigned int inode_type:4;
3804 + unsigned int mode:12; /* protection */
3805 + unsigned int uid:8; /* index into uid table */
3806 + unsigned int guid:8; /* index into guid table */
3807 + unsigned int mtime;
3808 + unsigned int start_block;
3809 + unsigned int fragment;
3810 + unsigned int offset;
3811 + unsigned int file_size:32;
3812 + unsigned short block_list[0];
3813 +} __attribute__ ((packed));
3815 +struct squashfs_dir_inode_header_2 {
3816 + unsigned int inode_type:4;
3817 + unsigned int mode:12; /* protection */
3818 + unsigned int uid:8; /* index into uid table */
3819 + unsigned int guid:8; /* index into guid table */
3820 + unsigned int file_size:19;
3821 + unsigned int offset:13;
3822 + unsigned int mtime;
3823 + unsigned int start_block:24;
3824 +} __attribute__ ((packed));
3826 +struct squashfs_ldir_inode_header_2 {
3827 + unsigned int inode_type:4;
3828 + unsigned int mode:12; /* protection */
3829 + unsigned int uid:8; /* index into uid table */
3830 + unsigned int guid:8; /* index into guid table */
3831 + unsigned int file_size:27;
3832 + unsigned int offset:13;
3833 + unsigned int mtime;
3834 + unsigned int start_block:24;
3835 + unsigned int i_count:16;
3836 + struct squashfs_dir_index_2 index[0];
3837 +} __attribute__ ((packed));
3839 +union squashfs_inode_header_2 {
3840 + struct squashfs_base_inode_header_2 base;
3841 + struct squashfs_dev_inode_header_2 dev;
3842 + struct squashfs_symlink_inode_header_2 symlink;
3843 + struct squashfs_reg_inode_header_2 reg;
3844 + struct squashfs_dir_inode_header_2 dir;
3845 + struct squashfs_ldir_inode_header_2 ldir;
3846 + struct squashfs_ipc_inode_header_2 ipc;
3849 +struct squashfs_dir_header_2 {
3850 + unsigned int count:8;
3851 + unsigned int start_block:24;
3852 +} __attribute__ ((packed));
3854 +struct squashfs_dir_entry_2 {
3855 + unsigned int offset:13;
3856 + unsigned int type:3;
3857 + unsigned int size:8;
3859 +} __attribute__ ((packed));
3861 +struct squashfs_fragment_entry_2 {
3862 + unsigned int start_block;
3863 + unsigned int size;
3864 +} __attribute__ ((packed));
3866 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3867 + SQUASHFS_MEMSET(s, d, n);\
3868 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3869 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3870 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3871 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3873 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3874 + SQUASHFS_SWAP_START\
3875 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3878 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3879 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3881 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3882 + SQUASHFS_SWAP_START\
3883 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3884 + sizeof(struct squashfs_dev_inode_header_2)); \
3885 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3888 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3889 + SQUASHFS_SWAP_START\
3890 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3891 + sizeof(struct squashfs_symlink_inode_header_2));\
3892 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3895 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3896 + SQUASHFS_SWAP_START\
3897 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3898 + sizeof(struct squashfs_reg_inode_header_2));\
3899 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3900 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3901 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3902 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3903 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3906 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3907 + SQUASHFS_SWAP_START\
3908 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3909 + sizeof(struct squashfs_dir_inode_header_2));\
3910 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3911 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3912 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3913 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3916 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3917 + SQUASHFS_SWAP_START\
3918 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3919 + sizeof(struct squashfs_ldir_inode_header_2));\
3920 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3921 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3922 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3923 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3924 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3927 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3928 + SQUASHFS_SWAP_START\
3929 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3930 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3931 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3932 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3934 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3935 + SQUASHFS_SWAP_START\
3936 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3937 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3938 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3941 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3942 + SQUASHFS_SWAP_START\
3943 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3944 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3945 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3946 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3949 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3950 + SQUASHFS_SWAP_START\
3951 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3952 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3953 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3956 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3958 +/* fragment and fragment table defines */
3959 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3961 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3962 + SQUASHFS_METADATA_SIZE)
3964 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3965 + SQUASHFS_METADATA_SIZE)
3967 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3968 + SQUASHFS_METADATA_SIZE - 1) / \
3969 + SQUASHFS_METADATA_SIZE)
3971 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3979 + * macros used to swap each structure entry, taking into account
3980 + * bitfields and different bitfield placing conventions on differing
3984 +#include <asm/byteorder.h>
3986 +#ifdef __BIG_ENDIAN
3987 + /* convert from little endian to big endian */
3988 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3991 + /* convert from big endian to little endian */
3992 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3993 + tbits, 64 - tbits - b_pos)
3996 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3999 + s = (unsigned char *)p + (pos / 8);\
4000 + d = ((unsigned char *) &val) + 7;\
4001 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4003 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4006 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4011 +++ kernel-power-2.6.28/include/linux/squashfs_fs_i.h
4013 +#ifndef SQUASHFS_FS_I
4014 +#define SQUASHFS_FS_I
4018 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4019 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4021 + * This program is free software; you can redistribute it and/or
4022 + * modify it under the terms of the GNU General Public License
4023 + * as published by the Free Software Foundation; either version 2,
4024 + * or (at your option) any later version.
4026 + * This program is distributed in the hope that it will be useful,
4027 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4028 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4029 + * GNU General Public License for more details.
4031 + * You should have received a copy of the GNU General Public License
4032 + * along with this program; if not, write to the Free Software
4033 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4038 +struct squashfs_inode_info {
4039 + long long start_block;
4040 + unsigned int offset;
4043 + long long fragment_start_block;
4044 + unsigned int fragment_size;
4045 + unsigned int fragment_offset;
4046 + long long block_list_start;
4049 + long long directory_index_start;
4050 + unsigned int directory_index_offset;
4051 + unsigned int directory_index_count;
4052 + unsigned int parent_inode;
4055 + struct inode vfs_inode;
4059 +++ kernel-power-2.6.28/include/linux/squashfs_fs_sb.h
4061 +#ifndef SQUASHFS_FS_SB
4062 +#define SQUASHFS_FS_SB
4066 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4067 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4069 + * This program is free software; you can redistribute it and/or
4070 + * modify it under the terms of the GNU General Public License
4071 + * as published by the Free Software Foundation; either version 2,
4072 + * or (at your option) any later version.
4074 + * This program is distributed in the hope that it will be useful,
4075 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4076 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4077 + * GNU General Public License for more details.
4079 + * You should have received a copy of the GNU General Public License
4080 + * along with this program; if not, write to the Free Software
4081 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4083 + * squashfs_fs_sb.h
4086 +#include <linux/squashfs_fs.h>
4088 +struct squashfs_cache_entry {
4092 + long long next_index;
4096 + wait_queue_head_t wait_queue;
4100 +struct squashfs_cache {
4109 + wait_queue_head_t wait_queue;
4110 + struct squashfs_cache_entry entry[0];
4113 +struct squashfs_sb_info {
4114 + struct squashfs_super_block sblk;
4116 + int devblksize_log2;
4118 + struct squashfs_cache *block_cache;
4119 + struct squashfs_cache *fragment_cache;
4120 + int next_meta_index;
4121 + unsigned int *uid;
4122 + unsigned int *guid;
4123 + long long *fragment_index;
4124 + unsigned int *fragment_index_2;
4126 + struct mutex read_data_mutex;
4127 + struct mutex read_page_mutex;
4128 + struct mutex meta_index_mutex;
4129 + struct meta_index *meta_index;
4131 + long long *inode_lookup_table;
4132 + int (*read_inode)(struct inode *i, squashfs_inode_t \
4134 + long long (*read_blocklist)(struct inode *inode, int \
4135 + index, int readahead_blks, char *block_list, \
4136 + unsigned short **block_p, unsigned int *bsize);
4137 + int (*read_fragment_index_table)(struct super_block *s);
4140 --- kernel-power-2.6.28.orig/init/do_mounts_rd.c
4141 +++ kernel-power-2.6.28/init/do_mounts_rd.c
4143 #include <linux/ext2_fs.h>
4144 #include <linux/romfs_fs.h>
4145 #include <linux/cramfs_fs.h>
4146 +#include <linux/squashfs_fs.h>
4147 #include <linux/initrd.h>
4148 #include <linux/string.h>
4151 * numbers could not be found.
4153 * We currently check for the following magic numbers:
4159 struct ext2_super_block *ext2sb;
4160 struct romfs_super_block *romfsb;
4161 struct cramfs_super *cramfsb;
4162 + struct squashfs_super_block *squashfsb;
4167 ext2sb = (struct ext2_super_block *) buf;
4168 romfsb = (struct romfs_super_block *) buf;
4169 cramfsb = (struct cramfs_super *) buf;
4170 + squashfsb = (struct squashfs_super_block *) buf;
4171 memset(buf, 0xe5, size);
4178 + /* squashfs is at block zero too */
4179 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4180 + printk(KERN_NOTICE
4181 + "RAMDISK: squashfs filesystem found at block %d\n",
4183 + if (squashfsb->s_major < 3)
4184 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4186 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4191 * Read block 1 to test for minix and ext2 superblock