1 From: Phillip Lougher <phillip.lougher@gmail.com>
3 Patch-mainline: Who knows?
5 This patch contains the SquashFS file system.
7 Acked-by: Greg Kroah-Hartman <gregkh@suse.com>
12 fs/squashfs/Makefile | 7
13 fs/squashfs/inode.c | 2174 +++++++++++++++++++++++++++++++++++++++++
14 fs/squashfs/squashfs.h | 86 +
15 fs/squashfs/squashfs2_0.c | 740 +++++++++++++
16 include/linux/squashfs_fs.h | 935 +++++++++++++++++
17 include/linux/squashfs_fs_i.h | 45
18 include/linux/squashfs_fs_sb.h | 79 +
19 init/do_mounts_rd.c | 16
20 10 files changed, 4133 insertions(+)
24 @@ -1391,6 +1391,56 @@ config CRAMFS
29 + tristate "SquashFS 3.4 - Squashed file system support"
32 + Saying Y here includes support for SquashFS 3.4 (a Compressed
33 + Read-Only File System). Squashfs is a highly compressed read-only
34 + filesystem for Linux. It uses zlib compression to compress both
35 + files, inodes and directories. Inodes in the system are very small
36 + and all blocks are packed to minimise data overhead. Block sizes
37 + greater than 4K are supported up to a maximum of 1 Mbytes (default
38 + block size 128K). SquashFS 3.3 supports 64 bit filesystems and files
39 + (larger than 4GB), full uid/gid information, hard links and timestamps.
41 + Squashfs is intended for general read-only filesystem use, for
42 + archival use (i.e. in cases where a .tar.gz file may be used), and in
43 + embedded systems where low overhead is needed. Further information
44 + and filesystem tools are available from http://squashfs.sourceforge.net.
46 + If you want to compile this as a module ( = code which can be
47 + inserted in and removed from the running kernel whenever you want),
48 + say M here and read <file:Documentation/modules.txt>. The module
49 + will be called squashfs. Note that the root file system (the one
50 + containing the directory /) cannot be compiled as a module.
54 +config SQUASHFS_EMBEDDED
56 + bool "Additional option for memory-constrained systems"
60 + Saying Y here allows you to specify cache size.
64 +config SQUASHFS_FRAGMENT_CACHE_SIZE
65 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
69 + By default SquashFS caches the last 3 fragments read from
70 + the filesystem. Increasing this amount may mean SquashFS
71 + has to re-read fragments less often from disk, at the expense
72 + of extra system memory. Decreasing this amount will mean
73 + SquashFS uses less memory at the expense of extra reads from disk.
75 + Note there must be at least one cached fragment. Anything
76 + much more than three will probably not make much difference.
79 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
83 @@ -77,6 +77,7 @@ obj-$(CONFIG_JBD) += jbd/
84 obj-$(CONFIG_JBD2) += jbd2/
85 obj-$(CONFIG_EXT2_FS) += ext2/
86 obj-$(CONFIG_CRAMFS) += cramfs/
87 +obj-$(CONFIG_SQUASHFS) += squashfs/
89 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
90 obj-$(CONFIG_CODA_FS) += coda/
92 +++ b/fs/squashfs/Makefile
95 +# Makefile for the linux squashfs routines.
98 +obj-$(CONFIG_SQUASHFS) += squashfs.o
99 +squashfs-y += inode.o
100 +squashfs-y += squashfs2_0.o
102 +++ b/fs/squashfs/inode.c
105 + * Squashfs - a compressed read only filesystem for Linux
107 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
108 + * Phillip Lougher <phillip@lougher.demon.co.uk>
110 + * This program is free software; you can redistribute it and/or
111 + * modify it under the terms of the GNU General Public License
112 + * as published by the Free Software Foundation; either version 2,
113 + * or (at your option) any later version.
115 + * This program is distributed in the hope that it will be useful,
116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 + * GNU General Public License for more details.
120 + * You should have received a copy of the GNU General Public License
121 + * along with this program; if not, write to the Free Software
122 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
127 +#include <linux/squashfs_fs.h>
128 +#include <linux/module.h>
129 +#include <linux/zlib.h>
130 +#include <linux/fs.h>
131 +#include <linux/squashfs_fs_sb.h>
132 +#include <linux/squashfs_fs_i.h>
133 +#include <linux/buffer_head.h>
134 +#include <linux/vfs.h>
135 +#include <linux/vmalloc.h>
136 +#include <linux/spinlock.h>
137 +#include <linux/smp_lock.h>
138 +#include <linux/exportfs.h>
139 +#include <linux/sched.h>
141 +#include "squashfs.h"
143 +static struct dentry *squashfs_fh_to_dentry(struct super_block *s,
144 + struct fid *fid, int fh_len, int fh_type);
145 +static struct dentry *squashfs_fh_to_parent(struct super_block *s,
146 + struct fid *fid, int fh_len, int fh_type);
147 +static struct dentry *squashfs_get_parent(struct dentry *child);
148 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode);
149 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
150 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
151 +static long long read_blocklist(struct inode *inode, int index,
152 + int readahead_blks, char *block_list,
153 + unsigned short **block_p, unsigned int *bsize);
154 +static int squashfs_readpage(struct file *file, struct page *page);
155 +static int squashfs_readdir(struct file *, void *, filldir_t);
156 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
157 + struct nameidata *);
158 +static int squashfs_remount(struct super_block *s, int *flags, char *data);
159 +static void squashfs_put_super(struct super_block *);
160 +static int squashfs_get_sb(struct file_system_type *,int, const char *, void *,
161 + struct vfsmount *);
162 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
163 +static void squashfs_destroy_inode(struct inode *inode);
164 +static int init_inodecache(void);
165 +static void destroy_inodecache(void);
167 +static struct file_system_type squashfs_fs_type = {
168 + .owner = THIS_MODULE,
169 + .name = "squashfs",
170 + .get_sb = squashfs_get_sb,
171 + .kill_sb = kill_block_super,
172 + .fs_flags = FS_REQUIRES_DEV
175 +static const unsigned char squashfs_filetype_table[] = {
176 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
179 +static struct super_operations squashfs_super_ops = {
180 + .alloc_inode = squashfs_alloc_inode,
181 + .destroy_inode = squashfs_destroy_inode,
182 + .statfs = squashfs_statfs,
183 + .put_super = squashfs_put_super,
184 + .remount_fs = squashfs_remount
187 +static struct export_operations squashfs_export_ops = {
188 + .fh_to_dentry = squashfs_fh_to_dentry,
189 + .fh_to_parent = squashfs_fh_to_parent,
190 + .get_parent = squashfs_get_parent
193 +SQSH_EXTERN const struct address_space_operations squashfs_symlink_aops = {
194 + .readpage = squashfs_symlink_readpage
197 +SQSH_EXTERN const struct address_space_operations squashfs_aops = {
198 + .readpage = squashfs_readpage
201 +static const struct file_operations squashfs_dir_ops = {
202 + .read = generic_read_dir,
203 + .readdir = squashfs_readdir
206 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
207 + .lookup = squashfs_lookup
211 +static struct buffer_head *get_block_length(struct super_block *s,
212 + int *cur_index, int *offset, int *c_byte)
214 + struct squashfs_sb_info *msblk = s->s_fs_info;
215 + unsigned short temp;
216 + struct buffer_head *bh;
218 + if (!(bh = sb_bread(s, *cur_index)))
221 + if (msblk->devblksize - *offset == 1) {
223 + ((unsigned char *) &temp)[1] = *((unsigned char *)
224 + (bh->b_data + *offset));
226 + ((unsigned char *) &temp)[0] = *((unsigned char *)
227 + (bh->b_data + *offset));
229 + if (!(bh = sb_bread(s, ++(*cur_index))))
232 + ((unsigned char *) &temp)[0] = *((unsigned char *)
235 + ((unsigned char *) &temp)[1] = *((unsigned char *)
241 + ((unsigned char *) &temp)[1] = *((unsigned char *)
242 + (bh->b_data + *offset));
243 + ((unsigned char *) &temp)[0] = *((unsigned char *)
244 + (bh->b_data + *offset + 1));
246 + ((unsigned char *) &temp)[0] = *((unsigned char *)
247 + (bh->b_data + *offset));
248 + ((unsigned char *) &temp)[1] = *((unsigned char *)
249 + (bh->b_data + *offset + 1));
255 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
256 + if (*offset == msblk->devblksize) {
258 + if (!(bh = sb_bread(s, ++(*cur_index))))
262 + if (*((unsigned char *) (bh->b_data + *offset)) !=
263 + SQUASHFS_MARKER_BYTE) {
264 + ERROR("Metadata block marker corrupt @ %x\n",
278 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
279 + long long index, unsigned int length,
280 + long long *next_index, int srclength)
282 + struct squashfs_sb_info *msblk = s->s_fs_info;
283 + struct squashfs_super_block *sblk = &msblk->sblk;
284 + struct buffer_head **bh;
285 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
286 + unsigned int cur_index = index >> msblk->devblksize_log2;
287 + int bytes, avail_bytes, b = 0, k = 0;
288 + unsigned int compressed;
289 + unsigned int c_byte = length;
291 + bh = kmalloc(((sblk->block_size >> msblk->devblksize_log2) + 1) *
292 + sizeof(struct buffer_head *), GFP_KERNEL);
298 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
299 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
301 + TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n", index,
302 + compressed ? "" : "un", (unsigned int) c_byte, srclength);
304 + if (c_byte > srclength || index < 0 || (index + c_byte) > sblk->bytes_used)
307 + for (b = 0; bytes < (int) c_byte; b++, cur_index++) {
308 + bh[b] = sb_getblk(s, cur_index);
310 + goto block_release;
311 + bytes += msblk->devblksize;
313 + ll_rw_block(READ, b, bh);
315 + if (index < 0 || (index + 2) > sblk->bytes_used)
318 + bh[0] = get_block_length(s, &cur_index, &offset, &c_byte);
323 + bytes = msblk->devblksize - offset;
324 + compressed = SQUASHFS_COMPRESSED(c_byte);
325 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
327 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
328 + ? "" : "un", (unsigned int) c_byte);
330 + if (c_byte > srclength || (index + c_byte) > sblk->bytes_used)
331 + goto block_release;
333 + for (; bytes < c_byte; b++) {
334 + bh[b] = sb_getblk(s, ++cur_index);
336 + goto block_release;
337 + bytes += msblk->devblksize;
339 + ll_rw_block(READ, b - 1, bh + 1);
349 + mutex_lock(&msblk->read_data_mutex);
351 + msblk->stream.next_out = buffer;
352 + msblk->stream.avail_out = srclength;
354 + for (bytes = 0; k < b; k++) {
355 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
357 + wait_on_buffer(bh[k]);
358 + if (!buffer_uptodate(bh[k]))
359 + goto release_mutex;
361 + msblk->stream.next_in = bh[k]->b_data + offset;
362 + msblk->stream.avail_in = avail_bytes;
365 + zlib_err = zlib_inflateInit(&msblk->stream);
366 + if (zlib_err != Z_OK) {
367 + ERROR("zlib_inflateInit returned unexpected result 0x%x,"
368 + " srclength %d\n", zlib_err, srclength);
369 + goto release_mutex;
372 + if (avail_bytes == 0) {
379 + zlib_err = zlib_inflate(&msblk->stream, Z_NO_FLUSH);
380 + if (zlib_err != Z_OK && zlib_err != Z_STREAM_END) {
381 + ERROR("zlib_inflate returned unexpected result 0x%x,"
382 + " srclength %d, avail_in %d, avail_out %d\n", zlib_err,
383 + srclength, msblk->stream.avail_in, msblk->stream.avail_out);
384 + goto release_mutex;
387 + bytes += avail_bytes;
392 + if (zlib_err != Z_STREAM_END)
393 + goto release_mutex;
395 + zlib_err = zlib_inflateEnd(&msblk->stream);
396 + if (zlib_err != Z_OK) {
397 + ERROR("zlib_inflateEnd returned unexpected result 0x%x,"
398 + " srclength %d\n", zlib_err, srclength);
399 + goto release_mutex;
401 + bytes = msblk->stream.total_out;
402 + mutex_unlock(&msblk->read_data_mutex);
406 + for(i = 0; i < b; i++) {
407 + wait_on_buffer(bh[i]);
408 + if (!buffer_uptodate(bh[i]))
409 + goto block_release;
412 + for (bytes = 0; k < b; k++) {
413 + avail_bytes = min(c_byte - bytes, msblk->devblksize - offset);
415 + memcpy(buffer + bytes, bh[k]->b_data + offset, avail_bytes);
416 + bytes += avail_bytes;
423 + *next_index = index + c_byte + (length ? 0 :
424 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags) ? 3 : 2));
430 + mutex_unlock(&msblk->read_data_mutex);
437 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
443 +static struct squashfs_cache_entry *squashfs_cache_get(struct super_block *s,
444 + struct squashfs_cache *cache, long long block, int length)
447 + struct squashfs_cache_entry *entry;
449 + spin_lock(&cache->lock);
452 + for (i = 0; i < cache->entries && cache->entry[i].block != block; i++);
454 + if (i == cache->entries) {
455 + if (cache->unused_blks == 0) {
457 + spin_unlock(&cache->lock);
458 + wait_event(cache->wait_queue, cache->unused_blks);
459 + spin_lock(&cache->lock);
464 + i = cache->next_blk;
465 + for (n = 0; n < cache->entries; n++) {
466 + if (cache->entry[i].locked == 0)
468 + i = (i + 1) % cache->entries;
471 + cache->next_blk = (i + 1) % cache->entries;
472 + entry = &cache->entry[i];
474 + cache->unused_blks --;
475 + entry->block = block;
477 + entry->pending = 1;
478 + entry->waiting = 0;
480 + spin_unlock(&cache->lock);
482 + entry->length = squashfs_read_data(s, entry->data,
483 + block, length, &entry->next_index, cache->block_size);
485 + spin_lock(&cache->lock);
487 + if (entry->length == 0)
490 + entry->pending = 0;
491 + spin_unlock(&cache->lock);
492 + if (entry->waiting)
493 + wake_up_all(&entry->wait_queue);
497 + entry = &cache->entry[i];
498 + if (entry->locked == 0)
499 + cache->unused_blks --;
502 + if (entry->pending) {
504 + spin_unlock(&cache->lock);
505 + wait_event(entry->wait_queue, !entry->pending);
509 + spin_unlock(&cache->lock);
514 + TRACE("Got %s %d, start block %lld, locked %d, error %d\n", i,
515 + cache->name, entry->block, entry->locked, entry->error);
517 + ERROR("Unable to read %s cache entry [%llx]\n", cache->name, block);
522 +static void squashfs_cache_put(struct squashfs_cache *cache,
523 + struct squashfs_cache_entry *entry)
525 + spin_lock(&cache->lock);
527 + if (entry->locked == 0) {
528 + cache->unused_blks ++;
529 + spin_unlock(&cache->lock);
530 + if (cache->waiting)
531 + wake_up(&cache->wait_queue);
533 + spin_unlock(&cache->lock);
537 +static void squashfs_cache_delete(struct squashfs_cache *cache)
544 + for (i = 0; i < cache->entries; i++)
545 + if (cache->entry[i].data) {
546 + if (cache->use_vmalloc)
547 + vfree(cache->entry[i].data);
549 + kfree(cache->entry[i].data);
556 +static struct squashfs_cache *squashfs_cache_init(char *name, int entries,
557 + int block_size, int use_vmalloc)
560 + struct squashfs_cache *cache = kzalloc(sizeof(struct squashfs_cache) +
561 + entries * sizeof(struct squashfs_cache_entry), GFP_KERNEL);
562 + if (cache == NULL) {
563 + ERROR("Failed to allocate %s cache\n", name);
567 + cache->next_blk = 0;
568 + cache->unused_blks = entries;
569 + cache->entries = entries;
570 + cache->block_size = block_size;
571 + cache->use_vmalloc = use_vmalloc;
572 + cache->name = name;
573 + cache->waiting = 0;
574 + spin_lock_init(&cache->lock);
575 + init_waitqueue_head(&cache->wait_queue);
577 + for (i = 0; i < entries; i++) {
578 + init_waitqueue_head(&cache->entry[i].wait_queue);
579 + cache->entry[i].block = SQUASHFS_INVALID_BLK;
580 + cache->entry[i].data = use_vmalloc ? vmalloc(block_size) :
581 + kmalloc(block_size, GFP_KERNEL);
582 + if (cache->entry[i].data == NULL) {
583 + ERROR("Failed to allocate %s cache entry\n", name);
591 + squashfs_cache_delete(cache);
597 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, void *buffer,
598 + long long block, unsigned int offset,
599 + int length, long long *next_block,
600 + unsigned int *next_offset)
602 + struct squashfs_sb_info *msblk = s->s_fs_info;
603 + int bytes, return_length = length;
604 + struct squashfs_cache_entry *entry;
606 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
609 + entry = squashfs_cache_get(s, msblk->block_cache, block, 0);
610 + bytes = entry->length - offset;
612 + if (entry->error || bytes < 1) {
615 + } else if (bytes >= length) {
617 + memcpy(buffer, entry->data + offset, length);
618 + if (entry->length - offset == length) {
619 + *next_block = entry->next_index;
622 + *next_block = block;
623 + *next_offset = offset + length;
628 + memcpy(buffer, entry->data + offset, bytes);
629 + buffer = (char *) buffer + bytes;
631 + block = entry->next_index;
632 + squashfs_cache_put(msblk->block_cache, entry);
639 + squashfs_cache_put(msblk->block_cache, entry);
640 + return return_length;
644 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
645 + long long *fragment_start_block,
646 + unsigned int *fragment_size)
648 + struct squashfs_sb_info *msblk = s->s_fs_info;
649 + long long start_block =
650 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
651 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
652 + struct squashfs_fragment_entry fragment_entry;
655 + struct squashfs_fragment_entry sfragment_entry;
657 + if (!squashfs_get_cached_block(s, &sfragment_entry, start_block, offset,
658 + sizeof(sfragment_entry), &start_block, &offset))
660 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
662 + if (!squashfs_get_cached_block(s, &fragment_entry, start_block, offset,
663 + sizeof(fragment_entry), &start_block, &offset))
666 + *fragment_start_block = fragment_entry.start_block;
667 + *fragment_size = fragment_entry.size;
676 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk,
677 + struct squashfs_cache_entry *fragment)
679 + squashfs_cache_put(msblk->fragment_cache, fragment);
684 +struct squashfs_cache_entry *get_cached_fragment(struct super_block *s,
685 + long long start_block, int length)
687 + struct squashfs_sb_info *msblk = s->s_fs_info;
689 + return squashfs_cache_get(s, msblk->fragment_cache, start_block, length);
693 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
694 + struct squashfs_base_inode_header *inodeb)
696 + i->i_ino = inodeb->inode_number;
697 + i->i_mtime.tv_sec = inodeb->mtime;
698 + i->i_atime.tv_sec = inodeb->mtime;
699 + i->i_ctime.tv_sec = inodeb->mtime;
700 + i->i_uid = msblk->uid[inodeb->uid];
701 + i->i_mode = inodeb->mode;
704 + if (inodeb->guid == SQUASHFS_GUIDS)
705 + i->i_gid = i->i_uid;
707 + i->i_gid = msblk->guid[inodeb->guid];
711 +static squashfs_inode_t squashfs_inode_lookup(struct super_block *s, int ino)
713 + struct squashfs_sb_info *msblk = s->s_fs_info;
714 + long long start = msblk->inode_lookup_table[SQUASHFS_LOOKUP_BLOCK(ino - 1)];
715 + int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino - 1);
716 + squashfs_inode_t inode;
718 + TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino);
721 + squashfs_inode_t sinode;
723 + if (!squashfs_get_cached_block(s, &sinode, start, offset,
724 + sizeof(sinode), &start, &offset))
726 + SQUASHFS_SWAP_INODE_T((&inode), &sinode);
727 + } else if (!squashfs_get_cached_block(s, &inode, start, offset,
728 + sizeof(inode), &start, &offset))
731 + TRACE("squashfs_inode_lookup, inode = 0x%llx\n", inode);
736 + return SQUASHFS_INVALID_BLK;
741 +static struct dentry *squashfs_export_iget(struct super_block *s,
742 + unsigned int inode_number)
744 + squashfs_inode_t inode;
746 + struct dentry *dentry;
748 + TRACE("Entered squashfs_export_iget\n");
750 + inode = squashfs_inode_lookup(s, inode_number);
751 + if(inode == SQUASHFS_INVALID_BLK) {
752 + dentry = ERR_PTR(-ENOENT);
756 + i = squashfs_iget(s, inode, inode_number);
758 + dentry = ERR_PTR(-EACCES);
762 + dentry = d_alloc_anon(i);
763 + if (dentry == NULL) {
765 + dentry = ERR_PTR(-ENOMEM);
773 +static struct dentry *squashfs_fh_to_dentry(struct super_block *s,
774 + struct fid *fid, int fh_len, int fh_type)
776 + if((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT) ||
780 + return squashfs_export_iget(s, fid->i32.ino);
784 +static struct dentry *squashfs_fh_to_parent(struct super_block *s,
785 + struct fid *fid, int fh_len, int fh_type)
787 + if(fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)
790 + return squashfs_export_iget(s, fid->i32.parent_ino);
794 +static struct dentry *squashfs_get_parent(struct dentry *child)
796 + struct inode *i = child->d_inode;
798 + TRACE("Entered squashfs_get_parent\n");
800 + return squashfs_export_iget(i->i_sb, SQUASHFS_I(i)->u.s2.parent_inode);
804 +SQSH_EXTERN struct inode *squashfs_iget(struct super_block *s,
805 + squashfs_inode_t inode, unsigned int inode_number)
807 + struct squashfs_sb_info *msblk = s->s_fs_info;
808 + struct inode *i = iget_locked(s, inode_number);
810 + TRACE("Entered squashfs_iget\n");
812 + if(i && (i->i_state & I_NEW)) {
813 + (msblk->read_inode)(i, inode);
814 + unlock_new_inode(i);
821 +static int squashfs_read_inode(struct inode *i, squashfs_inode_t inode)
823 + struct super_block *s = i->i_sb;
824 + struct squashfs_sb_info *msblk = s->s_fs_info;
825 + struct squashfs_super_block *sblk = &msblk->sblk;
826 + long long block = SQUASHFS_INODE_BLK(inode) + sblk->inode_table_start;
827 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
828 + long long next_block;
829 + unsigned int next_offset;
830 + union squashfs_inode_header id, sid;
831 + struct squashfs_base_inode_header *inodeb = &id.base, *sinodeb = &sid.base;
833 + TRACE("Entered squashfs_read_inode\n");
836 + if (!squashfs_get_cached_block(s, sinodeb, block, offset,
837 + sizeof(*sinodeb), &next_block, &next_offset))
839 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb, sizeof(*sinodeb));
841 + if (!squashfs_get_cached_block(s, inodeb, block, offset,
842 + sizeof(*inodeb), &next_block, &next_offset))
845 + squashfs_new_inode(msblk, i, inodeb);
847 + switch(inodeb->inode_type) {
848 + case SQUASHFS_FILE_TYPE: {
849 + unsigned int frag_size;
850 + long long frag_blk;
851 + struct squashfs_reg_inode_header *inodep = &id.reg;
852 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
855 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
856 + sizeof(*sinodep), &next_block, &next_offset))
858 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
860 + if (!squashfs_get_cached_block(s, inodep, block, offset,
861 + sizeof(*inodep), &next_block, &next_offset))
864 + frag_blk = SQUASHFS_INVALID_BLK;
866 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
867 + if(!get_fragment_location(s, inodep->fragment, &frag_blk,
872 + i->i_size = inodep->file_size;
873 + i->i_fop = &generic_ro_fops;
874 + i->i_mode |= S_IFREG;
875 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
876 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
877 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
878 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
879 + SQUASHFS_I(i)->start_block = inodep->start_block;
880 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
881 + SQUASHFS_I(i)->offset = next_offset;
882 + i->i_data.a_ops = &squashfs_aops;
884 + TRACE("File inode %x:%x, start_block %llx, "
885 + "block_list_start %llx, offset %x\n",
886 + SQUASHFS_INODE_BLK(inode), offset,
887 + inodep->start_block, next_block,
891 + case SQUASHFS_LREG_TYPE: {
892 + unsigned int frag_size;
893 + long long frag_blk;
894 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
895 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
898 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
899 + sizeof(*sinodep), &next_block, &next_offset))
901 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
903 + if (!squashfs_get_cached_block(s, inodep, block, offset,
904 + sizeof(*inodep), &next_block, &next_offset))
907 + frag_blk = SQUASHFS_INVALID_BLK;
909 + if (inodep->fragment != SQUASHFS_INVALID_FRAG)
910 + if (!get_fragment_location(s, inodep->fragment, &frag_blk,
914 + i->i_nlink = inodep->nlink;
915 + i->i_size = inodep->file_size;
916 + i->i_fop = &generic_ro_fops;
917 + i->i_mode |= S_IFREG;
918 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
919 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
920 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
921 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
922 + SQUASHFS_I(i)->start_block = inodep->start_block;
923 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
924 + SQUASHFS_I(i)->offset = next_offset;
925 + i->i_data.a_ops = &squashfs_aops;
927 + TRACE("File inode %x:%x, start_block %llx, "
928 + "block_list_start %llx, offset %x\n",
929 + SQUASHFS_INODE_BLK(inode), offset,
930 + inodep->start_block, next_block,
934 + case SQUASHFS_DIR_TYPE: {
935 + struct squashfs_dir_inode_header *inodep = &id.dir;
936 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
939 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
940 + sizeof(*sinodep), &next_block, &next_offset))
942 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
944 + if (!squashfs_get_cached_block(s, inodep, block, offset,
945 + sizeof(*inodep), &next_block, &next_offset))
948 + i->i_nlink = inodep->nlink;
949 + i->i_size = inodep->file_size;
950 + i->i_op = &squashfs_dir_inode_ops;
951 + i->i_fop = &squashfs_dir_ops;
952 + i->i_mode |= S_IFDIR;
953 + SQUASHFS_I(i)->start_block = inodep->start_block;
954 + SQUASHFS_I(i)->offset = inodep->offset;
955 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
956 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
958 + TRACE("Directory inode %x:%x, start_block %x, offset "
959 + "%x\n", SQUASHFS_INODE_BLK(inode),
960 + offset, inodep->start_block,
964 + case SQUASHFS_LDIR_TYPE: {
965 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
966 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
969 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
970 + sizeof(*sinodep), &next_block, &next_offset))
972 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep, sinodep);
974 + if (!squashfs_get_cached_block(s, inodep, block, offset,
975 + sizeof(*inodep), &next_block, &next_offset))
978 + i->i_nlink = inodep->nlink;
979 + i->i_size = inodep->file_size;
980 + i->i_op = &squashfs_dir_inode_ops;
981 + i->i_fop = &squashfs_dir_ops;
982 + i->i_mode |= S_IFDIR;
983 + SQUASHFS_I(i)->start_block = inodep->start_block;
984 + SQUASHFS_I(i)->offset = inodep->offset;
985 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
986 + SQUASHFS_I(i)->u.s2.directory_index_offset = next_offset;
987 + SQUASHFS_I(i)->u.s2.directory_index_count = inodep->i_count;
988 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
990 + TRACE("Long directory inode %x:%x, start_block %x, offset %x\n",
991 + SQUASHFS_INODE_BLK(inode), offset,
992 + inodep->start_block, inodep->offset);
995 + case SQUASHFS_SYMLINK_TYPE: {
996 + struct squashfs_symlink_inode_header *inodep = &id.symlink;
997 + struct squashfs_symlink_inode_header *sinodep = &sid.symlink;
1000 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
1001 + sizeof(*sinodep), &next_block, &next_offset))
1003 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep, sinodep);
1005 + if (!squashfs_get_cached_block(s, inodep, block, offset,
1006 + sizeof(*inodep), &next_block, &next_offset))
1009 + i->i_nlink = inodep->nlink;
1010 + i->i_size = inodep->symlink_size;
1011 + i->i_op = &page_symlink_inode_operations;
1012 + i->i_data.a_ops = &squashfs_symlink_aops;
1013 + i->i_mode |= S_IFLNK;
1014 + SQUASHFS_I(i)->start_block = next_block;
1015 + SQUASHFS_I(i)->offset = next_offset;
1017 + TRACE("Symbolic link inode %x:%x, start_block %llx, offset %x\n",
1018 + SQUASHFS_INODE_BLK(inode), offset,
1019 + next_block, next_offset);
1022 + case SQUASHFS_BLKDEV_TYPE:
1023 + case SQUASHFS_CHRDEV_TYPE: {
1024 + struct squashfs_dev_inode_header *inodep = &id.dev;
1025 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
1027 + if (msblk->swap) {
1028 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
1029 + sizeof(*sinodep), &next_block, &next_offset))
1031 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
1033 + if (!squashfs_get_cached_block(s, inodep, block, offset,
1034 + sizeof(*inodep), &next_block, &next_offset))
1037 + i->i_nlink = inodep->nlink;
1038 + i->i_mode |= (inodeb->inode_type == SQUASHFS_CHRDEV_TYPE) ?
1039 + S_IFCHR : S_IFBLK;
1040 + init_special_inode(i, i->i_mode, old_decode_dev(inodep->rdev));
1042 + TRACE("Device inode %x:%x, rdev %x\n",
1043 + SQUASHFS_INODE_BLK(inode), offset, inodep->rdev);
1046 + case SQUASHFS_FIFO_TYPE:
1047 + case SQUASHFS_SOCKET_TYPE: {
1048 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
1049 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
1051 + if (msblk->swap) {
1052 + if (!squashfs_get_cached_block(s, sinodep, block, offset,
1053 + sizeof(*sinodep), &next_block, &next_offset))
1055 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
1057 + if (!squashfs_get_cached_block(s, inodep, block, offset,
1058 + sizeof(*inodep), &next_block, &next_offset))
1061 + i->i_nlink = inodep->nlink;
1062 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
1063 + ? S_IFIFO : S_IFSOCK;
1064 + init_special_inode(i, i->i_mode, 0);
1068 + ERROR("Unknown inode type %d in squashfs_iget!\n",
1069 + inodeb->inode_type);
1070 + goto failed_read1;
1076 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
1079 + make_bad_inode(i);
1084 +static int read_inode_lookup_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_LOOKUP_BLOCK_BYTES(sblk->inodes);
1090 + TRACE("In read_inode_lookup_table, length %d\n", length);
1092 + /* Allocate inode lookup table */
1093 + msblk->inode_lookup_table = kmalloc(length, GFP_KERNEL);
1094 + if (msblk->inode_lookup_table == NULL) {
1095 + ERROR("Failed to allocate inode lookup table\n");
1099 + if (!squashfs_read_data(s, (char *) msblk->inode_lookup_table,
1100 + sblk->lookup_table_start, length |
1101 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1102 + ERROR("unable to read inode lookup table\n");
1106 + if (msblk->swap) {
1110 + for (i = 0; i < SQUASHFS_LOOKUP_BLOCKS(sblk->inodes); i++) {
1112 + SQUASHFS_SWAP_LOOKUP_BLOCKS((&block),
1113 + &msblk->inode_lookup_table[i], 1);
1114 + msblk->inode_lookup_table[i] = block;
1122 +static int read_fragment_index_table(struct super_block *s)
1124 + struct squashfs_sb_info *msblk = s->s_fs_info;
1125 + struct squashfs_super_block *sblk = &msblk->sblk;
1126 + unsigned int length = SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments);
1131 + /* Allocate fragment index table */
1132 + msblk->fragment_index = kmalloc(length, GFP_KERNEL);
1133 + if (msblk->fragment_index == NULL) {
1134 + ERROR("Failed to allocate fragment index table\n");
1138 + if (!squashfs_read_data(s, (char *) msblk->fragment_index,
1139 + sblk->fragment_table_start, length |
1140 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length)) {
1141 + ERROR("unable to read fragment index table\n");
1145 + if (msblk->swap) {
1147 + long long fragment;
1149 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments); i++) {
1151 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1152 + &msblk->fragment_index[i], 1);
1153 + msblk->fragment_index[i] = fragment;
1161 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1163 + struct squashfs_super_block *sblk = &msblk->sblk;
1165 + msblk->read_inode = squashfs_read_inode;
1166 + msblk->read_blocklist = read_blocklist;
1167 + msblk->read_fragment_index_table = read_fragment_index_table;
1169 + if (sblk->s_major == 1) {
1170 + if (!squashfs_1_0_supported(msblk)) {
1171 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1172 + "are unsupported\n");
1173 + SERROR("Please recompile with Squashfs 1.0 support enabled\n");
1176 + } else if (sblk->s_major == 2) {
1177 + if (!squashfs_2_0_supported(msblk)) {
1178 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1179 + "are unsupported\n");
1180 + SERROR("Please recompile with Squashfs 2.0 support enabled\n");
1183 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1185 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1186 + "filesystem\n", sblk->s_major, sblk->s_minor);
1187 + SERROR("Please update your kernel\n");
1195 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1197 + struct squashfs_sb_info *msblk;
1198 + struct squashfs_super_block *sblk;
1199 + char b[BDEVNAME_SIZE];
1200 + struct inode *root;
1202 + TRACE("Entered squashfs_fill_superblock\n");
1204 + s->s_fs_info = kzalloc(sizeof(struct squashfs_sb_info), GFP_KERNEL);
1205 + if (s->s_fs_info == NULL) {
1206 + ERROR("Failed to allocate superblock\n");
1209 + msblk = s->s_fs_info;
1211 + msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize());
1212 + if (msblk->stream.workspace == NULL) {
1213 + ERROR("Failed to allocate zlib workspace\n");
1216 + sblk = &msblk->sblk;
1218 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1219 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1221 + mutex_init(&msblk->read_data_mutex);
1222 + mutex_init(&msblk->read_page_mutex);
1223 + mutex_init(&msblk->meta_index_mutex);
1225 + /* sblk->bytes_used is checked in squashfs_read_data to ensure reads are not
1226 + * beyond filesystem end. As we're using squashfs_read_data to read sblk here,
1227 + * first set sblk->bytes_used to a useful value */
1228 + sblk->bytes_used = sizeof(struct squashfs_super_block);
1229 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1230 + sizeof(struct squashfs_super_block) |
1231 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, sizeof(struct squashfs_super_block))) {
1232 + SERROR("unable to read superblock\n");
1233 + goto failed_mount;
1236 + /* Check it is a SQUASHFS superblock */
1237 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1238 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1239 + struct squashfs_super_block ssblk;
1241 + WARNING("Mounting a different endian SQUASHFS filesystem on %s\n",
1242 + bdevname(s->s_bdev, b));
1244 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1245 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1248 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1249 + bdevname(s->s_bdev, b));
1250 + goto failed_mount;
1254 + /* Check the MAJOR & MINOR versions */
1255 + if(!supported_squashfs_filesystem(msblk, silent))
1256 + goto failed_mount;
1258 + /* Check the filesystem does not extend beyond the end of the
1260 + if(sblk->bytes_used < 0 || sblk->bytes_used > i_size_read(s->s_bdev->bd_inode))
1261 + goto failed_mount;
1263 + /* Check the root inode for sanity */
1264 + if (SQUASHFS_INODE_OFFSET(sblk->root_inode) > SQUASHFS_METADATA_SIZE)
1265 + goto failed_mount;
1267 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1268 + TRACE("Inodes are %scompressed\n", SQUASHFS_UNCOMPRESSED_INODES(sblk->flags)
1270 + TRACE("Data is %scompressed\n", SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1272 + TRACE("Check data is %spresent in the filesystem\n",
1273 + SQUASHFS_CHECK_DATA(sblk->flags) ? "" : "not ");
1274 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1275 + TRACE("Block size %d\n", sblk->block_size);
1276 + TRACE("Number of inodes %d\n", sblk->inodes);
1277 + if (sblk->s_major > 1)
1278 + TRACE("Number of fragments %d\n", sblk->fragments);
1279 + TRACE("Number of uids %d\n", sblk->no_uids);
1280 + TRACE("Number of gids %d\n", sblk->no_guids);
1281 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1282 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1283 + if (sblk->s_major > 1)
1284 + TRACE("sblk->fragment_table_start %llx\n", sblk->fragment_table_start);
1285 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1287 + s->s_maxbytes = MAX_LFS_FILESIZE;
1288 + s->s_flags |= MS_RDONLY;
1289 + s->s_op = &squashfs_super_ops;
1291 + msblk->block_cache = squashfs_cache_init("metadata", SQUASHFS_CACHED_BLKS,
1292 + SQUASHFS_METADATA_SIZE, 0);
1293 + if (msblk->block_cache == NULL)
1294 + goto failed_mount;
1296 + /* Allocate read_page block */
1297 + msblk->read_page = vmalloc(sblk->block_size);
1298 + if (msblk->read_page == NULL) {
1299 + ERROR("Failed to allocate read_page block\n");
1300 + goto failed_mount;
1303 + /* Allocate uid and gid tables */
1304 + msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1305 + sizeof(unsigned int), GFP_KERNEL);
1306 + if (msblk->uid == NULL) {
1307 + ERROR("Failed to allocate uid/gid table\n");
1308 + goto failed_mount;
1310 + msblk->guid = msblk->uid + sblk->no_uids;
1312 + if (msblk->swap) {
1313 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1315 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1316 + ((sblk->no_uids + sblk->no_guids) *
1317 + sizeof(unsigned int)) |
1318 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1319 + ERROR("unable to read uid/gid table\n");
1320 + goto failed_mount;
1323 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1324 + sblk->no_guids), (sizeof(unsigned int) * 8));
1326 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1327 + ((sblk->no_uids + sblk->no_guids) *
1328 + sizeof(unsigned int)) |
1329 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, (sblk->no_uids + sblk->no_guids) * sizeof(unsigned int))) {
1330 + ERROR("unable to read uid/gid table\n");
1331 + goto failed_mount;
1335 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1336 + goto allocate_root;
1338 + msblk->fragment_cache = squashfs_cache_init("fragment",
1339 + SQUASHFS_CACHED_FRAGMENTS, sblk->block_size, 1);
1340 + if (msblk->fragment_cache == NULL)
1341 + goto failed_mount;
1343 + /* Allocate and read fragment index table */
1344 + if (msblk->read_fragment_index_table(s) == 0)
1345 + goto failed_mount;
1347 + if(sblk->s_major < 3 || sblk->lookup_table_start == SQUASHFS_INVALID_BLK)
1348 + goto allocate_root;
1350 + /* Allocate and read inode lookup table */
1351 + if (read_inode_lookup_table(s) == 0)
1352 + goto failed_mount;
1354 + s->s_export_op = &squashfs_export_ops;
1357 + root = new_inode(s);
1358 + if ((msblk->read_inode)(root, sblk->root_inode) == 0)
1359 + goto failed_mount;
1360 + insert_inode_hash(root);
1362 + s->s_root = d_alloc_root(root);
1363 + if (s->s_root == NULL) {
1364 + ERROR("Root inode create failed\n");
1366 + goto failed_mount;
1369 + TRACE("Leaving squashfs_fill_super\n");
1373 + kfree(msblk->inode_lookup_table);
1374 + kfree(msblk->fragment_index);
1375 + squashfs_cache_delete(msblk->fragment_cache);
1376 + kfree(msblk->uid);
1377 + vfree(msblk->read_page);
1378 + squashfs_cache_delete(msblk->block_cache);
1379 + kfree(msblk->fragment_index_2);
1380 + vfree(msblk->stream.workspace);
1381 + kfree(s->s_fs_info);
1382 + s->s_fs_info = NULL;
1390 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1392 + struct squashfs_sb_info *msblk = dentry->d_sb->s_fs_info;
1393 + struct squashfs_super_block *sblk = &msblk->sblk;
1395 + TRACE("Entered squashfs_statfs\n");
1397 + buf->f_type = SQUASHFS_MAGIC;
1398 + buf->f_bsize = sblk->block_size;
1399 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1400 + buf->f_bfree = buf->f_bavail = 0;
1401 + buf->f_files = sblk->inodes;
1403 + buf->f_namelen = SQUASHFS_NAME_LEN;
1409 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1411 + struct inode *inode = page->mapping->host;
1412 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes, avail_bytes;
1413 + long long block = SQUASHFS_I(inode)->start_block;
1414 + int offset = SQUASHFS_I(inode)->offset;
1415 + void *pageaddr = kmap(page);
1417 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1418 + "%llx, offset %x\n", page->index,
1419 + SQUASHFS_I(inode)->start_block,
1420 + SQUASHFS_I(inode)->offset);
1422 + for (length = 0; length < index; length += bytes) {
1423 + bytes = squashfs_get_cached_block(inode->i_sb, NULL, block,
1424 + offset, PAGE_CACHE_SIZE, &block, &offset);
1426 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1431 + if (length != index) {
1432 + ERROR("(squashfs_symlink_readpage) length != index\n");
1437 + avail_bytes = min_t(int, i_size_read(inode) - length, PAGE_CACHE_SIZE);
1439 + bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block, offset,
1440 + avail_bytes, &block, &offset);
1442 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1445 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1447 + flush_dcache_page(page);
1448 + SetPageUptodate(page);
1449 + unlock_page(page);
1455 +static struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1457 + struct meta_index *meta = NULL;
1458 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1461 + mutex_lock(&msblk->meta_index_mutex);
1463 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1465 + if (msblk->meta_index == NULL)
1466 + goto not_allocated;
1468 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++) {
1469 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1470 + msblk->meta_index[i].offset >= offset &&
1471 + msblk->meta_index[i].offset <= index &&
1472 + msblk->meta_index[i].locked == 0) {
1473 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1474 + msblk->meta_index[i].offset);
1475 + meta = &msblk->meta_index[i];
1476 + offset = meta->offset;
1484 + mutex_unlock(&msblk->meta_index_mutex);
1490 +static struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1492 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1493 + struct meta_index *meta = NULL;
1496 + mutex_lock(&msblk->meta_index_mutex);
1498 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1500 + if (msblk->meta_index == NULL) {
1501 + msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1502 + SQUASHFS_META_NUMBER, GFP_KERNEL);
1503 + if (msblk->meta_index == NULL) {
1504 + ERROR("Failed to allocate meta_index\n");
1507 + for (i = 0; i < SQUASHFS_META_NUMBER; i++) {
1508 + msblk->meta_index[i].inode_number = 0;
1509 + msblk->meta_index[i].locked = 0;
1511 + msblk->next_meta_index = 0;
1514 + for (i = SQUASHFS_META_NUMBER; i &&
1515 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1516 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1517 + SQUASHFS_META_NUMBER;
1520 + TRACE("empty_meta_index: failed!\n");
1524 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1525 + msblk->next_meta_index,
1526 + &msblk->meta_index[msblk->next_meta_index]);
1528 + meta = &msblk->meta_index[msblk->next_meta_index];
1529 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1530 + SQUASHFS_META_NUMBER;
1532 + meta->inode_number = inode->i_ino;
1533 + meta->offset = offset;
1534 + meta->skip = skip;
1535 + meta->entries = 0;
1539 + mutex_unlock(&msblk->meta_index_mutex);
1544 +static void release_meta_index(struct inode *inode, struct meta_index *meta)
1551 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1552 + long long *start_block, int *offset)
1554 + struct squashfs_sb_info *msblk = s->s_fs_info;
1555 + unsigned int *block_listp;
1558 + if (msblk->swap) {
1559 + char sblock_list[blocks << 2];
1561 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1562 + *offset, blocks << 2, start_block, offset)) {
1563 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1566 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1567 + ((unsigned int *)sblock_list), blocks);
1569 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1570 + *offset, blocks << 2, start_block, offset)) {
1571 + ERROR("Fail reading block list [%llx:%x]\n", *start_block, *offset);
1576 + for (block_listp = (unsigned int *) block_list; blocks;
1577 + block_listp++, blocks --)
1578 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1589 +static inline int calculate_skip(int blocks) {
1590 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1591 + return skip >= 7 ? 7 : skip + 1;
1595 +static int get_meta_index(struct inode *inode, int index,
1596 + long long *index_block, int *index_offset,
1597 + long long *data_block, char *block_list)
1599 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1600 + struct squashfs_super_block *sblk = &msblk->sblk;
1601 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1603 + struct meta_index *meta;
1604 + struct meta_entry *meta_entry;
1605 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1606 + int cur_offset = SQUASHFS_I(inode)->offset;
1607 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1610 + index /= SQUASHFS_META_INDEXES * skip;
1612 + while (offset < index) {
1613 + meta = locate_meta_index(inode, index, offset + 1);
1615 + if (meta == NULL) {
1616 + meta = empty_meta_index(inode, offset + 1, skip);
1620 + if(meta->entries == 0)
1623 + offset = index < meta->offset + meta->entries ? index :
1624 + meta->offset + meta->entries - 1;
1626 + meta_entry = &meta->meta_entry[offset - meta->offset];
1627 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1628 + cur_offset = meta_entry->offset;
1629 + cur_data_block = meta_entry->data_block;
1630 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1631 + "meta->entries %d\n", offset, meta->offset, meta->entries);
1632 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1633 + " data_block 0x%llx\n", cur_index_block,
1634 + cur_offset, cur_data_block);
1637 + for (i = meta->offset + meta->entries; i <= index &&
1638 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1639 + int blocks = skip * SQUASHFS_META_INDEXES;
1642 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) : blocks;
1643 + int res = read_block_index(inode->i_sb, block, block_list,
1644 + &cur_index_block, &cur_offset);
1649 + cur_data_block += res;
1653 + meta_entry = &meta->meta_entry[i - meta->offset];
1654 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1655 + meta_entry->offset = cur_offset;
1656 + meta_entry->data_block = cur_data_block;
1661 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1662 + meta->offset, meta->entries);
1664 + release_meta_index(inode, meta);
1668 + *index_block = cur_index_block;
1669 + *index_offset = cur_offset;
1670 + *data_block = cur_data_block;
1672 + return offset * SQUASHFS_META_INDEXES * skip;
1675 + release_meta_index(inode, meta);
1680 +static long long read_blocklist(struct inode *inode, int index,
1681 + int readahead_blks, char *block_list,
1682 + unsigned short **block_p, unsigned int *bsize)
1684 + long long block_ptr;
1687 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1690 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1691 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset, block);
1699 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1700 + int res = read_block_index(inode->i_sb, blocks, block_list,
1701 + &block_ptr, &offset);
1708 + if (read_block_index(inode->i_sb, 1, block_list, &block_ptr, &offset) == -1)
1710 + *bsize = *((unsigned int *) block_list);
1719 +static int squashfs_readpage(struct file *file, struct page *page)
1721 + struct inode *inode = page->mapping->host;
1722 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1723 + struct squashfs_super_block *sblk = &msblk->sblk;
1724 + unsigned char *block_list = NULL;
1726 + unsigned int bsize, i;
1728 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1730 + struct squashfs_cache_entry *fragment = NULL;
1731 + char *data_ptr = msblk->read_page;
1733 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1734 + int start_index = page->index & ~mask;
1735 + int end_index = start_index | mask;
1736 + int file_end = i_size_read(inode) >> sblk->block_log;
1739 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1740 + page->index, SQUASHFS_I(inode)->start_block);
1742 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1743 + PAGE_CACHE_SHIFT))
1746 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1747 + || index < file_end) {
1748 + block_list = kmalloc(SIZE, GFP_KERNEL);
1749 + if (block_list == NULL) {
1750 + ERROR("Failed to allocate block_list\n");
1754 + block = (msblk->read_blocklist)(inode, index, 1, block_list, NULL, &bsize);
1758 + if (bsize == 0) { /* hole */
1759 + bytes = index == file_end ?
1760 + (i_size_read(inode) & (sblk->block_size - 1)) : sblk->block_size;
1763 + mutex_lock(&msblk->read_page_mutex);
1765 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1766 + bsize, NULL, sblk->block_size);
1769 + ERROR("Unable to read page, block %llx, size %x\n", block, bsize);
1770 + mutex_unlock(&msblk->read_page_mutex);
1775 + fragment = get_cached_fragment(inode->i_sb,
1776 + SQUASHFS_I(inode)-> u.s1.fragment_start_block,
1777 + SQUASHFS_I(inode)->u.s1.fragment_size);
1779 + if (fragment->error) {
1780 + ERROR("Unable to read page, block %llx, size %x\n",
1781 + SQUASHFS_I(inode)->u.s1.fragment_start_block,
1782 + (int) SQUASHFS_I(inode)->u.s1.fragment_size);
1783 + release_cached_fragment(msblk, fragment);
1786 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1787 + data_ptr = fragment->data + SQUASHFS_I(inode)->u.s1.fragment_offset;
1790 + for (i = start_index; i <= end_index && bytes > 0; i++,
1791 + bytes -= PAGE_CACHE_SIZE, data_ptr += PAGE_CACHE_SIZE) {
1792 + struct page *push_page;
1793 + int avail = sparse ? 0 : min_t(unsigned int, bytes, PAGE_CACHE_SIZE);
1795 + TRACE("bytes %d, i %d, available_bytes %d\n", bytes, i, avail);
1797 + push_page = (i == page->index) ? page :
1798 + grab_cache_page_nowait(page->mapping, i);
1803 + if (PageUptodate(push_page))
1806 + pageaddr = kmap_atomic(push_page, KM_USER0);
1807 + memcpy(pageaddr, data_ptr, avail);
1808 + memset(pageaddr + avail, 0, PAGE_CACHE_SIZE - avail);
1809 + kunmap_atomic(pageaddr, KM_USER0);
1810 + flush_dcache_page(push_page);
1811 + SetPageUptodate(push_page);
1813 + unlock_page(push_page);
1814 + if(i != page->index)
1815 + page_cache_release(push_page);
1818 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1819 + || index < file_end) {
1821 + mutex_unlock(&msblk->read_page_mutex);
1822 + kfree(block_list);
1824 + release_cached_fragment(msblk, fragment);
1829 + SetPageError(page);
1831 + pageaddr = kmap_atomic(page, KM_USER0);
1832 + memset(pageaddr, 0, PAGE_CACHE_SIZE);
1833 + kunmap_atomic(pageaddr, KM_USER0);
1834 + flush_dcache_page(page);
1835 + if (!PageError(page))
1836 + SetPageUptodate(page);
1837 + unlock_page(page);
1839 + kfree(block_list);
1844 +static int get_dir_index_using_offset(struct super_block *s,
1845 + long long *next_block, unsigned int *next_offset,
1846 + long long index_start, unsigned int index_offset, int i_count,
1849 + struct squashfs_sb_info *msblk = s->s_fs_info;
1850 + struct squashfs_super_block *sblk = &msblk->sblk;
1851 + int i, length = 0;
1852 + struct squashfs_dir_index index;
1854 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1855 + i_count, (unsigned int) f_pos);
1861 + for (i = 0; i < i_count; i++) {
1862 + if (msblk->swap) {
1863 + struct squashfs_dir_index sindex;
1864 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1865 + sizeof(sindex), &index_start, &index_offset);
1866 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1868 + squashfs_get_cached_block(s, &index, index_start, index_offset,
1869 + sizeof(index), &index_start, &index_offset);
1871 + if (index.index > f_pos)
1874 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1875 + index.size + 1, &index_start, &index_offset);
1877 + length = index.index;
1878 + *next_block = index.start_block + sblk->directory_table_start;
1881 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1884 + return length + 3;
1888 +static int get_dir_index_using_name(struct super_block *s,
1889 + long long *next_block, unsigned int *next_offset,
1890 + long long index_start, unsigned int index_offset, int i_count,
1891 + const char *name, int size)
1893 + struct squashfs_sb_info *msblk = s->s_fs_info;
1894 + struct squashfs_super_block *sblk = &msblk->sblk;
1895 + int i, length = 0;
1896 + struct squashfs_dir_index *index;
1899 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1901 + str = kmalloc(sizeof(struct squashfs_dir_index) +
1902 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL);
1903 + if (str == NULL) {
1904 + ERROR("Failed to allocate squashfs_dir_index\n");
1908 + index = (struct squashfs_dir_index *) (str + SQUASHFS_NAME_LEN + 1);
1909 + strncpy(str, name, size);
1912 + for (i = 0; i < i_count; i++) {
1913 + if (msblk->swap) {
1914 + struct squashfs_dir_index sindex;
1915 + squashfs_get_cached_block(s, &sindex, index_start, index_offset,
1916 + sizeof(sindex), &index_start, &index_offset);
1917 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1919 + squashfs_get_cached_block(s, index, index_start, index_offset,
1920 + sizeof(struct squashfs_dir_index), &index_start, &index_offset);
1922 + squashfs_get_cached_block(s, index->name, index_start, index_offset,
1923 + index->size + 1, &index_start, &index_offset);
1925 + index->name[index->size + 1] = '\0';
1927 + if (strcmp(index->name, str) > 0)
1930 + length = index->index;
1931 + *next_block = index->start_block + sblk->directory_table_start;
1934 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1938 + return length + 3;
1942 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1944 + struct inode *i = file->f_dentry->d_inode;
1945 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1946 + struct squashfs_super_block *sblk = &msblk->sblk;
1947 + long long next_block = SQUASHFS_I(i)->start_block +
1948 + sblk->directory_table_start;
1949 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
1950 + struct squashfs_dir_header dirh;
1951 + struct squashfs_dir_entry *dire;
1953 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1955 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
1956 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
1957 + if (dire == NULL) {
1958 + ERROR("Failed to allocate squashfs_dir_entry\n");
1962 + while(file->f_pos < 3) {
1966 + if(file->f_pos == 0) {
1973 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1975 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1976 + (unsigned int) dirent, name, size, (int)
1977 + file->f_pos, i_ino, squashfs_filetype_table[1]);
1979 + if (filldir(dirent, name, size, file->f_pos, i_ino,
1980 + squashfs_filetype_table[1]) < 0) {
1981 + TRACE("Filldir returned less than 0\n");
1984 + file->f_pos += size;
1987 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1988 + SQUASHFS_I(i)->u.s2.directory_index_start,
1989 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1990 + SQUASHFS_I(i)->u.s2.directory_index_count, file->f_pos);
1992 + while (length < i_size_read(i)) {
1993 + /* read directory header */
1994 + if (msblk->swap) {
1995 + struct squashfs_dir_header sdirh;
1997 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
1998 + next_offset, sizeof(sdirh), &next_block, &next_offset))
2001 + length += sizeof(sdirh);
2002 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2004 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2005 + next_offset, sizeof(dirh), &next_block, &next_offset))
2008 + length += sizeof(dirh);
2011 + dir_count = dirh.count + 1;
2012 + while (dir_count--) {
2013 + if (msblk->swap) {
2014 + struct squashfs_dir_entry sdire;
2015 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2016 + next_offset, sizeof(sdire), &next_block, &next_offset))
2019 + length += sizeof(sdire);
2020 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2022 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2023 + next_offset, sizeof(*dire), &next_block, &next_offset))
2026 + length += sizeof(*dire);
2029 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2030 + next_offset, dire->size + 1, &next_block, &next_offset))
2033 + length += dire->size + 1;
2035 + if (file->f_pos >= length)
2038 + dire->name[dire->size + 1] = '\0';
2040 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
2041 + (unsigned int) dirent, dire->name, dire->size + 1,
2042 + (int) file->f_pos, dirh.start_block, dire->offset,
2043 + dirh.inode_number + dire->inode_number,
2044 + squashfs_filetype_table[dire->type]);
2046 + if (filldir(dirent, dire->name, dire->size + 1, file->f_pos,
2047 + dirh.inode_number + dire->inode_number,
2048 + squashfs_filetype_table[dire->type]) < 0) {
2049 + TRACE("Filldir returned less than 0\n");
2052 + file->f_pos = length;
2061 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2068 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2069 + struct nameidata *nd)
2071 + const unsigned char *name = dentry->d_name.name;
2072 + int len = dentry->d_name.len;
2073 + struct inode *inode = NULL;
2074 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2075 + struct squashfs_super_block *sblk = &msblk->sblk;
2076 + long long next_block = SQUASHFS_I(i)->start_block +
2077 + sblk->directory_table_start;
2078 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dir_count;
2079 + struct squashfs_dir_header dirh;
2080 + struct squashfs_dir_entry *dire;
2082 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2084 + dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2085 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL);
2086 + if (dire == NULL) {
2087 + ERROR("Failed to allocate squashfs_dir_entry\n");
2091 + if (len > SQUASHFS_NAME_LEN)
2094 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2095 + SQUASHFS_I(i)->u.s2.directory_index_start,
2096 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2097 + SQUASHFS_I(i)->u.s2.directory_index_count, name, len);
2099 + while (length < i_size_read(i)) {
2100 + /* read directory header */
2101 + if (msblk->swap) {
2102 + struct squashfs_dir_header sdirh;
2103 + if (!squashfs_get_cached_block(i->i_sb, &sdirh, next_block,
2104 + next_offset, sizeof(sdirh), &next_block, &next_offset))
2107 + length += sizeof(sdirh);
2108 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2110 + if (!squashfs_get_cached_block(i->i_sb, &dirh, next_block,
2111 + next_offset, sizeof(dirh), &next_block, &next_offset))
2114 + length += sizeof(dirh);
2117 + dir_count = dirh.count + 1;
2118 + while (dir_count--) {
2119 + if (msblk->swap) {
2120 + struct squashfs_dir_entry sdire;
2121 + if (!squashfs_get_cached_block(i->i_sb, &sdire, next_block,
2122 + next_offset, sizeof(sdire), &next_block, &next_offset))
2125 + length += sizeof(sdire);
2126 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2128 + if (!squashfs_get_cached_block(i->i_sb, dire, next_block,
2129 + next_offset, sizeof(*dire), &next_block, &next_offset))
2132 + length += sizeof(*dire);
2135 + if (!squashfs_get_cached_block(i->i_sb, dire->name, next_block,
2136 + next_offset, dire->size + 1, &next_block, &next_offset))
2139 + length += dire->size + 1;
2141 + if (name[0] < dire->name[0])
2144 + if ((len == dire->size + 1) && !strncmp(name, dire->name, len)) {
2145 + squashfs_inode_t ino = SQUASHFS_MKINODE(dirh.start_block,
2148 + TRACE("calling squashfs_iget for directory entry %s, inode"
2149 + " %x:%x, %d\n", name, dirh.start_block, dire->offset,
2150 + dirh.inode_number + dire->inode_number);
2152 + inode = squashfs_iget(i->i_sb, ino, dirh.inode_number + dire->inode_number);
2162 + return d_splice_alias(inode, dentry);
2163 + d_add(dentry, inode);
2164 + return ERR_PTR(0);
2167 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2173 +static int squashfs_remount(struct super_block *s, int *flags, char *data)
2175 + *flags |= MS_RDONLY;
2180 +static void squashfs_put_super(struct super_block *s)
2182 + if (s->s_fs_info) {
2183 + struct squashfs_sb_info *sbi = s->s_fs_info;
2184 + squashfs_cache_delete(sbi->block_cache);
2185 + squashfs_cache_delete(sbi->fragment_cache);
2186 + vfree(sbi->read_page);
2188 + kfree(sbi->fragment_index);
2189 + kfree(sbi->fragment_index_2);
2190 + kfree(sbi->meta_index);
2191 + vfree(sbi->stream.workspace);
2192 + kfree(s->s_fs_info);
2193 + s->s_fs_info = NULL;
2198 +static int squashfs_get_sb(struct file_system_type *fs_type, int flags,
2199 + const char *dev_name, void *data, struct vfsmount *mnt)
2201 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super,
2206 +static int __init init_squashfs_fs(void)
2208 + int err = init_inodecache();
2212 + printk(KERN_INFO "squashfs: version 3.4 (2008/08/26) "
2213 + "Phillip Lougher\n");
2215 + err = register_filesystem(&squashfs_fs_type);
2217 + destroy_inodecache();
2224 +static void __exit exit_squashfs_fs(void)
2226 + unregister_filesystem(&squashfs_fs_type);
2227 + destroy_inodecache();
2231 +static struct kmem_cache * squashfs_inode_cachep;
2234 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2236 + struct squashfs_inode_info *ei;
2237 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2238 + return ei ? &ei->vfs_inode : NULL;
2242 +static void squashfs_destroy_inode(struct inode *inode)
2244 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2248 +static void init_once(void *foo)
2250 + struct squashfs_inode_info *ei = foo;
2252 + inode_init_once(&ei->vfs_inode);
2256 +static int __init init_inodecache(void)
2258 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2259 + sizeof(struct squashfs_inode_info), 0,
2260 + SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT, init_once);
2261 + if (squashfs_inode_cachep == NULL)
2267 +static void destroy_inodecache(void)
2269 + kmem_cache_destroy(squashfs_inode_cachep);
2273 +module_init(init_squashfs_fs);
2274 +module_exit(exit_squashfs_fs);
2275 +MODULE_DESCRIPTION("squashfs 3.4, a compressed read-only filesystem");
2276 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.demon.co.uk>");
2277 +MODULE_LICENSE("GPL");
2279 +++ b/fs/squashfs/squashfs.h
2282 + * Squashfs - a compressed read only filesystem for Linux
2284 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
2285 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2287 + * This program is free software; you can redistribute it and/or
2288 + * modify it under the terms of the GNU General Public License
2289 + * as published by the Free Software Foundation; either version 2,
2290 + * or (at your option) any later version.
2292 + * This program is distributed in the hope that it will be useful,
2293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2295 + * GNU General Public License for more details.
2297 + * You should have received a copy of the GNU General Public License
2298 + * along with this program; if not, write to the Free Software
2299 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2304 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2305 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2308 +#ifdef SQUASHFS_TRACE
2309 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
2311 +#define TRACE(s, args...) {}
2314 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
2316 +#define SERROR(s, args...) do { \
2318 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
2321 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
2323 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
2325 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
2328 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
2329 +#define SQSH_EXTERN
2330 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
2331 + long long index, unsigned int length,
2332 + long long *next_index, int srclength);
2333 +extern int squashfs_get_cached_block(struct super_block *s, void *buffer,
2334 + long long block, unsigned int offset,
2335 + int length, long long *next_block,
2336 + unsigned int *next_offset);
2337 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
2338 + squashfs_cache_entry *fragment);
2339 +extern struct squashfs_cache_entry *get_cached_fragment(struct super_block
2340 + *s, long long start_block,
2342 +extern struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode, unsigned int inode_number);
2343 +extern const struct address_space_operations squashfs_symlink_aops;
2344 +extern const struct address_space_operations squashfs_aops;
2345 +extern struct inode_operations squashfs_dir_inode_ops;
2347 +#define SQSH_EXTERN static
2350 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
2351 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
2353 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
2359 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
2360 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
2362 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2368 +++ b/fs/squashfs/squashfs2_0.c
2371 + * Squashfs - a compressed read only filesystem for Linux
2373 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
2374 + * Phillip Lougher <phillip@lougher.demon.co.uk>
2376 + * This program is free software; you can redistribute it and/or
2377 + * modify it under the terms of the GNU General Public License
2378 + * as published by the Free Software Foundation; either version 2,
2379 + * or (at your option) any later version.
2381 + * This program is distributed in the hope that it will be useful,
2382 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2383 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2384 + * GNU General Public License for more details.
2386 + * You should have received a copy of the GNU General Public License
2387 + * along with this program; if not, write to the Free Software
2388 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2393 +#include <linux/squashfs_fs.h>
2394 +#include <linux/module.h>
2395 +#include <linux/zlib.h>
2396 +#include <linux/fs.h>
2397 +#include <linux/squashfs_fs_sb.h>
2398 +#include <linux/squashfs_fs_i.h>
2400 +#include "squashfs.h"
2401 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2402 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2403 + struct nameidata *);
2405 +static struct file_operations squashfs_dir_ops_2 = {
2406 + .read = generic_read_dir,
2407 + .readdir = squashfs_readdir_2
2410 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2411 + .lookup = squashfs_lookup_2
2414 +static unsigned char squashfs_filetype_table[] = {
2415 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2418 +static int read_fragment_index_table_2(struct super_block *s)
2420 + struct squashfs_sb_info *msblk = s->s_fs_info;
2421 + struct squashfs_super_block *sblk = &msblk->sblk;
2423 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2424 + (sblk->fragments), GFP_KERNEL))) {
2425 + ERROR("Failed to allocate uid/gid table\n");
2429 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2430 + !squashfs_read_data(s, (char *)
2431 + msblk->fragment_index_2,
2432 + sblk->fragment_table_start,
2433 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2434 + (sblk->fragments) |
2435 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments))) {
2436 + ERROR("unable to read fragment index table\n");
2440 + if (msblk->swap) {
2442 + unsigned int fragment;
2444 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2446 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2447 + &msblk->fragment_index_2[i], 1);
2448 + msblk->fragment_index_2[i] = fragment;
2456 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2457 + long long *fragment_start_block,
2458 + unsigned int *fragment_size)
2460 + struct squashfs_sb_info *msblk = s->s_fs_info;
2461 + long long start_block =
2462 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2463 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2464 + struct squashfs_fragment_entry_2 fragment_entry;
2466 + if (msblk->swap) {
2467 + struct squashfs_fragment_entry_2 sfragment_entry;
2469 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2470 + start_block, offset,
2471 + sizeof(sfragment_entry), &start_block,
2474 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2476 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2477 + start_block, offset,
2478 + sizeof(fragment_entry), &start_block,
2482 + *fragment_start_block = fragment_entry.start_block;
2483 + *fragment_size = fragment_entry.size;
2492 +static void squashfs_new_inode(struct squashfs_sb_info *msblk, struct inode *i,
2493 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2495 + struct squashfs_super_block *sblk = &msblk->sblk;
2498 + i->i_mtime.tv_sec = sblk->mkfs_time;
2499 + i->i_atime.tv_sec = sblk->mkfs_time;
2500 + i->i_ctime.tv_sec = sblk->mkfs_time;
2501 + i->i_uid = msblk->uid[inodeb->uid];
2502 + i->i_mode = inodeb->mode;
2505 + if (inodeb->guid == SQUASHFS_GUIDS)
2506 + i->i_gid = i->i_uid;
2508 + i->i_gid = msblk->guid[inodeb->guid];
2512 +static int squashfs_read_inode_2(struct inode *i, squashfs_inode_t inode)
2514 + struct super_block *s = i->i_sb;
2515 + struct squashfs_sb_info *msblk = s->s_fs_info;
2516 + struct squashfs_super_block *sblk = &msblk->sblk;
2517 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2518 + sblk->inode_table_start;
2519 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2520 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block -
2521 + sblk->inode_table_start, offset);
2522 + long long next_block;
2523 + unsigned int next_offset;
2524 + union squashfs_inode_header_2 id, sid;
2525 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2526 + *sinodeb = &sid.base;
2528 + TRACE("Entered squashfs_read_inode_2\n");
2530 + if (msblk->swap) {
2531 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2532 + offset, sizeof(*sinodeb), &next_block,
2535 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2536 + sizeof(*sinodeb));
2538 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2539 + offset, sizeof(*inodeb), &next_block,
2543 + squashfs_new_inode(msblk, i, inodeb, ino);
2545 + switch(inodeb->inode_type) {
2546 + case SQUASHFS_FILE_TYPE: {
2547 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2548 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2549 + long long frag_blk;
2550 + unsigned int frag_size = 0;
2552 + if (msblk->swap) {
2553 + if (!squashfs_get_cached_block(s, (char *)
2554 + sinodep, block, offset,
2555 + sizeof(*sinodep), &next_block,
2558 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2560 + if (!squashfs_get_cached_block(s, (char *)
2561 + inodep, block, offset,
2562 + sizeof(*inodep), &next_block,
2566 + frag_blk = SQUASHFS_INVALID_BLK;
2567 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2568 + !get_fragment_location_2(s,
2569 + inodep->fragment, &frag_blk, &frag_size))
2572 + i->i_size = inodep->file_size;
2573 + i->i_fop = &generic_ro_fops;
2574 + i->i_mode |= S_IFREG;
2575 + i->i_mtime.tv_sec = inodep->mtime;
2576 + i->i_atime.tv_sec = inodep->mtime;
2577 + i->i_ctime.tv_sec = inodep->mtime;
2578 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2579 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2580 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2581 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2582 + SQUASHFS_I(i)->start_block = inodep->start_block;
2583 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2584 + SQUASHFS_I(i)->offset = next_offset;
2585 + i->i_data.a_ops = &squashfs_aops;
2587 + TRACE("File inode %x:%x, start_block %x, "
2588 + "block_list_start %llx, offset %x\n",
2589 + SQUASHFS_INODE_BLK(inode), offset,
2590 + inodep->start_block, next_block,
2594 + case SQUASHFS_DIR_TYPE: {
2595 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2596 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2598 + if (msblk->swap) {
2599 + if (!squashfs_get_cached_block(s, (char *)
2600 + sinodep, block, offset,
2601 + sizeof(*sinodep), &next_block,
2604 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2606 + if (!squashfs_get_cached_block(s, (char *)
2607 + inodep, block, offset,
2608 + sizeof(*inodep), &next_block,
2612 + i->i_size = inodep->file_size;
2613 + i->i_op = &squashfs_dir_inode_ops_2;
2614 + i->i_fop = &squashfs_dir_ops_2;
2615 + i->i_mode |= S_IFDIR;
2616 + i->i_mtime.tv_sec = inodep->mtime;
2617 + i->i_atime.tv_sec = inodep->mtime;
2618 + i->i_ctime.tv_sec = inodep->mtime;
2619 + SQUASHFS_I(i)->start_block = inodep->start_block;
2620 + SQUASHFS_I(i)->offset = inodep->offset;
2621 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2622 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2624 + TRACE("Directory inode %x:%x, start_block %x, offset "
2625 + "%x\n", SQUASHFS_INODE_BLK(inode),
2626 + offset, inodep->start_block,
2630 + case SQUASHFS_LDIR_TYPE: {
2631 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2632 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2634 + if (msblk->swap) {
2635 + if (!squashfs_get_cached_block(s, (char *)
2636 + sinodep, block, offset,
2637 + sizeof(*sinodep), &next_block,
2640 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2643 + if (!squashfs_get_cached_block(s, (char *)
2644 + inodep, block, offset,
2645 + sizeof(*inodep), &next_block,
2649 + i->i_size = inodep->file_size;
2650 + i->i_op = &squashfs_dir_inode_ops_2;
2651 + i->i_fop = &squashfs_dir_ops_2;
2652 + i->i_mode |= S_IFDIR;
2653 + i->i_mtime.tv_sec = inodep->mtime;
2654 + i->i_atime.tv_sec = inodep->mtime;
2655 + i->i_ctime.tv_sec = inodep->mtime;
2656 + SQUASHFS_I(i)->start_block = inodep->start_block;
2657 + SQUASHFS_I(i)->offset = inodep->offset;
2658 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2659 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2661 + SQUASHFS_I(i)->u.s2.directory_index_count =
2663 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2665 + TRACE("Long directory inode %x:%x, start_block %x, "
2667 + SQUASHFS_INODE_BLK(inode), offset,
2668 + inodep->start_block, inodep->offset);
2671 + case SQUASHFS_SYMLINK_TYPE: {
2672 + struct squashfs_symlink_inode_header_2 *inodep =
2674 + struct squashfs_symlink_inode_header_2 *sinodep =
2677 + if (msblk->swap) {
2678 + if (!squashfs_get_cached_block(s, (char *)
2679 + sinodep, block, offset,
2680 + sizeof(*sinodep), &next_block,
2683 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2686 + if (!squashfs_get_cached_block(s, (char *)
2687 + inodep, block, offset,
2688 + sizeof(*inodep), &next_block,
2692 + i->i_size = inodep->symlink_size;
2693 + i->i_op = &page_symlink_inode_operations;
2694 + i->i_data.a_ops = &squashfs_symlink_aops;
2695 + i->i_mode |= S_IFLNK;
2696 + SQUASHFS_I(i)->start_block = next_block;
2697 + SQUASHFS_I(i)->offset = next_offset;
2699 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2701 + SQUASHFS_INODE_BLK(inode), offset,
2702 + next_block, next_offset);
2705 + case SQUASHFS_BLKDEV_TYPE:
2706 + case SQUASHFS_CHRDEV_TYPE: {
2707 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2708 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2710 + if (msblk->swap) {
2711 + if (!squashfs_get_cached_block(s, (char *)
2712 + sinodep, block, offset,
2713 + sizeof(*sinodep), &next_block,
2716 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2718 + if (!squashfs_get_cached_block(s, (char *)
2719 + inodep, block, offset,
2720 + sizeof(*inodep), &next_block,
2724 + i->i_mode |= (inodeb->inode_type ==
2725 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2727 + init_special_inode(i, i->i_mode,
2728 + old_decode_dev(inodep->rdev));
2730 + TRACE("Device inode %x:%x, rdev %x\n",
2731 + SQUASHFS_INODE_BLK(inode), offset,
2735 + case SQUASHFS_FIFO_TYPE:
2736 + case SQUASHFS_SOCKET_TYPE: {
2738 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2739 + ? S_IFIFO : S_IFSOCK;
2740 + init_special_inode(i, i->i_mode, 0);
2744 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2745 + inodeb->inode_type);
2746 + goto failed_read1;
2752 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2759 +static int get_dir_index_using_offset(struct super_block *s, long long
2760 + *next_block, unsigned int *next_offset,
2761 + long long index_start,
2762 + unsigned int index_offset, int i_count,
2765 + struct squashfs_sb_info *msblk = s->s_fs_info;
2766 + struct squashfs_super_block *sblk = &msblk->sblk;
2767 + int i, length = 0;
2768 + struct squashfs_dir_index_2 index;
2770 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2771 + i_count, (unsigned int) f_pos);
2776 + for (i = 0; i < i_count; i++) {
2777 + if (msblk->swap) {
2778 + struct squashfs_dir_index_2 sindex;
2779 + squashfs_get_cached_block(s, (char *) &sindex,
2780 + index_start, index_offset,
2781 + sizeof(sindex), &index_start,
2783 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2785 + squashfs_get_cached_block(s, (char *) &index,
2786 + index_start, index_offset,
2787 + sizeof(index), &index_start,
2790 + if (index.index > f_pos)
2793 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2794 + index.size + 1, &index_start,
2797 + length = index.index;
2798 + *next_block = index.start_block + sblk->directory_table_start;
2801 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2808 +static int get_dir_index_using_name(struct super_block *s, long long
2809 + *next_block, unsigned int *next_offset,
2810 + long long index_start,
2811 + unsigned int index_offset, int i_count,
2812 + const char *name, int size)
2814 + struct squashfs_sb_info *msblk = s->s_fs_info;
2815 + struct squashfs_super_block *sblk = &msblk->sblk;
2816 + int i, length = 0;
2817 + struct squashfs_dir_index_2 *index;
2820 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2822 + if (!(str = kmalloc(sizeof(struct squashfs_dir_index) +
2823 + (SQUASHFS_NAME_LEN + 1) * 2, GFP_KERNEL))) {
2824 + ERROR("Failed to allocate squashfs_dir_index\n");
2828 + index = (struct squashfs_dir_index_2 *) (str + SQUASHFS_NAME_LEN + 1);
2829 + strncpy(str, name, size);
2832 + for (i = 0; i < i_count; i++) {
2833 + if (msblk->swap) {
2834 + struct squashfs_dir_index_2 sindex;
2835 + squashfs_get_cached_block(s, (char *) &sindex,
2836 + index_start, index_offset,
2837 + sizeof(sindex), &index_start,
2839 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2841 + squashfs_get_cached_block(s, (char *) index,
2842 + index_start, index_offset,
2843 + sizeof(struct squashfs_dir_index_2),
2844 + &index_start, &index_offset);
2846 + squashfs_get_cached_block(s, index->name, index_start,
2847 + index_offset, index->size + 1,
2848 + &index_start, &index_offset);
2850 + index->name[index->size + 1] = '\0';
2852 + if (strcmp(index->name, str) > 0)
2855 + length = index->index;
2856 + *next_block = index->start_block + sblk->directory_table_start;
2859 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2866 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2868 + struct inode *i = file->f_dentry->d_inode;
2869 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2870 + struct squashfs_super_block *sblk = &msblk->sblk;
2871 + long long next_block = SQUASHFS_I(i)->start_block +
2872 + sblk->directory_table_start;
2873 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2875 + struct squashfs_dir_header_2 dirh;
2876 + struct squashfs_dir_entry_2 *dire;
2878 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2880 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2881 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2882 + ERROR("Failed to allocate squashfs_dir_entry\n");
2886 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2887 + SQUASHFS_I(i)->u.s2.directory_index_start,
2888 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2889 + SQUASHFS_I(i)->u.s2.directory_index_count,
2892 + while (length < i_size_read(i)) {
2893 + /* read directory header */
2894 + if (msblk->swap) {
2895 + struct squashfs_dir_header_2 sdirh;
2897 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2898 + next_block, next_offset, sizeof(sdirh),
2899 + &next_block, &next_offset))
2902 + length += sizeof(sdirh);
2903 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2905 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2906 + next_block, next_offset, sizeof(dirh),
2907 + &next_block, &next_offset))
2910 + length += sizeof(dirh);
2913 + dir_count = dirh.count + 1;
2914 + while (dir_count--) {
2915 + if (msblk->swap) {
2916 + struct squashfs_dir_entry_2 sdire;
2917 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2918 + &sdire, next_block, next_offset,
2919 + sizeof(sdire), &next_block,
2923 + length += sizeof(sdire);
2924 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2926 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2927 + dire, next_block, next_offset,
2928 + sizeof(*dire), &next_block,
2932 + length += sizeof(*dire);
2935 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2936 + next_block, next_offset,
2937 + dire->size + 1, &next_block,
2941 + length += dire->size + 1;
2943 + if (file->f_pos >= length)
2946 + dire->name[dire->size + 1] = '\0';
2948 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2949 + (unsigned int) dirent, dire->name,
2950 + dire->size + 1, (int) file->f_pos,
2951 + dirh.start_block, dire->offset,
2952 + squashfs_filetype_table[dire->type]);
2954 + if (filldir(dirent, dire->name, dire->size + 1,
2955 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2956 + dirh.start_block, dire->offset),
2957 + squashfs_filetype_table[dire->type])
2959 + TRACE("Filldir returned less than 0\n");
2962 + file->f_pos = length;
2971 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2978 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2979 + struct nameidata *nd)
2981 + const unsigned char *name = dentry->d_name.name;
2982 + int len = dentry->d_name.len;
2983 + struct inode *inode = NULL;
2984 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2985 + struct squashfs_super_block *sblk = &msblk->sblk;
2986 + long long next_block = SQUASHFS_I(i)->start_block +
2987 + sblk->directory_table_start;
2988 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2990 + struct squashfs_dir_header_2 dirh;
2991 + struct squashfs_dir_entry_2 *dire;
2992 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2994 + TRACE("Entered squashfs_lookup_2 [%llx:%x]\n", next_block, next_offset);
2996 + if (!(dire = kmalloc(sizeof(struct squashfs_dir_entry) +
2997 + SQUASHFS_NAME_LEN + 1, GFP_KERNEL))) {
2998 + ERROR("Failed to allocate squashfs_dir_entry\n");
3002 + if (len > SQUASHFS_NAME_LEN)
3005 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
3006 + SQUASHFS_I(i)->u.s2.directory_index_start,
3007 + SQUASHFS_I(i)->u.s2.directory_index_offset,
3008 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
3011 + while (length < i_size_read(i)) {
3012 + /* read directory header */
3013 + if (msblk->swap) {
3014 + struct squashfs_dir_header_2 sdirh;
3015 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
3016 + next_block, next_offset, sizeof(sdirh),
3017 + &next_block, &next_offset))
3020 + length += sizeof(sdirh);
3021 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
3023 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
3024 + next_block, next_offset, sizeof(dirh),
3025 + &next_block, &next_offset))
3028 + length += sizeof(dirh);
3031 + dir_count = dirh.count + 1;
3032 + while (dir_count--) {
3033 + if (msblk->swap) {
3034 + struct squashfs_dir_entry_2 sdire;
3035 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3036 + &sdire, next_block,next_offset,
3037 + sizeof(sdire), &next_block,
3041 + length += sizeof(sdire);
3042 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
3044 + if (!squashfs_get_cached_block(i->i_sb, (char *)
3045 + dire, next_block,next_offset,
3046 + sizeof(*dire), &next_block,
3050 + length += sizeof(*dire);
3053 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
3054 + next_block, next_offset, dire->size + 1,
3055 + &next_block, &next_offset))
3058 + length += dire->size + 1;
3060 + if (sorted && name[0] < dire->name[0])
3063 + if ((len == dire->size + 1) && !strncmp(name,
3064 + dire->name, len)) {
3065 + squashfs_inode_t ino =
3066 + SQUASHFS_MKINODE(dirh.start_block,
3068 + unsigned int inode_number = SQUASHFS_MK_VFS_INODE(dirh.start_block,
3071 + TRACE("calling squashfs_iget for directory "
3072 + "entry %s, inode %x:%x, %lld\n", name,
3073 + dirh.start_block, dire->offset, ino);
3075 + inode = squashfs_iget(i->i_sb, ino, inode_number);
3084 + d_add(dentry, inode);
3085 + return ERR_PTR(0);
3088 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
3094 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3096 + struct squashfs_super_block *sblk = &msblk->sblk;
3098 + msblk->read_inode = squashfs_read_inode_2;
3099 + msblk->read_fragment_index_table = read_fragment_index_table_2;
3101 + sblk->bytes_used = sblk->bytes_used_2;
3102 + sblk->uid_start = sblk->uid_start_2;
3103 + sblk->guid_start = sblk->guid_start_2;
3104 + sblk->inode_table_start = sblk->inode_table_start_2;
3105 + sblk->directory_table_start = sblk->directory_table_start_2;
3106 + sblk->fragment_table_start = sblk->fragment_table_start_2;
3111 +++ b/include/linux/squashfs_fs.h
3113 +#ifndef SQUASHFS_FS
3114 +#define SQUASHFS_FS
3119 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
3120 + * Phillip Lougher <phillip@lougher.demon.co.uk>
3122 + * This program is free software; you can redistribute it and/or
3123 + * modify it under the terms of the GNU General Public License
3124 + * as published by the Free Software Foundation; either version 2,
3125 + * or (at your option) any later version.
3127 + * This program is distributed in the hope that it will be useful,
3128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3130 + * GNU General Public License for more details.
3132 + * You should have received a copy of the GNU General Public License
3133 + * along with this program; if not, write to the Free Software
3134 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3139 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3140 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3143 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3144 +#define SQUASHFS_MAJOR 3
3145 +#define SQUASHFS_MINOR 1
3146 +#define SQUASHFS_MAGIC 0x73717368
3147 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3148 +#define SQUASHFS_START 0
3150 +/* size of metadata (inode and directory) blocks */
3151 +#define SQUASHFS_METADATA_SIZE 8192
3152 +#define SQUASHFS_METADATA_LOG 13
3154 +/* default size of data blocks */
3155 +#define SQUASHFS_FILE_SIZE 131072
3156 +#define SQUASHFS_FILE_LOG 17
3158 +#define SQUASHFS_FILE_MAX_SIZE 1048576
3160 +/* Max number of uids and gids */
3161 +#define SQUASHFS_UIDS 256
3162 +#define SQUASHFS_GUIDS 255
3164 +/* Max length of filename (not 255) */
3165 +#define SQUASHFS_NAME_LEN 256
3167 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3168 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3169 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3170 +#define SQUASHFS_USED_BLK ((long long) -2)
3172 +/* Filesystem flags */
3173 +#define SQUASHFS_NOI 0
3174 +#define SQUASHFS_NOD 1
3175 +#define SQUASHFS_CHECK 2
3176 +#define SQUASHFS_NOF 3
3177 +#define SQUASHFS_NO_FRAG 4
3178 +#define SQUASHFS_ALWAYS_FRAG 5
3179 +#define SQUASHFS_DUPLICATE 6
3180 +#define SQUASHFS_EXPORT 7
3182 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3184 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3187 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3190 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3193 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3196 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3197 + SQUASHFS_ALWAYS_FRAG)
3199 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3200 + SQUASHFS_DUPLICATE)
3202 +#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
3205 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3208 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3209 + duplicate_checking, exportable) (noi | (nod << 1) | (check_data << 2) \
3210 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3211 + (duplicate_checking << 6) | (exportable << 7))
3213 +/* Max number of types and file types */
3214 +#define SQUASHFS_DIR_TYPE 1
3215 +#define SQUASHFS_FILE_TYPE 2
3216 +#define SQUASHFS_SYMLINK_TYPE 3
3217 +#define SQUASHFS_BLKDEV_TYPE 4
3218 +#define SQUASHFS_CHRDEV_TYPE 5
3219 +#define SQUASHFS_FIFO_TYPE 6
3220 +#define SQUASHFS_SOCKET_TYPE 7
3221 +#define SQUASHFS_LDIR_TYPE 8
3222 +#define SQUASHFS_LREG_TYPE 9
3224 +/* 1.0 filesystem type definitions */
3225 +#define SQUASHFS_TYPES 5
3226 +#define SQUASHFS_IPC_TYPE 0
3228 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3230 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3232 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3233 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3235 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3237 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3239 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) ((B) & \
3240 + ~SQUASHFS_COMPRESSED_BIT_BLOCK)
3242 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3245 + * Inode number ops. Inodes consist of a compressed block number, and an
3246 + * uncompressed offset within that block
3248 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3250 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3252 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3255 +/* Compute 32 bit VFS inode number from squashfs inode number */
3256 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3260 +/* Translate between VFS mode and squashfs mode */
3261 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3263 +/* fragment and fragment table defines */
3264 +#define SQUASHFS_FRAGMENT_BYTES(A) ((A) * sizeof(struct squashfs_fragment_entry))
3266 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3267 + SQUASHFS_METADATA_SIZE)
3269 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3270 + SQUASHFS_METADATA_SIZE)
3272 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3273 + SQUASHFS_METADATA_SIZE - 1) / \
3274 + SQUASHFS_METADATA_SIZE)
3276 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3277 + sizeof(long long))
3279 +/* inode lookup table defines */
3280 +#define SQUASHFS_LOOKUP_BYTES(A) ((A) * sizeof(squashfs_inode_t))
3282 +#define SQUASHFS_LOOKUP_BLOCK(A) (SQUASHFS_LOOKUP_BYTES(A) / \
3283 + SQUASHFS_METADATA_SIZE)
3285 +#define SQUASHFS_LOOKUP_BLOCK_OFFSET(A) (SQUASHFS_LOOKUP_BYTES(A) % \
3286 + SQUASHFS_METADATA_SIZE)
3288 +#define SQUASHFS_LOOKUP_BLOCKS(A) ((SQUASHFS_LOOKUP_BYTES(A) + \
3289 + SQUASHFS_METADATA_SIZE - 1) / \
3290 + SQUASHFS_METADATA_SIZE)
3292 +#define SQUASHFS_LOOKUP_BLOCK_BYTES(A) (SQUASHFS_LOOKUP_BLOCKS(A) *\
3293 + sizeof(long long))
3295 +/* cached data constants for filesystem */
3296 +#define SQUASHFS_CACHED_BLKS 8
3298 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3300 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3301 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3303 +#define SQUASHFS_MARKER_BYTE 0xff
3305 +/* meta index cache */
3306 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3307 +#define SQUASHFS_META_ENTRIES 31
3308 +#define SQUASHFS_META_NUMBER 8
3309 +#define SQUASHFS_SLOTS 4
3311 +struct meta_entry {
3312 + long long data_block;
3313 + unsigned int index_block;
3314 + unsigned short offset;
3315 + unsigned short pad;
3318 +struct meta_index {
3319 + unsigned int inode_number;
3320 + unsigned int offset;
3321 + unsigned short entries;
3322 + unsigned short skip;
3323 + unsigned short locked;
3324 + unsigned short pad;
3325 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3330 + * definitions for structures on disk
3333 +typedef long long squashfs_block_t;
3334 +typedef long long squashfs_inode_t;
3336 +struct squashfs_super_block {
3337 + unsigned int s_magic;
3338 + unsigned int inodes;
3339 + unsigned int bytes_used_2;
3340 + unsigned int uid_start_2;
3341 + unsigned int guid_start_2;
3342 + unsigned int inode_table_start_2;
3343 + unsigned int directory_table_start_2;
3344 + unsigned int s_major:16;
3345 + unsigned int s_minor:16;
3346 + unsigned int block_size_1:16;
3347 + unsigned int block_log:16;
3348 + unsigned int flags:8;
3349 + unsigned int no_uids:8;
3350 + unsigned int no_guids:8;
3351 + unsigned int mkfs_time /* time of filesystem creation */;
3352 + squashfs_inode_t root_inode;
3353 + unsigned int block_size;
3354 + unsigned int fragments;
3355 + unsigned int fragment_table_start_2;
3356 + long long bytes_used;
3357 + long long uid_start;
3358 + long long guid_start;
3359 + long long inode_table_start;
3360 + long long directory_table_start;
3361 + long long fragment_table_start;
3362 + long long lookup_table_start;
3363 +} __attribute__ ((packed));
3365 +struct squashfs_dir_index {
3366 + unsigned int index;
3367 + unsigned int start_block;
3368 + unsigned char size;
3369 + unsigned char name[0];
3370 +} __attribute__ ((packed));
3372 +#define SQUASHFS_BASE_INODE_HEADER \
3373 + unsigned int inode_type:4; \
3374 + unsigned int mode:12; \
3375 + unsigned int uid:8; \
3376 + unsigned int guid:8; \
3377 + unsigned int mtime; \
3378 + unsigned int inode_number;
3380 +struct squashfs_base_inode_header {
3381 + SQUASHFS_BASE_INODE_HEADER;
3382 +} __attribute__ ((packed));
3384 +struct squashfs_ipc_inode_header {
3385 + SQUASHFS_BASE_INODE_HEADER;
3386 + unsigned int nlink;
3387 +} __attribute__ ((packed));
3389 +struct squashfs_dev_inode_header {
3390 + SQUASHFS_BASE_INODE_HEADER;
3391 + unsigned int nlink;
3392 + unsigned short rdev;
3393 +} __attribute__ ((packed));
3395 +struct squashfs_symlink_inode_header {
3396 + SQUASHFS_BASE_INODE_HEADER;
3397 + unsigned int nlink;
3398 + unsigned short symlink_size;
3400 +} __attribute__ ((packed));
3402 +struct squashfs_reg_inode_header {
3403 + SQUASHFS_BASE_INODE_HEADER;
3404 + squashfs_block_t start_block;
3405 + unsigned int fragment;
3406 + unsigned int offset;
3407 + unsigned int file_size;
3408 + unsigned short block_list[0];
3409 +} __attribute__ ((packed));
3411 +struct squashfs_lreg_inode_header {
3412 + SQUASHFS_BASE_INODE_HEADER;
3413 + unsigned int nlink;
3414 + squashfs_block_t start_block;
3415 + unsigned int fragment;
3416 + unsigned int offset;
3417 + long long file_size;
3418 + unsigned short block_list[0];
3419 +} __attribute__ ((packed));
3421 +struct squashfs_dir_inode_header {
3422 + SQUASHFS_BASE_INODE_HEADER;
3423 + unsigned int nlink;
3424 + unsigned int file_size:19;
3425 + unsigned int offset:13;
3426 + unsigned int start_block;
3427 + unsigned int parent_inode;
3428 +} __attribute__ ((packed));
3430 +struct squashfs_ldir_inode_header {
3431 + SQUASHFS_BASE_INODE_HEADER;
3432 + unsigned int nlink;
3433 + unsigned int file_size:27;
3434 + unsigned int offset:13;
3435 + unsigned int start_block;
3436 + unsigned int i_count:16;
3437 + unsigned int parent_inode;
3438 + struct squashfs_dir_index index[0];
3439 +} __attribute__ ((packed));
3441 +union squashfs_inode_header {
3442 + struct squashfs_base_inode_header base;
3443 + struct squashfs_dev_inode_header dev;
3444 + struct squashfs_symlink_inode_header symlink;
3445 + struct squashfs_reg_inode_header reg;
3446 + struct squashfs_lreg_inode_header lreg;
3447 + struct squashfs_dir_inode_header dir;
3448 + struct squashfs_ldir_inode_header ldir;
3449 + struct squashfs_ipc_inode_header ipc;
3452 +struct squashfs_dir_entry {
3453 + unsigned int offset:13;
3454 + unsigned int type:3;
3455 + unsigned int size:8;
3456 + int inode_number:16;
3458 +} __attribute__ ((packed));
3460 +struct squashfs_dir_header {
3461 + unsigned int count:8;
3462 + unsigned int start_block;
3463 + unsigned int inode_number;
3464 +} __attribute__ ((packed));
3466 +struct squashfs_fragment_entry {
3467 + long long start_block;
3468 + unsigned int size;
3469 + unsigned int unused;
3470 +} __attribute__ ((packed));
3472 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3473 +extern int squashfs_uncompress_init(void);
3474 +extern int squashfs_uncompress_exit(void);
3477 + * macros to convert each packed bitfield structure from little endian to big
3478 + * endian and vice versa. These are needed when creating or using a filesystem
3479 + * on a machine with different byte ordering to the target architecture.
3483 +#define SQUASHFS_SWAP_START \
3486 + unsigned long long val;\
3487 + unsigned char *s;\
3490 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3491 + SQUASHFS_SWAP_START\
3492 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3493 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3494 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3495 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3496 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3497 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3498 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3499 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3500 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3501 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3502 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3503 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3504 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3505 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3506 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3507 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3508 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3509 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3510 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3511 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3512 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3513 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3514 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3515 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3516 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3517 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3518 + SQUASHFS_SWAP((s)->lookup_table_start, d, 888, 64);\
3521 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3522 + SQUASHFS_MEMSET(s, d, n);\
3523 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3524 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3525 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3526 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3527 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3528 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3530 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3531 + SQUASHFS_SWAP_START\
3532 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3535 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3536 + SQUASHFS_SWAP_START\
3537 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3538 + sizeof(struct squashfs_ipc_inode_header))\
3539 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3542 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3543 + SQUASHFS_SWAP_START\
3544 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3545 + sizeof(struct squashfs_dev_inode_header)); \
3546 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3547 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3550 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3551 + SQUASHFS_SWAP_START\
3552 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3553 + sizeof(struct squashfs_symlink_inode_header));\
3554 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3555 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3558 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3559 + SQUASHFS_SWAP_START\
3560 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3561 + sizeof(struct squashfs_reg_inode_header));\
3562 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3563 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3564 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3565 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3568 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3569 + SQUASHFS_SWAP_START\
3570 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3571 + sizeof(struct squashfs_lreg_inode_header));\
3572 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3573 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3574 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3575 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3576 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3579 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3580 + SQUASHFS_SWAP_START\
3581 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3582 + sizeof(struct squashfs_dir_inode_header));\
3583 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3584 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3585 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3586 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3587 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3590 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3591 + SQUASHFS_SWAP_START\
3592 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3593 + sizeof(struct squashfs_ldir_inode_header));\
3594 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3595 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3596 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3597 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3598 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3599 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3602 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3603 + SQUASHFS_SWAP_START\
3604 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3605 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3606 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3607 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3610 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3611 + SQUASHFS_SWAP_START\
3612 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3613 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3614 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3615 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3618 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3619 + SQUASHFS_SWAP_START\
3620 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3621 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3622 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3623 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3624 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3627 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3628 + SQUASHFS_SWAP_START\
3629 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3630 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3631 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3634 +#define SQUASHFS_SWAP_INODE_T(s, d) SQUASHFS_SWAP_LONG_LONGS(s, d, 1)
3636 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3638 + int bit_position;\
3639 + SQUASHFS_SWAP_START\
3640 + SQUASHFS_MEMSET(s, d, n * 2);\
3641 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3643 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3646 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3648 + int bit_position;\
3649 + SQUASHFS_SWAP_START\
3650 + SQUASHFS_MEMSET(s, d, n * 4);\
3651 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3653 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3656 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3658 + int bit_position;\
3659 + SQUASHFS_SWAP_START\
3660 + SQUASHFS_MEMSET(s, d, n * 8);\
3661 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3663 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3666 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3668 + int bit_position;\
3669 + SQUASHFS_SWAP_START\
3670 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3671 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3673 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3676 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3677 +#define SQUASHFS_SWAP_LOOKUP_BLOCKS(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3679 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3681 +struct squashfs_base_inode_header_1 {
3682 + unsigned int inode_type:4;
3683 + unsigned int mode:12; /* protection */
3684 + unsigned int uid:4; /* index into uid table */
3685 + unsigned int guid:4; /* index into guid table */
3686 +} __attribute__ ((packed));
3688 +struct squashfs_ipc_inode_header_1 {
3689 + unsigned int inode_type:4;
3690 + unsigned int mode:12; /* protection */
3691 + unsigned int uid:4; /* index into uid table */
3692 + unsigned int guid:4; /* index into guid table */
3693 + unsigned int type:4;
3694 + unsigned int offset:4;
3695 +} __attribute__ ((packed));
3697 +struct squashfs_dev_inode_header_1 {
3698 + unsigned int inode_type:4;
3699 + unsigned int mode:12; /* protection */
3700 + unsigned int uid:4; /* index into uid table */
3701 + unsigned int guid:4; /* index into guid table */
3702 + unsigned short rdev;
3703 +} __attribute__ ((packed));
3705 +struct squashfs_symlink_inode_header_1 {
3706 + unsigned int inode_type:4;
3707 + unsigned int mode:12; /* protection */
3708 + unsigned int uid:4; /* index into uid table */
3709 + unsigned int guid:4; /* index into guid table */
3710 + unsigned short symlink_size;
3712 +} __attribute__ ((packed));
3714 +struct squashfs_reg_inode_header_1 {
3715 + unsigned int inode_type:4;
3716 + unsigned int mode:12; /* protection */
3717 + unsigned int uid:4; /* index into uid table */
3718 + unsigned int guid:4; /* index into guid table */
3719 + unsigned int mtime;
3720 + unsigned int start_block;
3721 + unsigned int file_size:32;
3722 + unsigned short block_list[0];
3723 +} __attribute__ ((packed));
3725 +struct squashfs_dir_inode_header_1 {
3726 + unsigned int inode_type:4;
3727 + unsigned int mode:12; /* protection */
3728 + unsigned int uid:4; /* index into uid table */
3729 + unsigned int guid:4; /* index into guid table */
3730 + unsigned int file_size:19;
3731 + unsigned int offset:13;
3732 + unsigned int mtime;
3733 + unsigned int start_block:24;
3734 +} __attribute__ ((packed));
3736 +union squashfs_inode_header_1 {
3737 + struct squashfs_base_inode_header_1 base;
3738 + struct squashfs_dev_inode_header_1 dev;
3739 + struct squashfs_symlink_inode_header_1 symlink;
3740 + struct squashfs_reg_inode_header_1 reg;
3741 + struct squashfs_dir_inode_header_1 dir;
3742 + struct squashfs_ipc_inode_header_1 ipc;
3745 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3746 + SQUASHFS_MEMSET(s, d, n);\
3747 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3748 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3749 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3750 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3752 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3753 + SQUASHFS_SWAP_START\
3754 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3757 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3758 + SQUASHFS_SWAP_START\
3759 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3760 + sizeof(struct squashfs_ipc_inode_header_1));\
3761 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3762 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3765 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3766 + SQUASHFS_SWAP_START\
3767 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3768 + sizeof(struct squashfs_dev_inode_header_1));\
3769 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3772 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3773 + SQUASHFS_SWAP_START\
3774 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3775 + sizeof(struct squashfs_symlink_inode_header_1));\
3776 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3779 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3780 + SQUASHFS_SWAP_START\
3781 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3782 + sizeof(struct squashfs_reg_inode_header_1));\
3783 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3784 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3785 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3788 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3789 + SQUASHFS_SWAP_START\
3790 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3791 + sizeof(struct squashfs_dir_inode_header_1));\
3792 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3793 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3794 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3795 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3800 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3802 +struct squashfs_dir_index_2 {
3803 + unsigned int index:27;
3804 + unsigned int start_block:29;
3805 + unsigned char size;
3806 + unsigned char name[0];
3807 +} __attribute__ ((packed));
3809 +struct squashfs_base_inode_header_2 {
3810 + unsigned int inode_type:4;
3811 + unsigned int mode:12; /* protection */
3812 + unsigned int uid:8; /* index into uid table */
3813 + unsigned int guid:8; /* index into guid table */
3814 +} __attribute__ ((packed));
3816 +struct squashfs_ipc_inode_header_2 {
3817 + unsigned int inode_type:4;
3818 + unsigned int mode:12; /* protection */
3819 + unsigned int uid:8; /* index into uid table */
3820 + unsigned int guid:8; /* index into guid table */
3821 +} __attribute__ ((packed));
3823 +struct squashfs_dev_inode_header_2 {
3824 + unsigned int inode_type:4;
3825 + unsigned int mode:12; /* protection */
3826 + unsigned int uid:8; /* index into uid table */
3827 + unsigned int guid:8; /* index into guid table */
3828 + unsigned short rdev;
3829 +} __attribute__ ((packed));
3831 +struct squashfs_symlink_inode_header_2 {
3832 + unsigned int inode_type:4;
3833 + unsigned int mode:12; /* protection */
3834 + unsigned int uid:8; /* index into uid table */
3835 + unsigned int guid:8; /* index into guid table */
3836 + unsigned short symlink_size;
3838 +} __attribute__ ((packed));
3840 +struct squashfs_reg_inode_header_2 {
3841 + unsigned int inode_type:4;
3842 + unsigned int mode:12; /* protection */
3843 + unsigned int uid:8; /* index into uid table */
3844 + unsigned int guid:8; /* index into guid table */
3845 + unsigned int mtime;
3846 + unsigned int start_block;
3847 + unsigned int fragment;
3848 + unsigned int offset;
3849 + unsigned int file_size:32;
3850 + unsigned short block_list[0];
3851 +} __attribute__ ((packed));
3853 +struct squashfs_dir_inode_header_2 {
3854 + unsigned int inode_type:4;
3855 + unsigned int mode:12; /* protection */
3856 + unsigned int uid:8; /* index into uid table */
3857 + unsigned int guid:8; /* index into guid table */
3858 + unsigned int file_size:19;
3859 + unsigned int offset:13;
3860 + unsigned int mtime;
3861 + unsigned int start_block:24;
3862 +} __attribute__ ((packed));
3864 +struct squashfs_ldir_inode_header_2 {
3865 + unsigned int inode_type:4;
3866 + unsigned int mode:12; /* protection */
3867 + unsigned int uid:8; /* index into uid table */
3868 + unsigned int guid:8; /* index into guid table */
3869 + unsigned int file_size:27;
3870 + unsigned int offset:13;
3871 + unsigned int mtime;
3872 + unsigned int start_block:24;
3873 + unsigned int i_count:16;
3874 + struct squashfs_dir_index_2 index[0];
3875 +} __attribute__ ((packed));
3877 +union squashfs_inode_header_2 {
3878 + struct squashfs_base_inode_header_2 base;
3879 + struct squashfs_dev_inode_header_2 dev;
3880 + struct squashfs_symlink_inode_header_2 symlink;
3881 + struct squashfs_reg_inode_header_2 reg;
3882 + struct squashfs_dir_inode_header_2 dir;
3883 + struct squashfs_ldir_inode_header_2 ldir;
3884 + struct squashfs_ipc_inode_header_2 ipc;
3887 +struct squashfs_dir_header_2 {
3888 + unsigned int count:8;
3889 + unsigned int start_block:24;
3890 +} __attribute__ ((packed));
3892 +struct squashfs_dir_entry_2 {
3893 + unsigned int offset:13;
3894 + unsigned int type:3;
3895 + unsigned int size:8;
3897 +} __attribute__ ((packed));
3899 +struct squashfs_fragment_entry_2 {
3900 + unsigned int start_block;
3901 + unsigned int size;
3902 +} __attribute__ ((packed));
3904 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3905 + SQUASHFS_MEMSET(s, d, n);\
3906 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3907 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3908 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3909 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3911 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3912 + SQUASHFS_SWAP_START\
3913 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3916 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3917 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3919 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3920 + SQUASHFS_SWAP_START\
3921 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3922 + sizeof(struct squashfs_dev_inode_header_2)); \
3923 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3926 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3927 + SQUASHFS_SWAP_START\
3928 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3929 + sizeof(struct squashfs_symlink_inode_header_2));\
3930 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3933 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3934 + SQUASHFS_SWAP_START\
3935 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3936 + sizeof(struct squashfs_reg_inode_header_2));\
3937 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3938 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3939 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3940 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3941 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3944 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3945 + SQUASHFS_SWAP_START\
3946 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3947 + sizeof(struct squashfs_dir_inode_header_2));\
3948 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3949 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3950 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3951 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3954 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3955 + SQUASHFS_SWAP_START\
3956 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3957 + sizeof(struct squashfs_ldir_inode_header_2));\
3958 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3959 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3960 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3961 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3962 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3965 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3966 + SQUASHFS_SWAP_START\
3967 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3968 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3969 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3970 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3972 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3973 + SQUASHFS_SWAP_START\
3974 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3975 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3976 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3979 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3980 + SQUASHFS_SWAP_START\
3981 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3982 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3983 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3984 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3987 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3988 + SQUASHFS_SWAP_START\
3989 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3990 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3991 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3994 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3996 +/* fragment and fragment table defines */
3997 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3999 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
4000 + SQUASHFS_METADATA_SIZE)
4002 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
4003 + SQUASHFS_METADATA_SIZE)
4005 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
4006 + SQUASHFS_METADATA_SIZE - 1) / \
4007 + SQUASHFS_METADATA_SIZE)
4009 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
4017 + * macros used to swap each structure entry, taking into account
4018 + * bitfields and different bitfield placing conventions on differing
4022 +#include <asm/byteorder.h>
4024 +#ifdef __BIG_ENDIAN
4025 + /* convert from little endian to big endian */
4026 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4029 + /* convert from big endian to little endian */
4030 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
4031 + tbits, 64 - tbits - b_pos)
4034 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4037 + s = (unsigned char *)p + (pos / 8);\
4038 + d = ((unsigned char *) &val) + 7;\
4039 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4041 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4044 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
4049 +++ b/include/linux/squashfs_fs_i.h
4051 +#ifndef SQUASHFS_FS_I
4052 +#define SQUASHFS_FS_I
4056 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4057 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4059 + * This program is free software; you can redistribute it and/or
4060 + * modify it under the terms of the GNU General Public License
4061 + * as published by the Free Software Foundation; either version 2,
4062 + * or (at your option) any later version.
4064 + * This program is distributed in the hope that it will be useful,
4065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4067 + * GNU General Public License for more details.
4069 + * You should have received a copy of the GNU General Public License
4070 + * along with this program; if not, write to the Free Software
4071 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4076 +struct squashfs_inode_info {
4077 + long long start_block;
4078 + unsigned int offset;
4081 + long long fragment_start_block;
4082 + unsigned int fragment_size;
4083 + unsigned int fragment_offset;
4084 + long long block_list_start;
4087 + long long directory_index_start;
4088 + unsigned int directory_index_offset;
4089 + unsigned int directory_index_count;
4090 + unsigned int parent_inode;
4093 + struct inode vfs_inode;
4097 +++ b/include/linux/squashfs_fs_sb.h
4099 +#ifndef SQUASHFS_FS_SB
4100 +#define SQUASHFS_FS_SB
4104 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4105 + * Phillip Lougher <phillip@lougher.demon.co.uk>
4107 + * This program is free software; you can redistribute it and/or
4108 + * modify it under the terms of the GNU General Public License
4109 + * as published by the Free Software Foundation; either version 2,
4110 + * or (at your option) any later version.
4112 + * This program is distributed in the hope that it will be useful,
4113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4115 + * GNU General Public License for more details.
4117 + * You should have received a copy of the GNU General Public License
4118 + * along with this program; if not, write to the Free Software
4119 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4121 + * squashfs_fs_sb.h
4124 +#include <linux/squashfs_fs.h>
4126 +struct squashfs_cache_entry {
4130 + long long next_index;
4134 + wait_queue_head_t wait_queue;
4138 +struct squashfs_cache {
4147 + wait_queue_head_t wait_queue;
4148 + struct squashfs_cache_entry entry[0];
4151 +struct squashfs_sb_info {
4152 + struct squashfs_super_block sblk;
4154 + int devblksize_log2;
4156 + struct squashfs_cache *block_cache;
4157 + struct squashfs_cache *fragment_cache;
4158 + int next_meta_index;
4159 + unsigned int *uid;
4160 + unsigned int *guid;
4161 + long long *fragment_index;
4162 + unsigned int *fragment_index_2;
4164 + struct mutex read_data_mutex;
4165 + struct mutex read_page_mutex;
4166 + struct mutex meta_index_mutex;
4167 + struct meta_index *meta_index;
4169 + long long *inode_lookup_table;
4170 + int (*read_inode)(struct inode *i, squashfs_inode_t \
4172 + long long (*read_blocklist)(struct inode *inode, int \
4173 + index, int readahead_blks, char *block_list, \
4174 + unsigned short **block_p, unsigned int *bsize);
4175 + int (*read_fragment_index_table)(struct super_block *s);
4178 --- a/init/do_mounts_rd.c
4179 +++ b/init/do_mounts_rd.c
4181 #include <linux/ext2_fs.h>
4182 #include <linux/romfs_fs.h>
4183 #include <linux/cramfs_fs.h>
4184 +#include <linux/squashfs_fs.h>
4185 #include <linux/initrd.h>
4186 #include <linux/string.h>
4188 @@ -37,6 +38,7 @@ static int __init crd_load(int in_fd, in
4189 * numbers could not be found.
4191 * We currently check for the following magic numbers:
4196 @@ -51,6 +53,7 @@ identify_ramdisk_image(int fd, int start
4197 struct ext2_super_block *ext2sb;
4198 struct romfs_super_block *romfsb;
4199 struct cramfs_super *cramfsb;
4200 + struct squashfs_super_block *squashfsb;
4204 @@ -62,6 +65,7 @@ identify_ramdisk_image(int fd, int start
4205 ext2sb = (struct ext2_super_block *) buf;
4206 romfsb = (struct romfs_super_block *) buf;
4207 cramfsb = (struct cramfs_super *) buf;
4208 + squashfsb = (struct squashfs_super_block *) buf;
4209 memset(buf, 0xe5, size);
4212 @@ -99,6 +103,18 @@ identify_ramdisk_image(int fd, int start
4216 + /* squashfs is at block zero too */
4217 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4218 + printk(KERN_NOTICE
4219 + "RAMDISK: squashfs filesystem found at block %d\n",
4221 + if (squashfsb->s_major < 3)
4222 + nblocks = (squashfsb->bytes_used_2+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4224 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4229 * Read block 1 to test for minix and ext2 superblock