3 @@ -1371,6 +1371,71 @@ config CRAMFS
8 + tristate "SquashFS 3.0 - Squashed file system support"
11 + Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
12 + System). Squashfs is a highly compressed read-only filesystem for Linux.
13 + It uses zlib compression to compress both files, inodes and directories.
14 + Inodes in the system are very small and all blocks are packed to minimise
15 + data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
16 + SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
17 + uid/gid information, hard links and timestamps.
19 + Squashfs is intended for general read-only filesystem use, for archival
20 + use (i.e. in cases where a .tar.gz file may be used), and in embedded
21 + systems where low overhead is needed. Further information and filesystem tools
22 + are available from http://squashfs.sourceforge.net.
24 + If you want to compile this as a module ( = code which can be
25 + inserted in and removed from the running kernel whenever you want),
26 + say M here and read <file:Documentation/modules.txt>. The module
27 + will be called squashfs. Note that the root file system (the one
28 + containing the directory /) cannot be compiled as a module.
32 +config SQUASHFS_EMBEDDED
34 + bool "Additional options for memory-constrained systems"
38 + Saying Y here allows you to specify cache sizes and how Squashfs
39 + allocates memory. This is only intended for memory constrained
44 +config SQUASHFS_FRAGMENT_CACHE_SIZE
45 + int "Number of fragments cached" if SQUASHFS_EMBEDDED
49 + By default SquashFS caches the last 3 fragments read from
50 + the filesystem. Increasing this amount may mean SquashFS
51 + has to re-read fragments less often from disk, at the expense
52 + of extra system memory. Decreasing this amount will mean
53 + SquashFS uses less memory at the expense of extra reads from disk.
55 + Note there must be at least one cached fragment. Anything
56 + much more than three will probably not make much difference.
58 +config SQUASHFS_VMALLOC
59 + bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
63 + By default SquashFS uses kmalloc to obtain fragment cache memory.
64 + Kmalloc memory is the standard kernel allocator, but it can fail
65 + on memory constrained systems. Because of the way Vmalloc works,
66 + Vmalloc can succeed when kmalloc fails. Specifying this option
67 + will make SquashFS always use Vmalloc to allocate the
68 + fragment cache memory.
73 tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
77 @@ -68,6 +68,7 @@ obj-$(CONFIG_JBD) += jbd/
78 obj-$(CONFIG_JBD2) += jbd2/
79 obj-$(CONFIG_EXT2_FS) += ext2/
80 obj-$(CONFIG_CRAMFS) += cramfs/
81 +obj-$(CONFIG_SQUASHFS) += squashfs/
82 obj-$(CONFIG_RAMFS) += ramfs/
83 obj-$(CONFIG_HUGETLBFS) += hugetlbfs/
84 obj-$(CONFIG_CODA_FS) += coda/
86 +++ b/fs/squashfs/inode.c
89 + * Squashfs - a compressed read only filesystem for Linux
91 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
92 + * Phillip Lougher <phillip@lougher.org.uk>
94 + * This program is free software; you can redistribute it and/or
95 + * modify it under the terms of the GNU General Public License
96 + * as published by the Free Software Foundation; either version 2,
97 + * or (at your option) any later version.
99 + * This program is distributed in the hope that it will be useful,
100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102 + * GNU General Public License for more details.
104 + * You should have received a copy of the GNU General Public License
105 + * along with this program; if not, write to the Free Software
106 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
111 +#include <linux/types.h>
112 +#include <linux/squashfs_fs.h>
113 +#include <linux/module.h>
114 +#include <linux/errno.h>
115 +#include <linux/slab.h>
116 +#include <linux/fs.h>
117 +#include <linux/smp_lock.h>
118 +#include <linux/slab.h>
119 +#include <linux/squashfs_fs_sb.h>
120 +#include <linux/squashfs_fs_i.h>
121 +#include <linux/buffer_head.h>
122 +#include <linux/vfs.h>
123 +#include <linux/init.h>
124 +#include <linux/dcache.h>
125 +#include <linux/wait.h>
126 +#include <linux/zlib.h>
127 +#include <linux/blkdev.h>
128 +#include <linux/vmalloc.h>
129 +#include <asm/uaccess.h>
130 +#include <asm/semaphore.h>
132 +#include "squashfs.h"
134 +static void squashfs_put_super(struct super_block *);
135 +static int squashfs_statfs(struct dentry *, struct kstatfs *);
136 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
137 +static int squashfs_readpage(struct file *file, struct page *page);
138 +static int squashfs_readpage4K(struct file *file, struct page *page);
139 +static int squashfs_readdir(struct file *, void *, filldir_t);
140 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
141 +static void squashfs_destroy_inode(struct inode *inode);
142 +static int init_inodecache(void);
143 +static void destroy_inodecache(void);
144 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
145 + struct nameidata *);
146 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
147 +static long long read_blocklist(struct inode *inode, int index,
148 + int readahead_blks, char *block_list,
149 + unsigned short **block_p, unsigned int *bsize);
150 +static int squashfs_get_sb(struct file_system_type *, int,
151 + const char *, void *, struct vfsmount *);
154 +static z_stream stream;
156 +static struct file_system_type squashfs_fs_type = {
157 + .owner = THIS_MODULE,
158 + .name = "squashfs",
159 + .get_sb = squashfs_get_sb,
160 + .kill_sb = kill_block_super,
161 + .fs_flags = FS_REQUIRES_DEV
164 +static unsigned char squashfs_filetype_table[] = {
165 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
168 +static struct super_operations squashfs_ops = {
169 + .alloc_inode = squashfs_alloc_inode,
170 + .destroy_inode = squashfs_destroy_inode,
171 + .statfs = squashfs_statfs,
172 + .put_super = squashfs_put_super,
175 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
176 + .readpage = squashfs_symlink_readpage
179 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
180 + .readpage = squashfs_readpage
183 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
184 + .readpage = squashfs_readpage4K
187 +static struct file_operations squashfs_dir_ops = {
188 + .read = generic_read_dir,
189 + .readdir = squashfs_readdir
192 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
193 + .lookup = squashfs_lookup
197 +static struct buffer_head *get_block_length(struct super_block *s,
198 + int *cur_index, int *offset, int *c_byte)
200 + struct squashfs_sb_info *msblk = s->s_fs_info;
201 + unsigned short temp;
202 + struct buffer_head *bh;
204 + if (!(bh = sb_bread(s, *cur_index)))
207 + if (msblk->devblksize - *offset == 1) {
209 + ((unsigned char *) &temp)[1] = *((unsigned char *)
210 + (bh->b_data + *offset));
212 + ((unsigned char *) &temp)[0] = *((unsigned char *)
213 + (bh->b_data + *offset));
215 + if (!(bh = sb_bread(s, ++(*cur_index))))
218 + ((unsigned char *) &temp)[0] = *((unsigned char *)
221 + ((unsigned char *) &temp)[1] = *((unsigned char *)
227 + ((unsigned char *) &temp)[1] = *((unsigned char *)
228 + (bh->b_data + *offset));
229 + ((unsigned char *) &temp)[0] = *((unsigned char *)
230 + (bh->b_data + *offset + 1));
232 + ((unsigned char *) &temp)[0] = *((unsigned char *)
233 + (bh->b_data + *offset));
234 + ((unsigned char *) &temp)[1] = *((unsigned char *)
235 + (bh->b_data + *offset + 1));
241 + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
242 + if (*offset == msblk->devblksize) {
244 + if (!(bh = sb_bread(s, ++(*cur_index))))
248 + if (*((unsigned char *) (bh->b_data + *offset)) !=
249 + SQUASHFS_MARKER_BYTE) {
250 + ERROR("Metadata block marker corrupt @ %x\n",
264 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
265 + long long index, unsigned int length,
266 + long long *next_index)
268 + struct squashfs_sb_info *msblk = s->s_fs_info;
269 + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
270 + msblk->devblksize_log2) + 2];
271 + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
272 + unsigned int cur_index = index >> msblk->devblksize_log2;
273 + int bytes, avail_bytes, b = 0, k;
275 + unsigned int compressed;
276 + unsigned int c_byte = length;
279 + bytes = msblk->devblksize - offset;
280 + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
281 + c_buffer = compressed ? msblk->read_data : buffer;
282 + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
284 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
285 + ? "" : "un", (unsigned int) c_byte);
287 + if (!(bh[0] = sb_getblk(s, cur_index)))
288 + goto block_release;
290 + for (b = 1; bytes < c_byte; b++) {
291 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
292 + goto block_release;
293 + bytes += msblk->devblksize;
295 + ll_rw_block(READ, b, bh);
297 + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
301 + bytes = msblk->devblksize - offset;
302 + compressed = SQUASHFS_COMPRESSED(c_byte);
303 + c_buffer = compressed ? msblk->read_data : buffer;
304 + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
306 + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
307 + ? "" : "un", (unsigned int) c_byte);
309 + for (b = 1; bytes < c_byte; b++) {
310 + if (!(bh[b] = sb_getblk(s, ++cur_index)))
311 + goto block_release;
312 + bytes += msblk->devblksize;
314 + ll_rw_block(READ, b - 1, bh + 1);
318 + down(&msblk->read_data_mutex);
320 + for (bytes = 0, k = 0; k < b; k++) {
321 + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
322 + msblk->devblksize - offset :
324 + wait_on_buffer(bh[k]);
325 + if (!buffer_uptodate(bh[k]))
326 + goto block_release;
327 + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
328 + bytes += avail_bytes;
339 + stream.next_in = c_buffer;
340 + stream.avail_in = c_byte;
341 + stream.next_out = buffer;
342 + stream.avail_out = msblk->read_size;
344 + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
345 + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
346 + != Z_STREAM_END) || ((zlib_err =
347 + zlib_inflateEnd(&stream)) != Z_OK)) {
348 + ERROR("zlib_fs returned unexpected result 0x%x\n",
352 + bytes = stream.total_out;
354 + up(&msblk->read_data_mutex);
358 + *next_index = index + c_byte + (length ? 0 :
359 + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
368 + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
373 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
374 + long long block, unsigned int offset,
375 + int length, long long *next_block,
376 + unsigned int *next_offset)
378 + struct squashfs_sb_info *msblk = s->s_fs_info;
379 + int n, i, bytes, return_length = length;
380 + long long next_index;
382 + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
385 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
386 + if (msblk->block_cache[i].block == block)
389 + down(&msblk->block_cache_mutex);
391 + if (i == SQUASHFS_CACHED_BLKS) {
392 + /* read inode header block */
393 + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
394 + n ; n --, i = (i + 1) %
395 + SQUASHFS_CACHED_BLKS)
396 + if (msblk->block_cache[i].block !=
403 + init_waitqueue_entry(&wait, current);
404 + add_wait_queue(&msblk->waitq, &wait);
405 + set_current_state(TASK_UNINTERRUPTIBLE);
406 + up(&msblk->block_cache_mutex);
408 + set_current_state(TASK_RUNNING);
409 + remove_wait_queue(&msblk->waitq, &wait);
412 + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
414 + if (msblk->block_cache[i].block ==
415 + SQUASHFS_INVALID_BLK) {
416 + if (!(msblk->block_cache[i].data =
417 + kmalloc(SQUASHFS_METADATA_SIZE,
419 + ERROR("Failed to allocate cache"
421 + up(&msblk->block_cache_mutex);
426 + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
427 + up(&msblk->block_cache_mutex);
429 + if (!(msblk->block_cache[i].length =
430 + squashfs_read_data(s,
431 + msblk->block_cache[i].data,
432 + block, 0, &next_index))) {
433 + ERROR("Unable to read cache block [%llx:%x]\n",
438 + down(&msblk->block_cache_mutex);
439 + wake_up(&msblk->waitq);
440 + msblk->block_cache[i].block = block;
441 + msblk->block_cache[i].next_index = next_index;
442 + TRACE("Read cache block [%llx:%x]\n", block, offset);
445 + if (msblk->block_cache[i].block != block) {
446 + up(&msblk->block_cache_mutex);
450 + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
452 + memcpy(buffer, msblk->block_cache[i].data +
454 + if (msblk->block_cache[i].length - offset == length) {
455 + *next_block = msblk->block_cache[i].next_index;
458 + *next_block = block;
459 + *next_offset = offset + length;
461 + up(&msblk->block_cache_mutex);
465 + memcpy(buffer, msblk->block_cache[i].data +
469 + block = msblk->block_cache[i].next_index;
470 + up(&msblk->block_cache_mutex);
477 + return return_length;
483 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
484 + long long *fragment_start_block,
485 + unsigned int *fragment_size)
487 + struct squashfs_sb_info *msblk = s->s_fs_info;
488 + long long start_block =
489 + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
490 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
491 + struct squashfs_fragment_entry fragment_entry;
494 + struct squashfs_fragment_entry sfragment_entry;
496 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
497 + start_block, offset,
498 + sizeof(sfragment_entry), &start_block,
501 + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
503 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
504 + start_block, offset,
505 + sizeof(fragment_entry), &start_block,
509 + *fragment_start_block = fragment_entry.start_block;
510 + *fragment_size = fragment_entry.size;
519 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
520 + squashfs_fragment_cache *fragment)
522 + down(&msblk->fragment_mutex);
523 + fragment->locked --;
524 + wake_up(&msblk->fragment_wait_queue);
525 + up(&msblk->fragment_mutex);
529 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
530 + *s, long long start_block,
534 + struct squashfs_sb_info *msblk = s->s_fs_info;
537 + down(&msblk->fragment_mutex);
539 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
540 + msblk->fragment[i].block != start_block; i++);
542 + if (i == SQUASHFS_CACHED_FRAGMENTS) {
543 + for (i = msblk->next_fragment, n =
544 + SQUASHFS_CACHED_FRAGMENTS; n &&
545 + msblk->fragment[i].locked; n--, i = (i + 1) %
546 + SQUASHFS_CACHED_FRAGMENTS);
551 + init_waitqueue_entry(&wait, current);
552 + add_wait_queue(&msblk->fragment_wait_queue,
554 + set_current_state(TASK_UNINTERRUPTIBLE);
555 + up(&msblk->fragment_mutex);
557 + set_current_state(TASK_RUNNING);
558 + remove_wait_queue(&msblk->fragment_wait_queue,
562 + msblk->next_fragment = (msblk->next_fragment + 1) %
563 + SQUASHFS_CACHED_FRAGMENTS;
565 + if (msblk->fragment[i].data == NULL)
566 + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
567 + (SQUASHFS_FILE_MAX_SIZE))) {
568 + ERROR("Failed to allocate fragment "
570 + up(&msblk->fragment_mutex);
574 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
575 + msblk->fragment[i].locked = 1;
576 + up(&msblk->fragment_mutex);
578 + if (!(msblk->fragment[i].length = squashfs_read_data(s,
579 + msblk->fragment[i].data,
580 + start_block, length, NULL))) {
581 + ERROR("Unable to read fragment cache block "
582 + "[%llx]\n", start_block);
583 + msblk->fragment[i].locked = 0;
587 + msblk->fragment[i].block = start_block;
588 + TRACE("New fragment %d, start block %lld, locked %d\n",
589 + i, msblk->fragment[i].block,
590 + msblk->fragment[i].locked);
594 + msblk->fragment[i].locked++;
595 + up(&msblk->fragment_mutex);
596 + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
597 + msblk->fragment[i].block,
598 + msblk->fragment[i].locked);
602 + return &msblk->fragment[i];
609 +static struct inode *squashfs_new_inode(struct super_block *s,
610 + struct squashfs_base_inode_header *inodeb)
612 + struct squashfs_sb_info *msblk = s->s_fs_info;
613 + struct inode *i = new_inode(s);
616 + i->i_ino = inodeb->inode_number;
617 + i->i_mtime.tv_sec = inodeb->mtime;
618 + i->i_atime.tv_sec = inodeb->mtime;
619 + i->i_ctime.tv_sec = inodeb->mtime;
620 + i->i_uid = msblk->uid[inodeb->uid];
621 + i->i_mode = inodeb->mode;
623 + if (inodeb->guid == SQUASHFS_GUIDS)
624 + i->i_gid = i->i_uid;
626 + i->i_gid = msblk->guid[inodeb->guid];
633 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
636 + struct squashfs_sb_info *msblk = s->s_fs_info;
637 + struct squashfs_super_block *sblk = &msblk->sblk;
638 + long long block = SQUASHFS_INODE_BLK(inode) +
639 + sblk->inode_table_start;
640 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
641 + long long next_block;
642 + unsigned int next_offset;
643 + union squashfs_inode_header id, sid;
644 + struct squashfs_base_inode_header *inodeb = &id.base,
645 + *sinodeb = &sid.base;
647 + TRACE("Entered squashfs_iget\n");
650 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
651 + offset, sizeof(*sinodeb), &next_block,
654 + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
657 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
658 + offset, sizeof(*inodeb), &next_block,
662 + switch(inodeb->inode_type) {
663 + case SQUASHFS_FILE_TYPE: {
664 + unsigned int frag_size;
665 + long long frag_blk;
666 + struct squashfs_reg_inode_header *inodep = &id.reg;
667 + struct squashfs_reg_inode_header *sinodep = &sid.reg;
670 + if (!squashfs_get_cached_block(s, (char *)
671 + sinodep, block, offset,
672 + sizeof(*sinodep), &next_block,
675 + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
677 + if (!squashfs_get_cached_block(s, (char *)
678 + inodep, block, offset,
679 + sizeof(*inodep), &next_block,
683 + frag_blk = SQUASHFS_INVALID_BLK;
684 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
685 + !get_fragment_location(s,
686 + inodep->fragment, &frag_blk, &frag_size))
689 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
693 + i->i_size = inodep->file_size;
694 + i->i_fop = &generic_ro_fops;
695 + i->i_mode |= S_IFREG;
696 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
697 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
698 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
699 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
700 + SQUASHFS_I(i)->start_block = inodep->start_block;
701 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
702 + SQUASHFS_I(i)->offset = next_offset;
703 + if (sblk->block_size > 4096)
704 + i->i_data.a_ops = &squashfs_aops;
706 + i->i_data.a_ops = &squashfs_aops_4K;
708 + TRACE("File inode %x:%x, start_block %llx, "
709 + "block_list_start %llx, offset %x\n",
710 + SQUASHFS_INODE_BLK(inode), offset,
711 + inodep->start_block, next_block,
715 + case SQUASHFS_LREG_TYPE: {
716 + unsigned int frag_size;
717 + long long frag_blk;
718 + struct squashfs_lreg_inode_header *inodep = &id.lreg;
719 + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
722 + if (!squashfs_get_cached_block(s, (char *)
723 + sinodep, block, offset,
724 + sizeof(*sinodep), &next_block,
727 + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
729 + if (!squashfs_get_cached_block(s, (char *)
730 + inodep, block, offset,
731 + sizeof(*inodep), &next_block,
735 + frag_blk = SQUASHFS_INVALID_BLK;
736 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
737 + !get_fragment_location(s,
738 + inodep->fragment, &frag_blk, &frag_size))
741 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
744 + i->i_nlink = inodep->nlink;
745 + i->i_size = inodep->file_size;
746 + i->i_fop = &generic_ro_fops;
747 + i->i_mode |= S_IFREG;
748 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
749 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
750 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
751 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
752 + SQUASHFS_I(i)->start_block = inodep->start_block;
753 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
754 + SQUASHFS_I(i)->offset = next_offset;
755 + if (sblk->block_size > 4096)
756 + i->i_data.a_ops = &squashfs_aops;
758 + i->i_data.a_ops = &squashfs_aops_4K;
760 + TRACE("File inode %x:%x, start_block %llx, "
761 + "block_list_start %llx, offset %x\n",
762 + SQUASHFS_INODE_BLK(inode), offset,
763 + inodep->start_block, next_block,
767 + case SQUASHFS_DIR_TYPE: {
768 + struct squashfs_dir_inode_header *inodep = &id.dir;
769 + struct squashfs_dir_inode_header *sinodep = &sid.dir;
772 + if (!squashfs_get_cached_block(s, (char *)
773 + sinodep, block, offset,
774 + sizeof(*sinodep), &next_block,
777 + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
779 + if (!squashfs_get_cached_block(s, (char *)
780 + inodep, block, offset,
781 + sizeof(*inodep), &next_block,
785 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
788 + i->i_nlink = inodep->nlink;
789 + i->i_size = inodep->file_size;
790 + i->i_op = &squashfs_dir_inode_ops;
791 + i->i_fop = &squashfs_dir_ops;
792 + i->i_mode |= S_IFDIR;
793 + SQUASHFS_I(i)->start_block = inodep->start_block;
794 + SQUASHFS_I(i)->offset = inodep->offset;
795 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
796 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
798 + TRACE("Directory inode %x:%x, start_block %x, offset "
799 + "%x\n", SQUASHFS_INODE_BLK(inode),
800 + offset, inodep->start_block,
804 + case SQUASHFS_LDIR_TYPE: {
805 + struct squashfs_ldir_inode_header *inodep = &id.ldir;
806 + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
809 + if (!squashfs_get_cached_block(s, (char *)
810 + sinodep, block, offset,
811 + sizeof(*sinodep), &next_block,
814 + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
817 + if (!squashfs_get_cached_block(s, (char *)
818 + inodep, block, offset,
819 + sizeof(*inodep), &next_block,
823 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
826 + i->i_nlink = inodep->nlink;
827 + i->i_size = inodep->file_size;
828 + i->i_op = &squashfs_dir_inode_ops;
829 + i->i_fop = &squashfs_dir_ops;
830 + i->i_mode |= S_IFDIR;
831 + SQUASHFS_I(i)->start_block = inodep->start_block;
832 + SQUASHFS_I(i)->offset = inodep->offset;
833 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
834 + SQUASHFS_I(i)->u.s2.directory_index_offset =
836 + SQUASHFS_I(i)->u.s2.directory_index_count =
838 + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
840 + TRACE("Long directory inode %x:%x, start_block %x, "
842 + SQUASHFS_INODE_BLK(inode), offset,
843 + inodep->start_block, inodep->offset);
846 + case SQUASHFS_SYMLINK_TYPE: {
847 + struct squashfs_symlink_inode_header *inodep =
849 + struct squashfs_symlink_inode_header *sinodep =
853 + if (!squashfs_get_cached_block(s, (char *)
854 + sinodep, block, offset,
855 + sizeof(*sinodep), &next_block,
858 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
861 + if (!squashfs_get_cached_block(s, (char *)
862 + inodep, block, offset,
863 + sizeof(*inodep), &next_block,
867 + if((i = squashfs_new_inode(s, inodeb)) == NULL)
870 + i->i_nlink = inodep->nlink;
871 + i->i_size = inodep->symlink_size;
872 + i->i_op = &page_symlink_inode_operations;
873 + i->i_data.a_ops = &squashfs_symlink_aops;
874 + i->i_mode |= S_IFLNK;
875 + SQUASHFS_I(i)->start_block = next_block;
876 + SQUASHFS_I(i)->offset = next_offset;
878 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
880 + SQUASHFS_INODE_BLK(inode), offset,
881 + next_block, next_offset);
884 + case SQUASHFS_BLKDEV_TYPE:
885 + case SQUASHFS_CHRDEV_TYPE: {
886 + struct squashfs_dev_inode_header *inodep = &id.dev;
887 + struct squashfs_dev_inode_header *sinodep = &sid.dev;
890 + if (!squashfs_get_cached_block(s, (char *)
891 + sinodep, block, offset,
892 + sizeof(*sinodep), &next_block,
895 + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
897 + if (!squashfs_get_cached_block(s, (char *)
898 + inodep, block, offset,
899 + sizeof(*inodep), &next_block,
903 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
906 + i->i_nlink = inodep->nlink;
907 + i->i_mode |= (inodeb->inode_type ==
908 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
910 + init_special_inode(i, i->i_mode,
911 + old_decode_dev(inodep->rdev));
913 + TRACE("Device inode %x:%x, rdev %x\n",
914 + SQUASHFS_INODE_BLK(inode), offset,
918 + case SQUASHFS_FIFO_TYPE:
919 + case SQUASHFS_SOCKET_TYPE: {
920 + struct squashfs_ipc_inode_header *inodep = &id.ipc;
921 + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
924 + if (!squashfs_get_cached_block(s, (char *)
925 + sinodep, block, offset,
926 + sizeof(*sinodep), &next_block,
929 + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
931 + if (!squashfs_get_cached_block(s, (char *)
932 + inodep, block, offset,
933 + sizeof(*inodep), &next_block,
937 + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
940 + i->i_nlink = inodep->nlink;
941 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
942 + ? S_IFIFO : S_IFSOCK;
943 + init_special_inode(i, i->i_mode, 0);
947 + ERROR("Unknown inode type %d in squashfs_iget!\n",
948 + inodeb->inode_type);
952 + insert_inode_hash(i);
956 + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
963 +static int read_fragment_index_table(struct super_block *s)
965 + struct squashfs_sb_info *msblk = s->s_fs_info;
966 + struct squashfs_super_block *sblk = &msblk->sblk;
968 + /* Allocate fragment index table */
969 + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
970 + (sblk->fragments), GFP_KERNEL))) {
971 + ERROR("Failed to allocate uid/gid table\n");
975 + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
976 + !squashfs_read_data(s, (char *)
977 + msblk->fragment_index,
978 + sblk->fragment_table_start,
979 + SQUASHFS_FRAGMENT_INDEX_BYTES
980 + (sblk->fragments) |
981 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
982 + ERROR("unable to read fragment index table\n");
988 + long long fragment;
990 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
992 + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
993 + &msblk->fragment_index[i], 1);
994 + msblk->fragment_index[i] = fragment;
1002 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1004 + struct squashfs_super_block *sblk = &msblk->sblk;
1006 + msblk->iget = squashfs_iget;
1007 + msblk->read_blocklist = read_blocklist;
1008 + msblk->read_fragment_index_table = read_fragment_index_table;
1010 + if (sblk->s_major == 1) {
1011 + if (!squashfs_1_0_supported(msblk)) {
1012 + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1013 + "are unsupported\n");
1014 + SERROR("Please recompile with "
1015 + "Squashfs 1.0 support enabled\n");
1018 + } else if (sblk->s_major == 2) {
1019 + if (!squashfs_2_0_supported(msblk)) {
1020 + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1021 + "are unsupported\n");
1022 + SERROR("Please recompile with "
1023 + "Squashfs 2.0 support enabled\n");
1026 + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1028 + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1029 + "filesystem\n", sblk->s_major, sblk->s_minor);
1030 + SERROR("Please update your kernel\n");
1038 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1040 + struct squashfs_sb_info *msblk;
1041 + struct squashfs_super_block *sblk;
1043 + char b[BDEVNAME_SIZE];
1044 + struct inode *root;
1046 + TRACE("Entered squashfs_read_superblock\n");
1048 + if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1050 + ERROR("Failed to allocate superblock\n");
1053 + memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1054 + msblk = s->s_fs_info;
1055 + sblk = &msblk->sblk;
1057 + msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1058 + msblk->devblksize_log2 = ffz(~msblk->devblksize);
1060 + init_MUTEX(&msblk->read_data_mutex);
1061 + init_MUTEX(&msblk->read_page_mutex);
1062 + init_MUTEX(&msblk->block_cache_mutex);
1063 + init_MUTEX(&msblk->fragment_mutex);
1064 + init_MUTEX(&msblk->meta_index_mutex);
1066 + init_waitqueue_head(&msblk->waitq);
1067 + init_waitqueue_head(&msblk->fragment_wait_queue);
1069 + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1070 + sizeof(struct squashfs_super_block) |
1071 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1072 + SERROR("unable to read superblock\n");
1073 + goto failed_mount;
1076 + /* Check it is a SQUASHFS superblock */
1078 + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1079 + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1080 + struct squashfs_super_block ssblk;
1082 + WARNING("Mounting a different endian SQUASHFS "
1083 + "filesystem on %s\n", bdevname(s->s_bdev, b));
1085 + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1086 + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1089 + SERROR("Can't find a SQUASHFS superblock on %s\n",
1090 + bdevname(s->s_bdev, b));
1091 + goto failed_mount;
1095 + /* Check the MAJOR & MINOR versions */
1096 + if(!supported_squashfs_filesystem(msblk, silent))
1097 + goto failed_mount;
1099 + TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1100 + TRACE("Inodes are %scompressed\n",
1101 + SQUASHFS_UNCOMPRESSED_INODES
1102 + (sblk->flags) ? "un" : "");
1103 + TRACE("Data is %scompressed\n",
1104 + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1106 + TRACE("Check data is %s present in the filesystem\n",
1107 + SQUASHFS_CHECK_DATA(sblk->flags) ?
1109 + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1110 + TRACE("Block size %d\n", sblk->block_size);
1111 + TRACE("Number of inodes %d\n", sblk->inodes);
1112 + if (sblk->s_major > 1)
1113 + TRACE("Number of fragments %d\n", sblk->fragments);
1114 + TRACE("Number of uids %d\n", sblk->no_uids);
1115 + TRACE("Number of gids %d\n", sblk->no_guids);
1116 + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1117 + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1118 + if (sblk->s_major > 1)
1119 + TRACE("sblk->fragment_table_start %llx\n",
1120 + sblk->fragment_table_start);
1121 + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1123 + s->s_flags |= MS_RDONLY;
1124 + s->s_op = &squashfs_ops;
1126 + /* Init inode_table block pointer array */
1127 + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1128 + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1129 + ERROR("Failed to allocate block cache\n");
1130 + goto failed_mount;
1133 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1134 + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1136 + msblk->next_cache = 0;
1138 + /* Allocate read_data block */
1139 + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1140 + SQUASHFS_METADATA_SIZE :
1143 + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1144 + ERROR("Failed to allocate read_data block\n");
1145 + goto failed_mount;
1148 + /* Allocate read_page block */
1149 + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1150 + ERROR("Failed to allocate read_page block\n");
1151 + goto failed_mount;
1154 + /* Allocate uid and gid tables */
1155 + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1156 + sizeof(unsigned int), GFP_KERNEL))) {
1157 + ERROR("Failed to allocate uid/gid table\n");
1158 + goto failed_mount;
1160 + msblk->guid = msblk->uid + sblk->no_uids;
1162 + if (msblk->swap) {
1163 + unsigned int suid[sblk->no_uids + sblk->no_guids];
1165 + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1166 + ((sblk->no_uids + sblk->no_guids) *
1167 + sizeof(unsigned int)) |
1168 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1169 + ERROR("unable to read uid/gid table\n");
1170 + goto failed_mount;
1173 + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1174 + sblk->no_guids), (sizeof(unsigned int) * 8));
1176 + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1177 + ((sblk->no_uids + sblk->no_guids) *
1178 + sizeof(unsigned int)) |
1179 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1180 + ERROR("unable to read uid/gid table\n");
1181 + goto failed_mount;
1185 + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1186 + goto allocate_root;
1188 + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1189 + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1190 + ERROR("Failed to allocate fragment block cache\n");
1191 + goto failed_mount;
1194 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1195 + msblk->fragment[i].locked = 0;
1196 + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1197 + msblk->fragment[i].data = NULL;
1200 + msblk->next_fragment = 0;
1202 + /* Allocate fragment index table */
1203 + if (msblk->read_fragment_index_table(s) == 0)
1204 + goto failed_mount;
1207 + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1208 + goto failed_mount;
1210 + if ((s->s_root = d_alloc_root(root)) == NULL) {
1211 + ERROR("Root inode create failed\n");
1213 + goto failed_mount;
1216 + TRACE("Leaving squashfs_read_super\n");
1220 + kfree(msblk->fragment_index);
1221 + kfree(msblk->fragment);
1222 + kfree(msblk->uid);
1223 + kfree(msblk->read_page);
1224 + kfree(msblk->read_data);
1225 + kfree(msblk->block_cache);
1226 + kfree(msblk->fragment_index_2);
1227 + kfree(s->s_fs_info);
1228 + s->s_fs_info = NULL;
1236 +static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1238 + struct squashfs_sb_info *msblk = dentry->d_inode->i_sb->s_fs_info;
1239 + struct squashfs_super_block *sblk = &msblk->sblk;
1241 + TRACE("Entered squashfs_statfs\n");
1243 + buf->f_type = SQUASHFS_MAGIC;
1244 + buf->f_bsize = sblk->block_size;
1245 + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1246 + buf->f_bfree = buf->f_bavail = 0;
1247 + buf->f_files = sblk->inodes;
1249 + buf->f_namelen = SQUASHFS_NAME_LEN;
1255 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1257 + struct inode *inode = page->mapping->host;
1258 + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1259 + long long block = SQUASHFS_I(inode)->start_block;
1260 + int offset = SQUASHFS_I(inode)->offset;
1261 + void *pageaddr = kmap(page);
1263 + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1264 + "%llx, offset %x\n", page->index,
1265 + SQUASHFS_I(inode)->start_block,
1266 + SQUASHFS_I(inode)->offset);
1268 + for (length = 0; length < index; length += bytes) {
1269 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1270 + block, offset, PAGE_CACHE_SIZE, &block,
1272 + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1278 + if (length != index) {
1279 + ERROR("(squashfs_symlink_readpage) length != index\n");
1284 + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1285 + i_size_read(inode) - length;
1287 + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1288 + offset, bytes, &block, &offset)))
1289 + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1292 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1294 + SetPageUptodate(page);
1295 + unlock_page(page);
1301 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1303 + struct meta_index *meta = NULL;
1304 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1307 + down(&msblk->meta_index_mutex);
1309 + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1311 + if(msblk->meta_index == NULL)
1312 + goto not_allocated;
1314 + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1315 + if (msblk->meta_index[i].inode_number == inode->i_ino &&
1316 + msblk->meta_index[i].offset >= offset &&
1317 + msblk->meta_index[i].offset <= index &&
1318 + msblk->meta_index[i].locked == 0) {
1319 + TRACE("locate_meta_index: entry %d, offset %d\n", i,
1320 + msblk->meta_index[i].offset);
1321 + meta = &msblk->meta_index[i];
1322 + offset = meta->offset;
1329 + up(&msblk->meta_index_mutex);
1335 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1337 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1338 + struct meta_index *meta = NULL;
1341 + down(&msblk->meta_index_mutex);
1343 + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1345 + if(msblk->meta_index == NULL) {
1346 + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1347 + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1348 + ERROR("Failed to allocate meta_index\n");
1351 + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1352 + msblk->meta_index[i].inode_number = 0;
1353 + msblk->meta_index[i].locked = 0;
1355 + msblk->next_meta_index = 0;
1358 + for(i = SQUASHFS_META_NUMBER; i &&
1359 + msblk->meta_index[msblk->next_meta_index].locked; i --)
1360 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1361 + SQUASHFS_META_NUMBER;
1364 + TRACE("empty_meta_index: failed!\n");
1368 + TRACE("empty_meta_index: returned meta entry %d, %p\n",
1369 + msblk->next_meta_index,
1370 + &msblk->meta_index[msblk->next_meta_index]);
1372 + meta = &msblk->meta_index[msblk->next_meta_index];
1373 + msblk->next_meta_index = (msblk->next_meta_index + 1) %
1374 + SQUASHFS_META_NUMBER;
1376 + meta->inode_number = inode->i_ino;
1377 + meta->offset = offset;
1378 + meta->skip = skip;
1379 + meta->entries = 0;
1383 + up(&msblk->meta_index_mutex);
1388 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1394 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1395 + long long *start_block, int *offset)
1397 + struct squashfs_sb_info *msblk = s->s_fs_info;
1398 + unsigned int *block_listp;
1401 + if (msblk->swap) {
1402 + char sblock_list[blocks << 2];
1404 + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1405 + *offset, blocks << 2, start_block, offset)) {
1406 + ERROR("Unable to read block list [%llx:%x]\n",
1407 + *start_block, *offset);
1410 + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1411 + ((unsigned int *)sblock_list), blocks);
1413 + if (!squashfs_get_cached_block(s, block_list, *start_block,
1414 + *offset, blocks << 2, start_block, offset)) {
1415 + ERROR("Unable to read block list [%llx:%x]\n",
1416 + *start_block, *offset);
1420 + for (block_listp = (unsigned int *) block_list; blocks;
1421 + block_listp++, blocks --)
1422 + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1433 +static inline int calculate_skip(int blocks) {
1434 + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1435 + return skip >= 7 ? 7 : skip + 1;
1439 +static int get_meta_index(struct inode *inode, int index,
1440 + long long *index_block, int *index_offset,
1441 + long long *data_block, char *block_list)
1443 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1444 + struct squashfs_super_block *sblk = &msblk->sblk;
1445 + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1447 + struct meta_index *meta;
1448 + struct meta_entry *meta_entry;
1449 + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1450 + int cur_offset = SQUASHFS_I(inode)->offset;
1451 + long long cur_data_block = SQUASHFS_I(inode)->start_block;
1454 + index /= SQUASHFS_META_INDEXES * skip;
1456 + while ( offset < index ) {
1457 + meta = locate_meta_index(inode, index, offset + 1);
1459 + if (meta == NULL) {
1460 + if ((meta = empty_meta_index(inode, offset + 1,
1464 + offset = index < meta->offset + meta->entries ? index :
1465 + meta->offset + meta->entries - 1;
1466 + meta_entry = &meta->meta_entry[offset - meta->offset];
1467 + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1468 + cur_offset = meta_entry->offset;
1469 + cur_data_block = meta_entry->data_block;
1470 + TRACE("get_meta_index: offset %d, meta->offset %d, "
1471 + "meta->entries %d\n", offset, meta->offset,
1473 + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1474 + " data_block 0x%llx\n", cur_index_block,
1475 + cur_offset, cur_data_block);
1478 + for (i = meta->offset + meta->entries; i <= index &&
1479 + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1480 + int blocks = skip * SQUASHFS_META_INDEXES;
1483 + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1485 + int res = read_block_index(inode->i_sb, block,
1486 + block_list, &cur_index_block,
1492 + cur_data_block += res;
1496 + meta_entry = &meta->meta_entry[i - meta->offset];
1497 + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1498 + meta_entry->offset = cur_offset;
1499 + meta_entry->data_block = cur_data_block;
1504 + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1505 + meta->offset, meta->entries);
1507 + release_meta_index(inode, meta);
1511 + *index_block = cur_index_block;
1512 + *index_offset = cur_offset;
1513 + *data_block = cur_data_block;
1515 + return offset * SQUASHFS_META_INDEXES * skip;
1518 + release_meta_index(inode, meta);
1523 +static long long read_blocklist(struct inode *inode, int index,
1524 + int readahead_blks, char *block_list,
1525 + unsigned short **block_p, unsigned int *bsize)
1527 + long long block_ptr;
1530 + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1533 + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1534 + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1543 + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1544 + int res = read_block_index(inode->i_sb, blocks, block_list,
1545 + &block_ptr, &offset);
1552 + if (read_block_index(inode->i_sb, 1, block_list,
1553 + &block_ptr, &offset) == -1)
1555 + *bsize = *((unsigned int *) block_list);
1564 +static int squashfs_readpage(struct file *file, struct page *page)
1566 + struct inode *inode = page->mapping->host;
1567 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1568 + struct squashfs_super_block *sblk = &msblk->sblk;
1569 + unsigned char block_list[SIZE];
1571 + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1572 + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1574 + struct squashfs_fragment_cache *fragment = NULL;
1575 + char *data_ptr = msblk->read_page;
1577 + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1578 + int start_index = page->index & ~mask;
1579 + int end_index = start_index | mask;
1581 + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1583 + SQUASHFS_I(inode)->start_block);
1585 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1586 + PAGE_CACHE_SHIFT))
1589 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1590 + || index < (i_size_read(inode) >>
1591 + sblk->block_log)) {
1592 + if ((block = (msblk->read_blocklist)(inode, index, 1,
1593 + block_list, NULL, &bsize)) == 0)
1596 + down(&msblk->read_page_mutex);
1598 + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1599 + block, bsize, NULL))) {
1600 + ERROR("Unable to read page, block %llx, size %x\n", block,
1602 + up(&msblk->read_page_mutex);
1606 + if ((fragment = get_cached_fragment(inode->i_sb,
1607 + SQUASHFS_I(inode)->
1608 + u.s1.fragment_start_block,
1609 + SQUASHFS_I(inode)->u.s1.fragment_size))
1611 + ERROR("Unable to read page, block %llx, size %x\n",
1612 + SQUASHFS_I(inode)->
1613 + u.s1.fragment_start_block,
1614 + (int) SQUASHFS_I(inode)->
1615 + u.s1.fragment_size);
1618 + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1619 + (i_size_read(inode) & (sblk->block_size
1621 + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1622 + data_ptr = fragment->data;
1625 + for (i = start_index; i <= end_index && byte_offset < bytes;
1626 + i++, byte_offset += PAGE_CACHE_SIZE) {
1627 + struct page *push_page;
1628 + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1629 + PAGE_CACHE_SIZE : bytes - byte_offset;
1631 + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1632 + bytes, i, byte_offset, available_bytes);
1634 + if (i == page->index) {
1635 + pageaddr = kmap_atomic(page, KM_USER0);
1636 + memcpy(pageaddr, data_ptr + byte_offset,
1638 + memset(pageaddr + available_bytes, 0,
1639 + PAGE_CACHE_SIZE - available_bytes);
1640 + kunmap_atomic(pageaddr, KM_USER0);
1641 + flush_dcache_page(page);
1642 + SetPageUptodate(page);
1643 + unlock_page(page);
1644 + } else if ((push_page =
1645 + grab_cache_page_nowait(page->mapping, i))) {
1646 + pageaddr = kmap_atomic(push_page, KM_USER0);
1648 + memcpy(pageaddr, data_ptr + byte_offset,
1650 + memset(pageaddr + available_bytes, 0,
1651 + PAGE_CACHE_SIZE - available_bytes);
1652 + kunmap_atomic(pageaddr, KM_USER0);
1653 + flush_dcache_page(push_page);
1654 + SetPageUptodate(push_page);
1655 + unlock_page(push_page);
1656 + page_cache_release(push_page);
1660 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1661 + || index < (i_size_read(inode) >>
1663 + up(&msblk->read_page_mutex);
1665 + release_cached_fragment(msblk, fragment);
1670 + pageaddr = kmap_atomic(page, KM_USER0);
1671 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1672 + kunmap_atomic(pageaddr, KM_USER0);
1673 + flush_dcache_page(page);
1674 + SetPageUptodate(page);
1675 + unlock_page(page);
1681 +static int squashfs_readpage4K(struct file *file, struct page *page)
1683 + struct inode *inode = page->mapping->host;
1684 + struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1685 + struct squashfs_super_block *sblk = &msblk->sblk;
1686 + unsigned char block_list[SIZE];
1688 + unsigned int bsize, bytes = 0;
1691 + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1693 + SQUASHFS_I(inode)->start_block);
1695 + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1696 + PAGE_CACHE_SHIFT)) {
1697 + pageaddr = kmap_atomic(page, KM_USER0);
1701 + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1702 + || page->index < (i_size_read(inode) >>
1703 + sblk->block_log)) {
1704 + block = (msblk->read_blocklist)(inode, page->index, 1,
1705 + block_list, NULL, &bsize);
1707 + down(&msblk->read_page_mutex);
1708 + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1710 + pageaddr = kmap_atomic(page, KM_USER0);
1712 + memcpy(pageaddr, msblk->read_page, bytes);
1714 + ERROR("Unable to read page, block %llx, size %x\n",
1716 + up(&msblk->read_page_mutex);
1718 + struct squashfs_fragment_cache *fragment =
1719 + get_cached_fragment(inode->i_sb,
1720 + SQUASHFS_I(inode)->
1721 + u.s1.fragment_start_block,
1722 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1723 + pageaddr = kmap_atomic(page, KM_USER0);
1725 + bytes = i_size_read(inode) & (sblk->block_size - 1);
1726 + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1727 + u.s1.fragment_offset, bytes);
1728 + release_cached_fragment(msblk, fragment);
1730 + ERROR("Unable to read page, block %llx, size %x\n",
1731 + SQUASHFS_I(inode)->
1732 + u.s1.fragment_start_block, (int)
1733 + SQUASHFS_I(inode)-> u.s1.fragment_size);
1737 + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1738 + kunmap_atomic(pageaddr, KM_USER0);
1739 + flush_dcache_page(page);
1740 + SetPageUptodate(page);
1741 + unlock_page(page);
1747 +static int get_dir_index_using_offset(struct super_block *s, long long
1748 + *next_block, unsigned int *next_offset,
1749 + long long index_start,
1750 + unsigned int index_offset, int i_count,
1753 + struct squashfs_sb_info *msblk = s->s_fs_info;
1754 + struct squashfs_super_block *sblk = &msblk->sblk;
1755 + int i, length = 0;
1756 + struct squashfs_dir_index index;
1758 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1759 + i_count, (unsigned int) f_pos);
1765 + for (i = 0; i < i_count; i++) {
1766 + if (msblk->swap) {
1767 + struct squashfs_dir_index sindex;
1768 + squashfs_get_cached_block(s, (char *) &sindex,
1769 + index_start, index_offset,
1770 + sizeof(sindex), &index_start,
1772 + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1774 + squashfs_get_cached_block(s, (char *) &index,
1775 + index_start, index_offset,
1776 + sizeof(index), &index_start,
1779 + if (index.index > f_pos)
1782 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
1783 + index.size + 1, &index_start,
1786 + length = index.index;
1787 + *next_block = index.start_block + sblk->directory_table_start;
1790 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1793 + return length + 3;
1797 +static int get_dir_index_using_name(struct super_block *s, long long
1798 + *next_block, unsigned int *next_offset,
1799 + long long index_start,
1800 + unsigned int index_offset, int i_count,
1801 + const char *name, int size)
1803 + struct squashfs_sb_info *msblk = s->s_fs_info;
1804 + struct squashfs_super_block *sblk = &msblk->sblk;
1805 + int i, length = 0;
1806 + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1807 + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1808 + char str[SQUASHFS_NAME_LEN + 1];
1810 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1812 + strncpy(str, name, size);
1815 + for (i = 0; i < i_count; i++) {
1816 + if (msblk->swap) {
1817 + struct squashfs_dir_index sindex;
1818 + squashfs_get_cached_block(s, (char *) &sindex,
1819 + index_start, index_offset,
1820 + sizeof(sindex), &index_start,
1822 + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1824 + squashfs_get_cached_block(s, (char *) index,
1825 + index_start, index_offset,
1826 + sizeof(struct squashfs_dir_index),
1827 + &index_start, &index_offset);
1829 + squashfs_get_cached_block(s, index->name, index_start,
1830 + index_offset, index->size + 1,
1831 + &index_start, &index_offset);
1833 + index->name[index->size + 1] = '\0';
1835 + if (strcmp(index->name, str) > 0)
1838 + length = index->index;
1839 + *next_block = index->start_block + sblk->directory_table_start;
1842 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1843 + return length + 3;
1847 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1849 + struct inode *i = file->f_dentry->d_inode;
1850 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1851 + struct squashfs_super_block *sblk = &msblk->sblk;
1852 + long long next_block = SQUASHFS_I(i)->start_block +
1853 + sblk->directory_table_start;
1854 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1856 + struct squashfs_dir_header dirh;
1857 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1858 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1860 + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1862 + while(file->f_pos < 3) {
1866 + if(file->f_pos == 0) {
1873 + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1875 + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1876 + (unsigned int) dirent, name, size, (int)
1877 + file->f_pos, i_ino,
1878 + squashfs_filetype_table[1]);
1880 + if (filldir(dirent, name, size,
1881 + file->f_pos, i_ino,
1882 + squashfs_filetype_table[1]) < 0) {
1883 + TRACE("Filldir returned less than 0\n");
1886 + file->f_pos += size;
1890 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1891 + SQUASHFS_I(i)->u.s2.directory_index_start,
1892 + SQUASHFS_I(i)->u.s2.directory_index_offset,
1893 + SQUASHFS_I(i)->u.s2.directory_index_count,
1896 + while (length < i_size_read(i)) {
1897 + /* read directory header */
1898 + if (msblk->swap) {
1899 + struct squashfs_dir_header sdirh;
1901 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1902 + next_block, next_offset, sizeof(sdirh),
1903 + &next_block, &next_offset))
1906 + length += sizeof(sdirh);
1907 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1909 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1910 + next_block, next_offset, sizeof(dirh),
1911 + &next_block, &next_offset))
1914 + length += sizeof(dirh);
1917 + dir_count = dirh.count + 1;
1918 + while (dir_count--) {
1919 + if (msblk->swap) {
1920 + struct squashfs_dir_entry sdire;
1921 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1922 + &sdire, next_block, next_offset,
1923 + sizeof(sdire), &next_block,
1927 + length += sizeof(sdire);
1928 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1930 + if (!squashfs_get_cached_block(i->i_sb, (char *)
1931 + dire, next_block, next_offset,
1932 + sizeof(*dire), &next_block,
1936 + length += sizeof(*dire);
1939 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
1940 + next_block, next_offset,
1941 + dire->size + 1, &next_block,
1945 + length += dire->size + 1;
1947 + if (file->f_pos >= length)
1950 + dire->name[dire->size + 1] = '\0';
1952 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1953 + (unsigned int) dirent, dire->name,
1954 + dire->size + 1, (int) file->f_pos,
1955 + dirh.start_block, dire->offset,
1956 + dirh.inode_number + dire->inode_number,
1957 + squashfs_filetype_table[dire->type]);
1959 + if (filldir(dirent, dire->name, dire->size + 1,
1961 + dirh.inode_number + dire->inode_number,
1962 + squashfs_filetype_table[dire->type])
1964 + TRACE("Filldir returned less than 0\n");
1967 + file->f_pos = length;
1976 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1982 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
1983 + struct nameidata *nd)
1985 + const unsigned char *name = dentry->d_name.name;
1986 + int len = dentry->d_name.len;
1987 + struct inode *inode = NULL;
1988 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1989 + struct squashfs_super_block *sblk = &msblk->sblk;
1990 + long long next_block = SQUASHFS_I(i)->start_block +
1991 + sblk->directory_table_start;
1992 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
1994 + struct squashfs_dir_header dirh;
1995 + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
1996 + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1998 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2000 + if (len > SQUASHFS_NAME_LEN)
2003 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2004 + SQUASHFS_I(i)->u.s2.directory_index_start,
2005 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2006 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2009 + while (length < i_size_read(i)) {
2010 + /* read directory header */
2011 + if (msblk->swap) {
2012 + struct squashfs_dir_header sdirh;
2013 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2014 + next_block, next_offset, sizeof(sdirh),
2015 + &next_block, &next_offset))
2018 + length += sizeof(sdirh);
2019 + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2021 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2022 + next_block, next_offset, sizeof(dirh),
2023 + &next_block, &next_offset))
2026 + length += sizeof(dirh);
2029 + dir_count = dirh.count + 1;
2030 + while (dir_count--) {
2031 + if (msblk->swap) {
2032 + struct squashfs_dir_entry sdire;
2033 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2034 + &sdire, next_block,next_offset,
2035 + sizeof(sdire), &next_block,
2039 + length += sizeof(sdire);
2040 + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2042 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2043 + dire, next_block,next_offset,
2044 + sizeof(*dire), &next_block,
2048 + length += sizeof(*dire);
2051 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2052 + next_block, next_offset, dire->size + 1,
2053 + &next_block, &next_offset))
2056 + length += dire->size + 1;
2058 + if (name[0] < dire->name[0])
2061 + if ((len == dire->size + 1) && !strncmp(name,
2062 + dire->name, len)) {
2063 + squashfs_inode_t ino =
2064 + SQUASHFS_MKINODE(dirh.start_block,
2067 + TRACE("calling squashfs_iget for directory "
2068 + "entry %s, inode %x:%x, %d\n", name,
2069 + dirh.start_block, dire->offset,
2070 + dirh.inode_number + dire->inode_number);
2072 + inode = (msblk->iget)(i->i_sb, ino);
2080 + d_add(dentry, inode);
2081 + return ERR_PTR(0);
2084 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2090 +static void squashfs_put_super(struct super_block *s)
2094 + if (s->s_fs_info) {
2095 + struct squashfs_sb_info *sbi = s->s_fs_info;
2096 + if (sbi->block_cache)
2097 + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2098 + if (sbi->block_cache[i].block !=
2099 + SQUASHFS_INVALID_BLK)
2100 + kfree(sbi->block_cache[i].data);
2101 + if (sbi->fragment)
2102 + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
2103 + SQUASHFS_FREE(sbi->fragment[i].data);
2104 + kfree(sbi->fragment);
2105 + kfree(sbi->block_cache);
2106 + kfree(sbi->read_data);
2107 + kfree(sbi->read_page);
2109 + kfree(sbi->fragment_index);
2110 + kfree(sbi->fragment_index_2);
2111 + kfree(sbi->meta_index);
2112 + kfree(s->s_fs_info);
2113 + s->s_fs_info = NULL;
2118 +static int squashfs_get_sb(struct file_system_type *fs_type,
2119 + int flags, const char *dev_name, void *data,
2120 + struct vfsmount *mnt)
2122 + return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
2126 +static int __init init_squashfs_fs(void)
2128 + int err = init_inodecache();
2132 + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2133 + "Phillip Lougher\n");
2135 + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2136 + ERROR("Failed to allocate zlib workspace\n");
2137 + destroy_inodecache();
2142 + if ((err = register_filesystem(&squashfs_fs_type))) {
2143 + vfree(stream.workspace);
2144 + destroy_inodecache();
2152 +static void __exit exit_squashfs_fs(void)
2154 + vfree(stream.workspace);
2155 + unregister_filesystem(&squashfs_fs_type);
2156 + destroy_inodecache();
2160 +static struct kmem_cache * squashfs_inode_cachep;
2163 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2165 + struct squashfs_inode_info *ei;
2166 + ei = kmem_cache_alloc(squashfs_inode_cachep, GFP_KERNEL);
2169 + return &ei->vfs_inode;
2173 +static void squashfs_destroy_inode(struct inode *inode)
2175 + kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2179 +static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
2181 + struct squashfs_inode_info *ei = foo;
2183 + if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2184 + SLAB_CTOR_CONSTRUCTOR)
2185 + inode_init_once(&ei->vfs_inode);
2189 +static int __init init_inodecache(void)
2191 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2192 + sizeof(struct squashfs_inode_info),
2193 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2195 + if (squashfs_inode_cachep == NULL)
2201 +static void destroy_inodecache(void)
2203 + kmem_cache_destroy(squashfs_inode_cachep);
2207 +module_init(init_squashfs_fs);
2208 +module_exit(exit_squashfs_fs);
2209 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2210 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2211 +MODULE_LICENSE("GPL");
2213 +++ b/fs/squashfs/Makefile
2216 +# Makefile for the linux squashfs routines.
2219 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2220 +squashfs-y += inode.o
2221 +squashfs-y += squashfs2_0.o
2223 +++ b/fs/squashfs/squashfs2_0.c
2226 + * Squashfs - a compressed read only filesystem for Linux
2228 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2229 + * Phillip Lougher <phillip@lougher.org.uk>
2231 + * This program is free software; you can redistribute it and/or
2232 + * modify it under the terms of the GNU General Public License
2233 + * as published by the Free Software Foundation; either version 2,
2234 + * or (at your option) any later version.
2236 + * This program is distributed in the hope that it will be useful,
2237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2239 + * GNU General Public License for more details.
2241 + * You should have received a copy of the GNU General Public License
2242 + * along with this program; if not, write to the Free Software
2243 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2248 +#include <linux/types.h>
2249 +#include <linux/squashfs_fs.h>
2250 +#include <linux/module.h>
2251 +#include <linux/errno.h>
2252 +#include <linux/slab.h>
2253 +#include <linux/fs.h>
2254 +#include <linux/smp_lock.h>
2255 +#include <linux/slab.h>
2256 +#include <linux/squashfs_fs_sb.h>
2257 +#include <linux/squashfs_fs_i.h>
2258 +#include <linux/buffer_head.h>
2259 +#include <linux/vfs.h>
2260 +#include <linux/init.h>
2261 +#include <linux/dcache.h>
2262 +#include <linux/wait.h>
2263 +#include <linux/zlib.h>
2264 +#include <linux/blkdev.h>
2265 +#include <linux/vmalloc.h>
2266 +#include <asm/uaccess.h>
2267 +#include <asm/semaphore.h>
2269 +#include "squashfs.h"
2270 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2271 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2272 + struct nameidata *);
2274 +static struct file_operations squashfs_dir_ops_2 = {
2275 + .read = generic_read_dir,
2276 + .readdir = squashfs_readdir_2
2279 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2280 + .lookup = squashfs_lookup_2
2283 +static unsigned char squashfs_filetype_table[] = {
2284 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2287 +static int read_fragment_index_table_2(struct super_block *s)
2289 + struct squashfs_sb_info *msblk = s->s_fs_info;
2290 + struct squashfs_super_block *sblk = &msblk->sblk;
2292 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2293 + (sblk->fragments), GFP_KERNEL))) {
2294 + ERROR("Failed to allocate uid/gid table\n");
2298 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2299 + !squashfs_read_data(s, (char *)
2300 + msblk->fragment_index_2,
2301 + sblk->fragment_table_start,
2302 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2303 + (sblk->fragments) |
2304 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2305 + ERROR("unable to read fragment index table\n");
2309 + if (msblk->swap) {
2311 + unsigned int fragment;
2313 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2315 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2316 + &msblk->fragment_index_2[i], 1);
2317 + msblk->fragment_index_2[i] = fragment;
2325 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2326 + long long *fragment_start_block,
2327 + unsigned int *fragment_size)
2329 + struct squashfs_sb_info *msblk = s->s_fs_info;
2330 + long long start_block =
2331 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2332 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2333 + struct squashfs_fragment_entry_2 fragment_entry;
2335 + if (msblk->swap) {
2336 + struct squashfs_fragment_entry_2 sfragment_entry;
2338 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2339 + start_block, offset,
2340 + sizeof(sfragment_entry), &start_block,
2343 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2345 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2346 + start_block, offset,
2347 + sizeof(fragment_entry), &start_block,
2351 + *fragment_start_block = fragment_entry.start_block;
2352 + *fragment_size = fragment_entry.size;
2361 +static struct inode *squashfs_new_inode(struct super_block *s,
2362 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2364 + struct squashfs_sb_info *msblk = s->s_fs_info;
2365 + struct squashfs_super_block *sblk = &msblk->sblk;
2366 + struct inode *i = new_inode(s);
2370 + i->i_mtime.tv_sec = sblk->mkfs_time;
2371 + i->i_atime.tv_sec = sblk->mkfs_time;
2372 + i->i_ctime.tv_sec = sblk->mkfs_time;
2373 + i->i_uid = msblk->uid[inodeb->uid];
2374 + i->i_mode = inodeb->mode;
2377 + if (inodeb->guid == SQUASHFS_GUIDS)
2378 + i->i_gid = i->i_uid;
2380 + i->i_gid = msblk->guid[inodeb->guid];
2387 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2390 + struct squashfs_sb_info *msblk = s->s_fs_info;
2391 + struct squashfs_super_block *sblk = &msblk->sblk;
2392 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2393 + sblk->inode_table_start;
2394 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2395 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2396 + - sblk->inode_table_start, offset);
2397 + long long next_block;
2398 + unsigned int next_offset;
2399 + union squashfs_inode_header_2 id, sid;
2400 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2401 + *sinodeb = &sid.base;
2403 + TRACE("Entered squashfs_iget\n");
2405 + if (msblk->swap) {
2406 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2407 + offset, sizeof(*sinodeb), &next_block,
2410 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2411 + sizeof(*sinodeb));
2413 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2414 + offset, sizeof(*inodeb), &next_block,
2418 + switch(inodeb->inode_type) {
2419 + case SQUASHFS_FILE_TYPE: {
2420 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2421 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2422 + long long frag_blk;
2423 + unsigned int frag_size;
2425 + if (msblk->swap) {
2426 + if (!squashfs_get_cached_block(s, (char *)
2427 + sinodep, block, offset,
2428 + sizeof(*sinodep), &next_block,
2431 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2433 + if (!squashfs_get_cached_block(s, (char *)
2434 + inodep, block, offset,
2435 + sizeof(*inodep), &next_block,
2439 + frag_blk = SQUASHFS_INVALID_BLK;
2440 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2441 + !get_fragment_location_2(s,
2442 + inodep->fragment, &frag_blk, &frag_size))
2445 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2446 + goto failed_read1;
2448 + i->i_size = inodep->file_size;
2449 + i->i_fop = &generic_ro_fops;
2450 + i->i_mode |= S_IFREG;
2451 + i->i_mtime.tv_sec = inodep->mtime;
2452 + i->i_atime.tv_sec = inodep->mtime;
2453 + i->i_ctime.tv_sec = inodep->mtime;
2454 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2455 + i->i_blksize = PAGE_CACHE_SIZE;
2456 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2457 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2458 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2459 + SQUASHFS_I(i)->start_block = inodep->start_block;
2460 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2461 + SQUASHFS_I(i)->offset = next_offset;
2462 + if (sblk->block_size > 4096)
2463 + i->i_data.a_ops = &squashfs_aops;
2465 + i->i_data.a_ops = &squashfs_aops_4K;
2467 + TRACE("File inode %x:%x, start_block %x, "
2468 + "block_list_start %llx, offset %x\n",
2469 + SQUASHFS_INODE_BLK(inode), offset,
2470 + inodep->start_block, next_block,
2474 + case SQUASHFS_DIR_TYPE: {
2475 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2476 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2478 + if (msblk->swap) {
2479 + if (!squashfs_get_cached_block(s, (char *)
2480 + sinodep, block, offset,
2481 + sizeof(*sinodep), &next_block,
2484 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2486 + if (!squashfs_get_cached_block(s, (char *)
2487 + inodep, block, offset,
2488 + sizeof(*inodep), &next_block,
2492 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2493 + goto failed_read1;
2495 + i->i_size = inodep->file_size;
2496 + i->i_op = &squashfs_dir_inode_ops_2;
2497 + i->i_fop = &squashfs_dir_ops_2;
2498 + i->i_mode |= S_IFDIR;
2499 + i->i_mtime.tv_sec = inodep->mtime;
2500 + i->i_atime.tv_sec = inodep->mtime;
2501 + i->i_ctime.tv_sec = inodep->mtime;
2502 + SQUASHFS_I(i)->start_block = inodep->start_block;
2503 + SQUASHFS_I(i)->offset = inodep->offset;
2504 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2505 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2507 + TRACE("Directory inode %x:%x, start_block %x, offset "
2508 + "%x\n", SQUASHFS_INODE_BLK(inode),
2509 + offset, inodep->start_block,
2513 + case SQUASHFS_LDIR_TYPE: {
2514 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2515 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2517 + if (msblk->swap) {
2518 + if (!squashfs_get_cached_block(s, (char *)
2519 + sinodep, block, offset,
2520 + sizeof(*sinodep), &next_block,
2523 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2526 + if (!squashfs_get_cached_block(s, (char *)
2527 + inodep, block, offset,
2528 + sizeof(*inodep), &next_block,
2532 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2533 + goto failed_read1;
2535 + i->i_size = inodep->file_size;
2536 + i->i_op = &squashfs_dir_inode_ops_2;
2537 + i->i_fop = &squashfs_dir_ops_2;
2538 + i->i_mode |= S_IFDIR;
2539 + i->i_mtime.tv_sec = inodep->mtime;
2540 + i->i_atime.tv_sec = inodep->mtime;
2541 + i->i_ctime.tv_sec = inodep->mtime;
2542 + SQUASHFS_I(i)->start_block = inodep->start_block;
2543 + SQUASHFS_I(i)->offset = inodep->offset;
2544 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2545 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2547 + SQUASHFS_I(i)->u.s2.directory_index_count =
2549 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2551 + TRACE("Long directory inode %x:%x, start_block %x, "
2553 + SQUASHFS_INODE_BLK(inode), offset,
2554 + inodep->start_block, inodep->offset);
2557 + case SQUASHFS_SYMLINK_TYPE: {
2558 + struct squashfs_symlink_inode_header_2 *inodep =
2560 + struct squashfs_symlink_inode_header_2 *sinodep =
2563 + if (msblk->swap) {
2564 + if (!squashfs_get_cached_block(s, (char *)
2565 + sinodep, block, offset,
2566 + sizeof(*sinodep), &next_block,
2569 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2572 + if (!squashfs_get_cached_block(s, (char *)
2573 + inodep, block, offset,
2574 + sizeof(*inodep), &next_block,
2578 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2579 + goto failed_read1;
2581 + i->i_size = inodep->symlink_size;
2582 + i->i_op = &page_symlink_inode_operations;
2583 + i->i_data.a_ops = &squashfs_symlink_aops;
2584 + i->i_mode |= S_IFLNK;
2585 + SQUASHFS_I(i)->start_block = next_block;
2586 + SQUASHFS_I(i)->offset = next_offset;
2588 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2590 + SQUASHFS_INODE_BLK(inode), offset,
2591 + next_block, next_offset);
2594 + case SQUASHFS_BLKDEV_TYPE:
2595 + case SQUASHFS_CHRDEV_TYPE: {
2596 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2597 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2599 + if (msblk->swap) {
2600 + if (!squashfs_get_cached_block(s, (char *)
2601 + sinodep, block, offset,
2602 + sizeof(*sinodep), &next_block,
2605 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2607 + if (!squashfs_get_cached_block(s, (char *)
2608 + inodep, block, offset,
2609 + sizeof(*inodep), &next_block,
2613 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2614 + goto failed_read1;
2616 + i->i_mode |= (inodeb->inode_type ==
2617 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2619 + init_special_inode(i, i->i_mode,
2620 + old_decode_dev(inodep->rdev));
2622 + TRACE("Device inode %x:%x, rdev %x\n",
2623 + SQUASHFS_INODE_BLK(inode), offset,
2627 + case SQUASHFS_FIFO_TYPE:
2628 + case SQUASHFS_SOCKET_TYPE: {
2629 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2630 + goto failed_read1;
2632 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2633 + ? S_IFIFO : S_IFSOCK;
2634 + init_special_inode(i, i->i_mode, 0);
2638 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2639 + inodeb->inode_type);
2640 + goto failed_read1;
2643 + insert_inode_hash(i);
2647 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2654 +static int get_dir_index_using_offset(struct super_block *s, long long
2655 + *next_block, unsigned int *next_offset,
2656 + long long index_start,
2657 + unsigned int index_offset, int i_count,
2660 + struct squashfs_sb_info *msblk = s->s_fs_info;
2661 + struct squashfs_super_block *sblk = &msblk->sblk;
2662 + int i, length = 0;
2663 + struct squashfs_dir_index_2 index;
2665 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2666 + i_count, (unsigned int) f_pos);
2671 + for (i = 0; i < i_count; i++) {
2672 + if (msblk->swap) {
2673 + struct squashfs_dir_index_2 sindex;
2674 + squashfs_get_cached_block(s, (char *) &sindex,
2675 + index_start, index_offset,
2676 + sizeof(sindex), &index_start,
2678 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2680 + squashfs_get_cached_block(s, (char *) &index,
2681 + index_start, index_offset,
2682 + sizeof(index), &index_start,
2685 + if (index.index > f_pos)
2688 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2689 + index.size + 1, &index_start,
2692 + length = index.index;
2693 + *next_block = index.start_block + sblk->directory_table_start;
2696 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2703 +static int get_dir_index_using_name(struct super_block *s, long long
2704 + *next_block, unsigned int *next_offset,
2705 + long long index_start,
2706 + unsigned int index_offset, int i_count,
2707 + const char *name, int size)
2709 + struct squashfs_sb_info *msblk = s->s_fs_info;
2710 + struct squashfs_super_block *sblk = &msblk->sblk;
2711 + int i, length = 0;
2712 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2713 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2714 + char str[SQUASHFS_NAME_LEN + 1];
2716 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2718 + strncpy(str, name, size);
2721 + for (i = 0; i < i_count; i++) {
2722 + if (msblk->swap) {
2723 + struct squashfs_dir_index_2 sindex;
2724 + squashfs_get_cached_block(s, (char *) &sindex,
2725 + index_start, index_offset,
2726 + sizeof(sindex), &index_start,
2728 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2730 + squashfs_get_cached_block(s, (char *) index,
2731 + index_start, index_offset,
2732 + sizeof(struct squashfs_dir_index_2),
2733 + &index_start, &index_offset);
2735 + squashfs_get_cached_block(s, index->name, index_start,
2736 + index_offset, index->size + 1,
2737 + &index_start, &index_offset);
2739 + index->name[index->size + 1] = '\0';
2741 + if (strcmp(index->name, str) > 0)
2744 + length = index->index;
2745 + *next_block = index->start_block + sblk->directory_table_start;
2748 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2753 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2755 + struct inode *i = file->f_dentry->d_inode;
2756 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2757 + struct squashfs_super_block *sblk = &msblk->sblk;
2758 + long long next_block = SQUASHFS_I(i)->start_block +
2759 + sblk->directory_table_start;
2760 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2762 + struct squashfs_dir_header_2 dirh;
2763 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2764 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2766 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2768 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2769 + SQUASHFS_I(i)->u.s2.directory_index_start,
2770 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2771 + SQUASHFS_I(i)->u.s2.directory_index_count,
2774 + while (length < i_size_read(i)) {
2775 + /* read directory header */
2776 + if (msblk->swap) {
2777 + struct squashfs_dir_header_2 sdirh;
2779 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2780 + next_block, next_offset, sizeof(sdirh),
2781 + &next_block, &next_offset))
2784 + length += sizeof(sdirh);
2785 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2787 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2788 + next_block, next_offset, sizeof(dirh),
2789 + &next_block, &next_offset))
2792 + length += sizeof(dirh);
2795 + dir_count = dirh.count + 1;
2796 + while (dir_count--) {
2797 + if (msblk->swap) {
2798 + struct squashfs_dir_entry_2 sdire;
2799 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2800 + &sdire, next_block, next_offset,
2801 + sizeof(sdire), &next_block,
2805 + length += sizeof(sdire);
2806 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2808 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2809 + dire, next_block, next_offset,
2810 + sizeof(*dire), &next_block,
2814 + length += sizeof(*dire);
2817 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2818 + next_block, next_offset,
2819 + dire->size + 1, &next_block,
2823 + length += dire->size + 1;
2825 + if (file->f_pos >= length)
2828 + dire->name[dire->size + 1] = '\0';
2830 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2831 + (unsigned int) dirent, dire->name,
2832 + dire->size + 1, (int) file->f_pos,
2833 + dirh.start_block, dire->offset,
2834 + squashfs_filetype_table[dire->type]);
2836 + if (filldir(dirent, dire->name, dire->size + 1,
2837 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2838 + dirh.start_block, dire->offset),
2839 + squashfs_filetype_table[dire->type])
2841 + TRACE("Filldir returned less than 0\n");
2844 + file->f_pos = length;
2853 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2859 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2860 + struct nameidata *nd)
2862 + const unsigned char *name = dentry->d_name.name;
2863 + int len = dentry->d_name.len;
2864 + struct inode *inode = NULL;
2865 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2866 + struct squashfs_super_block *sblk = &msblk->sblk;
2867 + long long next_block = SQUASHFS_I(i)->start_block +
2868 + sblk->directory_table_start;
2869 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2871 + struct squashfs_dir_header_2 dirh;
2872 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2873 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2874 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2876 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2878 + if (len > SQUASHFS_NAME_LEN)
2881 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2882 + SQUASHFS_I(i)->u.s2.directory_index_start,
2883 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2884 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2887 + while (length < i_size_read(i)) {
2888 + /* read directory header */
2889 + if (msblk->swap) {
2890 + struct squashfs_dir_header_2 sdirh;
2891 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2892 + next_block, next_offset, sizeof(sdirh),
2893 + &next_block, &next_offset))
2896 + length += sizeof(sdirh);
2897 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2899 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2900 + next_block, next_offset, sizeof(dirh),
2901 + &next_block, &next_offset))
2904 + length += sizeof(dirh);
2907 + dir_count = dirh.count + 1;
2908 + while (dir_count--) {
2909 + if (msblk->swap) {
2910 + struct squashfs_dir_entry_2 sdire;
2911 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2912 + &sdire, next_block,next_offset,
2913 + sizeof(sdire), &next_block,
2917 + length += sizeof(sdire);
2918 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2920 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2921 + dire, next_block,next_offset,
2922 + sizeof(*dire), &next_block,
2926 + length += sizeof(*dire);
2929 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2930 + next_block, next_offset, dire->size + 1,
2931 + &next_block, &next_offset))
2934 + length += dire->size + 1;
2936 + if (sorted && name[0] < dire->name[0])
2939 + if ((len == dire->size + 1) && !strncmp(name,
2940 + dire->name, len)) {
2941 + squashfs_inode_t ino =
2942 + SQUASHFS_MKINODE(dirh.start_block,
2945 + TRACE("calling squashfs_iget for directory "
2946 + "entry %s, inode %x:%x, %lld\n", name,
2947 + dirh.start_block, dire->offset, ino);
2949 + inode = (msblk->iget)(i->i_sb, ino);
2957 + d_add(dentry, inode);
2958 + return ERR_PTR(0);
2961 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2967 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2969 + struct squashfs_super_block *sblk = &msblk->sblk;
2971 + msblk->iget = squashfs_iget_2;
2972 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2974 + sblk->bytes_used = sblk->bytes_used_2;
2975 + sblk->uid_start = sblk->uid_start_2;
2976 + sblk->guid_start = sblk->guid_start_2;
2977 + sblk->inode_table_start = sblk->inode_table_start_2;
2978 + sblk->directory_table_start = sblk->directory_table_start_2;
2979 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2984 +++ b/fs/squashfs/squashfs.h
2987 + * Squashfs - a compressed read only filesystem for Linux
2989 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2990 + * Phillip Lougher <phillip@lougher.org.uk>
2992 + * This program is free software; you can redistribute it and/or
2993 + * modify it under the terms of the GNU General Public License
2994 + * as published by the Free Software Foundation; either version 2,
2995 + * or (at your option) any later version.
2997 + * This program is distributed in the hope that it will be useful,
2998 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2999 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3000 + * GNU General Public License for more details.
3002 + * You should have received a copy of the GNU General Public License
3003 + * along with this program; if not, write to the Free Software
3004 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3009 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3010 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3013 +#ifdef SQUASHFS_TRACE
3014 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3016 +#define TRACE(s, args...) {}
3019 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3021 +#define SERROR(s, args...) do { \
3023 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3026 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3028 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3030 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3033 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3034 +#define SQSH_EXTERN
3035 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3036 + long long index, unsigned int length,
3037 + long long *next_index);
3038 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3039 + long long block, unsigned int offset,
3040 + int length, long long *next_block,
3041 + unsigned int *next_offset);
3042 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3043 + squashfs_fragment_cache *fragment);
3044 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3045 + *s, long long start_block,
3047 +extern struct address_space_operations squashfs_symlink_aops;
3048 +extern struct address_space_operations squashfs_aops;
3049 +extern struct address_space_operations squashfs_aops_4K;
3050 +extern struct inode_operations squashfs_dir_inode_ops;
3052 +#define SQSH_EXTERN static
3055 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3056 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3058 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3064 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3065 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3067 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3073 +++ b/include/linux/squashfs_fs.h
3075 +#ifndef SQUASHFS_FS
3076 +#define SQUASHFS_FS
3081 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3082 + * Phillip Lougher <phillip@lougher.org.uk>
3084 + * This program is free software; you can redistribute it and/or
3085 + * modify it under the terms of the GNU General Public License
3086 + * as published by the Free Software Foundation; either version 2,
3087 + * or (at your option) any later version.
3089 + * This program is distributed in the hope that it will be useful,
3090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3092 + * GNU General Public License for more details.
3094 + * You should have received a copy of the GNU General Public License
3095 + * along with this program; if not, write to the Free Software
3096 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3101 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3102 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3105 +#ifdef CONFIG_SQUASHFS_VMALLOC
3106 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3107 +#define SQUASHFS_FREE(a) vfree(a)
3109 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3110 +#define SQUASHFS_FREE(a) kfree(a)
3112 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3113 +#define SQUASHFS_MAJOR 3
3114 +#define SQUASHFS_MINOR 0
3115 +#define SQUASHFS_MAGIC 0x73717368
3116 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3117 +#define SQUASHFS_START 0
3119 +/* size of metadata (inode and directory) blocks */
3120 +#define SQUASHFS_METADATA_SIZE 8192
3121 +#define SQUASHFS_METADATA_LOG 13
3123 +/* default size of data blocks */
3124 +#define SQUASHFS_FILE_SIZE 65536
3125 +#define SQUASHFS_FILE_LOG 16
3127 +#define SQUASHFS_FILE_MAX_SIZE 65536
3129 +/* Max number of uids and gids */
3130 +#define SQUASHFS_UIDS 256
3131 +#define SQUASHFS_GUIDS 255
3133 +/* Max length of filename (not 255) */
3134 +#define SQUASHFS_NAME_LEN 256
3136 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3137 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3138 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3139 +#define SQUASHFS_USED_BLK ((long long) -2)
3141 +/* Filesystem flags */
3142 +#define SQUASHFS_NOI 0
3143 +#define SQUASHFS_NOD 1
3144 +#define SQUASHFS_CHECK 2
3145 +#define SQUASHFS_NOF 3
3146 +#define SQUASHFS_NO_FRAG 4
3147 +#define SQUASHFS_ALWAYS_FRAG 5
3148 +#define SQUASHFS_DUPLICATE 6
3150 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3152 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3155 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3158 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3161 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3164 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3165 + SQUASHFS_ALWAYS_FRAG)
3167 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3168 + SQUASHFS_DUPLICATE)
3170 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3173 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3174 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3175 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3176 + (duplicate_checking << 6))
3178 +/* Max number of types and file types */
3179 +#define SQUASHFS_DIR_TYPE 1
3180 +#define SQUASHFS_FILE_TYPE 2
3181 +#define SQUASHFS_SYMLINK_TYPE 3
3182 +#define SQUASHFS_BLKDEV_TYPE 4
3183 +#define SQUASHFS_CHRDEV_TYPE 5
3184 +#define SQUASHFS_FIFO_TYPE 6
3185 +#define SQUASHFS_SOCKET_TYPE 7
3186 +#define SQUASHFS_LDIR_TYPE 8
3187 +#define SQUASHFS_LREG_TYPE 9
3189 +/* 1.0 filesystem type definitions */
3190 +#define SQUASHFS_TYPES 5
3191 +#define SQUASHFS_IPC_TYPE 0
3193 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3195 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3197 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3198 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3200 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3202 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3204 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3205 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3206 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3208 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3211 + * Inode number ops. Inodes consist of a compressed block number, and an
3212 + * uncompressed offset within that block
3214 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3216 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3218 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3221 +/* Compute 32 bit VFS inode number from squashfs inode number */
3222 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3226 +/* Translate between VFS mode and squashfs mode */
3227 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3229 +/* fragment and fragment table defines */
3230 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3232 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3233 + SQUASHFS_METADATA_SIZE)
3235 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3236 + SQUASHFS_METADATA_SIZE)
3238 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3239 + SQUASHFS_METADATA_SIZE - 1) / \
3240 + SQUASHFS_METADATA_SIZE)
3242 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3243 + sizeof(long long))
3245 +/* cached data constants for filesystem */
3246 +#define SQUASHFS_CACHED_BLKS 8
3248 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3250 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3251 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3253 +#define SQUASHFS_MARKER_BYTE 0xff
3255 +/* meta index cache */
3256 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3257 +#define SQUASHFS_META_ENTRIES 31
3258 +#define SQUASHFS_META_NUMBER 8
3259 +#define SQUASHFS_SLOTS 4
3261 +struct meta_entry {
3262 + long long data_block;
3263 + unsigned int index_block;
3264 + unsigned short offset;
3265 + unsigned short pad;
3268 +struct meta_index {
3269 + unsigned int inode_number;
3270 + unsigned int offset;
3271 + unsigned short entries;
3272 + unsigned short skip;
3273 + unsigned short locked;
3274 + unsigned short pad;
3275 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3280 + * definitions for structures on disk
3283 +typedef long long squashfs_block_t;
3284 +typedef long long squashfs_inode_t;
3286 +struct squashfs_super_block {
3287 + unsigned int s_magic;
3288 + unsigned int inodes;
3289 + unsigned int bytes_used_2;
3290 + unsigned int uid_start_2;
3291 + unsigned int guid_start_2;
3292 + unsigned int inode_table_start_2;
3293 + unsigned int directory_table_start_2;
3294 + unsigned int s_major:16;
3295 + unsigned int s_minor:16;
3296 + unsigned int block_size_1:16;
3297 + unsigned int block_log:16;
3298 + unsigned int flags:8;
3299 + unsigned int no_uids:8;
3300 + unsigned int no_guids:8;
3301 + unsigned int mkfs_time /* time of filesystem creation */;
3302 + squashfs_inode_t root_inode;
3303 + unsigned int block_size;
3304 + unsigned int fragments;
3305 + unsigned int fragment_table_start_2;
3306 + long long bytes_used;
3307 + long long uid_start;
3308 + long long guid_start;
3309 + long long inode_table_start;
3310 + long long directory_table_start;
3311 + long long fragment_table_start;
3313 +} __attribute__ ((packed));
3315 +struct squashfs_dir_index {
3316 + unsigned int index;
3317 + unsigned int start_block;
3318 + unsigned char size;
3319 + unsigned char name[0];
3320 +} __attribute__ ((packed));
3322 +#define SQUASHFS_BASE_INODE_HEADER \
3323 + unsigned int inode_type:4; \
3324 + unsigned int mode:12; \
3325 + unsigned int uid:8; \
3326 + unsigned int guid:8; \
3327 + unsigned int mtime; \
3328 + unsigned int inode_number;
3330 +struct squashfs_base_inode_header {
3331 + SQUASHFS_BASE_INODE_HEADER;
3332 +} __attribute__ ((packed));
3334 +struct squashfs_ipc_inode_header {
3335 + SQUASHFS_BASE_INODE_HEADER;
3336 + unsigned int nlink;
3337 +} __attribute__ ((packed));
3339 +struct squashfs_dev_inode_header {
3340 + SQUASHFS_BASE_INODE_HEADER;
3341 + unsigned int nlink;
3342 + unsigned short rdev;
3343 +} __attribute__ ((packed));
3345 +struct squashfs_symlink_inode_header {
3346 + SQUASHFS_BASE_INODE_HEADER;
3347 + unsigned int nlink;
3348 + unsigned short symlink_size;
3350 +} __attribute__ ((packed));
3352 +struct squashfs_reg_inode_header {
3353 + SQUASHFS_BASE_INODE_HEADER;
3354 + squashfs_block_t start_block;
3355 + unsigned int fragment;
3356 + unsigned int offset;
3357 + unsigned int file_size;
3358 + unsigned short block_list[0];
3359 +} __attribute__ ((packed));
3361 +struct squashfs_lreg_inode_header {
3362 + SQUASHFS_BASE_INODE_HEADER;
3363 + unsigned int nlink;
3364 + squashfs_block_t start_block;
3365 + unsigned int fragment;
3366 + unsigned int offset;
3367 + long long file_size;
3368 + unsigned short block_list[0];
3369 +} __attribute__ ((packed));
3371 +struct squashfs_dir_inode_header {
3372 + SQUASHFS_BASE_INODE_HEADER;
3373 + unsigned int nlink;
3374 + unsigned int file_size:19;
3375 + unsigned int offset:13;
3376 + unsigned int start_block;
3377 + unsigned int parent_inode;
3378 +} __attribute__ ((packed));
3380 +struct squashfs_ldir_inode_header {
3381 + SQUASHFS_BASE_INODE_HEADER;
3382 + unsigned int nlink;
3383 + unsigned int file_size:27;
3384 + unsigned int offset:13;
3385 + unsigned int start_block;
3386 + unsigned int i_count:16;
3387 + unsigned int parent_inode;
3388 + struct squashfs_dir_index index[0];
3389 +} __attribute__ ((packed));
3391 +union squashfs_inode_header {
3392 + struct squashfs_base_inode_header base;
3393 + struct squashfs_dev_inode_header dev;
3394 + struct squashfs_symlink_inode_header symlink;
3395 + struct squashfs_reg_inode_header reg;
3396 + struct squashfs_lreg_inode_header lreg;
3397 + struct squashfs_dir_inode_header dir;
3398 + struct squashfs_ldir_inode_header ldir;
3399 + struct squashfs_ipc_inode_header ipc;
3402 +struct squashfs_dir_entry {
3403 + unsigned int offset:13;
3404 + unsigned int type:3;
3405 + unsigned int size:8;
3406 + int inode_number:16;
3408 +} __attribute__ ((packed));
3410 +struct squashfs_dir_header {
3411 + unsigned int count:8;
3412 + unsigned int start_block;
3413 + unsigned int inode_number;
3414 +} __attribute__ ((packed));
3416 +struct squashfs_fragment_entry {
3417 + long long start_block;
3418 + unsigned int size;
3419 + unsigned int unused;
3420 +} __attribute__ ((packed));
3422 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3423 +extern int squashfs_uncompress_init(void);
3424 +extern int squashfs_uncompress_exit(void);
3427 + * macros to convert each packed bitfield structure from little endian to big
3428 + * endian and vice versa. These are needed when creating or using a filesystem
3429 + * on a machine with different byte ordering to the target architecture.
3433 +#define SQUASHFS_SWAP_START \
3436 + unsigned long long val;\
3437 + unsigned char *s;\
3440 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3441 + SQUASHFS_SWAP_START\
3442 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3443 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3444 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3445 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3446 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3447 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3448 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3449 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3450 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3451 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3452 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3453 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3454 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3455 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3456 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3457 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3458 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3459 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3460 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3461 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3462 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3463 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3464 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3465 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3466 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3467 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3468 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3471 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3472 + SQUASHFS_MEMSET(s, d, n);\
3473 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3474 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3475 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3476 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3477 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3478 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3480 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3481 + SQUASHFS_SWAP_START\
3482 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3485 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3486 + SQUASHFS_SWAP_START\
3487 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3488 + sizeof(struct squashfs_ipc_inode_header))\
3489 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3492 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3493 + SQUASHFS_SWAP_START\
3494 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3495 + sizeof(struct squashfs_dev_inode_header)); \
3496 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3497 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3500 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3501 + SQUASHFS_SWAP_START\
3502 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3503 + sizeof(struct squashfs_symlink_inode_header));\
3504 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3505 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3508 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3509 + SQUASHFS_SWAP_START\
3510 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3511 + sizeof(struct squashfs_reg_inode_header));\
3512 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3513 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3514 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3515 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3518 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3519 + SQUASHFS_SWAP_START\
3520 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3521 + sizeof(struct squashfs_lreg_inode_header));\
3522 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3523 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3524 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3525 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3526 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3529 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3530 + SQUASHFS_SWAP_START\
3531 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3532 + sizeof(struct squashfs_dir_inode_header));\
3533 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3534 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3535 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3536 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3537 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3540 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3541 + SQUASHFS_SWAP_START\
3542 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3543 + sizeof(struct squashfs_ldir_inode_header));\
3544 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3545 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3546 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3547 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3548 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3549 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3552 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3553 + SQUASHFS_SWAP_START\
3554 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3555 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3556 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3557 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3560 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3561 + SQUASHFS_SWAP_START\
3562 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3563 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3564 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3565 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3568 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3569 + SQUASHFS_SWAP_START\
3570 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3571 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3572 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3573 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3574 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3577 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3578 + SQUASHFS_SWAP_START\
3579 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3580 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3581 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3584 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3586 + int bit_position;\
3587 + SQUASHFS_SWAP_START\
3588 + SQUASHFS_MEMSET(s, d, n * 2);\
3589 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3591 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3594 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3596 + int bit_position;\
3597 + SQUASHFS_SWAP_START\
3598 + SQUASHFS_MEMSET(s, d, n * 4);\
3599 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3601 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3604 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3606 + int bit_position;\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_MEMSET(s, d, n * 8);\
3609 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3611 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3614 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3616 + int bit_position;\
3617 + SQUASHFS_SWAP_START\
3618 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3619 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3621 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3624 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3626 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3628 +struct squashfs_base_inode_header_1 {
3629 + unsigned int inode_type:4;
3630 + unsigned int mode:12; /* protection */
3631 + unsigned int uid:4; /* index into uid table */
3632 + unsigned int guid:4; /* index into guid table */
3633 +} __attribute__ ((packed));
3635 +struct squashfs_ipc_inode_header_1 {
3636 + unsigned int inode_type:4;
3637 + unsigned int mode:12; /* protection */
3638 + unsigned int uid:4; /* index into uid table */
3639 + unsigned int guid:4; /* index into guid table */
3640 + unsigned int type:4;
3641 + unsigned int offset:4;
3642 +} __attribute__ ((packed));
3644 +struct squashfs_dev_inode_header_1 {
3645 + unsigned int inode_type:4;
3646 + unsigned int mode:12; /* protection */
3647 + unsigned int uid:4; /* index into uid table */
3648 + unsigned int guid:4; /* index into guid table */
3649 + unsigned short rdev;
3650 +} __attribute__ ((packed));
3652 +struct squashfs_symlink_inode_header_1 {
3653 + unsigned int inode_type:4;
3654 + unsigned int mode:12; /* protection */
3655 + unsigned int uid:4; /* index into uid table */
3656 + unsigned int guid:4; /* index into guid table */
3657 + unsigned short symlink_size;
3659 +} __attribute__ ((packed));
3661 +struct squashfs_reg_inode_header_1 {
3662 + unsigned int inode_type:4;
3663 + unsigned int mode:12; /* protection */
3664 + unsigned int uid:4; /* index into uid table */
3665 + unsigned int guid:4; /* index into guid table */
3666 + unsigned int mtime;
3667 + unsigned int start_block;
3668 + unsigned int file_size:32;
3669 + unsigned short block_list[0];
3670 +} __attribute__ ((packed));
3672 +struct squashfs_dir_inode_header_1 {
3673 + unsigned int inode_type:4;
3674 + unsigned int mode:12; /* protection */
3675 + unsigned int uid:4; /* index into uid table */
3676 + unsigned int guid:4; /* index into guid table */
3677 + unsigned int file_size:19;
3678 + unsigned int offset:13;
3679 + unsigned int mtime;
3680 + unsigned int start_block:24;
3681 +} __attribute__ ((packed));
3683 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3684 + SQUASHFS_MEMSET(s, d, n);\
3685 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3686 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3687 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3688 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3690 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3691 + SQUASHFS_SWAP_START\
3692 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3695 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3696 + SQUASHFS_SWAP_START\
3697 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3698 + sizeof(struct squashfs_ipc_inode_header_1));\
3699 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3700 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3703 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3704 + SQUASHFS_SWAP_START\
3705 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3706 + sizeof(struct squashfs_dev_inode_header_1));\
3707 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3710 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3711 + SQUASHFS_SWAP_START\
3712 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3713 + sizeof(struct squashfs_symlink_inode_header_1));\
3714 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3717 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3718 + SQUASHFS_SWAP_START\
3719 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3720 + sizeof(struct squashfs_reg_inode_header_1));\
3721 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3722 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3723 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3726 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3727 + SQUASHFS_SWAP_START\
3728 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3729 + sizeof(struct squashfs_dir_inode_header_1));\
3730 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3731 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3732 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3733 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3738 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3740 +struct squashfs_dir_index_2 {
3741 + unsigned int index:27;
3742 + unsigned int start_block:29;
3743 + unsigned char size;
3744 + unsigned char name[0];
3745 +} __attribute__ ((packed));
3747 +struct squashfs_base_inode_header_2 {
3748 + unsigned int inode_type:4;
3749 + unsigned int mode:12; /* protection */
3750 + unsigned int uid:8; /* index into uid table */
3751 + unsigned int guid:8; /* index into guid table */
3752 +} __attribute__ ((packed));
3754 +struct squashfs_ipc_inode_header_2 {
3755 + unsigned int inode_type:4;
3756 + unsigned int mode:12; /* protection */
3757 + unsigned int uid:8; /* index into uid table */
3758 + unsigned int guid:8; /* index into guid table */
3759 +} __attribute__ ((packed));
3761 +struct squashfs_dev_inode_header_2 {
3762 + unsigned int inode_type:4;
3763 + unsigned int mode:12; /* protection */
3764 + unsigned int uid:8; /* index into uid table */
3765 + unsigned int guid:8; /* index into guid table */
3766 + unsigned short rdev;
3767 +} __attribute__ ((packed));
3769 +struct squashfs_symlink_inode_header_2 {
3770 + unsigned int inode_type:4;
3771 + unsigned int mode:12; /* protection */
3772 + unsigned int uid:8; /* index into uid table */
3773 + unsigned int guid:8; /* index into guid table */
3774 + unsigned short symlink_size;
3776 +} __attribute__ ((packed));
3778 +struct squashfs_reg_inode_header_2 {
3779 + unsigned int inode_type:4;
3780 + unsigned int mode:12; /* protection */
3781 + unsigned int uid:8; /* index into uid table */
3782 + unsigned int guid:8; /* index into guid table */
3783 + unsigned int mtime;
3784 + unsigned int start_block;
3785 + unsigned int fragment;
3786 + unsigned int offset;
3787 + unsigned int file_size:32;
3788 + unsigned short block_list[0];
3789 +} __attribute__ ((packed));
3791 +struct squashfs_dir_inode_header_2 {
3792 + unsigned int inode_type:4;
3793 + unsigned int mode:12; /* protection */
3794 + unsigned int uid:8; /* index into uid table */
3795 + unsigned int guid:8; /* index into guid table */
3796 + unsigned int file_size:19;
3797 + unsigned int offset:13;
3798 + unsigned int mtime;
3799 + unsigned int start_block:24;
3800 +} __attribute__ ((packed));
3802 +struct squashfs_ldir_inode_header_2 {
3803 + unsigned int inode_type:4;
3804 + unsigned int mode:12; /* protection */
3805 + unsigned int uid:8; /* index into uid table */
3806 + unsigned int guid:8; /* index into guid table */
3807 + unsigned int file_size:27;
3808 + unsigned int offset:13;
3809 + unsigned int mtime;
3810 + unsigned int start_block:24;
3811 + unsigned int i_count:16;
3812 + struct squashfs_dir_index_2 index[0];
3813 +} __attribute__ ((packed));
3815 +union squashfs_inode_header_2 {
3816 + struct squashfs_base_inode_header_2 base;
3817 + struct squashfs_dev_inode_header_2 dev;
3818 + struct squashfs_symlink_inode_header_2 symlink;
3819 + struct squashfs_reg_inode_header_2 reg;
3820 + struct squashfs_dir_inode_header_2 dir;
3821 + struct squashfs_ldir_inode_header_2 ldir;
3822 + struct squashfs_ipc_inode_header_2 ipc;
3825 +struct squashfs_dir_header_2 {
3826 + unsigned int count:8;
3827 + unsigned int start_block:24;
3828 +} __attribute__ ((packed));
3830 +struct squashfs_dir_entry_2 {
3831 + unsigned int offset:13;
3832 + unsigned int type:3;
3833 + unsigned int size:8;
3835 +} __attribute__ ((packed));
3837 +struct squashfs_fragment_entry_2 {
3838 + unsigned int start_block;
3839 + unsigned int size;
3840 +} __attribute__ ((packed));
3842 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3843 + SQUASHFS_MEMSET(s, d, n);\
3844 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3845 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3846 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3847 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3849 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3850 + SQUASHFS_SWAP_START\
3851 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3854 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3855 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3857 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3858 + SQUASHFS_SWAP_START\
3859 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3860 + sizeof(struct squashfs_dev_inode_header_2)); \
3861 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3864 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3865 + SQUASHFS_SWAP_START\
3866 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3867 + sizeof(struct squashfs_symlink_inode_header_2));\
3868 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3871 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3872 + SQUASHFS_SWAP_START\
3873 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3874 + sizeof(struct squashfs_reg_inode_header_2));\
3875 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3876 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3877 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3878 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3879 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3882 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3883 + SQUASHFS_SWAP_START\
3884 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3885 + sizeof(struct squashfs_dir_inode_header_2));\
3886 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3887 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3888 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3889 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3892 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3893 + SQUASHFS_SWAP_START\
3894 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3895 + sizeof(struct squashfs_ldir_inode_header_2));\
3896 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3897 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3898 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3899 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3900 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3903 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3904 + SQUASHFS_SWAP_START\
3905 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3906 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3907 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3908 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3910 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3911 + SQUASHFS_SWAP_START\
3912 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3913 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3914 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3917 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3918 + SQUASHFS_SWAP_START\
3919 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3920 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3921 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3922 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3925 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3926 + SQUASHFS_SWAP_START\
3927 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3928 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3929 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3932 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3934 +/* fragment and fragment table defines */
3935 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3937 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3938 + SQUASHFS_METADATA_SIZE)
3940 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3941 + SQUASHFS_METADATA_SIZE)
3943 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3944 + SQUASHFS_METADATA_SIZE - 1) / \
3945 + SQUASHFS_METADATA_SIZE)
3947 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3955 + * macros used to swap each structure entry, taking into account
3956 + * bitfields and different bitfield placing conventions on differing
3960 +#include <asm/byteorder.h>
3962 +#ifdef __BIG_ENDIAN
3963 + /* convert from little endian to big endian */
3964 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3967 + /* convert from big endian to little endian */
3968 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3969 + tbits, 64 - tbits - b_pos)
3972 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3975 + s = (unsigned char *)p + (pos / 8);\
3976 + d = ((unsigned char *) &val) + 7;\
3977 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3979 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3982 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3987 +++ b/include/linux/squashfs_fs_i.h
3989 +#ifndef SQUASHFS_FS_I
3990 +#define SQUASHFS_FS_I
3994 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3995 + * Phillip Lougher <phillip@lougher.org.uk>
3997 + * This program is free software; you can redistribute it and/or
3998 + * modify it under the terms of the GNU General Public License
3999 + * as published by the Free Software Foundation; either version 2,
4000 + * or (at your option) any later version.
4002 + * This program is distributed in the hope that it will be useful,
4003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4005 + * GNU General Public License for more details.
4007 + * You should have received a copy of the GNU General Public License
4008 + * along with this program; if not, write to the Free Software
4009 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4014 +struct squashfs_inode_info {
4015 + long long start_block;
4016 + unsigned int offset;
4019 + long long fragment_start_block;
4020 + unsigned int fragment_size;
4021 + unsigned int fragment_offset;
4022 + long long block_list_start;
4025 + long long directory_index_start;
4026 + unsigned int directory_index_offset;
4027 + unsigned int directory_index_count;
4028 + unsigned int parent_inode;
4031 + struct inode vfs_inode;
4035 +++ b/include/linux/squashfs_fs_sb.h
4037 +#ifndef SQUASHFS_FS_SB
4038 +#define SQUASHFS_FS_SB
4042 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4043 + * Phillip Lougher <phillip@lougher.org.uk>
4045 + * This program is free software; you can redistribute it and/or
4046 + * modify it under the terms of the GNU General Public License
4047 + * as published by the Free Software Foundation; either version 2,
4048 + * or (at your option) any later version.
4050 + * This program is distributed in the hope that it will be useful,
4051 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4052 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4053 + * GNU General Public License for more details.
4055 + * You should have received a copy of the GNU General Public License
4056 + * along with this program; if not, write to the Free Software
4057 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4059 + * squashfs_fs_sb.h
4062 +#include <linux/squashfs_fs.h>
4064 +struct squashfs_cache {
4067 + long long next_index;
4071 +struct squashfs_fragment_cache {
4074 + unsigned int locked;
4078 +struct squashfs_sb_info {
4079 + struct squashfs_super_block sblk;
4081 + int devblksize_log2;
4083 + struct squashfs_cache *block_cache;
4084 + struct squashfs_fragment_cache *fragment;
4086 + int next_fragment;
4087 + int next_meta_index;
4088 + unsigned int *uid;
4089 + unsigned int *guid;
4090 + long long *fragment_index;
4091 + unsigned int *fragment_index_2;
4092 + unsigned int read_size;
4095 + struct semaphore read_data_mutex;
4096 + struct semaphore read_page_mutex;
4097 + struct semaphore block_cache_mutex;
4098 + struct semaphore fragment_mutex;
4099 + struct semaphore meta_index_mutex;
4100 + wait_queue_head_t waitq;
4101 + wait_queue_head_t fragment_wait_queue;
4102 + struct meta_index *meta_index;
4103 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4105 + long long (*read_blocklist)(struct inode *inode, int \
4106 + index, int readahead_blks, char *block_list, \
4107 + unsigned short **block_p, unsigned int *bsize);
4108 + int (*read_fragment_index_table)(struct super_block *s);
4111 --- a/init/do_mounts_rd.c
4112 +++ b/init/do_mounts_rd.c
4114 #include <linux/ext2_fs.h>
4115 #include <linux/romfs_fs.h>
4116 #include <linux/cramfs_fs.h>
4117 +#include <linux/squashfs_fs.h>
4118 #include <linux/initrd.h>
4119 #include <linux/string.h>
4121 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4122 * numbers could not be found.
4124 * We currently check for the following magic numbers:
4129 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4130 struct ext2_super_block *ext2sb;
4131 struct romfs_super_block *romfsb;
4132 struct cramfs_super *cramfsb;
4133 + struct squashfs_super_block *squashfsb;
4137 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4138 ext2sb = (struct ext2_super_block *) buf;
4139 romfsb = (struct romfs_super_block *) buf;
4140 cramfsb = (struct cramfs_super *) buf;
4141 + squashfsb = (struct squashfs_super_block *) buf;
4142 memset(buf, 0xe5, size);
4145 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
4149 + /* squashfs is at block zero too */
4150 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4151 + printk(KERN_NOTICE
4152 + "RAMDISK: squashfs filesystem found at block %d\n",
4154 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4159 * Read block 1 to test for minix and ext2 superblock