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)"
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 + inode_init_once(&ei->vfs_inode);
2187 +static int __init init_inodecache(void)
2189 + squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2190 + sizeof(struct squashfs_inode_info),
2191 + 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2193 + if (squashfs_inode_cachep == NULL)
2199 +static void destroy_inodecache(void)
2201 + kmem_cache_destroy(squashfs_inode_cachep);
2205 +module_init(init_squashfs_fs);
2206 +module_exit(exit_squashfs_fs);
2207 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2208 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2209 +MODULE_LICENSE("GPL");
2211 +++ b/fs/squashfs/Makefile
2214 +# Makefile for the linux squashfs routines.
2217 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2218 +squashfs-y += inode.o
2219 +squashfs-y += squashfs2_0.o
2221 +++ b/fs/squashfs/squashfs2_0.c
2224 + * Squashfs - a compressed read only filesystem for Linux
2226 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2227 + * Phillip Lougher <phillip@lougher.org.uk>
2229 + * This program is free software; you can redistribute it and/or
2230 + * modify it under the terms of the GNU General Public License
2231 + * as published by the Free Software Foundation; either version 2,
2232 + * or (at your option) any later version.
2234 + * This program is distributed in the hope that it will be useful,
2235 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2236 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2237 + * GNU General Public License for more details.
2239 + * You should have received a copy of the GNU General Public License
2240 + * along with this program; if not, write to the Free Software
2241 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2246 +#include <linux/types.h>
2247 +#include <linux/squashfs_fs.h>
2248 +#include <linux/module.h>
2249 +#include <linux/errno.h>
2250 +#include <linux/slab.h>
2251 +#include <linux/fs.h>
2252 +#include <linux/smp_lock.h>
2253 +#include <linux/slab.h>
2254 +#include <linux/squashfs_fs_sb.h>
2255 +#include <linux/squashfs_fs_i.h>
2256 +#include <linux/buffer_head.h>
2257 +#include <linux/vfs.h>
2258 +#include <linux/init.h>
2259 +#include <linux/dcache.h>
2260 +#include <linux/wait.h>
2261 +#include <linux/zlib.h>
2262 +#include <linux/blkdev.h>
2263 +#include <linux/vmalloc.h>
2264 +#include <asm/uaccess.h>
2265 +#include <asm/semaphore.h>
2267 +#include "squashfs.h"
2268 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2269 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2270 + struct nameidata *);
2272 +static struct file_operations squashfs_dir_ops_2 = {
2273 + .read = generic_read_dir,
2274 + .readdir = squashfs_readdir_2
2277 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2278 + .lookup = squashfs_lookup_2
2281 +static unsigned char squashfs_filetype_table[] = {
2282 + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2285 +static int read_fragment_index_table_2(struct super_block *s)
2287 + struct squashfs_sb_info *msblk = s->s_fs_info;
2288 + struct squashfs_super_block *sblk = &msblk->sblk;
2290 + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2291 + (sblk->fragments), GFP_KERNEL))) {
2292 + ERROR("Failed to allocate uid/gid table\n");
2296 + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2297 + !squashfs_read_data(s, (char *)
2298 + msblk->fragment_index_2,
2299 + sblk->fragment_table_start,
2300 + SQUASHFS_FRAGMENT_INDEX_BYTES_2
2301 + (sblk->fragments) |
2302 + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2303 + ERROR("unable to read fragment index table\n");
2307 + if (msblk->swap) {
2309 + unsigned int fragment;
2311 + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2313 + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2314 + &msblk->fragment_index_2[i], 1);
2315 + msblk->fragment_index_2[i] = fragment;
2323 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2324 + long long *fragment_start_block,
2325 + unsigned int *fragment_size)
2327 + struct squashfs_sb_info *msblk = s->s_fs_info;
2328 + long long start_block =
2329 + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2330 + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2331 + struct squashfs_fragment_entry_2 fragment_entry;
2333 + if (msblk->swap) {
2334 + struct squashfs_fragment_entry_2 sfragment_entry;
2336 + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2337 + start_block, offset,
2338 + sizeof(sfragment_entry), &start_block,
2341 + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2343 + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2344 + start_block, offset,
2345 + sizeof(fragment_entry), &start_block,
2349 + *fragment_start_block = fragment_entry.start_block;
2350 + *fragment_size = fragment_entry.size;
2359 +static struct inode *squashfs_new_inode(struct super_block *s,
2360 + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2362 + struct squashfs_sb_info *msblk = s->s_fs_info;
2363 + struct squashfs_super_block *sblk = &msblk->sblk;
2364 + struct inode *i = new_inode(s);
2368 + i->i_mtime.tv_sec = sblk->mkfs_time;
2369 + i->i_atime.tv_sec = sblk->mkfs_time;
2370 + i->i_ctime.tv_sec = sblk->mkfs_time;
2371 + i->i_uid = msblk->uid[inodeb->uid];
2372 + i->i_mode = inodeb->mode;
2375 + if (inodeb->guid == SQUASHFS_GUIDS)
2376 + i->i_gid = i->i_uid;
2378 + i->i_gid = msblk->guid[inodeb->guid];
2385 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2388 + struct squashfs_sb_info *msblk = s->s_fs_info;
2389 + struct squashfs_super_block *sblk = &msblk->sblk;
2390 + unsigned int block = SQUASHFS_INODE_BLK(inode) +
2391 + sblk->inode_table_start;
2392 + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2393 + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2394 + - sblk->inode_table_start, offset);
2395 + long long next_block;
2396 + unsigned int next_offset;
2397 + union squashfs_inode_header_2 id, sid;
2398 + struct squashfs_base_inode_header_2 *inodeb = &id.base,
2399 + *sinodeb = &sid.base;
2401 + TRACE("Entered squashfs_iget\n");
2403 + if (msblk->swap) {
2404 + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2405 + offset, sizeof(*sinodeb), &next_block,
2408 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2409 + sizeof(*sinodeb));
2411 + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2412 + offset, sizeof(*inodeb), &next_block,
2416 + switch(inodeb->inode_type) {
2417 + case SQUASHFS_FILE_TYPE: {
2418 + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2419 + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2420 + long long frag_blk;
2421 + unsigned int frag_size;
2423 + if (msblk->swap) {
2424 + if (!squashfs_get_cached_block(s, (char *)
2425 + sinodep, block, offset,
2426 + sizeof(*sinodep), &next_block,
2429 + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2431 + if (!squashfs_get_cached_block(s, (char *)
2432 + inodep, block, offset,
2433 + sizeof(*inodep), &next_block,
2437 + frag_blk = SQUASHFS_INVALID_BLK;
2438 + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2439 + !get_fragment_location_2(s,
2440 + inodep->fragment, &frag_blk, &frag_size))
2443 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2444 + goto failed_read1;
2446 + i->i_size = inodep->file_size;
2447 + i->i_fop = &generic_ro_fops;
2448 + i->i_mode |= S_IFREG;
2449 + i->i_mtime.tv_sec = inodep->mtime;
2450 + i->i_atime.tv_sec = inodep->mtime;
2451 + i->i_ctime.tv_sec = inodep->mtime;
2452 + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2453 + i->i_blksize = PAGE_CACHE_SIZE;
2454 + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2455 + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2456 + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2457 + SQUASHFS_I(i)->start_block = inodep->start_block;
2458 + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2459 + SQUASHFS_I(i)->offset = next_offset;
2460 + if (sblk->block_size > 4096)
2461 + i->i_data.a_ops = &squashfs_aops;
2463 + i->i_data.a_ops = &squashfs_aops_4K;
2465 + TRACE("File inode %x:%x, start_block %x, "
2466 + "block_list_start %llx, offset %x\n",
2467 + SQUASHFS_INODE_BLK(inode), offset,
2468 + inodep->start_block, next_block,
2472 + case SQUASHFS_DIR_TYPE: {
2473 + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2474 + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2476 + if (msblk->swap) {
2477 + if (!squashfs_get_cached_block(s, (char *)
2478 + sinodep, block, offset,
2479 + sizeof(*sinodep), &next_block,
2482 + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2484 + if (!squashfs_get_cached_block(s, (char *)
2485 + inodep, block, offset,
2486 + sizeof(*inodep), &next_block,
2490 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2491 + goto failed_read1;
2493 + i->i_size = inodep->file_size;
2494 + i->i_op = &squashfs_dir_inode_ops_2;
2495 + i->i_fop = &squashfs_dir_ops_2;
2496 + i->i_mode |= S_IFDIR;
2497 + i->i_mtime.tv_sec = inodep->mtime;
2498 + i->i_atime.tv_sec = inodep->mtime;
2499 + i->i_ctime.tv_sec = inodep->mtime;
2500 + SQUASHFS_I(i)->start_block = inodep->start_block;
2501 + SQUASHFS_I(i)->offset = inodep->offset;
2502 + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2503 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2505 + TRACE("Directory inode %x:%x, start_block %x, offset "
2506 + "%x\n", SQUASHFS_INODE_BLK(inode),
2507 + offset, inodep->start_block,
2511 + case SQUASHFS_LDIR_TYPE: {
2512 + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2513 + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2515 + if (msblk->swap) {
2516 + if (!squashfs_get_cached_block(s, (char *)
2517 + sinodep, block, offset,
2518 + sizeof(*sinodep), &next_block,
2521 + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2524 + if (!squashfs_get_cached_block(s, (char *)
2525 + inodep, block, offset,
2526 + sizeof(*inodep), &next_block,
2530 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2531 + goto failed_read1;
2533 + i->i_size = inodep->file_size;
2534 + i->i_op = &squashfs_dir_inode_ops_2;
2535 + i->i_fop = &squashfs_dir_ops_2;
2536 + i->i_mode |= S_IFDIR;
2537 + i->i_mtime.tv_sec = inodep->mtime;
2538 + i->i_atime.tv_sec = inodep->mtime;
2539 + i->i_ctime.tv_sec = inodep->mtime;
2540 + SQUASHFS_I(i)->start_block = inodep->start_block;
2541 + SQUASHFS_I(i)->offset = inodep->offset;
2542 + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2543 + SQUASHFS_I(i)->u.s2.directory_index_offset =
2545 + SQUASHFS_I(i)->u.s2.directory_index_count =
2547 + SQUASHFS_I(i)->u.s2.parent_inode = 0;
2549 + TRACE("Long directory inode %x:%x, start_block %x, "
2551 + SQUASHFS_INODE_BLK(inode), offset,
2552 + inodep->start_block, inodep->offset);
2555 + case SQUASHFS_SYMLINK_TYPE: {
2556 + struct squashfs_symlink_inode_header_2 *inodep =
2558 + struct squashfs_symlink_inode_header_2 *sinodep =
2561 + if (msblk->swap) {
2562 + if (!squashfs_get_cached_block(s, (char *)
2563 + sinodep, block, offset,
2564 + sizeof(*sinodep), &next_block,
2567 + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2570 + if (!squashfs_get_cached_block(s, (char *)
2571 + inodep, block, offset,
2572 + sizeof(*inodep), &next_block,
2576 + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2577 + goto failed_read1;
2579 + i->i_size = inodep->symlink_size;
2580 + i->i_op = &page_symlink_inode_operations;
2581 + i->i_data.a_ops = &squashfs_symlink_aops;
2582 + i->i_mode |= S_IFLNK;
2583 + SQUASHFS_I(i)->start_block = next_block;
2584 + SQUASHFS_I(i)->offset = next_offset;
2586 + TRACE("Symbolic link inode %x:%x, start_block %llx, "
2588 + SQUASHFS_INODE_BLK(inode), offset,
2589 + next_block, next_offset);
2592 + case SQUASHFS_BLKDEV_TYPE:
2593 + case SQUASHFS_CHRDEV_TYPE: {
2594 + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2595 + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2597 + if (msblk->swap) {
2598 + if (!squashfs_get_cached_block(s, (char *)
2599 + sinodep, block, offset,
2600 + sizeof(*sinodep), &next_block,
2603 + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2605 + if (!squashfs_get_cached_block(s, (char *)
2606 + inodep, block, offset,
2607 + sizeof(*inodep), &next_block,
2611 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2612 + goto failed_read1;
2614 + i->i_mode |= (inodeb->inode_type ==
2615 + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
2617 + init_special_inode(i, i->i_mode,
2618 + old_decode_dev(inodep->rdev));
2620 + TRACE("Device inode %x:%x, rdev %x\n",
2621 + SQUASHFS_INODE_BLK(inode), offset,
2625 + case SQUASHFS_FIFO_TYPE:
2626 + case SQUASHFS_SOCKET_TYPE: {
2627 + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2628 + goto failed_read1;
2630 + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2631 + ? S_IFIFO : S_IFSOCK;
2632 + init_special_inode(i, i->i_mode, 0);
2636 + ERROR("Unknown inode type %d in squashfs_iget!\n",
2637 + inodeb->inode_type);
2638 + goto failed_read1;
2641 + insert_inode_hash(i);
2645 + ERROR("Unable to read inode [%x:%x]\n", block, offset);
2652 +static int get_dir_index_using_offset(struct super_block *s, long long
2653 + *next_block, unsigned int *next_offset,
2654 + long long index_start,
2655 + unsigned int index_offset, int i_count,
2658 + struct squashfs_sb_info *msblk = s->s_fs_info;
2659 + struct squashfs_super_block *sblk = &msblk->sblk;
2660 + int i, length = 0;
2661 + struct squashfs_dir_index_2 index;
2663 + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2664 + i_count, (unsigned int) f_pos);
2669 + for (i = 0; i < i_count; i++) {
2670 + if (msblk->swap) {
2671 + struct squashfs_dir_index_2 sindex;
2672 + squashfs_get_cached_block(s, (char *) &sindex,
2673 + index_start, index_offset,
2674 + sizeof(sindex), &index_start,
2676 + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2678 + squashfs_get_cached_block(s, (char *) &index,
2679 + index_start, index_offset,
2680 + sizeof(index), &index_start,
2683 + if (index.index > f_pos)
2686 + squashfs_get_cached_block(s, NULL, index_start, index_offset,
2687 + index.size + 1, &index_start,
2690 + length = index.index;
2691 + *next_block = index.start_block + sblk->directory_table_start;
2694 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2701 +static int get_dir_index_using_name(struct super_block *s, long long
2702 + *next_block, unsigned int *next_offset,
2703 + long long index_start,
2704 + unsigned int index_offset, int i_count,
2705 + const char *name, int size)
2707 + struct squashfs_sb_info *msblk = s->s_fs_info;
2708 + struct squashfs_super_block *sblk = &msblk->sblk;
2709 + int i, length = 0;
2710 + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2711 + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2712 + char str[SQUASHFS_NAME_LEN + 1];
2714 + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2716 + strncpy(str, name, size);
2719 + for (i = 0; i < i_count; i++) {
2720 + if (msblk->swap) {
2721 + struct squashfs_dir_index_2 sindex;
2722 + squashfs_get_cached_block(s, (char *) &sindex,
2723 + index_start, index_offset,
2724 + sizeof(sindex), &index_start,
2726 + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2728 + squashfs_get_cached_block(s, (char *) index,
2729 + index_start, index_offset,
2730 + sizeof(struct squashfs_dir_index_2),
2731 + &index_start, &index_offset);
2733 + squashfs_get_cached_block(s, index->name, index_start,
2734 + index_offset, index->size + 1,
2735 + &index_start, &index_offset);
2737 + index->name[index->size + 1] = '\0';
2739 + if (strcmp(index->name, str) > 0)
2742 + length = index->index;
2743 + *next_block = index->start_block + sblk->directory_table_start;
2746 + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2751 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2753 + struct inode *i = file->f_dentry->d_inode;
2754 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2755 + struct squashfs_super_block *sblk = &msblk->sblk;
2756 + long long next_block = SQUASHFS_I(i)->start_block +
2757 + sblk->directory_table_start;
2758 + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2760 + struct squashfs_dir_header_2 dirh;
2761 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2762 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2764 + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2766 + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2767 + SQUASHFS_I(i)->u.s2.directory_index_start,
2768 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2769 + SQUASHFS_I(i)->u.s2.directory_index_count,
2772 + while (length < i_size_read(i)) {
2773 + /* read directory header */
2774 + if (msblk->swap) {
2775 + struct squashfs_dir_header_2 sdirh;
2777 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2778 + next_block, next_offset, sizeof(sdirh),
2779 + &next_block, &next_offset))
2782 + length += sizeof(sdirh);
2783 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2785 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2786 + next_block, next_offset, sizeof(dirh),
2787 + &next_block, &next_offset))
2790 + length += sizeof(dirh);
2793 + dir_count = dirh.count + 1;
2794 + while (dir_count--) {
2795 + if (msblk->swap) {
2796 + struct squashfs_dir_entry_2 sdire;
2797 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2798 + &sdire, next_block, next_offset,
2799 + sizeof(sdire), &next_block,
2803 + length += sizeof(sdire);
2804 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2806 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2807 + dire, next_block, next_offset,
2808 + sizeof(*dire), &next_block,
2812 + length += sizeof(*dire);
2815 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2816 + next_block, next_offset,
2817 + dire->size + 1, &next_block,
2821 + length += dire->size + 1;
2823 + if (file->f_pos >= length)
2826 + dire->name[dire->size + 1] = '\0';
2828 + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2829 + (unsigned int) dirent, dire->name,
2830 + dire->size + 1, (int) file->f_pos,
2831 + dirh.start_block, dire->offset,
2832 + squashfs_filetype_table[dire->type]);
2834 + if (filldir(dirent, dire->name, dire->size + 1,
2835 + file->f_pos, SQUASHFS_MK_VFS_INODE(
2836 + dirh.start_block, dire->offset),
2837 + squashfs_filetype_table[dire->type])
2839 + TRACE("Filldir returned less than 0\n");
2842 + file->f_pos = length;
2851 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2857 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2858 + struct nameidata *nd)
2860 + const unsigned char *name = dentry->d_name.name;
2861 + int len = dentry->d_name.len;
2862 + struct inode *inode = NULL;
2863 + struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2864 + struct squashfs_super_block *sblk = &msblk->sblk;
2865 + long long next_block = SQUASHFS_I(i)->start_block +
2866 + sblk->directory_table_start;
2867 + int next_offset = SQUASHFS_I(i)->offset, length = 0,
2869 + struct squashfs_dir_header_2 dirh;
2870 + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2871 + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2872 + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2874 + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2876 + if (len > SQUASHFS_NAME_LEN)
2879 + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2880 + SQUASHFS_I(i)->u.s2.directory_index_start,
2881 + SQUASHFS_I(i)->u.s2.directory_index_offset,
2882 + SQUASHFS_I(i)->u.s2.directory_index_count, name,
2885 + while (length < i_size_read(i)) {
2886 + /* read directory header */
2887 + if (msblk->swap) {
2888 + struct squashfs_dir_header_2 sdirh;
2889 + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2890 + next_block, next_offset, sizeof(sdirh),
2891 + &next_block, &next_offset))
2894 + length += sizeof(sdirh);
2895 + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2897 + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2898 + next_block, next_offset, sizeof(dirh),
2899 + &next_block, &next_offset))
2902 + length += sizeof(dirh);
2905 + dir_count = dirh.count + 1;
2906 + while (dir_count--) {
2907 + if (msblk->swap) {
2908 + struct squashfs_dir_entry_2 sdire;
2909 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2910 + &sdire, next_block,next_offset,
2911 + sizeof(sdire), &next_block,
2915 + length += sizeof(sdire);
2916 + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2918 + if (!squashfs_get_cached_block(i->i_sb, (char *)
2919 + dire, next_block,next_offset,
2920 + sizeof(*dire), &next_block,
2924 + length += sizeof(*dire);
2927 + if (!squashfs_get_cached_block(i->i_sb, dire->name,
2928 + next_block, next_offset, dire->size + 1,
2929 + &next_block, &next_offset))
2932 + length += dire->size + 1;
2934 + if (sorted && name[0] < dire->name[0])
2937 + if ((len == dire->size + 1) && !strncmp(name,
2938 + dire->name, len)) {
2939 + squashfs_inode_t ino =
2940 + SQUASHFS_MKINODE(dirh.start_block,
2943 + TRACE("calling squashfs_iget for directory "
2944 + "entry %s, inode %x:%x, %lld\n", name,
2945 + dirh.start_block, dire->offset, ino);
2947 + inode = (msblk->iget)(i->i_sb, ino);
2955 + d_add(dentry, inode);
2956 + return ERR_PTR(0);
2959 + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2965 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2967 + struct squashfs_super_block *sblk = &msblk->sblk;
2969 + msblk->iget = squashfs_iget_2;
2970 + msblk->read_fragment_index_table = read_fragment_index_table_2;
2972 + sblk->bytes_used = sblk->bytes_used_2;
2973 + sblk->uid_start = sblk->uid_start_2;
2974 + sblk->guid_start = sblk->guid_start_2;
2975 + sblk->inode_table_start = sblk->inode_table_start_2;
2976 + sblk->directory_table_start = sblk->directory_table_start_2;
2977 + sblk->fragment_table_start = sblk->fragment_table_start_2;
2982 +++ b/fs/squashfs/squashfs.h
2985 + * Squashfs - a compressed read only filesystem for Linux
2987 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2988 + * Phillip Lougher <phillip@lougher.org.uk>
2990 + * This program is free software; you can redistribute it and/or
2991 + * modify it under the terms of the GNU General Public License
2992 + * as published by the Free Software Foundation; either version 2,
2993 + * or (at your option) any later version.
2995 + * This program is distributed in the hope that it will be useful,
2996 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2997 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2998 + * GNU General Public License for more details.
3000 + * You should have received a copy of the GNU General Public License
3001 + * along with this program; if not, write to the Free Software
3002 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3007 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3008 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3011 +#ifdef SQUASHFS_TRACE
3012 +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3014 +#define TRACE(s, args...) {}
3017 +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
3019 +#define SERROR(s, args...) do { \
3021 + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3024 +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
3026 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3028 + return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3031 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3032 +#define SQSH_EXTERN
3033 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3034 + long long index, unsigned int length,
3035 + long long *next_index);
3036 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3037 + long long block, unsigned int offset,
3038 + int length, long long *next_block,
3039 + unsigned int *next_offset);
3040 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3041 + squashfs_fragment_cache *fragment);
3042 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3043 + *s, long long start_block,
3045 +extern struct address_space_operations squashfs_symlink_aops;
3046 +extern struct address_space_operations squashfs_aops;
3047 +extern struct address_space_operations squashfs_aops_4K;
3048 +extern struct inode_operations squashfs_dir_inode_ops;
3050 +#define SQSH_EXTERN static
3053 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3054 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3056 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3062 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3063 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3065 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3070 --- a/include/linux/magic.h
3071 +++ b/include/linux/magic.h
3073 #define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs"
3074 #define REISER2FS_JR_SUPER_MAGIC_STRING "ReIsEr3Fs"
3076 +#define SQUASHFS_MAGIC 0x73717368
3077 +#define SQUASHFS_MAGIC_SWAP 0x68737173
3079 #define SMB_SUPER_MAGIC 0x517B
3080 #define USBDEVICE_SUPER_MAGIC 0x9fa2
3083 +++ b/include/linux/squashfs_fs.h
3085 +#ifndef SQUASHFS_FS
3086 +#define SQUASHFS_FS
3091 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3092 + * Phillip Lougher <phillip@lougher.org.uk>
3094 + * This program is free software; you can redistribute it and/or
3095 + * modify it under the terms of the GNU General Public License
3096 + * as published by the Free Software Foundation; either version 2,
3097 + * or (at your option) any later version.
3099 + * This program is distributed in the hope that it will be useful,
3100 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3101 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3102 + * GNU General Public License for more details.
3104 + * You should have received a copy of the GNU General Public License
3105 + * along with this program; if not, write to the Free Software
3106 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3111 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3112 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3115 +#ifdef CONFIG_SQUASHFS_VMALLOC
3116 +#define SQUASHFS_ALLOC(a) vmalloc(a)
3117 +#define SQUASHFS_FREE(a) vfree(a)
3119 +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
3120 +#define SQUASHFS_FREE(a) kfree(a)
3122 +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
3123 +#define SQUASHFS_MAJOR 3
3124 +#define SQUASHFS_MINOR 0
3125 +#define SQUASHFS_START 0
3127 +/* size of metadata (inode and directory) blocks */
3128 +#define SQUASHFS_METADATA_SIZE 8192
3129 +#define SQUASHFS_METADATA_LOG 13
3131 +/* default size of data blocks */
3132 +#define SQUASHFS_FILE_SIZE 65536
3133 +#define SQUASHFS_FILE_LOG 16
3135 +#define SQUASHFS_FILE_MAX_SIZE 65536
3137 +/* Max number of uids and gids */
3138 +#define SQUASHFS_UIDS 256
3139 +#define SQUASHFS_GUIDS 255
3141 +/* Max length of filename (not 255) */
3142 +#define SQUASHFS_NAME_LEN 256
3144 +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
3145 +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
3146 +#define SQUASHFS_INVALID_BLK ((long long) -1)
3147 +#define SQUASHFS_USED_BLK ((long long) -2)
3149 +/* Filesystem flags */
3150 +#define SQUASHFS_NOI 0
3151 +#define SQUASHFS_NOD 1
3152 +#define SQUASHFS_CHECK 2
3153 +#define SQUASHFS_NOF 3
3154 +#define SQUASHFS_NO_FRAG 4
3155 +#define SQUASHFS_ALWAYS_FRAG 5
3156 +#define SQUASHFS_DUPLICATE 6
3158 +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
3160 +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
3163 +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
3166 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3169 +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3172 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3173 + SQUASHFS_ALWAYS_FRAG)
3175 +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
3176 + SQUASHFS_DUPLICATE)
3178 +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
3181 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3182 + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
3183 + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3184 + (duplicate_checking << 6))
3186 +/* Max number of types and file types */
3187 +#define SQUASHFS_DIR_TYPE 1
3188 +#define SQUASHFS_FILE_TYPE 2
3189 +#define SQUASHFS_SYMLINK_TYPE 3
3190 +#define SQUASHFS_BLKDEV_TYPE 4
3191 +#define SQUASHFS_CHRDEV_TYPE 5
3192 +#define SQUASHFS_FIFO_TYPE 6
3193 +#define SQUASHFS_SOCKET_TYPE 7
3194 +#define SQUASHFS_LDIR_TYPE 8
3195 +#define SQUASHFS_LREG_TYPE 9
3197 +/* 1.0 filesystem type definitions */
3198 +#define SQUASHFS_TYPES 5
3199 +#define SQUASHFS_IPC_TYPE 0
3201 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3203 +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
3205 +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3206 + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
3208 +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
3210 +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
3212 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
3213 + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3214 + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3216 +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3219 + * Inode number ops. Inodes consist of a compressed block number, and an
3220 + * uncompressed offset within that block
3222 +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
3224 +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
3226 +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3229 +/* Compute 32 bit VFS inode number from squashfs inode number */
3230 +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
3234 +/* Translate between VFS mode and squashfs mode */
3235 +#define SQUASHFS_MODE(a) ((a) & 0xfff)
3237 +/* fragment and fragment table defines */
3238 +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
3240 +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
3241 + SQUASHFS_METADATA_SIZE)
3243 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
3244 + SQUASHFS_METADATA_SIZE)
3246 +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
3247 + SQUASHFS_METADATA_SIZE - 1) / \
3248 + SQUASHFS_METADATA_SIZE)
3250 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
3251 + sizeof(long long))
3253 +/* cached data constants for filesystem */
3254 +#define SQUASHFS_CACHED_BLKS 8
3256 +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
3258 +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
3259 + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3261 +#define SQUASHFS_MARKER_BYTE 0xff
3263 +/* meta index cache */
3264 +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3265 +#define SQUASHFS_META_ENTRIES 31
3266 +#define SQUASHFS_META_NUMBER 8
3267 +#define SQUASHFS_SLOTS 4
3269 +#include <linux/magic.h>
3271 +struct meta_entry {
3272 + long long data_block;
3273 + unsigned int index_block;
3274 + unsigned short offset;
3275 + unsigned short pad;
3278 +struct meta_index {
3279 + unsigned int inode_number;
3280 + unsigned int offset;
3281 + unsigned short entries;
3282 + unsigned short skip;
3283 + unsigned short locked;
3284 + unsigned short pad;
3285 + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
3290 + * definitions for structures on disk
3293 +typedef long long squashfs_block_t;
3294 +typedef long long squashfs_inode_t;
3296 +struct squashfs_super_block {
3297 + unsigned int s_magic;
3298 + unsigned int inodes;
3299 + unsigned int bytes_used_2;
3300 + unsigned int uid_start_2;
3301 + unsigned int guid_start_2;
3302 + unsigned int inode_table_start_2;
3303 + unsigned int directory_table_start_2;
3304 + unsigned int s_major:16;
3305 + unsigned int s_minor:16;
3306 + unsigned int block_size_1:16;
3307 + unsigned int block_log:16;
3308 + unsigned int flags:8;
3309 + unsigned int no_uids:8;
3310 + unsigned int no_guids:8;
3311 + unsigned int mkfs_time /* time of filesystem creation */;
3312 + squashfs_inode_t root_inode;
3313 + unsigned int block_size;
3314 + unsigned int fragments;
3315 + unsigned int fragment_table_start_2;
3316 + long long bytes_used;
3317 + long long uid_start;
3318 + long long guid_start;
3319 + long long inode_table_start;
3320 + long long directory_table_start;
3321 + long long fragment_table_start;
3323 +} __attribute__ ((packed));
3325 +struct squashfs_dir_index {
3326 + unsigned int index;
3327 + unsigned int start_block;
3328 + unsigned char size;
3329 + unsigned char name[0];
3330 +} __attribute__ ((packed));
3332 +#define SQUASHFS_BASE_INODE_HEADER \
3333 + unsigned int inode_type:4; \
3334 + unsigned int mode:12; \
3335 + unsigned int uid:8; \
3336 + unsigned int guid:8; \
3337 + unsigned int mtime; \
3338 + unsigned int inode_number;
3340 +struct squashfs_base_inode_header {
3341 + SQUASHFS_BASE_INODE_HEADER;
3342 +} __attribute__ ((packed));
3344 +struct squashfs_ipc_inode_header {
3345 + SQUASHFS_BASE_INODE_HEADER;
3346 + unsigned int nlink;
3347 +} __attribute__ ((packed));
3349 +struct squashfs_dev_inode_header {
3350 + SQUASHFS_BASE_INODE_HEADER;
3351 + unsigned int nlink;
3352 + unsigned short rdev;
3353 +} __attribute__ ((packed));
3355 +struct squashfs_symlink_inode_header {
3356 + SQUASHFS_BASE_INODE_HEADER;
3357 + unsigned int nlink;
3358 + unsigned short symlink_size;
3360 +} __attribute__ ((packed));
3362 +struct squashfs_reg_inode_header {
3363 + SQUASHFS_BASE_INODE_HEADER;
3364 + squashfs_block_t start_block;
3365 + unsigned int fragment;
3366 + unsigned int offset;
3367 + unsigned int file_size;
3368 + unsigned short block_list[0];
3369 +} __attribute__ ((packed));
3371 +struct squashfs_lreg_inode_header {
3372 + SQUASHFS_BASE_INODE_HEADER;
3373 + unsigned int nlink;
3374 + squashfs_block_t start_block;
3375 + unsigned int fragment;
3376 + unsigned int offset;
3377 + long long file_size;
3378 + unsigned short block_list[0];
3379 +} __attribute__ ((packed));
3381 +struct squashfs_dir_inode_header {
3382 + SQUASHFS_BASE_INODE_HEADER;
3383 + unsigned int nlink;
3384 + unsigned int file_size:19;
3385 + unsigned int offset:13;
3386 + unsigned int start_block;
3387 + unsigned int parent_inode;
3388 +} __attribute__ ((packed));
3390 +struct squashfs_ldir_inode_header {
3391 + SQUASHFS_BASE_INODE_HEADER;
3392 + unsigned int nlink;
3393 + unsigned int file_size:27;
3394 + unsigned int offset:13;
3395 + unsigned int start_block;
3396 + unsigned int i_count:16;
3397 + unsigned int parent_inode;
3398 + struct squashfs_dir_index index[0];
3399 +} __attribute__ ((packed));
3401 +union squashfs_inode_header {
3402 + struct squashfs_base_inode_header base;
3403 + struct squashfs_dev_inode_header dev;
3404 + struct squashfs_symlink_inode_header symlink;
3405 + struct squashfs_reg_inode_header reg;
3406 + struct squashfs_lreg_inode_header lreg;
3407 + struct squashfs_dir_inode_header dir;
3408 + struct squashfs_ldir_inode_header ldir;
3409 + struct squashfs_ipc_inode_header ipc;
3412 +struct squashfs_dir_entry {
3413 + unsigned int offset:13;
3414 + unsigned int type:3;
3415 + unsigned int size:8;
3416 + int inode_number:16;
3418 +} __attribute__ ((packed));
3420 +struct squashfs_dir_header {
3421 + unsigned int count:8;
3422 + unsigned int start_block;
3423 + unsigned int inode_number;
3424 +} __attribute__ ((packed));
3426 +struct squashfs_fragment_entry {
3427 + long long start_block;
3428 + unsigned int size;
3429 + unsigned int unused;
3430 +} __attribute__ ((packed));
3432 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3433 +extern int squashfs_uncompress_init(void);
3434 +extern int squashfs_uncompress_exit(void);
3437 + * macros to convert each packed bitfield structure from little endian to big
3438 + * endian and vice versa. These are needed when creating or using a filesystem
3439 + * on a machine with different byte ordering to the target architecture.
3443 +#define SQUASHFS_SWAP_START \
3446 + unsigned long long val;\
3447 + unsigned char *s;\
3450 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3451 + SQUASHFS_SWAP_START\
3452 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3453 + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3454 + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3455 + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3456 + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3457 + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3458 + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3459 + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3460 + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3461 + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3462 + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3463 + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3464 + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3465 + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3466 + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3467 + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3468 + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3469 + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3470 + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3471 + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3472 + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3473 + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3474 + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3475 + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3476 + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3477 + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3478 + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3481 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3482 + SQUASHFS_MEMSET(s, d, n);\
3483 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3484 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3485 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3486 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3487 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3488 + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3490 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3491 + SQUASHFS_SWAP_START\
3492 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3495 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3496 + SQUASHFS_SWAP_START\
3497 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3498 + sizeof(struct squashfs_ipc_inode_header))\
3499 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3502 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3503 + SQUASHFS_SWAP_START\
3504 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3505 + sizeof(struct squashfs_dev_inode_header)); \
3506 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3507 + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3510 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3511 + SQUASHFS_SWAP_START\
3512 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3513 + sizeof(struct squashfs_symlink_inode_header));\
3514 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3515 + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3518 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3519 + SQUASHFS_SWAP_START\
3520 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3521 + sizeof(struct squashfs_reg_inode_header));\
3522 + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3523 + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3524 + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3525 + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3528 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3529 + SQUASHFS_SWAP_START\
3530 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3531 + sizeof(struct squashfs_lreg_inode_header));\
3532 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3533 + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3534 + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3535 + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3536 + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3539 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3540 + SQUASHFS_SWAP_START\
3541 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3542 + sizeof(struct squashfs_dir_inode_header));\
3543 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3544 + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3545 + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3546 + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3547 + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3550 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3551 + SQUASHFS_SWAP_START\
3552 + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3553 + sizeof(struct squashfs_ldir_inode_header));\
3554 + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3555 + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3556 + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3557 + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3558 + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3559 + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3562 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3563 + SQUASHFS_SWAP_START\
3564 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3565 + SQUASHFS_SWAP((s)->index, d, 0, 32);\
3566 + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3567 + SQUASHFS_SWAP((s)->size, d, 64, 8);\
3570 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3571 + SQUASHFS_SWAP_START\
3572 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3573 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3574 + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3575 + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3578 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3579 + SQUASHFS_SWAP_START\
3580 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3581 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3582 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3583 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3584 + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3587 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3588 + SQUASHFS_SWAP_START\
3589 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3590 + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3591 + SQUASHFS_SWAP((s)->size, d, 64, 32);\
3594 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3596 + int bit_position;\
3597 + SQUASHFS_SWAP_START\
3598 + SQUASHFS_MEMSET(s, d, n * 2);\
3599 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3601 + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3604 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3606 + int bit_position;\
3607 + SQUASHFS_SWAP_START\
3608 + SQUASHFS_MEMSET(s, d, n * 4);\
3609 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3611 + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3614 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3616 + int bit_position;\
3617 + SQUASHFS_SWAP_START\
3618 + SQUASHFS_MEMSET(s, d, n * 8);\
3619 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3621 + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3624 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3626 + int bit_position;\
3627 + SQUASHFS_SWAP_START\
3628 + SQUASHFS_MEMSET(s, d, n * bits / 8);\
3629 + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3631 + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3634 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3636 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3638 +struct squashfs_base_inode_header_1 {
3639 + unsigned int inode_type:4;
3640 + unsigned int mode:12; /* protection */
3641 + unsigned int uid:4; /* index into uid table */
3642 + unsigned int guid:4; /* index into guid table */
3643 +} __attribute__ ((packed));
3645 +struct squashfs_ipc_inode_header_1 {
3646 + unsigned int inode_type:4;
3647 + unsigned int mode:12; /* protection */
3648 + unsigned int uid:4; /* index into uid table */
3649 + unsigned int guid:4; /* index into guid table */
3650 + unsigned int type:4;
3651 + unsigned int offset:4;
3652 +} __attribute__ ((packed));
3654 +struct squashfs_dev_inode_header_1 {
3655 + unsigned int inode_type:4;
3656 + unsigned int mode:12; /* protection */
3657 + unsigned int uid:4; /* index into uid table */
3658 + unsigned int guid:4; /* index into guid table */
3659 + unsigned short rdev;
3660 +} __attribute__ ((packed));
3662 +struct squashfs_symlink_inode_header_1 {
3663 + unsigned int inode_type:4;
3664 + unsigned int mode:12; /* protection */
3665 + unsigned int uid:4; /* index into uid table */
3666 + unsigned int guid:4; /* index into guid table */
3667 + unsigned short symlink_size;
3669 +} __attribute__ ((packed));
3671 +struct squashfs_reg_inode_header_1 {
3672 + unsigned int inode_type:4;
3673 + unsigned int mode:12; /* protection */
3674 + unsigned int uid:4; /* index into uid table */
3675 + unsigned int guid:4; /* index into guid table */
3676 + unsigned int mtime;
3677 + unsigned int start_block;
3678 + unsigned int file_size:32;
3679 + unsigned short block_list[0];
3680 +} __attribute__ ((packed));
3682 +struct squashfs_dir_inode_header_1 {
3683 + unsigned int inode_type:4;
3684 + unsigned int mode:12; /* protection */
3685 + unsigned int uid:4; /* index into uid table */
3686 + unsigned int guid:4; /* index into guid table */
3687 + unsigned int file_size:19;
3688 + unsigned int offset:13;
3689 + unsigned int mtime;
3690 + unsigned int start_block:24;
3691 +} __attribute__ ((packed));
3693 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3694 + SQUASHFS_MEMSET(s, d, n);\
3695 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3696 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3697 + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3698 + SQUASHFS_SWAP((s)->guid, d, 20, 4);
3700 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3701 + SQUASHFS_SWAP_START\
3702 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3705 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3706 + SQUASHFS_SWAP_START\
3707 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3708 + sizeof(struct squashfs_ipc_inode_header_1));\
3709 + SQUASHFS_SWAP((s)->type, d, 24, 4);\
3710 + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3713 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3714 + SQUASHFS_SWAP_START\
3715 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3716 + sizeof(struct squashfs_dev_inode_header_1));\
3717 + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3720 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3721 + SQUASHFS_SWAP_START\
3722 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3723 + sizeof(struct squashfs_symlink_inode_header_1));\
3724 + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3727 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3728 + SQUASHFS_SWAP_START\
3729 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3730 + sizeof(struct squashfs_reg_inode_header_1));\
3731 + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3732 + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3733 + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3736 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3737 + SQUASHFS_SWAP_START\
3738 + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3739 + sizeof(struct squashfs_dir_inode_header_1));\
3740 + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3741 + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3742 + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3743 + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3748 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3750 +struct squashfs_dir_index_2 {
3751 + unsigned int index:27;
3752 + unsigned int start_block:29;
3753 + unsigned char size;
3754 + unsigned char name[0];
3755 +} __attribute__ ((packed));
3757 +struct squashfs_base_inode_header_2 {
3758 + unsigned int inode_type:4;
3759 + unsigned int mode:12; /* protection */
3760 + unsigned int uid:8; /* index into uid table */
3761 + unsigned int guid:8; /* index into guid table */
3762 +} __attribute__ ((packed));
3764 +struct squashfs_ipc_inode_header_2 {
3765 + unsigned int inode_type:4;
3766 + unsigned int mode:12; /* protection */
3767 + unsigned int uid:8; /* index into uid table */
3768 + unsigned int guid:8; /* index into guid table */
3769 +} __attribute__ ((packed));
3771 +struct squashfs_dev_inode_header_2 {
3772 + unsigned int inode_type:4;
3773 + unsigned int mode:12; /* protection */
3774 + unsigned int uid:8; /* index into uid table */
3775 + unsigned int guid:8; /* index into guid table */
3776 + unsigned short rdev;
3777 +} __attribute__ ((packed));
3779 +struct squashfs_symlink_inode_header_2 {
3780 + unsigned int inode_type:4;
3781 + unsigned int mode:12; /* protection */
3782 + unsigned int uid:8; /* index into uid table */
3783 + unsigned int guid:8; /* index into guid table */
3784 + unsigned short symlink_size;
3786 +} __attribute__ ((packed));
3788 +struct squashfs_reg_inode_header_2 {
3789 + unsigned int inode_type:4;
3790 + unsigned int mode:12; /* protection */
3791 + unsigned int uid:8; /* index into uid table */
3792 + unsigned int guid:8; /* index into guid table */
3793 + unsigned int mtime;
3794 + unsigned int start_block;
3795 + unsigned int fragment;
3796 + unsigned int offset;
3797 + unsigned int file_size:32;
3798 + unsigned short block_list[0];
3799 +} __attribute__ ((packed));
3801 +struct squashfs_dir_inode_header_2 {
3802 + unsigned int inode_type:4;
3803 + unsigned int mode:12; /* protection */
3804 + unsigned int uid:8; /* index into uid table */
3805 + unsigned int guid:8; /* index into guid table */
3806 + unsigned int file_size:19;
3807 + unsigned int offset:13;
3808 + unsigned int mtime;
3809 + unsigned int start_block:24;
3810 +} __attribute__ ((packed));
3812 +struct squashfs_ldir_inode_header_2 {
3813 + unsigned int inode_type:4;
3814 + unsigned int mode:12; /* protection */
3815 + unsigned int uid:8; /* index into uid table */
3816 + unsigned int guid:8; /* index into guid table */
3817 + unsigned int file_size:27;
3818 + unsigned int offset:13;
3819 + unsigned int mtime;
3820 + unsigned int start_block:24;
3821 + unsigned int i_count:16;
3822 + struct squashfs_dir_index_2 index[0];
3823 +} __attribute__ ((packed));
3825 +union squashfs_inode_header_2 {
3826 + struct squashfs_base_inode_header_2 base;
3827 + struct squashfs_dev_inode_header_2 dev;
3828 + struct squashfs_symlink_inode_header_2 symlink;
3829 + struct squashfs_reg_inode_header_2 reg;
3830 + struct squashfs_dir_inode_header_2 dir;
3831 + struct squashfs_ldir_inode_header_2 ldir;
3832 + struct squashfs_ipc_inode_header_2 ipc;
3835 +struct squashfs_dir_header_2 {
3836 + unsigned int count:8;
3837 + unsigned int start_block:24;
3838 +} __attribute__ ((packed));
3840 +struct squashfs_dir_entry_2 {
3841 + unsigned int offset:13;
3842 + unsigned int type:3;
3843 + unsigned int size:8;
3845 +} __attribute__ ((packed));
3847 +struct squashfs_fragment_entry_2 {
3848 + unsigned int start_block;
3849 + unsigned int size;
3850 +} __attribute__ ((packed));
3852 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3853 + SQUASHFS_MEMSET(s, d, n);\
3854 + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3855 + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3856 + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3857 + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3859 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3860 + SQUASHFS_SWAP_START\
3861 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3864 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3865 + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3867 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3868 + SQUASHFS_SWAP_START\
3869 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3870 + sizeof(struct squashfs_dev_inode_header_2)); \
3871 + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3874 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3875 + SQUASHFS_SWAP_START\
3876 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3877 + sizeof(struct squashfs_symlink_inode_header_2));\
3878 + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3881 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3882 + SQUASHFS_SWAP_START\
3883 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3884 + sizeof(struct squashfs_reg_inode_header_2));\
3885 + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3886 + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3887 + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3888 + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3889 + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3892 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3893 + SQUASHFS_SWAP_START\
3894 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3895 + sizeof(struct squashfs_dir_inode_header_2));\
3896 + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3897 + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3898 + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3899 + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3902 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3903 + SQUASHFS_SWAP_START\
3904 + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3905 + sizeof(struct squashfs_ldir_inode_header_2));\
3906 + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3907 + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3908 + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3909 + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3910 + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3913 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3914 + SQUASHFS_SWAP_START\
3915 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3916 + SQUASHFS_SWAP((s)->index, d, 0, 27);\
3917 + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3918 + SQUASHFS_SWAP((s)->size, d, 56, 8);\
3920 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3921 + SQUASHFS_SWAP_START\
3922 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3923 + SQUASHFS_SWAP((s)->count, d, 0, 8);\
3924 + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3927 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3928 + SQUASHFS_SWAP_START\
3929 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3930 + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3931 + SQUASHFS_SWAP((s)->type, d, 13, 3);\
3932 + SQUASHFS_SWAP((s)->size, d, 16, 8);\
3935 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3936 + SQUASHFS_SWAP_START\
3937 + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3938 + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3939 + SQUASHFS_SWAP((s)->size, d, 32, 32);\
3942 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3944 +/* fragment and fragment table defines */
3945 +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
3947 +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3948 + SQUASHFS_METADATA_SIZE)
3950 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3951 + SQUASHFS_METADATA_SIZE)
3953 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3954 + SQUASHFS_METADATA_SIZE - 1) / \
3955 + SQUASHFS_METADATA_SIZE)
3957 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3965 + * macros used to swap each structure entry, taking into account
3966 + * bitfields and different bitfield placing conventions on differing
3970 +#include <asm/byteorder.h>
3972 +#ifdef __BIG_ENDIAN
3973 + /* convert from little endian to big endian */
3974 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3977 + /* convert from big endian to little endian */
3978 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3979 + tbits, 64 - tbits - b_pos)
3982 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
3985 + s = (unsigned char *)p + (pos / 8);\
3986 + d = ((unsigned char *) &val) + 7;\
3987 + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
3989 + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
3992 +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
3997 +++ b/include/linux/squashfs_fs_i.h
3999 +#ifndef SQUASHFS_FS_I
4000 +#define SQUASHFS_FS_I
4004 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4005 + * Phillip Lougher <phillip@lougher.org.uk>
4007 + * This program is free software; you can redistribute it and/or
4008 + * modify it under the terms of the GNU General Public License
4009 + * as published by the Free Software Foundation; either version 2,
4010 + * or (at your option) any later version.
4012 + * This program is distributed in the hope that it will be useful,
4013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4015 + * GNU General Public License for more details.
4017 + * You should have received a copy of the GNU General Public License
4018 + * along with this program; if not, write to the Free Software
4019 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4024 +struct squashfs_inode_info {
4025 + long long start_block;
4026 + unsigned int offset;
4029 + long long fragment_start_block;
4030 + unsigned int fragment_size;
4031 + unsigned int fragment_offset;
4032 + long long block_list_start;
4035 + long long directory_index_start;
4036 + unsigned int directory_index_offset;
4037 + unsigned int directory_index_count;
4038 + unsigned int parent_inode;
4041 + struct inode vfs_inode;
4045 +++ b/include/linux/squashfs_fs_sb.h
4047 +#ifndef SQUASHFS_FS_SB
4048 +#define SQUASHFS_FS_SB
4052 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4053 + * Phillip Lougher <phillip@lougher.org.uk>
4055 + * This program is free software; you can redistribute it and/or
4056 + * modify it under the terms of the GNU General Public License
4057 + * as published by the Free Software Foundation; either version 2,
4058 + * or (at your option) any later version.
4060 + * This program is distributed in the hope that it will be useful,
4061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4063 + * GNU General Public License for more details.
4065 + * You should have received a copy of the GNU General Public License
4066 + * along with this program; if not, write to the Free Software
4067 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4069 + * squashfs_fs_sb.h
4072 +#include <linux/squashfs_fs.h>
4074 +struct squashfs_cache {
4077 + long long next_index;
4081 +struct squashfs_fragment_cache {
4084 + unsigned int locked;
4088 +struct squashfs_sb_info {
4089 + struct squashfs_super_block sblk;
4091 + int devblksize_log2;
4093 + struct squashfs_cache *block_cache;
4094 + struct squashfs_fragment_cache *fragment;
4096 + int next_fragment;
4097 + int next_meta_index;
4098 + unsigned int *uid;
4099 + unsigned int *guid;
4100 + long long *fragment_index;
4101 + unsigned int *fragment_index_2;
4102 + unsigned int read_size;
4105 + struct semaphore read_data_mutex;
4106 + struct semaphore read_page_mutex;
4107 + struct semaphore block_cache_mutex;
4108 + struct semaphore fragment_mutex;
4109 + struct semaphore meta_index_mutex;
4110 + wait_queue_head_t waitq;
4111 + wait_queue_head_t fragment_wait_queue;
4112 + struct meta_index *meta_index;
4113 + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
4115 + long long (*read_blocklist)(struct inode *inode, int \
4116 + index, int readahead_blks, char *block_list, \
4117 + unsigned short **block_p, unsigned int *bsize);
4118 + int (*read_fragment_index_table)(struct super_block *s);
4121 --- a/init/do_mounts_rd.c
4122 +++ b/init/do_mounts_rd.c
4124 #include <linux/ext2_fs.h>
4125 #include <linux/romfs_fs.h>
4126 #include <linux/cramfs_fs.h>
4127 +#include <linux/squashfs_fs.h>
4128 #include <linux/initrd.h>
4129 #include <linux/string.h>
4132 * numbers could not be found.
4134 * We currently check for the following magic numbers:
4140 struct ext2_super_block *ext2sb;
4141 struct romfs_super_block *romfsb;
4142 struct cramfs_super *cramfsb;
4143 + struct squashfs_super_block *squashfsb;
4148 ext2sb = (struct ext2_super_block *) buf;
4149 romfsb = (struct romfs_super_block *) buf;
4150 cramfsb = (struct cramfs_super *) buf;
4151 + squashfsb = (struct squashfs_super_block *) buf;
4152 memset(buf, 0xe5, size);
4155 @@ -101,6 +105,15 @@
4159 + /* squashfs is at block zero too */
4160 + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4161 + printk(KERN_NOTICE
4162 + "RAMDISK: squashfs filesystem found at block %d\n",
4164 + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4169 * Read block 1 to test for minix and ext2 superblock