conf/distro/jlime-donkey.conf : Added parted & Dialog to distro_rdepends
[vuplus_openembedded] / packages / linux / linux-openzaurus-2.6.18 / squashfs3.0-2.6.15.patch
1  fs/Kconfig                     |   65 +
2  fs/Makefile                    |    1 
3  fs/squashfs/Makefile           |    7 
4  fs/squashfs/inode.c            | 2127 +++++++++++++++++++++++++++++++++++++++++
5  fs/squashfs/squashfs.h         |   86 +
6  fs/squashfs/squashfs2_0.c      |  758 ++++++++++++++
7  include/linux/squashfs_fs.h    |  911 +++++++++++++++++
8  include/linux/squashfs_fs_i.h  |   45 
9  include/linux/squashfs_fs_sb.h |   74 +
10  init/do_mounts_rd.c            |   13 
11  10 files changed, 4087 insertions(+)
12
13 Index: linux-2.6.18/fs/Kconfig
14 ===================================================================
15 --- linux-2.6.18.orig/fs/Kconfig        2006-09-20 04:42:06.000000000 +0100
16 +++ linux-2.6.18/fs/Kconfig     2006-09-20 15:45:15.000000000 +0100
17 @@ -1249,6 +1249,71 @@ config CRAMFS
18  
19           If unsure, say N.
20  
21 +config SQUASHFS
22 +       tristate "SquashFS 3.0 - Squashed file system support"
23 +       select ZLIB_INFLATE
24 +       help
25 +         Saying Y here includes support for SquashFS 3.0 (a Compressed Read-Only File
26 +         System).  Squashfs is a highly compressed read-only filesystem for Linux.
27 +         It uses zlib compression to compress both files, inodes and directories.
28 +         Inodes in the system are very small and all blocks are packed to minimise
29 +         data overhead. Block sizes greater than 4K are supported up to a maximum of 64K.
30 +         SquashFS 3.0 supports 64 bit filesystems and files (larger than 4GB), full
31 +         uid/gid information, hard links and timestamps.
32 +
33 +         Squashfs is intended for general read-only filesystem use, for archival
34 +         use (i.e. in cases where a .tar.gz file may be used), and in embedded
35 +         systems where low overhead is needed.  Further information and filesystem tools
36 +         are available from http://squashfs.sourceforge.net.
37 +
38 +         If you want to compile this as a module ( = code which can be
39 +         inserted in and removed from the running kernel whenever you want),
40 +         say M here and read <file:Documentation/modules.txt>.  The module
41 +         will be called squashfs.  Note that the root file system (the one
42 +         containing the directory /) cannot be compiled as a module.
43 +
44 +         If unsure, say N.
45 +
46 +config SQUASHFS_EMBEDDED
47 +
48 +       bool "Additional options for memory-constrained systems" 
49 +       depends on SQUASHFS
50 +       default n
51 +       help
52 +         Saying Y here allows you to specify cache sizes and how Squashfs
53 +         allocates memory.  This is only intended for memory constrained
54 +         systems.
55 +
56 +         If unsure, say N.
57 +
58 +config SQUASHFS_FRAGMENT_CACHE_SIZE
59 +       int "Number of fragments cached" if SQUASHFS_EMBEDDED
60 +       depends on SQUASHFS
61 +       default "3"
62 +       help
63 +         By default SquashFS caches the last 3 fragments read from
64 +         the filesystem.  Increasing this amount may mean SquashFS
65 +         has to re-read fragments less often from disk, at the expense
66 +         of extra system memory.  Decreasing this amount will mean
67 +         SquashFS uses less memory at the expense of extra reads from disk.
68 +
69 +         Note there must be at least one cached fragment.  Anything
70 +         much more than three will probably not make much difference.
71 +
72 +config SQUASHFS_VMALLOC
73 +       bool "Use Vmalloc rather than Kmalloc" if SQUASHFS_EMBEDDED
74 +       depends on SQUASHFS
75 +       default n
76 +       help
77 +         By default SquashFS uses kmalloc to obtain fragment cache memory.
78 +         Kmalloc memory is the standard kernel allocator, but it can fail
79 +         on memory constrained systems.  Because of the way Vmalloc works,
80 +         Vmalloc can succeed when kmalloc fails.  Specifying this option
81 +         will make SquashFS always use Vmalloc to allocate the
82 +         fragment cache memory.
83 +
84 +         If unsure, say N.
85 +
86  config VXFS_FS
87         tristate "FreeVxFS file system support (VERITAS VxFS(TM) compatible)"
88         help
89 Index: linux-2.6.18/fs/Makefile
90 ===================================================================
91 --- linux-2.6.18.orig/fs/Makefile       2006-09-20 04:42:06.000000000 +0100
92 +++ linux-2.6.18/fs/Makefile    2006-09-20 15:45:15.000000000 +0100
93 @@ -57,6 +57,7 @@ obj-$(CONFIG_EXT3_FS)         += ext3/ # Before
94  obj-$(CONFIG_JBD)              += jbd/
95  obj-$(CONFIG_EXT2_FS)          += ext2/
96  obj-$(CONFIG_CRAMFS)           += cramfs/
97 +obj-$(CONFIG_SQUASHFS)         += squashfs/
98  obj-$(CONFIG_RAMFS)            += ramfs/
99  obj-$(CONFIG_HUGETLBFS)                += hugetlbfs/
100  obj-$(CONFIG_CODA_FS)          += coda/
101 Index: linux-2.6.18/fs/squashfs/inode.c
102 ===================================================================
103 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
104 +++ linux-2.6.18/fs/squashfs/inode.c    2006-09-20 16:15:58.000000000 +0100
105 @@ -0,0 +1,2127 @@
106 +/*
107 + * Squashfs - a compressed read only filesystem for Linux
108 + *
109 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
110 + * Phillip Lougher <phillip@lougher.org.uk>
111 + *
112 + * This program is free software; you can redistribute it and/or
113 + * modify it under the terms of the GNU General Public License
114 + * as published by the Free Software Foundation; either version 2,
115 + * or (at your option) any later version.
116 + *
117 + * This program is distributed in the hope that it will be useful,
118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
120 + * GNU General Public License for more details.
121 + *
122 + * You should have received a copy of the GNU General Public License
123 + * along with this program; if not, write to the Free Software
124 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
125 + *
126 + * inode.c
127 + */
128 +
129 +#include <linux/types.h>
130 +#include <linux/squashfs_fs.h>
131 +#include <linux/module.h>
132 +#include <linux/errno.h>
133 +#include <linux/slab.h>
134 +#include <linux/fs.h>
135 +#include <linux/smp_lock.h>
136 +#include <linux/slab.h>
137 +#include <linux/squashfs_fs_sb.h>
138 +#include <linux/squashfs_fs_i.h>
139 +#include <linux/buffer_head.h>
140 +#include <linux/vfs.h>
141 +#include <linux/init.h>
142 +#include <linux/dcache.h>
143 +#include <linux/wait.h>
144 +#include <linux/zlib.h>
145 +#include <linux/blkdev.h>
146 +#include <linux/vmalloc.h>
147 +#include <asm/uaccess.h>
148 +#include <asm/semaphore.h>
149 +
150 +#include "squashfs.h"
151 +
152 +static void squashfs_put_super(struct super_block *);
153 +static int squashfs_statfs(struct super_block *, struct kstatfs *);
154 +static int squashfs_symlink_readpage(struct file *file, struct page *page);
155 +static int squashfs_readpage(struct file *file, struct page *page);
156 +static int squashfs_readpage4K(struct file *file, struct page *page);
157 +static int squashfs_readdir(struct file *, void *, filldir_t);
158 +static struct inode *squashfs_alloc_inode(struct super_block *sb);
159 +static void squashfs_destroy_inode(struct inode *inode);
160 +static int init_inodecache(void);
161 +static void destroy_inodecache(void);
162 +static struct dentry *squashfs_lookup(struct inode *, struct dentry *,
163 +                               struct nameidata *);
164 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
165 +static long long read_blocklist(struct inode *inode, int index,
166 +                               int readahead_blks, char *block_list,
167 +                               unsigned short **block_p, unsigned int *bsize);
168 +static struct super_block *squashfs_get_sb(struct file_system_type *, int,
169 +                               const char *, void *, struct vfsmount *);
170 +
171 +
172 +static z_stream stream;
173 +
174 +static struct file_system_type squashfs_fs_type = {
175 +       .owner = THIS_MODULE,
176 +       .name = "squashfs",
177 +       .get_sb = squashfs_get_sb,
178 +       .kill_sb = kill_block_super,
179 +       .fs_flags = FS_REQUIRES_DEV
180 +};
181 +
182 +static unsigned char squashfs_filetype_table[] = {
183 +       DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
184 +};
185 +
186 +static struct super_operations squashfs_ops = {
187 +       .alloc_inode = squashfs_alloc_inode,
188 +       .destroy_inode = squashfs_destroy_inode,
189 +       .statfs = squashfs_statfs,
190 +       .put_super = squashfs_put_super,
191 +};
192 +
193 +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
194 +       .readpage = squashfs_symlink_readpage
195 +};
196 +
197 +SQSH_EXTERN struct address_space_operations squashfs_aops = {
198 +       .readpage = squashfs_readpage
199 +};
200 +
201 +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
202 +       .readpage = squashfs_readpage4K
203 +};
204 +
205 +static struct file_operations squashfs_dir_ops = {
206 +       .read = generic_read_dir,
207 +       .readdir = squashfs_readdir
208 +};
209 +
210 +SQSH_EXTERN struct inode_operations squashfs_dir_inode_ops = {
211 +       .lookup = squashfs_lookup
212 +};
213 +
214 +
215 +static struct buffer_head *get_block_length(struct super_block *s,
216 +                               int *cur_index, int *offset, int *c_byte)
217 +{
218 +       struct squashfs_sb_info *msblk = s->s_fs_info;
219 +       unsigned short temp;
220 +       struct buffer_head *bh;
221 +
222 +       if (!(bh = sb_bread(s, *cur_index)))
223 +               goto out;
224 +
225 +       if (msblk->devblksize - *offset == 1) {
226 +               if (msblk->swap)
227 +                       ((unsigned char *) &temp)[1] = *((unsigned char *)
228 +                               (bh->b_data + *offset));
229 +               else
230 +                       ((unsigned char *) &temp)[0] = *((unsigned char *)
231 +                               (bh->b_data + *offset));
232 +               brelse(bh);
233 +               if (!(bh = sb_bread(s, ++(*cur_index))))
234 +                       goto out;
235 +               if (msblk->swap)
236 +                       ((unsigned char *) &temp)[0] = *((unsigned char *)
237 +                               bh->b_data); 
238 +               else
239 +                       ((unsigned char *) &temp)[1] = *((unsigned char *)
240 +                               bh->b_data); 
241 +               *c_byte = temp;
242 +               *offset = 1;
243 +       } else {
244 +               if (msblk->swap) {
245 +                       ((unsigned char *) &temp)[1] = *((unsigned char *)
246 +                               (bh->b_data + *offset));
247 +                       ((unsigned char *) &temp)[0] = *((unsigned char *)
248 +                               (bh->b_data + *offset + 1)); 
249 +               } else {
250 +                       ((unsigned char *) &temp)[0] = *((unsigned char *)
251 +                               (bh->b_data + *offset));
252 +                       ((unsigned char *) &temp)[1] = *((unsigned char *)
253 +                               (bh->b_data + *offset + 1)); 
254 +               }
255 +               *c_byte = temp;
256 +               *offset += 2;
257 +       }
258 +
259 +       if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
260 +               if (*offset == msblk->devblksize) {
261 +                       brelse(bh);
262 +                       if (!(bh = sb_bread(s, ++(*cur_index))))
263 +                               goto out;
264 +                       *offset = 0;
265 +               }
266 +               if (*((unsigned char *) (bh->b_data + *offset)) !=
267 +                                               SQUASHFS_MARKER_BYTE) {
268 +                       ERROR("Metadata block marker corrupt @ %x\n",
269 +                                               *cur_index);
270 +                       brelse(bh);
271 +                       goto out;
272 +               }
273 +               (*offset)++;
274 +       }
275 +       return bh;
276 +
277 +out:
278 +       return NULL;
279 +}
280 +
281 +
282 +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
283 +                       long long index, unsigned int length,
284 +                       long long *next_index)
285 +{
286 +       struct squashfs_sb_info *msblk = s->s_fs_info;
287 +       struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
288 +                       msblk->devblksize_log2) + 2];
289 +       unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
290 +       unsigned int cur_index = index >> msblk->devblksize_log2;
291 +       int bytes, avail_bytes, b = 0, k;
292 +       char *c_buffer;
293 +       unsigned int compressed;
294 +       unsigned int c_byte = length;
295 +
296 +       if (c_byte) {
297 +               bytes = msblk->devblksize - offset;
298 +               compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
299 +               c_buffer = compressed ? msblk->read_data : buffer;
300 +               c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
301 +
302 +               TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
303 +                                       ? "" : "un", (unsigned int) c_byte);
304 +
305 +               if (!(bh[0] = sb_getblk(s, cur_index)))
306 +                       goto block_release;
307 +
308 +               for (b = 1; bytes < c_byte; b++) {
309 +                       if (!(bh[b] = sb_getblk(s, ++cur_index)))
310 +                               goto block_release;
311 +                       bytes += msblk->devblksize;
312 +               }
313 +               ll_rw_block(READ, b, bh);
314 +       } else {
315 +               if (!(bh[0] = get_block_length(s, &cur_index, &offset,
316 +                                                               &c_byte)))
317 +                       goto read_failure;
318 +
319 +               bytes = msblk->devblksize - offset;
320 +               compressed = SQUASHFS_COMPRESSED(c_byte);
321 +               c_buffer = compressed ? msblk->read_data : buffer;
322 +               c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
323 +
324 +               TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
325 +                                       ? "" : "un", (unsigned int) c_byte);
326 +
327 +               for (b = 1; bytes < c_byte; b++) {
328 +                       if (!(bh[b] = sb_getblk(s, ++cur_index)))
329 +                               goto block_release;
330 +                       bytes += msblk->devblksize;
331 +               }
332 +               ll_rw_block(READ, b - 1, bh + 1);
333 +       }
334 +
335 +       if (compressed)
336 +               down(&msblk->read_data_mutex);
337 +
338 +       for (bytes = 0, k = 0; k < b; k++) {
339 +               avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
340 +                                       msblk->devblksize - offset :
341 +                                       c_byte - bytes;
342 +               wait_on_buffer(bh[k]);
343 +               if (!buffer_uptodate(bh[k]))
344 +                       goto block_release;
345 +               memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
346 +               bytes += avail_bytes;
347 +               offset = 0;
348 +               brelse(bh[k]);
349 +       }
350 +
351 +       /*
352 +        * uncompress block
353 +        */
354 +       if (compressed) {
355 +               int zlib_err;
356 +
357 +               stream.next_in = c_buffer;
358 +               stream.avail_in = c_byte;
359 +               stream.next_out = buffer;
360 +               stream.avail_out = msblk->read_size;
361 +
362 +               if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
363 +                               ((zlib_err = zlib_inflate(&stream, Z_FINISH))
364 +                                != Z_STREAM_END) || ((zlib_err =
365 +                               zlib_inflateEnd(&stream)) != Z_OK)) {
366 +                       ERROR("zlib_fs returned unexpected result 0x%x\n",
367 +                               zlib_err);
368 +                       bytes = 0;
369 +               } else
370 +                       bytes = stream.total_out;
371 +               
372 +               up(&msblk->read_data_mutex);
373 +       }
374 +
375 +       if (next_index)
376 +               *next_index = index + c_byte + (length ? 0 :
377 +                               (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
378 +                                ? 3 : 2));
379 +       return bytes;
380 +
381 +block_release:
382 +       while (--b >= 0)
383 +               brelse(bh[b]);
384 +
385 +read_failure:
386 +       ERROR("sb_bread failed reading block 0x%x\n", cur_index);
387 +       return 0;
388 +}
389 +
390 +
391 +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
392 +                               long long block, unsigned int offset,
393 +                               int length, long long *next_block,
394 +                               unsigned int *next_offset)
395 +{
396 +       struct squashfs_sb_info *msblk = s->s_fs_info;
397 +       int n, i, bytes, return_length = length;
398 +       long long next_index;
399 +
400 +       TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
401 +
402 +       while ( 1 ) {
403 +               for (i = 0; i < SQUASHFS_CACHED_BLKS; i++) 
404 +                       if (msblk->block_cache[i].block == block)
405 +                               break; 
406 +               
407 +               down(&msblk->block_cache_mutex);
408 +
409 +               if (i == SQUASHFS_CACHED_BLKS) {
410 +                       /* read inode header block */
411 +                       for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
412 +                                       n ; n --, i = (i + 1) %
413 +                                       SQUASHFS_CACHED_BLKS)
414 +                               if (msblk->block_cache[i].block !=
415 +                                                       SQUASHFS_USED_BLK)
416 +                                       break;
417 +
418 +                       if (n == 0) {
419 +                               wait_queue_t wait;
420 +
421 +                               init_waitqueue_entry(&wait, current);
422 +                               add_wait_queue(&msblk->waitq, &wait);
423 +                               set_current_state(TASK_UNINTERRUPTIBLE);
424 +                               up(&msblk->block_cache_mutex);
425 +                               schedule();
426 +                               set_current_state(TASK_RUNNING);
427 +                               remove_wait_queue(&msblk->waitq, &wait);
428 +                               continue;
429 +                       }
430 +                       msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
431 +
432 +                       if (msblk->block_cache[i].block ==
433 +                                                       SQUASHFS_INVALID_BLK) {
434 +                               if (!(msblk->block_cache[i].data =
435 +                                               kmalloc(SQUASHFS_METADATA_SIZE,
436 +                                               GFP_KERNEL))) {
437 +                                       ERROR("Failed to allocate cache"
438 +                                                       "block\n");
439 +                                       up(&msblk->block_cache_mutex);
440 +                                       goto out;
441 +                               }
442 +                       }
443 +       
444 +                       msblk->block_cache[i].block = SQUASHFS_USED_BLK;
445 +                       up(&msblk->block_cache_mutex);
446 +
447 +                       if (!(msblk->block_cache[i].length =
448 +                                               squashfs_read_data(s,
449 +                                               msblk->block_cache[i].data,
450 +                                               block, 0, &next_index))) {
451 +                               ERROR("Unable to read cache block [%llx:%x]\n",
452 +                                               block, offset);
453 +                               goto out;
454 +                       }
455 +
456 +                       down(&msblk->block_cache_mutex);
457 +                       wake_up(&msblk->waitq);
458 +                       msblk->block_cache[i].block = block;
459 +                       msblk->block_cache[i].next_index = next_index;
460 +                       TRACE("Read cache block [%llx:%x]\n", block, offset);
461 +               }
462 +
463 +               if (msblk->block_cache[i].block != block) {
464 +                       up(&msblk->block_cache_mutex);
465 +                       continue;
466 +               }
467 +
468 +               if ((bytes = msblk->block_cache[i].length - offset) >= length) {
469 +                       if (buffer)
470 +                               memcpy(buffer, msblk->block_cache[i].data +
471 +                                               offset, length);
472 +                       if (msblk->block_cache[i].length - offset == length) {
473 +                               *next_block = msblk->block_cache[i].next_index;
474 +                               *next_offset = 0;
475 +                       } else {
476 +                               *next_block = block;
477 +                               *next_offset = offset + length;
478 +                       }
479 +                       up(&msblk->block_cache_mutex);
480 +                       goto finish;
481 +               } else {
482 +                       if (buffer) {
483 +                               memcpy(buffer, msblk->block_cache[i].data +
484 +                                               offset, bytes);
485 +                               buffer += bytes;
486 +                       }
487 +                       block = msblk->block_cache[i].next_index;
488 +                       up(&msblk->block_cache_mutex);
489 +                       length -= bytes;
490 +                       offset = 0;
491 +               }
492 +       }
493 +
494 +finish:
495 +       return return_length;
496 +out:
497 +       return 0;
498 +}
499 +
500 +
501 +static int get_fragment_location(struct super_block *s, unsigned int fragment,
502 +                               long long *fragment_start_block,
503 +                               unsigned int *fragment_size)
504 +{
505 +       struct squashfs_sb_info *msblk = s->s_fs_info;
506 +       long long start_block =
507 +               msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
508 +       int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
509 +       struct squashfs_fragment_entry fragment_entry;
510 +
511 +       if (msblk->swap) {
512 +               struct squashfs_fragment_entry sfragment_entry;
513 +
514 +               if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
515 +                                       start_block, offset,
516 +                                       sizeof(sfragment_entry), &start_block,
517 +                                       &offset))
518 +                       goto out;
519 +               SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
520 +       } else
521 +               if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
522 +                                       start_block, offset,
523 +                                       sizeof(fragment_entry), &start_block,
524 +                                       &offset))
525 +                       goto out;
526 +
527 +       *fragment_start_block = fragment_entry.start_block;
528 +       *fragment_size = fragment_entry.size;
529 +
530 +       return 1;
531 +
532 +out:
533 +       return 0;
534 +}
535 +
536 +
537 +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
538 +                                       squashfs_fragment_cache *fragment)
539 +{
540 +       down(&msblk->fragment_mutex);
541 +       fragment->locked --;
542 +       wake_up(&msblk->fragment_wait_queue);
543 +       up(&msblk->fragment_mutex);
544 +}
545 +
546 +
547 +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
548 +                                       *s, long long start_block,
549 +                                       int length)
550 +{
551 +       int i, n, nf;
552 +       struct squashfs_sb_info *msblk = s->s_fs_info;
553 +
554 +       while ( 1 ) {
555 +               down(&msblk->fragment_mutex);
556 +
557 +               for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
558 +                               msblk->fragment[i].block != start_block; i++);
559 +
560 +               if (i == SQUASHFS_CACHED_FRAGMENTS) {
561 +                       nf = (msblk->next_fragment + 1) % 
562 +                               SQUASHFS_CACHED_FRAGMENTS;
563 +                       for (i = msblk->next_fragment, n =
564 +                               SQUASHFS_CACHED_FRAGMENTS; n &&
565 +                               msblk->fragment[i].locked; n--, i = (i + 1) %
566 +                               SQUASHFS_CACHED_FRAGMENTS);
567 +
568 +                       if (n == 0) {
569 +                               wait_queue_t wait;
570 +
571 +                               init_waitqueue_entry(&wait, current);
572 +                               add_wait_queue(&msblk->fragment_wait_queue,
573 +                                                                       &wait);
574 +                               set_current_state(TASK_UNINTERRUPTIBLE);
575 +                               up(&msblk->fragment_mutex);
576 +                               schedule();
577 +                               set_current_state(TASK_RUNNING);
578 +                               remove_wait_queue(&msblk->fragment_wait_queue,
579 +                                                                       &wait);
580 +                               continue;
581 +                       }
582 +                       msblk->next_fragment = nf;
583 +                       
584 +                       if (msblk->fragment[i].data == NULL)
585 +                               if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
586 +                                               (SQUASHFS_FILE_MAX_SIZE))) {
587 +                                       ERROR("Failed to allocate fragment "
588 +                                                       "cache block\n");
589 +                                       up(&msblk->fragment_mutex);
590 +                                       goto out;
591 +                               }
592 +
593 +                       msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
594 +                       msblk->fragment[i].locked = 1;
595 +                       up(&msblk->fragment_mutex);
596 +
597 +                       if (!(msblk->fragment[i].length = squashfs_read_data(s,
598 +                                               msblk->fragment[i].data,
599 +                                               start_block, length, NULL))) {
600 +                               ERROR("Unable to read fragment cache block "
601 +                                                       "[%llx]\n", start_block);
602 +                               msblk->fragment[i].locked = 0;
603 +                               goto out;
604 +                       }
605 +
606 +                       msblk->fragment[i].block = start_block;
607 +                       TRACE("New fragment %d, start block %lld, locked %d\n",
608 +                                               i, msblk->fragment[i].block,
609 +                                               msblk->fragment[i].locked);
610 +                       break;
611 +               }
612 +
613 +               msblk->fragment[i].locked++;
614 +               up(&msblk->fragment_mutex);
615 +               TRACE("Got fragment %d, start block %lld, locked %d\n", i,
616 +                                               msblk->fragment[i].block,
617 +                                               msblk->fragment[i].locked);
618 +               break;
619 +       }
620 +
621 +       return &msblk->fragment[i];
622 +
623 +out:
624 +       return NULL;
625 +}
626 +
627 +
628 +static struct inode *squashfs_new_inode(struct super_block *s,
629 +               struct squashfs_base_inode_header *inodeb)
630 +{
631 +       struct squashfs_sb_info *msblk = s->s_fs_info;
632 +       struct inode *i = new_inode(s);
633 +
634 +       if (i) {
635 +               i->i_ino = inodeb->inode_number;
636 +               i->i_mtime.tv_sec = inodeb->mtime;
637 +               i->i_atime.tv_sec = inodeb->mtime;
638 +               i->i_ctime.tv_sec = inodeb->mtime;
639 +               i->i_uid = msblk->uid[inodeb->uid];
640 +               i->i_mode = inodeb->mode;
641 +               i->i_size = 0;
642 +               if (inodeb->guid == SQUASHFS_GUIDS)
643 +                       i->i_gid = i->i_uid;
644 +               else
645 +                       i->i_gid = msblk->guid[inodeb->guid];
646 +       }
647 +
648 +       return i;
649 +}
650 +
651 +
652 +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
653 +{
654 +       struct inode *i;
655 +       struct squashfs_sb_info *msblk = s->s_fs_info;
656 +       struct squashfs_super_block *sblk = &msblk->sblk;
657 +       long long block = SQUASHFS_INODE_BLK(inode) +
658 +               sblk->inode_table_start;
659 +       unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
660 +       long long next_block;
661 +       unsigned int next_offset;
662 +       union squashfs_inode_header id, sid;
663 +       struct squashfs_base_inode_header *inodeb = &id.base,
664 +                                         *sinodeb = &sid.base;
665 +
666 +       TRACE("Entered squashfs_iget\n");
667 +
668 +       if (msblk->swap) {
669 +               if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
670 +                                       offset, sizeof(*sinodeb), &next_block,
671 +                                       &next_offset))
672 +                       goto failed_read;
673 +               SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
674 +                                       sizeof(*sinodeb));
675 +       } else
676 +               if (!squashfs_get_cached_block(s, (char *) inodeb, block,
677 +                                       offset, sizeof(*inodeb), &next_block,
678 +                                       &next_offset))
679 +                       goto failed_read;
680 +
681 +       switch(inodeb->inode_type) {
682 +               case SQUASHFS_FILE_TYPE: {
683 +                       unsigned int frag_size;
684 +                       long long frag_blk;
685 +                       struct squashfs_reg_inode_header *inodep = &id.reg;
686 +                       struct squashfs_reg_inode_header *sinodep = &sid.reg;
687 +                               
688 +                       if (msblk->swap) {
689 +                               if (!squashfs_get_cached_block(s, (char *)
690 +                                               sinodep, block, offset,
691 +                                               sizeof(*sinodep), &next_block,
692 +                                               &next_offset))
693 +                                       goto failed_read;
694 +                               SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
695 +                       } else
696 +                               if (!squashfs_get_cached_block(s, (char *)
697 +                                               inodep, block, offset,
698 +                                               sizeof(*inodep), &next_block,
699 +                                               &next_offset))
700 +                                       goto failed_read;
701 +
702 +                       frag_blk = SQUASHFS_INVALID_BLK;
703 +                       if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
704 +                                       !get_fragment_location(s,
705 +                                       inodep->fragment, &frag_blk, &frag_size))
706 +                               goto failed_read;
707 +                               
708 +                       if((i = squashfs_new_inode(s, inodeb)) == NULL)
709 +                               goto failed_read1;
710 +
711 +                       i->i_nlink = 1;
712 +                       i->i_size = inodep->file_size;
713 +                       i->i_fop = &generic_ro_fops;
714 +                       i->i_mode |= S_IFREG;
715 +                       i->i_blocks = ((i->i_size - 1) >> 9) + 1;
716 +                       i->i_blksize = PAGE_CACHE_SIZE;
717 +                       SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
718 +                       SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
719 +                       SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
720 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
721 +                       SQUASHFS_I(i)->u.s1.block_list_start = next_block;
722 +                       SQUASHFS_I(i)->offset = next_offset;
723 +                       if (sblk->block_size > 4096)
724 +                               i->i_data.a_ops = &squashfs_aops;
725 +                       else
726 +                               i->i_data.a_ops = &squashfs_aops_4K;
727 +
728 +                       TRACE("File inode %x:%x, start_block %llx, "
729 +                                       "block_list_start %llx, offset %x\n",
730 +                                       SQUASHFS_INODE_BLK(inode), offset,
731 +                                       inodep->start_block, next_block,
732 +                                       next_offset);
733 +                       break;
734 +               }
735 +               case SQUASHFS_LREG_TYPE: {
736 +                       unsigned int frag_size;
737 +                       long long frag_blk;
738 +                       struct squashfs_lreg_inode_header *inodep = &id.lreg;
739 +                       struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
740 +                               
741 +                       if (msblk->swap) {
742 +                               if (!squashfs_get_cached_block(s, (char *)
743 +                                               sinodep, block, offset,
744 +                                               sizeof(*sinodep), &next_block,
745 +                                               &next_offset))
746 +                                       goto failed_read;
747 +                               SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
748 +                       } else
749 +                               if (!squashfs_get_cached_block(s, (char *)
750 +                                               inodep, block, offset,
751 +                                               sizeof(*inodep), &next_block,
752 +                                               &next_offset))
753 +                                       goto failed_read;
754 +
755 +                       frag_blk = SQUASHFS_INVALID_BLK;
756 +                       if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
757 +                                       !get_fragment_location(s,
758 +                                       inodep->fragment, &frag_blk, &frag_size))
759 +                               goto failed_read;
760 +                               
761 +                       if((i = squashfs_new_inode(s, inodeb)) == NULL)
762 +                               goto failed_read1;
763 +
764 +                       i->i_nlink = inodep->nlink;
765 +                       i->i_size = inodep->file_size;
766 +                       i->i_fop = &generic_ro_fops;
767 +                       i->i_mode |= S_IFREG;
768 +                       i->i_blocks = ((i->i_size - 1) >> 9) + 1;
769 +                       i->i_blksize = PAGE_CACHE_SIZE;
770 +                       SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
771 +                       SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
772 +                       SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
773 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
774 +                       SQUASHFS_I(i)->u.s1.block_list_start = next_block;
775 +                       SQUASHFS_I(i)->offset = next_offset;
776 +                       if (sblk->block_size > 4096)
777 +                               i->i_data.a_ops = &squashfs_aops;
778 +                       else
779 +                               i->i_data.a_ops = &squashfs_aops_4K;
780 +
781 +                       TRACE("File inode %x:%x, start_block %llx, "
782 +                                       "block_list_start %llx, offset %x\n",
783 +                                       SQUASHFS_INODE_BLK(inode), offset,
784 +                                       inodep->start_block, next_block,
785 +                                       next_offset);
786 +                       break;
787 +               }
788 +               case SQUASHFS_DIR_TYPE: {
789 +                       struct squashfs_dir_inode_header *inodep = &id.dir;
790 +                       struct squashfs_dir_inode_header *sinodep = &sid.dir;
791 +
792 +                       if (msblk->swap) {
793 +                               if (!squashfs_get_cached_block(s, (char *)
794 +                                               sinodep, block, offset,
795 +                                               sizeof(*sinodep), &next_block,
796 +                                               &next_offset))
797 +                                       goto failed_read;
798 +                               SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
799 +                       } else
800 +                               if (!squashfs_get_cached_block(s, (char *)
801 +                                               inodep, block, offset,
802 +                                               sizeof(*inodep), &next_block,
803 +                                               &next_offset))
804 +                                       goto failed_read;
805 +
806 +                       if((i = squashfs_new_inode(s, inodeb)) == NULL)
807 +                               goto failed_read1;
808 +
809 +                       i->i_nlink = inodep->nlink;
810 +                       i->i_size = inodep->file_size;
811 +                       i->i_op = &squashfs_dir_inode_ops;
812 +                       i->i_fop = &squashfs_dir_ops;
813 +                       i->i_mode |= S_IFDIR;
814 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
815 +                       SQUASHFS_I(i)->offset = inodep->offset;
816 +                       SQUASHFS_I(i)->u.s2.directory_index_count = 0;
817 +                       SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
818 +
819 +                       TRACE("Directory inode %x:%x, start_block %x, offset "
820 +                                       "%x\n", SQUASHFS_INODE_BLK(inode),
821 +                                       offset, inodep->start_block,
822 +                                       inodep->offset);
823 +                       break;
824 +               }
825 +               case SQUASHFS_LDIR_TYPE: {
826 +                       struct squashfs_ldir_inode_header *inodep = &id.ldir;
827 +                       struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
828 +
829 +                       if (msblk->swap) {
830 +                               if (!squashfs_get_cached_block(s, (char *)
831 +                                               sinodep, block, offset,
832 +                                               sizeof(*sinodep), &next_block,
833 +                                               &next_offset))
834 +                                       goto failed_read;
835 +                               SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
836 +                                               sinodep);
837 +                       } else
838 +                               if (!squashfs_get_cached_block(s, (char *)
839 +                                               inodep, block, offset,
840 +                                               sizeof(*inodep), &next_block,
841 +                                               &next_offset))
842 +                                       goto failed_read;
843 +
844 +                       if((i = squashfs_new_inode(s, inodeb)) == NULL)
845 +                               goto failed_read1;
846 +
847 +                       i->i_nlink = inodep->nlink;
848 +                       i->i_size = inodep->file_size;
849 +                       i->i_op = &squashfs_dir_inode_ops;
850 +                       i->i_fop = &squashfs_dir_ops;
851 +                       i->i_mode |= S_IFDIR;
852 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
853 +                       SQUASHFS_I(i)->offset = inodep->offset;
854 +                       SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
855 +                       SQUASHFS_I(i)->u.s2.directory_index_offset =
856 +                                                               next_offset;
857 +                       SQUASHFS_I(i)->u.s2.directory_index_count =
858 +                                                               inodep->i_count;
859 +                       SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
860 +
861 +                       TRACE("Long directory inode %x:%x, start_block %x, "
862 +                                       "offset %x\n",
863 +                                       SQUASHFS_INODE_BLK(inode), offset,
864 +                                       inodep->start_block, inodep->offset);
865 +                       break;
866 +               }
867 +               case SQUASHFS_SYMLINK_TYPE: {
868 +                       struct squashfs_symlink_inode_header *inodep =
869 +                                                               &id.symlink;
870 +                       struct squashfs_symlink_inode_header *sinodep =
871 +                                                               &sid.symlink;
872 +       
873 +                       if (msblk->swap) {
874 +                               if (!squashfs_get_cached_block(s, (char *)
875 +                                               sinodep, block, offset,
876 +                                               sizeof(*sinodep), &next_block,
877 +                                               &next_offset))
878 +                                       goto failed_read;
879 +                               SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
880 +                                                               sinodep);
881 +                       } else
882 +                               if (!squashfs_get_cached_block(s, (char *)
883 +                                               inodep, block, offset,
884 +                                               sizeof(*inodep), &next_block,
885 +                                               &next_offset))
886 +                                       goto failed_read;
887 +
888 +                       if((i = squashfs_new_inode(s, inodeb)) == NULL)
889 +                               goto failed_read1;
890 +
891 +                       i->i_nlink = inodep->nlink;
892 +                       i->i_size = inodep->symlink_size;
893 +                       i->i_op = &page_symlink_inode_operations;
894 +                       i->i_data.a_ops = &squashfs_symlink_aops;
895 +                       i->i_mode |= S_IFLNK;
896 +                       SQUASHFS_I(i)->start_block = next_block;
897 +                       SQUASHFS_I(i)->offset = next_offset;
898 +
899 +                       TRACE("Symbolic link inode %x:%x, start_block %llx, "
900 +                                       "offset %x\n",
901 +                                       SQUASHFS_INODE_BLK(inode), offset,
902 +                                       next_block, next_offset);
903 +                       break;
904 +                }
905 +                case SQUASHFS_BLKDEV_TYPE:
906 +                case SQUASHFS_CHRDEV_TYPE: {
907 +                       struct squashfs_dev_inode_header *inodep = &id.dev;
908 +                       struct squashfs_dev_inode_header *sinodep = &sid.dev;
909 +
910 +                       if (msblk->swap) {
911 +                               if (!squashfs_get_cached_block(s, (char *)
912 +                                               sinodep, block, offset,
913 +                                               sizeof(*sinodep), &next_block,
914 +                                               &next_offset))
915 +                                       goto failed_read;
916 +                               SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
917 +                       } else  
918 +                               if (!squashfs_get_cached_block(s, (char *)
919 +                                               inodep, block, offset,
920 +                                               sizeof(*inodep), &next_block,
921 +                                               &next_offset))
922 +                                       goto failed_read;
923 +
924 +                       if ((i = squashfs_new_inode(s, inodeb)) == NULL)
925 +                               goto failed_read1;
926 +
927 +                       i->i_nlink = inodep->nlink;
928 +                       i->i_mode |= (inodeb->inode_type ==
929 +                                       SQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :
930 +                                       S_IFBLK;
931 +                       init_special_inode(i, i->i_mode,
932 +                                       old_decode_dev(inodep->rdev));
933 +
934 +                       TRACE("Device inode %x:%x, rdev %x\n",
935 +                                       SQUASHFS_INODE_BLK(inode), offset,
936 +                                       inodep->rdev);
937 +                       break;
938 +                }
939 +                case SQUASHFS_FIFO_TYPE:
940 +                case SQUASHFS_SOCKET_TYPE: {
941 +                       struct squashfs_ipc_inode_header *inodep = &id.ipc;
942 +                       struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
943 +
944 +                       if (msblk->swap) {
945 +                               if (!squashfs_get_cached_block(s, (char *)
946 +                                               sinodep, block, offset,
947 +                                               sizeof(*sinodep), &next_block,
948 +                                               &next_offset))
949 +                                       goto failed_read;
950 +                               SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
951 +                       } else  
952 +                               if (!squashfs_get_cached_block(s, (char *)
953 +                                               inodep, block, offset,
954 +                                               sizeof(*inodep), &next_block,
955 +                                               &next_offset))
956 +                                       goto failed_read;
957 +
958 +                       if ((i = squashfs_new_inode(s, inodeb)) == NULL)
959 +                               goto failed_read1;
960 +
961 +                       i->i_nlink = inodep->nlink;
962 +                       i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
963 +                                                       ? S_IFIFO : S_IFSOCK;
964 +                       init_special_inode(i, i->i_mode, 0);
965 +                       break;
966 +                }
967 +                default:
968 +                       ERROR("Unknown inode type %d in squashfs_iget!\n",
969 +                                       inodeb->inode_type);
970 +                       goto failed_read1;
971 +       }
972 +       
973 +       insert_inode_hash(i);
974 +       return i;
975 +
976 +failed_read:
977 +       ERROR("Unable to read inode [%llx:%x]\n", block, offset);
978 +
979 +failed_read1:
980 +       return NULL;
981 +}
982 +
983 +
984 +static int read_fragment_index_table(struct super_block *s)
985 +{
986 +       struct squashfs_sb_info *msblk = s->s_fs_info;
987 +       struct squashfs_super_block *sblk = &msblk->sblk;
988 +
989 +       /* Allocate fragment index table */
990 +       if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
991 +                                       (sblk->fragments), GFP_KERNEL))) {
992 +               ERROR("Failed to allocate uid/gid table\n");
993 +               return 0;
994 +       }
995 +   
996 +       if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
997 +                                       !squashfs_read_data(s, (char *)
998 +                                       msblk->fragment_index,
999 +                                       sblk->fragment_table_start,
1000 +                                       SQUASHFS_FRAGMENT_INDEX_BYTES
1001 +                                       (sblk->fragments) |
1002 +                                       SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1003 +               ERROR("unable to read fragment index table\n");
1004 +               return 0;
1005 +       }
1006 +
1007 +       if (msblk->swap) {
1008 +               int i;
1009 +               long long fragment;
1010 +
1011 +               for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
1012 +                                                                       i++) {
1013 +                       SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
1014 +                                               &msblk->fragment_index[i], 1);
1015 +                       msblk->fragment_index[i] = fragment;
1016 +               }
1017 +       }
1018 +
1019 +       return 1;
1020 +}
1021 +
1022 +
1023 +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
1024 +{
1025 +       struct squashfs_super_block *sblk = &msblk->sblk;
1026 +
1027 +       msblk->iget = squashfs_iget;
1028 +       msblk->read_blocklist = read_blocklist;
1029 +       msblk->read_fragment_index_table = read_fragment_index_table;
1030 +
1031 +       if (sblk->s_major == 1) {
1032 +               if (!squashfs_1_0_supported(msblk)) {
1033 +                       SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
1034 +                               "are unsupported\n");
1035 +                       SERROR("Please recompile with "
1036 +                               "Squashfs 1.0 support enabled\n");
1037 +                       return 0;
1038 +               }
1039 +       } else if (sblk->s_major == 2) {
1040 +               if (!squashfs_2_0_supported(msblk)) {
1041 +                       SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
1042 +                               "are unsupported\n");
1043 +                       SERROR("Please recompile with "
1044 +                               "Squashfs 2.0 support enabled\n");
1045 +                       return 0;
1046 +               }
1047 +       } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
1048 +                       SQUASHFS_MINOR) {
1049 +               SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
1050 +                               "filesystem\n", sblk->s_major, sblk->s_minor);
1051 +               SERROR("Please update your kernel\n");
1052 +               return 0;
1053 +       }
1054 +
1055 +       return 1;
1056 +}
1057 +
1058 +
1059 +static int squashfs_fill_super(struct super_block *s, void *data, int silent)
1060 +{
1061 +       struct squashfs_sb_info *msblk;
1062 +       struct squashfs_super_block *sblk;
1063 +       int i;
1064 +       char b[BDEVNAME_SIZE];
1065 +       struct inode *root;
1066 +
1067 +       TRACE("Entered squashfs_read_superblock\n");
1068 +
1069 +       if (!(s->s_fs_info = kmalloc(sizeof(struct squashfs_sb_info),
1070 +                                               GFP_KERNEL))) {
1071 +               ERROR("Failed to allocate superblock\n");
1072 +               goto failure;
1073 +       }
1074 +       memset(s->s_fs_info, 0, sizeof(struct squashfs_sb_info));
1075 +       msblk = s->s_fs_info;
1076 +       sblk = &msblk->sblk;
1077 +       
1078 +       msblk->devblksize = sb_min_blocksize(s, BLOCK_SIZE);
1079 +       msblk->devblksize_log2 = ffz(~msblk->devblksize);
1080 +
1081 +       init_MUTEX(&msblk->read_data_mutex);
1082 +       init_MUTEX(&msblk->read_page_mutex);
1083 +       init_MUTEX(&msblk->block_cache_mutex);
1084 +       init_MUTEX(&msblk->fragment_mutex);
1085 +       init_MUTEX(&msblk->meta_index_mutex);
1086 +       
1087 +       init_waitqueue_head(&msblk->waitq);
1088 +       init_waitqueue_head(&msblk->fragment_wait_queue);
1089 +
1090 +       if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
1091 +                                       sizeof(struct squashfs_super_block) |
1092 +                                       SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1093 +               SERROR("unable to read superblock\n");
1094 +               goto failed_mount;
1095 +       }
1096 +
1097 +       /* Check it is a SQUASHFS superblock */
1098 +       msblk->swap = 0;
1099 +       if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
1100 +               if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
1101 +                       struct squashfs_super_block ssblk;
1102 +
1103 +                       WARNING("Mounting a different endian SQUASHFS "
1104 +                               "filesystem on %s\n", bdevname(s->s_bdev, b));
1105 +
1106 +                       SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
1107 +                       memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
1108 +                       msblk->swap = 1;
1109 +               } else  {
1110 +                       SERROR("Can't find a SQUASHFS superblock on %s\n",
1111 +                                                       bdevname(s->s_bdev, b));
1112 +                       goto failed_mount;
1113 +               }
1114 +       }
1115 +
1116 +       /* Check the MAJOR & MINOR versions */
1117 +       if(!supported_squashfs_filesystem(msblk, silent))
1118 +               goto failed_mount;
1119 +
1120 +       TRACE("Found valid superblock on %s\n", bdevname(s->s_bdev, b));
1121 +       TRACE("Inodes are %scompressed\n",
1122 +                                       SQUASHFS_UNCOMPRESSED_INODES
1123 +                                       (sblk->flags) ? "un" : "");
1124 +       TRACE("Data is %scompressed\n",
1125 +                                       SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
1126 +                                       ? "un" : "");
1127 +       TRACE("Check data is %s present in the filesystem\n",
1128 +                                       SQUASHFS_CHECK_DATA(sblk->flags) ?
1129 +                                       "" : "not");
1130 +       TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
1131 +       TRACE("Block size %d\n", sblk->block_size);
1132 +       TRACE("Number of inodes %d\n", sblk->inodes);
1133 +       if (sblk->s_major > 1)
1134 +               TRACE("Number of fragments %d\n", sblk->fragments);
1135 +       TRACE("Number of uids %d\n", sblk->no_uids);
1136 +       TRACE("Number of gids %d\n", sblk->no_guids);
1137 +       TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
1138 +       TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
1139 +       if (sblk->s_major > 1)
1140 +               TRACE("sblk->fragment_table_start %llx\n",
1141 +                                       sblk->fragment_table_start);
1142 +       TRACE("sblk->uid_start %llx\n", sblk->uid_start);
1143 +
1144 +       s->s_flags |= MS_RDONLY;
1145 +       s->s_op = &squashfs_ops;
1146 +
1147 +       /* Init inode_table block pointer array */
1148 +       if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
1149 +                                       SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
1150 +               ERROR("Failed to allocate block cache\n");
1151 +               goto failed_mount;
1152 +       }
1153 +
1154 +       for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
1155 +               msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
1156 +
1157 +       msblk->next_cache = 0;
1158 +
1159 +       /* Allocate read_data block */
1160 +       msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
1161 +                                       SQUASHFS_METADATA_SIZE :
1162 +                                       sblk->block_size;
1163 +
1164 +       if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
1165 +               ERROR("Failed to allocate read_data block\n");
1166 +               goto failed_mount;
1167 +       }
1168 +
1169 +       /* Allocate read_page block */
1170 +       if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
1171 +               ERROR("Failed to allocate read_page block\n");
1172 +               goto failed_mount;
1173 +       }
1174 +
1175 +       /* Allocate uid and gid tables */
1176 +       if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
1177 +                                       sizeof(unsigned int), GFP_KERNEL))) {
1178 +               ERROR("Failed to allocate uid/gid table\n");
1179 +               goto failed_mount;
1180 +       }
1181 +       msblk->guid = msblk->uid + sblk->no_uids;
1182 +   
1183 +       if (msblk->swap) {
1184 +               unsigned int suid[sblk->no_uids + sblk->no_guids];
1185 +
1186 +               if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
1187 +                                       ((sblk->no_uids + sblk->no_guids) *
1188 +                                        sizeof(unsigned int)) |
1189 +                                       SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1190 +                       ERROR("unable to read uid/gid table\n");
1191 +                       goto failed_mount;
1192 +               }
1193 +
1194 +               SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
1195 +                       sblk->no_guids), (sizeof(unsigned int) * 8));
1196 +       } else
1197 +               if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
1198 +                                       ((sblk->no_uids + sblk->no_guids) *
1199 +                                        sizeof(unsigned int)) |
1200 +                                       SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
1201 +                       ERROR("unable to read uid/gid table\n");
1202 +                       goto failed_mount;
1203 +               }
1204 +
1205 +
1206 +       if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
1207 +               goto allocate_root;
1208 +
1209 +       if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
1210 +                               SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
1211 +               ERROR("Failed to allocate fragment block cache\n");
1212 +               goto failed_mount;
1213 +       }
1214 +
1215 +       for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
1216 +               msblk->fragment[i].locked = 0;
1217 +               msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
1218 +               msblk->fragment[i].data = NULL;
1219 +       }
1220 +
1221 +       msblk->next_fragment = 0;
1222 +
1223 +       /* Allocate fragment index table */
1224 +       if (msblk->read_fragment_index_table(s) == 0)
1225 +               goto failed_mount;
1226 +
1227 +allocate_root:
1228 +       if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
1229 +               goto failed_mount;
1230 +
1231 +       if ((s->s_root = d_alloc_root(root)) == NULL) {
1232 +               ERROR("Root inode create failed\n");
1233 +               iput(root);
1234 +               goto failed_mount;
1235 +       }
1236 +
1237 +       TRACE("Leaving squashfs_read_super\n");
1238 +       return 0;
1239 +
1240 +failed_mount:
1241 +       kfree(msblk->fragment_index);
1242 +       kfree(msblk->fragment);
1243 +       kfree(msblk->uid);
1244 +       kfree(msblk->read_page);
1245 +       kfree(msblk->read_data);
1246 +       kfree(msblk->block_cache);
1247 +       kfree(msblk->fragment_index_2);
1248 +       kfree(s->s_fs_info);
1249 +       s->s_fs_info = NULL;
1250 +       return -EINVAL;
1251 +
1252 +failure:
1253 +       return -ENOMEM;
1254 +}
1255 +
1256 +
1257 +static int squashfs_statfs(struct super_block *s, struct kstatfs *buf)
1258 +{
1259 +       struct squashfs_sb_info *msblk = s->s_fs_info;
1260 +       struct squashfs_super_block *sblk = &msblk->sblk;
1261 +
1262 +       TRACE("Entered squashfs_statfs\n");
1263 +
1264 +       buf->f_type = SQUASHFS_MAGIC;
1265 +       buf->f_bsize = sblk->block_size;
1266 +       buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
1267 +       buf->f_bfree = buf->f_bavail = 0;
1268 +       buf->f_files = sblk->inodes;
1269 +       buf->f_ffree = 0;
1270 +       buf->f_namelen = SQUASHFS_NAME_LEN;
1271 +
1272 +       return 0;
1273 +}
1274 +
1275 +
1276 +static int squashfs_symlink_readpage(struct file *file, struct page *page)
1277 +{
1278 +       struct inode *inode = page->mapping->host;
1279 +       int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
1280 +       long long block = SQUASHFS_I(inode)->start_block;
1281 +       int offset = SQUASHFS_I(inode)->offset;
1282 +       void *pageaddr = kmap(page);
1283 +
1284 +       TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
1285 +                               "%llx, offset %x\n", page->index,
1286 +                               SQUASHFS_I(inode)->start_block,
1287 +                               SQUASHFS_I(inode)->offset);
1288 +
1289 +       for (length = 0; length < index; length += bytes) {
1290 +               if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
1291 +                               block, offset, PAGE_CACHE_SIZE, &block,
1292 +                               &offset))) {
1293 +                       ERROR("Unable to read symbolic link [%llx:%x]\n", block,
1294 +                                       offset);
1295 +                       goto skip_read;
1296 +               }
1297 +       }
1298 +
1299 +       if (length != index) {
1300 +               ERROR("(squashfs_symlink_readpage) length != index\n");
1301 +               bytes = 0;
1302 +               goto skip_read;
1303 +       }
1304 +
1305 +       bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
1306 +                                       i_size_read(inode) - length;
1307 +
1308 +       if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
1309 +                                       offset, bytes, &block, &offset)))
1310 +               ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
1311 +
1312 +skip_read:
1313 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1314 +       kunmap(page);
1315 +       SetPageUptodate(page);
1316 +       unlock_page(page);
1317 +
1318 +       return 0;
1319 +}
1320 +
1321 +
1322 +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
1323 +{
1324 +       struct meta_index *meta = NULL;
1325 +       struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1326 +       int i;
1327 +
1328 +       down(&msblk->meta_index_mutex);
1329 +
1330 +       TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
1331 +
1332 +       if(msblk->meta_index == NULL)
1333 +               goto not_allocated;
1334 +
1335 +       for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
1336 +               if (msblk->meta_index[i].inode_number == inode->i_ino &&
1337 +                               msblk->meta_index[i].offset >= offset &&
1338 +                               msblk->meta_index[i].offset <= index &&
1339 +                               msblk->meta_index[i].locked == 0) {
1340 +                       TRACE("locate_meta_index: entry %d, offset %d\n", i,
1341 +                                       msblk->meta_index[i].offset);
1342 +                       meta = &msblk->meta_index[i];
1343 +                       offset = meta->offset;
1344 +               }
1345 +
1346 +       if (meta)
1347 +               meta->locked = 1;
1348 +
1349 +not_allocated:
1350 +       up(&msblk->meta_index_mutex);
1351 +
1352 +       return meta;
1353 +}
1354 +
1355 +
1356 +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
1357 +{
1358 +       struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1359 +       struct meta_index *meta = NULL;
1360 +       int i;
1361 +
1362 +       down(&msblk->meta_index_mutex);
1363 +
1364 +       TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
1365 +
1366 +       if(msblk->meta_index == NULL) {
1367 +               if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
1368 +                                       SQUASHFS_META_NUMBER, GFP_KERNEL))) {
1369 +                       ERROR("Failed to allocate meta_index\n");
1370 +                       goto failed;
1371 +               }
1372 +               for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
1373 +                       msblk->meta_index[i].inode_number = 0;
1374 +                       msblk->meta_index[i].locked = 0;
1375 +               }
1376 +               msblk->next_meta_index = 0;
1377 +       }
1378 +
1379 +       for(i = SQUASHFS_META_NUMBER; i &&
1380 +                       msblk->meta_index[msblk->next_meta_index].locked; i --)
1381 +               msblk->next_meta_index = (msblk->next_meta_index + 1) %
1382 +                       SQUASHFS_META_NUMBER;
1383 +
1384 +       if(i == 0) {
1385 +               TRACE("empty_meta_index: failed!\n");
1386 +               goto failed;
1387 +       }
1388 +
1389 +       TRACE("empty_meta_index: returned meta entry %d, %p\n",
1390 +                       msblk->next_meta_index,
1391 +                       &msblk->meta_index[msblk->next_meta_index]);
1392 +
1393 +       meta = &msblk->meta_index[msblk->next_meta_index];
1394 +       msblk->next_meta_index = (msblk->next_meta_index + 1) %
1395 +                       SQUASHFS_META_NUMBER;
1396 +
1397 +       meta->inode_number = inode->i_ino;
1398 +       meta->offset = offset;
1399 +       meta->skip = skip;
1400 +       meta->entries = 0;
1401 +       meta->locked = 1;
1402 +
1403 +failed:
1404 +       up(&msblk->meta_index_mutex);
1405 +       return meta;
1406 +}
1407 +
1408 +
1409 +void release_meta_index(struct inode *inode, struct meta_index *meta)
1410 +{
1411 +       meta->locked = 0;
1412 +}
1413 +
1414 +
1415 +static int read_block_index(struct super_block *s, int blocks, char *block_list,
1416 +               long long *start_block, int *offset)
1417 +{
1418 +       struct squashfs_sb_info *msblk = s->s_fs_info;
1419 +       unsigned int *block_listp;
1420 +       int block = 0;
1421 +       
1422 +       if (msblk->swap) {
1423 +               char sblock_list[blocks << 2];
1424 +
1425 +               if (!squashfs_get_cached_block(s, sblock_list, *start_block,
1426 +                               *offset, blocks << 2, start_block, offset)) {
1427 +                       ERROR("Unable to read block list [%llx:%x]\n",
1428 +                               *start_block, *offset);
1429 +                       goto failure;
1430 +               }
1431 +               SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
1432 +                               ((unsigned int *)sblock_list), blocks);
1433 +       } else
1434 +               if (!squashfs_get_cached_block(s, block_list, *start_block,
1435 +                               *offset, blocks << 2, start_block, offset)) {
1436 +                       ERROR("Unable to read block list [%llx:%x]\n",
1437 +                               *start_block, *offset);
1438 +                       goto failure;
1439 +               }
1440 +
1441 +       for (block_listp = (unsigned int *) block_list; blocks;
1442 +                               block_listp++, blocks --)
1443 +               block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
1444 +
1445 +       return block;
1446 +
1447 +failure:
1448 +       return -1;
1449 +}
1450 +
1451 +
1452 +#define SIZE 256
1453 +
1454 +static inline int calculate_skip(int blocks) {
1455 +       int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
1456 +       return skip >= 7 ? 7 : skip + 1;
1457 +}
1458 +
1459 +
1460 +static int get_meta_index(struct inode *inode, int index,
1461 +               long long *index_block, int *index_offset,
1462 +               long long *data_block, char *block_list)
1463 +{
1464 +       struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1465 +       struct squashfs_super_block *sblk = &msblk->sblk;
1466 +       int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
1467 +       int offset = 0;
1468 +       struct meta_index *meta;
1469 +       struct meta_entry *meta_entry;
1470 +       long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
1471 +       int cur_offset = SQUASHFS_I(inode)->offset;
1472 +       long long cur_data_block = SQUASHFS_I(inode)->start_block;
1473 +       int i;
1474
1475 +       index /= SQUASHFS_META_INDEXES * skip;
1476 +
1477 +       while ( offset < index ) {
1478 +               meta = locate_meta_index(inode, index, offset + 1);
1479 +
1480 +               if (meta == NULL) {
1481 +                       if ((meta = empty_meta_index(inode, offset + 1,
1482 +                                                       skip)) == NULL)
1483 +                               goto all_done;
1484 +               } else {
1485 +                       offset = index < meta->offset + meta->entries ? index :
1486 +                               meta->offset + meta->entries - 1;
1487 +                       meta_entry = &meta->meta_entry[offset - meta->offset];
1488 +                       cur_index_block = meta_entry->index_block + sblk->inode_table_start;
1489 +                       cur_offset = meta_entry->offset;
1490 +                       cur_data_block = meta_entry->data_block;
1491 +                       TRACE("get_meta_index: offset %d, meta->offset %d, "
1492 +                               "meta->entries %d\n", offset, meta->offset,
1493 +                               meta->entries);
1494 +                       TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
1495 +                               " data_block 0x%llx\n", cur_index_block,
1496 +                               cur_offset, cur_data_block);
1497 +               }
1498 +
1499 +               for (i = meta->offset + meta->entries; i <= index &&
1500 +                               i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
1501 +                       int blocks = skip * SQUASHFS_META_INDEXES;
1502 +
1503 +                       while (blocks) {
1504 +                               int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
1505 +                                       blocks;
1506 +                               int res = read_block_index(inode->i_sb, block,
1507 +                                       block_list, &cur_index_block,
1508 +                                       &cur_offset);
1509 +
1510 +                               if (res == -1)
1511 +                                       goto failed;
1512 +
1513 +                               cur_data_block += res;
1514 +                               blocks -= block;
1515 +                       }
1516 +
1517 +                       meta_entry = &meta->meta_entry[i - meta->offset];
1518 +                       meta_entry->index_block = cur_index_block - sblk->inode_table_start;
1519 +                       meta_entry->offset = cur_offset;
1520 +                       meta_entry->data_block = cur_data_block;
1521 +                       meta->entries ++;
1522 +                       offset ++;
1523 +               }
1524 +
1525 +               TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
1526 +                               meta->offset, meta->entries);
1527 +
1528 +               release_meta_index(inode, meta);
1529 +       }
1530 +
1531 +all_done:
1532 +       *index_block = cur_index_block;
1533 +       *index_offset = cur_offset;
1534 +       *data_block = cur_data_block;
1535 +
1536 +       return offset * SQUASHFS_META_INDEXES * skip;
1537 +
1538 +failed:
1539 +       release_meta_index(inode, meta);
1540 +       return -1;
1541 +}
1542 +
1543 +
1544 +static long long read_blocklist(struct inode *inode, int index,
1545 +                               int readahead_blks, char *block_list,
1546 +                               unsigned short **block_p, unsigned int *bsize)
1547 +{
1548 +       long long block_ptr;
1549 +       int offset;
1550 +       long long block;
1551 +       int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
1552 +               block_list);
1553 +
1554 +       TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
1555 +                      " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
1556 +                      block);
1557 +
1558 +       if(res == -1)
1559 +               goto failure;
1560 +
1561 +       index -= res;
1562 +
1563 +       while ( index ) {
1564 +               int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
1565 +               int res = read_block_index(inode->i_sb, blocks, block_list,
1566 +                       &block_ptr, &offset);
1567 +               if (res == -1)
1568 +                       goto failure;
1569 +               block += res;
1570 +               index -= blocks;
1571 +       }
1572 +
1573 +       if (read_block_index(inode->i_sb, 1, block_list,
1574 +                       &block_ptr, &offset) == -1)
1575 +               goto failure;
1576 +       *bsize = *((unsigned int *) block_list);
1577 +
1578 +       return block;
1579 +
1580 +failure:
1581 +       return 0;
1582 +}
1583 +
1584 +
1585 +static int squashfs_readpage(struct file *file, struct page *page)
1586 +{
1587 +       struct inode *inode = page->mapping->host;
1588 +       struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1589 +       struct squashfs_super_block *sblk = &msblk->sblk;
1590 +       unsigned char block_list[SIZE];
1591 +       long long block;
1592 +       unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
1593 +       int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
1594 +       void *pageaddr;
1595 +       struct squashfs_fragment_cache *fragment = NULL;
1596 +       char *data_ptr = msblk->read_page;
1597 +       
1598 +       int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
1599 +       int start_index = page->index & ~mask;
1600 +       int end_index = start_index | mask;
1601 +
1602 +       TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
1603 +                                       page->index,
1604 +                                       SQUASHFS_I(inode)->start_block);
1605 +
1606 +       if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1607 +                                       PAGE_CACHE_SHIFT))
1608 +               goto skip_read;
1609 +
1610 +       if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1611 +                                       || index < (i_size_read(inode) >>
1612 +                                       sblk->block_log)) {
1613 +               if ((block = (msblk->read_blocklist)(inode, index, 1,
1614 +                                       block_list, NULL, &bsize)) == 0)
1615 +                       goto skip_read;
1616 +
1617 +               down(&msblk->read_page_mutex);
1618 +               
1619 +               if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
1620 +                                       block, bsize, NULL))) {
1621 +                       ERROR("Unable to read page, block %llx, size %x\n", block,
1622 +                                       bsize);
1623 +                       up(&msblk->read_page_mutex);
1624 +                       goto skip_read;
1625 +               }
1626 +       } else {
1627 +               if ((fragment = get_cached_fragment(inode->i_sb,
1628 +                                       SQUASHFS_I(inode)->
1629 +                                       u.s1.fragment_start_block,
1630 +                                       SQUASHFS_I(inode)->u.s1.fragment_size))
1631 +                                       == NULL) {
1632 +                       ERROR("Unable to read page, block %llx, size %x\n",
1633 +                                       SQUASHFS_I(inode)->
1634 +                                       u.s1.fragment_start_block,
1635 +                                       (int) SQUASHFS_I(inode)->
1636 +                                       u.s1.fragment_size);
1637 +                       goto skip_read;
1638 +               }
1639 +               bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
1640 +                                       (i_size_read(inode) & (sblk->block_size
1641 +                                       - 1));
1642 +               byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
1643 +               data_ptr = fragment->data;
1644 +       }
1645 +
1646 +       for (i = start_index; i <= end_index && byte_offset < bytes;
1647 +                                       i++, byte_offset += PAGE_CACHE_SIZE) {
1648 +               struct page *push_page;
1649 +               int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
1650 +                                       PAGE_CACHE_SIZE : bytes - byte_offset;
1651 +
1652 +               TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
1653 +                                       bytes, i, byte_offset, available_bytes);
1654 +
1655 +               if (i == page->index)  {
1656 +                       pageaddr = kmap_atomic(page, KM_USER0);
1657 +                       memcpy(pageaddr, data_ptr + byte_offset,
1658 +                                       available_bytes);
1659 +                       memset(pageaddr + available_bytes, 0,
1660 +                                       PAGE_CACHE_SIZE - available_bytes);
1661 +                       kunmap_atomic(pageaddr, KM_USER0);
1662 +                       flush_dcache_page(page);
1663 +                       SetPageUptodate(page);
1664 +                       unlock_page(page);
1665 +               } else if ((push_page =
1666 +                               grab_cache_page_nowait(page->mapping, i))) {
1667 +                       pageaddr = kmap_atomic(push_page, KM_USER0);
1668 +
1669 +                       memcpy(pageaddr, data_ptr + byte_offset,
1670 +                                       available_bytes);
1671 +                       memset(pageaddr + available_bytes, 0,
1672 +                                       PAGE_CACHE_SIZE - available_bytes);
1673 +                       kunmap_atomic(pageaddr, KM_USER0);
1674 +                       flush_dcache_page(push_page);
1675 +                       SetPageUptodate(push_page);
1676 +                       unlock_page(push_page);
1677 +                       page_cache_release(push_page);
1678 +               }
1679 +       }
1680 +
1681 +       if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1682 +                                       || index < (i_size_read(inode) >>
1683 +                                       sblk->block_log))
1684 +               up(&msblk->read_page_mutex);
1685 +       else
1686 +               release_cached_fragment(msblk, fragment);
1687 +
1688 +       return 0;
1689 +
1690 +skip_read:
1691 +       pageaddr = kmap_atomic(page, KM_USER0);
1692 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1693 +       kunmap_atomic(pageaddr, KM_USER0);
1694 +       flush_dcache_page(page);
1695 +       SetPageUptodate(page);
1696 +       unlock_page(page);
1697 +
1698 +       return 0;
1699 +}
1700 +
1701 +
1702 +static int squashfs_readpage4K(struct file *file, struct page *page)
1703 +{
1704 +       struct inode *inode = page->mapping->host;
1705 +       struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
1706 +       struct squashfs_super_block *sblk = &msblk->sblk;
1707 +       unsigned char block_list[SIZE];
1708 +       long long block;
1709 +       unsigned int bsize, bytes = 0;
1710 +       void *pageaddr;
1711 +       
1712 +       TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
1713 +                                       page->index,
1714 +                                       SQUASHFS_I(inode)->start_block);
1715 +
1716 +       if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
1717 +                                       PAGE_CACHE_SHIFT)) {
1718 +               pageaddr = kmap_atomic(page, KM_USER0);
1719 +               goto skip_read;
1720 +       }
1721 +
1722 +       if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
1723 +                                       || page->index < (i_size_read(inode) >>
1724 +                                       sblk->block_log)) {
1725 +               block = (msblk->read_blocklist)(inode, page->index, 1,
1726 +                                       block_list, NULL, &bsize);
1727 +
1728 +               down(&msblk->read_page_mutex);
1729 +               bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
1730 +                                       bsize, NULL);
1731 +               pageaddr = kmap_atomic(page, KM_USER0);
1732 +               if (bytes)
1733 +                       memcpy(pageaddr, msblk->read_page, bytes);
1734 +               else
1735 +                       ERROR("Unable to read page, block %llx, size %x\n",
1736 +                                       block, bsize);
1737 +               up(&msblk->read_page_mutex);
1738 +       } else {
1739 +               struct squashfs_fragment_cache *fragment =
1740 +                       get_cached_fragment(inode->i_sb,
1741 +                                       SQUASHFS_I(inode)->
1742 +                                       u.s1.fragment_start_block,
1743 +                                       SQUASHFS_I(inode)-> u.s1.fragment_size);
1744 +               pageaddr = kmap_atomic(page, KM_USER0);
1745 +               if (fragment) {
1746 +                       bytes = i_size_read(inode) & (sblk->block_size - 1);
1747 +                       memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
1748 +                                       u.s1.fragment_offset, bytes);
1749 +                       release_cached_fragment(msblk, fragment);
1750 +               } else
1751 +                       ERROR("Unable to read page, block %llx, size %x\n",
1752 +                                       SQUASHFS_I(inode)->
1753 +                                       u.s1.fragment_start_block, (int)
1754 +                                       SQUASHFS_I(inode)-> u.s1.fragment_size);
1755 +       }
1756 +
1757 +skip_read:
1758 +       memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1759 +       kunmap_atomic(pageaddr, KM_USER0);
1760 +       flush_dcache_page(page);
1761 +       SetPageUptodate(page);
1762 +       unlock_page(page);
1763 +
1764 +       return 0;
1765 +}
1766 +
1767 +
1768 +static int get_dir_index_using_offset(struct super_block *s, long long 
1769 +                               *next_block, unsigned int *next_offset,
1770 +                               long long index_start,
1771 +                               unsigned int index_offset, int i_count,
1772 +                               long long f_pos)
1773 +{
1774 +       struct squashfs_sb_info *msblk = s->s_fs_info;
1775 +       struct squashfs_super_block *sblk = &msblk->sblk;
1776 +       int i, length = 0;
1777 +       struct squashfs_dir_index index;
1778 +
1779 +       TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
1780 +                                       i_count, (unsigned int) f_pos);
1781 +
1782 +       f_pos =- 3;
1783 +       if (f_pos == 0)
1784 +               goto finish;
1785 +
1786 +       for (i = 0; i < i_count; i++) {
1787 +               if (msblk->swap) {
1788 +                       struct squashfs_dir_index sindex;
1789 +                       squashfs_get_cached_block(s, (char *) &sindex,
1790 +                                       index_start, index_offset,
1791 +                                       sizeof(sindex), &index_start,
1792 +                                       &index_offset);
1793 +                       SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
1794 +               } else
1795 +                       squashfs_get_cached_block(s, (char *) &index,
1796 +                                       index_start, index_offset,
1797 +                                       sizeof(index), &index_start,
1798 +                                       &index_offset);
1799 +
1800 +               if (index.index > f_pos)
1801 +                       break;
1802 +
1803 +               squashfs_get_cached_block(s, NULL, index_start, index_offset,
1804 +                                       index.size + 1, &index_start,
1805 +                                       &index_offset);
1806 +
1807 +               length = index.index;
1808 +               *next_block = index.start_block + sblk->directory_table_start;
1809 +       }
1810 +
1811 +       *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1812 +
1813 +finish:
1814 +       return length + 3;
1815 +}
1816 +
1817 +
1818 +static int get_dir_index_using_name(struct super_block *s, long long
1819 +                               *next_block, unsigned int *next_offset,
1820 +                               long long index_start,
1821 +                               unsigned int index_offset, int i_count,
1822 +                               const char *name, int size)
1823 +{
1824 +       struct squashfs_sb_info *msblk = s->s_fs_info;
1825 +       struct squashfs_super_block *sblk = &msblk->sblk;
1826 +       int i, length = 0;
1827 +       char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
1828 +       struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
1829 +       char str[SQUASHFS_NAME_LEN + 1];
1830 +
1831 +       TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
1832 +
1833 +       strncpy(str, name, size);
1834 +       str[size] = '\0';
1835 +
1836 +       for (i = 0; i < i_count; i++) {
1837 +               if (msblk->swap) {
1838 +                       struct squashfs_dir_index sindex;
1839 +                       squashfs_get_cached_block(s, (char *) &sindex,
1840 +                                       index_start, index_offset,
1841 +                                       sizeof(sindex), &index_start,
1842 +                                       &index_offset);
1843 +                       SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
1844 +               } else
1845 +                       squashfs_get_cached_block(s, (char *) index,
1846 +                                       index_start, index_offset,
1847 +                                       sizeof(struct squashfs_dir_index),
1848 +                                       &index_start, &index_offset);
1849 +
1850 +               squashfs_get_cached_block(s, index->name, index_start,
1851 +                                       index_offset, index->size + 1,
1852 +                                       &index_start, &index_offset);
1853 +
1854 +               index->name[index->size + 1] = '\0';
1855 +
1856 +               if (strcmp(index->name, str) > 0)
1857 +                       break;
1858 +
1859 +               length = index->index;
1860 +               *next_block = index->start_block + sblk->directory_table_start;
1861 +       }
1862 +
1863 +       *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
1864 +       return length + 3;
1865 +}
1866 +
1867 +               
1868 +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
1869 +{
1870 +       struct inode *i = file->f_dentry->d_inode;
1871 +       struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
1872 +       struct squashfs_super_block *sblk = &msblk->sblk;
1873 +       long long next_block = SQUASHFS_I(i)->start_block +
1874 +               sblk->directory_table_start;
1875 +       int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
1876 +               dir_count;
1877 +       struct squashfs_dir_header dirh;
1878 +       char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
1879 +       struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
1880 +
1881 +       TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
1882 +
1883 +       while(file->f_pos < 3) {
1884 +               char *name;
1885 +               int size, i_ino;
1886 +
1887 +               if(file->f_pos == 0) {
1888 +                       name = ".";
1889 +                       size = 1;
1890 +                       i_ino = i->i_ino;
1891 +               } else {
1892 +                       name = "..";
1893 +                       size = 2;
1894 +                       i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
1895 +               }
1896 +               TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
1897 +                               (unsigned int) dirent, name, size, (int)
1898 +                               file->f_pos, i_ino,
1899 +                               squashfs_filetype_table[1]);
1900 +
1901 +               if (filldir(dirent, name, size,
1902 +                               file->f_pos, i_ino,
1903 +                               squashfs_filetype_table[1]) < 0) {
1904 +                               TRACE("Filldir returned less than 0\n");
1905 +                               goto finish;
1906 +               }
1907 +               file->f_pos += size;
1908 +               dirs_read++;
1909 +       }
1910 +
1911 +       length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
1912 +                               SQUASHFS_I(i)->u.s2.directory_index_start,
1913 +                               SQUASHFS_I(i)->u.s2.directory_index_offset,
1914 +                               SQUASHFS_I(i)->u.s2.directory_index_count,
1915 +                               file->f_pos);
1916 +
1917 +       while (length < i_size_read(i)) {
1918 +               /* read directory header */
1919 +               if (msblk->swap) {
1920 +                       struct squashfs_dir_header sdirh;
1921 +                       
1922 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
1923 +                                       next_block, next_offset, sizeof(sdirh),
1924 +                                       &next_block, &next_offset))
1925 +                               goto failed_read;
1926 +
1927 +                       length += sizeof(sdirh);
1928 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
1929 +               } else {
1930 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
1931 +                                       next_block, next_offset, sizeof(dirh),
1932 +                                       &next_block, &next_offset))
1933 +                               goto failed_read;
1934 +
1935 +                       length += sizeof(dirh);
1936 +               }
1937 +
1938 +               dir_count = dirh.count + 1;
1939 +               while (dir_count--) {
1940 +                       if (msblk->swap) {
1941 +                               struct squashfs_dir_entry sdire;
1942 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
1943 +                                               &sdire, next_block, next_offset,
1944 +                                               sizeof(sdire), &next_block,
1945 +                                               &next_offset))
1946 +                                       goto failed_read;
1947 +                               
1948 +                               length += sizeof(sdire);
1949 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
1950 +                       } else {
1951 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
1952 +                                               dire, next_block, next_offset,
1953 +                                               sizeof(*dire), &next_block,
1954 +                                               &next_offset))
1955 +                                       goto failed_read;
1956 +
1957 +                               length += sizeof(*dire);
1958 +                       }
1959 +
1960 +                       if (!squashfs_get_cached_block(i->i_sb, dire->name,
1961 +                                               next_block, next_offset,
1962 +                                               dire->size + 1, &next_block,
1963 +                                               &next_offset))
1964 +                               goto failed_read;
1965 +
1966 +                       length += dire->size + 1;
1967 +
1968 +                       if (file->f_pos >= length)
1969 +                               continue;
1970 +
1971 +                       dire->name[dire->size + 1] = '\0';
1972 +
1973 +                       TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
1974 +                                       (unsigned int) dirent, dire->name,
1975 +                                       dire->size + 1, (int) file->f_pos,
1976 +                                       dirh.start_block, dire->offset,
1977 +                                       dirh.inode_number + dire->inode_number,
1978 +                                       squashfs_filetype_table[dire->type]);
1979 +
1980 +                       if (filldir(dirent, dire->name, dire->size + 1,
1981 +                                       file->f_pos,
1982 +                                       dirh.inode_number + dire->inode_number,
1983 +                                       squashfs_filetype_table[dire->type])
1984 +                                       < 0) {
1985 +                               TRACE("Filldir returned less than 0\n");
1986 +                               goto finish;
1987 +                       }
1988 +                       file->f_pos = length;
1989 +                       dirs_read++;
1990 +               }
1991 +       }
1992 +
1993 +finish:
1994 +       return dirs_read;
1995 +
1996 +failed_read:
1997 +       ERROR("Unable to read directory block [%llx:%x]\n", next_block,
1998 +               next_offset);
1999 +       return 0;
2000 +}
2001 +
2002 +
2003 +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry,
2004 +                               struct nameidata *nd)
2005 +{
2006 +       const unsigned char *name = dentry->d_name.name;
2007 +       int len = dentry->d_name.len;
2008 +       struct inode *inode = NULL;
2009 +       struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2010 +       struct squashfs_super_block *sblk = &msblk->sblk;
2011 +       long long next_block = SQUASHFS_I(i)->start_block +
2012 +                               sblk->directory_table_start;
2013 +       int next_offset = SQUASHFS_I(i)->offset, length = 0,
2014 +                               dir_count;
2015 +       struct squashfs_dir_header dirh;
2016 +       char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
2017 +       struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
2018 +
2019 +       TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2020 +
2021 +       if (len > SQUASHFS_NAME_LEN)
2022 +               goto exit_loop;
2023 +
2024 +       length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2025 +                               SQUASHFS_I(i)->u.s2.directory_index_start,
2026 +                               SQUASHFS_I(i)->u.s2.directory_index_offset,
2027 +                               SQUASHFS_I(i)->u.s2.directory_index_count, name,
2028 +                               len);
2029 +
2030 +       while (length < i_size_read(i)) {
2031 +               /* read directory header */
2032 +               if (msblk->swap) {
2033 +                       struct squashfs_dir_header sdirh;
2034 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2035 +                                       next_block, next_offset, sizeof(sdirh),
2036 +                                       &next_block, &next_offset))
2037 +                               goto failed_read;
2038 +
2039 +                       length += sizeof(sdirh);
2040 +                       SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
2041 +               } else {
2042 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2043 +                                       next_block, next_offset, sizeof(dirh),
2044 +                                       &next_block, &next_offset))
2045 +                               goto failed_read;
2046 +
2047 +                       length += sizeof(dirh);
2048 +               }
2049 +
2050 +               dir_count = dirh.count + 1;
2051 +               while (dir_count--) {
2052 +                       if (msblk->swap) {
2053 +                               struct squashfs_dir_entry sdire;
2054 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2055 +                                               &sdire, next_block,next_offset,
2056 +                                               sizeof(sdire), &next_block,
2057 +                                               &next_offset))
2058 +                                       goto failed_read;
2059 +                               
2060 +                               length += sizeof(sdire);
2061 +                               SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
2062 +                       } else {
2063 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2064 +                                               dire, next_block,next_offset,
2065 +                                               sizeof(*dire), &next_block,
2066 +                                               &next_offset))
2067 +                                       goto failed_read;
2068 +
2069 +                               length += sizeof(*dire);
2070 +                       }
2071 +
2072 +                       if (!squashfs_get_cached_block(i->i_sb, dire->name,
2073 +                                       next_block, next_offset, dire->size + 1,
2074 +                                       &next_block, &next_offset))
2075 +                               goto failed_read;
2076 +
2077 +                       length += dire->size + 1;
2078 +
2079 +                       if (name[0] < dire->name[0])
2080 +                               goto exit_loop;
2081 +
2082 +                       if ((len == dire->size + 1) && !strncmp(name,
2083 +                                               dire->name, len)) {
2084 +                               squashfs_inode_t ino =
2085 +                                       SQUASHFS_MKINODE(dirh.start_block,
2086 +                                       dire->offset);
2087 +
2088 +                               TRACE("calling squashfs_iget for directory "
2089 +                                       "entry %s, inode %x:%x, %d\n", name,
2090 +                                       dirh.start_block, dire->offset,
2091 +                                       dirh.inode_number + dire->inode_number);
2092 +
2093 +                               inode = (msblk->iget)(i->i_sb, ino);
2094 +
2095 +                               goto exit_loop;
2096 +                       }
2097 +               }
2098 +       }
2099 +
2100 +exit_loop:
2101 +       d_add(dentry, inode);
2102 +       return ERR_PTR(0);
2103 +
2104 +failed_read:
2105 +       ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2106 +               next_offset);
2107 +       goto exit_loop;
2108 +}
2109 +
2110 +
2111 +static void squashfs_put_super(struct super_block *s)
2112 +{
2113 +       int i;
2114 +
2115 +       if (s->s_fs_info) {
2116 +               struct squashfs_sb_info *sbi = s->s_fs_info;
2117 +               if (sbi->block_cache)
2118 +                       for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
2119 +                               if (sbi->block_cache[i].block !=
2120 +                                                       SQUASHFS_INVALID_BLK)
2121 +                                       kfree(sbi->block_cache[i].data);
2122 +               if (sbi->fragment)
2123 +                       for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) 
2124 +                               SQUASHFS_FREE(sbi->fragment[i].data);
2125 +               kfree(sbi->fragment);
2126 +               kfree(sbi->block_cache);
2127 +               kfree(sbi->read_data);
2128 +               kfree(sbi->read_page);
2129 +               kfree(sbi->uid);
2130 +               kfree(sbi->fragment_index);
2131 +               kfree(sbi->fragment_index_2);
2132 +               kfree(sbi->meta_index);
2133 +               kfree(s->s_fs_info);
2134 +               s->s_fs_info = NULL;
2135 +       }
2136 +}
2137 +
2138 +
2139 +static struct super_block *squashfs_get_sb(struct file_system_type *fs_type,
2140 +                               int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2141 +{
2142 +       return get_sb_bdev(fs_type, flags, dev_name, data, squashfs_fill_super, mnt);
2143 +}
2144 +
2145 +
2146 +static int __init init_squashfs_fs(void)
2147 +{
2148 +       int err = init_inodecache();
2149 +       if (err)
2150 +               goto out;
2151 +
2152 +       printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
2153 +               "Phillip Lougher\n");
2154 +
2155 +       if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
2156 +               ERROR("Failed to allocate zlib workspace\n");
2157 +               destroy_inodecache();
2158 +               err = -ENOMEM;
2159 +               goto out;
2160 +       }
2161 +
2162 +       if ((err = register_filesystem(&squashfs_fs_type))) {
2163 +               vfree(stream.workspace);
2164 +               destroy_inodecache();
2165 +       }
2166 +
2167 +out:
2168 +       return err;
2169 +}
2170 +
2171 +
2172 +static void __exit exit_squashfs_fs(void)
2173 +{
2174 +       vfree(stream.workspace);
2175 +       unregister_filesystem(&squashfs_fs_type);
2176 +       destroy_inodecache();
2177 +}
2178 +
2179 +
2180 +static kmem_cache_t * squashfs_inode_cachep;
2181 +
2182 +
2183 +static struct inode *squashfs_alloc_inode(struct super_block *sb)
2184 +{
2185 +       struct squashfs_inode_info *ei;
2186 +       ei = kmem_cache_alloc(squashfs_inode_cachep, SLAB_KERNEL);
2187 +       if (!ei)
2188 +               return NULL;
2189 +       return &ei->vfs_inode;
2190 +}
2191 +
2192 +
2193 +static void squashfs_destroy_inode(struct inode *inode)
2194 +{
2195 +       kmem_cache_free(squashfs_inode_cachep, SQUASHFS_I(inode));
2196 +}
2197 +
2198 +
2199 +static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
2200 +{
2201 +       struct squashfs_inode_info *ei = foo;
2202 +
2203 +       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
2204 +                                                       SLAB_CTOR_CONSTRUCTOR)
2205 +               inode_init_once(&ei->vfs_inode);
2206 +}
2207
2208 +
2209 +static int __init init_inodecache(void)
2210 +{
2211 +       squashfs_inode_cachep = kmem_cache_create("squashfs_inode_cache",
2212 +            sizeof(struct squashfs_inode_info),
2213 +            0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
2214 +            init_once, NULL);
2215 +       if (squashfs_inode_cachep == NULL)
2216 +               return -ENOMEM;
2217 +       return 0;
2218 +}
2219 +
2220 +
2221 +static void destroy_inodecache(void)
2222 +{
2223 +       if (kmem_cache_destroy(squashfs_inode_cachep))
2224 +               printk(KERN_INFO "squashfs_inode_cache: not all structures "
2225 +                       "were freed\n");
2226 +}
2227 +
2228 +
2229 +module_init(init_squashfs_fs);
2230 +module_exit(exit_squashfs_fs);
2231 +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
2232 +MODULE_AUTHOR("Phillip Lougher <phillip@lougher.org.uk>");
2233 Index: linux-2.6.18/fs/squashfs/Makefile
2234 ===================================================================
2235 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
2236 +++ linux-2.6.18/fs/squashfs/Makefile   2006-09-20 15:45:15.000000000 +0100
2237 @@ -0,0 +1,7 @@
2238 +#
2239 +# Makefile for the linux squashfs routines.
2240 +#
2241 +
2242 +obj-$(CONFIG_SQUASHFS) += squashfs.o
2243 +squashfs-y += inode.o
2244 +squashfs-y += squashfs2_0.o
2245 Index: linux-2.6.18/fs/squashfs/squashfs2_0.c
2246 ===================================================================
2247 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
2248 +++ linux-2.6.18/fs/squashfs/squashfs2_0.c      2006-09-20 15:45:15.000000000 +0100
2249 @@ -0,0 +1,758 @@
2250 +/*
2251 + * Squashfs - a compressed read only filesystem for Linux
2252 + *
2253 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
2254 + * Phillip Lougher <phillip@lougher.org.uk>
2255 + *
2256 + * This program is free software; you can redistribute it and/or
2257 + * modify it under the terms of the GNU General Public License
2258 + * as published by the Free Software Foundation; either version 2,
2259 + * or (at your option) any later version.
2260 + *
2261 + * This program is distributed in the hope that it will be useful,
2262 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2263 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2264 + * GNU General Public License for more details.
2265 + *
2266 + * You should have received a copy of the GNU General Public License
2267 + * along with this program; if not, write to the Free Software
2268 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2269 + *
2270 + * squashfs2_0.c
2271 + */
2272 +
2273 +#include <linux/types.h>
2274 +#include <linux/squashfs_fs.h>
2275 +#include <linux/module.h>
2276 +#include <linux/errno.h>
2277 +#include <linux/slab.h>
2278 +#include <linux/fs.h>
2279 +#include <linux/smp_lock.h>
2280 +#include <linux/slab.h>
2281 +#include <linux/squashfs_fs_sb.h>
2282 +#include <linux/squashfs_fs_i.h>
2283 +#include <linux/buffer_head.h>
2284 +#include <linux/vfs.h>
2285 +#include <linux/init.h>
2286 +#include <linux/dcache.h>
2287 +#include <linux/wait.h>
2288 +#include <linux/zlib.h>
2289 +#include <linux/blkdev.h>
2290 +#include <linux/vmalloc.h>
2291 +#include <asm/uaccess.h>
2292 +#include <asm/semaphore.h>
2293 +
2294 +#include "squashfs.h"
2295 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
2296 +static struct dentry *squashfs_lookup_2(struct inode *, struct dentry *,
2297 +                               struct nameidata *);
2298 +
2299 +static struct file_operations squashfs_dir_ops_2 = {
2300 +       .read = generic_read_dir,
2301 +       .readdir = squashfs_readdir_2
2302 +};
2303 +
2304 +static struct inode_operations squashfs_dir_inode_ops_2 = {
2305 +       .lookup = squashfs_lookup_2
2306 +};
2307 +
2308 +static unsigned char squashfs_filetype_table[] = {
2309 +       DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
2310 +};
2311 +
2312 +static int read_fragment_index_table_2(struct super_block *s)
2313 +{
2314 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2315 +       struct squashfs_super_block *sblk = &msblk->sblk;
2316 +
2317 +       if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
2318 +                                       (sblk->fragments), GFP_KERNEL))) {
2319 +               ERROR("Failed to allocate uid/gid table\n");
2320 +               return 0;
2321 +       }
2322 +   
2323 +       if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
2324 +                                       !squashfs_read_data(s, (char *)
2325 +                                       msblk->fragment_index_2,
2326 +                                       sblk->fragment_table_start,
2327 +                                       SQUASHFS_FRAGMENT_INDEX_BYTES_2
2328 +                                       (sblk->fragments) |
2329 +                                       SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
2330 +               ERROR("unable to read fragment index table\n");
2331 +               return 0;
2332 +       }
2333 +
2334 +       if (msblk->swap) {
2335 +               int i;
2336 +               unsigned int fragment;
2337 +
2338 +               for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
2339 +                                                                       i++) {
2340 +                       SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
2341 +                                               &msblk->fragment_index_2[i], 1);
2342 +                       msblk->fragment_index_2[i] = fragment;
2343 +               }
2344 +       }
2345 +
2346 +       return 1;
2347 +}
2348 +
2349 +
2350 +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
2351 +                               long long *fragment_start_block,
2352 +                               unsigned int *fragment_size)
2353 +{
2354 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2355 +       long long start_block =
2356 +               msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
2357 +       int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
2358 +       struct squashfs_fragment_entry_2 fragment_entry;
2359 +
2360 +       if (msblk->swap) {
2361 +               struct squashfs_fragment_entry_2 sfragment_entry;
2362 +
2363 +               if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
2364 +                                       start_block, offset,
2365 +                                       sizeof(sfragment_entry), &start_block,
2366 +                                       &offset))
2367 +                       goto out;
2368 +               SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
2369 +       } else
2370 +               if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
2371 +                                       start_block, offset,
2372 +                                       sizeof(fragment_entry), &start_block,
2373 +                                       &offset))
2374 +                       goto out;
2375 +
2376 +       *fragment_start_block = fragment_entry.start_block;
2377 +       *fragment_size = fragment_entry.size;
2378 +
2379 +       return 1;
2380 +
2381 +out:
2382 +       return 0;
2383 +}
2384 +
2385 +
2386 +static struct inode *squashfs_new_inode(struct super_block *s,
2387 +               struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
2388 +{
2389 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2390 +       struct squashfs_super_block *sblk = &msblk->sblk;
2391 +       struct inode *i = new_inode(s);
2392 +
2393 +       if (i) {
2394 +               i->i_ino = ino;
2395 +               i->i_mtime.tv_sec = sblk->mkfs_time;
2396 +               i->i_atime.tv_sec = sblk->mkfs_time;
2397 +               i->i_ctime.tv_sec = sblk->mkfs_time;
2398 +               i->i_uid = msblk->uid[inodeb->uid];
2399 +               i->i_mode = inodeb->mode;
2400 +               i->i_nlink = 1;
2401 +               i->i_size = 0;
2402 +               if (inodeb->guid == SQUASHFS_GUIDS)
2403 +                       i->i_gid = i->i_uid;
2404 +               else
2405 +                       i->i_gid = msblk->guid[inodeb->guid];
2406 +       }
2407 +
2408 +       return i;
2409 +}
2410 +
2411 +
2412 +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
2413 +{
2414 +       struct inode *i;
2415 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2416 +       struct squashfs_super_block *sblk = &msblk->sblk;
2417 +       unsigned int block = SQUASHFS_INODE_BLK(inode) +
2418 +               sblk->inode_table_start;
2419 +       unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
2420 +       unsigned int ino = SQUASHFS_MK_VFS_INODE(block
2421 +               - sblk->inode_table_start, offset);
2422 +       long long next_block;
2423 +       unsigned int next_offset;
2424 +       union squashfs_inode_header_2 id, sid;
2425 +       struct squashfs_base_inode_header_2 *inodeb = &id.base,
2426 +                                         *sinodeb = &sid.base;
2427 +
2428 +       TRACE("Entered squashfs_iget\n");
2429 +
2430 +       if (msblk->swap) {
2431 +               if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
2432 +                                       offset, sizeof(*sinodeb), &next_block,
2433 +                                       &next_offset))
2434 +                       goto failed_read;
2435 +               SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
2436 +                                       sizeof(*sinodeb));
2437 +       } else
2438 +               if (!squashfs_get_cached_block(s, (char *) inodeb, block,
2439 +                                       offset, sizeof(*inodeb), &next_block,
2440 +                                       &next_offset))
2441 +                       goto failed_read;
2442 +
2443 +       switch(inodeb->inode_type) {
2444 +               case SQUASHFS_FILE_TYPE: {
2445 +                       struct squashfs_reg_inode_header_2 *inodep = &id.reg;
2446 +                       struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
2447 +                       long long frag_blk;
2448 +                       unsigned int frag_size;
2449 +                               
2450 +                       if (msblk->swap) {
2451 +                               if (!squashfs_get_cached_block(s, (char *)
2452 +                                               sinodep, block, offset,
2453 +                                               sizeof(*sinodep), &next_block,
2454 +                                               &next_offset))
2455 +                                       goto failed_read;
2456 +                               SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
2457 +                       } else
2458 +                               if (!squashfs_get_cached_block(s, (char *)
2459 +                                               inodep, block, offset,
2460 +                                               sizeof(*inodep), &next_block,
2461 +                                               &next_offset))
2462 +                                       goto failed_read;
2463 +
2464 +                       frag_blk = SQUASHFS_INVALID_BLK;
2465 +                       if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
2466 +                                       !get_fragment_location_2(s,
2467 +                                       inodep->fragment, &frag_blk, &frag_size))
2468 +                               goto failed_read;
2469 +                               
2470 +                       if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2471 +                               goto failed_read1;
2472 +
2473 +                       i->i_size = inodep->file_size;
2474 +                       i->i_fop = &generic_ro_fops;
2475 +                       i->i_mode |= S_IFREG;
2476 +                       i->i_mtime.tv_sec = inodep->mtime;
2477 +                       i->i_atime.tv_sec = inodep->mtime;
2478 +                       i->i_ctime.tv_sec = inodep->mtime;
2479 +                       i->i_blocks = ((i->i_size - 1) >> 9) + 1;
2480 +                       i->i_blksize = PAGE_CACHE_SIZE;
2481 +                       SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
2482 +                       SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
2483 +                       SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
2484 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
2485 +                       SQUASHFS_I(i)->u.s1.block_list_start = next_block;
2486 +                       SQUASHFS_I(i)->offset = next_offset;
2487 +                       if (sblk->block_size > 4096)
2488 +                               i->i_data.a_ops = &squashfs_aops;
2489 +                       else
2490 +                               i->i_data.a_ops = &squashfs_aops_4K;
2491 +
2492 +                       TRACE("File inode %x:%x, start_block %x, "
2493 +                                       "block_list_start %llx, offset %x\n",
2494 +                                       SQUASHFS_INODE_BLK(inode), offset,
2495 +                                       inodep->start_block, next_block,
2496 +                                       next_offset);
2497 +                       break;
2498 +               }
2499 +               case SQUASHFS_DIR_TYPE: {
2500 +                       struct squashfs_dir_inode_header_2 *inodep = &id.dir;
2501 +                       struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
2502 +
2503 +                       if (msblk->swap) {
2504 +                               if (!squashfs_get_cached_block(s, (char *)
2505 +                                               sinodep, block, offset,
2506 +                                               sizeof(*sinodep), &next_block,
2507 +                                               &next_offset))
2508 +                                       goto failed_read;
2509 +                               SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
2510 +                       } else
2511 +                               if (!squashfs_get_cached_block(s, (char *)
2512 +                                               inodep, block, offset,
2513 +                                               sizeof(*inodep), &next_block,
2514 +                                               &next_offset))
2515 +                                       goto failed_read;
2516 +
2517 +                       if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2518 +                               goto failed_read1;
2519 +
2520 +                       i->i_size = inodep->file_size;
2521 +                       i->i_op = &squashfs_dir_inode_ops_2;
2522 +                       i->i_fop = &squashfs_dir_ops_2;
2523 +                       i->i_mode |= S_IFDIR;
2524 +                       i->i_mtime.tv_sec = inodep->mtime;
2525 +                       i->i_atime.tv_sec = inodep->mtime;
2526 +                       i->i_ctime.tv_sec = inodep->mtime;
2527 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
2528 +                       SQUASHFS_I(i)->offset = inodep->offset;
2529 +                       SQUASHFS_I(i)->u.s2.directory_index_count = 0;
2530 +                       SQUASHFS_I(i)->u.s2.parent_inode = 0;
2531 +
2532 +                       TRACE("Directory inode %x:%x, start_block %x, offset "
2533 +                                       "%x\n", SQUASHFS_INODE_BLK(inode),
2534 +                                       offset, inodep->start_block,
2535 +                                       inodep->offset);
2536 +                       break;
2537 +               }
2538 +               case SQUASHFS_LDIR_TYPE: {
2539 +                       struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
2540 +                       struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
2541 +
2542 +                       if (msblk->swap) {
2543 +                               if (!squashfs_get_cached_block(s, (char *)
2544 +                                               sinodep, block, offset,
2545 +                                               sizeof(*sinodep), &next_block,
2546 +                                               &next_offset))
2547 +                                       goto failed_read;
2548 +                               SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
2549 +                                               sinodep);
2550 +                       } else
2551 +                               if (!squashfs_get_cached_block(s, (char *)
2552 +                                               inodep, block, offset,
2553 +                                               sizeof(*inodep), &next_block,
2554 +                                               &next_offset))
2555 +                                       goto failed_read;
2556 +
2557 +                       if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2558 +                               goto failed_read1;
2559 +
2560 +                       i->i_size = inodep->file_size;
2561 +                       i->i_op = &squashfs_dir_inode_ops_2;
2562 +                       i->i_fop = &squashfs_dir_ops_2;
2563 +                       i->i_mode |= S_IFDIR;
2564 +                       i->i_mtime.tv_sec = inodep->mtime;
2565 +                       i->i_atime.tv_sec = inodep->mtime;
2566 +                       i->i_ctime.tv_sec = inodep->mtime;
2567 +                       SQUASHFS_I(i)->start_block = inodep->start_block;
2568 +                       SQUASHFS_I(i)->offset = inodep->offset;
2569 +                       SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
2570 +                       SQUASHFS_I(i)->u.s2.directory_index_offset =
2571 +                                                               next_offset;
2572 +                       SQUASHFS_I(i)->u.s2.directory_index_count =
2573 +                                                               inodep->i_count;
2574 +                       SQUASHFS_I(i)->u.s2.parent_inode = 0;
2575 +
2576 +                       TRACE("Long directory inode %x:%x, start_block %x, "
2577 +                                       "offset %x\n",
2578 +                                       SQUASHFS_INODE_BLK(inode), offset,
2579 +                                       inodep->start_block, inodep->offset);
2580 +                       break;
2581 +               }
2582 +               case SQUASHFS_SYMLINK_TYPE: {
2583 +                       struct squashfs_symlink_inode_header_2 *inodep =
2584 +                                                               &id.symlink;
2585 +                       struct squashfs_symlink_inode_header_2 *sinodep =
2586 +                                                               &sid.symlink;
2587 +       
2588 +                       if (msblk->swap) {
2589 +                               if (!squashfs_get_cached_block(s, (char *)
2590 +                                               sinodep, block, offset,
2591 +                                               sizeof(*sinodep), &next_block,
2592 +                                               &next_offset))
2593 +                                       goto failed_read;
2594 +                               SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
2595 +                                                               sinodep);
2596 +                       } else
2597 +                               if (!squashfs_get_cached_block(s, (char *)
2598 +                                               inodep, block, offset,
2599 +                                               sizeof(*inodep), &next_block,
2600 +                                               &next_offset))
2601 +                                       goto failed_read;
2602 +
2603 +                       if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2604 +                               goto failed_read1;
2605 +
2606 +                       i->i_size = inodep->symlink_size;
2607 +                       i->i_op = &page_symlink_inode_operations;
2608 +                       i->i_data.a_ops = &squashfs_symlink_aops;
2609 +                       i->i_mode |= S_IFLNK;
2610 +                       SQUASHFS_I(i)->start_block = next_block;
2611 +                       SQUASHFS_I(i)->offset = next_offset;
2612 +
2613 +                       TRACE("Symbolic link inode %x:%x, start_block %llx, "
2614 +                                       "offset %x\n",
2615 +                                       SQUASHFS_INODE_BLK(inode), offset,
2616 +                                       next_block, next_offset);
2617 +                       break;
2618 +                }
2619 +                case SQUASHFS_BLKDEV_TYPE:
2620 +                case SQUASHFS_CHRDEV_TYPE: {
2621 +                       struct squashfs_dev_inode_header_2 *inodep = &id.dev;
2622 +                       struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
2623 +
2624 +                       if (msblk->swap) {
2625 +                               if (!squashfs_get_cached_block(s, (char *)
2626 +                                               sinodep, block, offset,
2627 +                                               sizeof(*sinodep), &next_block,
2628 +                                               &next_offset))
2629 +                                       goto failed_read;
2630 +                               SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
2631 +                       } else  
2632 +                               if (!squashfs_get_cached_block(s, (char *)
2633 +                                               inodep, block, offset,
2634 +                                               sizeof(*inodep), &next_block,
2635 +                                               &next_offset))
2636 +                                       goto failed_read;
2637 +
2638 +                       if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2639 +                               goto failed_read1;
2640 +
2641 +                       i->i_mode |= (inodeb->inode_type ==
2642 +                                       SQUASHFS_CHRDEV_TYPE) ?  S_IFCHR :
2643 +                                       S_IFBLK;
2644 +                       init_special_inode(i, i->i_mode,
2645 +                                       old_decode_dev(inodep->rdev));
2646 +
2647 +                       TRACE("Device inode %x:%x, rdev %x\n",
2648 +                                       SQUASHFS_INODE_BLK(inode), offset,
2649 +                                       inodep->rdev);
2650 +                       break;
2651 +                }
2652 +                case SQUASHFS_FIFO_TYPE:
2653 +                case SQUASHFS_SOCKET_TYPE: {
2654 +                       if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
2655 +                               goto failed_read1;
2656 +
2657 +                       i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
2658 +                                                       ? S_IFIFO : S_IFSOCK;
2659 +                       init_special_inode(i, i->i_mode, 0);
2660 +                       break;
2661 +                }
2662 +                default:
2663 +                       ERROR("Unknown inode type %d in squashfs_iget!\n",
2664 +                                       inodeb->inode_type);
2665 +                       goto failed_read1;
2666 +       }
2667 +       
2668 +       insert_inode_hash(i);
2669 +       return i;
2670 +
2671 +failed_read:
2672 +       ERROR("Unable to read inode [%x:%x]\n", block, offset);
2673 +
2674 +failed_read1:
2675 +       return NULL;
2676 +}
2677 +
2678 +
2679 +static int get_dir_index_using_offset(struct super_block *s, long long 
2680 +                               *next_block, unsigned int *next_offset,
2681 +                               long long index_start,
2682 +                               unsigned int index_offset, int i_count,
2683 +                               long long f_pos)
2684 +{
2685 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2686 +       struct squashfs_super_block *sblk = &msblk->sblk;
2687 +       int i, length = 0;
2688 +       struct squashfs_dir_index_2 index;
2689 +
2690 +       TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
2691 +                                       i_count, (unsigned int) f_pos);
2692 +
2693 +       if (f_pos == 0)
2694 +               goto finish;
2695 +
2696 +       for (i = 0; i < i_count; i++) {
2697 +               if (msblk->swap) {
2698 +                       struct squashfs_dir_index_2 sindex;
2699 +                       squashfs_get_cached_block(s, (char *) &sindex,
2700 +                                       index_start, index_offset,
2701 +                                       sizeof(sindex), &index_start,
2702 +                                       &index_offset);
2703 +                       SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
2704 +               } else
2705 +                       squashfs_get_cached_block(s, (char *) &index,
2706 +                                       index_start, index_offset,
2707 +                                       sizeof(index), &index_start,
2708 +                                       &index_offset);
2709 +
2710 +               if (index.index > f_pos)
2711 +                       break;
2712 +
2713 +               squashfs_get_cached_block(s, NULL, index_start, index_offset,
2714 +                                       index.size + 1, &index_start,
2715 +                                       &index_offset);
2716 +
2717 +               length = index.index;
2718 +               *next_block = index.start_block + sblk->directory_table_start;
2719 +       }
2720 +
2721 +       *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2722 +
2723 +finish:
2724 +       return length;
2725 +}
2726 +
2727 +
2728 +static int get_dir_index_using_name(struct super_block *s, long long
2729 +                               *next_block, unsigned int *next_offset,
2730 +                               long long index_start,
2731 +                               unsigned int index_offset, int i_count,
2732 +                               const char *name, int size)
2733 +{
2734 +       struct squashfs_sb_info *msblk = s->s_fs_info;
2735 +       struct squashfs_super_block *sblk = &msblk->sblk;
2736 +       int i, length = 0;
2737 +       char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
2738 +       struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
2739 +       char str[SQUASHFS_NAME_LEN + 1];
2740 +
2741 +       TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
2742 +
2743 +       strncpy(str, name, size);
2744 +       str[size] = '\0';
2745 +
2746 +       for (i = 0; i < i_count; i++) {
2747 +               if (msblk->swap) {
2748 +                       struct squashfs_dir_index_2 sindex;
2749 +                       squashfs_get_cached_block(s, (char *) &sindex,
2750 +                                       index_start, index_offset,
2751 +                                       sizeof(sindex), &index_start,
2752 +                                       &index_offset);
2753 +                       SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
2754 +               } else
2755 +                       squashfs_get_cached_block(s, (char *) index,
2756 +                                       index_start, index_offset,
2757 +                                       sizeof(struct squashfs_dir_index_2),
2758 +                                       &index_start, &index_offset);
2759 +
2760 +               squashfs_get_cached_block(s, index->name, index_start,
2761 +                                       index_offset, index->size + 1,
2762 +                                       &index_start, &index_offset);
2763 +
2764 +               index->name[index->size + 1] = '\0';
2765 +
2766 +               if (strcmp(index->name, str) > 0)
2767 +                       break;
2768 +
2769 +               length = index->index;
2770 +               *next_block = index->start_block + sblk->directory_table_start;
2771 +       }
2772 +
2773 +       *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
2774 +       return length;
2775 +}
2776 +
2777 +               
2778 +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
2779 +{
2780 +       struct inode *i = file->f_dentry->d_inode;
2781 +       struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2782 +       struct squashfs_super_block *sblk = &msblk->sblk;
2783 +       long long next_block = SQUASHFS_I(i)->start_block +
2784 +               sblk->directory_table_start;
2785 +       int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
2786 +               dir_count;
2787 +       struct squashfs_dir_header_2 dirh;
2788 +       char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
2789 +       struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2790 +
2791 +       TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
2792 +
2793 +       length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
2794 +                               SQUASHFS_I(i)->u.s2.directory_index_start,
2795 +                               SQUASHFS_I(i)->u.s2.directory_index_offset,
2796 +                               SQUASHFS_I(i)->u.s2.directory_index_count,
2797 +                               file->f_pos);
2798 +
2799 +       while (length < i_size_read(i)) {
2800 +               /* read directory header */
2801 +               if (msblk->swap) {
2802 +                       struct squashfs_dir_header_2 sdirh;
2803 +                       
2804 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2805 +                                       next_block, next_offset, sizeof(sdirh),
2806 +                                       &next_block, &next_offset))
2807 +                               goto failed_read;
2808 +
2809 +                       length += sizeof(sdirh);
2810 +                       SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2811 +               } else {
2812 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2813 +                                       next_block, next_offset, sizeof(dirh),
2814 +                                       &next_block, &next_offset))
2815 +                               goto failed_read;
2816 +
2817 +                       length += sizeof(dirh);
2818 +               }
2819 +
2820 +               dir_count = dirh.count + 1;
2821 +               while (dir_count--) {
2822 +                       if (msblk->swap) {
2823 +                               struct squashfs_dir_entry_2 sdire;
2824 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2825 +                                               &sdire, next_block, next_offset,
2826 +                                               sizeof(sdire), &next_block,
2827 +                                               &next_offset))
2828 +                                       goto failed_read;
2829 +                               
2830 +                               length += sizeof(sdire);
2831 +                               SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2832 +                       } else {
2833 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2834 +                                               dire, next_block, next_offset,
2835 +                                               sizeof(*dire), &next_block,
2836 +                                               &next_offset))
2837 +                                       goto failed_read;
2838 +
2839 +                               length += sizeof(*dire);
2840 +                       }
2841 +
2842 +                       if (!squashfs_get_cached_block(i->i_sb, dire->name,
2843 +                                               next_block, next_offset,
2844 +                                               dire->size + 1, &next_block,
2845 +                                               &next_offset))
2846 +                               goto failed_read;
2847 +
2848 +                       length += dire->size + 1;
2849 +
2850 +                       if (file->f_pos >= length)
2851 +                               continue;
2852 +
2853 +                       dire->name[dire->size + 1] = '\0';
2854 +
2855 +                       TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
2856 +                                       (unsigned int) dirent, dire->name,
2857 +                                       dire->size + 1, (int) file->f_pos,
2858 +                                       dirh.start_block, dire->offset,
2859 +                                       squashfs_filetype_table[dire->type]);
2860 +
2861 +                       if (filldir(dirent, dire->name, dire->size + 1,
2862 +                                       file->f_pos, SQUASHFS_MK_VFS_INODE(
2863 +                                       dirh.start_block, dire->offset),
2864 +                                       squashfs_filetype_table[dire->type])
2865 +                                       < 0) {
2866 +                               TRACE("Filldir returned less than 0\n");
2867 +                               goto finish;
2868 +                       }
2869 +                       file->f_pos = length;
2870 +                       dirs_read++;
2871 +               }
2872 +       }
2873 +
2874 +finish:
2875 +       return dirs_read;
2876 +
2877 +failed_read:
2878 +       ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2879 +               next_offset);
2880 +       return 0;
2881 +}
2882 +
2883 +
2884 +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry,
2885 +                               struct nameidata *nd)
2886 +{
2887 +       const unsigned char *name = dentry->d_name.name;
2888 +       int len = dentry->d_name.len;
2889 +       struct inode *inode = NULL;
2890 +       struct squashfs_sb_info *msblk = i->i_sb->s_fs_info;
2891 +       struct squashfs_super_block *sblk = &msblk->sblk;
2892 +       long long next_block = SQUASHFS_I(i)->start_block +
2893 +                               sblk->directory_table_start;
2894 +       int next_offset = SQUASHFS_I(i)->offset, length = 0,
2895 +                               dir_count;
2896 +       struct squashfs_dir_header_2 dirh;
2897 +       char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
2898 +       struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
2899 +       int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
2900 +
2901 +       TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
2902 +
2903 +       if (len > SQUASHFS_NAME_LEN)
2904 +               goto exit_loop;
2905 +
2906 +       length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
2907 +                               SQUASHFS_I(i)->u.s2.directory_index_start,
2908 +                               SQUASHFS_I(i)->u.s2.directory_index_offset,
2909 +                               SQUASHFS_I(i)->u.s2.directory_index_count, name,
2910 +                               len);
2911 +
2912 +       while (length < i_size_read(i)) {
2913 +               /* read directory header */
2914 +               if (msblk->swap) {
2915 +                       struct squashfs_dir_header_2 sdirh;
2916 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
2917 +                                       next_block, next_offset, sizeof(sdirh),
2918 +                                       &next_block, &next_offset))
2919 +                               goto failed_read;
2920 +
2921 +                       length += sizeof(sdirh);
2922 +                       SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
2923 +               } else {
2924 +                       if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
2925 +                                       next_block, next_offset, sizeof(dirh),
2926 +                                       &next_block, &next_offset))
2927 +                               goto failed_read;
2928 +
2929 +                       length += sizeof(dirh);
2930 +               }
2931 +
2932 +               dir_count = dirh.count + 1;
2933 +               while (dir_count--) {
2934 +                       if (msblk->swap) {
2935 +                               struct squashfs_dir_entry_2 sdire;
2936 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2937 +                                               &sdire, next_block,next_offset,
2938 +                                               sizeof(sdire), &next_block,
2939 +                                               &next_offset))
2940 +                                       goto failed_read;
2941 +                               
2942 +                               length += sizeof(sdire);
2943 +                               SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
2944 +                       } else {
2945 +                               if (!squashfs_get_cached_block(i->i_sb, (char *)
2946 +                                               dire, next_block,next_offset,
2947 +                                               sizeof(*dire), &next_block,
2948 +                                               &next_offset))
2949 +                                       goto failed_read;
2950 +
2951 +                               length += sizeof(*dire);
2952 +                       }
2953 +
2954 +                       if (!squashfs_get_cached_block(i->i_sb, dire->name,
2955 +                                       next_block, next_offset, dire->size + 1,
2956 +                                       &next_block, &next_offset))
2957 +                               goto failed_read;
2958 +
2959 +                       length += dire->size + 1;
2960 +
2961 +                       if (sorted && name[0] < dire->name[0])
2962 +                               goto exit_loop;
2963 +
2964 +                       if ((len == dire->size + 1) && !strncmp(name,
2965 +                                               dire->name, len)) {
2966 +                               squashfs_inode_t ino =
2967 +                                       SQUASHFS_MKINODE(dirh.start_block,
2968 +                                       dire->offset);
2969 +
2970 +                               TRACE("calling squashfs_iget for directory "
2971 +                                       "entry %s, inode %x:%x, %lld\n", name,
2972 +                                       dirh.start_block, dire->offset, ino);
2973 +
2974 +                               inode = (msblk->iget)(i->i_sb, ino);
2975 +
2976 +                               goto exit_loop;
2977 +                       }
2978 +               }
2979 +       }
2980 +
2981 +exit_loop:
2982 +       d_add(dentry, inode);
2983 +       return ERR_PTR(0);
2984 +
2985 +failed_read:
2986 +       ERROR("Unable to read directory block [%llx:%x]\n", next_block,
2987 +               next_offset);
2988 +       goto exit_loop;
2989 +}
2990 +
2991 +
2992 +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
2993 +{
2994 +       struct squashfs_super_block *sblk = &msblk->sblk;
2995 +
2996 +       msblk->iget = squashfs_iget_2;
2997 +       msblk->read_fragment_index_table = read_fragment_index_table_2;
2998 +
2999 +       sblk->bytes_used = sblk->bytes_used_2;
3000 +       sblk->uid_start = sblk->uid_start_2;
3001 +       sblk->guid_start = sblk->guid_start_2;
3002 +       sblk->inode_table_start = sblk->inode_table_start_2;
3003 +       sblk->directory_table_start = sblk->directory_table_start_2;
3004 +       sblk->fragment_table_start = sblk->fragment_table_start_2;
3005 +
3006 +       return 1;
3007 +}
3008 Index: linux-2.6.18/fs/squashfs/squashfs.h
3009 ===================================================================
3010 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
3011 +++ linux-2.6.18/fs/squashfs/squashfs.h 2006-09-20 15:45:15.000000000 +0100
3012 @@ -0,0 +1,86 @@
3013 +/*
3014 + * Squashfs - a compressed read only filesystem for Linux
3015 + *
3016 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3017 + * Phillip Lougher <phillip@lougher.org.uk>
3018 + *
3019 + * This program is free software; you can redistribute it and/or
3020 + * modify it under the terms of the GNU General Public License
3021 + * as published by the Free Software Foundation; either version 2,
3022 + * or (at your option) any later version.
3023 + *
3024 + * This program is distributed in the hope that it will be useful,
3025 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3026 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3027 + * GNU General Public License for more details.
3028 + *
3029 + * You should have received a copy of the GNU General Public License
3030 + * along with this program; if not, write to the Free Software
3031 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3032 + *
3033 + * squashfs.h
3034 + */
3035 +
3036 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3037 +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3038 +#endif
3039 +
3040 +#ifdef SQUASHFS_TRACE
3041 +#define TRACE(s, args...)      printk(KERN_NOTICE "SQUASHFS: "s, ## args)
3042 +#else
3043 +#define TRACE(s, args...)      {}
3044 +#endif
3045 +
3046 +#define ERROR(s, args...)      printk(KERN_ERR "SQUASHFS error: "s, ## args)
3047 +
3048 +#define SERROR(s, args...)     do { \
3049 +                               if (!silent) \
3050 +                               printk(KERN_ERR "SQUASHFS error: "s, ## args);\
3051 +                               } while(0)
3052 +
3053 +#define WARNING(s, args...)    printk(KERN_WARNING "SQUASHFS: "s, ## args)
3054 +
3055 +static inline struct squashfs_inode_info *SQUASHFS_I(struct inode *inode)
3056 +{
3057 +       return list_entry(inode, struct squashfs_inode_info, vfs_inode);
3058 +}
3059 +
3060 +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
3061 +#define SQSH_EXTERN
3062 +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
3063 +                               long long index, unsigned int length,
3064 +                               long long *next_index);
3065 +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
3066 +                               long long block, unsigned int offset,
3067 +                               int length, long long *next_block,
3068 +                               unsigned int *next_offset);
3069 +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
3070 +                                       squashfs_fragment_cache *fragment);
3071 +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
3072 +                                       *s, long long start_block,
3073 +                                       int length);
3074 +extern struct address_space_operations squashfs_symlink_aops;
3075 +extern struct address_space_operations squashfs_aops;
3076 +extern struct address_space_operations squashfs_aops_4K;
3077 +extern struct inode_operations squashfs_dir_inode_ops;
3078 +#else
3079 +#define SQSH_EXTERN static
3080 +#endif
3081 +
3082 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3083 +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
3084 +#else
3085 +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
3086 +{
3087 +       return 0;
3088 +}
3089 +#endif
3090 +
3091 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3092 +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
3093 +#else
3094 +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
3095 +{
3096 +       return 0;
3097 +}
3098 +#endif
3099 Index: linux-2.6.18/include/linux/squashfs_fs.h
3100 ===================================================================
3101 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
3102 +++ linux-2.6.18/include/linux/squashfs_fs.h    2006-09-20 15:45:15.000000000 +0100
3103 @@ -0,0 +1,911 @@
3104 +#ifndef SQUASHFS_FS
3105 +#define SQUASHFS_FS
3106 +
3107 +/*
3108 + * Squashfs
3109 + *
3110 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
3111 + * Phillip Lougher <phillip@lougher.org.uk>
3112 + *
3113 + * This program is free software; you can redistribute it and/or
3114 + * modify it under the terms of the GNU General Public License
3115 + * as published by the Free Software Foundation; either version 2,
3116 + * or (at your option) any later version.
3117 + *
3118 + * This program is distributed in the hope that it will be useful,
3119 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3120 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3121 + * GNU General Public License for more details.
3122 + *
3123 + * You should have received a copy of the GNU General Public License
3124 + * along with this program; if not, write to the Free Software
3125 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3126 + *
3127 + * squashfs_fs.h
3128 + */
3129 +
3130 +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3131 +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
3132 +#endif
3133 +
3134 +#ifdef CONFIG_SQUASHFS_VMALLOC
3135 +#define SQUASHFS_ALLOC(a)              vmalloc(a)
3136 +#define SQUASHFS_FREE(a)               vfree(a)
3137 +#else
3138 +#define SQUASHFS_ALLOC(a)              kmalloc(a, GFP_KERNEL)
3139 +#define SQUASHFS_FREE(a)               kfree(a)
3140 +#endif
3141 +#define SQUASHFS_CACHED_FRAGMENTS      CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE     
3142 +#define SQUASHFS_MAJOR                 3
3143 +#define SQUASHFS_MINOR                 0
3144 +#define SQUASHFS_MAGIC                 0x73717368
3145 +#define SQUASHFS_MAGIC_SWAP            0x68737173
3146 +#define SQUASHFS_START                 0
3147 +
3148 +/* size of metadata (inode and directory) blocks */
3149 +#define SQUASHFS_METADATA_SIZE         8192
3150 +#define SQUASHFS_METADATA_LOG          13
3151 +
3152 +/* default size of data blocks */
3153 +#define SQUASHFS_FILE_SIZE             65536
3154 +#define SQUASHFS_FILE_LOG              16
3155 +
3156 +#define SQUASHFS_FILE_MAX_SIZE         65536
3157 +
3158 +/* Max number of uids and gids */
3159 +#define SQUASHFS_UIDS                  256
3160 +#define SQUASHFS_GUIDS                 255
3161 +
3162 +/* Max length of filename (not 255) */
3163 +#define SQUASHFS_NAME_LEN              256
3164 +
3165 +#define SQUASHFS_INVALID               ((long long) 0xffffffffffff)
3166 +#define SQUASHFS_INVALID_FRAG          ((unsigned int) 0xffffffff)
3167 +#define SQUASHFS_INVALID_BLK           ((long long) -1)
3168 +#define SQUASHFS_USED_BLK              ((long long) -2)
3169 +
3170 +/* Filesystem flags */
3171 +#define SQUASHFS_NOI                   0
3172 +#define SQUASHFS_NOD                   1
3173 +#define SQUASHFS_CHECK                 2
3174 +#define SQUASHFS_NOF                   3
3175 +#define SQUASHFS_NO_FRAG               4
3176 +#define SQUASHFS_ALWAYS_FRAG           5
3177 +#define SQUASHFS_DUPLICATE             6
3178 +
3179 +#define SQUASHFS_BIT(flag, bit)                ((flag >> bit) & 1)
3180 +
3181 +#define SQUASHFS_UNCOMPRESSED_INODES(flags)    SQUASHFS_BIT(flags, \
3182 +                                               SQUASHFS_NOI)
3183 +
3184 +#define SQUASHFS_UNCOMPRESSED_DATA(flags)      SQUASHFS_BIT(flags, \
3185 +                                               SQUASHFS_NOD)
3186 +
3187 +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
3188 +                                               SQUASHFS_NOF)
3189 +
3190 +#define SQUASHFS_NO_FRAGMENTS(flags)           SQUASHFS_BIT(flags, \
3191 +                                               SQUASHFS_NO_FRAG)
3192 +
3193 +#define SQUASHFS_ALWAYS_FRAGMENTS(flags)       SQUASHFS_BIT(flags, \
3194 +                                               SQUASHFS_ALWAYS_FRAG)
3195 +
3196 +#define SQUASHFS_DUPLICATES(flags)             SQUASHFS_BIT(flags, \
3197 +                                               SQUASHFS_DUPLICATE)
3198 +
3199 +#define SQUASHFS_CHECK_DATA(flags)             SQUASHFS_BIT(flags, \
3200 +                                               SQUASHFS_CHECK)
3201 +
3202 +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
3203 +               duplicate_checking)     (noi | (nod << 1) | (check_data << 2) \
3204 +               | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
3205 +               (duplicate_checking << 6))
3206 +
3207 +/* Max number of types and file types */
3208 +#define SQUASHFS_DIR_TYPE              1
3209 +#define SQUASHFS_FILE_TYPE             2
3210 +#define SQUASHFS_SYMLINK_TYPE          3
3211 +#define SQUASHFS_BLKDEV_TYPE           4
3212 +#define SQUASHFS_CHRDEV_TYPE           5
3213 +#define SQUASHFS_FIFO_TYPE             6
3214 +#define SQUASHFS_SOCKET_TYPE           7
3215 +#define SQUASHFS_LDIR_TYPE             8
3216 +#define SQUASHFS_LREG_TYPE             9
3217 +
3218 +/* 1.0 filesystem type definitions */
3219 +#define SQUASHFS_TYPES                 5
3220 +#define SQUASHFS_IPC_TYPE              0
3221 +
3222 +/* Flag whether block is compressed or uncompressed, bit is set if block is
3223 + * uncompressed */
3224 +#define SQUASHFS_COMPRESSED_BIT                (1 << 15)
3225 +
3226 +#define SQUASHFS_COMPRESSED_SIZE(B)    (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
3227 +               (B) & ~SQUASHFS_COMPRESSED_BIT :  SQUASHFS_COMPRESSED_BIT)
3228 +
3229 +#define SQUASHFS_COMPRESSED(B)         (!((B) & SQUASHFS_COMPRESSED_BIT))
3230 +
3231 +#define SQUASHFS_COMPRESSED_BIT_BLOCK          (1 << 24)
3232 +
3233 +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B)      (((B) & \
3234 +       ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
3235 +       ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
3236 +
3237 +#define SQUASHFS_COMPRESSED_BLOCK(B)   (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
3238 +
3239 +/*
3240 + * Inode number ops.  Inodes consist of a compressed block number, and an
3241 + * uncompressed  offset within that block
3242 + */
3243 +#define SQUASHFS_INODE_BLK(a)          ((unsigned int) ((a) >> 16))
3244 +
3245 +#define SQUASHFS_INODE_OFFSET(a)       ((unsigned int) ((a) & 0xffff))
3246 +
3247 +#define SQUASHFS_MKINODE(A, B)         ((squashfs_inode_t)(((squashfs_inode_t) (A)\
3248 +                                       << 16) + (B)))
3249 +
3250 +/* Compute 32 bit VFS inode number from squashfs inode number */
3251 +#define SQUASHFS_MK_VFS_INODE(a, b)    ((unsigned int) (((a) << 8) + \
3252 +                                       ((b) >> 2) + 1))
3253 +/* XXX */
3254 +
3255 +/* Translate between VFS mode and squashfs mode */
3256 +#define SQUASHFS_MODE(a)               ((a) & 0xfff)
3257 +
3258 +/* fragment and fragment table defines */
3259 +#define SQUASHFS_FRAGMENT_BYTES(A)     (A * sizeof(struct squashfs_fragment_entry))
3260 +
3261 +#define SQUASHFS_FRAGMENT_INDEX(A)     (SQUASHFS_FRAGMENT_BYTES(A) / \
3262 +                                       SQUASHFS_METADATA_SIZE)
3263 +
3264 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A)      (SQUASHFS_FRAGMENT_BYTES(A) % \
3265 +                                               SQUASHFS_METADATA_SIZE)
3266 +
3267 +#define SQUASHFS_FRAGMENT_INDEXES(A)   ((SQUASHFS_FRAGMENT_BYTES(A) + \
3268 +                                       SQUASHFS_METADATA_SIZE - 1) / \
3269 +                                       SQUASHFS_METADATA_SIZE)
3270 +
3271 +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A)       (SQUASHFS_FRAGMENT_INDEXES(A) *\
3272 +                                               sizeof(long long))
3273 +
3274 +/* cached data constants for filesystem */
3275 +#define SQUASHFS_CACHED_BLKS           8
3276 +
3277 +#define SQUASHFS_MAX_FILE_SIZE_LOG     64
3278 +
3279 +#define SQUASHFS_MAX_FILE_SIZE         ((long long) 1 << \
3280 +                                       (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
3281 +
3282 +#define SQUASHFS_MARKER_BYTE           0xff
3283 +
3284 +/* meta index cache */
3285 +#define SQUASHFS_META_INDEXES  (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
3286 +#define SQUASHFS_META_ENTRIES  31
3287 +#define SQUASHFS_META_NUMBER   8
3288 +#define SQUASHFS_SLOTS         4
3289 +
3290 +struct meta_entry {
3291 +       long long               data_block;
3292 +       unsigned int            index_block;
3293 +       unsigned short          offset;
3294 +       unsigned short          pad;
3295 +};
3296 +
3297 +struct meta_index {
3298 +       unsigned int            inode_number;
3299 +       unsigned int            offset;
3300 +       unsigned short          entries;
3301 +       unsigned short          skip;
3302 +       unsigned short          locked;
3303 +       unsigned short          pad;
3304 +       struct meta_entry       meta_entry[SQUASHFS_META_ENTRIES];
3305 +};
3306 +
3307 +
3308 +/*
3309 + * definitions for structures on disk
3310 + */
3311 +
3312 +typedef long long              squashfs_block_t;
3313 +typedef long long              squashfs_inode_t;
3314 +
3315 +struct squashfs_super_block {
3316 +       unsigned int            s_magic;
3317 +       unsigned int            inodes;
3318 +       unsigned int            bytes_used_2;
3319 +       unsigned int            uid_start_2;
3320 +       unsigned int            guid_start_2;
3321 +       unsigned int            inode_table_start_2;
3322 +       unsigned int            directory_table_start_2;
3323 +       unsigned int            s_major:16;
3324 +       unsigned int            s_minor:16;
3325 +       unsigned int            block_size_1:16;
3326 +       unsigned int            block_log:16;
3327 +       unsigned int            flags:8;
3328 +       unsigned int            no_uids:8;
3329 +       unsigned int            no_guids:8;
3330 +       unsigned int            mkfs_time /* time of filesystem creation */;
3331 +       squashfs_inode_t        root_inode;
3332 +       unsigned int            block_size;
3333 +       unsigned int            fragments;
3334 +       unsigned int            fragment_table_start_2;
3335 +       long long               bytes_used;
3336 +       long long               uid_start;
3337 +       long long               guid_start;
3338 +       long long               inode_table_start;
3339 +       long long               directory_table_start;
3340 +       long long               fragment_table_start;
3341 +       long long               unused;
3342 +} __attribute__ ((packed));
3343 +
3344 +struct squashfs_dir_index {
3345 +       unsigned int            index;
3346 +       unsigned int            start_block;
3347 +       unsigned char           size;
3348 +       unsigned char           name[0];
3349 +} __attribute__ ((packed));
3350 +
3351 +#define SQUASHFS_BASE_INODE_HEADER             \
3352 +       unsigned int            inode_type:4;   \
3353 +       unsigned int            mode:12;        \
3354 +       unsigned int            uid:8;          \
3355 +       unsigned int            guid:8;         \
3356 +       unsigned int            mtime;          \
3357 +       unsigned int            inode_number;
3358 +
3359 +struct squashfs_base_inode_header {
3360 +       SQUASHFS_BASE_INODE_HEADER;
3361 +} __attribute__ ((packed));
3362 +
3363 +struct squashfs_ipc_inode_header {
3364 +       SQUASHFS_BASE_INODE_HEADER;
3365 +       unsigned int            nlink;
3366 +} __attribute__ ((packed));
3367 +
3368 +struct squashfs_dev_inode_header {
3369 +       SQUASHFS_BASE_INODE_HEADER;
3370 +       unsigned int            nlink;
3371 +       unsigned short          rdev;
3372 +} __attribute__ ((packed));
3373 +       
3374 +struct squashfs_symlink_inode_header {
3375 +       SQUASHFS_BASE_INODE_HEADER;
3376 +       unsigned int            nlink;
3377 +       unsigned short          symlink_size;
3378 +       char                    symlink[0];
3379 +} __attribute__ ((packed));
3380 +
3381 +struct squashfs_reg_inode_header {
3382 +       SQUASHFS_BASE_INODE_HEADER;
3383 +       squashfs_block_t        start_block;
3384 +       unsigned int            fragment;
3385 +       unsigned int            offset;
3386 +       unsigned int            file_size;
3387 +       unsigned short          block_list[0];
3388 +} __attribute__ ((packed));
3389 +
3390 +struct squashfs_lreg_inode_header {
3391 +       SQUASHFS_BASE_INODE_HEADER;
3392 +       unsigned int            nlink;
3393 +       squashfs_block_t        start_block;
3394 +       unsigned int            fragment;
3395 +       unsigned int            offset;
3396 +       long long               file_size;
3397 +       unsigned short          block_list[0];
3398 +} __attribute__ ((packed));
3399 +
3400 +struct squashfs_dir_inode_header {
3401 +       SQUASHFS_BASE_INODE_HEADER;
3402 +       unsigned int            nlink;
3403 +       unsigned int            file_size:19;
3404 +       unsigned int            offset:13;
3405 +       unsigned int            start_block;
3406 +       unsigned int            parent_inode;
3407 +} __attribute__  ((packed));
3408 +
3409 +struct squashfs_ldir_inode_header {
3410 +       SQUASHFS_BASE_INODE_HEADER;
3411 +       unsigned int            nlink;
3412 +       unsigned int            file_size:27;
3413 +       unsigned int            offset:13;
3414 +       unsigned int            start_block;
3415 +       unsigned int            i_count:16;
3416 +       unsigned int            parent_inode;
3417 +       struct squashfs_dir_index       index[0];
3418 +} __attribute__  ((packed));
3419 +
3420 +union squashfs_inode_header {
3421 +       struct squashfs_base_inode_header       base;
3422 +       struct squashfs_dev_inode_header        dev;
3423 +       struct squashfs_symlink_inode_header    symlink;
3424 +       struct squashfs_reg_inode_header        reg;
3425 +       struct squashfs_lreg_inode_header       lreg;
3426 +       struct squashfs_dir_inode_header        dir;
3427 +       struct squashfs_ldir_inode_header       ldir;
3428 +       struct squashfs_ipc_inode_header        ipc;
3429 +};
3430 +       
3431 +struct squashfs_dir_entry {
3432 +       unsigned int            offset:13;
3433 +       unsigned int            type:3;
3434 +       unsigned int            size:8;
3435 +       int                     inode_number:16;
3436 +       char                    name[0];
3437 +} __attribute__ ((packed));
3438 +
3439 +struct squashfs_dir_header {
3440 +       unsigned int            count:8;
3441 +       unsigned int            start_block;
3442 +       unsigned int            inode_number;
3443 +} __attribute__ ((packed));
3444 +
3445 +struct squashfs_fragment_entry {
3446 +       long long               start_block;
3447 +       unsigned int            size;
3448 +       unsigned int            unused;
3449 +} __attribute__ ((packed));
3450 +
3451 +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
3452 +extern int squashfs_uncompress_init(void);
3453 +extern int squashfs_uncompress_exit(void);
3454 +
3455 +/*
3456 + * macros to convert each packed bitfield structure from little endian to big
3457 + * endian and vice versa.  These are needed when creating or using a filesystem
3458 + * on a machine with different byte ordering to the target architecture.
3459 + *
3460 + */
3461 +
3462 +#define SQUASHFS_SWAP_START \
3463 +       int bits;\
3464 +       int b_pos;\
3465 +       unsigned long long val;\
3466 +       unsigned char *s;\
3467 +       unsigned char *d;
3468 +
3469 +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
3470 +       SQUASHFS_SWAP_START\
3471 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
3472 +       SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
3473 +       SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
3474 +       SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
3475 +       SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
3476 +       SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
3477 +       SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
3478 +       SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
3479 +       SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
3480 +       SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
3481 +       SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
3482 +       SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
3483 +       SQUASHFS_SWAP((s)->flags, d, 288, 8);\
3484 +       SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
3485 +       SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
3486 +       SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
3487 +       SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
3488 +       SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
3489 +       SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
3490 +       SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
3491 +       SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
3492 +       SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
3493 +       SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
3494 +       SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
3495 +       SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
3496 +       SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
3497 +       SQUASHFS_SWAP((s)->unused, d, 888, 64);\
3498 +}
3499 +
3500 +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3501 +       SQUASHFS_MEMSET(s, d, n);\
3502 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3503 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3504 +       SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3505 +       SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3506 +       SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3507 +       SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
3508 +
3509 +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
3510 +       SQUASHFS_SWAP_START\
3511 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
3512 +}
3513 +
3514 +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
3515 +       SQUASHFS_SWAP_START\
3516 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3517 +                       sizeof(struct squashfs_ipc_inode_header))\
3518 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3519 +}
3520 +
3521 +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
3522 +       SQUASHFS_SWAP_START\
3523 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3524 +                       sizeof(struct squashfs_dev_inode_header)); \
3525 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3526 +       SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
3527 +}
3528 +
3529 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
3530 +       SQUASHFS_SWAP_START\
3531 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3532 +                       sizeof(struct squashfs_symlink_inode_header));\
3533 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3534 +       SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
3535 +}
3536 +
3537 +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
3538 +       SQUASHFS_SWAP_START\
3539 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3540 +                       sizeof(struct squashfs_reg_inode_header));\
3541 +       SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
3542 +       SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
3543 +       SQUASHFS_SWAP((s)->offset, d, 192, 32);\
3544 +       SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
3545 +}
3546 +
3547 +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
3548 +       SQUASHFS_SWAP_START\
3549 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3550 +                       sizeof(struct squashfs_lreg_inode_header));\
3551 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3552 +       SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
3553 +       SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
3554 +       SQUASHFS_SWAP((s)->offset, d, 224, 32);\
3555 +       SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
3556 +}
3557 +
3558 +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
3559 +       SQUASHFS_SWAP_START\
3560 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3561 +                       sizeof(struct squashfs_dir_inode_header));\
3562 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3563 +       SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
3564 +       SQUASHFS_SWAP((s)->offset, d, 147, 13);\
3565 +       SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
3566 +       SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
3567 +}
3568 +
3569 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
3570 +       SQUASHFS_SWAP_START\
3571 +       SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
3572 +                       sizeof(struct squashfs_ldir_inode_header));\
3573 +       SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
3574 +       SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
3575 +       SQUASHFS_SWAP((s)->offset, d, 155, 13);\
3576 +       SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
3577 +       SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
3578 +       SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
3579 +}
3580 +
3581 +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
3582 +       SQUASHFS_SWAP_START\
3583 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
3584 +       SQUASHFS_SWAP((s)->index, d, 0, 32);\
3585 +       SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
3586 +       SQUASHFS_SWAP((s)->size, d, 64, 8);\
3587 +}
3588 +
3589 +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
3590 +       SQUASHFS_SWAP_START\
3591 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
3592 +       SQUASHFS_SWAP((s)->count, d, 0, 8);\
3593 +       SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
3594 +       SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
3595 +}
3596 +
3597 +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
3598 +       SQUASHFS_SWAP_START\
3599 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
3600 +       SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3601 +       SQUASHFS_SWAP((s)->type, d, 13, 3);\
3602 +       SQUASHFS_SWAP((s)->size, d, 16, 8);\
3603 +       SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
3604 +}
3605 +
3606 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
3607 +       SQUASHFS_SWAP_START\
3608 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
3609 +       SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
3610 +       SQUASHFS_SWAP((s)->size, d, 64, 32);\
3611 +}
3612 +
3613 +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
3614 +       int entry;\
3615 +       int bit_position;\
3616 +       SQUASHFS_SWAP_START\
3617 +       SQUASHFS_MEMSET(s, d, n * 2);\
3618 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3619 +                       16)\
3620 +               SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
3621 +}
3622 +
3623 +#define SQUASHFS_SWAP_INTS(s, d, n) {\
3624 +       int entry;\
3625 +       int bit_position;\
3626 +       SQUASHFS_SWAP_START\
3627 +       SQUASHFS_MEMSET(s, d, n * 4);\
3628 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3629 +                       32)\
3630 +               SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
3631 +}
3632 +
3633 +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
3634 +       int entry;\
3635 +       int bit_position;\
3636 +       SQUASHFS_SWAP_START\
3637 +       SQUASHFS_MEMSET(s, d, n * 8);\
3638 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3639 +                       64)\
3640 +               SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
3641 +}
3642 +
3643 +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
3644 +       int entry;\
3645 +       int bit_position;\
3646 +       SQUASHFS_SWAP_START\
3647 +       SQUASHFS_MEMSET(s, d, n * bits / 8);\
3648 +       for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
3649 +                       bits)\
3650 +               SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
3651 +}
3652 +
3653 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
3654 +
3655 +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
3656 +
3657 +struct squashfs_base_inode_header_1 {
3658 +       unsigned int            inode_type:4;
3659 +       unsigned int            mode:12; /* protection */
3660 +       unsigned int            uid:4; /* index into uid table */
3661 +       unsigned int            guid:4; /* index into guid table */
3662 +} __attribute__ ((packed));
3663 +
3664 +struct squashfs_ipc_inode_header_1 {
3665 +       unsigned int            inode_type:4;
3666 +       unsigned int            mode:12; /* protection */
3667 +       unsigned int            uid:4; /* index into uid table */
3668 +       unsigned int            guid:4; /* index into guid table */
3669 +       unsigned int            type:4;
3670 +       unsigned int            offset:4;
3671 +} __attribute__ ((packed));
3672 +
3673 +struct squashfs_dev_inode_header_1 {
3674 +       unsigned int            inode_type:4;
3675 +       unsigned int            mode:12; /* protection */
3676 +       unsigned int            uid:4; /* index into uid table */
3677 +       unsigned int            guid:4; /* index into guid table */
3678 +       unsigned short          rdev;
3679 +} __attribute__ ((packed));
3680 +       
3681 +struct squashfs_symlink_inode_header_1 {
3682 +       unsigned int            inode_type:4;
3683 +       unsigned int            mode:12; /* protection */
3684 +       unsigned int            uid:4; /* index into uid table */
3685 +       unsigned int            guid:4; /* index into guid table */
3686 +       unsigned short          symlink_size;
3687 +       char                    symlink[0];
3688 +} __attribute__ ((packed));
3689 +
3690 +struct squashfs_reg_inode_header_1 {
3691 +       unsigned int            inode_type:4;
3692 +       unsigned int            mode:12; /* protection */
3693 +       unsigned int            uid:4; /* index into uid table */
3694 +       unsigned int            guid:4; /* index into guid table */
3695 +       unsigned int            mtime;
3696 +       unsigned int            start_block;
3697 +       unsigned int            file_size:32;
3698 +       unsigned short          block_list[0];
3699 +} __attribute__ ((packed));
3700 +
3701 +struct squashfs_dir_inode_header_1 {
3702 +       unsigned int            inode_type:4;
3703 +       unsigned int            mode:12; /* protection */
3704 +       unsigned int            uid:4; /* index into uid table */
3705 +       unsigned int            guid:4; /* index into guid table */
3706 +       unsigned int            file_size:19;
3707 +       unsigned int            offset:13;
3708 +       unsigned int            mtime;
3709 +       unsigned int            start_block:24;
3710 +} __attribute__  ((packed));
3711 +
3712 +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
3713 +       SQUASHFS_MEMSET(s, d, n);\
3714 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3715 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3716 +       SQUASHFS_SWAP((s)->uid, d, 16, 4);\
3717 +       SQUASHFS_SWAP((s)->guid, d, 20, 4);
3718 +
3719 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
3720 +       SQUASHFS_SWAP_START\
3721 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
3722 +}
3723 +
3724 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
3725 +       SQUASHFS_SWAP_START\
3726 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3727 +                       sizeof(struct squashfs_ipc_inode_header_1));\
3728 +       SQUASHFS_SWAP((s)->type, d, 24, 4);\
3729 +       SQUASHFS_SWAP((s)->offset, d, 28, 4);\
3730 +}
3731 +
3732 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
3733 +       SQUASHFS_SWAP_START\
3734 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3735 +                       sizeof(struct squashfs_dev_inode_header_1));\
3736 +       SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
3737 +}
3738 +
3739 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
3740 +       SQUASHFS_SWAP_START\
3741 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3742 +                       sizeof(struct squashfs_symlink_inode_header_1));\
3743 +       SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
3744 +}
3745 +
3746 +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
3747 +       SQUASHFS_SWAP_START\
3748 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3749 +                       sizeof(struct squashfs_reg_inode_header_1));\
3750 +       SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
3751 +       SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
3752 +       SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
3753 +}
3754 +
3755 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
3756 +       SQUASHFS_SWAP_START\
3757 +       SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
3758 +                       sizeof(struct squashfs_dir_inode_header_1));\
3759 +       SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
3760 +       SQUASHFS_SWAP((s)->offset, d, 43, 13);\
3761 +       SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
3762 +       SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
3763 +}
3764 +
3765 +#endif
3766 +
3767 +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
3768 +
3769 +struct squashfs_dir_index_2 {
3770 +       unsigned int            index:27;
3771 +       unsigned int            start_block:29;
3772 +       unsigned char           size;
3773 +       unsigned char           name[0];
3774 +} __attribute__ ((packed));
3775 +
3776 +struct squashfs_base_inode_header_2 {
3777 +       unsigned int            inode_type:4;
3778 +       unsigned int            mode:12; /* protection */
3779 +       unsigned int            uid:8; /* index into uid table */
3780 +       unsigned int            guid:8; /* index into guid table */
3781 +} __attribute__ ((packed));
3782 +
3783 +struct squashfs_ipc_inode_header_2 {
3784 +       unsigned int            inode_type:4;
3785 +       unsigned int            mode:12; /* protection */
3786 +       unsigned int            uid:8; /* index into uid table */
3787 +       unsigned int            guid:8; /* index into guid table */
3788 +} __attribute__ ((packed));
3789 +
3790 +struct squashfs_dev_inode_header_2 {
3791 +       unsigned int            inode_type:4;
3792 +       unsigned int            mode:12; /* protection */
3793 +       unsigned int            uid:8; /* index into uid table */
3794 +       unsigned int            guid:8; /* index into guid table */
3795 +       unsigned short          rdev;
3796 +} __attribute__ ((packed));
3797 +       
3798 +struct squashfs_symlink_inode_header_2 {
3799 +       unsigned int            inode_type:4;
3800 +       unsigned int            mode:12; /* protection */
3801 +       unsigned int            uid:8; /* index into uid table */
3802 +       unsigned int            guid:8; /* index into guid table */
3803 +       unsigned short          symlink_size;
3804 +       char                    symlink[0];
3805 +} __attribute__ ((packed));
3806 +
3807 +struct squashfs_reg_inode_header_2 {
3808 +       unsigned int            inode_type:4;
3809 +       unsigned int            mode:12; /* protection */
3810 +       unsigned int            uid:8; /* index into uid table */
3811 +       unsigned int            guid:8; /* index into guid table */
3812 +       unsigned int            mtime;
3813 +       unsigned int            start_block;
3814 +       unsigned int            fragment;
3815 +       unsigned int            offset;
3816 +       unsigned int            file_size:32;
3817 +       unsigned short          block_list[0];
3818 +} __attribute__ ((packed));
3819 +
3820 +struct squashfs_dir_inode_header_2 {
3821 +       unsigned int            inode_type:4;
3822 +       unsigned int            mode:12; /* protection */
3823 +       unsigned int            uid:8; /* index into uid table */
3824 +       unsigned int            guid:8; /* index into guid table */
3825 +       unsigned int            file_size:19;
3826 +       unsigned int            offset:13;
3827 +       unsigned int            mtime;
3828 +       unsigned int            start_block:24;
3829 +} __attribute__  ((packed));
3830 +
3831 +struct squashfs_ldir_inode_header_2 {
3832 +       unsigned int            inode_type:4;
3833 +       unsigned int            mode:12; /* protection */
3834 +       unsigned int            uid:8; /* index into uid table */
3835 +       unsigned int            guid:8; /* index into guid table */
3836 +       unsigned int            file_size:27;
3837 +       unsigned int            offset:13;
3838 +       unsigned int            mtime;
3839 +       unsigned int            start_block:24;
3840 +       unsigned int            i_count:16;
3841 +       struct squashfs_dir_index_2     index[0];
3842 +} __attribute__  ((packed));
3843 +
3844 +union squashfs_inode_header_2 {
3845 +       struct squashfs_base_inode_header_2     base;
3846 +       struct squashfs_dev_inode_header_2      dev;
3847 +       struct squashfs_symlink_inode_header_2  symlink;
3848 +       struct squashfs_reg_inode_header_2      reg;
3849 +       struct squashfs_dir_inode_header_2      dir;
3850 +       struct squashfs_ldir_inode_header_2     ldir;
3851 +       struct squashfs_ipc_inode_header_2      ipc;
3852 +};
3853 +       
3854 +struct squashfs_dir_header_2 {
3855 +       unsigned int            count:8;
3856 +       unsigned int            start_block:24;
3857 +} __attribute__ ((packed));
3858 +
3859 +struct squashfs_dir_entry_2 {
3860 +       unsigned int            offset:13;
3861 +       unsigned int            type:3;
3862 +       unsigned int            size:8;
3863 +       char                    name[0];
3864 +} __attribute__ ((packed));
3865 +
3866 +struct squashfs_fragment_entry_2 {
3867 +       unsigned int            start_block;
3868 +       unsigned int            size;
3869 +} __attribute__ ((packed));
3870 +
3871 +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3872 +       SQUASHFS_MEMSET(s, d, n);\
3873 +       SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
3874 +       SQUASHFS_SWAP((s)->mode, d, 4, 12);\
3875 +       SQUASHFS_SWAP((s)->uid, d, 16, 8);\
3876 +       SQUASHFS_SWAP((s)->guid, d, 24, 8);\
3877 +
3878 +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
3879 +       SQUASHFS_SWAP_START\
3880 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
3881 +}
3882 +
3883 +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
3884 +       SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
3885 +
3886 +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
3887 +       SQUASHFS_SWAP_START\
3888 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3889 +                       sizeof(struct squashfs_dev_inode_header_2)); \
3890 +       SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
3891 +}
3892 +
3893 +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
3894 +       SQUASHFS_SWAP_START\
3895 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3896 +                       sizeof(struct squashfs_symlink_inode_header_2));\
3897 +       SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
3898 +}
3899 +
3900 +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
3901 +       SQUASHFS_SWAP_START\
3902 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3903 +                       sizeof(struct squashfs_reg_inode_header_2));\
3904 +       SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
3905 +       SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
3906 +       SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
3907 +       SQUASHFS_SWAP((s)->offset, d, 128, 32);\
3908 +       SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
3909 +}
3910 +
3911 +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
3912 +       SQUASHFS_SWAP_START\
3913 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3914 +                       sizeof(struct squashfs_dir_inode_header_2));\
3915 +       SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
3916 +       SQUASHFS_SWAP((s)->offset, d, 51, 13);\
3917 +       SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
3918 +       SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
3919 +}
3920 +
3921 +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
3922 +       SQUASHFS_SWAP_START\
3923 +       SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
3924 +                       sizeof(struct squashfs_ldir_inode_header_2));\
3925 +       SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
3926 +       SQUASHFS_SWAP((s)->offset, d, 59, 13);\
3927 +       SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
3928 +       SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
3929 +       SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
3930 +}
3931 +
3932 +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
3933 +       SQUASHFS_SWAP_START\
3934 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
3935 +       SQUASHFS_SWAP((s)->index, d, 0, 27);\
3936 +       SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
3937 +       SQUASHFS_SWAP((s)->size, d, 56, 8);\
3938 +}
3939 +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
3940 +       SQUASHFS_SWAP_START\
3941 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
3942 +       SQUASHFS_SWAP((s)->count, d, 0, 8);\
3943 +       SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
3944 +}
3945 +
3946 +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
3947 +       SQUASHFS_SWAP_START\
3948 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
3949 +       SQUASHFS_SWAP((s)->offset, d, 0, 13);\
3950 +       SQUASHFS_SWAP((s)->type, d, 13, 3);\
3951 +       SQUASHFS_SWAP((s)->size, d, 16, 8);\
3952 +}
3953 +
3954 +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
3955 +       SQUASHFS_SWAP_START\
3956 +       SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
3957 +       SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
3958 +       SQUASHFS_SWAP((s)->size, d, 32, 32);\
3959 +}
3960 +
3961 +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
3962 +
3963 +/* fragment and fragment table defines */
3964 +#define SQUASHFS_FRAGMENT_BYTES_2(A)   (A * sizeof(struct squashfs_fragment_entry_2))
3965 +
3966 +#define SQUASHFS_FRAGMENT_INDEX_2(A)   (SQUASHFS_FRAGMENT_BYTES_2(A) / \
3967 +                                       SQUASHFS_METADATA_SIZE)
3968 +
3969 +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A)    (SQUASHFS_FRAGMENT_BYTES_2(A) % \
3970 +                                               SQUASHFS_METADATA_SIZE)
3971 +
3972 +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
3973 +                                       SQUASHFS_METADATA_SIZE - 1) / \
3974 +                                       SQUASHFS_METADATA_SIZE)
3975 +
3976 +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A)     (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
3977 +                                               sizeof(int))
3978 +
3979 +#endif
3980 +
3981 +#ifdef __KERNEL__
3982 +
3983 +/*
3984 + * macros used to swap each structure entry, taking into account
3985 + * bitfields and different bitfield placing conventions on differing
3986 + * architectures
3987 + */
3988 +
3989 +#include <asm/byteorder.h>
3990 +
3991 +#ifdef __BIG_ENDIAN
3992 +       /* convert from little endian to big endian */
3993 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3994 +               tbits, b_pos)
3995 +#else
3996 +       /* convert from big endian to little endian */ 
3997 +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
3998 +               tbits, 64 - tbits - b_pos)
3999 +#endif
4000 +
4001 +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
4002 +       b_pos = pos % 8;\
4003 +       val = 0;\
4004 +       s = (unsigned char *)p + (pos / 8);\
4005 +       d = ((unsigned char *) &val) + 7;\
4006 +       for(bits = 0; bits < (tbits + b_pos); bits += 8) \
4007 +               *d-- = *s++;\
4008 +       value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
4009 +}
4010 +
4011 +#define SQUASHFS_MEMSET(s, d, n)       memset(s, 0, n);
4012 +
4013 +#endif
4014 +#endif
4015 Index: linux-2.6.18/include/linux/squashfs_fs_i.h
4016 ===================================================================
4017 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
4018 +++ linux-2.6.18/include/linux/squashfs_fs_i.h  2006-09-20 15:45:15.000000000 +0100
4019 @@ -0,0 +1,45 @@
4020 +#ifndef SQUASHFS_FS_I
4021 +#define SQUASHFS_FS_I
4022 +/*
4023 + * Squashfs
4024 + *
4025 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4026 + * Phillip Lougher <phillip@lougher.org.uk>
4027 + *
4028 + * This program is free software; you can redistribute it and/or
4029 + * modify it under the terms of the GNU General Public License
4030 + * as published by the Free Software Foundation; either version 2,
4031 + * or (at your option) any later version.
4032 + *
4033 + * This program is distributed in the hope that it will be useful,
4034 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4035 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4036 + * GNU General Public License for more details.
4037 + *
4038 + * You should have received a copy of the GNU General Public License
4039 + * along with this program; if not, write to the Free Software
4040 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4041 + *
4042 + * squashfs_fs_i.h
4043 + */
4044 +
4045 +struct squashfs_inode_info {
4046 +       long long       start_block;
4047 +       unsigned int    offset;
4048 +       union {
4049 +               struct {
4050 +                       long long       fragment_start_block;
4051 +                       unsigned int    fragment_size;
4052 +                       unsigned int    fragment_offset;
4053 +                       long long       block_list_start;
4054 +               } s1;
4055 +               struct {
4056 +                       long long       directory_index_start;
4057 +                       unsigned int    directory_index_offset;
4058 +                       unsigned int    directory_index_count;
4059 +                       unsigned int    parent_inode;
4060 +               } s2;
4061 +       } u;
4062 +       struct inode    vfs_inode;
4063 +};
4064 +#endif
4065 Index: linux-2.6.18/include/linux/squashfs_fs_sb.h
4066 ===================================================================
4067 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
4068 +++ linux-2.6.18/include/linux/squashfs_fs_sb.h 2006-09-20 15:45:15.000000000 +0100
4069 @@ -0,0 +1,74 @@
4070 +#ifndef SQUASHFS_FS_SB
4071 +#define SQUASHFS_FS_SB
4072 +/*
4073 + * Squashfs
4074 + *
4075 + * Copyright (c) 2002, 2003, 2004, 2005, 2006
4076 + * Phillip Lougher <phillip@lougher.org.uk>
4077 + *
4078 + * This program is free software; you can redistribute it and/or
4079 + * modify it under the terms of the GNU General Public License
4080 + * as published by the Free Software Foundation; either version 2,
4081 + * or (at your option) any later version.
4082 + *
4083 + * This program is distributed in the hope that it will be useful,
4084 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4086 + * GNU General Public License for more details.
4087 + *
4088 + * You should have received a copy of the GNU General Public License
4089 + * along with this program; if not, write to the Free Software
4090 + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4091 + *
4092 + * squashfs_fs_sb.h
4093 + */
4094 +
4095 +#include <linux/squashfs_fs.h>
4096 +
4097 +struct squashfs_cache {
4098 +       long long       block;
4099 +       int             length;
4100 +       long long       next_index;
4101 +       char            *data;
4102 +};
4103 +
4104 +struct squashfs_fragment_cache {
4105 +       long long       block;
4106 +       int             length;
4107 +       unsigned int    locked;
4108 +       char            *data;
4109 +};
4110 +
4111 +struct squashfs_sb_info {
4112 +       struct squashfs_super_block     sblk;
4113 +       int                     devblksize;
4114 +       int                     devblksize_log2;
4115 +       int                     swap;
4116 +       struct squashfs_cache   *block_cache;
4117 +       struct squashfs_fragment_cache  *fragment;
4118 +       int                     next_cache;
4119 +       int                     next_fragment;
4120 +       int                     next_meta_index;
4121 +       unsigned int            *uid;
4122 +       unsigned int            *guid;
4123 +       long long               *fragment_index;
4124 +       unsigned int            *fragment_index_2;
4125 +       unsigned int            read_size;
4126 +       char                    *read_data;
4127 +       char                    *read_page;
4128 +       struct semaphore        read_data_mutex;
4129 +       struct semaphore        read_page_mutex;
4130 +       struct semaphore        block_cache_mutex;
4131 +       struct semaphore        fragment_mutex;
4132 +       struct semaphore        meta_index_mutex;
4133 +       wait_queue_head_t       waitq;
4134 +       wait_queue_head_t       fragment_wait_queue;
4135 +       struct meta_index       *meta_index;
4136 +       struct inode            *(*iget)(struct super_block *s,  squashfs_inode_t \
4137 +                               inode);
4138 +       long long               (*read_blocklist)(struct inode *inode, int \
4139 +                               index, int readahead_blks, char *block_list, \
4140 +                               unsigned short **block_p, unsigned int *bsize);
4141 +       int                     (*read_fragment_index_table)(struct super_block *s);
4142 +};
4143 +#endif
4144 Index: linux-2.6.18/init/do_mounts_rd.c
4145 ===================================================================
4146 --- linux-2.6.18.orig/init/do_mounts_rd.c       2006-09-20 04:42:06.000000000 +0100
4147 +++ linux-2.6.18/init/do_mounts_rd.c    2006-09-20 15:45:15.000000000 +0100
4148 @@ -5,6 +5,7 @@
4149  #include <linux/ext2_fs.h>
4150  #include <linux/romfs_fs.h>
4151  #include <linux/cramfs_fs.h>
4152 +#include <linux/squashfs_fs.h>
4153  #include <linux/initrd.h>
4154  #include <linux/string.h>
4155  
4156 @@ -39,6 +40,7 @@ static int __init crd_load(int in_fd, in
4157   * numbers could not be found.
4158   *
4159   * We currently check for the following magic numbers:
4160 + *      squashfs
4161   *     minix
4162   *     ext2
4163   *     romfs
4164 @@ -53,6 +55,7 @@ identify_ramdisk_image(int fd, int start
4165         struct ext2_super_block *ext2sb;
4166         struct romfs_super_block *romfsb;
4167         struct cramfs_super *cramfsb;
4168 +       struct squashfs_super_block *squashfsb;
4169         int nblocks = -1;
4170         unsigned char *buf;
4171  
4172 @@ -64,6 +67,7 @@ identify_ramdisk_image(int fd, int start
4173         ext2sb = (struct ext2_super_block *) buf;
4174         romfsb = (struct romfs_super_block *) buf;
4175         cramfsb = (struct cramfs_super *) buf;
4176 +       squashfsb = (struct squashfs_super_block *) buf;
4177         memset(buf, 0xe5, size);
4178  
4179         /*
4180 @@ -101,6 +105,15 @@ identify_ramdisk_image(int fd, int start
4181                 goto done;
4182         }
4183  
4184 +       /* squashfs is at block zero too */
4185 +       if (squashfsb->s_magic == SQUASHFS_MAGIC) {
4186 +               printk(KERN_NOTICE
4187 +                      "RAMDISK: squashfs filesystem found at block %d\n",
4188 +                      start_block);
4189 +               nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
4190 +               goto done;
4191 +       }
4192 +
4193         /*
4194          * Read block 1 to test for minix and ext2 superblock
4195          */