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