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