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